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

Fixed: Last run doesn't shows previous occurrences for jobs of Initial load page (#303) #376

Merged
merged 8 commits into from
Feb 9, 2023
46 changes: 23 additions & 23 deletions src/components/InitialJobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ion-item>
<ion-icon slot="start" :icon="calendarClearOutline" />
<ion-label class="ion-text-wrap">{{ $t("Last run") }}</ion-label>
<ion-label class="ion-text-wrap" slot="end">{{ currentJob?.lastUpdatedStamp ? getTime(currentJob?.lastUpdatedStamp) : $t('No previous occurrence') }}</ion-label>
<ion-label class="ion-text-wrap" slot="end">{{ previousOccurrence ? getTime(previousOccurrence) : $t('No previous occurrence') }}</ion-label>
</ion-item>

<ion-item>
Expand All @@ -23,7 +23,7 @@
show-default-buttons
hour-cycle="h23"
:value="runTime ? getDateTime(runTime) : ''"
@ionChange="updateRunTime($event, currentJob)"
@ionChange="updateRunTime($event)"
/>
</ion-content>
</ion-modal>
Expand All @@ -44,21 +44,20 @@
<ion-item>
<ion-icon slot="start" :icon="calendarClearOutline" />
<ion-label class="ion-text-wrap">{{ $t("Last run") }}</ion-label>
<ion-label slot="end">{{ currentJob?.lastUpdatedStamp ? getTime(currentJob?.lastUpdatedStamp) : $t('No previous occurrence') }}</ion-label>
<ion-label slot="end">{{ previousOccurrence ? getTime(previousOccurrence) : $t('No previous occurrence') }}</ion-label>
</ion-item>

<ion-item button>
<ion-icon slot="start" :icon="timeOutline" />
<ion-label class="ion-text-wrap">{{ $t("Run time") }}</ion-label>
<ion-label @click="() => isOpen = true" slot="end">{{ currentJob?.runTime ? getTime(currentJob.runTime) : $t('Select run time') }}</ion-label>
<ion-label @click="() => isOpen = true" slot="end">{{ runTime ? getTime(runTime) : $t('Select run time') }}</ion-label>
<ion-modal class="date-time-modal" :is-open="isOpen" @didDismiss="() => isOpen = false">
<ion-content force-overscroll="false">
<ion-datetime
show-default-buttons
hour-cycle="h12"
:min="minDateTime"
:value="currentJob?.runTime ? getDateTime(currentJob?.runTime) : ''"
@ionChange="updateRunTime($event, currentJob)"
:value="runTime ? getDateTime(runTime) : ''"
@ionChange="updateRunTime($event)"
/>
</ion-content>
</ion-modal>
Expand Down Expand Up @@ -93,7 +92,7 @@
</ion-item>
</ion-list>

<ion-button size="small" fill="outline" expand="block" :disabled="!hasPermission(Actions.APP_JOB_UPDATE) || !lastShopifyOrderId" @click="runJob('Orders')">{{ $t("Run import") }}</ion-button>
<ion-button size="small" fill="outline" expand="block" :disabled="!hasPermission(Actions.APP_JOB_UPDATE)" @click="runJob('Orders')">{{ $t("Run import") }}</ion-button>
</section>
</template>

Expand Down Expand Up @@ -124,6 +123,7 @@ import { translate } from "@/i18n";
import { DateTime } from 'luxon';
import { handleDateTimeInput,isFutureDate, showToast } from '@/utils';
import { Actions, hasPermission } from '@/authorization'
import { JobService } from "@/services/JobService";

