nopaque/app/static/js/RessourceLists/JobInputList.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

class JobInputList extends RessourceList {
2022-09-02 11:07:30 +00:00
static autoInit() {
for (let jobInputListElement of document.querySelectorAll('.job-input-list:not(.no-autoinit)')) {
new JobInputList(jobInputListElement);
}
}
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 input</label>
</div>
<table>
<thead>
<tr>
<th>Filename</th>
<th></th>
</tr>
</thead>
<tbody class="list"></tbody>
</table>
<ul class="pagination"></ul>
`.trim();
},
item: `
2022-09-02 11:07:30 +00:00
<tr class="clickable hoverable">
<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>
</td>
</tr>
`.trim(),
2022-09-02 11:07:30 +00:00
ressourceMapper: (jobInput) => {
return {
'id': jobInput.id,
'creation-date': jobInput.creation_date,
'filename': jobInput.filename
};
},
2022-09-02 11:07:30 +00:00
sortArgs: ['filename', {order: 'asc'}],
valueNames: [
{data: ['id']},
{data: ['creation-date']},
'filename'
]
};
constructor(listElement, options = {}) {
super(listElement, {...JobInputList.options, ...options});
this.jobId = listElement.dataset.jobId;
}
2021-11-30 15:22:16 +00:00
init(user) {
this._init(user.jobs[this.jobId].inputs);
}
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 jobInputElement = event.target.closest('tr');
let jobInputId = jobInputElement.dataset.id;
switch (action) {
2022-09-02 11:07:30 +00:00
case 'download': {
2021-11-30 15:22:16 +00:00
window.location.href = `/jobs/${this.jobId}/inputs/${jobInputId}/download`;
break;
2022-09-02 11:07:30 +00:00
}
default: {
break;
2022-09-02 11:07:30 +00:00
}
}
}
2022-09-02 11:07:30 +00:00
onPatch(patch) {return;}
}