Skip to content

Commit bde81a8

Browse files
committed
Fix confirmation dialogs to make more sense for UDP #381
1 parent c00dbb5 commit bde81a8

3 files changed

Lines changed: 43 additions & 18 deletions

File tree

src/components/JobPanel.vue

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ export default {
162162
await this.refreshElement(job, updatedJob => this.broadcast('editProcess', updatedJob));
163163
},
164164
async startAndQueueProcess(options) {
165-
const job = await this.createJob(this.process, options);
166-
await this.queueJob(job);
165+
await this.createJob(this.process, options, true);
167166
},
168167
async executeProcessWithOptions() {
169168
const fields = [
@@ -201,20 +200,34 @@ export default {
201200
}
202201
}
203202
},
204-
jobCreated(job) {
203+
jobAfterCreation(job, queueing = false) {
205204
const buttons = [];
206-
if (this.supports('estimateJob')) {
207-
buttons.push({text: 'Estimate', action: () => this.estimateJob(job)});
208-
}
209-
if (this.supports('startJob')) {
210-
buttons.push({text: 'Start processing', action: () => this.queueJob(job)});
205+
if (job.status === 'created' && !queueing) {
206+
if (this.supports('estimateJob') && job.status === 'created') {
207+
buttons.push({text: 'Estimate', action: () => this.estimateJob(job)});
208+
}
209+
if (this.supports('startJob') && job.status === 'created') {
210+
buttons.push({text: 'Start processing', action: () => this.queueJob(job)});
211+
}
212+
} else if (!queueing) {
213+
if (this.supportsRead) {
214+
buttons.push({ text: 'Details', action: () => this.showJobInfo(job) });
215+
}
216+
if (job.status !== 'queued' && this.supportsDebug) { // not when created or queued
217+
buttons.push({text: 'Logs', action: () => this.showLogs(job)});
218+
}
211219
}
212-
if (this.supports('deleteJob')) {
220+
if (this.supports('deleteJob')) { // always
213221
buttons.push({text: 'Delete', action: () => this.deleteJob(job)});
214222
}
215-
Utils.confirm(this, 'Job "' + Utils.getResourceTitle(job) + '" created!', buttons);
223+
const title = Utils.getResourceTitle(job);
224+
let message = `Job "${title}" ${job.status || 'created'}!`;
225+
if (queueing) {
226+
message += ` Queuing for execution...`;
227+
}
228+
Utils.confirm(this, message, buttons);
216229
},
217-
async createJob(process, data) {
230+
async createJob(process, data, queue = false) {
218231
try {
219232
let job = await this.create([
220233
process,
@@ -224,7 +237,10 @@ export default {
224237
data.budget,
225238
data
226239
]);
227-
this.jobCreated(job);
240+
this.jobAfterCreation(job, queue);
241+
if (queue) {
242+
job = await this.queueJob({data: job});
243+
}
228244
return job;
229245
} catch (error) {
230246
Utils.exception(this, error, 'Create Job Error: ' + (data.title || ''));
@@ -357,15 +373,15 @@ export default {
357373
},
358374
async queueJob(job) {
359375
await this.refreshElement(job, async (updatedJob) => {
360-
if (updatedJob.status === 'finished' && !confirm(`The batch job "${Utils.getResourceTitle(updatedJob)}" has already finished with results. Queueing the job again may discard all previous results! Do you really want to queue it again?`)) {
376+
if (updatedJob.status === 'finished' && !confirm(`The batch job "${Utils.getResourceTitle(updatedJob)}" has already finished with results. Queuing the job again may discard all previous results! Do you really want to queue it again?`)) {
361377
return;
362378
}
363379
364380
try {
365-
let updatedJob = await this.queue({data: job});
366-
Utils.ok(this, 'Job "' + Utils.getResourceTitle(updatedJob) + '" successfully queued.');
381+
let updatedJob = await this.queue({data: updatedJob});
382+
this.jobAfterCreation(updatedJob);
367383
} catch(error) {
368-
Utils.exception(this, error, 'Queue Job Error: ' + Utils.getResourceTitle(job));
384+
Utils.exception(this, error, 'Queue Job Error: ' + Utils.getResourceTitle(updatedJob));
369385
}
370386
});
371387
},

src/components/WorkPanelMixin.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ export default (namespace, singular, plural, loadInitially = true) => {
5858
return this.$config.dataRefreshInterval*60*1000; // Refresh data every x minutes
5959
},
6060
async refreshElement(obj, callback = null) {
61-
var old = Object.assign({}, obj);
61+
const old = Object.assign({}, obj);
6262
try {
6363
let updated = await this.read({data: obj});
6464
if (typeof callback === 'function') {
65-
callback(updated, old);
65+
if (updated) {
66+
callback(updated, old);
67+
} else {
68+
Utils.error(this, "Unable to update " + singular + ". Data may be outdated.");
69+
callback(old, old);
70+
}
6671
}
6772
} catch(error) {
6873
Utils.exception(this, error, "Load " + singular + " error");

src/store/storeFactory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export default ({namespace, listFn, paginateFn, createFn, updateFn, deleteFn, re
6363
let updated = null;
6464
if (!(data instanceof UserProcess)) {
6565
let id = Utils.isObject(data) ? data[primaryKey] : data;
66+
if (typeof id === 'undefined' || id === null || id === '') {
67+
console.warn("No id provided:", data);
68+
return null;
69+
}
6670
// Try to get UserProcess from store
6771
data = cx.getters.getById(id);
6872
if (!data) {

0 commit comments

Comments
 (0)