Skip to content

Commit

Permalink
Merge pull request #172 from ymaheshwari1/#2dmggua-updated
Browse files Browse the repository at this point in the history
Implemented: support to reorder pending export jobs from the updates page(#2dmggua)
  • Loading branch information
adityasharma7 authored Feb 20, 2023
2 parents 7257f6f + 3c8bb64 commit c80a302
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 2 deletions.
186 changes: 186 additions & 0 deletions src/components/JobReorderModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<template>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button @click="closeModal">
<ion-icon slot="icon-only" :icon="closeOutline" />
</ion-button>
</ion-buttons>
<ion-title>{{ $t('Export product threshold jobs') }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<ion-reorder-group @ionItemReorder="doReorder($event)" disabled="false">
<ion-item v-for="job in modifiedJobs" :key="job.jobId">
<ion-label>{{ job.jobName }}</ion-label>
<ion-label>{{ job.runTime ? getTime(job.runTime) : "-" }}</ion-label>
<ion-label>{{ timeTillJob(job.runTime)}}</ion-label>
<ion-icon :icon="checkmarkCircleOutline" color="success" v-if="successJobs.includes(job.jobId)" />
<ion-icon :icon="closeCircleOutline" color="danger" v-if="failedJobs.includes(job.jobId)" />
<ion-reorder />
</ion-item>
</ion-reorder-group>

<ion-fab vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button @click="save()" :disabled="failedJobs.length">
<ion-icon :icon="saveOutline" />
</ion-fab-button>
</ion-fab>
</ion-content>
</template>

<script lang="ts">
import {
IonButtons,
IonButton,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonReorder,
IonReorderGroup,
IonTitle,
IonToolbar,
modalController
} from '@ionic/vue';
import { defineComponent } from 'vue';
import { checkmarkCircleOutline, closeCircleOutline, closeOutline, saveOutline } from 'ionicons/icons';
import { mapGetters, useStore } from 'vuex';
import { DateTime } from 'luxon';
import { JobService } from '@/services/JobService';
import { hasError, showToast } from '@/utils';
import logger from '@/logger';
import { translate } from '@/i18n';
export default defineComponent({
name: 'JobReorderModal',
components: {
IonButtons,
IonButton,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonReorder,
IonReorderGroup,
IonTitle,
IonToolbar,
},
data() {
return {
failedJobs: [] as any,
successJobs: [] as any,
modifiedJobs: JSON.parse(JSON.stringify((this as any).jobs))
}
},
computed: {
...mapGetters({
userProfile: "user/getUserProfile"
}),
},
props: ["jobs"],
methods: {
timeTillJob (time: any) {
const timeDiff = DateTime.fromMillis(time).diff(DateTime.local());
return DateTime.local().plus(timeDiff).toRelative();
},
closeModal(isJobsUpdated = false) {
modalController.dismiss({ isJobsUpdated });
},
getTime (time: any) {
return DateTime.fromMillis(time).toLocaleString(DateTime.TIME_SIMPLE);
},
findJobDiff(previousSeq: any, updatedSeq: any) {
// finding the diff using array element position
const diffSeq: any = Object.keys(previousSeq).reduce((diff, key) => {
if (updatedSeq[key].jobId === previousSeq[key].jobId && updatedSeq[key].runTime === previousSeq[key].runTime) return diff
return {
...diff,
[key]: updatedSeq[key]
}
}, {})
return diffSeq;
},
doReorder(event: CustomEvent) {
// making the item reorder action as complete and storing the updated order in jobs
const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(this.modifiedJobs)));
let diffSeq = this.findJobDiff(this.jobs, updatedSeq)
const runTimeSequence = this.jobs.map((job: any) => job.runTime)
diffSeq = Object.keys(diffSeq).map((key: any) => {
diffSeq[key].runTime = runTimeSequence[key]
return diffSeq[key]
})
this.modifiedJobs = updatedSeq
},
async save() {
this.failedJobs = []
this.successJobs = []
const diffSeq = this.findJobDiff(this.jobs, this.modifiedJobs)
const updatedJobsOrder = Object.keys(diffSeq).map((key) => diffSeq[key])
if(!updatedJobsOrder.length) {
showToast(translate('No jobs to update'))
this.closeModal();
return;
}
await Promise.allSettled(updatedJobsOrder.map(async (job: any) => {
const payload = {
'jobId': job.jobId,
'systemJobEnumId': job.systemJobEnumId,
'statusId': "SERVICE_PENDING",
'runTime': job.runTime
}
try {
const resp = await JobService.updateJob(payload)
if (resp.status == 200 && !hasError(resp) && resp.data.successMessage) {
// if the job succeded when updating then adding the jobId to the successJobs array
this.successJobs.push(job.jobId)
} else {
// if the job failed when updating then adding the jobId to the failedJobs array
this.failedJobs.push(job.jobId)
logger.error(`Failed to update job ${job.jobId}`)
}
} catch (err) {
this.failedJobs.push(job.jobId)
logger.error(err)
}
}))
// If there are no failed jobs then redirecting the user to the threshold updates page
if (!this.failedJobs.length) {
this.closeModal(true);
showToast(translate('Jobs sequence updated successfully'))
} else {
showToast(translate('Failed to update some jobs'))
}
},
},
setup() {
const store = useStore();
return {
checkmarkCircleOutline,
closeCircleOutline,
closeOutline,
saveOutline,
store
};
},
});
</script>

