nopaque/app/static/js/RessourceLists/JobResultList.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

class JobResultList extends RessourceList {
static options = {
item: `
2021-12-08 10:25:52 +00:00
<tr class="hoverable">
<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(),
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;
}
2021-11-30 15:22:16 +00:00
init(user) {
super._init(user.jobs[this.jobId].results);
}
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]');
if (actionButtonElement === null) {return;}
2021-12-01 13:15:20 +00:00
action = actionButtonElement.dataset.action;
switch (action) {
case 'download':
window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`;
break;
default:
break;
}
}
2022-07-04 12:09:17 +00:00
onPATCH(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) {
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);
}
break;
default:
break;
}
}
}
}