Skip to content
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

Fix/export zip sims #546

Merged
merged 3 commits into from
Jan 26, 2024
Merged
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
39 changes: 18 additions & 21 deletions app/src/js/remote-api/operations/sims.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
const hasDocument = (sims, withDocument) => {
if(!withDocument){
if (!withDocument) {
return false;
}
// We activate the download of a ZIP with documents only if we have at least on file using the file:// protocol.
const hasDocument = Object.values(sims.rubrics).filter(rubric => {
return rubric.documentsLg1?.find(doc => {
return doc.url.indexOf("file") === 0
})
})?.length > 0
const hasDocument =
Object.values(sims.rubrics).filter((rubric) => {
return rubric.documentsLg1?.find((doc) => {
return doc.url.indexOf('file') === 0;
});
})?.length > 0;

return hasDocument
}
return hasDocument;
};

export default {
getSims: (id) => [`metadataReport/${id}`],
getDefaultSims: () => ['metadataReport/default'],
getOwners: (id) => [`metadataReport/Owner/${id}`],
exportSims: (id, config, sims) => [
`metadataReport/export/${id}?emptyMas=${config.emptyMas}&lg1=${config.lg1}&lg2=${config.lg2}&document=${hasDocument(sims, config.document)}`,
`metadataReport/export/${id}?emptyMas=${config.emptyMas}&lg1=${
config.lg1
}&lg2=${config.lg2}&document=${hasDocument(sims, config.document)}`,
{
method: 'GET',
mode: 'cors',
Expand All @@ -28,26 +31,20 @@ export default {
},
async (res) => {
const blob = await res.blob();
const a = document.createElement("a");
const a = document.createElement('a');
document.body.appendChild(a);

const url = window.URL.createObjectURL(blob);
a.href = url;

if(hasDocument(sims, config.document)){
const header = res.headers.get('Content-Disposition');
const parts = header.split(';');
const fileName = parts[1].split('=')[1]?.replace(/\"/, "");
a.download = fileName + '.zip';
} else {
const fileName = sims.labelLg1?.replace(/[/<>*:?|]/gi, '');
a.download = fileName + '.odt';
}
const header = res.headers.get('Content-Disposition');
const parts = header.split(';');
a.download = parts[1].split('=')[1]?.replaceAll(/\"/g, '');
a.click();
window.URL.revokeObjectURL(url);

if(res.headers.get('X-Missing-Documents')){
return new Set(res.headers.get('X-Missing-Documents').split(','))
if (res.headers.get('X-Missing-Documents')) {
return new Set(res.headers.get('X-Missing-Documents').split(','));
}
return new Set();
},
Expand Down
Loading