class JobResultList extends RessourceList {
static options = {
item: `
|
|
file_download
|
`.trim(),
ressourceMapper: jobResult => {
return {
'id': jobResult.id,
'creation-date': jobResult.creation_date,
'description': jobResult.description,
'filename': jobResult.filename
};
},
sortValueName: 'creation-date',
valueNames: [
{data: ['id']},
{data: ['creation-date']},
'description',
'filename'
]
};
constructor(listElement, options = {}) {
super(listElement, {...JobResultList.options, ...options});
this.jobId = listElement.dataset.jobId;
}
init(user) {
super._init(user.jobs[this.jobId].results);
}
onclick(event) {
let action;
let actionButtonElement;
let jobResultElement;
let jobResultId;
jobResultElement = event.target.closest('tr[data-id]');
if (jobResultElement === null) {return;}
jobResultId = jobResultElement.dataset.id;
actionButtonElement = event.target.closest('.action-button[data-action]');
if (actionButtonElement === null) {return;}
action = actionButtonElement.dataset.action;
switch (action) {
case 'download':
window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`;
break;
default:
break;
}
}
onPATCH(patch) {
if (!this.isInitialized) {return;}
let filteredPatch;
let operation;
let re;
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/results/([A-Za-z0-9]*)`);
filteredPatch = patch.filter(operation => re.test(operation.path));
for (operation of filteredPatch) {
switch(operation.op) {
case 'add':
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/results/([A-Za-z0-9]*)$`);
if (re.test(operation.path)) {
this.add(operation.value);
}
break;
default:
break;
}
}
}
}