From 7a7020292b10adceaeafbc2ffb3e4a04d305bd65 Mon Sep 17 00:00:00 2001 From: Artyom Savchenko Date: Fri, 6 Mar 2026 12:24:47 +0700 Subject: [PATCH] Add action to export project documents (#10592) Signed-off-by: Artem Savchenko --- models/controlled-documents/src/index.ts | 27 +++++++++++++++++++ plugins/controlled-documents/src/plugin.ts | 1 + .../components/ExportToWorkspaceModal.svelte | 25 +++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/models/controlled-documents/src/index.ts b/models/controlled-documents/src/index.ts index bb8f0768f0..5f333087a7 100644 --- a/models/controlled-documents/src/index.ts +++ b/models/controlled-documents/src/index.ts @@ -897,6 +897,33 @@ export function createModel (builder: Builder): void { documents.action.ExportDocuments ) + createAction( + builder, + { + action: view.actionImpl.ShowPopup, + actionProps: { + component: exportPlugin.component.ExportToWorkspaceModal, + fillProps: { + _objects: 'value' + }, + props: { + projectDocExport: true, + docClass: documents.class.ControlledDocument + } + }, + label: exportPlugin.string.ExportToWorkspace, + icon: exportPlugin.icon.Export, + input: 'any', + category: view.category.General, + target: documents.class.ProjectDocument, + context: { + mode: ['context', 'browser'], + group: 'copy' + } + }, + documents.action.ExportProjectDocuments + ) + createAction( builder, { diff --git a/plugins/controlled-documents/src/plugin.ts b/plugins/controlled-documents/src/plugin.ts index 1ecf43d074..0460f81531 100644 --- a/plugins/controlled-documents/src/plugin.ts +++ b/plugins/controlled-documents/src/plugin.ts @@ -125,6 +125,7 @@ export const documentsPlugin = plugin(documentsId, { EditDocSpace: '' as Ref, TransferDocument: '' as Ref, ExportDocuments: '' as Ref>, + ExportProjectDocuments: '' as Ref>, ExportDocumentsFromSpace: '' as Ref>, Print: '' as Ref>, PrintProjectDocument: '' as Ref>, diff --git a/plugins/export-resources/src/components/ExportToWorkspaceModal.svelte b/plugins/export-resources/src/components/ExportToWorkspaceModal.svelte index 9a22e135af..19dfc4a85a 100644 --- a/plugins/export-resources/src/components/ExportToWorkspaceModal.svelte +++ b/plugins/export-resources/src/components/ExportToWorkspaceModal.svelte @@ -24,7 +24,7 @@ type Space, type Class } from '@hcengineering/core' - import { Card, getCurrentWorkspaceUuid } from '@hcengineering/presentation' + import { Card, getClient, getCurrentWorkspaceUuid } from '@hcengineering/presentation' import { DropdownLabels, DropdownLabelsIntl, Label } from '@hcengineering/ui' import { getResource } from '@hcengineering/platform' import login from '@hcengineering/login' @@ -39,6 +39,7 @@ export let value: Doc | Doc[] | Space export let docClass: Ref> | undefined = undefined export let spaceExport: boolean | undefined = false + export let projectDocExport: boolean | undefined = false const dispatch = createEventDispatcher() @@ -117,14 +118,34 @@ $: canSave = targetWorkspace !== undefined && _class != null && (spaceExport === true || filteredSelectedDocs.length > 0) + async function getExportDocuments (): Promise> { + if (docClass == null) { + console.error('Document class is required to export project documents') + return [] + } + const client = getClient() + const innerIds = selectedDocs.map((d) => (d as any)?.document).filter((id) => id != null) + + if (innerIds.length > 0) { + const docs = await client.findAll(docClass, { + _id: { $in: innerIds } + }) + return filterDocsForExport(docs, exportFilterMode) + } + return [] + } + async function handleExport (): Promise { if (!canSave || _class == null) return loading = true + + const effectiveDocs = projectDocExport === true ? await getExportDocuments() : filteredSelectedDocs + void exportToWorkspace( _class, exportQuery, - filteredSelectedDocs, + effectiveDocs, targetWorkspace, undefined, exportFilterMode === 'skipArchivedObsolete',