2023-10-05 12:11:17 +00:00
|
|
|
ResourceDisplays.JobDisplay = class JobDisplay extends ResourceDisplays.BaseDisplay {
|
2023-10-09 12:21:31 +00:00
|
|
|
static htmlClass = 'job-display';
|
|
|
|
|
2021-01-11 12:36:45 +00:00
|
|
|
constructor(displayElement) {
|
|
|
|
super(displayElement);
|
2021-11-30 15:22:16 +00:00
|
|
|
this.jobId = this.displayElement.dataset.jobId;
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
init(user) {
|
2022-09-02 11:07:30 +00:00
|
|
|
let 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-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
onPatch(patch) {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}`);
|
|
|
|
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
|
|
|
for (let operation of filteredPatch) {
|
2021-01-11 12:36:45 +00:00
|
|
|
switch(operation.op) {
|
2022-09-02 11:07:30 +00:00
|
|
|
case 'remove': {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}$`);
|
|
|
|
if (re.test(operation.path)) {
|
|
|
|
window.location.href = '/dashboard#jobs';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'replace': {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/end_date$`);
|
2021-11-30 15:22:16 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
|
|
|
default: {
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTitle(title) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(this.displayElement.querySelectorAll('.job-title'), title);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setDescription(description) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(this.displayElement.querySelectorAll('.job-description'), description);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setStatus(status) {
|
2022-09-02 11:07:30 +00:00
|
|
|
let elements = this.displayElement.querySelectorAll('.job-status');
|
|
|
|
for (let element of elements) {
|
2023-01-10 09:01:54 +00:00
|
|
|
element.dataset.status = status;
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
2022-02-08 11:26:20 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.job-status-spinner');
|
2022-09-02 11:07:30 +00:00
|
|
|
for (let element of elements) {
|
2022-02-08 11:26:20 +00:00
|
|
|
if (['COMPLETED', 'FAILED'].includes(status)) {
|
2021-01-11 12:36:45 +00:00
|
|
|
element.classList.add('hide');
|
|
|
|
} else {
|
|
|
|
element.classList.remove('hide');
|
|
|
|
}
|
|
|
|
}
|
2022-06-28 10:30:02 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.job-log-trigger');
|
2022-09-02 11:07:30 +00:00
|
|
|
for (let element of elements) {
|
2022-06-28 10:30:02 +00:00
|
|
|
if (['COMPLETED', 'FAILED'].includes(status)) {
|
|
|
|
element.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
element.classList.add('hide');
|
|
|
|
}
|
|
|
|
}
|
2022-09-02 11:07:30 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.action-button[data-action="get-log-request"]');
|
|
|
|
for (let element of elements) {
|
2022-02-08 11:26:20 +00:00
|
|
|
if (['COMPLETED', 'FAILED'].includes(status)) {
|
2022-09-02 11:07:30 +00:00
|
|
|
element.classList.remove('disabled');
|
2021-01-11 12:36:45 +00:00
|
|
|
} else {
|
2022-09-02 11:07:30 +00:00
|
|
|
element.classList.add('disabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elements = this.displayElement.querySelectorAll('.action-button[data-action="restart-request"]');
|
|
|
|
for (let element of elements) {
|
|
|
|
if (status === 'FAILED') {
|
|
|
|
element.classList.remove('disabled');
|
|
|
|
} else {
|
|
|
|
element.classList.add('disabled');
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
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')
|
|
|
|
);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setService(service) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(this.displayElement.querySelectorAll('.job-service'), service);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setServiceArgs(serviceArgs) {
|
2022-02-03 11:39:16 +00:00
|
|
|
this.setElements(
|
|
|
|
this.displayElement.querySelectorAll('.job-service-args'),
|
|
|
|
JSON.stringify(serviceArgs)
|
|
|
|
);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setServiceVersion(serviceVersion) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(this.displayElement.querySelectorAll('.job-service-version'), serviceVersion);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
2023-10-05 14:08:04 +00:00
|
|
|
};
|