From 5a7bd4e18f7564cddcebb55a5f2249199a465823 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 8 Jan 2020 12:27:18 +0100 Subject: [PATCH] filters refactor --- db/dump/fixtures.sql | 3 +- e2e/helpers/selectors.js | 2 +- modules/order/front/filter/index.html | 40 ++++++------ modules/order/front/filter/index.js | 92 ++++++++++++--------------- modules/order/front/filter/style.scss | 4 ++ modules/order/front/routes.json | 2 +- 6 files changed, 65 insertions(+), 78 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e76f2f5bf..167301a55 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -643,7 +643,8 @@ INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `life`,`workerFk (2, 'ITG', 'Anthurium', 1, 31, 5, 0), (3, 'WPN', 'Paniculata', 2, 31, 5, 0), (4, 'PRT', 'Delivery ports', 3, NULL, 5, 1), - (5, 'CON', 'Container', 3, NULL, 5, 1); + (5, 'CON', 'Container', 3, NULL, 5, 1), + (6, 'ALS', 'Alstroemeria', 1, 31, 5, 0); INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`) VALUES diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f94ae26a7..60dbf8802 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -605,7 +605,7 @@ export default { orderByAutocomplete: 'vn-autocomplete[label="Order by"]', plantRealmButton: 'vn-order-catalog > vn-side-menu vn-icon[icon="icon-plant"]', typeAutocomplete: 'vn-autocomplete[data="$ctrl.itemTypes"]', - itemIdInput: 'vn-catalog-filter vn-textfield[ng-model="$ctrl.itemFk"] input', + itemIdInput: 'vn-catalog-filter vn-textfield[ng-model="$ctrl.itemId"] input', itemTagValueInput: 'vn-catalog-filter vn-textfield[ng-model="$ctrl.value"] input', openTagSearch: 'vn-catalog-filter > div > vn-vertical > vn-textfield[ng-model="$ctrl.value"] .append i', tagAutocomplete: 'vn-order-catalog-search-panel vn-autocomplete[ng-model="filter.tagFk"]', diff --git a/modules/order/front/filter/index.html b/modules/order/front/filter/index.html index 2b92b5f4a..13010a553 100644 --- a/modules/order/front/filter/index.html +++ b/modules/order/front/filter/index.html @@ -6,27 +6,26 @@
+ + + ng-click="$ctrl.categoryId = category.id"> - - - - @@ -73,7 +69,7 @@ + ng-model="$ctrl.itemId"> @@ -106,20 +102,20 @@
- {{$ctrl.category.value}} + {{category.selection.name}} - {{$ctrl.type.value}} + {{type.selection.name}} { - let category; - let type; + if (this.$stateParams.categoryId) + this.categoryId = this.$stateParams.categoryId; - if (this.$stateParams.category) - category = JSON.parse(this.$stateParams.category); - - if (this.$stateParams.type) - type = JSON.parse(this.$stateParams.type); - - if (category && category.id) - this.category = category; - - if (type && type.id) - this.type = type; + if (this.$stateParams.typeId) + this.typeId = this.$stateParams.typeId; }); } - get category() { - return this._category; + get categoryId() { + return this._categoryId; } - set category(value) { - this.catalog.$scope.model.data = []; - this.itemTypes = []; - this.type = null; + set categoryId(value) { + if (!value || (this.categoryId == value)) + value = null; - if (!value || (this.category && this.category.id == value.id)) - this._category = null; - else - this._category = value; + this._categoryId = value; + this.itemTypes = []; + this.typeId = null; this.updateStateParams(); if (this.tags.length > 0) this.applyFilters(); - if (this._category) + if (value) this.updateItemTypes(); } - get type() { - return this._type; + get typeId() { + return this._typeId; } - set type(value) { - if (value && this.type && this.type.id == value.id) return; - - this._type = value; - - if (!value || !value.id) - this._type = null; + set typeId(value) { + this._typeId = value; this.updateStateParams(); - if ((value && value.id) || this.tags.length > 0) + if ((value) || this.tags.length > 0) this.applyFilters(); } @@ -91,17 +76,18 @@ class Controller { */ updateItemTypes() { let params = { - itemCategoryId: this.category.id + itemCategoryId: this.categoryId }; const query = `Orders/${this.order.id}/getItemTypeAvailable`; - this.$http.get(query, {params}).then(res => { - this.itemTypes = res.data; - }); + this.$http.get(query, {params}).then(res => + this.itemTypes = res.data); } onSearchById(event) { - if (event.key === 'Enter' && (this.tags.length > 0 || this.itemFk || this.type)) + console.log(event); + const hasValue = this.tags.length > 0 || this.itemId || this.typeId; + if (event.key === 'Enter' && hasValue) this.applyFilters(); } @@ -117,7 +103,7 @@ class Controller { remove(index) { this.tags.splice(index, 1); - if (this.tags.length >= 0 || this.itemFk || this.type) + if (this.tags.length >= 0 || this.itemId || this.typeId) this.applyFilters(); } @@ -126,14 +112,14 @@ class Controller { let newFilter = {}; const model = this.catalog.$scope.model; - if (this.category) - newFilter.categoryFk = this.category.id; + if (this.categoryId) + newFilter.categoryFk = this.categoryId; - if (this.type) - newFilter.typeFk = this.type.id; + if (this.typeId) + newFilter.typeFk = this.typeId; - if (this.itemFk) - newFilter = {'i.id': this.itemFk}; + if (this.itemId) + newFilter = {'i.id': this.itemId}; newParams = { orderFk: this.order.id, @@ -164,13 +150,13 @@ class Controller { updateStateParams() { const params = {}; - if (this.category) - params.category = JSON.stringify(this.category); + if (this.categoryId) + params.categoryId = this.categoryId; + else params.categoryId = undefined; - if (this.type) - params.type = JSON.stringify(this.type); - else - params.type = undefined; + if (this.typeId) + params.typeId = this.typeId; + else params.typeId = undefined; this.$state.go(this.$state.current.name, params); } diff --git a/modules/order/front/filter/style.scss b/modules/order/front/filter/style.scss index 0cac5765f..f4fe226f2 100644 --- a/modules/order/front/filter/style.scss +++ b/modules/order/front/filter/style.scss @@ -14,6 +14,10 @@ vn-catalog-filter > div { align-items: flex-start; flex-wrap: wrap; + vn-autocomplete[vn-id="category"] { + display: none + } + & > vn-one { padding: $spacing-sm; min-width: 33.33%; diff --git a/modules/order/front/routes.json b/modules/order/front/routes.json index 86eda488f..789870fd1 100644 --- a/modules/order/front/routes.json +++ b/modules/order/front/routes.json @@ -41,7 +41,7 @@ "order": "$ctrl.order" } }, { - "url": "/catalog?category&type", + "url": "/catalog?categoryId&typeId", "state": "order.card.catalog", "component": "vn-order-catalog", "description": "Catalog",