From e1f376d3e81a5e3c79bee1c8cacb25c04a22404e Mon Sep 17 00:00:00 2001 From: yelinz Date: Thu, 13 Jun 2024 11:10:17 +0200 Subject: [PATCH] feat(list): add url for LinkTo generation --- addon/components/document-list-item.hbs | 18 +++++++----- tests/dummy/app/services/alexandria-config.js | 28 +++++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/addon/components/document-list-item.hbs b/addon/components/document-list-item.hbs index 9ccdd697..9c8b2f97 100644 --- a/addon/components/document-list-item.hbs +++ b/addon/components/document-list-item.hbs @@ -44,13 +44,17 @@ {{else if (eq column "link")}} - {{#let (this.config.documentListLinkTo @document) as |linkConfig|}} - - {{linkConfig.label}} - + {{#let (await (this.config.documentListLinkTo @document)) as |linkConfig|}} + {{#if linkConfig.url}} + {{linkConfig.label}} + {{else}} + + {{linkConfig.label}} + + {{/if}} {{/let}} {{else if (eq column "date")}} diff --git a/tests/dummy/app/services/alexandria-config.js b/tests/dummy/app/services/alexandria-config.js index 4ab70981..dc540c92 100644 --- a/tests/dummy/app/services/alexandria-config.js +++ b/tests/dummy/app/services/alexandria-config.js @@ -1,9 +1,12 @@ -import { later } from "@ember/runloop"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; import { macroCondition, isTesting } from "@embroider/macros"; import AlexandriaConfigService from "ember-alexandria/services/alexandria-config"; export default class CustomAlexandriaConfigService extends AlexandriaConfigService { + @service router; + enablePDFConversion = true; enableWebDAV = true; @@ -35,18 +38,27 @@ export default class CustomAlexandriaConfigService extends AlexandriaConfigServi return {}; } - resolveUser(id) { + async resolveUser(id) { const timeout = macroCondition(isTesting()) ? 1 : 200; - return new Promise((resolve) => - later(this, () => resolve((id || "").toUpperCase()), timeout), - ); + await new Promise((resolve) => setTimeout(resolve, timeout)); + + return (id || "-").toUpperCase(); } - documentListLinkTo() { + @action + async documentListLinkTo(document) { + const timeout = macroCondition(isTesting()) ? 1 : 200; + + await new Promise((resolve) => setTimeout(resolve, timeout)); + return { - route: "index", - label: "To document detail", + url: this.router.urlFor("alexandria-meta", 1, { + queryParams: { + document: document.id, + }, + }), + label: "View Detail", }; } }