class JobResultList extends RessourceList { static autoInit() { for (let jobResultListElement of document.querySelectorAll('.job-result-list:not(.no-autoinit)')) { new JobResultList(jobResultListElement); } } static options = { listContainerInnerHTMLGenerator: (listContainerElement) => { listContainerElement.innerHTML = `
search
Description Filename
`.trim(); }, ressourceMapper: (jobResult) => { return { 'id': jobResult.id, 'creation-date': jobResult.creation_date, 'description': jobResult.description, 'filename': jobResult.filename }; }, sortParams: ['filename', {order: 'asc'}], listjs: { item: ` file_download `.trim(), valueNames: [ {data: ['id']}, {data: ['creation-date']}, 'description', 'filename' ] } }; constructor(listContainerElement, options = {}) { super(listContainerElement, {...JobResultList.options, ...options}); this.jobId = listContainerElement.dataset.jobId; } init(user) { super._init(user.jobs[this.jobId].results); } onClick(event) { let jobResultElement = event.target.closest('tr'); if (jobResultElement === null) {return;} let jobResultId = jobResultElement.dataset.id; if (jobResultId === undefined) {return;} let actionButtonElement = event.target.closest('.action-button'); let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action; switch (action) { case 'download': { window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`; break; } default: { break; } } } 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) { switch(operation.op) { 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);} break; } default: { break; } } } } }