From aa32a6bfeb3957808ff511ed7f8c53c7280d51bd Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 27 Sep 2024 16:21:50 +0530 Subject: [PATCH 1/4] Implemented: bringing moqui redirection info in ofbiz apps (#299) --- package-lock.json | 94 ++++++++++++++++++------ package.json | 4 +- src/services/UserService.ts | 29 ++++++++ src/store/modules/user/UserState.ts | 4 + src/store/modules/user/actions.ts | 22 +++++- src/store/modules/user/index.ts | 4 + src/store/modules/user/mutation-types.ts | 3 +- src/store/modules/user/mutations.ts | 3 + 8 files changed, 133 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 88b8a73b..13be5d46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,8 @@ "@casl/ability": "^6.0.0", "@hotwax/app-version-info": "^1.0.0", "@hotwax/apps-theme": "^1.2.6", - "@hotwax/dxp-components": "1.13.0", - "@hotwax/oms-api": "1.14.0", + "@hotwax/dxp-components": "1.15.2", + "@hotwax/oms-api": "1.15.0", "@ionic/core": "^7.6.0", "@ionic/vue": "^7.6.0", "@ionic/vue-router": "^7.6.0", @@ -2802,9 +2802,9 @@ "integrity": "sha512-zpUjGoY7LBlKeiP0V7tonrmoey8HQ5THQmyixQ+IDtrjmEJNBjynW/Ef3gC0FUNNPuVqxWPZdT5CVgaETLGTwg==" }, "node_modules/@hotwax/dxp-components": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/@hotwax/dxp-components/-/dxp-components-1.13.0.tgz", - "integrity": "sha512-AkzHpGIWYFURIAKaqioNZdkaeJBaJHs+ep+5ibLyEj+Ex+GsyMsI9L1NVO+tl91ECkCNx02QjHPhMfpo0osQ3w==", + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/@hotwax/dxp-components/-/dxp-components-1.15.2.tgz", + "integrity": "sha512-0jF1xkRIVrDbJwUaaPwWUhp3cVBpdjgAJO/fOQ4XYjzKb8rYXgw0Xm/qHHUnSeAZW5laMnQrm1KtPZp8szu4dQ==", "dependencies": { "@hotwax/oms-api": "^1.8.1", "@ionic/core": "^7.6.0", @@ -2815,7 +2815,8 @@ "pinia-plugin-persistedstate": "^3.1.0", "register-service-worker": "^1.7.2", "vue": "^3.3.4", - "vue-i18n": "^9.2.2" + "vue-i18n": "^9.2.2", + "vue-markdown-render": "^2.2.1" } }, "node_modules/@hotwax/dxp-components/node_modules/@intlify/core-base": { @@ -2859,16 +2860,6 @@ "url": "https://github.com/sponsors/kazupon" } }, - "node_modules/@hotwax/dxp-components/node_modules/@ionic/core": { - "version": "7.8.2", - "resolved": "https://registry.npmjs.org/@ionic/core/-/core-7.8.2.tgz", - "integrity": "sha512-1Iwe4XSaEYD0u7U/AnnKYNRXmPxx/doTl6pExXq/nlEd7q0AykRkPEy5rClqrQcJOrgFogAx1FwSObfgm0xnNw==", - "dependencies": { - "@stencil/core": "^4.12.2", - "ionicons": "^7.2.2", - "tslib": "^2.1.0" - } - }, "node_modules/@hotwax/dxp-components/node_modules/pinia": { "version": "2.0.36", "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.0.36.tgz", @@ -2927,11 +2918,6 @@ } } }, - "node_modules/@hotwax/dxp-components/node_modules/tslib": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", - "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" - }, "node_modules/@hotwax/dxp-components/node_modules/vue-i18n": { "version": "9.10.2", "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.10.2.tgz", @@ -2952,9 +2938,9 @@ } }, "node_modules/@hotwax/oms-api": { - "version": "1.14.0", - "resolved": "https://registry.npmjs.org/@hotwax/oms-api/-/oms-api-1.14.0.tgz", - "integrity": "sha512-dYkrFEi0oJHKiJ/VctKmyIY4WTVV2lmljm1EflgQ/LM7BTJ9jVEeT1zgYJ5vO906kW7SWM4pl7mZI3dDCt1YCQ==", + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/@hotwax/oms-api/-/oms-api-1.15.0.tgz", + "integrity": "sha512-6WXJ5z5JaAxgKith6dblLchP471xUYcFaeggN5onWZBkgGx5NqkLT0rgLWTW/UcVQMokxKtzSc+mcJ4eI1mGww==", "dependencies": { "@types/node-json-transform": "^1.0.0", "axios": "^0.21.1", @@ -11683,6 +11669,14 @@ "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", "dev": true }, + "node_modules/linkify-it": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-4.0.1.tgz", + "integrity": "sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw==", + "dependencies": { + "uc.micro": "^1.0.1" + } + }, "node_modules/listr2": { "version": "3.14.0", "resolved": "https://registry.npmjs.org/listr2/-/listr2-3.14.0.tgz", @@ -12097,6 +12091,37 @@ "semver": "bin/semver.js" } }, + "node_modules/markdown-it": { + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-13.0.2.tgz", + "integrity": "sha512-FtwnEuuK+2yVU7goGn/MJ0WBZMM9ZPgU9spqlFs7/A/pDIUNSOQZhUgOqYCficIuR2QaFnrt8LHqBWsbTAoI5w==", + "dependencies": { + "argparse": "^2.0.1", + "entities": "~3.0.1", + "linkify-it": "^4.0.1", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + }, + "bin": { + "markdown-it": "bin/markdown-it.js" + } + }, + "node_modules/markdown-it/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "node_modules/markdown-it/node_modules/entities": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-3.0.1.tgz", + "integrity": "sha512-WiyBqoomrwMdFG1e0kqvASYfnlb0lp8M5o5Fw2OFq1hNZxxcNk8Ik0Xm7LxzBhuidnZB/UtBqVCgUz3kBOP51Q==", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/md5": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz", @@ -12113,6 +12138,11 @@ "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==", "dev": true }, + "node_modules/mdurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", + "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==" + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -16123,6 +16153,11 @@ "node": ">=4.2.0" } }, + "node_modules/uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==" + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -17002,6 +17037,17 @@ "node": ">=8" } }, + "node_modules/vue-markdown-render": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/vue-markdown-render/-/vue-markdown-render-2.2.1.tgz", + "integrity": "sha512-XkYnC0PMdbs6Vy6j/gZXSvCuOS0787Se5COwXlepRqiqPiunyCIeTPQAO2XnB4Yl04EOHXwLx5y6IuszMWSgyQ==", + "dependencies": { + "markdown-it": "^13.0.2" + }, + "peerDependencies": { + "vue": "^3.3.4" + } + }, "node_modules/vue-router": { "version": "4.2.5", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.2.5.tgz", diff --git a/package.json b/package.json index be760c54..00dca5e8 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "@casl/ability": "^6.0.0", "@hotwax/app-version-info": "^1.0.0", "@hotwax/apps-theme": "^1.2.6", - "@hotwax/dxp-components": "1.13.0", - "@hotwax/oms-api": "1.14.0", + "@hotwax/dxp-components": "1.15.2", + "@hotwax/oms-api": "1.15.0", "@ionic/core": "^7.6.0", "@ionic/vue": "^7.6.0", "@ionic/vue-router": "^7.6.0", diff --git a/src/services/UserService.ts b/src/services/UserService.ts index 91c30033..8ca13a62 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -13,6 +13,34 @@ const login = async (username: string, password: string): Promise => { }); } +const moquiLogin = async (omsRedirectionUrl: string, token: string): Promise => { + const baseURL = omsRedirectionUrl.startsWith('http') ? omsRedirectionUrl.includes('/rest/s1/order-routing') ? omsRedirectionUrl : `${omsRedirectionUrl}/rest/s1/order-routing/` : `https://${omsRedirectionUrl}.hotwax.io/rest/s1/order-routing/`; + let api_key = "" + + try { + const resp = await client({ + url: "login", + method: "post", + baseURL, + params: { + token + }, + headers: { + "Content-Type": "application/json" + } + }) as any; + + if(!hasError(resp) && (resp.data.api_key || resp.data.token)) { + api_key = resp.data.api_key || resp.data.token + } else { + throw "Sorry, login failed. Please try again"; + } + } catch(err) { + return Promise.resolve(""); + } + return Promise.resolve(api_key) +} + const setUserPreference = async (payload: any): Promise => { return api({ url: "service/setUserPreference", @@ -195,5 +223,6 @@ export const UserService = { getUserProfile, getUserPermissions, login, + moquiLogin, setUserPreference, } \ No newline at end of file diff --git a/src/store/modules/user/UserState.ts b/src/store/modules/user/UserState.ts index 4fea94b0..7d692caf 100644 --- a/src/store/modules/user/UserState.ts +++ b/src/store/modules/user/UserState.ts @@ -5,4 +5,8 @@ export default interface UserState { pwaState: any; instanceUrl: string; currentEComStore: object; + omsRedirectionInfo: { + url: string; + token: string; + } } \ No newline at end of file diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 5a10c0d3..0029dba6 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -18,7 +18,7 @@ const actions: ActionTree = { */ async login ({ commit, dispatch }, payload) { - const { token, oms } = payload; + const { token, oms, omsRedirectionUrl } = payload; dispatch("setUserInstanceUrl", oms); try { if (token) { @@ -66,6 +66,17 @@ const actions: ActionTree = { Settings.defaultZone = userProfile.userTimeZone; } + if(omsRedirectionUrl) { + const api_key = await UserService.moquiLogin(omsRedirectionUrl, token) + if(api_key) { + dispatch("setOmsRedirectionInfo", { url: omsRedirectionUrl, token: api_key }) + } else { + console.error("Some of the configuration of the app is missing."); + } + } else { + console.error("Some of the configuration of the app is missing.") + } + // TODO user single mutation commit(types.USER_CURRENT_ECOM_STORE_UPDATED, preferredStore); commit(types.USER_INFO_UPDATED, userProfile); @@ -83,7 +94,7 @@ const actions: ActionTree = { /** * Logout user */ - async logout ({ commit }, payload) { + async logout ({ commit, dispatch }, payload) { // store the url on which we need to redirect the user after logout api completes in case of SSO enabled let redirectionUrl = '' @@ -118,6 +129,7 @@ const actions: ActionTree = { this.dispatch("order/resetOrderQuery") this.dispatch("job/clearCtgryAndBrkrngJobs") this.dispatch("util/clearInvConfigs") + dispatch("setOmsRedirectionInfo", { url: "", token: "" }) resetPermissions(); // reset plugin state on logout @@ -167,7 +179,11 @@ const actions: ActionTree = { updatePwaState({ commit }, payload) { commit(types.USER_PWA_STATE_UPDATED, payload); - } + }, + + setOmsRedirectionInfo({ commit }, payload) { + commit(types.USER_OMS_REDIRECTION_INFO_UPDATED, payload) + }, } export default actions; \ No newline at end of file diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts index 7b32b1b3..d83675ac 100644 --- a/src/store/modules/user/index.ts +++ b/src/store/modules/user/index.ts @@ -16,6 +16,10 @@ const userModule: Module = { pwaState: { updateExists: false, registration: null, + }, + omsRedirectionInfo: { + url: "", + token: "" } }, getters, diff --git a/src/store/modules/user/mutation-types.ts b/src/store/modules/user/mutation-types.ts index 7100ad58..48cafc20 100644 --- a/src/store/modules/user/mutation-types.ts +++ b/src/store/modules/user/mutation-types.ts @@ -6,4 +6,5 @@ export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED' export const USER_PERMISSIONS_UPDATED = SN_USER + '/PERMISSIONS_UPDATED' export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED' export const USER_STORE_RSRV_INV_STATUS_UPDATED = SN_USER + '/STORE_RSRV_INV_STATUS_UPDATED' -export const USER_PWA_STATE_UPDATED = SN_USER + '/PWA_STATE_UPDATED' \ No newline at end of file +export const USER_PWA_STATE_UPDATED = SN_USER + '/PWA_STATE_UPDATED' +export const USER_OMS_REDIRECTION_INFO_UPDATED = SN_USER + '/OMS_REDIRECTION_INFO_UPDATED' diff --git a/src/store/modules/user/mutations.ts b/src/store/modules/user/mutations.ts index f9834596..087452d2 100644 --- a/src/store/modules/user/mutations.ts +++ b/src/store/modules/user/mutations.ts @@ -28,5 +28,8 @@ const mutations: MutationTree = { state.pwaState.registration = payload.registration; state.pwaState.updateExists = payload.updateExists; }, + [types.USER_OMS_REDIRECTION_INFO_UPDATED](state, payload) { + state.omsRedirectionInfo = payload; + } } export default mutations; \ No newline at end of file From 8a107c04c1d04b9d9f1a8e7fe2570c5c5a5dc057 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 4 Oct 2024 13:00:35 +0530 Subject: [PATCH 2/4] Implemented: logic to fetch brokering job from moqui (#299) --- src/services/JobService.ts | 104 +++++++++++++++++++++++- src/store/modules/job/JobState.ts | 3 +- src/store/modules/job/actions.ts | 45 ++++++++++ src/store/modules/job/getters.ts | 3 + src/store/modules/job/index.ts | 3 +- src/store/modules/job/mutation-types.ts | 3 +- src/store/modules/job/mutations.ts | 3 + src/store/modules/user/getters.ts | 3 + src/views/catalog-product-details.vue | 14 ++-- src/views/job-actions-popover.vue | 58 ++++++++++--- src/views/job-history-modal.vue | 48 +++++++++-- 11 files changed, 259 insertions(+), 28 deletions(-) diff --git a/src/services/JobService.ts b/src/services/JobService.ts index 5892fce1..80f70039 100644 --- a/src/services/JobService.ts +++ b/src/services/JobService.ts @@ -1,4 +1,4 @@ -import { api } from '@/adapter'; +import { api, client } from '@/adapter'; import store from '@/store' import { DateTime } from 'luxon'; @@ -153,15 +153,117 @@ const scheduleJob = async (payload: any): Promise => { }); } +const fetchBrokeringJobId = async (payload: any): Promise => { + return api({ + url: "performFind", + method: "get", + params: payload + }); +} + +const fetchBrokeringJobSchedule = async (routingGroupId: string): Promise => { + const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; + + const url = omsRedirectionInfo.url + const baseURL = url.startsWith('http') ? url.includes('/rest/s1/order-routing') ? url : `${url}/rest/s1/order-routing/` : `https://${url}.hotwax.io/rest/s1/order-routing/`; + + return client({ + url: `groups/${routingGroupId}/schedule`, + method: "GET", + baseURL, + headers: { + "api_key": omsRedirectionInfo.token, + "Content-Type": "application/json" + } + }); +} + +const fetchBrokeringJobActiveRun = async (jobName: string): Promise => { + const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; + + const url = omsRedirectionInfo.url + const baseURL = url.startsWith('http') ? url.includes('/rest/s1/order-routing') ? url : `${url}/rest/s1/order-routing/` : `https://${url}.hotwax.io/rest/s1/order-routing/`; + + return client({ + url: `serviceJobRuns/${jobName}/activeJobRun`, + method: "GET", + baseURL, + headers: { + "api_key": omsRedirectionInfo.token, + "Content-Type": "application/json" + } + }); +} + +const scheduleMaargJob = async (payload: any): Promise => { + const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; + + const url = omsRedirectionInfo.url + const baseURL = url.startsWith('http') ? url.includes('/rest/s1/order-routing') ? url : `${url}/rest/s1/order-routing/` : `https://${url}.hotwax.io/rest/s1/order-routing/`; + + return client({ + url: `groups/${payload.routingGroupId}/schedule`, + method: "POST", + baseURL, + data: payload, + headers: { + "api_key": omsRedirectionInfo.token, + "Content-Type": "application/json" + } + }); +} + + +const runMaargJobNow = async (routingGroupId: string): Promise => { + const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; + + const url = omsRedirectionInfo.url + const baseURL = url.startsWith('http') ? url.includes('/rest/s1/order-routing') ? url : `${url}/rest/s1/order-routing/` : `https://${url}.hotwax.io/rest/s1/order-routing/`; + + return client({ + url: `groups/${routingGroupId}/runNow`, + method: "POST", + baseURL, + headers: { + "api_key": omsRedirectionInfo.token, + "Content-Type": "application/json" + } + }); +} + +const fetchRoutingHistory = async (routingGroupId: string, params: any): Promise => { + const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; + + const url = omsRedirectionInfo.url + const baseURL = url.startsWith('http') ? url.includes('/rest/s1/order-routing') ? url : `${url}/rest/s1/order-routing/` : `https://${url}.hotwax.io/rest/s1/order-routing/`; + + return client({ + url: `groups/${routingGroupId}/routingRuns`, + method: "GET", + params, + baseURL, + headers: { + "api_key": omsRedirectionInfo.token, + "Content-Type": "application/json" + } + }); +} + export const JobService = { cancelJob, fetchBackgroundJobs, + fetchBrokeringJobActiveRun, + fetchBrokeringJobId, + fetchBrokeringJobSchedule, fetchJobLogs, fetchJobs, fetchJobInformation, + fetchRoutingHistory, pollJobs, prepareFetchJobsQuery, prepareFetchLogsQuery, scheduleJob, + scheduleMaargJob, + runMaargJobNow, runJobNow } \ No newline at end of file diff --git a/src/store/modules/job/JobState.ts b/src/store/modules/job/JobState.ts index c2349f87..3cc324c8 100644 --- a/src/store/modules/job/JobState.ts +++ b/src/store/modules/job/JobState.ts @@ -8,5 +8,6 @@ export default interface JobState { items: any[]; }, polling: boolean, - ctgryAndBrkrngJobs: any + ctgryAndBrkrngJobs: any, + brokeringJob: any } \ No newline at end of file diff --git a/src/store/modules/job/actions.ts b/src/store/modules/job/actions.ts index 628ec03f..aa230e44 100644 --- a/src/store/modules/job/actions.ts +++ b/src/store/modules/job/actions.ts @@ -175,6 +175,51 @@ const actions: ActionTree = { } return jobs; }, + + async fetchBrokeringJob ({ commit }) { + let resp = {} as any, jobId; + let jobInfo = {} as any; + + try { + resp = await JobService.fetchBrokeringJobId({ + "inputFields": { + "settingTypeEnumId": "JOB_BKR_ORD", + "productStoreId": this.state.user.currentEComStore?.productStoreId, + }, + "fieldList": ["settingTypeEnumId", "settingValue", "fromDate", "productStoreId"], + "entityName": "ProductStoreSetting", + "viewSize": 1, + "noConditionFind": "Y" + }) + + if(!hasError(resp)) { + jobId = resp.data.docs?.length ? resp.data.docs[0]?.settingValue : "" + + if(jobId) { + resp = await JobService.fetchBrokeringJobSchedule(jobId) + + if(!hasError(resp) && resp.data?.schedule) { + jobInfo = resp.data.schedule + resp = await JobService.fetchBrokeringJobActiveRun(jobInfo.jobName) + + if(!hasError(resp)) { + jobInfo["lastRunTime"] = resp.data.lastRunTime + jobInfo["routingGroupId"] = jobId + } else { + throw resp.data; + } + } else { + throw resp.data; + } + } + } + } catch(error: any) { + console.error(error); + } + + commit(types.JOB_BROKERING_JOB_UPDATED, jobInfo) + }, + clearCtgryAndBrkrngJobs({commit}) { commit(types.JOB_CTGRY_AND_BRKRNG_UPDATED, { jobs: [] }) } diff --git a/src/store/modules/job/getters.ts b/src/store/modules/job/getters.ts index 5e41a60a..0ff63d3d 100644 --- a/src/store/modules/job/getters.ts +++ b/src/store/modules/job/getters.ts @@ -20,6 +20,9 @@ const getters: GetterTree = { }, getCtgryAndBrkrngJob: (state) => (systemJobEnumId: string) => { return state.ctgryAndBrkrngJobs[systemJobEnumId] ? state.ctgryAndBrkrngJobs[systemJobEnumId] : {}; + }, + getBrokeringJob(state) { + return state.brokeringJob; } } export default getters; \ No newline at end of file diff --git a/src/store/modules/job/index.ts b/src/store/modules/job/index.ts index 98056db9..63f919fa 100644 --- a/src/store/modules/job/index.ts +++ b/src/store/modules/job/index.ts @@ -17,7 +17,8 @@ const jobModule: Module = { total: 0 }, polling: false, - ctgryAndBrkrngJobs: {} + ctgryAndBrkrngJobs: {}, + brokeringJob: {} }, getters, actions, diff --git a/src/store/modules/job/mutation-types.ts b/src/store/modules/job/mutation-types.ts index 9d80a97b..ba146cad 100644 --- a/src/store/modules/job/mutation-types.ts +++ b/src/store/modules/job/mutation-types.ts @@ -3,4 +3,5 @@ export const JOB_LIST_UPDATED = SN_JOB + '/LIST_UPDATED' export const JOB_LOGS_UPDATED = SN_JOB + '/LOGS_UPDATED' export const JOB_POLLING_UPDATED = SN_JOB + '/POLLING_UPDATED' export const JOB_UPDATED = SN_JOB + '/UPDATED' -export const JOB_CTGRY_AND_BRKRNG_UPDATED = SN_JOB + '/CTGRY_AND_BRKRNG_UPDATED' \ No newline at end of file +export const JOB_CTGRY_AND_BRKRNG_UPDATED = SN_JOB + '/CTGRY_AND_BRKRNG_UPDATED' +export const JOB_BROKERING_JOB_UPDATED = SN_JOB + '/BROKERING_JOB_UPDATED' \ No newline at end of file diff --git a/src/store/modules/job/mutations.ts b/src/store/modules/job/mutations.ts index 5823ebe2..f9058698 100644 --- a/src/store/modules/job/mutations.ts +++ b/src/store/modules/job/mutations.ts @@ -22,5 +22,8 @@ const mutations: MutationTree = { [types.JOB_CTGRY_AND_BRKRNG_UPDATED] (state, payload) { state.ctgryAndBrkrngJobs = payload; }, + [types.JOB_BROKERING_JOB_UPDATED] (state, payload) { + state.brokeringJob = payload; + }, } export default mutations; \ No newline at end of file diff --git a/src/store/modules/user/getters.ts b/src/store/modules/user/getters.ts index c00ce56f..10fc3a3b 100644 --- a/src/store/modules/user/getters.ts +++ b/src/store/modules/user/getters.ts @@ -32,6 +32,9 @@ const getters: GetterTree = { }, getCurrentEComStore(state) { return state.currentEComStore + }, + getOmsRedirectionInfo(state) { + return state.omsRedirectionInfo } } export default getters; \ No newline at end of file diff --git a/src/views/catalog-product-details.vue b/src/views/catalog-product-details.vue index 2fe4f942..dbdde1f3 100644 --- a/src/views/catalog-product-details.vue +++ b/src/views/catalog-product-details.vue @@ -295,13 +295,13 @@ - +

{{ $t('Order brokering') }}

-

{{ getCtgryAndBrkrngJob('JOB_BKR_ORD').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_BKR_ORD').lastRunTime) }}

+

{{ brokeringJob.lastRunTime && timeTillJob(brokeringJob.lastRunTime) }}

-

{{ getCtgryAndBrkrngJob('JOB_BKR_ORD').runTime ? timeTillJob(getCtgryAndBrkrngJob('JOB_BKR_ORD').runTime) : $t('disabled')}}

+

{{ (brokeringJob.paused === "N" && brokeringJob.nextExecutionDateTime) ? timeTillJob(brokeringJob.nextExecutionDateTime) : $t('disabled')}}

@@ -461,7 +461,8 @@ export default defineComponent({ product: "product/getCurrentCatalogProduct", currentEComStore: 'user/getCurrentEComStore', getCtgryAndBrkrngJob: "job/getCtgryAndBrkrngJob", - getInventoryConfig: "util/getInventoryConfig" + getInventoryConfig: "util/getInventoryConfig", + brokeringJob: "job/getBrokeringJob" }) }, async ionViewWillEnter() { @@ -550,15 +551,16 @@ export default defineComponent({ }, async getCtgryAndBrkrngJobs() { const systemJobEnumIds = JSON.parse(process.env.VUE_APP_CTGRY_AND_BRKRNG_JOB) + this.store.dispatch('job/fetchBrokeringJob') this.store.dispatch('job/fetchCtgryAndBrkrngJobs', { systemJobEnumIds }).then(() => { this.isCtgryAndBrkrngJobsLoaded = true }) }, - async openJobActionsPopover(event: Event, job: any, jobTitle: string) { + async openJobActionsPopover(event: Event, job: any, jobTitle: string, isMaargJob = false) { job.jobTitle = jobTitle const popover = await popoverController.create({ component: JobActionsPopover, - componentProps: { job }, + componentProps: { job, isMaargJob }, event, showBackdrop: false }); diff --git a/src/views/job-actions-popover.vue b/src/views/job-actions-popover.vue index 4cab508c..4b2ea3dc 100644 --- a/src/views/job-actions-popover.vue +++ b/src/views/job-actions-popover.vue @@ -7,8 +7,14 @@ {{ $t("Schedule in every 15 minutes") }}
+ + + + {{ $t("schedule") }} + + - + {{ $t("Run now") }} @@ -49,23 +55,42 @@ import { translate } from "@/i18n"; export default defineComponent({ name: "JobActionsPopover", - props: ["job"], + props: ["job", "isMaargJob"], components: { IonContent, IonIcon, IonItem, IonList }, + mounted() { + console.log(this.job); + }, methods: { closeJobActionsPopover() { popoverController.dismiss({ dismissed: true }); }, - async runNow() { + async runNow(job: any) { + let resp; + try { - const resp = await JobService.runJobNow(this.job) + if(this.isMaargJob) { + if(!job.jobName) { + resp = await JobService.scheduleMaargJob({ routingGroupId: job.routingGroupId, paused: 'Y' }) + if(hasError(resp)) { + throw resp.data; + } + // Updating jobName as if the user again clicks the runNow button then in that we don't want to call the scheduleBrokering service + job.jobName = resp.data.jobName + } + + resp = await JobService.runMaargJobNow(job.routingGroupId) + } else { + resp = await JobService.runJobNow(job) + } + if (!hasError(resp)) { showToast(translate('Service has been scheduled')) - await this.store.dispatch('job/fetchCtgryAndBrkrngJobs') + await Promise.allSettled([this.store.dispatch('job/fetchBrokeringJob'), this.store.dispatch('job/fetchCtgryAndBrkrngJobs')]) } else { showToast(translate('Something went wrong')) } @@ -79,16 +104,24 @@ export default defineComponent({ async openJobHistoryModal() { const jobHistoryModal = await modalController.create({ component: JobHistoryModal, - componentProps: { job: this.job } + componentProps: { job: this.job, isMaargJob: this.isMaargJob } }); return await jobHistoryModal.present(); }, async cancelJob() { + let resp; + console.log(this.isMaargJob); + try { - const resp = await JobService.cancelJob(this.job.jobId) + if(this.isMaargJob) { + resp = await JobService.scheduleMaargJob({ routingGroupId: this.job.routingGroupId, paused: 'Y' }) + } else { + resp = await JobService.cancelJob(this.job.jobId) + } + if (!hasError(resp)) { showToast(translate('Job cancelled successfully')) - await this.store.dispatch('job/fetchCtgryAndBrkrngJobs') + await Promise.allSettled([this.store.dispatch('job/fetchBrokeringJob'), this.store.dispatch('job/fetchCtgryAndBrkrngJobs')]) } else { showToast(translate('Something went wrong, could not cancel the job')) } @@ -117,11 +150,16 @@ export default defineComponent({ await alert.present(); }, async schdlInEvry15Mins() { + let resp; try { - const resp = await JobService.scheduleJob({ job: this.job, frequency: 'EVERY_15_MIN', runTime: '' }) + if(this.isMaargJob) { + resp = await JobService.scheduleMaargJob({ routingGroupId: this.job.routingGroupId, paused: 'N' }) + } else { + resp = await JobService.scheduleJob({ job: this.job, frequency: 'EVERY_15_MIN', runTime: '' }) + } if (!hasError(resp)) { showToast(translate('Service has been scheduled')); - await this.store.dispatch('job/fetchCtgryAndBrkrngJobs') + await Promise.allSettled([this.store.dispatch('job/fetchBrokeringJob'), this.store.dispatch('job/fetchCtgryAndBrkrngJobs')]) } else { showToast(translate('Something went wrong')) } diff --git a/src/views/job-history-modal.vue b/src/views/job-history-modal.vue index 568e6c5c..530dd240 100644 --- a/src/views/job-history-modal.vue +++ b/src/views/job-history-modal.vue @@ -18,11 +18,20 @@
- - {{ job.runTime ? getTime(job.runTime) : "-" }} -

{{ getDate(job.runTime) }}

-
- {{ getStatusDesc(job.statusId) }} + +
@@ -71,7 +80,7 @@ export default defineComponent({ jobHistory: [] as any } }, - props: ['job'], + props: ['job', 'isMaargJob'], computed: { ...mapGetters({ currentEComStore: 'user/getCurrentEComStore', @@ -112,11 +121,34 @@ export default defineComponent({ } catch(err) { console.error(err); } + }, + async fetchMaargJobHistory() { + try { + const resp = await JobService.fetchRoutingHistory(this.job.routingGroupId, { orderByField: "startDate DESC", pageSize: 500 }) + if(!hasError(resp)) { + const sortedRoutingHistory = resp.data.sort((a: any, b: any) => b.startDate - a.startDate) + this.jobHistory = sortedRoutingHistory + } else { + throw resp.data; + } + } catch(error: any) { + console.error(error) + } + }, + timeTillRun(endTime: any) { + const timeDiff = DateTime.fromMillis(endTime).diff(DateTime.local()); + return DateTime.local().plus(timeDiff).toRelative(); } }, async mounted() { - this.store.dispatch('util/getServiceStatusDesc') - await this.fetchJobHistory() + if(this.isMaargJob) { + await this.fetchMaargJobHistory(); + } else { + this.store.dispatch('util/getServiceStatusDesc') + await this.fetchJobHistory() + } + console.log(this.jobHistory); + }, setup() { const store = useStore(); From f1cef0a17e34715e8c8abf476e56c794eedf0847 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 4 Oct 2024 15:16:24 +0530 Subject: [PATCH 3/4] Implemented: logic to perform job scheduling actions (#299) --- .env.example | 2 +- src/views/catalog-product-details.vue | 2 +- src/views/job-actions-popover.vue | 28 ++++----------------------- src/views/job-history-modal.vue | 2 -- 4 files changed, 6 insertions(+), 28 deletions(-) diff --git a/.env.example b/.env.example index 6002fc9c..c186a06a 100644 --- a/.env.example +++ b/.env.example @@ -11,7 +11,7 @@ VUE_APP_BASE_URL= VUE_APP_ORDER_IN_BRKRNG_FILTERS=["orderTypeId: SALES_ORDER", "facilityId: _NA_", "orderStatusId: ORDER_APPROVED", "!orderItemStatusId: ITEM_CANCELLED" ] VUE_APP_PERMISSION_ID= VUE_APP_ALIAS= -VUE_APP_CTGRY_AND_BRKRNG_JOB=["JOB_REL_PREODR_CAT", "JOB_BKR_ORD", "JOB_RLS_ORD_DTE"] +VUE_APP_CTGRY_AND_BRKRNG_JOB=["JOB_REL_PREODR_CAT", "JOB_RLS_ORD_DTE"] VUE_APP_DEFAULT_ALIAS= VUE_APP_DEFAULT_LOG_LEVEL="error" VUE_APP_LOGIN_URL="http://launchpad.hotwax.io/login" \ No newline at end of file diff --git a/src/views/catalog-product-details.vue b/src/views/catalog-product-details.vue index dbdde1f3..3216c519 100644 --- a/src/views/catalog-product-details.vue +++ b/src/views/catalog-product-details.vue @@ -285,7 +285,7 @@
- +

{{ $t('Pre-sell computation') }}

{{ getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').lastRunTime) }}

diff --git a/src/views/job-actions-popover.vue b/src/views/job-actions-popover.vue index 4b2ea3dc..3d89da84 100644 --- a/src/views/job-actions-popover.vue +++ b/src/views/job-actions-popover.vue @@ -1,18 +1,12 @@