Skip to content

Commit

Permalink
Implemented: support to fetch the routings for routingGroup(#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Jan 16, 2024
1 parent f043448 commit 5a2a269
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ const routes: Array<RouteRecordRaw> = [
component: () => import("@/views/BrokeringRuns.vue")
},
{
path: "brokering/route",
component: () => import("@/views/BrokeringRoute.vue")
path: "brokering/:routingGroupId/routes",
component: () => import("@/views/BrokeringRoute.vue"),
props: true
},
{
path: "brokering/query",
Expand Down
9 changes: 9 additions & 0 deletions src/services/RoutingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ const createRoutingGroup = async (payload: any): Promise<any> => {
})
}

const fetchOrderRoutings = async (payload: any): Promise<any> => {
return api({
url: `groups/${payload.routingGroupId}/routings`,
method: "GET",
query: payload
});
}

export const OrderRoutingService = {
createRoutingGroup,
fetchOrderRoutings,
fetchRoutingGroups
}
30 changes: 30 additions & 0 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
showToast("Failed to create brokering run")
logger.error('err', err)
}
},

async setCurrentRoutingGroupId({ commit }, payload) {
commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, payload)
},

async fetchOrderRoutings({ commit }, routingGroupId) {
let orderRoutings = [] as any;
// filter groups on the basis of productStoreId
const payload = {
routingGroupId
}

try {
const resp = await OrderRoutingService.fetchOrderRoutings(payload);

if(!hasError(resp) && resp.data.length) {
orderRoutings = resp.data
} else {
throw resp.data
}
} catch(err) {
logger.error(err);
}

if(orderRoutings.length) {
orderRoutings = sortSequence(orderRoutings)
}

commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/orderRouting/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import RootState from "@/store/RootState"
const getters: GetterTree<OrderRoutingState, RootState> = {
getRoutingGroups(state) {
return state.groups
},
getOrderRoutings(state) {
return state.routes
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/orderRouting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const orderRoutingModule: Module<OrderRoutingState, RootState> = {
groups: [],
routes: [],
rule: [],
currentGroupId: '',
currentGroupId: '', // choosing only to save id and not whole object, as when updating the state we don't need to care updating the state on two different places
currentRouteId: ''
},
getters,
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/orderRouting/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const SN_ORDER_ROUTING = "orderRouting"
export const ORDER_ROUTING_GROUPS_UPDATED = SN_ORDER_ROUTING + "/GROUPS_UPDATED"
export const ORDER_ROUTING_ROUTES_UPDATED = SN_ORDER_ROUTING + "/ROUTES_UPDATED"
export const ORDER_ROUTINGS_UPDATED = SN_ORDER_ROUTING + "/ROUTES_UPDATED"
export const ORDER_ROUTING_RULE_UPDATED = SN_ORDER_ROUTING + "/RULE_UPDATED"
export const ORDER_ROUTING_CURRENT_GROUP_UPDATED = SN_ORDER_ROUTING + "/CURRENT_GROUP_UPDATED"
export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED"
2 changes: 1 addition & 1 deletion src/store/modules/orderRouting/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const mutations: MutationTree<OrderRoutingState> = {
[types.ORDER_ROUTING_GROUPS_UPDATED](state, payload) {
state.groups = payload
},
[types.ORDER_ROUTING_ROUTES_UPDATED](state, payload) {
[types.ORDER_ROUTINGS_UPDATED](state, payload) {
state.routes = payload
},
[types.ORDER_ROUTING_RULE_UPDATED](state, payload) {
Expand Down
27 changes: 21 additions & 6 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<ion-icon :icon="addCircleOutline" />
</ion-button>
</ion-list-header>
<ion-card v-for="card in [1, 2, 3, 4]" ref="cards" :key="card" @click="router.push('query')">
<ion-card v-for="routing in orderRoutings" :key="routing.orderRoutingId" @click="router.push('query')">
<ion-item lines="full">
<ion-label>
<h1>{{ "Order lookup name" }}</h1>
<h1>{{ routing.routingName }}</h1>
</ion-label>
<ion-chip>{{ `${card}/4` }}</ion-chip>
<ion-chip>{{ `${routing.sequenceNum}/4` }}</ion-chip>
</ion-item>
<ion-item ref="item">
<ion-badge>{{ "BADGE" }}</ion-badge>
<ion-item>
<ion-badge>{{ routing.statusId }}</ion-badge>
<ion-button fill="clear" color="medium" slot="end">
{{ "Archive" }}
</ion-button>
Expand Down Expand Up @@ -79,11 +79,26 @@
</template>

<script setup lang="ts">
import { IonBackButton, IonBadge, IonButtons, IonButton, IonCard, IonCardHeader, IonCardTitle, IonChip, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonListHeader, IonPage, IonTitle, IonToolbar } from "@ionic/vue";
import { IonBackButton, IonBadge, IonButtons, IonButton, IonCard, IonCardHeader, IonCardTitle, IonChip, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonListHeader, IonPage, IonTitle, IonToolbar, onIonViewWillEnter } from "@ionic/vue";
import { addCircleOutline, timeOutline, timerOutline } from "ionicons/icons"
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { computed, defineProps } from "vue";
const router = useRouter();
const store = useStore();
const props = defineProps({
routingGroupId: {
type: String,
required: true
}
})
const orderRoutings = computed(() => store.getters["orderRouting/getOrderRoutings"])
onIonViewWillEnter(async () => {
await store.dispatch('orderRouting/fetchOrderRoutings', props.routingGroupId)
})
</script>

<style scoped>
Expand Down
7 changes: 6 additions & 1 deletion src/views/BrokeringRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ion-content>
<main v-if="groups.length">
<section>
<ion-card v-for="group in groups" :key="group.routingGroupId" @click="router.push('brokering/route')">
<ion-card v-for="group in groups" :key="group.routingGroupId" @click="redirect(group.routingGroupId)">
<ion-card-header>
<ion-card-title>
{{ group.groupName }}
Expand Down Expand Up @@ -84,6 +84,11 @@ async function addNewRun() {
return newRunAlert.present();
}
async function redirect(routingGroupId: string) {
await store.dispatch('orderRouting/setCurrentRoutingGroupId', routingGroupId)
router.push(`brokering/${routingGroupId}/routes`)
}
</script>

<style scoped>
Expand Down

0 comments on commit 5a2a269

Please sign in to comment.