nopaque.resource_lists.JobOutputList = class JobOutputList extends nopaque.resource_lists.ResourceList {
static htmlClass = 'job-output-list';
constructor(listContainerElement, options = {}) {
super(listContainerElement, options);
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
this.isInitialized = false;
this.userId = listContainerElement.dataset.userId;
this.jobOutput = listContainerElement.dataset.jobOutput;
this.jobIds = listContainerElement.dataset.jobIds;
if (this.userId === undefined) {return;}
app.subscribeUser(this.userId).then((response) => {
app.socket.on('PATCH', (patch) => {
if (this.isInitialized) {this.onPatch(patch);}
});
});
app.getUser(this.userId).then((user) => {
let jobIds = JSON.parse(this.jobIds.replace(/'/g, '"'));
let job_results = {};
for (let jobId of jobIds) {
for (let jobResult of Object.values(user.jobs[jobId].results)) {
if (jobResult.mimetype === 'application/pdf') {
job_results[jobResult.id] = jobResult;
job_results[jobResult.id].description = user.jobs[jobId].description;
job_results[jobResult.id].title = user.jobs[jobId].title;
}
}
}
this.add(Object.values(job_results));
this.isInitialized = true;
});
}
get item() {
return `
|
|
|
add
|
`.trim();
}
get valueNames() {
return [
{data: ['id']},
{data: ['creation-date']},
'title',
'description',
'filename'
];
}
initListContainerElement() {
if (!this.listContainerElement.hasAttribute('id')) {
this.listContainerElement.id = nopaque.Utils.generateElementId('job-output-list-');
}
let listSearchElementId = nopaque.Utils.generateElementId(`${this.listContainerElement.id}-search-`);
this.listContainerElement.innerHTML = `
search
Title |
Description |
Filename |
|
`;
}
mapResourceToValue(jobOutput) {
console.log(jobOutput);
return {
'id': jobOutput.id,
'creation-date': jobOutput.creationDate,
'title': jobOutput.title,
'description': jobOutput.description,
'filename': jobOutput.filename
};
}
sort() {
this.listjs.sort('title', {order: 'asc'});
}
onClick(event) {
let listItemElement = event.target.closest('.list-item[data-id]');
if (listItemElement === null) {return;}
let itemId = listItemElement.dataset.id;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'add' : listActionElement.dataset.listAction;
switch (listAction) {
case 'add': {
listActionElement.querySelector('i').textContent = 'done';
listActionElement.dataset.listAction = 'remove';
break;
}
case 'remove': {
listActionElement.querySelector('i').textContent = 'add';
listActionElement.dataset.listAction = 'add';
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;
// }
// }
// }
// }
};