diff --git a/core/attachments/attachments-ui/package.json b/core/attachments/attachments-ui/package.json index 911c88a75..ae69ea305 100644 --- a/core/attachments/attachments-ui/package.json +++ b/core/attachments/attachments-ui/package.json @@ -26,11 +26,14 @@ "@xwiki/cristal-api": "workspace:*", "@xwiki/cristal-attachments-api": "workspace:*", "@xwiki/cristal-date-ui": "workspace:*", + "@xwiki/cristal-document-api": "workspace:*", "@xwiki/cristal-dsapi": "workspace:*", "@xwiki/cristal-extra-tabs-api": "workspace:*", "@xwiki/cristal-file-preview-ui": "workspace:*", "@xwiki/cristal-info-actions-api": "workspace:*", + "@xwiki/cristal-model-api": "workspace:*", "@xwiki/cristal-model-click-listener": "workspace:*", + "@xwiki/cristal-model-reference-api": "workspace:*", "@xwiki/cristal-uiextension-api": "workspace:*", "@xwiki/cristal-user-ui": "workspace:*", "inversify": "6.2.0", diff --git a/core/attachments/attachments-ui/src/vue/AttachmentsTab.vue b/core/attachments/attachments-ui/src/vue/AttachmentsTab.vue index 9a14b1b0e..cd6b3db4b 100644 --- a/core/attachments/attachments-ui/src/vue/AttachmentsTab.vue +++ b/core/attachments/attachments-ui/src/vue/AttachmentsTab.vue @@ -23,6 +23,7 @@ import AttachmentsTable from "./AttachmentsTable.vue"; import { AlertsService } from "@xwiki/cristal-alerts-api"; import { CristalApp } from "@xwiki/cristal-api"; import { AttachmentsService } from "@xwiki/cristal-attachments-api"; +import { DocumentService } from "@xwiki/cristal-document-api"; import { inject, ref, watch } from "vue"; import { useRoute } from "vue-router"; @@ -31,6 +32,10 @@ const attachmentsService = cristal .getContainer() .get("AttachmentsService")!; +const documentService = cristal + .getContainer() + .get("DocumentService")!; + const attachments = attachmentsService.list(); const isLoading = attachmentsService.isLoading(); const errorMessage = attachmentsService.getError(); @@ -38,14 +43,14 @@ const isUploading = attachmentsService.isUploading(); // Watch for route change to refresh the tab when a user visits a new page. const route = useRoute(); + +function getCurrentPageReference() { + return documentService.getCurrentDocumentReferenceString().value ?? ""; +} + watch( () => route.params.page, - () => - attachmentsService.refresh( - (route.params.page as string) || - cristal.getCurrentPage() || - "Main.WebHome", - ), + () => attachmentsService.refresh(getCurrentPageReference()), { immediate: true }, ); @@ -57,12 +62,7 @@ const alertsService = cristal async function upload(files: File[]) { try { - await attachmentsService.upload( - (route.params.page as string) || - cristal.getCurrentPage() || - ("Main.WebHome" as string), - files, - ); + await attachmentsService.upload(getCurrentPageReference(), files); attachmentUpload.value?.reset(); } catch (e) { if (e instanceof Error) { diff --git a/core/attachments/attachments-ui/src/vue/AttachmentsTable.vue b/core/attachments/attachments-ui/src/vue/AttachmentsTable.vue index 00d0c6698..5dbefb44b 100644 --- a/core/attachments/attachments-ui/src/vue/AttachmentsTable.vue +++ b/core/attachments/attachments-ui/src/vue/AttachmentsTable.vue @@ -3,6 +3,8 @@ import messages from "../translations"; import { Attachment } from "@xwiki/cristal-attachments-api"; import { Date } from "@xwiki/cristal-date-ui"; import { FileSize } from "@xwiki/cristal-file-preview-ui"; +import { AttachmentReference, EntityType } from "@xwiki/cristal-model-api"; +import { ModelReferenceParserProvider } from "@xwiki/cristal-model-reference-api"; import { User } from "@xwiki/cristal-user-ui"; import { computed, inject } from "vue"; import { useI18n } from "vue-i18n"; @@ -21,6 +23,10 @@ const props = defineProps<{ const cristal = inject("cristal")!; const listener = cristal.getContainer().get("ClickListener"); +const modelReferenceParser = cristal + .getContainer() + .get("ModelReferenceParserProvider") + .get()!; function attachmentPreview(url: string, event: Event) { event.preventDefault(); @@ -35,6 +41,19 @@ const hasAuthor = computed(() => { .length > 0 ); }); + +function attachmentName(name: string) { + try { + return ( + modelReferenceParser.parse( + name, + EntityType.ATTACHMENT, + ) as AttachmentReference + ).name; + } catch { + return ""; + } +}