Skip to content

Commit

Permalink
Merge pull request #37 from ymaheshwari1/#24
Browse files Browse the repository at this point in the history
Improved logic for order filters, added support for new rule creation and improved support for reordering of rule(#24)
  • Loading branch information
ymaheshwari1 authored Jan 23, 2024
2 parents 850a3af + ef9935e commit 119a78a
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ VUE_APP_DEFAULT_LOG_LEVEL="error"
VUE_APP_RULE_ENUMS={"FILTER":"ENTCT_FILTER","SORT":"ENTCT_SORT_BY","QUEUE":{"id":"OIP_QUEUE","code":"facilityId"},"SHIPPING_METHOD":{"id":"OIP_SHIP_METH_TYPE","code":"shipmentMethodTypeId"},"PRIORITY":{"id":"OIP_PRIORITY","code":"priority"},"PROMISE_DATE":{"id":"OIP_PROMISE_DATE","code":"promiseDaysCutoff"},"SALES_CHANNEL":{"id":"OIP_SALES_CHANNEL","code":"salesChannelEnumId"},"SHIP_BY":{"id":"OSP_SHIP_BY","code":"shipBeforeDate"},"SHIP_AFTER":{"id":"OSP_SHIP_AFTER","code":"shipAfterDate"},"ORDER_DATE":{"id":"OSP_ORDER_DATE","code":"orderDate"},"SHIPPING_METHOD_SORT":{"id":"OSP_SHIP_METH","code":"deliveryDays"}}
VUE_APP_RULE_FILTER_ENUMS={"FACILITY_GROUP":{"id":"IIP_FACILITY_GROUP","code":"facilityGroupId"},"PROXIMITY":{"id":"IIP_PROXIMITY","code":"distance"},"BRK_SAFETY_STOCK":{"id":"IIP_BRK_SFTY_STOCK","code":"brokeringSafetyStock"},"MEASUREMENT_SYSTEM":{"id":"IIP_MSMNT_SYSTEM","code":"measurementSystem"}}
VUE_APP_RULE_SORT_ENUMS={"PROXIMITY":{"id":"ISP_PROXIMITY","code":"distance"},"INV_BALANCE":{"id":"ISP_INV_BAL","code":"inventoryForAllocation"},"CUSTOMER_SEQ":{"id":"ISP_CUST_SEQ","code":"facilitySequence"}}
VUE_APP_RULE_ACTION_ENUMS={"AUTO_CANCEL_DAYS":{"id":"ORA_AUTO_CANCEL_DATE","code":"ADD_AUTO_CANCEL_DATE"},"NEXT_RULE":{"id":"ORA_NEXT_RULE","code":"NEXT_RULE"},"MOVE_TO_QUEUE":{"id":"ORA_MV_TO_QUEUE","code":"MOVE_TO_QUEUE"}}
VUE_APP_RULE_ACTION_ENUMS={"AUTO_CANCEL_DAYS":{"id":"ORA_AUTO_CANCEL_DAYS","code":"ADD_AUTO_CANCEL_DATE"},"NEXT_RULE":{"id":"ORA_NEXT_RULE","code":"NEXT_RULE"},"MOVE_TO_QUEUE":{"id":"ORA_MV_TO_QUEUE","code":"MOVE_TO_QUEUE"}}
VUE_APP_ROUTE_STATUS_ENUMS={"ROUTING_DRAFT":{"id":"ROUTING_DRAFT","desc":"Draft","code":"DRAFT","color":"medium"},"ROUTING_ACTIVE":{"id":"ROUTING_ACTIVE","desc":"Active","code":"ACTIVE","color":"success"},"ROUTING_ARCHIVED":{"id":"ROUTING_ARCHIVED","desc":"Archived","code":"ARCHIVED","color":"warning"}}
103 changes: 103 additions & 0 deletions src/components/AddOrderRouteFilterOptions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>{{ "Order Rule Sort" }}</ion-title>
<ion-buttons slot="end">
<ion-button @click="closeModal()">{{ $t('Close') }}</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item v-for="sort in Object.values(enums[props.parentEnumId] ? enums[props.parentEnumId] : {})" :key="sort.enumId">
<ion-checkbox :checked="isSortOptionSelected(sort.enumCode)" @ionChange="addSortOption(sort)">{{ sort.description || sort.enumCode }}</ion-checkbox>
</ion-item>
</ion-list>

<ion-fab vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button @click="saveSortOptions()">
<ion-icon :icon="saveOutline" />
</ion-fab-button>
</ion-fab>
</ion-content>
</ion-page>
</template>

<script setup lang="ts">
import { IonButton, IonButtons, IonCheckbox, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonItem, IonList, IonPage, IonTitle, IonToolbar, modalController } from "@ionic/vue";
import { useStore } from "vuex";
import { computed, defineProps, onMounted, ref } from "vue";
import { saveOutline } from "ionicons/icons";
const store = useStore();
const enums = computed(() => store.getters["util/getEnums"])
const props = defineProps({
orderRoutingId: {
type: String,
required: true
},
orderRoutingFilters: {
type: Object,
required: true
},
parentEnumId: {
type: String,
required: true
},
conditionTypeEnumId: {
type: String,
required: true
}
})
let routingFilters = ref({}) as any
onMounted(() => {
routingFilters.value = props.orderRoutingFilters ? JSON.parse(JSON.stringify(props.orderRoutingFilters)) : {}
})
function addSortOption(sort: any) {
const isSortOptionAlreadyApplied = isSortOptionSelected(sort.enumCode)?.fieldName
if(isSortOptionAlreadyApplied) {
delete routingFilters.value[props.conditionTypeEnumId][sort.enumCode]
} else {
// checking unchecking an option and then checking it again, we need to use the same values
if(props.orderRoutingFilters[props.conditionTypeEnumId]?.[sort.enumCode]) {
routingFilters.value[props.conditionTypeEnumId][sort.enumCode] = props.orderRoutingFilters[props.conditionTypeEnumId][sort.enumCode]
} else {
// when adding a new value, we don't need to pass conditionSeqId
// Added check that whether the filters for the conditionType exists or not, if not then create a new value for conditionType
routingFilters.value[props.conditionTypeEnumId] ? routingFilters.value[props.conditionTypeEnumId][sort.enumCode] = {
orderRoutingId: props.orderRoutingId,
conditionTypeEnumId: props.conditionTypeEnumId,
fieldName: sort.enumCode,
sequenceNum: Object.keys(routingFilters.value[props.conditionTypeEnumId]).length && routingFilters.value[props.conditionTypeEnumId][Object.keys(routingFilters.value[props.conditionTypeEnumId])[Object.keys(routingFilters.value[props.conditionTypeEnumId]).length - 1]]?.sequenceNum >= 0 ? routingFilters.value[props.conditionTypeEnumId][Object.keys(routingFilters.value[props.conditionTypeEnumId])[Object.keys(routingFilters.value[props.conditionTypeEnumId]).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0
} : routingFilters.value = {
...routingFilters.value,
[props.conditionTypeEnumId]: {
[sort.enumCode]: {
orderRoutingId: props.orderRoutingId,
conditionTypeEnumId: props.conditionTypeEnumId,
fieldName: sort.enumCode,
sequenceNum: 0
}
}
}
}
}
}
function saveSortOptions() {
closeModal(routingFilters.value, 'save');
}
function isSortOptionSelected(code: string) {
return routingFilters.value[props.conditionTypeEnumId]?.[code]
}
function closeModal(filters = {}, action = 'close') {
modalController.dismiss({ dismissed: true, filters }, action)
}
</script>
58 changes: 58 additions & 0 deletions src/components/PromiseFilterPopover.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<ion-content>
<ion-list>
<ion-list-header>
<ion-label>{{ $t("Promise date") }}</ion-label>
</ion-list-header>
<ion-item button @click="updatePromiseDate()">
<ion-label>{{ $t("Already passed") }}</ion-label>
</ion-item>
<ion-item button @click="updatePromiseDate('Upcoming duration')">
<ion-label>{{ $t("Upcoming duration") }}</ion-label>
</ion-item>
<ion-item button lines="none" @click="updatePromiseDate('Passed duration', true)">
<ion-label>{{ $t("Passed duration") }}</ion-label>
</ion-item>
</ion-list>
</ion-content>
</template>

<script setup lang="ts">
import { IonContent, IonItem, IonLabel, IonList, IonListHeader, alertController, popoverController } from "@ionic/vue";
async function updatePromiseDate(header = '', isPastDuration = false) {
let duration = 0
if(!header) {
popoverController.dismiss({ duration })
return;
}
const durationAlert = await alertController.create({
header,
buttons: [{
text: "Cancel",
role: "cancel"
}, {
text: "Save"
}],
inputs: [{
name: "duration",
placeholder: "duration"
}]
})
durationAlert.onDidDismiss().then(async (result: any) => {
// considered that if a role is available on dismiss, it will be a negative role in which we don't need to perform any action
if(result.role) {
return;
}
// TODO: add checks for duration value
const duration = result.data?.values?.duration;
popoverController.dismiss({ duration, isPastDuration })
})
return durationAlert.present();
}
</script>
48 changes: 31 additions & 17 deletions src/services/RoutingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ const fetchOrderRoutings = async (payload: any): Promise<any> => {
});
}

const fetchOrderRouting = async (orderRoutingId: string): Promise<any> => {
return api({
url: `routings/${orderRoutingId}`,
method: "GET"
})
}

const updateOrderRouting = async (payload: any): Promise<any> => {
return api({
url: `routings/${payload.orderRoutingId}`,
Expand All @@ -50,23 +57,11 @@ const updateOrderRouting = async (payload: any): Promise<any> => {
}

const createRoutingRule = async (payload: any): Promise<any> => {
let routingRuleId = '';
try {
const resp = await api({
url: "rules",
method: "POST",
data: payload
})

if(!hasError(resp) && resp?.data.routingRuleId) {
routingRuleId = resp.data.routingRuleId
}
} catch(err) {
showToast("Failed to create new rule")
logger.error(err)
}

return routingRuleId
return await api({
url: "rules",
method: "POST",
data: payload
})
}

const createOrderRouting = async (payload: any): Promise<any> => {
Expand All @@ -93,6 +88,22 @@ const fetchRoutingFilters = async (payload: any): Promise<any> => {
});
}

const updateRoutingFilter = async (payload: any): Promise<any> => {
return api({
url: `routings/${payload.orderRoutingId}/filter-conditions`,
method: "POST",
data: payload
});
}

const deleteRoutingFilter = async (payload: any): Promise<any> => {
return api({
url: `routings/${payload.orderRoutingId}/filter-conditions`,
method: "DELETE",
data: payload
});
}

const fetchRuleConditions = async (payload: any): Promise<any> => {
return api({
url: `rules/${payload.routingRuleId}/condition`,
Expand All @@ -113,6 +124,8 @@ export const OrderRoutingService = {
createOrderRouting,
createRoutingGroup,
createRoutingRule,
deleteRoutingFilter,
fetchOrderRouting,
fetchOrderRoutings,
fetchRoutingFilters,
fetchRoutingGroup,
Expand All @@ -121,5 +134,6 @@ export const OrderRoutingService = {
fetchRuleActions,
fetchRuleConditions,
updateOrderRouting,
updateRoutingFilter,
updateRoutingGroup
}
2 changes: 1 addition & 1 deletion src/store/modules/orderRouting/OrderRoutingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default interface OrderRoutingState {
routes: Array<any>;
rules: Array<any>;
currentGroup: any;
currentRouteId: string;
currentRoute: any;
currentRouteFilters: {
[key: string]: { // conditionTypeEnumId as key
[key: string]: RouteFilter // enumCode/fieldName as key
Expand Down
Loading

0 comments on commit 119a78a

Please sign in to comment.