nopaque/app/static/js/RessourceDisplays/JobDisplay.js

119 lines
3.3 KiB
JavaScript
Raw Normal View History

class JobDisplay extends RessourceDisplay {
constructor(displayElement) {
super(displayElement);
2021-11-30 15:22:16 +00:00
this.jobId = this.displayElement.dataset.jobId;
}
2021-11-30 15:22:16 +00:00
init(user) {
2021-12-01 13:15:20 +00:00
let job;
job = user.jobs[this.jobId];
2021-11-30 15:22:16 +00:00
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);
}
2021-11-30 15:22:16 +00:00
usersPatchHandler(patch) {
2021-12-01 13:15:20 +00:00
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':
2021-11-30 15:22:16 +00:00
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) {
2021-12-01 13:15:20 +00:00
this.setElements(this.displayElement.querySelectorAll('.job-title'), title);
}
setDescription(description) {
2021-12-01 13:15:20 +00:00
this.setElements(this.displayElement.querySelectorAll('.job-description'), description);
}
setStatus(status) {
2021-12-01 13:15:20 +00:00
let element;
let elements;
elements = this.displayElement.querySelectorAll('.job-status');
2021-12-01 13:15:20 +00:00
for (element of elements) {
element.dataset.jobStatus = status;
}
elements = this.displayElement.querySelectorAll('.job-status-spinner');
2021-12-01 13:15:20 +00:00
for (element of elements) {
if (['COMPLETED', 'FAILED'].includes(status)) {
element.classList.add('hide');
} else {
element.classList.remove('hide');
}
}
elements = this.displayElement.querySelectorAll('.job-log-trigger');
for (element of elements) {
if (['COMPLETED', 'FAILED'].includes(status)) {
element.classList.remove('hide');
} else {
element.classList.add('hide');
}
}
elements = this.displayElement.querySelectorAll('.job-restart-trigger');
2021-12-01 13:15:20 +00:00
for (element of elements) {
if (['COMPLETED', 'FAILED'].includes(status)) {
element.classList.remove('hide');
} else {
element.classList.add('hide');
}
}
}
2021-11-30 15:22:16 +00:00
setCreationDate(creationDate) {
2021-12-01 13:15:20 +00:00
this.setElements(
this.displayElement.querySelectorAll('.job-creation-date'),
new Date(creationDate).toLocaleString('en-US')
);
}
2021-11-30 15:22:16 +00:00
setEndDate(endDate) {
2021-12-01 13:15:20 +00:00
this.setElements(
this.displayElement.querySelectorAll('.job-end-date'),
new Date(endDate).toLocaleString('en-US')
);
}
setService(service) {
2021-12-01 13:15:20 +00:00
this.setElements(this.displayElement.querySelectorAll('.job-service'), service);
}
setServiceArgs(serviceArgs) {
this.setElements(
this.displayElement.querySelectorAll('.job-service-args'),
JSON.stringify(serviceArgs)
);
}
setServiceVersion(serviceVersion) {
2021-12-01 13:15:20 +00:00
this.setElements(this.displayElement.querySelectorAll('.job-service-version'), serviceVersion);
}
}