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

83 lines
2.3 KiB
JavaScript

class JobResultList extends RessourceList {
static options = {
item: `
<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;
}
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;
}
}
}
}