2021-01-11 12:36:45 +00:00
|
|
|
class JobResultList extends RessourceList {
|
2021-12-02 15:25:48 +00:00
|
|
|
static options = {
|
|
|
|
item: `
|
2021-12-08 10:25:52 +00:00
|
|
|
<tr class="hoverable">
|
2021-12-02 15:25:48 +00:00
|
|
|
<td><span class="description"></span></td>
|
|
|
|
<td><span class="filename"></span></td>
|
|
|
|
<td class="right-align">
|
|
|
|
<a class="action-button btn-floating tooltipped waves-effect waves-light" data-action="download" data-position="top" data-tooltip="View"><i class="material-icons">file_download</i></a>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.trim(),
|
2021-12-03 11:01:50 +00:00
|
|
|
ressourceMapper: jobResult => {
|
|
|
|
return {
|
|
|
|
id: jobResult.id,
|
|
|
|
creationDate: jobResult.creation_date,
|
2022-02-03 11:39:16 +00:00
|
|
|
description: jobResult.description,
|
2021-12-03 11:01:50 +00:00
|
|
|
filename: jobResult.filename
|
|
|
|
};
|
|
|
|
},
|
|
|
|
sortValueName: 'creationDate',
|
|
|
|
valueNames: [
|
|
|
|
{data: ['id']},
|
|
|
|
{data: ['creationDate']},
|
|
|
|
'description',
|
|
|
|
'filename'
|
|
|
|
]
|
2021-12-02 15:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-11 12:36:45 +00:00
|
|
|
constructor(listElement, options = {}) {
|
|
|
|
super(listElement, {...JobResultList.options, ...options});
|
2021-02-01 08:57:10 +00:00
|
|
|
this.jobId = listElement.dataset.jobId;
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
init(user) {
|
|
|
|
super._init(user.jobs[this.jobId].results);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onclick(event) {
|
2021-12-01 13:15:20 +00:00
|
|
|
let action;
|
|
|
|
let actionButtonElement;
|
|
|
|
let jobResultElement;
|
|
|
|
let jobResultId;
|
|
|
|
|
|
|
|
jobResultElement = event.target.closest('tr[data-id]');
|
2021-11-30 15:22:16 +00:00
|
|
|
if (jobResultElement === null) {return;}
|
2021-12-01 13:15:20 +00:00
|
|
|
jobResultId = jobResultElement.dataset.id;
|
|
|
|
actionButtonElement = event.target.closest('.action-button[data-action]');
|
2021-01-11 12:36:45 +00:00
|
|
|
if (actionButtonElement === null) {return;}
|
2021-12-01 13:15:20 +00:00
|
|
|
action = actionButtonElement.dataset.action;
|
2021-01-11 12:36:45 +00:00
|
|
|
switch (action) {
|
|
|
|
case 'download':
|
2021-12-08 13:45:15 +00:00
|
|
|
window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`;
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
usersPatchHandler(patch) {
|
2021-12-01 13:15:20 +00:00
|
|
|
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) {
|
2021-01-11 12:36:45 +00:00
|
|
|
switch(operation.op) {
|
|
|
|
case 'add':
|
2021-11-30 15:22:16 +00:00
|
|
|
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/results/([A-Za-z0-9]*)$`);
|
2021-12-01 13:15:20 +00:00
|
|
|
if (re.test(operation.path)) {
|
|
|
|
this.add(operation.value);
|
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|