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: support to check the oms connection status before scheduling a group(#49) #54

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ const fetchFacilityGroups = async (payload: any): Promise<any> => {
});
}

const checkOmsConnection = async (): Promise<any> => {
return api({
url: `checkOmsConnection`,
method: "GET"
});
}

export const UtilService = {
checkOmsConnection,
fetchEnums,
fetchFacilities,
fetchFacilityGroups,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const actions: ActionTree<UserState, RootState> = {
// TODO add any other tasks if need
commit(types.USER_END_SESSION)
this.dispatch("orderRouting/clearRouting")
this.dispatch("util/clearUtilState")
},

/**
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default interface UtilState {
};
facilities: object;
shippingMethods: object;
facilityGroups: object
facilityGroups: object;
isOmsConnectionExist: boolean | undefined;
}
19 changes: 19 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ const actions: ActionTree<UtilState, RootState> = {
}

commit(types.UTIL_FACILITY_GROUP_UPDATED, facilityGroups)
},

async checkOmsConnectionStatus({ commit }) {
let isOmsConnectionExist = false
try {
const resp = await UtilService.checkOmsConnection();

if(!hasError(resp)) {
isOmsConnectionExist = true
}
} catch(err) {
logger.error('error', err)
}

commit(types.UTIL_OMS_CONNECTION_STATUS_UPDATED, isOmsConnectionExist)
},

async clearUtilState({ commit }) {
commit(types.UTIL_CLEARED)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/util/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const getters: GetterTree<UtilState, RootState> = {
},
getFacilityGroups(state) {
return state.facilityGroups
},
isOmsConnectionExist(state) {
return state.isOmsConnectionExist
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const utilModule: Module<UtilState, RootState> = {
enums: {},
facilities: {},
shippingMethods: {},
facilityGroups: {}
facilityGroups: {},
isOmsConnectionExist: undefined
},
getters,
actions,
Expand Down
4 changes: 3 additions & 1 deletion src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export const SN_UTIL = "util"
export const UTIL_ENUMS_UPDATED = SN_UTIL + "/ENUMS_UPDATED"
export const UTIL_FACILITIES_UPDATED = SN_UTIL + "/FACILITIES_UPDATED"
export const UTIL_SHIPPING_METHOD_UPDATED = SN_UTIL + "/SHIPPING_METHOD_UPDATED"
export const UTIL_FACILITY_GROUP_UPDATED = SN_UTIL + "/FACILITY_GROUP_UPDATED"
export const UTIL_FACILITY_GROUP_UPDATED = SN_UTIL + "/FACILITY_GROUP_UPDATED"
export const UTIL_OMS_CONNECTION_STATUS_UPDATED = SN_UTIL + "/OMS_CONNECTION_STATUS_UPDATED"
export const UTIL_CLEARED = SN_UTIL + "/CLEARED"
10 changes: 10 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ const mutations: MutationTree<UtilState> = {
},
[types.UTIL_FACILITY_GROUP_UPDATED](state, payload) {
state.facilityGroups = payload
},
[types.UTIL_OMS_CONNECTION_STATUS_UPDATED](state, payload) {
state.isOmsConnectionExist = payload
},
[types.UTIL_CLEARED](state) {
state.enums = {}
state.facilities = {}
state.shippingMethods = {}
state.facilityGroups = {}
state.isOmsConnectionExist = undefined
}
}
export default mutations;
29 changes: 26 additions & 3 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
{{ "Scheduler" }}
</ion-card-title>
</ion-card-header>
<ion-item v-show="typeof isOmsConnectionExist === 'boolean' && !isOmsConnectionExist" lines="none">
<ion-label color="danger" class="ion-text-wrap">
{{ "Connection configuration is missing for oms." }}
</ion-label>
<ion-button fill="clear" @click="checkOmsConnectionStatus">
<ion-icon slot="icon-only" :icon="refreshOutline" />
</ion-button>
</ion-item>
<ion-item>
<ion-icon slot="start" :icon="timerOutline"/>
<ion-select label="Schedule" interface="popover" :placeholder="$t('Select')" :value="job.cronExpression" @ionChange="updateCronExpression($event)">
Expand All @@ -80,10 +88,10 @@
</ion-card>
<div class="actions desktop-only">
<div>
<ion-button size="small" fill="outline" color="danger" @click="disable">{{ "Disable" }}</ion-button>
<ion-button :disabled="typeof isOmsConnectionExist === 'boolean' && !isOmsConnectionExist" size="small" fill="outline" color="danger" @click="disable">{{ "Disable" }}</ion-button>
</div>
<div>
<ion-button size="small" fill="outline" @click="saveChanges()">{{ "Save changes" }}</ion-button>
<ion-button :disabled="typeof isOmsConnectionExist === 'boolean' && !isOmsConnectionExist" size="small" fill="outline" @click="saveChanges()">{{ "Save changes" }}</ion-button>
</div>
</div>
<ion-item>
Expand All @@ -106,7 +114,7 @@

<script setup lang="ts">
import { IonBackButton, IonBadge, IonButtons, IonButton, IonCard, IonCardHeader, IonCardTitle, IonChip, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonListHeader, IonPage, IonReorder, IonReorderGroup, IonSelect, IonSelectOption, IonTextarea, IonTitle, IonToolbar, alertController, modalController, onIonViewWillEnter } from "@ionic/vue";
import { addCircleOutline, archiveOutline, reorderTwoOutline, saveOutline, timerOutline } from "ionicons/icons"
import { addCircleOutline, archiveOutline, refreshOutline, reorderTwoOutline, saveOutline, timerOutline } from "ionicons/icons"
import { onBeforeRouteLeave, useRouter } from "vue-router";
import { useStore } from "vuex";
import { computed, defineProps, ref } from "vue";
Expand Down Expand Up @@ -139,6 +147,7 @@ let orderRoutings = ref([]) as any

const currentRoutingGroup: any = computed((): Group => store.getters["orderRouting/getCurrentRoutingGroup"])
const currentEComStore = computed(() => store.getters["user/getCurrentEComStore"])
const isOmsConnectionExist = computed(() => store.getters["util/isOmsConnectionExist"])

onIonViewWillEnter(async () => {
await store.dispatch("orderRouting/fetchCurrentRoutingGroup", props.routingGroupId)
Expand Down Expand Up @@ -190,10 +199,24 @@ function initializeOrderRoutings() {
routingsForReorder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
}

async function checkOmsConnectionStatus() {
await store.dispatch("util/checkOmsConnectionStatus")
}

async function saveChanges() {
// If this is the first time then we are fetching the omsConnection status, as if the value of isOmsConnectionExist value is a boolean it means we have previously fetched the connection status
if(typeof isOmsConnectionExist.value !== "boolean") {
await checkOmsConnectionStatus()
}

if(!isOmsConnectionExist.value) {
return;
}

if(!job.value.cronExpression) {
showToast("Please select a scheduling for job")
logger.error("Please select a scheduling for job")
return;
}

const payload = {
Expand Down
Loading