Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: predefined and custom option for selecting job run time (#85zrxc0xf) #449

Merged
merged 7 commits into from
May 8, 2023
88 changes: 74 additions & 14 deletions src/components/JobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<ion-item>
<ion-icon slot="start" :icon="timeOutline" />
<ion-label class="ion-text-wrap">{{ $t("Run time") }}</ion-label>
<ion-label class="ion-text-wrap" @click="() => isOpen = true" slot="end">{{ runTime ? getTime(runTime) : $t('Select run time') }}</ion-label>
<ion-select interface="popover" :placeholder="$t('Select')" :value="runTime.value" @ionChange="updateRunTime($event)">
<ion-select-option v-for="runTime in runTimeOptions" :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
Expand All @@ -28,8 +30,8 @@
<ion-datetime
show-default-buttons
hour-cycle="h23"
:value="runTime ? getDateTime(runTime) : ''"
@ionChange="updateRunTime($event)"
:value="runTime.value ? (runTime.type === 'CUSTOM' ? getDateTime(runTime.value) : getDateTime(DateTime.now().toMillis() + parseInt(runTime.value))) : ''"
@ionChange="updateCustomTime($event)"
/>
</ion-content>
</ion-modal>
Expand Down Expand Up @@ -152,17 +154,20 @@ export default defineComponent({
return {
isOpen: false,
jobStatus: this.status,
runTime: '' as any,
runTime: {
value: '',
type: 'CUSTOM' // as job's current time is 'custom'
} as any,
}
},
mounted() {
this.runTime = this.currentJob?.runTime
this.runTime.value = this.currentJob?.runTime
},
updated() {
// When updating the job, the job is fetched again with the latest values
// Updated value should be set to instance variable jobStatus
this.jobStatus = this.currentJob.statusId === "SERVICE_DRAFT" ? this.currentJob.statusId : this.currentJob.tempExprId;
this.runTime = this.currentJob?.runTime ? this.currentJob?.runTime : ''
this.runTime.value = this.currentJob?.runTime ? this.currentJob?.runTime : ''
},
props: ["title", "status", "type"],
computed: {
Expand Down Expand Up @@ -219,7 +224,27 @@ export default defineComponent({
header: (this as any).title,
showBackdrop: false
}
}
},
// value denotes the time in milliseconds for that label
runTimeOptions: () => [{
"value": 0,
Copy link
Contributor

@adityasharma7 adityasharma7 May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think due to this time will be passed to server resulting in schedule failure

"label": "Now"
}, {
"value": 300000,
"label": "In 5 minutes"
}, {
"value": 900000,
"label": "In 15 minutes"
}, {
"value": 3600000,
"label": "In an hour"
}, {
"value": 86400000,
"label": "Tomorrow"
}, {
"value": "CUSTOM",
"label": "Custom"
}]
},
methods: {
getDateTime(time: any) {
Expand Down Expand Up @@ -303,7 +328,9 @@ export default defineComponent({
async updateJob() {
const job = this.currentJob;
job['jobStatus'] = this.jobStatus !== 'SERVICE_DRAFT' ? this.jobStatus : 'HOURLY';
job.runTime = this.runTime;

job.runTime = this.runTime.value
if (this.runTime.type === 'PREDEFINED') job.runTime += DateTime.now().toMillis()

if (job?.statusId === 'SERVICE_DRAFT') {
this.store.dispatch('job/scheduleService', job).then((job: any) => {
Expand All @@ -329,13 +356,26 @@ export default defineComponent({
const timeDiff = DateTime.fromMillis(time).diff(DateTime.local());
return DateTime.local().plus(timeDiff).toRelative();
},
updateRunTime(ev: CustomEvent) {
const currTime = DateTime.now().toMillis();
const setTime = handleDateTimeInput(ev['detail'].value);
if(setTime > currTime) {
this.runTime = setTime;
updateRunTime(event: CustomEvent) {
const value = event.detail.value
if (value != 'CUSTOM') {
// checking if a predefined option is selected i.e the first five options
const isPrefinedValue = this.runTimeOptions.slice(0, 5).some((option: any) => option.value === value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isPrefinedValue = this.runTimeOptions.slice(0, 5).some((option: any) => option.value === value)
const isPredefinedValue = this.runTimeOptions.slice(0, 5).some((option: any) => option.value === value)


// Update the option list iff - a predefined option is selected
// and a custom date time is already there in the list
if (this.runTime.type === 'CUSTOM'
&& this.runTimeOptions[this.runTimeOptions.length - 1].value != 'CUSTOM'
&& isPrefinedValue) {
this.runTimeOptions.pop()
}

this.runTime = {
value,
type: isPrefinedValue ? 'PREDEFINED' : 'CUSTOM'
}
} else {
showToast(translate("Provide a future date and time"))
this.isOpen = true
}
},
async viewJobHistory(job: any) {
Expand Down Expand Up @@ -391,6 +431,25 @@ export default defineComponent({
pinnedJobs.add(enumId);
await this.store.dispatch('user/updatePinnedJobs', { pinnedJobs: [...pinnedJobs] });
}
},
updateCustomTime(event: CustomEvent) {
const currTime = DateTime.now().toMillis();
const setTime = handleDateTimeInput(event.detail.value);
if (setTime > currTime) {
if (this.runTimeOptions[this.runTimeOptions.length - 1].value != 'CUSTOM') this.runTimeOptions.pop()

this.runTimeOptions.push({
value: setTime,
label: this.getTime(setTime)
})

this.runTime = {
value: setTime,
type: 'CUSTOM'
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think custom option will remain selected in this case

showToast(translate("Provide a future date and time"))
}
}
},
setup() {
Expand All @@ -401,6 +460,7 @@ export default defineComponent({
Actions,
calendarClearOutline,
copyOutline,
DateTime,
flashOutline,
hasPermission,
timeOutline,
Expand Down
7 changes: 7 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"Completed orders": "Completed orders",
"Copied job details to clipboard": "Copied job details to clipboard",
"Copy details": "Copy details",
"Custom": "Custom",
"Daily": "Daily",
"Dashoard": "Dashoard",
"Days": "Days",
Expand Down Expand Up @@ -89,6 +90,9 @@
"Inventory": "Inventory",
"Inventory cost": "Inventory cost",
"Inventory level update": "Inventory level update",
"In 5 minutes": "In 5 minutes",
"In 15 minutes": "In 15 minutes",
"In an hour": "In an hour",
"Job details": "Job details",
"Job Manager": "Job Manager",
"Landed inventory cost": "Landed inventory cost",
Expand All @@ -111,6 +115,7 @@
"No previous occurrence": "No previous occurrence",
"Notes": "Notes",
"No time zone found": "No time zone found",
"Now": "Now",
"occurrences": "occurrences",
"OMS": "OMS",
"OMS instance": "OMS instance",
Expand Down Expand Up @@ -171,6 +176,7 @@
"Schedule in bulk": "Schedule in bulk",
"Schedule inventory hard sync": "Schedule inventory hard sync",
"Schedule product sync": "Schedule product sync",
"Select": "Select",
"Select run time": "Select run time",
"Search jobs": "Search jobs",
"Searched jobs will appear here": "Searched jobs will appear here",
Expand Down Expand Up @@ -221,6 +227,7 @@
"This job will be scheduled to run as soon as possible. There may not be enough time to revert this action.": "This job will be scheduled to run as soon as possible.{ space } There may not be enough time to revert this action.",
"Time zone updated successfully": "Time zone updated successfully",
"Timezone": "Timezone",
"Tomorrow": "Tomorrow",
"Transfer backorder related information to Shopify as tags and meta fields.": "Transfer backorder related information to Shopify as tags and meta fields.",
"Transfer pre-order related information to Shopify as tags and meta fields.": "Transfer pre-order related information to Shopify as tags and meta fields.",
"UI Components": "UI Components",
Expand Down