diff --git a/CHANGELOG.md b/CHANGELOG.md index ced1e9042..6b0509a28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added back in the Basic Google Analytics page block (NS-45) (NS-54) - Added config option to continue contributions to another manifest after submission (MAD-1514) +- Added manifest and canvas labels on CSV export (MAD-1420) + +### Fixed +- Fixed block editor button 'saved' instead of 'save' (MAD-1475) +- Fixed marking canvas as incomplete not marking manifest as incomplete (MAD-1516) ## [v2.2.7](https://github.com/digirati-co-uk/madoc-platform/compare/v2.2.6...v2.2.7) @@ -23,9 +28,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Disables server-side rendering on the 2 review/task pages. -### Fixed -- Fixed block editor button 'saved' instead of 'save' (MAD-1475) - ## [v2.2.6](https://github.com/digirati-co-uk/madoc-platform/compare/v2.2.5...v2.2.6) ### Added diff --git a/services/madoc-ts/src/extensions/project-export/export-configs/project/project-csv-simple-export.ts b/services/madoc-ts/src/extensions/project-export/export-configs/project/project-csv-simple-export.ts index 02598f8e7..d1928802e 100644 --- a/services/madoc-ts/src/extensions/project-export/export-configs/project/project-csv-simple-export.ts +++ b/services/madoc-ts/src/extensions/project-export/export-configs/project/project-csv-simple-export.ts @@ -1,6 +1,39 @@ import { parseModelTarget } from '../../../../utility/parse-model-target'; import { ExportFile } from '../../server-export'; import { ExportConfig, ExportDataOptions, ExportFileDefinition, SupportedExportResource } from '../../types'; +import { getValue } from '@iiif/helpers/i18n'; + +const labelCache: { manifestLabels: Record; canvasLabels: Record } = { + manifestLabels: {}, + canvasLabels: {}, +}; + +async function fetchLabels(api: any, manifestIds: number[], canvasIds: number[]) { + const newManifestIds = manifestIds.filter(id => id !== undefined && !labelCache.manifestLabels[id.toString()]); + const newCanvasIds = canvasIds.filter(id => id !== undefined && !labelCache.canvasLabels[id.toString()]); + + if (newManifestIds.length > 0) { + const manifests = await Promise.all(newManifestIds.map(id => api.getManifestById(id))); + manifests.forEach(response => { + const manifest = response.manifest; + if (manifest && manifest.id !== undefined) { + labelCache.manifestLabels[manifest.id.toString()] = getValue(manifest.label); + } + }); + } + + if (newCanvasIds.length > 0) { + const canvases = await Promise.all(newCanvasIds.map(id => api.getCanvasById(id))); + canvases.forEach(response => { + const canvas = response.canvas; + if (canvas && canvas.id !== undefined) { + labelCache.canvasLabels[canvas.id.toString()] = getValue(canvas.label); + } + }); + } + + return { manifestLabels: labelCache.manifestLabels, canvasLabels: labelCache.canvasLabels }; +} export const projectCsvSimpleExport: ExportConfig = { type: 'project-csv-simple-export', @@ -47,14 +80,15 @@ export const projectCsvSimpleExport: ExportConfig = { subject: SupportedExportResource, options: ExportDataOptions ): Promise { - // This will probably be a pretty long-running task. - const allPublished = await options.api.getProjectFieldsRaw(subject.id, { status: options.config.reviews ? 'all' : 'approved', entity: options.config.entity, }); const rowRecord: Record = {}; + const manifestIds: number[] = []; + const canvasIds: number[] = []; + for (const item of allPublished) { rowRecord[item.doc_id] = rowRecord[item.doc_id] || { target: item.target, @@ -69,8 +103,18 @@ export const projectCsvSimpleExport: ExportConfig = { rowRecord[item.doc_id][item.key] = rowRecord[item.doc_id][item.key] || []; rowRecord[item.doc_id][item.key].push({ value: item.value, id: item.id, revises: item.revises }); + + const target = parseModelTarget(item.target); + if (target.manifest && target.manifest.id !== undefined) { + manifestIds.push(target.manifest.id); + } + if (target.canvas && target.canvas.id !== undefined) { + canvasIds.push(target.canvas.id); + } } + const { manifestLabels, canvasLabels } = await fetchLabels(options.api, manifestIds, canvasIds); + function findBest(fields: any[]) { const revises = fields.map(r => r.revises); return fields.filter(r => !revises.includes(r.id)).pop() || fields[0]; @@ -78,10 +122,10 @@ export const projectCsvSimpleExport: ExportConfig = { const mappedList = Object.entries(rowRecord) .map(([key, record]) => { - const newRecord: any = {}; - - newRecord.model_id = record.model_id; - newRecord.doc_id = record.doc_id; + const newRecord: any = { + model_id: record.model_id, + doc_id: record.doc_id, + }; if (record.__fields) { for (const field of record.__fields) { @@ -89,11 +133,13 @@ export const projectCsvSimpleExport: ExportConfig = { } const target = parseModelTarget(record.target); - if (target.manifest) { + if (target.manifest && target.manifest.id !== undefined) { newRecord.manifest = target.manifest.id; + newRecord.manifest_label = manifestLabels[target.manifest.id.toString()]; } - if (target.canvas) { + if (target.canvas && target.canvas.id !== undefined) { newRecord.canvas = target.canvas.id; + newRecord.canvas_label = canvasLabels[target.canvas.id.toString()]; } return newRecord; } diff --git a/services/madoc-ts/src/frontend/site/features/canvas/CanvasTaskProgress.tsx b/services/madoc-ts/src/frontend/site/features/canvas/CanvasTaskProgress.tsx index 252490774..9acf2bbf2 100644 --- a/services/madoc-ts/src/frontend/site/features/canvas/CanvasTaskProgress.tsx +++ b/services/madoc-ts/src/frontend/site/features/canvas/CanvasTaskProgress.tsx @@ -68,6 +68,11 @@ export const CanvasTaskProgress: React.FC = () => { status: 2, status_text: 'in progress', }); + // mark parent as incomplete + await api.updateRevisionTask(canvasTask.parent_task, { + status: 2, + status_text: 'in progress', + }); await refetch(); } }); diff --git a/services/madoc-ts/translations/en/madoc.json b/services/madoc-ts/translations/en/madoc.json index 48a15f4c0..1b015c4d9 100644 --- a/services/madoc-ts/translations/en/madoc.json +++ b/services/madoc-ts/translations/en/madoc.json @@ -45,6 +45,7 @@ "All contributions": "All contributions", "All locales": "All locales", "All manifests": "All manifests", + "All of the contributions to this Manifest will be deleted": "All of the contributions to this Manifest will be deleted", "All of the contributions to this canvas will be deleted": "All of the contributions to this canvas will be deleted", "All of your work on these images will be lost if you continue and you will be taken back to the project homepage": "All of your work on these images will be lost if you continue and you will be taken back to the project homepage", "All projects": "All projects", @@ -218,6 +219,7 @@ "Continue where you left off?": "Continue where you left off?", "Continue working": "Continue working", "Contribute": "Contribute", + "Contribute to another manifest": "Contribute to another manifest", "Contribute to random canvas": "Contribute to random canvas", "Contribute to the next image": "Contribute to the next image", "Contribution Panel": "Contribution Panel", @@ -517,6 +519,8 @@ "Importing canvases": "Importing canvases", "In progress": "In progress", "In review": "In review", + "Include reviews": "Include reviews", + "Include submissions being reviewed in the export.": "Include submissions being reviewed in the export.", "Indexing resource into search": "Indexing resource into search", "Inline label": "Inline label", "Installation title": "Installation title", @@ -694,6 +698,7 @@ "Panel alignment": "Panel alignment", "Part of this page crashed": "Part of this page crashed", "Password": "Password", + "Paste Measurement Id ": "Paste Measurement Id ", "Pending": "Pending", "Permissions": "Permissions", "Personal notes": "Personal notes", @@ -880,6 +885,7 @@ "Structure": "Structure", "Style": "Style", "Submission approvals required": "Submission approvals required", + "Submission filter": "Submission filter", "Submission process": "Submission process", "Submit": "Submit", "Submit feedback": "Submit feedback",