mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-27 11:54:19 +00:00
111 lines
3.0 KiB
JavaScript
111 lines
3.0 KiB
JavaScript
class JobDisplay extends RessourceDisplay {
|
|
constructor(displayElement) {
|
|
super(displayElement);
|
|
this.jobId = this.displayElement.dataset.jobId;
|
|
}
|
|
|
|
init(user) {
|
|
let job;
|
|
|
|
job = user.jobs[this.jobId];
|
|
this.setCreationDate(job.creation_date);
|
|
this.setEndDate(job.creation_date);
|
|
this.setDescription(job.description);
|
|
this.setService(job.service);
|
|
this.setServiceArgs(job.service_args);
|
|
this.setServiceVersion(job.service_version);
|
|
this.setStatus(job.status);
|
|
this.setTitle(job.title);
|
|
}
|
|
|
|
usersPatchHandler(patch) {
|
|
let filteredPatch;
|
|
let operation;
|
|
let re;
|
|
|
|
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}`);
|
|
filteredPatch = patch.filter(operation => re.test(operation.path));
|
|
for (operation of filteredPatch) {
|
|
switch(operation.op) {
|
|
case 'replace':
|
|
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/end_date$`);
|
|
if (re.test(operation.path)) {
|
|
this.setEndDate(operation.value);
|
|
break;
|
|
}
|
|
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/status$`);
|
|
if (re.test(operation.path)) {
|
|
this.setStatus(operation.value);
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
setTitle(title) {
|
|
this.setElements(this.displayElement.querySelectorAll('.job-title'), title);
|
|
}
|
|
|
|
setDescription(description) {
|
|
this.setElements(this.displayElement.querySelectorAll('.job-description'), description);
|
|
}
|
|
|
|
setStatus(status) {
|
|
let element;
|
|
let elements;
|
|
|
|
elements = this.displayElement.querySelectorAll('.job-status');
|
|
for (element of elements) {
|
|
element.dataset.jobStatus = status;
|
|
}
|
|
elements = this.displayElement.querySelectorAll('.job-status-spinner');
|
|
for (element of elements) {
|
|
if (['COMPLETED', 'FAILED'].includes(status)) {
|
|
element.classList.add('hide');
|
|
} else {
|
|
element.classList.remove('hide');
|
|
}
|
|
}
|
|
elements = this.displayElement.querySelectorAll('.job-restart-trigger');
|
|
for (element of elements) {
|
|
if (['COMPLETED', 'FAILED'].includes(status)) {
|
|
element.classList.remove('hide');
|
|
} else {
|
|
element.classList.add('hide');
|
|
}
|
|
}
|
|
}
|
|
|
|
setCreationDate(creationDate) {
|
|
this.setElements(
|
|
this.displayElement.querySelectorAll('.job-creation-date'),
|
|
new Date(creationDate).toLocaleString('en-US')
|
|
);
|
|
}
|
|
|
|
setEndDate(endDate) {
|
|
this.setElements(
|
|
this.displayElement.querySelectorAll('.job-end-date'),
|
|
new Date(endDate).toLocaleString('en-US')
|
|
);
|
|
}
|
|
|
|
setService(service) {
|
|
this.setElements(this.displayElement.querySelectorAll('.job-service'), service);
|
|
}
|
|
|
|
setServiceArgs(serviceArgs) {
|
|
this.setElements(
|
|
this.displayElement.querySelectorAll('.job-service-args'),
|
|
JSON.stringify(serviceArgs)
|
|
);
|
|
}
|
|
|
|
setServiceVersion(serviceVersion) {
|
|
this.setElements(this.displayElement.querySelectorAll('.job-service-version'), serviceVersion);
|
|
}
|
|
}
|