|
8 | 8 | <button title="Details" @click="showJobInfo(p.row)" v-show="supports('describeJob')"><i class="fas fa-info"></i></button> |
9 | 9 | <button title="Show in Editor" @click="showInEditor(p.row)" v-show="supports('describeJob')"><i class="fas fa-code-branch"></i></button> |
10 | 10 | <button title="Estimate" @click="estimateJob(p.row)" v-show="supports('estimateJob')"><i class="fas fa-file-invoice-dollar"></i></button> |
11 | | - <button title="Update process graph" @click="updateProcessGraph(p.row)" v-show="supports('updateJob') && isJobInactive(p.row)"><i class="fas fa-edit"></i></button> |
| 11 | + <button title="Edit metadata" @click="editMetadata(p.row)" v-show="supports('updateJob') && isJobInactive(p.row)"><i class="fas fa-edit"></i></button> |
| 12 | + <button title="Replace process graph" @click="replaceProcessGraph(p.row)" v-show="supports('updateJob') && isJobInactive(p.row)"><i class="fas fa-retweet"></i></button> |
12 | 13 | <button title="Delete" @click="deleteJob(p.row)" v-show="supports('deleteJob')"><i class="fas fa-trash"></i></button> |
13 | 14 | <button title="Start processing" @click="queueJob(p.row)" v-show="supports('startJob') && isJobInactive(p.row)"><i class="fas fa-play-circle"></i></button> |
14 | 15 | <button title="Cancel processing" @click="cancelJob(p.row)" v-show="supports('stopJob') && isJobActive(p.row)"><i class="fas fa-stop-circle"></i></button> |
|
24 | 25 | import EventBus from '../eventbus.js'; |
25 | 26 | import WorkPanelMixin from './WorkPanelMixin.vue'; |
26 | 27 | import Utils from '../utils.js'; |
| 28 | +import Field from './blocks/field'; |
27 | 29 |
|
28 | 30 | export default { |
29 | 31 | name: 'JobPanel', |
@@ -115,25 +117,51 @@ export default { |
115 | 117 | } |
116 | 118 | Utils.confirm(this, 'Job created!', buttons); |
117 | 119 | }, |
118 | | - createJob(processGraph, title = null) { |
119 | | - this.connection.createJob(processGraph, title) |
| 120 | + getTitleField() { |
| 121 | + return new Field('title', 'Title', {type: 'string'}); |
| 122 | + }, |
| 123 | + getDescriptionField() { |
| 124 | + return new Field('description', 'Description', {type: 'string', format: 'commonmark'}, 'CommonMark (Markdown) is allowed.'); |
| 125 | + }, |
| 126 | + getBillingPlanField() { |
| 127 | + return new Field('plan', 'Billing plan', {type: 'string', format: 'billing-plan'}); |
| 128 | + }, |
| 129 | + getBudgetField() { |
| 130 | + return new Field('budget', 'Budget', {type: 'number', format: 'budget', default: null}); |
| 131 | + }, |
| 132 | + normalizeToDefaultData(data) { |
| 133 | + if (typeof data.title !== 'undefined' && (typeof data.title !== 'string' || data.title.length === 0)) { |
| 134 | + data.title = null; |
| 135 | + } |
| 136 | + if (typeof data.description !== 'undefined' && (typeof data.description !== 'string' || data.description.length === 0)) { |
| 137 | + data.description = null; |
| 138 | + } |
| 139 | + if (typeof data.plan !== 'undefined' && (typeof data.plan !== 'string' || data.plan.length === 0)) { |
| 140 | + data.plan = null; |
| 141 | + } |
| 142 | + if (typeof data.budget !== 'undefined' && (typeof data.budget !== 'number' || data.budget < 0)) { |
| 143 | + data.budget = null; |
| 144 | + } |
| 145 | + return data; |
| 146 | + }, |
| 147 | + createJob(processGraph, data) { |
| 148 | + data = this.normalizeToDefaultData(data); |
| 149 | + this.connection.createJob(processGraph, data.title, data.description, data.plan, data.budget) |
120 | 150 | .then(job => { |
121 | 151 | EventBus.$emit('jobCreated', job); |
122 | 152 | }).catch(error => { |
123 | 153 | Utils.exception(this, error, 'Sorry, could not create a batch job.'); |
124 | 154 | }); |
125 | 155 | }, |
126 | 156 | createJobFromScript() { |
127 | | - var title = prompt("Please specify a title for the job:"); |
128 | | - if (title === null) { |
129 | | - return; |
130 | | - } |
131 | | - else if (typeof title !== 'string' || title.length === 0) { |
132 | | - title = null; |
133 | | - } |
134 | | -
|
135 | 157 | EventBus.$emit('getProcessGraph', script => { |
136 | | - this.createJob(script, title); |
| 158 | + var fields = [ |
| 159 | + this.getTitleField(), |
| 160 | + this.getDescriptionField(), |
| 161 | + this.getBillingPlanField(), |
| 162 | + this.getBudgetField() |
| 163 | + ]; |
| 164 | + EventBus.$emit('showDataForm', "Create new batch job", fields, data => this.createJob(script, data)); |
137 | 165 | }); |
138 | 166 | }, |
139 | 167 | updateJobData(updatedJob) { |
@@ -190,23 +218,33 @@ export default { |
190 | 218 | }) |
191 | 219 | .catch(error => Utils.exception(this, error, "Sorry, could not load job estimate.")); |
192 | 220 | }, |
193 | | - updateProcessGraph(job) { |
| 221 | + replaceProcessGraph(job) { |
194 | 222 | EventBus.$emit('getProcessGraph', script => { |
195 | | - job.updateJob(script) |
196 | | - .then(updatedJob => { |
197 | | - Utils.ok(this, "Job successfully updated."); |
198 | | - this.updateJobData(updatedJob); |
199 | | - }) |
200 | | - .catch(error => Utils.exception(this, error, "Sorry, could not update job."));; |
| 223 | + this.updateJob(job, {processGraph: script}); |
| 224 | + }); |
| 225 | + }, |
| 226 | + editMetadata(oldJob) { |
| 227 | + this.refreshJob(oldJob, job => { |
| 228 | + var fields = [ |
| 229 | + this.getTitleField().setValue(job.title), |
| 230 | + this.getDescriptionField().setValue(job.description), |
| 231 | + this.getBillingPlanField().setValue(job.plan), |
| 232 | + this.getBudgetField().setValue(job.budget) |
| 233 | + ]; |
| 234 | + EventBus.$emit('showDataForm', "Edit batch job", fields, data => this.updateJob(job, data)); |
201 | 235 | }); |
202 | 236 | }, |
203 | 237 | updateTitle(job, newTitle) { |
204 | | - job.updateJob({title: newTitle}) |
| 238 | + this.updateJob(job, {title: newTitle}); |
| 239 | + }, |
| 240 | + updateJob(job, data) { |
| 241 | + data = this.normalizeToDefaultData(data); |
| 242 | + job.updateJob(data) |
205 | 243 | .then(updatedJob => { |
206 | | - Utils.ok(this, "Job title successfully updated."); |
| 244 | + Utils.ok(this, "Job successfully updated."); |
207 | 245 | this.updateJobData(updatedJob); |
208 | 246 | }) |
209 | | - .catch(error => Utils.exception(this, error, "Sorry, could not update job title.")); |
| 247 | + .catch(error => Utils.exception(this, error, "Sorry, could not update job."));; |
210 | 248 | }, |
211 | 249 | queueJob(job) { |
212 | 250 | job.startJob() |
|
0 commit comments