export default defineComponent({
name: "InitialJobConfiguration",
Expand All @@ -142,6 +142,7 @@ export default defineComponent({
},
data() {
return {
previousOccurrence: '',
isOpen: false,
lastShopifyOrderId: this.shopifyOrderId,
minDateTime: DateTime.now().toISO(),
Expand All @@ -150,7 +151,8 @@ export default defineComponent({
}
},
mounted() {
this.runTime = this.currentJob?.runTime
// Component is mounted even if there is no current job, do fetch previous occurrence if no current job
if (this.currentJob && Object.keys(this.currentJob).length) this.fetchPreviousOccurrence();
},
props: ['type', 'shopifyOrderId'],
computed: {
Expand All @@ -159,6 +161,11 @@ export default defineComponent({
})
},
methods: {
async fetchPreviousOccurrence() {
this.previousOccurrence = await JobService.fetchJobPreviousOccurrence({
systemJobEnumId: this.currentJob?.systemJobEnumId
})
},
async runJob(header: string) {
const alert = await alertController
.create({
Expand All @@ -183,10 +190,6 @@ export default defineComponent({
async updateJob() {
const job = this.currentJob;

if(!job) {
return;
}

job['sinceId'] = this.lastShopifyOrderId
job['jobStatus'] = job.tempExprId
job.runTime = this.runTime;
Expand All @@ -212,16 +215,13 @@ export default defineComponent({
const timeDiff = DateTime.fromMillis(time).diff(DateTime.local());
return DateTime.local().plus(timeDiff).toRelative();
},
updateRunTime(ev: CustomEvent, job: any) {
if (job) {
const currTime = DateTime.now().toMillis();
const setTime = handleDateTimeInput(ev['detail'].value);

if(setTime > currTime) {
this.runTime = setTime;
} else {
showToast(translate("Provide a future date and time"))
}
updateRunTime(ev: CustomEvent) {
const currTime = DateTime.now().toMillis();
const setTime = handleDateTimeInput(ev['detail'].value);
if(setTime > currTime) {
this.runTime = setTime;
} else {
showToast(translate("Provide a future date and time"))
}
}
},
Expand Down
19 changes: 8 additions & 11 deletions src/components/JobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
show-default-buttons
hour-cycle="h23"
:value="runTime ? getDateTime(runTime) : ''"
@ionChange="updateRunTime($event, currentJob)"
@ionChange="updateRunTime($event)"
/>
</ion-content>
</ion-modal>
Expand Down Expand Up @@ -328,16 +328,13 @@ export default defineComponent({
const timeDiff = DateTime.fromMillis(time).diff(DateTime.local());
return DateTime.local().plus(timeDiff).toRelative();
},
updateRunTime(ev: CustomEvent, job: any) {
if (job) {
const currTime = DateTime.now().toMillis();
const setTime = handleDateTimeInput(ev['detail'].value);

if(setTime > currTime) {
this.runTime = setTime;
} else {
showToast(translate("Provide a future date and time"))
}
updateRunTime(ev: CustomEvent) {
const currTime = DateTime.now().toMillis();
const setTime = handleDateTimeInput(ev['detail'].value);
if(setTime > currTime) {
this.runTime = setTime;
} else {
showToast(translate("Provide a future date and time"))
}
},
async viewJobHistory(job: any) {
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"Sorry, your username or password is incorrect. Please try again.": "Sorry, your username or password is incorrect. Please try again.",
"Select eCommerce": "Select eCommerce",
"Select store": "Select store",
"Service has been scheduled": "Service has been scheduled",
"Service updated successfully": "Service updated successfully",
"Settings": "Settings",
"Shopify Config": "Shopify Config",
Expand Down
47 changes: 47 additions & 0 deletions src/services/JobService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { hasError } from '@/utils'
import store from '@/store';
import { api } from '@/adapter';

const fetchJobInformation = async (payload: any): Promise <any> => {
Expand Down Expand Up @@ -62,10 +64,55 @@ const cancelJob = async (payload: any): Promise <any> => {
data: payload
});
}
const fetchJobPreviousOccurrence = async (payload: any): Promise <any> => {
try {
const params = {
"inputFields": {
"systemJobEnumId": payload.systemJobEnumId,
"statusId": ["SERVICE_DRAFT","SERVICE_PENDING","SERVICE_RUNNING", "SERVICE_QUEUED"],
"statusId_op": "not-in"
} as any,
"fieldList": [ "systemJobEnumId", "runTime"],
"noConditionFind": "Y",
"viewSize": 1,
"viewIndex": 0,
"orderBy": "runTime DESC"
}
if (store.state.user.currentEComStore?.productStoreId) {
params.inputFields = {
...params.inputFields,
"productStoreId": store.state.user.currentEComStore?.productStoreId,
"shopId_fld0_value": store.state.user.currentShopifyConfig?.shopId,
"shopId_fld0_grp": "1",
"shopId_fld0_op": "equals",
"shopId_fld1_grp": "2",
"shopId_fld1_op": "empty"
}
} else {
params.inputFields["productStoreId_op"] = "empty"
}
const resp = await api({
url: "/findJobs",
method: "get",
params: params,
cache: true
});
if (hasError(resp)) {
return Promise.reject(resp?.data);
} else {
// if there are no records response has { error: "No record found" } which is handled in if block
// We will have atleast a single record
return Promise.resolve(resp?.data.docs[0].runTime);
}
} catch(error: any) {
return Promise.reject(error)
}
}

export const JobService = {
fetchJobDescription,
fetchJobInformation,
fetchJobPreviousOccurrence,
fetchTemporalExpression,
updateJob,
scheduleJob,
Expand Down
5 changes: 5 additions & 0 deletions src/views/InitialLoad.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ export default defineComponent({
this.currentSelectedJobModal = label;
this.job = this.getJob(id);

if (!this.job) {
showToast(translate('Configuration missing'))
return;
}

if(this.job?.runtimeData?.sinceId?.length >= 0) {
this.lastShopifyOrderId = this.job.runtimeData.sinceId !== 'null' ? this.job.runtimeData.sinceId : ''
}
Expand Down