Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hotwax/preorder into preorder/
Browse files Browse the repository at this point in the history
  • Loading branch information
k2maan committed Sep 6, 2023
2 parents 58b2f7d + 9e9762b commit 836a16d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 74 deletions.
35 changes: 14 additions & 21 deletions src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<ion-menu-toggle auto-hide="false" v-for="(p, i) in appPages" :key="i">
<ion-item
button
@click="selectedIndex = i"
router-direction="root"
:router-link="p.url"
class="hydrated"
Expand Down Expand Up @@ -39,11 +38,12 @@ import {
IonMenu,
IonMenuToggle,
} from "@ionic/vue";
import { defineComponent, ref } from "vue";
import { computed, defineComponent} from "vue"
import { mapGetters } from "vuex";
import { albums ,shirt, pricetags, settings } from "ionicons/icons";
import { useStore } from "@/store";
import { useRouter } from "vue-router";
export default defineComponent({
name: "Menu",
Expand All @@ -59,30 +59,14 @@ export default defineComponent({
IonMenu,
IonMenuToggle,
},
created() {
// When open any specific page it should show that page selected
// TODO Find a better way
this.selectedIndex = this.appPages.findIndex((page) => {
return page.url === this.$router.currentRoute.value.path;
})
},
computed: {
...mapGetters({
isUserAuthenticated: 'user/isUserAuthenticated'
})
},
watch:{
$route (to) {
// When logout and login it should point to Oth index
// TODO Find a better way
if (to.path === '/login') {
this.selectedIndex = 0;
}
},
},
setup() {
const store = useStore();
const selectedIndex = ref(0);
const router = useRouter();
const appPages = [
{
title: "Orders",
Expand All @@ -93,12 +77,14 @@ export default defineComponent({
{
title: "Products",
url: "/products",
childRoutes: ["/product-details/"],
iosIcon: shirt,
mdIcon: shirt,
},
{
title: "Catalog",
url: "/catalog",
childRoutes: ["/catalog-product-details/"],
iosIcon: albums,
mdIcon: albums,
},
Expand All @@ -107,8 +93,15 @@ export default defineComponent({
url: "/settings",
iosIcon: settings,
mdIcon: settings,
},
}
];
const selectedIndex = computed(() => {
const path = router.currentRoute.value.path
return appPages.findIndex((screen) => screen.url === path || screen.childRoutes?.includes(path) || screen.childRoutes?.some((route)=> path.includes(route)))
})
return {
selectedIndex,
appPages,
Expand All @@ -118,7 +111,7 @@ export default defineComponent({
settings,
store
};
},
}
});
</script>
<style scoped>
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"preorders will be cancelled. This action cannot be undone.": "{count} preorders will be cancelled. This action cannot be undone.",
"Products": "Products",
"Product details": "Product details",
"Product summary": "Product summary",
"Product cannot be pre-sold because it does not have active purchase orders": "Product cannot be pre-sold because it does not have active purchase orders",
"Product has been accepting from against PO #": "Product has been accepting {category}s from {fromDate} against PO #${POID}",
"Product is eligible for but not added to the category": "Product is eligible for {category}s but not added to the {category} category",
Expand All @@ -164,7 +165,8 @@
"Release preorder to a warehouse": "Release preorder to a warehouse",
"Release preorders to a warehouse": "Release preorders to a warehouse",
"Release to a warehouse": "Release to a warehouse",
"Removing from in": "Removing from {categoryName} in {removeTime}",
"Removing from": "Removing from {categoryName} {removeTime}",
"Removed from": "Removed from {categoryName} {removeTime}",
"Removed from category": "Removed from category",
"Removed from category on because there is no active PO but still listed on stores": "Removed from {category} category on {changeDatetime} because there is no active PO but still listed on {listedCount} stores",
"Reserve inventory": "Reserve inventory",
Expand Down
3 changes: 0 additions & 3 deletions src/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ const actions: ActionTree<ProductState, RootState> = {
return product
}

emitter.emit("presentLoader")

let resp;
let productFilterCondition: any = `docType: PRODUCT AND groupId: ${payload.productId}`;
if (!isProductCached) productFilterCondition = `docType: PRODUCT AND (productId: ${payload.productId} OR groupId: ${payload.productId})`
Expand Down Expand Up @@ -260,7 +258,6 @@ const actions: ActionTree<ProductState, RootState> = {
console.error(error)
showToast(translate("Something went wrong"));
}
emitter.emit("dismissLoader");
return product
},
/**
Expand Down
95 changes: 46 additions & 49 deletions src/views/catalog-product-details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ion-buttons slot="start">
<ion-back-button default-href="/catalog"></ion-back-button>
</ion-buttons>
<ion-title>{{ $t("Product details") }}</ion-title>
<ion-title>{{ $t("Product summary") }}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
Expand Down Expand Up @@ -275,12 +275,7 @@
<h3>{{ $t('Category and brokering jobs') }}</h3>
</ion-card-title>
</ion-card-header>
<div v-if="!Object.keys(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT')).length
|| !Object.keys(getCtgryAndBrkrngJob('JOB_BKR_ORD')).length
|| !Object.keys(getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE')).length">
<ion-item>
<ion-skeleton-text animated style="height: 40%; width: 70%;" />
</ion-item>
<div v-if="!isCtgryAndBrkrngJobsLoaded">
<ion-item>
<ion-skeleton-text animated style="height: 30%; width: 40%;" />
</ion-item>
Expand All @@ -292,44 +287,35 @@
</ion-item>
</div>
<div v-else>
<!-- in case jobs are not available -->
<div v-if="!Object.keys(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT')).length
&& !Object.keys(getCtgryAndBrkrngJob('JOB_BKR_ORD')).length
&& !Object.keys(getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE')).length">
<ion-item>{{ $t("No jobs found") }}</ion-item>
</div>

<div v-else>
<ion-item detail button @click="openJobActionsPopover($event, getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT'), 'Pre-sell computation')">
<ion-label class="ion-text-wrap">
<h3>{{ $t('Pre-sell computation') }}</h3>
<p>{{ getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').lastRunTime) }}</p>
</ion-label>
<ion-label slot="end">
<p>{{ getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').runTime ? timeTillJob(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').runTime) : $t('disabled')}}</p>
</ion-label>
</ion-item>
<ion-item v-if="Object.keys(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT')).length" detail button @click="openJobActionsPopover($event, getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT'), 'Pre-sell computation')">
<ion-label class="ion-text-wrap">
<h3>{{ $t('Pre-sell computation') }}</h3>
<p>{{ getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').lastRunTime) }}</p>
</ion-label>
<ion-label slot="end">
<p>{{ getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').runTime ? timeTillJob(getCtgryAndBrkrngJob('JOB_REL_PREODR_CAT').runTime) : $t('disabled')}}</p>
</ion-label>
</ion-item>

<ion-item detail button @click="openJobActionsPopover($event, getCtgryAndBrkrngJob('JOB_BKR_ORD'), 'Order brokering')">
<ion-label class="ion-text-wrap">
<h3>{{ $t('Order brokering') }}</h3>
<p>{{ getCtgryAndBrkrngJob('JOB_BKR_ORD').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_BKR_ORD').lastRunTime) }}</p>
</ion-label>
<ion-label slot="end">
<p>{{ getCtgryAndBrkrngJob('JOB_BKR_ORD').runTime ? timeTillJob(getCtgryAndBrkrngJob('JOB_BKR_ORD').runTime) : $t('disabled')}}</p>
</ion-label>
</ion-item>
<ion-item v-if="Object.keys(getCtgryAndBrkrngJob('JOB_BKR_ORD')).length " detail button @click="openJobActionsPopover($event, getCtgryAndBrkrngJob('JOB_BKR_ORD'), 'Order brokering')">
<ion-label class="ion-text-wrap">
<h3>{{ $t('Order brokering') }}</h3>
<p>{{ getCtgryAndBrkrngJob('JOB_BKR_ORD').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_BKR_ORD').lastRunTime) }}</p>
</ion-label>
<ion-label slot="end">
<p>{{ getCtgryAndBrkrngJob('JOB_BKR_ORD').runTime ? timeTillJob(getCtgryAndBrkrngJob('JOB_BKR_ORD').runTime) : $t('disabled')}}</p>
</ion-label>
</ion-item>

<ion-item detail button @click="openJobActionsPopover($event, getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE'), 'Auto releasing')">
<ion-label class="ion-text-wrap">
<h3>{{ $t('Auto releasing') }}</h3>
<p>{{ getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').lastRunTime) }}</p>
</ion-label>
<ion-label slot="end">
<p>{{ getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').runTime ? timeTillJob(getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').runTime) : $t('disabled')}}</p>
</ion-label>
</ion-item>
</div>
<ion-item v-if="Object.keys(getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE')).length" detail button @click="openJobActionsPopover($event, getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE'), 'Auto releasing')">
<ion-label class="ion-text-wrap">
<h3>{{ $t('Auto releasing') }}</h3>
<p>{{ getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').lastRunTime && timeTillJob(getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').lastRunTime) }}</p>
</ion-label>
<ion-label slot="end">
<p>{{ getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').runTime ? timeTillJob(getCtgryAndBrkrngJob('JOB_RLS_ORD_DTE').runTime) : $t('disabled')}}</p>
</ion-label>
</ion-item>
</div>
</ion-card>

Expand Down Expand Up @@ -466,7 +452,8 @@ export default defineComponent({
configsByStores: [] as any,
listingJobRunTime: 0,
backorderCategoryId: '',
preOrderCategoryId: ''
preOrderCategoryId: '',
isCtgryAndBrkrngJobsLoaded: false
}
},
computed: {
Expand Down Expand Up @@ -569,7 +556,9 @@ export default defineComponent({
},
async getCtgryAndBrkrngJobs() {
const systemJobEnumIds = JSON.parse(process.env.VUE_APP_CTGRY_AND_BRKRNG_JOB)
await this.store.dispatch('job/fetchCtgryAndBrkrngJobs', { systemJobEnumIds })
this.store.dispatch('job/fetchCtgryAndBrkrngJobs', { systemJobEnumIds }).then(() => {
this.isCtgryAndBrkrngJobsLoaded = true
})
},
async openJobActionsPopover(event: Event, job: any, jobTitle: string) {
job.jobTitle = jobTitle
Expand Down Expand Up @@ -832,7 +821,6 @@ export default defineComponent({
async preparePoSummary() {
this.poSummary.eligible = this.poAndAtpDetails.totalPoAtp > 0 && this.atpCalcDetails.onlineAtp === 0;


const productCategories = this.currentVariant.productCategories;
const hasPreOrderCategory = productCategories?.includes(this.preOrderCategoryId);
const hasBackorderCategory = productCategories?.includes(this.backorderCategoryId);
Expand Down Expand Up @@ -873,7 +861,8 @@ export default defineComponent({
if (Object.keys(presellingJob).length === 0 || !presellingJob.runTime) {
this.poSummary.header = this.$t("Pre-sell processing disabled");
} else {
this.poSummary.header = this.$t("Removing from in", { categoryName, addingTime: this.timeTillJob(presellingJob.runTime) });
const headerMessage = this.isPastTime(presellingJob.runTime) ? "Removed from" : "Removing from";
this.poSummary.header = this.$t(headerMessage, { categoryName, removeTime: this.timeTillJob(presellingJob.runTime) });
}
if (this.atpCalcDetails.onlineAtp > 0) {
this.poSummary.body = this.$t("This product will be removed from because it is in stock", { categoryName });
Expand Down Expand Up @@ -951,7 +940,6 @@ export default defineComponent({
}
},
async prepareShopListings() {

// TODO Use ShopifyShopProduct to check if product is associated
this.shopListings = []
try {
Expand Down Expand Up @@ -984,7 +972,7 @@ export default defineComponent({
return shopifyConfigsAndProductIds
}, {})

await Promise.allSettled(Object.keys(configs).sort().map(async (shopId: any) => {
await Promise.allSettled(Object.keys(configs).map(async (shopId: any) => {
const configAndIdData = shopifyConfigsAndProductIds[shopId];
let listData = {
...configs[shopId], // adding shopify shop information to be available for showing name
Expand Down Expand Up @@ -1067,6 +1055,10 @@ export default defineComponent({
}
return externalId;
},
isPastTime(time: number) {
const timeDiff: any = DateTime.fromMillis(time).diff(DateTime.local());
return timeDiff.values.milliseconds <= 0;
},
async copyAuditMsg() {
const { Clipboard } = Plugins;
const auditMsg = this.poSummary.header + '\n' + this.poSummary.body
Expand All @@ -1077,6 +1069,11 @@ export default defineComponent({
showToast(this.$t("Copied to clipboard"));
})
},
getSortedShopListings(shopListings: any) {
// using return based sorting instead of localeCompare
// as localeCompare is slower
return shopListings.sort((a: any, b: any) => a.name < b.name ? -1 : 1)
}
},
setup() {
const store = useStore();
Expand Down

0 comments on commit 836a16d

Please sign in to comment.