nopaque/app/static/js/resource-lists/job-input-list.js

92 lines
2.9 KiB
JavaScript
Raw Normal View History

nopaque.resource_lists.JobInputList = class JobInputList extends nopaque.resource_lists.ResourceList {
2023-10-11 14:20:17 +00:00
static htmlClass = 'job-input-list';
2023-01-04 19:00:37 +00:00
constructor(listContainerElement, options = {}) {
super(listContainerElement, options);
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
this.isInitialized = false;
this.userId = listContainerElement.dataset.userId;
this.jobId = listContainerElement.dataset.jobId;
2023-02-10 13:51:47 +00:00
if (this.userId === undefined || this.jobId === undefined) {return;}
2024-12-05 13:26:05 +00:00
// app.userHub.addEventListener('patch', (event) => {
2024-12-03 14:59:08 +00:00
// if (this.isInitialized) {this.onPatch(event.detail);}
// });
2024-12-05 13:26:05 +00:00
app.userHub.get(this.userId).then((user) => {
2023-01-04 19:00:37 +00:00
this.add(Object.values(user.jobs[this.jobId].inputs));
this.isInitialized = true;
});
}
get item() {
return `
2023-01-05 14:03:59 +00:00
<tr class="list-item clickable hoverable">
2023-01-04 19:00:37 +00:00
<td><span class="filename"></span></td>
<td class="right-align">
2023-01-05 14:03:59 +00:00
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="download"><i class="material-icons">file_download</i></a>
2023-01-04 19:00:37 +00:00
</td>
</tr>
`.trim();
}
get valueNames() {
return [
{data: ['id']},
{data: ['creation-date']},
'filename'
];
}
initListContainerElement() {
if (!this.listContainerElement.hasAttribute('id')) {
this.listContainerElement.id = nopaque.Utils.generateElementId('job-input-list-');
2023-01-04 19:00:37 +00:00
}
let listSearchElementId = nopaque.Utils.generateElementId(`${this.listContainerElement.id}-search-`);
2023-01-04 19:00:37 +00:00
this.listContainerElement.innerHTML = `
<div class="input-field">
<i class="material-icons prefix">search</i>
<input id="${listSearchElementId}" class="search" type="text"></input>
<label for="${listSearchElementId}">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();
}
2023-01-05 07:11:27 +00:00
2023-01-04 19:00:37 +00:00
mapResourceToValue(jobInput) {
return {
'id': jobInput.id,
'creation-date': jobInput.creation_date,
'filename': jobInput.filename
};
}
sort() {
this.listjs.sort('filename', {order: 'asc'});
}
onClick(event) {
let listItemElement = event.target.closest('.list-item[data-id]');
2023-01-05 14:03:59 +00:00
if (listItemElement === null) {return;}
let itemId = listItemElement.dataset.id;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'download' : listActionElement.dataset.listAction;
2023-01-05 14:03:59 +00:00
switch (listAction) {
2023-01-04 19:00:37 +00:00
case 'download': {
2023-01-05 14:03:59 +00:00
window.location.href = `/jobs/${this.jobId}/inputs/${itemId}/download`;
2023-01-04 19:00:37 +00:00
break;
}
default: {
break;
}
}
}
2023-10-11 14:20:17 +00:00
};