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

[WIP]Implemented: support of oms-api package in the product module and updated the code as per the updated schema(#2k0bk8x) #108

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9be111b
Implemented: code to update token and instanceUrl on app initializati…
ymaheshwari1 Jul 15, 2022
3e4f057
Improved: code to use fetchProduct method when displaying information…
ymaheshwari1 Jul 15, 2022
cde73a2
Improved: the views to display the product images and updated method …
ymaheshwari1 Jul 15, 2022
8be3fef
Improved: package.json and lock file to include the oms-api package a…
ymaheshwari1 Jul 15, 2022
fccff61
Improved: code as per the changes in the package resp and updated the…
ymaheshwari1 Jul 19, 2022
6cc9776
Removed: product service as using oms package for fetching the produc…
ymaheshwari1 Aug 9, 2022
cd31c54
Improved: the version for the oms api and updated the product action(…
ymaheshwari1 Aug 26, 2022
304bf08
Merge branch 'main' of https://github.com/hotwax/receiving into #2k0bk8x
ymaheshwari1 Nov 21, 2022
d09311c
Updated: user state to store primary and secondary pref for product a…
ymaheshwari1 Nov 23, 2022
82c4a2b
Improved: code clear cached product whenever the primary or secondary…
ymaheshwari1 Nov 23, 2022
91448a4
Added an option to de-select secondary id, defined default values for…
ymaheshwari1 Nov 24, 2022
2b5a363
Updated: the icon for primary and secondary id on settings page(#2k0b…
ymaheshwari1 Nov 24, 2022
994c411
Updated: hotwax/oms-api package version and also updated the lock fil…
ymaheshwari1 Nov 24, 2022
6ac6f62
Reverted: changes to update product id config to oms package and also…
ymaheshwari1 Nov 24, 2022
c680689
Merge branch 'main' of https://github.com/hotwax/receiving into #2k0bk8x
ymaheshwari1 Nov 24, 2022
3d66e3a
Implemented: an adapter to import and export all methods from oms pac…
ymaheshwari1 Dec 2, 2022
8beaae4
Updated: the version for oms-api package(#2k0bk8x)
ymaheshwari1 Dec 2, 2022
4ea9024
Updated: queryString param value, added type for products inside app …
ymaheshwari1 Dec 2, 2022
6f2904d
Reverted: changes related to handling of primary and secondary identi…
ymaheshwari1 Dec 5, 2022
45b90c6
Merge branch 'main' of https://github.com/hotwax/receiving into #2k0bk8x
ymaheshwari1 Dec 5, 2022
e079592
Merge branch 'main' of https://github.com/hotwax/receiving into #2k0bk8x
ymaheshwari1 Dec 30, 2022
326acb1
Added: optional chaining for accessing product indentification(#2k0bk8x)
ymaheshwari1 Dec 30, 2022
52079d9
Improved: code to add condition to only call getProductIdentification…
ymaheshwari1 Dec 30, 2022
aa668ce
Improved: method to get product identification value(#2k0bk8x)
ymaheshwari1 Jan 3, 2023
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
411 changes: 237 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@capacitor/android": "^2.4.7",
"@capacitor/core": "^2.4.7",
"@hotwax/oms-api": "^1.0.1",
"@ionic/core": "6.2.9",
"@ionic/vue": "6.2.9",
"@ionic/vue-router": "6.2.9",
Expand Down
12 changes: 10 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import Menu from '@/components/Menu.vue';
import { defineComponent } from 'vue';
import { loadingController } from '@ionic/vue';
import emitter from "@/event-bus"
import { mapGetters, useStore } from "vuex";
import { mapGetters, useStore } from 'vuex';
import { updateToken, updateInstanceUrl } from '@/adapter'

export default defineComponent({
name: 'App',
Expand All @@ -32,7 +33,9 @@ export default defineComponent({
...mapGetters({
currentEComStore: 'user/getCurrentEComStore',
productIdentifications: 'util/getProductIdentifications',
userProfile: 'user/getUserProfile'
userProfile: 'user/getUserProfile',
userToken: 'user/getUserToken',
instanceUrl: 'user/getInstanceUrl'
})
},
methods: {
Expand Down Expand Up @@ -72,10 +75,15 @@ export default defineComponent({
if(this.userProfile) {
this.store.dispatch('user/getProductIdentificationPref', this.currentEComStore.productStoreId);
}

updateToken(this.userToken)
updateInstanceUrl(this.instanceUrl)
},
unmounted() {
emitter.off('presentLoader', this.presentLoader);
emitter.off('dismissLoader', this.dismissLoader);
updateToken('')
updateInstanceUrl('')
},
setup() {
const store = useStore();
Expand Down
17 changes: 17 additions & 0 deletions src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
fetchProducts,
init,
isError,
Product,
updateToken,
updateInstanceUrl
} from '@hotwax/oms-api'

export {
fetchProducts,
init,
isError,
Product,
updateToken,
updateInstanceUrl
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import './theme/variables.css';

import i18n from './i18n'
import store from './store'
import { init } from '@/adapter';

const app = createApp(App)
.use(IonicVue, {
Expand Down Expand Up @@ -63,6 +64,7 @@ app.config.globalProperties.$filters = {
}
}

init(store.getters['user/getUserToken'], store.getters['user/getInstanceUrl'], 3000)

router.isReady().then(() => {
app.mount('#app');
Expand Down
14 changes: 0 additions & 14 deletions src/services/ProductService.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/store/modules/product/ProductState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Product } from '@/adapter'

export default interface ProductState {
cached: any;
list: {
total: number;
items: any[];
items: Array<Product>;
}
}
50 changes: 26 additions & 24 deletions src/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import { ProductService } from '@/services/ProductService'
import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import ProductState from './ProductState'
import * as types from './mutation-types'
import { hasError, showToast } from '@/utils'
import { showToast } from '@/utils'
import emitter from '@/event-bus'
import { translate } from '@/i18n'
import { isError, fetchProducts, Product } from '@/adapter'

const actions: ActionTree<ProductState, RootState> = {
async fetchProducts ({commit, state}, { productIds }) {
const cachedProductIds = Object.keys(state.cached)
const productIdFilter = productIds.reduce((filter: string, productId: any) => {
// If product already exist in cached products skip
if (cachedProductIds.includes(productId)) {
return filter;
} else {
if (filter !== '') filter += ' OR '
return filter += productId;
const productIdFilter= productIds.reduce((filter: Array<any>, productId: any) => {
// If product does not exist in cached products then add the id
if (!cachedProductIds.includes(productId) && productId) {
filter.push(productId);
}
}, '');
return filter;
}, []);

if(productIdFilter === '') return;
const resp = await ProductService.fetchProducts({
"viewSize": productIds.length,
"filters": ['productId: (' + productIdFilter + ')']
// If there are no product ids to search skip the API call
if (productIdFilter.length <= 0) return;
const resp = await fetchProducts({
filters: { 'productId': { 'value': productIdFilter, 'op': 'OR' }},
viewSize: productIdFilter.length,
viewIndex: 0
})
if (resp.status === 200 && !hasError(resp)) {
const products = resp.data.response.docs;
if (!isError(resp) && resp.total > 0) {
const products: Array<Product> = resp.products;
// Handled empty response in case of failed query
if (resp.data) {
if (products) {
commit(types.PRODUCT_ADD_TO_CACHED_MULTIPLE, { products });
}
} else {
commit(types.PRODUCT_ADD_TO_CACHED_MULTIPLE, { products: [] });
}

if (productIds.viewIndex === 0) emitter.emit("dismissLoader");
Expand All @@ -41,15 +43,15 @@ const actions: ActionTree<ProductState, RootState> = {
let resp;
if (payload.viewIndex === 0) emitter.emit("presentLoader");
try {
resp = await ProductService.fetchProducts({
"filters": ['isVirtual: false'],
resp = await fetchProducts({
"filters": { 'isVirtual': { 'value': false }},
"viewSize": payload.viewSize,
"viewIndex": payload.viewIndex,
"keyword": payload.queryString
"viewIndex": payload.viewIndex * payload.viewSize,
"queryString": payload.queryString
})
if (resp.status === 200 && resp.data.response?.docs.length > 0 && !hasError(resp)) {
let products = resp.data.response.docs;
const total = resp.data.response.numFound;
if (!isError(resp)) {
let products: Product = resp.products;
const total = resp.total;

if (payload.viewIndex && payload.viewIndex > 0) products = state.list.items.concat(products)
commit(types.PRODUCT_LIST_UPDATED, { products, total });
Expand Down
5 changes: 5 additions & 0 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { translate } from '@/i18n'
import moment from 'moment';
import emitter from '@/event-bus'
import "moment-timezone";
import { updateInstanceUrl, updateToken } from '@/adapter'

const actions: ActionTree<UserState, RootState> = {

Expand Down Expand Up @@ -47,6 +48,7 @@ const actions: ActionTree<UserState, RootState> = {
}
} else {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
updateToken(resp.data.token)
await dispatch('getProfile')
return resp.data;
}
Expand Down Expand Up @@ -74,6 +76,8 @@ const actions: ActionTree<UserState, RootState> = {
async logout ({ commit }) {
// TODO add any other tasks if need
commit(types.USER_END_SESSION)
updateToken('')
updateInstanceUrl('')
this.dispatch('util/setProductIdentifications', [])
},

Expand Down Expand Up @@ -138,6 +142,7 @@ const actions: ActionTree<UserState, RootState> = {
// Set User Instance Url
setUserInstanceUrl ({ commit }, payload){
commit(types.USER_INSTANCE_URL_UPDATED, payload)
updateInstanceUrl(payload)
},

async getFacilityLocations( { commit }, facilityId ) {
Expand Down
16 changes: 4 additions & 12 deletions src/utils/product/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const getProductIdentificationValue = (productIdentifier: string, product: any) => {
import { Product } from "@/adapter";

// handled this case as on page load initially the data is not available, so not to execute furthur code
// untill product are not available
if(!Object.keys(product).length) {
return;
}
const getProductIdentificationValue = (productIdentifier: string, product: Product) => {

let value = product[productIdentifier]

// considered that the goodIdentification will always have values in the format "productIdentifier/value" and there will be no entry like "productIdentifier/"
const identification = product['goodIdentifications'].find((identification: string) => identification.startsWith(productIdentifier + "/"))

if(identification) {
const goodIdentification = identification.split('/')
value = goodIdentification[1]
if(!value) {
value = product['identifications']?.find((identification: any) => identification.productIdTypeEnumId === productIdentifier)?.idValue
}

return value;
Expand Down
8 changes: 4 additions & 4 deletions src/views/AddProductModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<ion-list v-for="product in products" :key="product.productId">
<ion-item lines="none">
<ion-thumbnail slot="start">
<Image :src="product.mainImageUrl" />
<Image :src="product.images?.mainImageUrl" />
</ion-thumbnail>
<ion-label>
<h2>{{ product.productName}}</h2>
<p>{{ product.productId}}</p>
<h2>{{ product.productName }}</h2>
<p>{{ product.productId }}</p>
</ion-label>
<ion-icon v-if="isProductAvailableInShipment(product.productId)" color="success" :icon="checkmarkCircle" />
<ion-button v-else fill="outline" @click="addtoShipment(product)">{{ $t("Add to Shipment") }}</ion-button>
Expand Down Expand Up @@ -96,7 +96,7 @@ export default defineComponent({
const payload = {
viewSize,
viewIndex,
queryString: '*' + this.queryString + '*'
queryString: this.queryString
}
if (this.queryString) {
await this.store.dispatch("product/findProduct", payload);
Expand Down
8 changes: 4 additions & 4 deletions src/views/AddProductToPOModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<ion-list v-for="product in products" :key="product.productId">
<ion-item lines="none">
<ion-thumbnail slot="start">
<Image :src="product.mainImageUrl" />
<Image :src="product.images?.mainImageUrl" />
</ion-thumbnail>
<ion-label>
<h2>{{ product.productName}}</h2>
<p>{{ product.productId}}</p>
<h2>{{ product.productName }}</h2>
<p>{{ product.productId }}</p>
</ion-label>
<ion-icon v-if="isProductAvailableInOrder(product.productId)" color="success" :icon="checkmarkCircle" />
<ion-button v-else fill="outline" @click="addtoOrder(product)">{{ $t("Add to Purchase Order") }}</ion-button>
Expand Down Expand Up @@ -96,7 +96,7 @@ export default defineComponent({
const payload = {
viewSize,
viewIndex,
queryString: '*' + this.queryString + '*'
queryString: this.queryString
}
if (this.queryString) {
await this.store.dispatch("product/findProduct", payload);
Expand Down
6 changes: 3 additions & 3 deletions src/views/PurchaseOrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
<div class="product">
<div class="product-info">
<ion-item lines="none">
<ion-thumbnail slot="start" @click="openImage(getProduct(item.productId).mainImageUrl, getProduct(item.productId).productName)">
<Image :src="getProduct(item.productId).mainImageUrl" />
<ion-thumbnail slot="start" @click="openImage(getProduct(item.productId).images?.mainImageUrl, getProduct(item.productId).productName)">
<Image :src="getProduct(item.productId).images?.mainImageUrl" />
</ion-thumbnail>
<ion-label class="ion-text-wrap">
<ion-label class="ion-text-wrap" v-if="getProduct(item.productId)">
<h2>{{ productHelpers.getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(item.productId)) }}</h2>
<p>{{ productHelpers.getProductIdentificationValue(productIdentificationPref.secondaryId, getProduct(item.productId)) }}</p>
</ion-label>
Expand Down
2 changes: 1 addition & 1 deletion src/views/ReceivingHistoryModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ion-list v-for="(item, index) in poHistory.items" :key="index">
<ion-item>
<ion-thumbnail slot="start">
<Image :src="getProduct(item.productId).mainImageUrl" />
<Image :src="getProduct(item.productId).images?.mainImageUrl" />
</ion-thumbnail>
<ion-label>
{{ item.receivedByUserLoginId }}
Expand Down
6 changes: 3 additions & 3 deletions src/views/ReturnDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
<div class="product">
<div class="product-info">
<ion-item lines="none">
<ion-thumbnail slot="start" @click="openImage(getProduct(item.productId).mainImageUrl, getProduct(item.productId).productName)">
<Image :src="getProduct(item.productId).mainImageUrl" />
<ion-thumbnail slot="start" @click="openImage(getProduct(item.productId).images?.mainImageUrl, getProduct(item.productId).productName)">
<Image :src="getProduct(item.productId).images?.mainImageUrl" />
</ion-thumbnail>
<ion-label class="ion-text-wrap">
<ion-label class="ion-text-wrap" v-if="getProduct(item.productId)">
<h2>{{ productHelpers.getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(item.productId)) }}</h2>
<p>{{ productHelpers.getProductIdentificationValue(productIdentificationPref.secondaryId, getProduct(item.productId)) }}</p>
</ion-label>
Expand Down
6 changes: 3 additions & 3 deletions src/views/ShipmentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
<div class="product">
<div class="product-info">
<ion-item lines="none">
<ion-thumbnail slot="start" @click="openImage(getProduct(item.productId).mainImageUrl, getProduct(item.productId).productName)">
<Image :src="getProduct(item.productId).mainImageUrl" />
<ion-thumbnail slot="start" @click="openImage(getProduct(item.productId).images?.mainImageUrl, getProduct(item.productId).productName)">
<Image :src="getProduct(item.productId).images?.mainImageUrl" />
</ion-thumbnail>
<ion-label class="ion-text-wrap">
<ion-label class="ion-text-wrap" v-if="getProduct(item.productId)">
<h2>{{ productHelpers.getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(item.productId)) }}</h2>
<p>{{ productHelpers.getProductIdentificationValue(productIdentificationPref.secondaryId, getProduct(item.productId)) }}</p>
</ion-label>
Expand Down