From 20f9f7af24355555eeab86d1281839ae1f70df11 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 6 Feb 2020 12:46:44 +0100 Subject: [PATCH 1/2] 2084 - Keep categoryId selected on item confirmation --- loopback/locale/es.json | 3 ++- modules/order/front/catalog/index.html | 2 +- modules/order/front/catalog/index.js | 8 ++++++-- modules/order/front/catalog/index.spec.js | 19 +++++++++++++++++-- modules/order/front/prices-popover/index.js | 21 ++++++++++----------- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index d2f2882bc..90d4f8793 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -125,5 +125,6 @@ "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})", "MESSAGE_CLAIM_ITEM_REGULARIZE": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a {{nickname}} provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})", - "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}" + "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", + "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto" } \ No newline at end of file diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 86b209e59..5cc72e3c8 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -29,7 +29,7 @@ ng-class="{'active': $ctrl.categoryId == category.id}" icon="{{::category.icon}}" vn-tooltip="{{::category.name}}" - ng-click="$ctrl.categoryId = category.id"> + ng-click="$ctrl.changeCategory(category.id)"> diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index a53d62089..ce684aabe 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -107,8 +107,7 @@ class Controller { } set categoryId(value) { - if (!value || (this.categoryId == value)) - value = null; + if (!value) value = null; this._categoryId = value; this.itemTypes = []; @@ -123,6 +122,11 @@ class Controller { this.updateItemTypes(); } + changeCategory(id) { + if (this._categoryId == id) id = null; + this.categoryId = id; + } + get typeId() { return this._typeId; } diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index 9f778ee41..dd9e13257 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -20,6 +20,7 @@ describe('Order', () => { $state.params.typeId = 2; $state.current.name = 'my.current.state'; controller = $componentController('vnOrderCatalog', {$scope, $state}); + controller._order = {id: 4}; })); describe('order() setter', () => { @@ -59,13 +60,28 @@ describe('Order', () => { it(`should set category property and then call updateStateParams() and applyFilters() methods`, () => { spyOn(controller, 'updateStateParams'); - controller._order = {id: 4}; controller.categoryId = 2; expect(controller.updateStateParams).toHaveBeenCalledWith(); }); }); + describe('changeCategory()', () => { + it(`should set categoryId property to null if the new value equals to the old one`, () => { + controller.categoryId = 2; + controller.changeCategory(2); + + expect(controller.categoryId).toBeNull(); + }); + + it(`should set categoryId property`, () => { + controller.categoryId = 2; + controller.changeCategory(1); + + expect(controller.categoryId).toEqual(1); + }); + }); + describe('typeId() setter', () => { it(`should set type property to null, call updateStateParams() method and not call applyFilters()`, () => { spyOn(controller, 'updateStateParams'); @@ -132,7 +148,6 @@ describe('Order', () => { spyOn(model, 'applyFilter'); controller._categoryId = 2; controller._typeId = 4; - controller._order = {id: 4}; controller.applyFilters(); diff --git a/modules/order/front/prices-popover/index.js b/modules/order/front/prices-popover/index.js index 40590b8bb..2df8bea15 100644 --- a/modules/order/front/prices-popover/index.js +++ b/modules/order/front/prices-popover/index.js @@ -127,19 +127,18 @@ class Controller extends Component { return; } - setTimeout(() => { - let params = { - orderFk: this.order.id, - items: filledLines - }; - this.$http.post(`OrderRows/addToOrder`, params).then(res => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$.popover.hide(); + let params = { + orderFk: this.order.id, + items: filledLines + }; - if (this.card) - this.card.reload(); - }); + this.$http.post(`OrderRows/addToOrder`, params).then(res => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.popover.hide(); + + if (this.card) + this.card.reload(); }); } } From b6473794434e49d744f6468cc215745ba405e464 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 6 Feb 2020 13:42:28 +0100 Subject: [PATCH 2/2] removed line --- modules/order/front/catalog/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index ce684aabe..a7d2c18b2 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -106,9 +106,7 @@ class Controller { return this._categoryId; } - set categoryId(value) { - if (!value) value = null; - + set categoryId(value = null) { this._categoryId = value; this.itemTypes = []; this.typeId = null;