Skip to content

Commit

Permalink
Improved: optimal code for brokering page(#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Oct 20, 2023
1 parent 50d79e6 commit a0bc6dc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 96 deletions.
72 changes: 31 additions & 41 deletions src/components/BatchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
<ion-select-option value="BACKORDER_PARKING">{{ $t("Back-order parking") }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item lines="full">
<ion-item>
<ion-icon slot="start" :icon="warningOutline" />
<ion-label>{{ $t('Unfillable orders') }}</ion-label>
<ion-toggle slot="end" :checked="unfillableOrder" @click="unfillableOrder = !unfillableOrder; updateCustomParameters()"></ion-toggle>
</ion-item>



<ion-list v-if="customOptionalParameters.length || customRequiredParameters.length">
<ion-item lines="none">
<ion-label>
Expand All @@ -44,7 +43,7 @@

<ion-item :key="index" v-for="(parameter, index) in customRequiredParameters">
<ion-label>{{ parameter.name }}</ion-label>
<ion-input ></ion-input>>
<ion-input :placeholder="parameter.name" v-model="parameter.value" />
<ion-note slot="helper">{{ parameter.type }}</ion-note>
</ion-item>

Expand All @@ -54,31 +53,29 @@

<ion-item :key="parameter.value" v-for="parameter in customOptionalParameters">
<ion-label>{{ parameter.name }}</ion-label>
<!-- Todo: look into issue with input taking one character at a time -->
<ion-input :placeholder="parameter.name" v-model="parameter.value" />
<ion-note slot="helper">{{ parameter.type }}</ion-note>
</ion-item>
</ion-list>
<ion-list v-else>
<ion-item>
<ion-label>{{ 'No parameters available' }}</ion-label>
<ion-label>{{ $t('No parameters available') }}</ion-label>
</ion-item>
</ion-list>

<ion-card>
<ion-item lines="none">
<ion-label>{{ 'Schedule' }}</ion-label>
</ion-item>
<ion-card-header>
<ion-card-title>{{ $t('Schedule') }}</ion-card-title>
</ion-card-header>

<ion-item :disabled="currentBatch?.jobId">
<ion-icon slot="start" :icon="timeOutline" />
<ion-label>{{ $t('Run time') }}</ion-label>
<ion-select interface="popover" :placeholder="$t('Select')" :value="runTime" @ionChange="updateRunTime($event)">
<ion-select-option v-for="runTime in runTimes" :key="runTime.value" :value="runTime.value">{{ $t(runTime.label) }}</ion-select-option>
</ion-select>
<!-- TODO: display a button when we are not having a runtime and open the datetime component
on click of that button
Currently, when mapping the same datetime component for label and button so it's not working so for
now commented the button and added a fallback string -->
<!-- <ion-button id="open-run-time-modal" size="small" fill="outline" color="medium" v-show="!currentJob?.runTime">{{ $t("Select run time") }}</ion-button> -->

<ion-modal class="date-time-modal" :is-open="isDateTimeModalOpen" @didDismiss="() => isDateTimeModalOpen = false">
<ion-content force-overscroll="false">
<ion-datetime
Expand Down Expand Up @@ -112,6 +109,8 @@ import {
IonButton,
IonButtons,
IonCard,
IonCardHeader,
IonCardTitle,
IonContent,
IonDatetime,
IonFab,
Expand All @@ -133,10 +132,10 @@ import {
modalController
} from '@ionic/vue';
import { defineComponent } from 'vue';
import { closeOutline, checkmarkDoneOutline, timeOutline, timerOutline, ticketOutline, warningOutline } from 'ionicons/icons';
import { closeOutline, checkmarkDoneOutline, ticketOutline, timeOutline, timerOutline, warningOutline } from 'ionicons/icons';
import { mapGetters, useStore } from 'vuex';
import { DateTime } from 'luxon';
import { handleDateTimeInput, generateAllowedRunTimes, generateAllowedFrequencies, generateJobCustomParameters, generateJobCustomOptions, getNowTimestamp, isCustomRunTime, isFutureDate, showToast, hasJobDataError } from '@/utils';
import { handleDateTimeInput, generateAllowedFrequencies, generateAllowedRunTimes, generateJobCustomParameters, generateJobCustomOptions, getNowTimestamp, hasJobDataError, isCustomRunTime, showToast } from '@/utils';
import { translate } from '@/i18n'
import CustomFrequencyModal from '@/components/CustomFrequencyModal.vue';
import { Actions, hasPermission } from '@/authorization'
Expand All @@ -147,6 +146,8 @@ export default defineComponent({
IonButton,
IonButtons,
IonCard,
IonCardHeader,
IonCardTitle,
IonContent,
IonDatetime,
IonFab,
Expand All @@ -166,7 +167,6 @@ export default defineComponent({
IonToggle,
IonToolbar,
},
props: ["id", "enumId"],
data() {
return {
jobEnums: JSON.parse(process.env?.VUE_APP_BATCH_JOB_ENUMS as string) as any,
Expand Down Expand Up @@ -230,15 +230,11 @@ export default defineComponent({
this.jobStatus = currentFrequency;
},
async updateJob() {
let batchJobEnum = this.enumId;
if (!batchJobEnum) {
const jobEnum: any = Object.values(this.jobEnums)?.find((job: any) => {
return job.unfillable === this.unfillableOrder && job.facilityId === this.batchFacilityId
});
batchJobEnum = jobEnum.id
}
const job = this.getJob(batchJobEnum)?.find((job: any) => job.status === 'SERVICE_DRAFT');
const jobEnum: any = Object.values(this.jobEnums)?.find((job: any) => {
return job.unfillable === this.unfillableOrder && job.facilityId === this.batchFacilityId
});
const job = this.getJob(jobEnum.id)?.find((job: any) => job.status === 'SERVICE_DRAFT');
if (!job) {
showToast(translate('Configuration missing'))
return;
Expand All @@ -254,14 +250,8 @@ export default defineComponent({
job['jobStatus'] = this.jobStatus !== 'SERVICE_DRAFT' ? this.jobStatus : 'HOURLY';
job['jobName'] = this.jobName || this.currentDateTime;
// if job runTime is not a valid date then making runTime as empty
// if (job?.runTime && !isFutureDate(job?.runTime)) {
// job.runTime = ''
// }
console.log('end', job);
if (job?.status === 'SERVICE_DRAFT') {
const jobCustomParameters = generateJobCustomParameters(this.customRequiredParameters, this.customOptionalParameters, job.runtimeData)
const jobCustomParameters = generateJobCustomParameters(this.customRequiredParameters, this.customOptionalParameters, job.runtimeData)
await this.store.dispatch('job/scheduleService', { job, jobCustomParameters })
} else if (job?.status === 'SERVICE_PENDING') {
await this.store.dispatch('job/updateJob', job)
Expand Down Expand Up @@ -289,9 +279,8 @@ export default defineComponent({
const jobEnum: any = Object.values(this.jobEnums)?.find((job: any) => {
return job.unfillable === this.unfillableOrder && job.facilityId === this.batchFacilityId
});
let batchJobEnum = jobEnum.id
const job = this.getJob(batchJobEnum)?.find((job: any) => job.status === 'SERVICE_DRAFT');
const job = this.getJob(jobEnum.id)?.find((job: any) => job.status === 'SERVICE_DRAFT');
this.customOptionalParameters = generateJobCustomOptions(job).optionalParameters;
this.customRequiredParameters = generateJobCustomOptions(job).requiredParameters;
},
Expand All @@ -308,28 +297,29 @@ export default defineComponent({
},
isRequiredParametersMissing() {
return this.customRequiredParameters.some((parameter: any) => !parameter.value?.trim())
},
}
},
setup() {
const store = useStore();
return {
checkmarkDoneOutline,
closeOutline,
getNowTimestamp,
hasPermission,
isCustomRunTime,
store,
ticketOutline,
timeOutline,
timerOutline,
warningOutline,
store,
DateTime,
getNowTimestamp,
isCustomRunTime,
Actions,
hasPermission
DateTime
};
},
});
</script>

<style scoped>
ion-content {
--offset-bottom: 100px;
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"No frequency found": "No frequency found",
"No jobs found": "No jobs found",
"No jobs have run yet": "No jobs have run yet",
"No parameters available": "No parameters available",
"No previous occurrence": "No previous occurrence",
"No time zone found": "No time zone found",
"Notes": "Notes",
Expand Down
58 changes: 3 additions & 55 deletions src/views/Brokering.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ion-item>
</ion-card>

<ion-card :button="isDesktop" v-for="batch in orderBatchJobs" :key="batch?.id" detail v-show="batch?.status === 'SERVICE_PENDING'" @click="hasPermission(Actions.APP_JOB_UPDATE) && viewJobConfiguration({ job:batch })">
<ion-card :button="isDesktop" v-for="batch in orderBatchJobs" :key="batch?.id" detail v-show="batch?.status === 'SERVICE_PENDING'" @click="hasPermission(Actions.APP_JOB_UPDATE) && viewJobConfiguration({ job: batch })">
<ion-card-header>
<div>
<ion-card-subtitle>{{ getBrokerQueue(batch) }}</ion-card-subtitle>
Expand Down Expand Up @@ -67,7 +67,6 @@

<script lang="ts">
import {
alertController,
IonBadge,
IonButton,
IonCard,
Expand All @@ -82,16 +81,15 @@ import {
IonList,
IonMenuButton,
IonPage,
IonRow,
IonText,
IonTitle,
IonToggle,
IonToolbar,
IonRow,
isPlatform,
modalController
} from '@ionic/vue';
import { defineComponent } from 'vue';
import { translate } from '@/i18n'
import { addCircleOutline, arrowRedoOutline, trashOutline } from 'ionicons/icons';
import BatchModal from '@/components/BatchModal.vue';
import { useStore } from "@/store";
Expand Down Expand Up @@ -166,55 +164,7 @@ export default defineComponent({
});
return batchmodal.present();
},
async deleteBatch(batch: any) {
const deleteBatchAlert = await alertController
.create({
header: this.$t('Cancel job'),
message: this.$t("Canceling this job will cancel this occurrence and all following occurrences. This job will have to be re-enabled manually to run it again."),
buttons: [
{
text: this.$t("Don't cancel"),
role: 'cancel',
},
{
text: this.$t("Cancel"),
handler: async () => {
await this.store.dispatch('job/cancelJob', batch);
},
},
],
});
return deleteBatchAlert.present();
},
async skipBatch (batch: any) {
const skipJobAlert = await alertController
.create({
header: this.$t('Skip job'),
message: this.$t('Skipping will run this job at the next occurrence based on the temporal expression.'),
buttons: [
{
text: this.$t("Don't skip"),
role: 'cancel',
},
{
text: this.$t('Skip'),
handler: async () => {
this.store.dispatch('job/skipJob', batch).then((resp) => {
if (resp.status === 200 && !hasError(resp)) {
showToast(translate("This job has been skipped"));
} else {
showToast(translate("This job schedule cannot be skipped"));
}
});
(this as any).$refs.slidingOptions.$el.closeSlidingItems();
},
}
]
});
return skipJobAlert.present();
},
getTime (time: any) {
// return DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED);
return DateTime.fromMillis(time).toLocaleString(DateTime.TIME_24_SIMPLE);
},
getBrokerQueue(job: any){
Expand Down Expand Up @@ -283,16 +233,14 @@ export default defineComponent({
let customOptionalParameters = generateJobCustomOptions(job).optionalParameters;
let customRequiredParameters = generateJobCustomOptions(job).requiredParameters;
// passing runTimeData params as empty, as we don't need to show the runTimeData information on UI as all the options from runtimeData might not be available in serviceInParams
// passing runTimeData params as empty, as we don't need to show the runTimeData information on UI
return generateJobCustomParameters(customRequiredParameters, customOptionalParameters, {})
// return generateJobCustomParameters(customRequiredParameters, customOptionalParameters, job.runtimeData)
}
},
mounted () {
this.fetchJobs();
emitter.on("productStoreOrConfigChanged", this.fetchJobs);
emitter.on('viewJobConfiguration', this.viewJobConfiguration)
},
unmounted() {
emitter.off("productStoreOrConfigChanged", this.fetchJobs);
Expand Down

0 comments on commit a0bc6dc

Please sign in to comment.