2021-01-11 12:36:45 +00:00
|
|
|
class JobResultList extends RessourceList {
|
2022-09-02 11:07:30 +00:00
|
|
|
static autoInit() {
|
|
|
|
for (let jobResultListElement of document.querySelectorAll('.job-result-list:not(.no-autoinit)')) {
|
|
|
|
new JobResultList(jobResultListElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 15:25:48 +00:00
|
|
|
static options = {
|
2022-09-02 11:07:30 +00:00
|
|
|
initialHtmlGenerator: (id) => {
|
|
|
|
return `
|
|
|
|
<div class="input-field">
|
|
|
|
<i class="material-icons prefix">search</i>
|
|
|
|
<input id="${id}-search" class="search" type="search"></input>
|
|
|
|
<label for="${id}-search">Search job result</label>
|
|
|
|
</div>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Filename</th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="list"></tbody>
|
|
|
|
</table>
|
|
|
|
<ul class="pagination"></ul>
|
|
|
|
`.trim();
|
|
|
|
},
|
2021-12-02 15:25:48 +00:00
|
|
|
item: `
|
2022-09-02 11:07:30 +00:00
|
|
|
<tr class="clickable 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">
|
2022-09-02 11:07:30 +00:00
|
|
|
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
|
2021-12-02 15:25:48 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.trim(),
|
2022-09-02 11:07:30 +00:00
|
|
|
ressourceMapper: (jobResult) => {
|
2021-12-03 11:01:50 +00:00
|
|
|
return {
|
2022-02-08 11:26:20 +00:00
|
|
|
'id': jobResult.id,
|
|
|
|
'creation-date': jobResult.creation_date,
|
|
|
|
'description': jobResult.description,
|
|
|
|
'filename': jobResult.filename
|
2021-12-03 11:01:50 +00:00
|
|
|
};
|
|
|
|
},
|
2022-09-02 11:07:30 +00:00
|
|
|
sortArgs: ['filename', {order: 'asc'}],
|
2021-12-03 11:01:50 +00:00
|
|
|
valueNames: [
|
|
|
|
{data: ['id']},
|
2022-02-08 11:26:20 +00:00
|
|
|
{data: ['creation-date']},
|
2021-12-03 11:01:50 +00:00
|
|
|
'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
|
|
|
}
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
onClick(event) {
|
|
|
|
let actionButtonElement = event.target.closest('.action-button');
|
|
|
|
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
|
|
|
|
let jobResultElement = event.target.closest('tr');
|
|
|
|
let jobResultId = jobResultElement.dataset.id;
|
2021-01-11 12:36:45 +00:00
|
|
|
switch (action) {
|
2022-09-02 11:07:30 +00:00
|
|
|
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;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
|
|
|
default: {
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
onPatch(patch) {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/results/([A-Za-z0-9]*)`);
|
|
|
|
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
|
|
|
for (let operation of filteredPatch) {
|
2021-01-11 12:36:45 +00:00
|
|
|
switch(operation.op) {
|
2022-09-02 11:07:30 +00:00
|
|
|
case 'add': {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/results/([A-Za-z0-9]*)$`);
|
|
|
|
if (re.test(operation.path)) {this.add(operation.value);}
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
|
|
|
default: {
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|