Skip to content

Commit

Permalink
Merge pull request #40 from ymaheshwari1/#39
Browse files Browse the repository at this point in the history
Implementes: support to schedule and update a job(#39)
  • Loading branch information
ymaheshwari1 authored Jan 25, 2024
2 parents 729936c + ff15d2d commit c7736d5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ VUE_APP_RULE_ENUMS={"QUEUE":{"id":"OIP_QUEUE","code":"facilityId"},"SHIPPING_MET
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_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"}}
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"}}
VUE_APP_CRON_EXPRESSIONS={"Every 30 minutes":"0 */30 * ? * *","Hourly":"0 0 * ? * *","Every six hours":"0 0 */6 ? * *","Every day at midnight":"0 0 0 * * ?"}
11 changes: 9 additions & 2 deletions src/services/RoutingService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import api from "@/api"
import logger from "@/logger";
import { hasError, showToast } from "@/utils";

const fetchRoutingGroups = async (payload: any): Promise<any> => {
return api({
Expand Down Expand Up @@ -136,6 +134,14 @@ const fetchRuleActions = async (payload: any): Promise<any> => {
});
}

const scheduleBrokering = async (payload: any): Promise<any> => {
return api({
url: `groups/${payload.routingGroupId}/schedule`,
method: "POST",
data: payload
});
}

export const OrderRoutingService = {
createOrderRouting,
createRoutingGroup,
Expand All @@ -151,6 +157,7 @@ export const OrderRoutingService = {
fetchRoutingRules,
fetchRuleActions,
fetchRuleConditions,
scheduleBrokering,
updateOrderRouting,
updateRoutingFilter,
updateRoutingGroup
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/orderRouting/getters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GetterTree } from "vuex"
import OrderRoutingState from "./OrderRoutingState"
import RootState from "@/store/RootState"
import { Group, Route } from "@/types"

const getters: GetterTree<OrderRoutingState, RootState> = {
getRoutingGroups(state) {
Expand Down
102 changes: 89 additions & 13 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,26 @@
{{ "Scheduler" }}
</ion-card-title>
</ion-card-header>
<ion-item>
<ion-icon slot="start" :icon="timeOutline"/>
<ion-label>{{ "Run time" }}</ion-label>
<!-- <ion-label slot="end">{{ currentRoutingGroup.runTime || "-" }}</ion-label> -->
</ion-item>
<ion-item>
<ion-icon slot="start" :icon="timerOutline"/>
<ion-label>{{ "Schedule" }}</ion-label>
<!-- <ion-label slot="end">{{ currentRoutingGroup.frequency || "-" }}</ion-label> -->
<ion-select label="Schedule" interface="popover" :placeholder="$t('Select')" :value="job.cronExpression" @ionChange="updateCronExpression($event)">
<ion-select-option v-for="(expression, description) in cronExpressions" :key="expression" :value="expression">{{ description }}</ion-select-option>
</ion-select>
</ion-item>
</ion-card>
<div class="actions desktop-only">
<div>
<ion-button 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>
</div>
</div>
<ion-item>
{{ `Created at ${currentRoutingGroup.createdDate || "-"}` }}
{{ `Created at ${getTime(currentRoutingGroup.createdDate)}` }}
</ion-item>
<ion-item>
{{ `Updated at ${currentRoutingGroup.lastUpdatedStamp || "-"}` }}
{{ `Updated at ${getTime(currentRoutingGroup.lastUpdatedStamp)}` }}
</ion-item>
</aside>
</section>
Expand All @@ -101,14 +105,18 @@
</template>

<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, IonTextarea, IonTitle, IonToolbar, alertController, modalController, onIonViewWillEnter, onIonViewWillLeave } from "@ionic/vue";
import { addCircleOutline, archiveOutline, reorderTwoOutline, saveOutline, timeOutline, timerOutline } from "ionicons/icons"
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, onIonViewWillLeave } from "@ionic/vue";
import { addCircleOutline, archiveOutline, reorderTwoOutline, saveOutline, timerOutline } from "ionicons/icons"
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { computed, defineProps, onMounted, ref } from "vue";
import { computed, defineProps, ref } from "vue";
import { Group, Route } from "@/types";
import ArchivedRoutingModal from "@/components/ArchivedRoutingModal.vue"
import emitter from "@/event-bus";
import { OrderRoutingService } from "@/services/RoutingService";
import logger from "@/logger";
import { DateTime } from "luxon";
import { hasError, showToast } from "@/utils";
const router = useRouter();
const store = useStore();
Expand All @@ -120,20 +128,25 @@ const props = defineProps({
})
const routingStatus = JSON.parse(process.env?.VUE_APP_ROUTE_STATUS_ENUMS as string)
const cronExpressions = JSON.parse(process.env?.VUE_APP_CRON_EXPRESSIONS as string)
let routingsToUpdate = ref([])
let initialRoutingsOrder = ref([])
let routingsForReorder = ref([])
let description = ref('')
let isDescUpdating = ref(false)
const currentRoutingGroup = computed((): Group => store.getters["orderRouting/getCurrentRoutingGroup"])
let job = ref({}) as any
const currentRoutingGroup: any = computed((): Group => store.getters["orderRouting/getCurrentRoutingGroup"])
const orderRoutings = computed(() => store.getters["orderRouting/getOrderRoutings"])
onIonViewWillEnter(async () => {
await Promise.all([store.dispatch("orderRouting/fetchOrderRoutings", props.routingGroupId), store.dispatch("orderRouting/fetchCurrentRoutingGroup", props.routingGroupId)])
initializeOrderRoutings();
job.value = currentRoutingGroup.value["schedule"] ? JSON.parse(JSON.stringify(currentRoutingGroup.value))["schedule"] : {}
description.value = currentRoutingGroup.value.description ? currentRoutingGroup.value.description : "No description available"
emitter.on("initializeOrderRoutings", initializeOrderRoutings)
})
Expand All @@ -142,11 +155,56 @@ onIonViewWillLeave(() => {
emitter.off("initializeOrderRoutings", initializeOrderRoutings)
})
function updateCronExpression(event: CustomEvent) {
job.value.cronExpression = event.detail.value
}
function getTime(time: any) {
return time ? DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED) : '-';
}
function initializeOrderRoutings() {
initialRoutingsOrder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
routingsForReorder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
}
async function saveChanges() {
if(!job.value.cronExpression) {
logger.error('Please select an expression before proceeding')
}
const payload = {
routingGroupId: props.routingGroupId,
paused: "N", // considering job in active status as soon as scheduled
...job.value
}
try {
const resp = await OrderRoutingService.scheduleBrokering(payload)
if(!hasError(resp)){
showToast("Job updated")
}
} catch(err) {
logger.error(err)
}
}
async function disable() {
const payload = {
routingGroupId: props.routingGroupId,
paused: "Y" // setting Y to disable the job
}
try {
const resp = await OrderRoutingService.scheduleBrokering(payload)
if(!hasError(resp)){
showToast("Job disabled")
}
} catch(err) {
logger.error(err)
}
}
async function redirect(orderRouting: Route) {
await store.dispatch('orderRouting/setCurrentOrderRouting', orderRouting)
router.push(`${orderRouting.orderRoutingId}/rules`)
Expand Down Expand Up @@ -281,4 +339,22 @@ ion-content > div > div {
justify-content: space-between;
border-right: 1px solid #92949C;
}
ion-modal.date-time-modal {
--width: 290px;
--height: 440px;
--border-radius: 8px;
}
.actions > ion-button {
margin: var(--spacer-sm);
}
@media (min-width: 991px) {
.actions {
display: flex;
justify-content: space-between;
margin: var(--spacer-base) var(--spacer-sm) var(--spacer-base);
}
}
</style>

0 comments on commit c7736d5

Please sign in to comment.