2019-08-20 09:24:52 +00:00
|
|
|
class JobList extends List {
|
2020-01-13 14:33:05 +00:00
|
|
|
constructor(idOrElement, subscriberList, options={}) {
|
|
|
|
super(idOrElement, {...JobList.DEFAULT_OPTIONS, ...options});
|
2019-09-18 09:32:35 +00:00
|
|
|
subscriberList.push(this);
|
2019-08-23 13:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-18 09:32:35 +00:00
|
|
|
_init(jobs) {
|
2019-08-30 11:31:00 +00:00
|
|
|
for (let [id, job] of Object.entries(jobs)) {
|
|
|
|
this.addJob(job);
|
2019-08-28 15:31:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 14:33:05 +00:00
|
|
|
this.update();
|
2019-08-20 09:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-30 11:31:00 +00:00
|
|
|
_update(patch) {
|
2020-01-15 09:52:51 +00:00
|
|
|
let item, jobStatusElement, operation, pathArray;
|
2019-08-30 11:31:00 +00:00
|
|
|
|
|
|
|
for (operation of patch) {
|
2019-09-02 07:17:13 +00:00
|
|
|
/* "/jobId/valueName" -> ["jobId", "valueName"] */
|
2019-08-30 11:31:00 +00:00
|
|
|
pathArray = operation.path.split("/").slice(1);
|
|
|
|
switch(operation.op) {
|
|
|
|
case "add":
|
2019-11-18 10:21:40 +00:00
|
|
|
if (pathArray.includes("results")) {break;}
|
2019-08-30 11:31:00 +00:00
|
|
|
this.addJob(operation.value);
|
2019-08-30 12:00:08 +00:00
|
|
|
this.update();
|
2019-08-30 11:31:00 +00:00
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
this.remove("id", pathArray[0]);
|
|
|
|
break;
|
|
|
|
case "replace":
|
|
|
|
item = this.get("id", pathArray[0])[0];
|
2019-09-02 13:24:09 +00:00
|
|
|
switch(pathArray[1]) {
|
2019-08-30 11:31:00 +00:00
|
|
|
case "status":
|
|
|
|
jobStatusElement = item.elm.querySelector(".status");
|
2020-01-15 09:52:51 +00:00
|
|
|
jobStatusElement.classList.remove(...Object.values(JobList.STATUS_COLORS));
|
|
|
|
jobStatusElement.classList.add(JobList.STATUS_COLORS[operation.value] || JobList.STATUS_COLORS['default']);
|
2019-08-30 11:31:00 +00:00
|
|
|
jobStatusElement.innerHTML = operation.value;
|
2020-01-16 14:04:12 +00:00
|
|
|
item.values({status: operation.value});
|
2019-08-30 12:00:08 +00:00
|
|
|
break;
|
2019-08-30 11:31:00 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
addJob(job) {
|
2020-01-15 09:52:51 +00:00
|
|
|
let rowElement, columnElement, serviceElement, serviceIconElement, titleElement, descriptionElement, statusElement, viewElement, viewIconElement;
|
2019-08-20 09:24:52 +00:00
|
|
|
|
2020-01-15 09:52:51 +00:00
|
|
|
// Create a row elment, where all related information get stored
|
|
|
|
rowElement = document.createElement("tr");
|
|
|
|
rowElement.dataset.id = job.id;
|
2019-08-20 09:24:52 +00:00
|
|
|
|
2020-01-15 09:52:51 +00:00
|
|
|
// Create a column containing a service type identifying icon
|
|
|
|
columnElement = document.createElement("td");
|
|
|
|
serviceElement = document.createElement("a");
|
|
|
|
serviceElement.classList.add("btn-floating", "disabled");
|
|
|
|
serviceIconElement = document.createElement("i");
|
|
|
|
serviceIconElement.classList.add("material-icons");
|
|
|
|
serviceIconElement.innerText = JobList.SERVICE_ICONS[job.service] || JobList.SERVICE_ICONS['default'];
|
|
|
|
serviceElement.appendChild(serviceIconElement);
|
|
|
|
columnElement.appendChild(serviceElement);
|
|
|
|
rowElement.appendChild(columnElement);
|
2019-08-20 09:24:52 +00:00
|
|
|
|
2020-01-15 09:52:51 +00:00
|
|
|
// Create a column containing the title and description
|
|
|
|
columnElement = document.createElement("td");
|
|
|
|
titleElement = document.createElement("b");
|
|
|
|
titleElement.classList.add("title");
|
|
|
|
titleElement.innerText = job.title;
|
|
|
|
descriptionElement = document.createElement("i");
|
|
|
|
descriptionElement.classList.add("description");
|
|
|
|
descriptionElement.innerText = job.description;
|
|
|
|
columnElement.appendChild(titleElement);
|
|
|
|
columnElement.appendChild(document.createElement("br"));
|
|
|
|
columnElement.appendChild(descriptionElement);
|
|
|
|
rowElement.appendChild(columnElement);
|
|
|
|
|
|
|
|
// Create a column containing the current status
|
|
|
|
columnElement = document.createElement("td");
|
|
|
|
statusElement = document.createElement("span");
|
|
|
|
statusElement.classList.add("badge", "new", "status", JobList.STATUS_COLORS[job.status] || JobList.STATUS_COLORS['default']);
|
|
|
|
statusElement.dataset.badgeCaption = "";
|
|
|
|
statusElement.innerText = job.status;
|
|
|
|
columnElement.appendChild(statusElement);
|
|
|
|
rowElement.appendChild(columnElement);
|
|
|
|
|
|
|
|
// Create a column containing a button leading to a details page
|
|
|
|
columnElement = document.createElement("td");
|
|
|
|
columnElement.classList.add("right-align");
|
|
|
|
viewElement = document.createElement("a");
|
|
|
|
viewElement.classList.add("waves-effect", "waves-light", "btn-small");
|
|
|
|
viewElement.href = `/jobs/${job.id}`;
|
|
|
|
viewElement.innerText = "View ";
|
|
|
|
viewIconElement = document.createElement("i");
|
|
|
|
viewIconElement.classList.add("material-icons", "right");
|
|
|
|
viewIconElement.innerText = "send";
|
|
|
|
viewElement.appendChild(viewIconElement);
|
|
|
|
columnElement.appendChild(viewElement);
|
|
|
|
rowElement.appendChild(columnElement);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an entry to the List.js datastructure and immediatly replace the
|
|
|
|
* generic DOM element with our own one created above.
|
|
|
|
*/
|
2020-01-16 14:04:12 +00:00
|
|
|
this.add([{description: job.description, id: job.id,
|
|
|
|
service: `/service=${job.service}`, status: job.status,
|
|
|
|
title: job.title}],
|
2020-01-15 09:52:51 +00:00
|
|
|
function(items) {items[0].elm = rowElement;});
|
2019-08-20 09:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-16 14:04:12 +00:00
|
|
|
JobList.DEFAULT_OPTIONS = {item: `<tr>
|
|
|
|
<td class="description"></td>
|
|
|
|
<td class="service"></td>
|
|
|
|
<td class="status"></td>
|
|
|
|
<td class="title"></td>
|
|
|
|
</tr>`,
|
2020-01-13 14:33:05 +00:00
|
|
|
page: 4,
|
|
|
|
pagination: {innerWindow: 8, outerWindow: 1},
|
2020-01-16 14:04:12 +00:00
|
|
|
valueNames: ["description", "service", "status", "title", {data: ["id"]}]};
|
2020-01-08 09:18:15 +00:00
|
|
|
JobList.SERVICE_ICONS = {"merge_images": "burst_mode",
|
|
|
|
"nlp": "format_textdirection_l_to_r",
|
2019-08-20 09:24:52 +00:00
|
|
|
"ocr": "find_in_page",
|
|
|
|
"default": "help"};
|
2019-11-05 14:22:25 +00:00
|
|
|
JobList.STATUS_COLORS = {"submitted": "blue",
|
|
|
|
"preparing": "light-blue",
|
|
|
|
"pending": "orange",
|
|
|
|
"running": "amber",
|
|
|
|
"complete": "green",
|
|
|
|
"stopping": "orange",
|
|
|
|
"removing": "deep-orange",
|
2019-08-20 09:24:52 +00:00
|
|
|
"default": "red"};
|