diff --git a/src/components/JobActionsPopover.vue b/src/components/JobActionsPopover.vue index 4e22a95a..cf9adfcf 100644 --- a/src/components/JobActionsPopover.vue +++ b/src/components/JobActionsPopover.vue @@ -14,7 +14,7 @@ {{ $t("Pin job") }} - + {{ $t("Run now") }} @@ -29,7 +29,6 @@ import { IonItem, IonList, IonListHeader, - alertController, modalController, popoverController } from "@ionic/vue"; @@ -38,9 +37,10 @@ import { copyOutline, flashOutline, pinOutline, timeOutline } from 'ionicons/ic import { mapGetters, useStore } from 'vuex' import JobHistoryModal from '@/components/JobHistoryModal.vue' import { Plugins } from '@capacitor/core'; -import { generateJobCustomParameters, hasJobDataError, showToast } from '@/utils' +import { generateJobCustomOptions, showToast } from '@/utils' import emitter from "@/event-bus" import { Actions, hasPermission } from '@/authorization' +import JobParameterModal from '@/components/JobParameterModal.vue' export default defineComponent({ name: "JobActionsPopover", @@ -94,35 +94,20 @@ export default defineComponent({ } this.closePopover(); }, - async runJobNow(job: any) { - const alert = await alertController - .create({ - header: this.$t("Run now"), - message: this.$t('Running this job now will not replace this job. A copy of this job will be created and run immediately. You may not be able to reverse this action.', { space: '

' }), - buttons: [ - { - text: this.$t("Cancel"), - role: 'cancel', - }, - { - text: this.$t('Run now'), - handler: async () => { - if(job) { - // return if job has missing data or error - if (hasJobDataError(job)) { - this.closePopover(); - return; - } - - const jobCustomParameters = generateJobCustomParameters([], [], job.runtimeData) - await this.store.dispatch('job/runServiceNow', { job, jobCustomParameters }) - this.closePopover(); - } - } - } - ] - }); - return alert.present(); + async openJobCustomParameterModal() { + const jobParameterModal = await modalController.create({ + component: JobParameterModal, + componentProps: { + customOptionalParameters: generateJobCustomOptions(this.job).optionalParameters, + customRequiredParameters: generateJobCustomOptions(this.job).requiredParameters, + currentJob: JSON.parse(JSON.stringify(this.job)), + runNow: true + }, + breakpoints: [0, 0.25, 0.5, 0.75, 1], + initialBreakpoint: 0.75 + }); + await jobParameterModal.present(); + this.closePopover(); }, }, setup() { diff --git a/src/components/JobConfiguration.vue b/src/components/JobConfiguration.vue index a27be9a9..7eaef23f 100644 --- a/src/components/JobConfiguration.vue +++ b/src/components/JobConfiguration.vue @@ -46,16 +46,16 @@
- + {{ $t('Add custom parameters') }} - + {{ name }}: {{ value }} - + @@ -94,7 +94,7 @@ {{ $t("History") }} - + {{ $t("Run now") }} @@ -388,33 +388,6 @@ export default defineComponent({ jobHistoryModal.dismiss({ dismissed: true }); }) }, - async runNow(job: any) { - const jobAlert = await alertController - .create({ - header: this.$t("Run now"), - message: this.$t('Running this job now will not replace this job. A copy of this job will be created and run immediately. You may not be able to reverse this action.', { space: '

' }), - buttons: [ - { - text: this.$t("Cancel"), - role: 'cancel', - }, - { - text: this.$t('Run now'), - handler: () => { - if (job && !hasJobDataError(job)) { - - // preparing the custom parameters those needs to passed with the job - const jobCustomParameters = generateJobCustomParameters(this.customRequiredParameters, this.customOptionalParameters, job.runtimeData) - - this.store.dispatch('job/runServiceNow', { job, jobCustomParameters }) - } - } - } - ] - }); - - return jobAlert.present(); - }, async copyJobInformation(job: any) { const { Clipboard } = Plugins; const jobDetails = `jobId: ${job.jobId}, jobName: ${job.enumName}, jobDescription: ${job.description} ${job.runtimeData ? (", runtimeData: " + JSON.stringify(job.runtimeData)) : ""}`; @@ -447,10 +420,19 @@ export default defineComponent({ if (setTime > currTime) this.generateRunTimes(setTime) else showToast(translate("Provide a future date and time")) }, - async openJobCustomParameterModal() { + async openJobCustomParameterModal(runNow?: boolean) { const jobParameterModal = await modalController.create({ - component: JobParameterModal, - componentProps: { customOptionalParameters: this.customOptionalParameters, customRequiredParameters: this.customRequiredParameters, currentJob: this.currentJob }, + component: JobParameterModal, + // deep cloning the props for the 'run now' case as the parameter objects are + // v-modeled in the job parameter modal hence, changes are reflected back on the UI + // (because of reference) which is misleading as the job with edited changes + // has already ran + componentProps: { + customOptionalParameters: runNow ? JSON.parse(JSON.stringify(this.customOptionalParameters)) : this.customOptionalParameters, + customRequiredParameters: runNow ? JSON.parse(JSON.stringify(this.customRequiredParameters)) : this.customRequiredParameters, + currentJob: runNow ? JSON.parse(JSON.stringify(this.currentJob)) : this.currentJob, + runNow + }, breakpoints: [0, 0.25, 0.5, 0.75, 1], initialBreakpoint: 0.75 }); diff --git a/src/components/JobParameterModal.vue b/src/components/JobParameterModal.vue index 487a119b..208696b5 100644 --- a/src/components/JobParameterModal.vue +++ b/src/components/JobParameterModal.vue @@ -1,8 +1,9 @@