Skip to content

Improvment/mad 1420 labels to csv #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, string>; canvasLabels: Record<string, string> } = {
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',
Expand Down Expand Up @@ -47,14 +80,15 @@ export const projectCsvSimpleExport: ExportConfig = {
subject: SupportedExportResource,
options: ExportDataOptions<any>
): Promise<ExportFileDefinition[] | undefined> {
// 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<string, any> = {};
const manifestIds: number[] = [];
const canvasIds: number[] = [];

for (const item of allPublished) {
rowRecord[item.doc_id] = rowRecord[item.doc_id] || {
target: item.target,
Expand All @@ -69,31 +103,43 @@ 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];
}

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) {
newRecord[field] = findBest(record[field])?.value;
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
6 changes: 6 additions & 0 deletions services/madoc-ts/translations/en/madoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading