diff --git a/src/components/ProductFilterModal.vue b/src/components/ProductFilterModal.vue
index bbceb6ee..51846f78 100644
--- a/src/components/ProductFilterModal.vue
+++ b/src/components/ProductFilterModal.vue
@@ -20,7 +20,7 @@
{{ option.label }}
-
+
{{ type === 'included' ? $t("excluded") : $t("included") }}
@@ -126,7 +126,7 @@ export default defineComponent({
},
isAlreadyApplied(value: string) {
const type = this.type === 'included' ? 'excluded' : 'included'
- return this.appliedFilters[type][this.searchfield].includes(value)
+ return this.appliedFilters[type][this.searchfield].list.includes(value)
}
},
setup() {
diff --git a/src/locales/en.json b/src/locales/en.json
index a2ed0659..a75339d2 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -44,6 +44,7 @@
"No previous occurrence": "No previous occurrence",
"No time zone found": "No time zone found",
"Only show selected products": "Only show selected products",
+ "Operator": "Operator",
"Password": "Password",
"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.",
diff --git a/src/store/modules/product/ProductState.ts b/src/store/modules/product/ProductState.ts
index 42cd0283..9ac5fd19 100644
--- a/src/store/modules/product/ProductState.ts
+++ b/src/store/modules/product/ProductState.ts
@@ -8,10 +8,16 @@ export default interface ProductState {
};
appliedFilters: {
included: {
- tags: Array
+ tags: {
+ list: any;
+ operator: string;
+ };
},
excluded: {
- tags: Array
+ tags: {
+ list: any;
+ operator: string;
+ };
}
};
query: any;
diff --git a/src/store/modules/product/actions.ts b/src/store/modules/product/actions.ts
index d735c0db..43e6970a 100644
--- a/src/store/modules/product/actions.ts
+++ b/src/store/modules/product/actions.ts
@@ -54,11 +54,19 @@ const actions: ActionTree = {
async updateAppliedFilters({ commit, state, dispatch }, payload) {
const value = payload.value
const appliedFilters = JSON.parse(JSON.stringify((state.appliedFilters as any)[payload.type][payload.id]))
- appliedFilters.includes(value) ? appliedFilters.splice(appliedFilters.indexOf(value), 1) : appliedFilters.push(value)
+ appliedFilters.list.includes(value) ? appliedFilters.list.splice(appliedFilters.list.indexOf(value), 1) : appliedFilters.list.push(value)
commit(types.PRODUCT_FILTER_UPDATED, {id: payload.id, type: payload.type, value: appliedFilters})
dispatch('updateQuery')
},
+ async updateAppliedFilterOperator({ commit, state, dispatch }, payload) {
+ const appliedFilters = JSON.parse(JSON.stringify((state.appliedFilters as any)[payload.type][payload.id]))
+ appliedFilters.operator = payload.value;
+ commit(types.PRODUCT_FILTER_UPDATED, {id: payload.id, type: payload.type, value: appliedFilters})
+ // If we have list items then only apply filters again
+ if(appliedFilters.list.length) dispatch('updateQuery')
+ },
+
async updateQuery({ commit, dispatch, state }, payload) {
// initializing the filter always on updateQuery call because we are adding values in the filter
// as string and if some value is removed then we need to do multiple operations on the filter string
@@ -88,16 +96,16 @@ const actions: ActionTree = {
state.query.json['filter'] = Object.keys(state.appliedFilters.included).reduce((filter, value) => {
const filterValues = (state.appliedFilters.included as any)[value]
- if (filterValues.length > 0) {
- filter.push(`${value}: ("${filterValues.join('" OR "')}")`)
+ if (filterValues.list.length > 0) {
+ filter.push(`${value}: ("${filterValues.list.join('" ' + filterValues.operator + ' "')}")`)
}
return filter
}, state.query.json['filter'])
state.query.json['filter'] = Object.keys(state.appliedFilters.excluded).reduce((filter, value) => {
const filterValues = (state.appliedFilters.excluded as any)[value]
- if (filterValues.length > 0) {
- filter.push(`-${value}: ("${filterValues.join('" OR "')}")`)
+ if (filterValues.list.length > 0) {
+ filter.push(`-${value}: ("${filterValues.list.join('" ' + filterValues.operator + ' "')}")`)
}
return filter
}, state.query.json['filter'])
diff --git a/src/store/modules/product/index.ts b/src/store/modules/product/index.ts
index d1d3f2c2..0c1a9ae4 100644
--- a/src/store/modules/product/index.ts
+++ b/src/store/modules/product/index.ts
@@ -17,10 +17,16 @@ const productModule: Module = {
},
appliedFilters: {
included: {
- tags: []
+ tags: {
+ list: [],
+ operator: "OR"
+ },
},
excluded: {
- tags: []
+ tags: {
+ list: [],
+ operator: "OR"
+ },
}
},
query: {
diff --git a/src/views/SelectProduct.vue b/src/views/SelectProduct.vue
index 7e62411e..a4eb96ec 100644
--- a/src/views/SelectProduct.vue
+++ b/src/views/SelectProduct.vue
@@ -31,17 +31,22 @@
-
-
- {{ $t("Tags") }}
-
- {{ $t('add') }}
-
-
-
-
+
+ {{ $t("Tags") }}
+
+ {{ $t('add') }}
+
+
+
+
+ {{ $t("Operator") }}
+
+ AND
+ OR
+
+
-
+
{{ tag }}
@@ -57,17 +62,22 @@
-
-
- {{ $t("Tags") }}
-
- {{ $t('add') }}
-
-
-
-
+
+ {{ $t("Tags") }}
+
+ {{ $t('add') }}
+
+
+
+
+ {{ $t("Operator") }}
+
+ AND
+ OR
+
+
-
+
{{ tag }}
@@ -163,6 +173,8 @@ import {
IonMenuButton,
IonPage,
IonSearchbar,
+ IonSelect,
+ IonSelectOption,
IonTitle,
IonToolbar,
modalController,
@@ -199,6 +211,8 @@ export default defineComponent({
IonMenuButton,
IonPage,
IonSearchbar,
+ IonSelect,
+ IonSelectOption,
IonTitle,
IonToolbar,
Image
@@ -285,6 +299,14 @@ export default defineComponent({
})
this.queryString = ''
},
+ async applyOperator(type: string, id: string, value: string) {
+ await this.store.dispatch('product/updateAppliedFilterOperator', {
+ type,
+ id,
+ value
+ })
+ this.queryString = ''
+ },
async resetFilters(type: string) {
// checking that if any of the current type does not have any attribute selected than not making solr query
if (Object.entries(this.appliedFilters[type]).every((filter: any) => filter[1].length <= 0)) {