From 12308de5d1fe8f8a78dd90aba6caf0b7719934e2 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 13 Mar 2019 15:09:10 +0100 Subject: [PATCH] catalog filter by item id #1219 --- modules/order/front/filter/index.html | 17 +++++++++----- modules/order/front/filter/index.js | 14 +++++++++--- modules/order/front/filter/index.spec.js | 28 ++++++++++++++++++++---- modules/order/front/locale/es.yml | 1 + 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/modules/order/front/filter/index.html b/modules/order/front/filter/index.html index f4c1c6390..d4d8fd751 100644 --- a/modules/order/front/filter/index.html +++ b/modules/order/front/filter/index.html @@ -41,11 +41,18 @@ - - + + + + + + @@ -59,7 +66,7 @@ - + diff --git a/modules/order/front/filter/index.js b/modules/order/front/filter/index.js index 8a80a80e2..26495b025 100644 --- a/modules/order/front/filter/index.js +++ b/modules/order/front/filter/index.js @@ -96,8 +96,13 @@ class Controller { }); } - onSearch(event) { - if (event.key !== 'Enter') return; + onSearchById(event) { + if (event.key !== 'Enter' || !this.itemFk) return; + this.applyFilters(); + } + + onSearchByTag(event) { + if (event.key !== 'Enter' || !this.value) return; this.tags.push({ value: this.value, }); @@ -114,7 +119,7 @@ class Controller { applyFilters() { let newParams = {}; - const newFilter = {}; + let newFilter = {}; const model = this.catalog.$scope.model; if (this.category) @@ -123,6 +128,9 @@ class Controller { if (this.type) newFilter.typeFk = this.type.id; + if (this.itemFk) + newFilter = {'i.id': this.itemFk}; + newParams = { orderFk: this.order.id, orderBy: this.catalog.getOrderBy(), diff --git a/modules/order/front/filter/index.spec.js b/modules/order/front/filter/index.spec.js index c31e87500..723342dbc 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; @@ -79,12 +79,12 @@ describe('Order', () => { }); }); - describe('onSearch()', () => { + describe('onSearchByTag()', () => { it(`should not add a new tag if the event key code doesn't equals to 'Enter'`, () => { spyOn(controller, 'applyFilters'); controller.order = {id: 4}; controller.value = 'Color'; - controller.onSearch({key: 'Tab'}); + controller.onSearchByTag({key: 'Tab'}); expect(controller.applyFilters).not.toHaveBeenCalledWith(); }); @@ -93,7 +93,27 @@ describe('Order', () => { spyOn(controller, 'applyFilters'); controller.order = {id: 4}; controller.value = 'Color'; - controller.onSearch({key: 'Enter'}); + + controller.onSearchByTag({key: 'Enter'}); + + expect(controller.applyFilters).toHaveBeenCalledWith(); + }); + }); + + 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.onSearchById({key: 'Tab'}); + + expect(controller.applyFilters).not.toHaveBeenCalledWith(); + }); + + it(`should filter by id if the event key code equals to 'Enter' an then call applyFilters()`, () => { + spyOn(controller, 'applyFilters'); + controller.itemFk = 1; + + controller.onSearchById({key: 'Enter'}); expect(controller.applyFilters).toHaveBeenCalledWith(); }); diff --git a/modules/order/front/locale/es.yml b/modules/order/front/locale/es.yml index 0b134783f..8fa991bc7 100644 --- a/modules/order/front/locale/es.yml +++ b/modules/order/front/locale/es.yml @@ -13,6 +13,7 @@ Lines: Lineas Accessories: Complemento Category: Reino Search tag: Buscar etiqueta +Item id: Id de artículo Order by: Ordenar por Order: Orden Price: Precio