From 5a7bd4e18f7564cddcebb55a5f2249199a465823 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 8 Jan 2020 12:27:18 +0100 Subject: [PATCH 1/5] 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", From a2e6719e1eae8a7a600b4429e18ef9746684d6ad Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 9 Jan 2020 08:42:58 +0100 Subject: [PATCH 2/5] updated unit tests --- modules/order/front/filter/index.js | 1 - modules/order/front/filter/index.spec.js | 40 ++++++++++++------------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/modules/order/front/filter/index.js b/modules/order/front/filter/index.js index 9677d1043..ba563d05c 100644 --- a/modules/order/front/filter/index.js +++ b/modules/order/front/filter/index.js @@ -85,7 +85,6 @@ class Controller { } onSearchById(event) { - console.log(event); const hasValue = this.tags.length > 0 || this.itemId || this.typeId; if (event.key === 'Enter' && hasValue) this.applyFilters(); diff --git a/modules/order/front/filter/index.spec.js b/modules/order/front/filter/index.spec.js index 8fb4baeca..278f875bc 100644 --- a/modules/order/front/filter/index.spec.js +++ b/modules/order/front/filter/index.spec.js @@ -1,7 +1,7 @@ import './index.js'; import crudModel from 'core/mocks/crud-model'; -describe('Order', () => { +fdescribe('Order', () => { describe('Component vnCatalogFilter', () => { let $scope; let $state; @@ -16,8 +16,8 @@ describe('Order', () => { $scope.model = crudModel; $scope.search = {}; $state = _$state_; - $state.params.category = '{"id": 1, "value": "My Category"}'; - $state.params.type = '{"id": 1, "value": "My type"}'; + $state.params.categoryId = 1; + $state.params.typeId = 2; $state.current.name = 'my.current.state'; controller = $componentController('vnCatalogFilter', {$element: null, $scope, $state}); controller.catalog = { @@ -35,15 +35,15 @@ describe('Order', () => { $scope.$apply(); - expect(controller.category).toEqual({id: 1, value: 'My Category'}); - expect(controller.type).toEqual({id: 1, value: 'My type'}); + expect(controller.categoryId).toEqual(1); + expect(controller.typeId).toEqual(2); }); }); - describe('category() setter', () => { + describe('categoryId() setter', () => { it(`should set category property to null, call updateStateParams() method and not call applyFilters()`, () => { spyOn(controller, 'updateStateParams'); - controller.category = null; + controller.categoryId = null; expect(controller.updateStateParams).toHaveBeenCalledWith(); }); @@ -51,17 +51,17 @@ describe('Order', () => { it(`should set category property and then call updateStateParams() and applyFilters() methods`, () => { spyOn(controller, 'updateStateParams'); controller._order = {id: 4}; - controller.category = {id: 2, value: 'My category'}; + controller.categoryId = 2; expect(controller.updateStateParams).toHaveBeenCalledWith(); }); }); - describe('type() setter', () => { + describe('typeId() setter', () => { it(`should set type property to null, call updateStateParams() method and not call applyFilters()`, () => { spyOn(controller, 'updateStateParams'); spyOn(controller, 'applyFilters'); - controller.type = null; + controller.typeId = null; expect(controller.updateStateParams).toHaveBeenCalledWith(); expect(controller.applyFilters).not.toHaveBeenCalledWith(); @@ -70,7 +70,7 @@ describe('Order', () => { it(`should set category property and then call updateStateParams() and applyFilters() methods`, () => { spyOn(controller, 'updateStateParams'); spyOn(controller, 'applyFilters'); - controller.type = {id: 2, value: 'My type'}; + controller.typeId = 2; expect(controller.updateStateParams).toHaveBeenCalledWith(); expect(controller.applyFilters).toHaveBeenCalledWith(); @@ -101,7 +101,7 @@ describe('Order', () => { describe('onSearchById()', () => { it(`should not filter by id if the event key code doesn't equals to 'Enter'`, () => { spyOn(controller, 'applyFilters'); - controller.itemFk = 1; + controller.itemId = 1; controller.onSearchById({key: 'Tab'}); expect(controller.applyFilters).not.toHaveBeenCalledWith(); @@ -109,7 +109,7 @@ describe('Order', () => { it(`should filter by id if the event key code equals to 'Enter' an then call applyFilters()`, () => { spyOn(controller, 'applyFilters'); - controller.itemFk = 1; + controller.itemId = 1; controller.onSearchById({key: 'Enter'}); @@ -121,14 +121,14 @@ describe('Order', () => { it(`should call model applyFilter() method with a new filter`, () => { let model = controller.catalog.$scope.model; spyOn(model, 'applyFilter'); - controller._category = {id: 1, value: 'My Category'}; - controller._type = {id: 1, value: 'My type'}; + controller._categoryId = 2; + controller._typeId = 4; controller._order = {id: 4}; controller.applyFilters(); expect(model.applyFilter).toHaveBeenCalledWith( - {where: {categoryFk: 1, typeFk: 1}}, + {where: {categoryFk: 2, typeFk: 4}}, {orderFk: 4, orderBy: controller.catalog.getOrderBy(), tags: []}); }); }); @@ -146,7 +146,7 @@ describe('Order', () => { it(`should remove a tag from tags property and call applyFilters() if there's no more tags`, () => { spyOn(controller, 'applyFilters'); - controller._category = {id: 1, value: 'My Category'}; + controller._categoryId = {id: 1, value: 'My Category'}; controller._type = {id: 1, value: 'My type'}; controller.tags = [{tagFk: 1, value: 'Blue'}]; controller.remove(0); @@ -159,9 +159,9 @@ describe('Order', () => { describe('updateStateParams()', () => { it(`should call state go() method passing category and type state params`, () => { spyOn(controller.$state, 'go'); - controller._category = {id: 1, value: 'My Category'}; - controller._type = {id: 1, value: 'My type'}; - let result = {category: '{"id":1,"value":"My Category"}', type: '{"id":1,"value":"My type"}'}; + controller._categoryId = 2; + controller._typeId = 4; + let result = {categoryId: 2, typeId: 4}; controller.updateStateParams(); expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result); From 436673986c12cf8913c1977b4d85f337fd67cb70 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 9 Jan 2020 08:43:33 +0100 Subject: [PATCH 3/5] removed focus --- modules/order/front/filter/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/front/filter/index.spec.js b/modules/order/front/filter/index.spec.js index 278f875bc..079df4121 100644 --- a/modules/order/front/filter/index.spec.js +++ b/modules/order/front/filter/index.spec.js @@ -1,7 +1,7 @@ import './index.js'; import crudModel from 'core/mocks/crud-model'; -fdescribe('Order', () => { +describe('Order', () => { describe('Component vnCatalogFilter', () => { let $scope; let $state; From c830bc6e8abe637bbf0453a2a24f68794e00227a Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 9 Jan 2020 09:23:59 +0100 Subject: [PATCH 4/5] fixed order by tag --- modules/order/front/catalog/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index adb66171e..5e2e96555 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -97,7 +97,7 @@ class Controller { return { field: this.orderField, way: this.orderWay, - isTag: !!(this.orderSelection && this.orderSelection.isTag) + isTag: (this.orderSelection && this.orderSelection.isTag) }; } From 7df41fc63cef289ba173313f0103f7a5ba06fb82 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 9 Jan 2020 11:21:54 +0100 Subject: [PATCH 5/5] solved bug ordering by tag --- modules/order/front/catalog/index.js | 17 ++++++++--------- modules/order/front/filter/index.spec.js | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index 5e2e96555..40c60b5ea 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -20,7 +20,7 @@ class Controller { ]; this.orderFields = [].concat(this.defaultOrderFields); this._orderWay = this.orderWays[0].way; - this._orderField = this.orderFields[0].field; + this.orderField = this.orderFields[0].field; } /** @@ -76,15 +76,13 @@ class Controller { if (value) this.applyOrder(); } - /** - * Get order fields - */ - get orderField() { - return this._orderField; + get orderSelection() { + return this._orderSelection; } - set orderField(value) { - this._orderField = value; + set orderSelection(value) { + this._orderSelection = value; + if (value) this.applyOrder(); } @@ -94,10 +92,11 @@ class Controller { * @return {Object} - Order param */ getOrderBy() { + const isTag = !!(this.orderSelection && this.orderSelection.isTag); return { field: this.orderField, way: this.orderWay, - isTag: (this.orderSelection && this.orderSelection.isTag) + isTag: isTag }; } diff --git a/modules/order/front/filter/index.spec.js b/modules/order/front/filter/index.spec.js index 079df4121..72a0f206b 100644 --- a/modules/order/front/filter/index.spec.js +++ b/modules/order/front/filter/index.spec.js @@ -146,8 +146,8 @@ describe('Order', () => { it(`should remove a tag from tags property and call applyFilters() if there's no more tags`, () => { spyOn(controller, 'applyFilters'); - controller._categoryId = {id: 1, value: 'My Category'}; - controller._type = {id: 1, value: 'My type'}; + controller._categoryId = 1; + controller._typeId = 1; controller.tags = [{tagFk: 1, value: 'Blue'}]; controller.remove(0);