From dd368a8c3f167e716b2d7e6d6c37ca1c39ceee1c Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Fri, 7 Feb 2020 13:38:32 +0100 Subject: [PATCH 1/3] refactor ticket.basicData steps --- .../10150-entry/00-ticketUpdateAction.sql | 5 ++ e2e/helpers/selectors.js | 2 +- .../06_basic_data_steps.spec.js | 12 +-- .../back/models/ticket-update-action.json | 57 ++++++++------- modules/ticket/front/basic-data/index.html | 5 +- modules/ticket/front/basic-data/index.js | 4 +- .../front/basic-data/step-three/index.html | 14 ---- .../front/basic-data/step-three/index.js | 73 ------------------- .../front/basic-data/step-three/index.spec.js | 67 ----------------- .../front/basic-data/step-three/locale/es.yml | 4 - .../front/basic-data/step-two/index.html | 20 +++++ .../ticket/front/basic-data/step-two/index.js | 49 ++++++++++++- modules/ticket/front/index.js | 1 - modules/ticket/front/routes.json | 8 -- 14 files changed, 112 insertions(+), 209 deletions(-) create mode 100644 db/changes/10150-entry/00-ticketUpdateAction.sql delete mode 100644 modules/ticket/front/basic-data/step-three/index.html delete mode 100644 modules/ticket/front/basic-data/step-three/index.js delete mode 100644 modules/ticket/front/basic-data/step-three/index.spec.js delete mode 100644 modules/ticket/front/basic-data/step-three/locale/es.yml diff --git a/db/changes/10150-entry/00-ticketUpdateAction.sql b/db/changes/10150-entry/00-ticketUpdateAction.sql new file mode 100644 index 000000000..a05c65d7a --- /dev/null +++ b/db/changes/10150-entry/00-ticketUpdateAction.sql @@ -0,0 +1,5 @@ +ALTER TABLE `vn`.`ticketUpdateAction` +ADD COLUMN `code` VARCHAR(45) NOT NULL AFTER `description`; + +UPDATE `vn`.`ticketUpdateAction` SET `code`='changePrice' WHERE `id`='1'; +UPDATE `vn`.`ticketUpdateAction` SET `code`='turnInMana' WHERE `id`='3'; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index d7e20018b..89a0fdbd8 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -471,7 +471,7 @@ export default { nextStepButton: 'vn-step-control .buttons > section:last-child vn-button', finalizeButton: 'vn-step-control .buttons > section:last-child button[type=submit]', stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two vn-tfoot > vn-tr > :nth-child(6)', - chargesReason: 'vn-autocomplete[ng-model="$ctrl.ticket.option"]', + chargesReason: 'div:nth-child(3) > vn-radio > div', }, ticketComponents: { base: 'vn-ticket-components [name="base-sum"]' diff --git a/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js b/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js index f677625cd..0be758205 100644 --- a/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js @@ -80,15 +80,15 @@ describe('Ticket Edit basic data path', () => { expect(result).toContain('-€248.00'); }); - it(`should then click next to move on to step three`, async() => { - await page.waitToClick(selectors.ticketBasicData.nextStepButton); - let url = await page.expectURL('data/step-three'); + // it(`should then click next to move on to step three`, async() => { + // await page.waitToClick(selectors.ticketBasicData.nextStepButton); + // let url = await page.expectURL('data/step-three'); - expect(url).toBe(true); - }); + // expect(url).toBe(true); + // }); it(`should select a new reason for the changes made then click on finalize`, async() => { - await page.autocompleteSearch(selectors.ticketBasicData.chargesReason, 'Cambiar los precios en el ticket'); + await page.waitToClick(selectors.ticketBasicData.chargesReason); await page.waitToClick(selectors.ticketBasicData.finalizeButton); let url = await page.expectURL('summary'); diff --git a/modules/ticket/back/models/ticket-update-action.json b/modules/ticket/back/models/ticket-update-action.json index c4a4ce8df..3072c2172 100644 --- a/modules/ticket/back/models/ticket-update-action.json +++ b/modules/ticket/back/models/ticket-update-action.json @@ -1,28 +1,31 @@ { - "name": "TicketUpdateAction", - "base": "VnModel", - "options": { - "mysql": { - "table": "ticketUpdateAction" - } - }, - "properties": { - "id": { - "id": true, - "type": "Number", - "description": "Identifier" - }, - "description": { - "type": "String", - "required": true - } -}, -"acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } -] -} + "name": "TicketUpdateAction", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketUpdateAction" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "description": { + "type": "String", + "required": true + }, + "code": { + "type": "String" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/ticket/front/basic-data/index.html b/modules/ticket/front/basic-data/index.html index f313110b3..34db1e246 100644 --- a/modules/ticket/front/basic-data/index.html +++ b/modules/ticket/front/basic-data/index.html @@ -3,9 +3,8 @@ step-count="10" steps="[ {name: 'Basic data', state: 'ticket.card.basicData.stepOne'}, - {name: 'Price difference', state: 'ticket.card.basicData.stepTwo'}, - {name: 'Charge', state: 'ticket.card.basicData.stepThree'}]" - on-step-change="$ctrl.onStepChange(state)" + {name: 'Price difference', state: 'ticket.card.basicData.stepTwo'}]" + on-step-change="$ctrl.onStepChange()" on-step-end="$ctrl.onSubmit()"> diff --git a/modules/ticket/front/basic-data/index.js b/modules/ticket/front/basic-data/index.js index 1afe6f9aa..4965ee61e 100644 --- a/modules/ticket/front/basic-data/index.js +++ b/modules/ticket/front/basic-data/index.js @@ -16,8 +16,8 @@ class Controller { this.child = child; } - onStepChange(state) { - return this.child.onStepChange(state); + onStepChange() { + return this.child.onStepChange(); } onSubmit() { diff --git a/modules/ticket/front/basic-data/step-three/index.html b/modules/ticket/front/basic-data/step-three/index.html deleted file mode 100644 index 300b8f6d3..000000000 --- a/modules/ticket/front/basic-data/step-three/index.html +++ /dev/null @@ -1,14 +0,0 @@ -
- - - - - - -
diff --git a/modules/ticket/front/basic-data/step-three/index.js b/modules/ticket/front/basic-data/step-three/index.js deleted file mode 100644 index 1cd643dd2..000000000 --- a/modules/ticket/front/basic-data/step-three/index.js +++ /dev/null @@ -1,73 +0,0 @@ -import ngModule from '../../module'; - -class Controller { - constructor($http, $scope, $state, $translate, vnApp) { - this.$http = $http; - this.$scope = $scope; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - } - - $onInit() { - this.data.registerChild(this); - } - - get ticket() { - return this._ticket; - } - - set ticket(value) { - this._ticket = value; - - if (value) this.ticket.option = 1; - } - - onStepChange(state) { - return true; - } - - onSubmit() { - if (!this.ticket.option) { - return this.vnApp.showError( - this.$translate.instant('Choose an option') - ); - } - - let query = `tickets/${this.ticket.id}/componentUpdate`; - let params = { - clientId: this.ticket.clientFk, - agencyModeId: this.ticket.agencyModeFk, - addressId: this.ticket.addressFk, - zoneId: this.ticket.zoneFk, - warehouseId: this.ticket.warehouseFk, - companyId: this.ticket.companyFk, - shipped: this.ticket.shipped, - landed: this.ticket.landed, - isDeleted: this.ticket.isDeleted, - option: this.ticket.option - }; - - this.$http.post(query, params).then(res => { - this.vnApp.showMessage( - this.$translate.instant(`The ticket has been unrouted`) - ); - this.card.reload(); - this.$state.go('ticket.card.summary', {id: this.$state.params.id}); - }); - } -} - -Controller.$inject = ['$http', '$scope', '$state', '$translate', 'vnApp']; - -ngModule.component('vnTicketBasicDataStepThree', { - template: require('./index.html'), - controller: Controller, - bindings: { - ticket: '<' - }, - require: { - card: '^vnTicketCard', - data: '^vnTicketBasicData' - } -}); diff --git a/modules/ticket/front/basic-data/step-three/index.spec.js b/modules/ticket/front/basic-data/step-three/index.spec.js deleted file mode 100644 index 6843caec1..000000000 --- a/modules/ticket/front/basic-data/step-three/index.spec.js +++ /dev/null @@ -1,67 +0,0 @@ -import './index.js'; - -describe('ticket', () => { - describe('Component vnTicketBasicDataStepThree', () => { - let now = Date.now(); - let $state; - let controller; - let $httpBackend; - let vnApp; - - beforeEach(ngModule('ticket')); - - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _vnApp_) => { - $state = _$state_; - spyOn($state, 'go'); - vnApp = _vnApp_; - spyOn(vnApp, 'showError'); - $httpBackend = _$httpBackend_; - controller = $componentController('vnTicketBasicDataStepThree', {$state}); - })); - - describe('onSubmit()', () => { - it(`should return an error if the item doesn't have option property in the controller`, () => { - controller._ticket = {id: 1}; - controller.onSubmit(); - - expect(vnApp.showError).toHaveBeenCalledWith('Choose an option'); - }); - - it('should perform a post query correctly then call two functions()', () => { - spyOn(controller.vnApp, 'showMessage'); - controller.card = {reload: () => {}}; - spyOn(controller.card, 'reload'); - - controller.ticket = { - id: 1, - agencyModeFk: 1, - addressFk: 121, - zoneFk: 3, - warehouseFk: 1, - shipped: now, - landed: now, - option: 1 - }; - - let data = { - agencyModeId: 1, - addressId: 121, - zoneId: 3, - warehouseId: 1, - shipped: now, - landed: now, - option: 1 - }; - - $httpBackend.whenPOST(`tickets/1/componentUpdate`, data).respond('ok'); - $httpBackend.expectPOST(`tickets/1/componentUpdate`, data); - controller.onSubmit(); - $httpBackend.flush(); - - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The ticket has been unrouted'); - expect(controller.card.reload).toHaveBeenCalledWith(); - expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', jasmine.any(Object)); - }); - }); - }); -}); diff --git a/modules/ticket/front/basic-data/step-three/locale/es.yml b/modules/ticket/front/basic-data/step-three/locale/es.yml deleted file mode 100644 index 185534c34..000000000 --- a/modules/ticket/front/basic-data/step-three/locale/es.yml +++ /dev/null @@ -1,4 +0,0 @@ -Charge: Cargo -Choose an option: Selecciona una opción -Charge difference to: Diferencia a cargo de -The ticket has been unrouted: El ticket ha sido desenrutado \ No newline at end of file diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 04cb7f212..345cb3f86 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -1,3 +1,23 @@ + + + +
+ Charge difference to +
+
+ + +
+
diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index a481afefc..ec8d94f9a 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -1,8 +1,11 @@ import ngModule from '../../module'; class Controller { - constructor($http) { + constructor($http, $state, $translate, vnApp) { this.$http = $http; + this.$state = $state; + this.$translate = $translate; + this.vnApp = vnApp; } $onInit() { @@ -21,9 +24,18 @@ class Controller { this.getTotalPrice(); this.getTotalNewPrice(); this.getTotalDifferenceOfPrice(); + this.loadDefaultTicketAction(); } - onStepChange(state) { + loadDefaultTicketAction() { + let filter = {where: {code: 'changePrice'}}; + + this.$http.get(`TicketUpdateActions`, {filter}).then(response => { + return this.ticket.option = response.data[0].id; + }); + } + + onStepChange() { return true; } @@ -53,9 +65,39 @@ class Controller { }); this.totalPriceDifference = totalPriceDifference; } + + onSubmit() { + if (!this.ticket.option) { + return this.vnApp.showError( + this.$translate.instant('Choose an option') + ); + } + + let query = `tickets/${this.ticket.id}/componentUpdate`; + let params = { + clientId: this.ticket.clientFk, + agencyModeId: this.ticket.agencyModeFk, + addressId: this.ticket.addressFk, + zoneId: this.ticket.zoneFk, + warehouseId: this.ticket.warehouseFk, + companyId: this.ticket.companyFk, + shipped: this.ticket.shipped, + landed: this.ticket.landed, + isDeleted: this.ticket.isDeleted, + option: parseInt(this.ticket.option) + }; + + this.$http.post(query, params).then(res => { + this.vnApp.showMessage( + this.$translate.instant(`The ticket has been unrouted`) + ); + this.card.reload(); + this.$state.go('ticket.card.summary', {id: this.$state.params.id}); + }); + } } -Controller.$inject = ['$http']; +Controller.$inject = ['$http', '$state', '$translate', 'vnApp']; ngModule.component('vnTicketBasicDataStepTwo', { template: require('./index.html'), @@ -64,6 +106,7 @@ ngModule.component('vnTicketBasicDataStepTwo', { ticket: '<' }, require: { + card: '^vnTicketCard', data: '^vnTicketBasicData' } }); diff --git a/modules/ticket/front/index.js b/modules/ticket/front/index.js index 2625d35f3..c3f15b214 100644 --- a/modules/ticket/front/index.js +++ b/modules/ticket/front/index.js @@ -13,7 +13,6 @@ import './summary'; import './basic-data'; import './basic-data/step-one'; import './basic-data/step-two'; -import './basic-data/step-three'; import './note'; import './expedition'; import './volume'; diff --git a/modules/ticket/front/routes.json b/modules/ticket/front/routes.json index af0683ee1..d95788036 100644 --- a/modules/ticket/front/routes.json +++ b/modules/ticket/front/routes.json @@ -79,14 +79,6 @@ "params": { "ticket": "$ctrl.data" } - }, { - "url" : "/step-three", - "state": "ticket.card.basicData.stepThree", - "component": "vn-ticket-basic-data-step-three", - "description": "Charge", - "params": { - "ticket": "$ctrl.data" - } }, { "url" : "/sale", "state": "ticket.card.sale", From afaa46a6d6cd2dfaed88fd34d07482f37e4d85d2 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Fri, 7 Feb 2020 14:12:37 +0100 Subject: [PATCH 2/3] fix e2e --- e2e/helpers/selectors.js | 2 +- e2e/paths/05-ticket-module/06_basic_data_steps.spec.js | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 89a0fdbd8..63e5ddf2f 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -471,7 +471,7 @@ export default { nextStepButton: 'vn-step-control .buttons > section:last-child vn-button', finalizeButton: 'vn-step-control .buttons > section:last-child button[type=submit]', stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two vn-tfoot > vn-tr > :nth-child(6)', - chargesReason: 'div:nth-child(3) > vn-radio > div', + chargesReason: 'vn-ticket-basic-data-step-two div:nth-child(3) > vn-radio', }, ticketComponents: { base: 'vn-ticket-components [name="base-sum"]' diff --git a/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js b/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js index 0be758205..de78b9fa7 100644 --- a/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js @@ -80,13 +80,6 @@ describe('Ticket Edit basic data path', () => { expect(result).toContain('-€248.00'); }); - // it(`should then click next to move on to step three`, async() => { - // await page.waitToClick(selectors.ticketBasicData.nextStepButton); - // let url = await page.expectURL('data/step-three'); - - // expect(url).toBe(true); - // }); - it(`should select a new reason for the changes made then click on finalize`, async() => { await page.waitToClick(selectors.ticketBasicData.chargesReason); await page.waitToClick(selectors.ticketBasicData.finalizeButton); From 7a643eff3424ef061159c80566d7497f9b3d2ff5 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Mon, 10 Feb 2020 07:03:09 +0100 Subject: [PATCH 3/3] fix index step-two --- modules/ticket/front/basic-data/step-two/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 345cb3f86..0154b3caa 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -12,9 +12,9 @@
+ ng-model="$ctrl.ticket.option" + label="{{::action.description}}" + val={{::action.id}}>