Skip to content

Commit

Permalink
Merge pull request #611 from sanskar345/job-manager/#609
Browse files Browse the repository at this point in the history
Implemented: support to not allow user to schedule job if runtime data has error or service is not available (#609)
  • Loading branch information
ravilodhi authored Oct 9, 2023
2 parents 0ac17ce + af9ee93 commit 18c2b93
Show file tree
Hide file tree
Showing 16 changed files with 2,213 additions and 72 deletions.
2,183 changes: 2,127 additions & 56 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@casl/ability": "^6.0.0",
"@hotwax/app-version-info": "^1.0.0",
"@hotwax/apps-theme": "^1.2.3",
"@hotwax/dxp-components": "^1.3.4",
"@hotwax/oms-api": "^1.6.0",
"@hotwax/dxp-components": "^1.7.5",
"@hotwax/oms-api": "^1.10.0",
"@ionic/core": "6.7.5",
"@ionic/vue": "6.7.5",
"@ionic/vue-router": "6.7.5",
Expand Down
3 changes: 2 additions & 1 deletion src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { api, client, initialise, resetConfig, updateInstanceUrl, updateToken } from '@hotwax/oms-api'
import { api, client, getConfig, initialise, resetConfig, updateInstanceUrl, updateToken } from '@hotwax/oms-api'

export {
api,
client,
getConfig,
initialise,
resetConfig,
updateInstanceUrl,
Expand Down
5 changes: 4 additions & 1 deletion src/components/BatchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import { defineComponent } from 'vue';
import { closeOutline, checkmarkDoneOutline } from 'ionicons/icons';
import { mapGetters, useStore } from 'vuex';
import { DateTime } from 'luxon';
import { handleDateTimeInput, generateJobCustomParameters, getNowTimestamp, isFutureDate, showToast } from '@/utils';
import { handleDateTimeInput, generateJobCustomParameters, getNowTimestamp, isFutureDate, showToast, hasJobDataError } from '@/utils';
import { translate } from '@/i18n'
export default defineComponent({
Expand Down Expand Up @@ -149,6 +149,9 @@ export default defineComponent({
return;
}
// return if job has missing data or error
if (hasJobDataError(job)) return;
if (this.jobRunTime) {
job['runTime'] = this.jobRunTime
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/InitialJobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ import {
import { mapGetters, useStore } from "vuex";
import { translate } from "@/i18n";
import { DateTime } from 'luxon';
import { isCustomRunTime, generateAllowedRunTimes, generateJobCustomParameters, generateJobCustomOptions, getNowTimestamp, handleDateTimeInput, isFutureDate, showToast } from '@/utils';
import { isCustomRunTime, generateAllowedRunTimes, generateJobCustomParameters, generateJobCustomOptions, getNowTimestamp, handleDateTimeInput, isFutureDate, showToast, hasJobDataError } from '@/utils';
import { Actions, hasPermission } from '@/authorization'
import { JobService } from "@/services/JobService";
import JobParameterModal from '@/components/JobParameterModal.vue'
Expand Down Expand Up @@ -260,6 +260,9 @@ export default defineComponent({
async updateJob() {
const job = this.currentJob;
// return if job has missing data or error
if (hasJobDataError(job)) return;
job['sinceId'] = this.lastShopifyOrderId
job['jobStatus'] = job.tempExprId
Expand Down
8 changes: 7 additions & 1 deletion src/components/JobActionsPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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, showToast } from '@/utils'
import { generateJobCustomParameters, hasJobDataError, showToast } from '@/utils'
import emitter from "@/event-bus"
import { Actions, hasPermission } from '@/authorization'
Expand Down Expand Up @@ -108,6 +108,12 @@ export default defineComponent({
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();
Expand Down
9 changes: 7 additions & 2 deletions src/components/JobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ import {
} from "ionicons/icons";
import JobHistoryModal from '@/components/JobHistoryModal.vue'
import { Plugins } from '@capacitor/core';
import { isCustomRunTime, generateAllowedRunTimes, generateAllowedFrequencies, generateJobCustomParameters, generateJobCustomOptions, getNowTimestamp, handleDateTimeInput, showToast, hasError } from "@/utils";
import { isCustomRunTime, generateAllowedRunTimes, generateAllowedFrequencies, generateJobCustomParameters, generateJobCustomOptions, getNowTimestamp, handleDateTimeInput, showToast, hasError, hasJobDataError } from "@/utils";
import { mapGetters, useStore } from "vuex";
import { DateTime } from 'luxon';
import { translate } from '@/i18n'
Expand Down Expand Up @@ -323,6 +323,10 @@ export default defineComponent({
},
async updateJob() {
const job = this.currentJob;
// return if job has missing data or error
if(hasJobDataError(job)) return;
job['jobStatus'] = this.jobStatus !== 'SERVICE_DRAFT' ? this.jobStatus : 'HOURLY';
// Handling the case for 'Now'. Sending the now value will fail the API as by the time
Expand Down Expand Up @@ -397,7 +401,8 @@ export default defineComponent({
{
text: this.$t('Run now'),
handler: () => {
if (job) {
if (job && !hasJobDataError(job)) {
// preparing the custom parameters those needs to passed with the job
const jobCustomParameters = generateJobCustomParameters(this.customRequiredParameters, this.customOptionalParameters, job.runtimeData)
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@
"There are no jobs running right now": "There are no jobs running right now",
"There are no miscellaneous jobs right now": "There are no miscellaneous jobs right now",
"This is the name of the OMS you are connected to right now. Make sure that you are connected to the right instance before proceeding.": "This is the name of the OMS you are connected to right now. Make sure that you are connected to the right instance before proceeding.",
"This job does not have any runtime data configuration.": "This job does not have any runtime data configuration.",
"This job does not have any service data configuration.": "This job does not have any service data configuration.",
"This job has been canceled": "This job has been canceled",
"This job has been skipped": "This job has been skipped",
"This job has slow frequency type, hence, feasible frequency will be set automatically": "This job has slow frequency type, hence, feasible frequency will be set automatically",
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import permissionRules from '@/authorization/Rules';
import permissionActions from '@/authorization/Actions';
import { dxpComponents } from '@hotwax/dxp-components'
import { login, logout, loader } from './user-utils';
import { getConfig, initialise } from './adapter';

const app = createApp(App)
.use(IonicVue, {
Expand All @@ -53,7 +54,9 @@ const app = createApp(App)
login,
logout,
loader,
appLoginUrl: process.env.VUE_APP_LOGIN_URL as string
appLoginUrl: process.env.VUE_APP_LOGIN_URL as string,
getConfig,
initialise
})

// Filters are removed in Vue 3 and global filter introduced https://v3.vuejs.org/guide/migration/filters.html#global-filters
Expand Down
22 changes: 22 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { toastController } from '@ionic/vue';
import Papa from 'papaparse'
import { DateTime } from "luxon";
import logger from "@/logger";
import { translate } from "@/i18n";

// TODO Use separate files for specific utilities

Expand Down Expand Up @@ -287,6 +288,26 @@ const getNowTimestamp = () => {
return DateTime.now().toISO();
}

const hasJobDataError = (job: any) => {
let warning = '';
let message = '';

if (job?.serviceName === '_NA_') {
warning = `${job.systemJobEnumId} :: This job does not have any service data configuration.`;
message = 'This job does not have any service data configuration.';
} else if (job?.runtimeData?._ERROR_MESSAGE_) {
warning = `${job.systemJobEnumId}(${job.serviceName}) has runtimeData error :: ${job.runtimeData._ERROR_MESSAGE_}`;
message = 'This job does not have any runtime data configuration.';
}

if(message) {
logger.warn(warning);
showToast(translate(message));
return true;
}
return false;
}

export {
isCustomRunTime,
getNowTimestamp,
Expand All @@ -295,6 +316,7 @@ export {
generateJobCustomParameters,
generateJobCustomOptions,
handleDateTimeInput,
hasJobDataError,
showToast,
hasError,
parseCsv,
Expand Down
5 changes: 4 additions & 1 deletion src/views/Fulfillment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import { useStore } from "@/store";
import { useRouter } from 'vue-router'
import { mapGetters } from "vuex";
import JobConfiguration from '@/components/JobConfiguration.vue';
import { generateJobCustomParameters, hasError, isFutureDate, showToast, prepareRuntime } from '@/utils';
import { generateJobCustomParameters, hasError, isFutureDate, showToast, prepareRuntime, hasJobDataError } from '@/utils';
import emitter from '@/event-bus';
import { JobService } from '@/services/JobService'
import MoreJobs from '@/components/MoreJobs.vue';
Expand Down Expand Up @@ -181,6 +181,9 @@ export default defineComponent({
return;
}
// return if job has missing data or error
if (hasJobDataError(job)) return;
// TODO: added this condition to not call the api when the value of the select automatically changes
// need to handle this properly
if ((checked && job?.status === 'SERVICE_PENDING') || (!checked && job?.status === 'SERVICE_DRAFT')) {
Expand Down
5 changes: 4 additions & 1 deletion src/views/InitialLoad.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import {
} from '@ionic/vue';
import { defineComponent } from 'vue';
import { mapGetters, useStore } from 'vuex';
import { generateJobCustomParameters, isFutureDate, showToast } from '@/utils';
import { hasJobDataError, generateJobCustomParameters, isFutureDate, showToast } from '@/utils';
import emitter from '@/event-bus';
import InitialJobConfiguration from '@/components/InitialJobConfiguration.vue';
import { useRouter } from 'vue-router';
Expand Down Expand Up @@ -156,6 +156,9 @@ export default defineComponent({
return;
}
// return if job has missing data or error
if (hasJobDataError(job)) return;
job['jobStatus'] = status
// if job runTime is not a valid date then making runTime as empty
Expand Down
5 changes: 4 additions & 1 deletion src/views/Inventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {
import { defineComponent } from 'vue';
import { mapGetters, useStore } from 'vuex';
import JobConfiguration from '@/components/JobConfiguration.vue'
import { generateJobCustomParameters, isFutureDate, showToast, prepareRuntime } from '@/utils';
import { generateJobCustomParameters, isFutureDate, showToast, prepareRuntime, hasJobDataError } from '@/utils';
import emitter from '@/event-bus';
import { useRouter } from 'vue-router'
import { translate } from '@/i18n';
Expand Down Expand Up @@ -154,6 +154,9 @@ export default defineComponent({
return;
}
// return if job has missing data or error
if (hasJobDataError(job)) return;
// TODO: added this condition to not call the api when the value of the select automatically changes
// need to handle this properly
if ((checked && job?.status === 'SERVICE_PENDING') || (!checked && job?.status === 'SERVICE_DRAFT')) {
Expand Down
5 changes: 4 additions & 1 deletion src/views/Orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ import { useStore } from "@/store";
import { useRouter } from 'vue-router'
import { mapGetters } from "vuex";
import JobConfiguration from '@/components/JobConfiguration.vue';
import { generateJobCustomParameters, isFutureDate, showToast, prepareRuntime } from '@/utils';
import { generateJobCustomParameters, isFutureDate, showToast, prepareRuntime, hasJobDataError } from '@/utils';
import emitter from '@/event-bus';
import MoreJobs from '@/components/MoreJobs.vue';
import { Actions, hasPermission } from '@/authorization'
Expand Down Expand Up @@ -205,6 +205,9 @@ export default defineComponent({
return;
}
// return if job has missing data or error
if (hasJobDataError(job)) return;
// TODO: added this condition to not call the api when the value of the select automatically changes
// need to handle this properly
if ((checked && job?.status === 'SERVICE_PENDING') || (!checked && job?.status === 'SERVICE_DRAFT')) {
Expand Down
7 changes: 5 additions & 2 deletions src/views/PreOrder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ import { mapGetters } from "vuex";
import { useRouter } from 'vue-router'
import { alertController } from '@ionic/vue';
import JobConfiguration from '@/components/JobConfiguration.vue'
import { generateJobCustomParameters, isFutureDate, showToast, prepareRuntime } from '@/utils';
import { generateJobCustomParameters, isFutureDate, showToast, prepareRuntime, hasJobDataError } from '@/utils';
import emitter from '@/event-bus';
import { translate } from '@/i18n';
import MoreJobs from '@/components/MoreJobs.vue';
Expand Down Expand Up @@ -260,6 +260,9 @@ export default defineComponent({
return;
}
// return if job has missing data or error
if (hasJobDataError(job)) return;
// TODO: added this condition to not call the api when the value of the select automatically changes
// need to handle this properly
if ((checked && job?.status === 'SERVICE_PENDING') || (!checked && job?.status === 'SERVICE_DRAFT')) {
Expand Down Expand Up @@ -297,7 +300,7 @@ export default defineComponent({
{
text: this.$t('Run now'),
handler: () => {
if (job) {
if (job && !hasJobDataError(job)) {
const jobCustomParameters = generateJobCustomParameters([], [], job.runtimeData)
this.store.dispatch('job/runServiceNow', { job, jobCustomParameters })
}
Expand Down
12 changes: 11 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path')

require("@hotwax/app-version-info")
module.exports = {
pluginOptions: {
Expand All @@ -12,5 +14,13 @@ module.exports = {
enableInSFC: true
}
},
runtimeCompiler: true
configureWebpack: {
resolve: {
alias: {
vue: path.resolve('./node_modules/vue')
}
}
},
runtimeCompiler: true,
transpileDependencies: ['@hotwax/dxp-components']
}

0 comments on commit 18c2b93

Please sign in to comment.