<style scoped>
ion-modal {
--width: 290px;
--height: 382px;
--border-radius: 8px;
}
</style>
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"excluded": "excluded",
"Exclude tags": "Exclude tags",
"Export product thresholds": "Export product thresholds",
"Export product threshold jobs": "Export product threshold jobs",
"Failed": "Failed",
"Failed to update some jobs": "Failed to update some jobs",
"Failed to schedule service, hence other jobs are not updated": "Failed to schedule service, hence other jobs are not updated",
Expand All @@ -46,6 +47,7 @@
"Include": "Include",
"Include tags": "Include tags",
"Info": "Info",
"Jobs sequence updated successfully": "Jobs sequence updated successfully",
"Keep editing": "Keep editing",
"Last run": "Last run",
"Loading": "Loading",
Expand All @@ -56,6 +58,7 @@
"Name": "Name",
"No job found.": "No job found.",
"No jobs have run yet": "No jobs have run yet",
"No jobs to update": "No jobs to update",
"No previous occurrence": "No previous occurrence",
"No threshold rule found. Invalid job": "No threshold rule found. Invalid job",
"No time zone found": "No time zone found",
Expand All @@ -73,6 +76,7 @@
"Ok": "Ok",
"OMS": "OMS",
"Ready to create an app?": "Ready to create an app?",
"Reorder export jobs": "Reorder export jobs",
"reset": "reset",
"retry": "retry",
"rule name": "rule name",
Expand Down
29 changes: 27 additions & 2 deletions src/views/ThresholdUpdates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@
<JobConfiguration :title="title" :job="currentJob" :productCount="productCount" :status="currentJobStatus" :type="freqType" :key="currentJob"/>
</aside>
</main>

<!-- showing reorder option on pending page and only when we are having pending jobs -->
<!-- Not defined fab button in the pending section div, as the slot property only works in ion-content and defining the button in div makes the fab button scrollable -->
<ion-fab v-if="segmentSelected === 'pending' && pendingJobs?.length !== 0" vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button @click="openReorderModal()">
<ion-icon :icon="pencilOutline" />
</ion-fab-button>
</ion-fab>
</ion-content>
</ion-page>
</template>
Expand All @@ -270,6 +278,8 @@ import {
IonCardHeader,
IonCardSubtitle,
IonCardTitle,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
Expand All @@ -292,14 +302,14 @@ import {
createAnimation
} from "@ionic/vue";
import JobConfiguration from '@/components/JobConfiguration.vue'
import { copyOutline, closeCircleOutline, checkmarkCircleOutline, optionsOutline, timeOutline, timerOutline } from "ionicons/icons";
import { copyOutline, closeCircleOutline, checkmarkCircleOutline, pencilOutline, optionsOutline, timeOutline, timerOutline } from "ionicons/icons";
import { Plugins } from '@capacitor/core';
import { hasError, showToast } from '@/utils'
import JobHistoryModal from '@/components/JobHistoryModal.vue';
import { DateTime } from 'luxon';
import { ProductService } from '@/services/ProductService';
import { Actions, hasPermission } from '@/authorization'
import JobReorderModal from '@/components/JobReorderModal.vue';
import emitter from '@/event-bus';
export default defineComponent({
Expand All @@ -312,6 +322,8 @@ export default defineComponent({
IonCardHeader,
IonCardSubtitle,
IonCardTitle,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
Expand Down Expand Up @@ -574,6 +586,18 @@ export default defineComponent({
createAnimation()
.addAnimation([gapAnimation, revealAnimation])
.play();
},
async openReorderModal() {
const jobReorderModal = await modalController.create({
component: JobReorderModal,
componentProps: { jobs: this.pendingJobs.filter((job: any) => job.systemJobEnumId === 'JOB_EXP_PROD_THRSHLD')} // passing export jobs, as we will only reorder export threshold jobs
})
jobReorderModal.onDidDismiss().then((result: any) => {
if (result?.data?.isJobsUpdated) {
this.store.dispatch('job/fetchPendingJobs', {viewSize:process.env.VUE_APP_VIEW_SIZE, viewIndex:0, jobEnums: this.jobEnums});
}
})
return jobReorderModal.present();
}
},
ionViewWillEnter() {
Expand All @@ -599,6 +623,7 @@ export default defineComponent({
store,
closeCircleOutline,
checkmarkCircleOutline,
pencilOutline,
optionsOutline,
timeOutline,
timerOutline,
Expand Down

0 comments on commit c80a302

Please sign in to comment.