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

Implemented: logic to create search preference and schedule a service (#29bdb9f) #40

Merged
merged 22 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
681cb9f
Implemented: UI for the save threshold modal and bind that modal with…
ymaheshwari1 May 4, 2022
d65572b
Improved: logic to prepare the query for the products(#29bdb9f)
ymaheshwari1 May 4, 2022
39ce6b0
Improved: code to add the static text in the en.json file(#29bdb9f)
ymaheshwari1 May 4, 2022
c387eb1
Implemented: code to define the logic to add search preference and ac…
ymaheshwari1 May 4, 2022
19059ce
Merge branch 'main' of https://github.com/hotwax/threshold-management…
ymaheshwari1 May 4, 2022
2905c01
Implemented: code to store the shopify config on the basis of product…
ymaheshwari1 May 4, 2022
923f410
Implemented: code to define the service to get the shopify config(#29…
ymaheshwari1 May 4, 2022
9e1e687
Implemented: logic to define method for creating search preference an…
ymaheshwari1 May 4, 2022
e7bc854
Implemented: condition to show an alert when a user does not enter a …
ymaheshwari1 May 5, 2022
ac0f2ce
Updated: en.json file(#29bdb9f)
ymaheshwari1 May 5, 2022
654af65
Improved: logic to save search preference and schedule a job(#29bdb9f)
ymaheshwari1 May 5, 2022
a23c9b4
Improved: code to handle the error condition when creating search pre…
ymaheshwari1 May 5, 2022
ac99ca2
Removed: unwanted console statement(#29bdb9f)
ymaheshwari1 May 5, 2022
25f63e8
Improved: logic to handle the viewSize when searching for a job(#29bd…
ymaheshwari1 May 5, 2022
9e37389
Updated: code by adding comments on multiple places(#29bdb9f)
ymaheshwari1 May 5, 2022
bbc327d
Updated: condition to handle the threshold default value(#29bdb9f)
ymaheshwari1 May 5, 2022
4d8120b
Merge branch 'main' of https://github.com/hotwax/threshold-management…
ymaheshwari1 May 5, 2022
3eb0ca6
Improved: code to optimize the logic for preparing the query(#29bdb9f)
ymaheshwari1 May 5, 2022
eec6959
Improved: code to pass viewSize when fetching shopify config, improve…
ymaheshwari1 May 5, 2022
fbac943
Improved: code to make the total sku count on the save threshold moda…
ymaheshwari1 May 5, 2022
e0812a1
Improved: logic to handle the response from the action when fetching …
ymaheshwari1 May 5, 2022
2d5969a
Updated: en.json file to add static message(#29bdb9f)
ymaheshwari1 May 5, 2022
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
204 changes: 204 additions & 0 deletions src/components/SaveThresholdModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<template>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button @click="closeModal">
<ion-icon slot="icon-only" :icon="closeOutline" />
</ion-button>
</ion-buttons>
<ion-title>{{ $t("Save threshold rule") }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<ion-list>
<ion-list-header>{{ $t("Info") }}</ion-list-header>
<ion-item>
<ion-icon :icon="shirtOutline" slot="start" />
<ion-label>{{ totalSKUs }} {{ $t('SKUs') }}</ion-label>
</ion-item>
<ion-item>
<ion-icon :icon="optionsOutline" slot="start" />
<ion-label>{{ threshold }} {{ $t('threshold') }}</ion-label>
</ion-item>

<ion-item>
<ion-label>{{ $t("Rule name") }}</ion-label>
<ion-input :placeholder="$t('rule name')" v-model="jobName"/>
</ion-item>
</ion-list>

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

<script lang="ts">
import { defineComponent } from 'vue';
import {
IonButton,
IonButtons,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonInput,
IonItem,
IonLabel,
IonList,
IonListHeader,
IonTitle,
IonToolbar,
modalController
} from '@ionic/vue';
import {
closeOutline,
shirtOutline,
optionsOutline,
cloudUploadOutline
} from 'ionicons/icons';
import { ProductService } from '@/services/ProductService';
import { hasError, showToast } from '@/utils';
import { translate } from '@/i18n';
import { mapGetters, useStore } from 'vuex';
import { DateTime } from 'luxon';
import { JobService } from '@/services/JobService';

export default defineComponent({
name: 'SaveThresholdModal',
components: {
IonButton,
IonButtons,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonInput,
IonItem,
IonLabel,
IonList,
IonListHeader,
IonTitle,
IonToolbar
},
props: ["threshold", "query", "totalSKUs"],
data () {
return {
jobName: ''
}
},
computed: {
...mapGetters({
currentEComStore: 'user/getCurrentEComStore',
shopifyConfig: 'util/getShopifyConfig',
jobs: 'job/getJobs'
})
},
methods: {
closeModal() {
modalController.dismiss({ dismissed: true });
},
async saveThresholdRule() {
const solrQuery = this.query

// removed params object from query as there is no need for grouping or pagination when storing the query
delete solrQuery.json.params
// made the query to default (*:*) before storing, as the threshold will be set for all the products those
// are fullfilling the filters condition
solrQuery.json['query'] = "*:*"

try {
const resp = await ProductService.createSearchPreference({
searchPrefValue: JSON.stringify(solrQuery)
});

if (resp.status == 200 && resp?.data?.searchPrefId) {
const searchPrefId = resp.data.searchPrefId;
this.scheduleService(searchPrefId, this.threshold)
} else {
showToast(translate('Something went wrong'))
}
} catch (err) {
console.error(err)
showToast(translate('Something went wrong'))
}
},
async scheduleService(searchPrefId: string, threshold: string) {
let job = this.jobs['ping']
const productStoreId = this.currentEComStore.productStoreId
let shopifyConfigId = this.shopifyConfig[productStoreId]
let resp = '' as any;

if (!job) {
await this.store.dispatch('job/fetchJobs', {
inputFields: {
statusId: "SERVICE_DRAFT",
statusId_op: "equals",
systemJobEnumId: "ping",
},
viewSize: 1
})
job = this.jobs['ping']
}

if(!shopifyConfigId) {
const resp = await this.store.dispatch('util/getShopifyConfig', productStoreId)
shopifyConfigId = resp[productStoreId]
}

const payload = job ? {
'JOB_NAME': this.jobName ? this.jobName : job.jobName,
'SERVICE_NAME': job.serviceName,
'SERVICE_COUNT': '0',
'jobFields': {
'productStoreId': productStoreId,
'systemJobEnumId': job.systemJobEnumId,
'tempExprId': job.tempExprId,
'maxRecurrenceCount': '-1',
'parentJobId': job.parentJobId,
'runAsUser': 'system', // default system, but empty in run now
'recurrenceTimeZone': DateTime.now().zoneName
},
'shopifyConfigId': shopifyConfigId,
'statusId': "SERVICE_PENDING",
'systemJobEnumId': job.systemJobEnumId,
searchPrefId,
threshold
} as any : {}

// checking if the runtimeData has productStoreId, and if present then adding it on root level
job?.runtimeData?.productStoreId?.length >= 0 && (payload['productStoreId'] = productStoreId)
job?.priority && (payload['SERVICE_PRIORITY'] = job.priority.toString())

try {
resp = await JobService.scheduleJob({ ...job.runtimeData, ...payload });
if (resp.status == 200 && !hasError(resp)) {
showToast(translate('Service has been scheduled'))
} else {
showToast(translate('Something went wrong'))
}
} catch (err) {
showToast(translate('Something went wrong'))
console.error(err)
}
return resp;
}
},
setup() {
const store = useStore();

return {
closeOutline,
cloudUploadOutline,
shirtOutline,
optionsOutline,
store
};
},
});
</script>
8 changes: 8 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"Don't skip": "Don't skip",
"Download": "Download",
"Download data in csv": "Download data in csv",
"Enter threshold value": "Enter threshold value",
"Every 5 minutes": "Every 5 minutes",
"Every 15 minutes": "Every 15 minutes",
"Every 30 minutes": "Every 30 minutes",
Expand All @@ -35,19 +36,23 @@
"No previous occurrence": "No previous occurrence",
"Only show selected products": "Only show selected products",
"Pending": "Pending",
"Please enter a threshold value to set for these products before proceeding.": "Please enter a threshold value to set for these products before proceeding.",
"Product list": "Product list",
"Product SKU column": "Product SKU column",
"Products not found": "Products not found",
"products selected": "products selected",
"Ok": "Ok",
"OMS": "OMS",
"Ready to create an app?": "Ready to create an app?",
"reset": "reset",
"retry": "retry",
"rule name": "rule name",
"Running": "Running",
"Run time": "Run time",
"Save changes": "Save changes",
"Schedule": "Schedule",
"Results": "Results",
"Rule name": "Rule name",
"Safety stock": "Safety stock",
"Save": "Save",
"Save threshold rule": "Save threshold rule",
Expand All @@ -61,9 +66,11 @@
"Select locations": "Select locations",
"Select the column index for the following information in the uploaded CSV": "Select the column index for the following information in the uploaded CSV",
"Select run time": "Select run time",
"Service has been scheduled": "Service has been scheduled",
"Set safety stock": "Set safety stock",
"Settings": "Settings",
"Shop": "Shop",
"SKUs": "SKUs",
"Size": "Size",
"Skip": "Skip",
"Skip job": "Skip job",
Expand All @@ -81,6 +88,7 @@
"There are no jobs pending right now": "There are no jobs pending right now",
"There are no jobs running right now": "There are no jobs running right now",
"Tags": "Tags",
"threshold": "threshold",
"Threshold": "Threshold",
"Threshold management": "Threshold management",
"Threshold Management": "Threshold Management",
Expand Down
9 changes: 9 additions & 0 deletions src/services/ProductService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ const fetchProductFacets = async (payload: any): Promise<any> => {
})
}

const createSearchPreference = async (payload: any): Promise<any> => {
return api({
url: "service/createSearchPreference",
method: "post",
data: payload
});
}

export const ProductService = {
createSearchPreference,
fetchProducts,
fetchProductFacets,
getProducts
Expand Down
11 changes: 10 additions & 1 deletion src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const getServiceStatusDesc = async (payload: any): Promise<any> => {
});
}

const getShopifyConfig = async (payload: any): Promise <any> => {
return api({
url: "performFind",
method: "post",
data: payload
});
}

export const UtilService = {
getServiceStatusDesc
getServiceStatusDesc,
getShopifyConfig
}
2 changes: 1 addition & 1 deletion src/store/modules/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const actions: ActionTree<JobState, RootState> = {
},
"entityName": "JobSandbox",
"noConditionFind": "Y",
"viewSize": (payload.inputFields?.systemJobEnumId?.length * 2)
"viewSize": payload.viewSize ? payload.viewSize : (payload.inputFields?.systemJobEnumId?.length * 2)
})
if (resp.status === 200 && !hasError(resp) && resp.data.docs) {
const cached = JSON.parse(JSON.stringify(state.cached));
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/job/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const getters: GetterTree <JobState, RootState> = {
getJobHistory (state){
return state.history.list;
},
getJobs: (state) => {
return state.cached;
}
}

export default getters;
1 change: 1 addition & 0 deletions src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default interface UtilState {
statusDesc: any;
shopifyConfig: any;
}
19 changes: 19 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ const actions: ActionTree<UtilState, RootState> = {
console.error(err)
}
},

async getShopifyConfig({ commit }, payload) {
// TODO: for now passing view size as 1 by considering that one product store id is associated with only
// one shopify config
const resp = await UtilService.getShopifyConfig({
"inputFields": {
"productStoreId": payload
},
"entityName": "ShopifyConfig",
"noConditionFind": "Y",
"fieldList": ["shopifyConfigId", "productStoreId"],
"viewSize": 1
})

if (resp.status === 200 && !hasError(resp)) {
commit(types.UTIL_SHOPIFY_CONFIG_UPDATED, resp.data.docs?.length > 0 ? resp.data.docs[0] : {});
return resp.data.docs[0];
}
},
}

export default actions;
5 changes: 4 additions & 1 deletion src/store/modules/util/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 <UtilState, RootState> = {
getStatusDesc: (state) => (statusId: any) => {
return state.statusDesc[statusId] ? state.statusDesc[statusId] : "-";
}
},
getShopifyConfig(state) {
return state.shopifyConfig
}
}
export default getters;
3 changes: 2 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import RootState from '@/store/RootState'
const utilModule: Module<UtilState, RootState> = {
namespaced: true,
state: {
statusDesc: {}
statusDesc: {},
shopifyConfig: {}
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const SN_UTIL = 'util'
export const UTIL_SERVICE_STATUS_DESC_UPDATED = SN_UTIL + '/SERVICE_STATUS_DESC_UPDATED'
export const UTIL_SERVICE_STATUS_DESC_UPDATED = SN_UTIL + '/SERVICE_STATUS_DESC_UPDATED'
export const UTIL_SHOPIFY_CONFIG_UPDATED = SN_UTIL + '/SHOPIFY_CONFIG_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const mutations: MutationTree <UtilState> = {
payload.map((status: any) => {
state.statusDesc[status.statusId] = status.description;
})
},
[types.UTIL_SHOPIFY_CONFIG_UPDATED] (state, payload) {
state.shopifyConfig[payload.productStoreId] = payload.shopifyConfigId;
}
}
export default mutations;
Loading