Web: Cleanup, abstract some code away into separate functions
No functional changes, just preparation for adding similar job actions.
This commit is contained in:
parent
2e2184df62
commit
698db0bf7c
@ -19,25 +19,23 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onButtonDelete() {
|
onButtonDelete() {
|
||||||
const numJobs = this.jobs.numSelected;
|
return this._handleJobActionPromise(
|
||||||
this.jobs.deleteJobs()
|
this.jobs.deleteJobs(), "marked for deletion");
|
||||||
.then(() => {
|
|
||||||
this.notifs.add(`${numJobs} jobs marked for deletion`);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
const errorMsg = JSON.stringify(error); // TODO: handle API errors better.
|
|
||||||
this.notifs.add(`Error: ${errorMsg}`);
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
onButtonCancel() {
|
onButtonCancel() {
|
||||||
|
return this._handleJobActionPromise(
|
||||||
|
this.jobs.cancelJobs(), "marked for cancellation");
|
||||||
|
},
|
||||||
|
|
||||||
|
_handleJobActionPromise(promise, description) {
|
||||||
const numJobs = this.jobs.numSelected;
|
const numJobs = this.jobs.numSelected;
|
||||||
this.jobs.cancelJobs()
|
return promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
let message;
|
let message;
|
||||||
if (numJobs == 1) {
|
if (numJobs == 1) {
|
||||||
message = `Job marked for cancellation`;
|
message = `Job ${description}`;
|
||||||
} else {
|
} else {
|
||||||
message = `${numJobs} jobs marked for cancellation`;
|
message = `${numJobs} jobs ${description}`;
|
||||||
}
|
}
|
||||||
this.notifs.add(message);
|
this.notifs.add(message);
|
||||||
})
|
})
|
||||||
|
@ -55,14 +55,27 @@ export const useJobs = defineStore('jobs', {
|
|||||||
});
|
});
|
||||||
return deletionPromise;
|
return deletionPromise;
|
||||||
},
|
},
|
||||||
cancelJobs() {
|
cancelJobs() { return this._setJobStatus("cancel-requested"); },
|
||||||
const statuschange = new API.JobStatusChange("cancel-requested", "requested from web interface");
|
|
||||||
return jobsAPI.setJobStatus(this.activeJob.id, statuschange);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string[]} statuses
|
||||||
|
* @returns bool indicating whether there is a selected job with any of the given statuses.
|
||||||
|
*/
|
||||||
_anyJobWithStatus(statuses) {
|
_anyJobWithStatus(statuses) {
|
||||||
return this.selectedJobs.reduce((foundJob, job) => (foundJob || statuses.includes(job.status)), false);
|
return this.selectedJobs.reduce((foundJob, job) => (foundJob || statuses.includes(job.status)), false);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transition the selected job(s) to the new status.
|
||||||
|
* @param {string} newStatus
|
||||||
|
* @returns a Promise for the API request.
|
||||||
|
*/
|
||||||
|
_setJobStatus(newStatus) {
|
||||||
|
const statuschange = new API.JobStatusChange(newStatus, "requested from web interface");
|
||||||
|
return jobsAPI.setJobStatus(this.activeJob.id, statuschange);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user