From a601a615e279d2e209e0a91ac4a3b09ccfc28094 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 16 Mar 2020 11:58:14 +0100 Subject: [PATCH 01/44] Claim refactor --- modules/claim/front/action/index.js | 38 +++++++----------- modules/claim/front/action/index.spec.js | 3 +- modules/claim/front/basic-data/index.html | 7 +++- modules/claim/front/basic-data/index.js | 14 ++----- modules/claim/front/basic-data/index.spec.js | 5 ++- modules/claim/front/detail/index.js | 16 +++----- modules/claim/front/detail/index.spec.js | 11 ++---- modules/claim/front/development/index.html | 2 +- modules/claim/front/development/index.js | 19 +++------ modules/claim/front/development/index.spec.js | 7 ++-- modules/claim/front/dms/style.scss | 31 --------------- modules/claim/front/index/index.js | 10 +---- modules/claim/front/photos/index.html | 7 ++-- modules/claim/front/photos/index.js | 15 +------ modules/claim/front/photos/index.spec.js | 3 +- modules/claim/front/summary/index.html | 4 +- modules/claim/front/summary/index.js | 39 ++++--------------- modules/claim/front/summary/index.spec.js | 10 +++-- 18 files changed, 75 insertions(+), 166 deletions(-) delete mode 100644 modules/claim/front/dms/style.scss diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index dc22cb4be..d4b3541e0 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -1,16 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($stateParams, $scope, $http, $translate, vnApp, $httpParamSerializer) { - this.$stateParams = $stateParams; - this.$ = $scope; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - this.$httpParamSerializer = $httpParamSerializer; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { - where: {claimFk: $stateParams.id}, + where: {claimFk: this.$params.id}, include: [ {relation: 'sale', scope: { @@ -34,9 +30,7 @@ class Controller { } getClaimedSales() { - let json = encodeURIComponent(JSON.stringify(this.claim.id)); - - let query = `ClaimBeginnings/${json}`; + let query = `ClaimBeginnings/${this.claim.id}`; this.$http.get(query).then(res => { if (res.data) this.claimedSales = res.data; @@ -54,8 +48,7 @@ class Controller { } deleteClaimedSale(id) { - let json = encodeURIComponent(JSON.stringify(id)); - let query = `ClaimEnds/${json}`; + let query = `ClaimEnds/${id}`; this.$http.delete(query).then(() => { this.$.model.refresh(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); @@ -63,7 +56,7 @@ class Controller { } importToNewRefundTicket() { - let query = `ClaimBeginnings/${this.$stateParams.id}/importToNewRefundTicket`; + let query = `ClaimBeginnings/${this.$params.id}/importToNewRefundTicket`; return this.$http.post(query).then(() => { this.$.model.refresh(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); @@ -112,7 +105,7 @@ class Controller { } importTicketLines(ticketFk) { - let data = {claimFk: this.$stateParams.id, ticketFk: ticketFk}; + let data = {claimFk: this.$params.id, ticketFk: ticketFk}; let query = `ClaimEnds/importTicketSales`; this.$http.post(query, data).then(() => { @@ -123,7 +116,7 @@ class Controller { } regularize() { - let data = {claimFk: this.$stateParams.id}; + let data = {claimFk: this.$params.id}; let query = `Claims/regularizeClaim`; return this.$http.post(query, data).then(() => { if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2) @@ -137,9 +130,8 @@ class Controller { getGreugeTypeId() { const params = {filter: {where: {code: 'freightPickUp'}}}; - const serializedParams = this.$httpParamSerializer(params); - const query = `GreugeTypes/findOne?${serializedParams}`; - return this.$http.get(query).then(res => { + const query = `GreugeTypes/findOne`; + return this.$http.get(query, {params}).then(res => { this.greugeTypeFreightId = res.data.id; return res; @@ -188,7 +180,7 @@ class Controller { } saveResponsibility(value) { - let query = `Claims/${this.$stateParams.id}/updateClaimAction`; + let query = `Claims/${this.$params.id}/updateClaimAction`; this.$http.post(query, {responsibility: value}).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); @@ -196,7 +188,7 @@ class Controller { } saveMana(value) { - let query = `Claims/${this.$stateParams.id}/updateClaimAction`; + let query = `Claims/${this.$params.id}/updateClaimAction`; this.$http.post(query, {isChargedToMana: value}).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); @@ -208,7 +200,7 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp', '$httpParamSerializer']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClaimAction', { template: require('./index.html'), diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index c0bcea452..639e90827 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -18,7 +18,8 @@ describe('claim', () => { $state = _$state_; $state.params.id = 1; - controller = $componentController('vnClaimAction', {$state, $scope}); + const $element = angular.element(''); + controller = $componentController('vnClaimAction', {$element, $scope}); controller.claim = {ticketFk: 1}; controller.$.model = {refresh: () => {}}; controller.$.addSales = { diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index 9be04cb57..948ac6b18 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -2,7 +2,7 @@ vn-id="watcher" data="$ctrl.claim" form="form" - url="Claims/{{$ctrl.$stateParams.id}}/updateClaim" + url="Claims/{{$ctrl.$params.id}}/updateClaim" save="post">
@@ -55,6 +55,9 @@ - + +
diff --git a/modules/claim/front/basic-data/index.js b/modules/claim/front/basic-data/index.js index bc616dd5c..c3eac92ff 100644 --- a/modules/claim/front/basic-data/index.js +++ b/modules/claim/front/basic-data/index.js @@ -1,24 +1,16 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $state, aclService) { - this.$scope = $scope; - this.$state = $state; - this.$stateParams = $state.params; - this.aclService = aclService; - } - +class Controller extends Section { onSubmit() { - this.$scope.watcher.submit().then(() => { + this.$.watcher.submit().then(() => { if (this.aclService.hasAny(['salesAssistant'])) this.$state.go('claim.card.detail'); }); } } -Controller.$inject = ['$scope', '$state', 'aclService']; - ngModule.component('vnClaimBasicData', { template: require('./index.html'), controller: Controller, diff --git a/modules/claim/front/basic-data/index.spec.js b/modules/claim/front/basic-data/index.spec.js index 54b6e025d..65e934cb8 100644 --- a/modules/claim/front/basic-data/index.spec.js +++ b/modules/claim/front/basic-data/index.spec.js @@ -11,12 +11,13 @@ describe('Claim', () => { beforeEach(angular.mock.inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); $scope.watcher = watcher; - let aclService = {hasAny: () => true}; - controller = $componentController('vnClaimBasicData', {$scope, aclService}); + const $element = angular.element(''); + controller = $componentController('vnClaimBasicData', {$element, $scope}); })); describe('onSubmit()', () => { it(`should redirect to 'claim.card.detail' state`, () => { + jest.spyOn(controller.aclService, 'hasAny').mockReturnValue(true); jest.spyOn(controller.$state, 'go'); controller.onSubmit(); diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index 74033b565..33b348513 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -1,17 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($state, $, $http, $translate, vnApp, aclService) { - this.$state = $state; - this.$ = $; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - this.aclService = aclService; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.edit = {}; this.filter = { - where: {claimFk: $state.params.id}, + where: {claimFk: this.$params.id}, include: [ { relation: 'sale', @@ -173,7 +169,7 @@ class Controller { } } -Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp', 'aclService']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClaimDetail', { template: require('./index.html'), diff --git a/modules/claim/front/detail/index.spec.js b/modules/claim/front/detail/index.spec.js index a4d7878c5..922076b9f 100644 --- a/modules/claim/front/detail/index.spec.js +++ b/modules/claim/front/detail/index.spec.js @@ -6,12 +6,10 @@ describe('claim', () => { let $scope; let controller; let $httpBackend; - let $state; - let aclService; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $scope = $rootScope.$new(); $scope.descriptor = { show: () => {} @@ -19,9 +17,8 @@ describe('claim', () => { $httpBackend = _$httpBackend_; $httpBackend.whenGET('Claims/ClaimBeginnings').respond({}); $httpBackend.whenGET(`Tickets/1/isEditable`).respond(true); - $state = _$state_; - aclService = {hasAny: () => true}; - controller = $componentController('vnClaimDetail', {$state, aclService, $scope}); + const $element = angular.element(''); + controller = $componentController('vnClaimDetail', {$element, $scope}); controller.claim = {ticketFk: 1}; controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}]; controller.salesClaimed = [{id: 1, sale: {}}]; @@ -33,6 +30,7 @@ describe('claim', () => { controller.$.editPopover = { hide: () => {} }; + jest.spyOn(controller.aclService, 'hasAny').mockReturnValue(true); })); describe('openAddSalesDialog()', () => { @@ -111,7 +109,6 @@ describe('claim', () => { quantity: 10}}; controller.newDiscount = 10; - jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller, 'calculateTotals'); jest.spyOn(controller, 'clearDiscount'); diff --git a/modules/claim/front/development/index.html b/modules/claim/front/development/index.html index 38082847a..2b504be11 100644 --- a/modules/claim/front/development/index.html +++ b/modules/claim/front/development/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ClaimDevelopments" fields="['id', 'claimFk', 'claimReasonFk', 'claimResultFk', 'claimResponsibleFk', 'workerFk', 'claimRedeliveryFk']" - link="{claimFk: $ctrl.$state.params.id}" + link="{claimFk: $ctrl.$params.id}" filter="$ctrl.filter" data="claimDevelopments" auto-load="true"> diff --git a/modules/claim/front/development/index.js b/modules/claim/front/development/index.js index d6220fbca..cc86d5452 100644 --- a/modules/claim/front/development/index.js +++ b/modules/claim/front/development/index.js @@ -1,18 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($state, $scope, aclService) { - this.$state = $state; - this.$scope = $scope; - this.aclService = aclService; - } - +class Controller extends Section { onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.watcher.updateOriginalData(); + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); if (this.aclService.hasAny(['salesAssistant'])) this.$state.go('claim.card.action'); @@ -20,8 +15,6 @@ class Controller { } } -Controller.$inject = ['$state', '$scope', 'aclService']; - ngModule.component('vnClaimDevelopment', { template: require('./index.html'), controller: Controller, diff --git a/modules/claim/front/development/index.spec.js b/modules/claim/front/development/index.spec.js index 4d9ebdc7e..5708f82f2 100644 --- a/modules/claim/front/development/index.spec.js +++ b/modules/claim/front/development/index.spec.js @@ -6,7 +6,6 @@ describe('Claim', () => { describe('Component vnClaimDevelopment', () => { let controller; let $scope; - let aclService; beforeEach(ngModule('claim')); @@ -14,13 +13,15 @@ describe('Claim', () => { $scope = $rootScope.$new(); $scope.watcher = watcher; $scope.model = crudModel; - aclService = {hasAny: () => true}; - controller = $componentController('vnClaimDevelopment', {$scope, aclService}); + const $element = angular.element(''); + controller = $componentController('vnClaimDevelopment', {$element, $scope}); })); describe('onSubmit()', () => { it(`should redirect to 'claim.card.action' state`, () => { + jest.spyOn(controller.aclService, 'hasAny').mockReturnValue(true); jest.spyOn(controller.$state, 'go'); + controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('claim.card.action'); diff --git a/modules/claim/front/dms/style.scss b/modules/claim/front/dms/style.scss deleted file mode 100644 index 28f9db6fc..000000000 --- a/modules/claim/front/dms/style.scss +++ /dev/null @@ -1,31 +0,0 @@ -@import "./variables"; - -vn-claim-dms-index { - .drop-zone { - color: $color-font-secondary; - box-sizing: border-box; - border-radius: 0.5em; - text-align: center; - min-height: 100%; - - .empty-rows { - padding: 5em $spacing-md; - font-size: 1.4em - } - - vn-icon { - font-size: 3em - } - } - - .photo-list { - - padding: $spacing-md; - min-height: 100%; - - .photo { - width: 32em; - height: 18em; - } - } -} \ No newline at end of file diff --git a/modules/claim/front/index/index.js b/modules/claim/front/index/index.js index 21464fea9..51a0c7042 100644 --- a/modules/claim/front/index/index.js +++ b/modules/claim/front/index/index.js @@ -1,11 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope) { - this.$ = $scope; - this.ticketSelected = null; - } - +export default class Controller extends Section { stateColor(claim) { switch (claim.description) { case 'Pendiente': @@ -52,8 +48,6 @@ export default class Controller { } } -Controller.$inject = ['$scope']; - ngModule.component('vnClaimIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/claim/front/photos/index.html b/modules/claim/front/photos/index.html index 447538bd1..4a6e3e7b2 100644 --- a/modules/claim/front/photos/index.html +++ b/modules/claim/front/photos/index.html @@ -1,10 +1,9 @@ -
@@ -12,8 +11,8 @@
+ ng-style="{'background': 'url(/api/dms/' + photo.dmsFk + '/downloadFile?access_token=' + $ctrl.vnToken.token + ')'}" + zoom-image="/api/dms/{{::photo.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}">
{ $httpParamSerializer = _$httpParamSerializer_; $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - controller = $componentController('vnClaimPhotos', {$: $scope}); + const $element = angular.element(''); + controller = $componentController('vnClaimPhotos', {$element, $scope}); controller.$.model = crudModel; controller.claim = { id: 1, diff --git a/modules/claim/front/summary/index.html b/modules/claim/front/summary/index.html index 20dca702b..6f639c709 100644 --- a/modules/claim/front/summary/index.html +++ b/modules/claim/front/summary/index.html @@ -86,8 +86,8 @@
+ ng-style="{'background': 'url(/api/dms/' + photo.dmsFk + '/downloadFile?access_token=' + $ctrl.vnToken.token + ')'}" + zoom-image="/api/dms/{{::photo.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}">
diff --git a/modules/claim/front/summary/index.js b/modules/claim/front/summary/index.js index 448ce9b38..06dedfbce 100644 --- a/modules/claim/front/summary/index.js +++ b/modules/claim/front/summary/index.js @@ -1,34 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, $stateParams, vnToken) { - this.$http = $http; - this.$ = $scope; - this.$stateParams = $stateParams; - this.accessToken = vnToken.token; - } - - get claim() { - return this._claim; - } - - - set claim(value) { - this._claim = value; - - // Get DMS on summary load - if (value) - this.$.$applyAsync(() => this.loadDms()); - } - - loadDms() { - this.$.model.where = { - claimFk: this.claim.id - }; - this.$.model.refresh(); - } - +class Controller extends Section { getSummary() { this.$http.get(`Claims/${this.claim.id}/getSummary`).then(response => { this.summary = response.data; @@ -36,8 +10,13 @@ class Controller { } $onChanges() { - if (this.claim && this.claim.id) + if (this.claim && this.claim.id) { this.getSummary(); + this.$.model.where = { + claimFk: this.claim.id + }; + this.$.model.refresh(); + } } showItemDescriptor(event, itemFk) { @@ -59,8 +38,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$stateParams', 'vnToken']; - ngModule.component('vnClaimSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/claim/front/summary/index.spec.js b/modules/claim/front/summary/index.spec.js index f1897a3e0..8b8369516 100644 --- a/modules/claim/front/summary/index.spec.js +++ b/modules/claim/front/summary/index.spec.js @@ -5,13 +5,16 @@ describe('Claim', () => { describe('Component summary', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { + $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - controller = $componentController('vnClaimSummary'); - controller.claim = {id: 1}; + const $element = angular.element(''); + controller = $componentController('vnClaimSummary', {$element, $scope}); + controller._claim = {id: 1}; controller.$.model = crudModel; })); @@ -29,6 +32,7 @@ describe('Claim', () => { describe('$onChanges()', () => { it('should call getSummary when item.id is defined', () => { jest.spyOn(controller, 'getSummary'); + controller.$onChanges(); expect(controller.getSummary).toHaveBeenCalledWith(); From 381f2a08efacf247651c729eb68e6296f9d3e328 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 17 Mar 2020 11:17:50 +0100 Subject: [PATCH 02/44] Client refactor --- modules/claim/front/summary/index.spec.js | 2 +- modules/client/front/address/create/index.js | 4 ++-- modules/client/front/address/edit/index.js | 4 ++-- modules/client/front/address/index/index.html | 2 +- modules/client/front/address/index/index.js | 15 +++++-------- .../client/front/address/index/index.spec.js | 5 +++-- modules/client/front/balance/index/index.html | 2 +- modules/client/front/balance/index/index.js | 20 ++++++----------- .../client/front/balance/index/index.spec.js | 5 +++-- modules/client/front/basic-data/index.js | 2 ++ modules/client/front/contact/index.html | 2 +- modules/client/front/contact/index.js | 22 ++++++------------- modules/client/front/create/index.js | 13 +++++------ modules/client/front/create/index.spec.js | 3 ++- .../front/credit-insurance/create/index.js | 17 ++++++-------- .../credit-insurance/create/index.spec.js | 3 ++- .../front/credit-insurance/index/index.js | 12 +++------- .../credit-insurance/index/index.spec.js | 13 ++++++----- .../insurance/create/index.js | 16 +++++++------- .../insurance/index/index.html | 4 ++-- .../credit-insurance/insurance/index/index.js | 12 +++++----- .../insurance/index/index.spec.js | 9 +++++--- modules/client/front/credit/create/index.js | 17 +++++--------- .../client/front/credit/create/index.spec.js | 7 +++--- modules/client/front/credit/index/index.html | 2 +- modules/client/front/credit/index/index.js | 9 ++++---- modules/client/front/dms/create/index.js | 14 +++++------- modules/client/front/dms/create/index.spec.js | 3 ++- modules/client/front/dms/edit/index.js | 18 ++++----------- modules/client/front/dms/edit/index.spec.js | 6 ++--- modules/client/front/dms/index/index.html | 6 ++--- modules/client/front/dms/index/index.js | 14 +++++------- modules/client/front/dms/index/index.spec.js | 3 ++- modules/client/front/fiscal-data/index.js | 4 ++-- modules/client/front/greuge/create/index.js | 12 +++++----- .../client/front/greuge/create/index.spec.js | 3 ++- modules/client/front/greuge/index/index.html | 4 ++-- modules/client/front/greuge/index/index.js | 9 ++++---- modules/client/front/index/index.js | 10 ++------- modules/client/front/index/index.spec.js | 7 ++++-- modules/client/front/log/index.html | 2 +- modules/client/front/log/index.js | 12 ++-------- modules/client/front/mandate/index.html | 2 +- modules/client/front/mandate/index.js | 9 ++++---- modules/client/front/note/index/index.html | 4 ++-- modules/client/front/note/index/index.js | 9 ++++---- modules/client/front/postcode/index.js | 10 --------- modules/client/front/postcode/index.spec.js | 9 ++++---- modules/client/front/recovery/create/index.js | 12 +++++----- .../front/recovery/create/index.spec.js | 3 ++- .../client/front/recovery/index/index.html | 2 +- modules/client/front/recovery/index/index.js | 13 +++-------- modules/client/front/sample/create/index.js | 18 ++++++--------- modules/client/front/sample/index/index.html | 2 +- modules/client/front/sample/index/index.js | 10 ++++----- modules/client/front/sms/index.js | 17 ++++---------- modules/client/front/sms/index.spec.js | 4 ++-- modules/client/front/summary/index.js | 9 ++------ modules/client/front/summary/index.spec.js | 7 ++++-- modules/client/front/web-access/index.js | 12 +++++----- modules/client/front/web-access/index.spec.js | 3 ++- modules/client/front/web-payment/index.html | 2 +- modules/client/front/web-payment/index.js | 13 +++-------- .../client/front/web-payment/index.spec.js | 3 ++- 64 files changed, 220 insertions(+), 302 deletions(-) diff --git a/modules/claim/front/summary/index.spec.js b/modules/claim/front/summary/index.spec.js index 8b8369516..b6e03d929 100644 --- a/modules/claim/front/summary/index.spec.js +++ b/modules/claim/front/summary/index.spec.js @@ -14,7 +14,7 @@ describe('Claim', () => { $httpBackend = _$httpBackend_; const $element = angular.element(''); controller = $componentController('vnClaimSummary', {$element, $scope}); - controller._claim = {id: 1}; + controller.claim = {id: 1}; controller.$.model = crudModel; })); diff --git a/modules/client/front/address/create/index.js b/modules/client/front/address/create/index.js index 9070c876f..69087f154 100644 --- a/modules/client/front/address/create/index.js +++ b/modules/client/front/address/create/index.js @@ -1,7 +1,7 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -export default class Controller extends Component { +export default class Controller extends Section { constructor($element, $) { super($element, $); diff --git a/modules/client/front/address/edit/index.js b/modules/client/front/address/edit/index.js index f310b7250..f2d660334 100644 --- a/modules/client/front/address/edit/index.js +++ b/modules/client/front/address/edit/index.js @@ -1,7 +1,7 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -export default class Controller extends Component { +export default class Controller extends Section { removeObservation(index) { this.$.watcher.setDirty(); this.$.model.remove(index); diff --git a/modules/client/front/address/index/index.html b/modules/client/front/address/index/index.html index c78f51748..bdf4496ce 100644 --- a/modules/client/front/address/index/index.html +++ b/modules/client/front/address/index/index.html @@ -1,6 +1,6 @@ { if (res.data) { @@ -72,7 +69,7 @@ class Controller { }); } } -Controller.$inject = ['$http', '$scope', '$stateParams', '$translate', 'vnApp']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientAddressIndex', { template: require('./index.html'), diff --git a/modules/client/front/address/index/index.spec.js b/modules/client/front/address/index/index.spec.js index 1398f617f..d53abe8be 100644 --- a/modules/client/front/address/index/index.spec.js +++ b/modules/client/front/address/index/index.spec.js @@ -15,9 +15,10 @@ describe('Client', () => { $stateParams.id = 1; $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - controller = $componentController('vnClientAddressIndex', {$stateParams, $scope}); + const $element = angular.element(''); + controller = $componentController('vnClientAddressIndex', {$element, $scope}); controller.client = {id: 101, defaultAddressFk: 121}; - controller.$scope.model = crudModel; + controller.$.model = crudModel; })); describe('setDefault()', () => { diff --git a/modules/client/front/balance/index/index.html b/modules/client/front/balance/index/index.html index 8cdb5c971..1e26607d1 100644 --- a/modules/client/front/balance/index/index.html +++ b/modules/client/front/balance/index/index.html @@ -97,7 +97,7 @@ + href="InvoiceOuts/{{::balance.id}}/download?access_token={{::$ctrl.vnToken.token}}"> diff --git a/modules/client/front/balance/index/index.js b/modules/client/front/balance/index/index.js index 5a5d0e0b2..13840af92 100644 --- a/modules/client/front/balance/index/index.js +++ b/modules/client/front/balance/index/index.js @@ -1,14 +1,10 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($stateParams, $translate, $scope, vnToken, $http, vnConfig) { - this.$http = $http; - this.$ = $scope; - this.$stateParams = $stateParams; - this.$translate = $translate; - this.accessToken = vnToken.token; - this.vnConfig = vnConfig; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: { relation: 'company', @@ -46,17 +42,16 @@ class Controller { getData() { return this.$.model.applyFilter(null, { - clientId: this.$stateParams.id, + clientId: this.$params.id, companyId: this.companyId }).then(() => this.$.riskModel.applyFilter({ where: { - clientFk: this.$stateParams.id, + clientFk: this.$params.id, companyFk: this.companyId } })).then(() => this.getBalances()); } - getCurrentBalance() { const clientRisks = this.$.riskModel.data; const selectedCompany = this.companyId; @@ -79,7 +74,6 @@ class Controller { }); } - openCreateDialog() { this.$.balanceCreateDialog.companyFk = this.companyId; this.$.balanceCreateDialog.onResponse = () => this.getData(); @@ -110,7 +104,7 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$translate', '$scope', 'vnToken', '$http', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientBalanceIndex', { template: require('./index.html'), diff --git a/modules/client/front/balance/index/index.spec.js b/modules/client/front/balance/index/index.spec.js index aaa12b2e3..37b345c57 100644 --- a/modules/client/front/balance/index/index.spec.js +++ b/modules/client/front/balance/index/index.spec.js @@ -10,7 +10,8 @@ describe('Client', () => { beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { $componentController = _$componentController_; let $scope = $rootScope.$new(); - controller = $componentController('vnClientBalanceIndex', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnClientBalanceIndex', {$element, $scope}); controller.$.model = {applyFilter: () => {}}; controller.$.riskModel = { applyFilter: () => {}, @@ -30,7 +31,7 @@ describe('Client', () => { describe('getData()', () => { it('should apply the filters on he models and get the client balance', () => { controller._companyId = 442; - controller.$stateParams.id = 101; + controller.$params.id = 101; jest.spyOn(controller, 'getBalances').mockReturnThis(); jest.spyOn(controller.$.model, 'applyFilter').mockReturnValue(Promise.resolve()); jest.spyOn(controller.$.riskModel, 'applyFilter').mockReturnValue(Promise.resolve()); diff --git a/modules/client/front/basic-data/index.js b/modules/client/front/basic-data/index.js index 093ef4bec..5d491ec75 100644 --- a/modules/client/front/basic-data/index.js +++ b/modules/client/front/basic-data/index.js @@ -1,7 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; ngModule.component('vnClientBasicData', { template: require('./index.html'), + controller: Section, bindings: { client: '<' } diff --git a/modules/client/front/contact/index.html b/modules/client/front/contact/index.html index 2cefdd86d..664a59567 100644 --- a/modules/client/front/contact/index.html +++ b/modules/client/front/contact/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ClientContacts" fields="['id', 'name', 'phone', 'clientFk']" - link="{clientFk: $ctrl.$stateParams.id}" + link="{clientFk: $ctrl.$params.id}" data="contacts" auto-load="true"> diff --git a/modules/client/front/contact/index.js b/modules/client/front/contact/index.js index 4b0cc95ca..aaf64d768 100644 --- a/modules/client/front/contact/index.js +++ b/modules/client/front/contact/index.js @@ -1,14 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams, $translate) { - this.$scope = $scope; - this.$stateParams = $stateParams; - this.$translate = $translate; - } - +class Controller extends Section { add() { - this.$scope.model.insert({ + this.$.model.insert({ clientFk: this.client.id, name: this.$translate.instant('Phone'), phone: null @@ -16,16 +11,13 @@ class Controller { } onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); - }); + this.$.watcher.check(); + this.$.model.save().then(() => + this.$.watcher.notifySaved() + ); } } -Controller.$inject = ['$scope', '$stateParams', '$translate']; - ngModule.component('vnClientContact', { template: require('./index.html'), controller: Controller, diff --git a/modules/client/front/create/index.js b/modules/client/front/create/index.js index a663717d6..cce41b3bc 100644 --- a/modules/client/front/create/index.js +++ b/modules/client/front/create/index.js @@ -1,12 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state, $http, $translate, vnApp) { - this.$ = $scope; - this.$state = $state; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); this.client = { active: true }; @@ -78,7 +75,7 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientCreate', { template: require('./index.html'), diff --git a/modules/client/front/create/index.spec.js b/modules/client/front/create/index.spec.js index c297b0545..b02e38383 100644 --- a/modules/client/front/create/index.spec.js +++ b/modules/client/front/create/index.spec.js @@ -22,7 +22,8 @@ describe('Client', () => { }; } }; - controller = $componentController('vnClientCreate', {$scope: $scope}); + const $element = angular.element(''); + controller = $componentController('vnClientCreate', {$element, $scope}); })); it('should define and set scope, state and client properties', () => { diff --git a/modules/client/front/credit-insurance/create/index.js b/modules/client/front/credit-insurance/create/index.js index 86c067086..5ea2a8039 100644 --- a/modules/client/front/credit-insurance/create/index.js +++ b/modules/client/front/credit-insurance/create/index.js @@ -1,19 +1,16 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($http, $filter, $state, $scope, $translate, vnApp) { - this.$http = $http; - this.$state = $state; - this.$scope = $scope; - this.$translate = $translate; - this.vnApp = vnApp; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.creditClassification = { - started: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm') + started: this.$filter('date')(new Date(), 'yyyy-MM-dd HH:mm') }; } onSubmit() { - if (this.$scope.form.$invalid) + if (this.$.form.$invalid) return this.vnApp.showError(this.$translate.instant('Some fields are invalid')); let query = `creditClassifications/createWithInsurance`; @@ -29,7 +26,7 @@ class Controller { } } -Controller.$inject = ['$http', '$filter', '$state', '$scope', '$translate', 'vnApp']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientCreditInsuranceCreate', { template: require('./index.html'), diff --git a/modules/client/front/credit-insurance/create/index.spec.js b/modules/client/front/credit-insurance/create/index.spec.js index 1d1cd0e08..29bd2c11e 100644 --- a/modules/client/front/credit-insurance/create/index.spec.js +++ b/modules/client/front/credit-insurance/create/index.spec.js @@ -14,7 +14,8 @@ describe('Client', () => { $scope.form = { $invalid: false }; - controller = $componentController('vnClientCreditInsuranceCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnClientCreditInsuranceCreate', {$element, $scope}); controller.client = {id: 101}; controller.card = { reload: () => {} diff --git a/modules/client/front/credit-insurance/index/index.js b/modules/client/front/credit-insurance/index/index.js index accdc8c5d..e386444f4 100644 --- a/modules/client/front/credit-insurance/index/index.js +++ b/modules/client/front/credit-insurance/index/index.js @@ -1,12 +1,8 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($http, $scope) { - this.$http = $http; - this.$scope = $scope; - } - +class Controller extends Section { $onChanges() { if (this.client && this.client.id) this._getClassifications(this.client.id); @@ -52,7 +48,7 @@ class Controller { closeContract(classification) { this.classificationId = classification.id; - this.$scope.closeContract.show(); + this.$.closeContract.show(); } returnDialog(response) { @@ -65,8 +61,6 @@ class Controller { } } -Controller.$inject = ['$http', '$scope']; - ngModule.component('vnClientCreditInsuranceIndex', { template: require('./index.html'), controller: Controller, diff --git a/modules/client/front/credit-insurance/index/index.spec.js b/modules/client/front/credit-insurance/index/index.spec.js index 48403263e..bed58a7d6 100644 --- a/modules/client/front/credit-insurance/index/index.spec.js +++ b/modules/client/front/credit-insurance/index/index.spec.js @@ -4,12 +4,15 @@ describe('Client', () => { describe('Component vnClientCreditInsuranceIndex', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnClientCreditInsuranceIndex'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnClientCreditInsuranceIndex', {$element, $scope}); controller.client = {id: 101}; })); @@ -59,14 +62,14 @@ describe('Client', () => { describe('closeContract()', () => { it('should define the classificationId property of the controller and then call the show method()', () => { - controller.$scope.closeContract = {show: () => {}}; - jest.spyOn(controller.$scope.closeContract, 'show'); + controller.$.closeContract = {show: () => {}}; + jest.spyOn(controller.$.closeContract, 'show'); expect(controller.classificationId).toBeFalsy(); controller.closeContract({id: 1}); expect(controller.classificationId).toEqual(1); - expect(controller.$scope.closeContract.show).toHaveBeenCalledWith(); + expect(controller.$.closeContract.show).toHaveBeenCalledWith(); }); }); diff --git a/modules/client/front/credit-insurance/insurance/create/index.js b/modules/client/front/credit-insurance/insurance/create/index.js index 2c7670ff5..2363cac76 100644 --- a/modules/client/front/credit-insurance/insurance/create/index.js +++ b/modules/client/front/credit-insurance/insurance/create/index.js @@ -1,25 +1,25 @@ import ngModule from '../../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state, $filter) { - this.$scope = $scope; - this.$state = $state; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.insurance = { - created: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss') + created: this.$filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss') }; } onSubmit() { - let params = {classificationId: this.$state.params.classificationId}; + let params = {classificationId: this.$params.classificationId}; let state = 'client.card.creditInsurance.insurance.index'; - this.$scope.watcher.submitGo(state, params).then(() => { + this.$.watcher.submitGo(state, params).then(() => { this.card.reload(); }); } } -Controller.$inject = ['$scope', '$state', '$filter']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientCreditInsuranceInsuranceCreate', { template: require('./index.html'), diff --git a/modules/client/front/credit-insurance/insurance/index/index.html b/modules/client/front/credit-insurance/insurance/index/index.html index 28f44f044..11c9935d0 100644 --- a/modules/client/front/credit-insurance/insurance/index/index.html +++ b/modules/client/front/credit-insurance/insurance/index/index.html @@ -1,7 +1,7 @@ @@ -30,7 +30,7 @@ diff --git a/modules/client/front/credit-insurance/insurance/index/index.js b/modules/client/front/credit-insurance/insurance/index/index.js index 4851bf200..f78d06785 100644 --- a/modules/client/front/credit-insurance/insurance/index/index.js +++ b/modules/client/front/credit-insurance/insurance/index/index.js @@ -1,9 +1,9 @@ import ngModule from '../../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($stateParams, $http) { - this.$stateParams = $stateParams; - this.$http = $http; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.isClosed = true; this.filter = { include: [ @@ -15,7 +15,7 @@ class Controller { $onInit() { let filter = { fields: ['finished'], - where: {id: this.$stateParams.classificationId} + where: {id: this.$params.classificationId} }; filter = encodeURIComponent(JSON.stringify(filter)); @@ -27,7 +27,7 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$http']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientCreditInsuranceInsuranceIndex', { template: require('./index.html'), diff --git a/modules/client/front/credit-insurance/insurance/index/index.spec.js b/modules/client/front/credit-insurance/insurance/index/index.spec.js index 8c3cdee83..490d6a924 100644 --- a/modules/client/front/credit-insurance/insurance/index/index.spec.js +++ b/modules/client/front/credit-insurance/insurance/index/index.spec.js @@ -4,13 +4,16 @@ describe('Client', () => { describe('Component vnClientCreditInsuranceInsuranceIndex', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { - let $stateParams = {classificationId: 1}; + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { + $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - controller = $componentController('vnClientCreditInsuranceInsuranceIndex', {$stateParams}); + const $element = angular.element(''); + controller = $componentController('vnClientCreditInsuranceInsuranceIndex', {$element, $scope}); + controller.$params = {classificationId: 1}; })); describe('$onInit()', () => { diff --git a/modules/client/front/credit/create/index.js b/modules/client/front/credit/create/index.js index 7493073b6..049c206b3 100644 --- a/modules/client/front/credit/create/index.js +++ b/modules/client/front/credit/create/index.js @@ -1,17 +1,12 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($http, $scope, $state) { - this.$http = $http; - this.$scope = $scope; - this.$state = $state; - } - +class Controller extends Section { onSubmit() { - this.$http.get(`Recoveries/${this.$state.params.id}/hasActiveRecovery`).then(res => { + this.$http.get(`Recoveries/${this.$params.id}/hasActiveRecovery`).then(res => { let activeRecovery = res.data; if (activeRecovery) - this.$scope.confirmation.show(); + this.$.confirmation.show(); else this.addCredit(); }); @@ -31,7 +26,7 @@ class Controller { } addCredit() { - this.$scope.watcher.submit().then( + this.$.watcher.submit().then( () => { this.goToIndex(); } @@ -39,8 +34,6 @@ class Controller { } } -Controller.$inject = ['$http', '$scope', '$state']; - ngModule.component('vnClientCreditCreate', { template: require('./index.html'), controller: Controller, diff --git a/modules/client/front/credit/create/index.spec.js b/modules/client/front/credit/create/index.spec.js index 13f034969..a69fb64a9 100644 --- a/modules/client/front/credit/create/index.spec.js +++ b/modules/client/front/credit/create/index.spec.js @@ -30,7 +30,8 @@ describe('Client', () => { $state = _$state_; $state.params.id = 101; $httpBackend = _$httpBackend_; - controller = $componentController('vnClientCreditCreate', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnClientCreditCreate', {$element, $scope}); })); describe('onSubmit()', () => { @@ -42,13 +43,13 @@ describe('Client', () => { }); it('should call show() method when the client have a recovery', () => { - jest.spyOn(controller.$scope.confirmation, 'show'); + jest.spyOn(controller.$.confirmation, 'show'); $httpBackend.whenGET(`Recoveries/101/hasActiveRecovery`).respond(true); $httpBackend.expectGET(`Recoveries/101/hasActiveRecovery`); controller.onSubmit(); $httpBackend.flush(); - expect(controller.$scope.confirmation.show).toHaveBeenCalledWith(); + expect(controller.$.confirmation.show).toHaveBeenCalledWith(); }); it('should call addCredit() method when the client doesnt have a recovery', () => { diff --git a/modules/client/front/credit/index/index.html b/modules/client/front/credit/index/index.html index 03de6f0e7..6cb7f9e84 100644 --- a/modules/client/front/credit/index/index.html +++ b/modules/client/front/credit/index/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ClientCredits" filter="::$ctrl.filter" - link="{clientFk: $ctrl.$stateParams.id}" + link="{clientFk: $ctrl.$params.id}" limit="20" data="credits" order="created DESC" diff --git a/modules/client/front/credit/index/index.js b/modules/client/front/credit/index/index.js index e8fae8d9d..bea30b2d1 100644 --- a/modules/client/front/credit/index/index.js +++ b/modules/client/front/credit/index/index.js @@ -1,8 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($stateParams) { - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [ { @@ -22,7 +23,7 @@ class Controller { } } -Controller.$inject = ['$stateParams']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientCreditIndex', { template: require('./index.html'), diff --git a/modules/client/front/dms/create/index.js b/modules/client/front/dms/create/index.js index 46c4d7565..0422ab6a6 100644 --- a/modules/client/front/dms/create/index.js +++ b/modules/client/front/dms/create/index.js @@ -1,14 +1,10 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp, vnConfig) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - this.vnConfig = vnConfig; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.dms = { files: [], hasFile: false, @@ -106,7 +102,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientDmsCreate', { template: require('./index.html'), diff --git a/modules/client/front/dms/create/index.spec.js b/modules/client/front/dms/create/index.spec.js index 2c1215d6b..0f0e2cb09 100644 --- a/modules/client/front/dms/create/index.spec.js +++ b/modules/client/front/dms/create/index.spec.js @@ -13,7 +13,8 @@ describe('Client', () => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnClientDmsCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnClientDmsCreate', {$element, $scope}); controller._client = {id: 101, name: 'Bruce wayne'}; })); diff --git a/modules/client/front/dms/edit/index.js b/modules/client/front/dms/edit/index.js index 460aa17a7..dedd67e3f 100644 --- a/modules/client/front/dms/edit/index.js +++ b/modules/client/front/dms/edit/index.js @@ -1,16 +1,8 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$stateParams = $state.params; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Section { get client() { return this._client; } @@ -38,7 +30,7 @@ class Controller { } setDefaultParams() { - const path = `Dms/${this.$stateParams.dmsId}`; + const path = `Dms/${this.$params.dmsId}`; this.$http.get(path).then(res => { const dms = res.data && res.data; this.dms = { @@ -55,7 +47,7 @@ class Controller { } onSubmit() { - const query = `dms/${this.$stateParams.dmsId}/updateFile`; + const query = `dms/${this.$params.dmsId}/updateFile`; const options = { method: 'POST', url: query, @@ -93,8 +85,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp']; - ngModule.component('vnClientDmsEdit', { template: require('./index.html'), controller: Controller, diff --git a/modules/client/front/dms/edit/index.spec.js b/modules/client/front/dms/edit/index.spec.js index 4d432cfd0..f4aaf52f8 100644 --- a/modules/client/front/dms/edit/index.spec.js +++ b/modules/client/front/dms/edit/index.spec.js @@ -5,16 +5,16 @@ describe('Client', () => { let controller; let $scope; let $httpBackend; - let $state; beforeEach(ngModule('client')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - $state = {params: {dmsId: 1}}; - controller = $componentController('vnClientDmsEdit', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnClientDmsEdit', {$element, $scope}); controller._client = {id: 1}; + controller.$params = {dmsId: 1}; })); describe('client() setter', () => { diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index 78bc45b57..987613d72 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -1,7 +1,7 @@ + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> {{::document.dms.file}} @@ -70,7 +70,7 @@ + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> diff --git a/modules/client/front/dms/index/index.js b/modules/client/front/dms/index/index.js index 0f1c8a2dc..2b47c3e57 100644 --- a/modules/client/front/dms/index/index.js +++ b/modules/client/front/dms/index/index.js @@ -1,14 +1,10 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($stateParams, $scope, vnToken, $http, vnApp, $translate) { - this.$stateParams = $stateParams; - this.$ = $scope; - this.accessToken = vnToken.token; - this.$http = $http; - this.vnApp = vnApp; - this.$translate = $translate; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: { relation: 'dms', @@ -71,7 +67,7 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$scope', 'vnToken', '$http', 'vnApp', '$translate']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientDmsIndex', { template: require('./index.html'), diff --git a/modules/client/front/dms/index/index.spec.js b/modules/client/front/dms/index/index.spec.js index 49b6014c0..388fff8ce 100644 --- a/modules/client/front/dms/index/index.spec.js +++ b/modules/client/front/dms/index/index.spec.js @@ -14,7 +14,8 @@ describe('Client', () => { $componentController = _$componentController_; $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - controller = $componentController('vnClientDmsIndex', {$: $scope}); + const $element = angular.element(''); + controller = $componentController('vnClientDmsIndex', {$element, $scope}); controller.$.model = crudModel; })); diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index f302606dd..fdbb0fafc 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -export default class Controller extends Component { +export default class Controller extends Section { onSubmit() { const orgData = this.$.watcher.orgData; delete this.client.despiteOfClient; diff --git a/modules/client/front/greuge/create/index.js b/modules/client/front/greuge/create/index.js index b0a2eec93..3154d15f0 100644 --- a/modules/client/front/greuge/create/index.js +++ b/modules/client/front/greuge/create/index.js @@ -1,12 +1,12 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state, $filter) { - this.$ = $scope; - this.$state = $state; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.greuge = { shipped: new Date(), - clientFk: $state.params.id + clientFk: this.$params.id }; } @@ -26,7 +26,7 @@ class Controller { ); } } -Controller.$inject = ['$scope', '$state', '$filter']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientGreugeCreate', { template: require('./index.html'), diff --git a/modules/client/front/greuge/create/index.spec.js b/modules/client/front/greuge/create/index.spec.js index 73563ca3d..342814747 100644 --- a/modules/client/front/greuge/create/index.spec.js +++ b/modules/client/front/greuge/create/index.spec.js @@ -22,7 +22,8 @@ describe('Client', () => { }; } }; - controller = $componentController('vnClientGreugeCreate', {$scope: $scope}); + const $element = angular.element(''); + controller = $componentController('vnClientGreugeCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index 683ac0afe..463ac6303 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -2,13 +2,13 @@ vn-id="model" url="greuges" filter="::$ctrl.filter" - link="{clientFk: $ctrl.$stateParams.id}" + link="{clientFk: $ctrl.$params.id}" limit="20" data="greuges" auto-load="true"> { let $state; + let $scope; let controller; beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, _$state_) => { + beforeEach(angular.mock.inject(($componentController, _$state_, $rootScope) => { $state = _$state_; - controller = $componentController('vnClientIndex'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnClientIndex', {$element, $scope}); })); describe('filterTickets()', () => { diff --git a/modules/client/front/log/index.html b/modules/client/front/log/index.html index 90874d0cb..881d5c039 100644 --- a/modules/client/front/log/index.html +++ b/modules/client/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/client/front/log/index.js b/modules/client/front/log/index.js index 2f01d229c..e4cac6e58 100644 --- a/modules/client/front/log/index.js +++ b/modules/client/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnClientLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/client/front/mandate/index.html b/modules/client/front/mandate/index.html index 79016761f..3084646da 100644 --- a/modules/client/front/mandate/index.html +++ b/modules/client/front/mandate/index.html @@ -2,7 +2,7 @@ vn-id="model" url="Mandates" filter="::$ctrl.filter" - link="{clientFk: $ctrl.$stateParams.id}" + link="{clientFk: $ctrl.$params.id}" limit="20" data="mandates" order="created DESC" diff --git a/modules/client/front/mandate/index.js b/modules/client/front/mandate/index.js index 607bb335b..640678e42 100644 --- a/modules/client/front/mandate/index.js +++ b/modules/client/front/mandate/index.js @@ -1,8 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($stateParams) { - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [ { @@ -21,7 +22,7 @@ class Controller { } } -Controller.$inject = ['$stateParams']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientMandate', { template: require('./index.html'), diff --git a/modules/client/front/note/index/index.html b/modules/client/front/note/index/index.html index a77362ff6..634a9c3ce 100644 --- a/modules/client/front/note/index/index.html +++ b/modules/client/front/note/index/index.html @@ -2,7 +2,7 @@ vn-id="model" url="clientObservations" filter="$ctrl.filter" - link="{clientFk: $ctrl.$stateParams.id}" + link="{clientFk: $ctrl.$params.id}" data="notes" auto-load="true"> @@ -24,7 +24,7 @@ diff --git a/modules/client/front/note/index/index.js b/modules/client/front/note/index/index.js index ef1f0d5fb..654c460e4 100644 --- a/modules/client/front/note/index/index.js +++ b/modules/client/front/note/index/index.js @@ -1,16 +1,17 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -export default class Controller { - constructor($stateParams) { - this.$stateParams = $stateParams; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { order: 'created DESC', }; } } -Controller.$inject = ['$stateParams']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientNote', { template: require('./index.html'), diff --git a/modules/client/front/postcode/index.js b/modules/client/front/postcode/index.js index 836ea9a81..c05ea0518 100644 --- a/modules/client/front/postcode/index.js +++ b/modules/client/front/postcode/index.js @@ -3,14 +3,6 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $translate, vnApp) { - super($element, $scope); - this.$ = $scope; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - } - get townSelection() { return this._townSelection; } @@ -54,8 +46,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp']; - ngModule.component('vnClientPostcode', { template: require('./index.html'), controller: Controller, diff --git a/modules/client/front/postcode/index.spec.js b/modules/client/front/postcode/index.spec.js index a5e5db9d5..2cefb6985 100644 --- a/modules/client/front/postcode/index.spec.js +++ b/modules/client/front/postcode/index.spec.js @@ -4,14 +4,15 @@ describe('Client', () => { describe('Component vnClientPostcode', () => { let controller; let $httpBackend; - let $element; + let $scope; beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - $element = angular.element(''); - controller = $componentController('vnClientPostcode', {$element}); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnClientPostcode', {$element, $scope}); controller.client = {id: 101}; })); diff --git a/modules/client/front/recovery/create/index.js b/modules/client/front/recovery/create/index.js index ee69e0861..aa378203b 100644 --- a/modules/client/front/recovery/create/index.js +++ b/modules/client/front/recovery/create/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state, $filter) { - this.$ = $scope; - this.$state = $state; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.recovery = { started: new Date() }; @@ -18,7 +18,7 @@ class Controller { } onSubmit() { - this.recovery.clientFk = this.$state.params.id; + this.recovery.clientFk = this.$params.id; this.$.watcher.submit().then( () => { this.goToIndex(); @@ -26,7 +26,7 @@ class Controller { ); } } -Controller.$inject = ['$scope', '$state', '$filter']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientRecoveryCreate', { template: require('./index.html'), diff --git a/modules/client/front/recovery/create/index.spec.js b/modules/client/front/recovery/create/index.spec.js index cf28cee8d..7cd198184 100644 --- a/modules/client/front/recovery/create/index.spec.js +++ b/modules/client/front/recovery/create/index.spec.js @@ -22,7 +22,8 @@ describe('Client', () => { }; } }; - controller = $componentController('vnClientRecoveryCreate', {$scope: $scope}); + const $element = angular.element(''); + controller = $componentController('vnClientRecoveryCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/client/front/recovery/index/index.html b/modules/client/front/recovery/index/index.html index d5c28dc88..214dff822 100644 --- a/modules/client/front/recovery/index/index.html +++ b/modules/client/front/recovery/index/index.html @@ -1,7 +1,7 @@ this.$scope.model.refresh() + () => this.$.model.refresh() ); } } } -Controller.$inject = ['$stateParams', '$scope', '$http']; - ngModule.component('vnClientRecoveryIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index f478243c7..bfb0fd287 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -1,16 +1,13 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { - constructor($element, $, vnApp, $httpParamSerializer, vnConfig) { +class Controller extends Section { + constructor($element, $) { super($element, $); - this.vnApp = vnApp; - this.$httpParamSerializer = $httpParamSerializer; - this.vnConfig = vnConfig; this.clientSample = { clientFk: this.$params.id, - companyId: vnConfig.companyFk + companyId: this.vnConfig.companyFk }; } @@ -82,12 +79,11 @@ class Controller extends Component { if (isPreview) params.isPreview = true; - const serializedParams = this.$httpParamSerializer(params); - const query = `email/${sampleType.code}?${serializedParams}`; - this.$http.get(query).then(cb); + const query = `email/${sampleType.code}`; + this.$http.get(query, {params}).then(cb); } } -Controller.$inject = ['$element', '$scope', 'vnApp', '$httpParamSerializer', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientSampleCreate', { template: require('./index.html'), diff --git a/modules/client/front/sample/index/index.html b/modules/client/front/sample/index/index.html index 4825d4121..dfd662ba5 100644 --- a/modules/client/front/sample/index/index.html +++ b/modules/client/front/sample/index/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ClientSamples" filter="::$ctrl.filter" - link="{clientFk: $ctrl.$stateParams.id}" + link="{clientFk: $ctrl.$params.id}" limit="20" data="samples" order="created DESC" diff --git a/modules/client/front/sample/index/index.js b/modules/client/front/sample/index/index.js index 4ce12e27c..48f9319ce 100644 --- a/modules/client/front/sample/index/index.js +++ b/modules/client/front/sample/index/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$ = $scope; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [ { @@ -45,7 +45,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$stateParams']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientSampleIndex', { template: require('./index.html'), diff --git a/modules/client/front/sms/index.js b/modules/client/front/sms/index.js index c7d89e717..3dfdda8a3 100644 --- a/modules/client/front/sms/index.js +++ b/modules/client/front/sms/index.js @@ -1,23 +1,14 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { - constructor($element, $scope, $http, $translate, vnApp) { - super($element, $scope); - - this.$scope = $scope; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Section { open() { - this.$scope.SMSDialog.show(); + this.$.SMSDialog.show(); } charactersRemaining() { - const element = this.$scope.message; + const element = this.$.message; const value = element.input.value; const maxLength = 160; diff --git a/modules/client/front/sms/index.spec.js b/modules/client/front/sms/index.spec.js index 3958aec3b..a7b4cd3df 100644 --- a/modules/client/front/sms/index.spec.js +++ b/modules/client/front/sms/index.spec.js @@ -15,7 +15,7 @@ describe('Client', () => { controller = $componentController('vnClientSms', {$element, $scope}); controller.client = {id: 101}; controller.$params = {id: 101}; - controller.$scope.message = { + controller.$.message = { input: { value: 'My SMS' } @@ -59,7 +59,7 @@ describe('Client', () => { describe('charactersRemaining()', () => { it('should return the characters remaining in a element', () => { - controller.$scope.message = { + controller.$.message = { input: { value: 'My message 0€' } diff --git a/modules/client/front/summary/index.js b/modules/client/front/summary/index.js index fdf0984b7..4dd299903 100644 --- a/modules/client/front/summary/index.js +++ b/modules/client/front/summary/index.js @@ -1,11 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($http) { - this.$http = $http; - } - +class Controller extends Section { $onChanges() { if (!this.client) return; @@ -41,8 +38,6 @@ class Controller { } } -Controller.$inject = ['$http']; - ngModule.component('vnClientSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/client/front/summary/index.spec.js b/modules/client/front/summary/index.spec.js index 15607008a..1c747d25a 100644 --- a/modules/client/front/summary/index.spec.js +++ b/modules/client/front/summary/index.spec.js @@ -4,12 +4,15 @@ describe('Client', () => { describe('Component vnClientSummary', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnClientSummary'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnClientSummary', {$element, $scope}); controller.client = {id: 101}; })); diff --git a/modules/client/front/web-access/index.js b/modules/client/front/web-access/index.js index bdd5375a3..3f7f46f04 100644 --- a/modules/client/front/web-access/index.js +++ b/modules/client/front/web-access/index.js @@ -1,11 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $http, vnApp, $translate) { - this.$ = $scope; - this.$http = $http; - this.vnApp = vnApp; - this.$translate = $translate; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); this.canChangePassword = false; this.canEnableCheckBox = true; } @@ -64,7 +62,7 @@ export default class Controller { return true; } } -Controller.$inject = ['$scope', '$http', 'vnApp', '$translate']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientWebAccess', { template: require('./index.html'), diff --git a/modules/client/front/web-access/index.spec.js b/modules/client/front/web-access/index.spec.js index 319d1d1dc..0ed3345d1 100644 --- a/modules/client/front/web-access/index.spec.js +++ b/modules/client/front/web-access/index.spec.js @@ -13,7 +13,8 @@ describe('Component VnClientWebAccess', () => { $httpBackend = _$httpBackend_; vnApp = _vnApp_; jest.spyOn(vnApp, 'showError'); - controller = $componentController('vnClientWebAccess', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnClientWebAccess', {$element, $scope}); })); describe('$onChanges()', () => { diff --git a/modules/client/front/web-payment/index.html b/modules/client/front/web-payment/index.html index 110f4a2bf..ef0e568c5 100644 --- a/modules/client/front/web-payment/index.html +++ b/modules/client/front/web-payment/index.html @@ -1,7 +1,7 @@ { - this.$scope.model.refresh(); + this.$.model.refresh(); }); } @@ -26,8 +21,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$stateParams']; - ngModule.component('vnClientWebPayment', { template: require('./index.html'), controller: Controller diff --git a/modules/client/front/web-payment/index.spec.js b/modules/client/front/web-payment/index.spec.js index dc2d40b1a..ee07f2fff 100644 --- a/modules/client/front/web-payment/index.spec.js +++ b/modules/client/front/web-payment/index.spec.js @@ -15,7 +15,8 @@ describe('Component vnClientWebPayment', () => { $httpBackend = _$httpBackend_; vnApp = _vnApp_; jest.spyOn(vnApp, 'showError'); - controller = $componentController('vnClientWebPayment', {$scope: $scope}); + const $element = angular.element(''); + controller = $componentController('vnClientWebPayment', {$element, $scope}); })); describe('confirm()', () => { From 88fe9a006e92bfe33953ce4aa5d6edabb919e8e0 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 17 Mar 2020 14:43:46 +0100 Subject: [PATCH 03/44] Item refactor --- modules/client/front/balance/create/index.js | 14 ++--- .../client/front/descriptor-popover/index.js | 6 +- modules/entry/front/buy/index.js | 12 +--- modules/entry/front/index/index.js | 9 +-- modules/entry/front/log/index.html | 2 +- modules/entry/front/log/index.js | 12 +--- modules/entry/front/summary/index.js | 11 +--- modules/entry/front/summary/index.spec.js | 3 +- .../front/descriptor-popover/index.js | 6 +- modules/invoiceOut/front/descriptor/index.js | 19 +++--- modules/invoiceOut/front/index/index.js | 13 +--- modules/invoiceOut/front/summary/index.js | 11 +--- .../invoiceOut/front/summary/index.spec.js | 7 ++- modules/item/front/barcode/index.js | 19 ++---- modules/item/front/basic-data/index.js | 5 +- modules/item/front/basic-data/index.spec.js | 3 +- modules/item/front/botanical/index.js | 14 ++--- modules/item/front/botanical/index.spec.js | 14 ++--- modules/item/front/create/index.js | 10 ++-- modules/item/front/create/index.spec.js | 3 +- .../item/front/descriptor-popover/index.js | 9 +-- .../front/descriptor-popover/index.spec.js | 5 +- modules/item/front/descriptor/index.js | 16 ++--- modules/item/front/diary/index.js | 59 +++++++------------ modules/item/front/diary/index.spec.js | 29 +++++---- modules/item/front/fetched-tags/index.js | 2 + modules/item/front/index/index.js | 17 +++--- modules/item/front/index/index.spec.js | 9 +-- modules/item/front/last-entries/index.js | 14 ++--- modules/item/front/log/index.html | 2 +- modules/item/front/log/index.js | 12 +--- modules/item/front/niche/index.html | 2 +- modules/item/front/niche/index.js | 19 ++---- modules/item/front/request/index.js | 4 +- modules/item/front/request/index.spec.js | 4 +- modules/item/front/summary/index.js | 9 +-- modules/item/front/summary/index.spec.js | 7 ++- modules/item/front/tags/index.html | 2 +- modules/item/front/tags/index.js | 24 ++++---- modules/item/front/tags/index.spec.js | 3 +- modules/item/front/tax/index.js | 14 +---- modules/item/front/waste/index.js | 4 +- 42 files changed, 170 insertions(+), 289 deletions(-) diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index a480fac72..f4c103bb4 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -1,14 +1,10 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $state, $http, vnApp, $translate, vnConfig) { - this.$http = $http; - this.$ = $scope; - this.$state = $state; - this.vnApp = vnApp; - this.$translate = $translate; - +class Controller extends Section { + constructor($element, $) { + super($element, $); this.receipt = { payed: new Date(), clientFk: this.$state.params.id, @@ -86,7 +82,7 @@ class Controller { }); } } -Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientBalanceCreate', { template: require('./index.html'), diff --git a/modules/client/front/descriptor-popover/index.js b/modules/client/front/descriptor-popover/index.js index 816eaf05e..67e885ea0 100644 --- a/modules/client/front/descriptor-popover/index.js +++ b/modules/client/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { + constructor($element, $scope) { super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; this.client = null; this._quicklinks = {}; } @@ -59,7 +56,6 @@ class Controller extends Component { ); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnClientDescriptorPopover', { template: require('./index.html'), diff --git a/modules/entry/front/buy/index.js b/modules/entry/front/buy/index.js index bc8788239..674243eb1 100644 --- a/modules/entry/front/buy/index.js +++ b/modules/entry/front/buy/index.js @@ -1,17 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; - -class Controller extends Component { - constructor($element, $) { - super($element, $); - } -} - -Controller.$inject = ['$element', '$scope']; +import Section from 'salix/components/section'; ngModule.component('vnEntryBuy', { template: require('./index.html'), - controller: Controller, + controller: Section, bindings: { entry: '<' } diff --git a/modules/entry/front/index/index.js b/modules/entry/front/index/index.js index 53d2f45e0..16f3ddb1b 100644 --- a/modules/entry/front/index/index.js +++ b/modules/entry/front/index/index.js @@ -1,10 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -export default class Controller { - constructor($scope) { - this.$ = $scope; - } - +export default class Controller extends Section { onSearch(params) { if (params) this.$.model.applyFilter(null, params); @@ -23,8 +20,6 @@ export default class Controller { } } -Controller.$inject = ['$scope']; - ngModule.component('vnEntryIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/entry/front/log/index.html b/modules/entry/front/log/index.html index 4932965d1..fd8ae7c2a 100644 --- a/modules/entry/front/log/index.html +++ b/modules/entry/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/entry/front/log/index.js b/modules/entry/front/log/index.js index a5fb6c668..d045f2035 100644 --- a/modules/entry/front/log/index.js +++ b/modules/entry/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnEntryLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/entry/front/summary/index.js b/modules/entry/front/summary/index.js index 3b26907d7..94eaf1791 100644 --- a/modules/entry/front/summary/index.js +++ b/modules/entry/front/summary/index.js @@ -1,13 +1,8 @@ import ngModule from '../module'; import './style.scss'; -import Component from 'core/lib/component'; - -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - } +import Section from 'salix/components/section'; +class Controller extends Section { get entry() { return this._entry; } @@ -26,8 +21,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.component('vnEntrySummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/entry/front/summary/index.spec.js b/modules/entry/front/summary/index.spec.js index 64952cec1..a59bb8009 100644 --- a/modules/entry/front/summary/index.spec.js +++ b/modules/entry/front/summary/index.spec.js @@ -4,7 +4,6 @@ describe('component vnEntrySummary', () => { let controller; let $httpBackend; let $scope; - let $element; beforeEach(angular.mock.module('entry', $translateProvider => { $translateProvider.translations('en', {}); @@ -13,7 +12,7 @@ describe('component vnEntrySummary', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $element = angular.element(``); + const $element = angular.element(``); controller = $componentController('vnEntrySummary', {$element, $scope}); })); diff --git a/modules/invoiceOut/front/descriptor-popover/index.js b/modules/invoiceOut/front/descriptor-popover/index.js index 2e3fb15fd..c171a687d 100644 --- a/modules/invoiceOut/front/descriptor-popover/index.js +++ b/modules/invoiceOut/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { + constructor($element, $scope,) { super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; this.worker = null; this._quicklinks = {}; } @@ -69,7 +66,6 @@ class Controller extends Component { }); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnInvoiceOutDescriptorPopover', { template: require('./index.html'), diff --git a/modules/invoiceOut/front/descriptor/index.js b/modules/invoiceOut/front/descriptor/index.js index a69f6ed8b..c6d1a5810 100644 --- a/modules/invoiceOut/front/descriptor/index.js +++ b/modules/invoiceOut/front/descriptor/index.js @@ -1,14 +1,9 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($scope, vnToken, vnApp, $state, $translate, $http, aclService) { - this.$scope = $scope; - this.accessToken = vnToken.token; - this.vnApp = vnApp; - this.$state = $state; - this.$translate = $translate; - this.$http = $http; - this.aclService = aclService; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.moreOptions = [ {callback: this.showInvoiceOutPdf, name: 'Show invoice PDF'}, {callback: this.showDeleteInvoiceOutDialog, name: 'Delete Invoice', acl: 'invoicing'}, @@ -58,11 +53,11 @@ class Controller { } showDeleteInvoiceOutDialog() { - this.$scope.deleteConfirmation.show(); + this.$.deleteConfirmation.show(); } showBookInvoiceOutDialog() { - this.$scope.bookConfirmation.show(); + this.$.bookConfirmation.show(); } deleteInvoiceOut(response) { @@ -94,7 +89,7 @@ class Controller { } } -Controller.$inject = ['$scope', 'vnToken', 'vnApp', '$state', '$translate', '$http', 'aclService']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnInvoiceOutDescriptor', { template: require('./index.html'), diff --git a/modules/invoiceOut/front/index/index.js b/modules/invoiceOut/front/index/index.js index dd8219fae..7f74bc021 100644 --- a/modules/invoiceOut/front/index/index.js +++ b/modules/invoiceOut/front/index/index.js @@ -1,12 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, vnToken) { - this.accessToken = vnToken.token; - this.$ = $scope; - this.selectedInvoiceOut = null; - } - +export default class Controller extends Section { showClientDescriptor(event, clientFk) { this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; @@ -27,7 +22,7 @@ export default class Controller { } openPdf(id, event) { - let url = `api/InvoiceOuts/${id}/download?access_token=${this.accessToken}`; + let url = `api/InvoiceOuts/${id}/download?access_token=${this.vnToken.token}`; window.open(url, '_blank'); event.preventDefault(); event.stopImmediatePropagation(); @@ -41,8 +36,6 @@ export default class Controller { } } -Controller.$inject = ['$scope', 'vnToken']; - ngModule.component('vnInvoiceOutIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/invoiceOut/front/summary/index.js b/modules/invoiceOut/front/summary/index.js index 0596c616f..7b9bb9efd 100644 --- a/modules/invoiceOut/front/summary/index.js +++ b/modules/invoiceOut/front/summary/index.js @@ -1,13 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, vnToken) { - this.accessToken = vnToken.token; - this.$http = $http; - this.$ = $scope; - } - +class Controller extends Section { set invoiceOut(value) { this._invoiceOut = value; if (value && value.id) @@ -45,8 +40,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', 'vnToken']; - ngModule.component('vnInvoiceOutSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/invoiceOut/front/summary/index.spec.js b/modules/invoiceOut/front/summary/index.spec.js index f6ab4cb91..ac6c40bcf 100644 --- a/modules/invoiceOut/front/summary/index.spec.js +++ b/modules/invoiceOut/front/summary/index.spec.js @@ -4,12 +4,15 @@ describe('InvoiceOut', () => { describe('Component summary', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('invoiceOut')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnInvoiceOutSummary'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnInvoiceOutSummary', {$element, $scope}); controller.invoiceOut = {id: 1}; })); diff --git a/modules/item/front/barcode/index.js b/modules/item/front/barcode/index.js index 4096ab7eb..a2d03616c 100644 --- a/modules/item/front/barcode/index.js +++ b/modules/item/front/barcode/index.js @@ -1,22 +1,15 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; - } - +export default class Controller extends Section { onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); - }); + this.$.watcher.check(); + this.$.model.save().then(() => + this.$.watcher.notifySaved() + ); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnItemBarcode', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/basic-data/index.js b/modules/item/front/basic-data/index.js index 33a60b32d..fb80c5178 100644 --- a/modules/item/front/basic-data/index.js +++ b/modules/item/front/basic-data/index.js @@ -1,6 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -class Controller extends Component { +import Section from 'salix/components/section'; + +class Controller extends Section { showIntrastat(event) { if (event.defaultPrevented) return; event.preventDefault(); diff --git a/modules/item/front/basic-data/index.spec.js b/modules/item/front/basic-data/index.spec.js index 178fac278..fd7be5d93 100644 --- a/modules/item/front/basic-data/index.spec.js +++ b/modules/item/front/basic-data/index.spec.js @@ -5,14 +5,13 @@ describe('vnItemBasicData', () => { let $httpBackend; let $scope; let controller; - let $element; beforeEach(ngModule('item')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $element = angular.element(''); + const $element = angular.element(''); controller = $componentController('vnItemBasicData', {$element, $scope}); controller.$.watcher = {}; controller.$params.id = 1; diff --git a/modules/item/front/botanical/index.js b/modules/item/front/botanical/index.js index 51161d53a..03c62a0e3 100644 --- a/modules/item/front/botanical/index.js +++ b/modules/item/front/botanical/index.js @@ -1,17 +1,17 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($http, $state) { - this.$http = $http; - this.$state = $state; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.botanical = { - itemFk: this.$state.params.id + itemFk: this.$params.id }; } _getBotanical() { let filter = { - where: {itemFk: this.$state.params.id}, + where: {itemFk: this.$params.id}, include: [{relation: 'genus'}, {relation: 'specie'}] }; this.$http.get(`ItemBotanicals?filter=${JSON.stringify(filter)}`) @@ -26,8 +26,6 @@ class Controller { } } -Controller.$inject = ['$http', '$state']; - ngModule.component('vnItemBotanical', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/botanical/index.spec.js b/modules/item/front/botanical/index.spec.js index f4b6fa3c2..1cf79bbb3 100644 --- a/modules/item/front/botanical/index.spec.js +++ b/modules/item/front/botanical/index.spec.js @@ -3,19 +3,17 @@ import './index.js'; describe('ItemBotanical', () => { describe('Component vnItemBotanical', () => { let $httpBackend; - let $state; + let $scope; let controller; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - $state = { - params: { - id: 123 - } - }; - controller = $componentController('vnItemBotanical', {$state}); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnItemBotanical', {$element, $scope}); + controller.$params = {id: 123}; })); describe('_getBotanical()', () => { diff --git a/modules/item/front/create/index.js b/modules/item/front/create/index.js index 646baa8cd..ab51b0734 100644 --- a/modules/item/front/create/index.js +++ b/modules/item/front/create/index.js @@ -1,9 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state) { - this.$ = $scope; - this.$state = $state; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.item = { relevancy: 0 }; @@ -16,7 +16,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$state']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemCreate', { template: require('./index.html'), diff --git a/modules/item/front/create/index.spec.js b/modules/item/front/create/index.spec.js index cd5197305..5bf82bc15 100644 --- a/modules/item/front/create/index.spec.js +++ b/modules/item/front/create/index.spec.js @@ -22,7 +22,8 @@ describe('Item', () => { }; } }; - controller = $componentController('vnItemCreate', {$scope: $scope}); + const $element = angular.element(''); + controller = $componentController('vnItemCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/item/front/descriptor-popover/index.js b/modules/item/front/descriptor-popover/index.js index 42886fd58..c7a62baae 100644 --- a/modules/item/front/descriptor-popover/index.js +++ b/modules/item/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.item = null; this._quicklinks = {}; } @@ -68,7 +65,7 @@ class Controller extends Component { ); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemDescriptorPopover', { template: require('./index.html'), diff --git a/modules/item/front/descriptor-popover/index.spec.js b/modules/item/front/descriptor-popover/index.spec.js index eb09bf7d9..dfc673b0b 100644 --- a/modules/item/front/descriptor-popover/index.spec.js +++ b/modules/item/front/descriptor-popover/index.spec.js @@ -5,7 +5,6 @@ describe('Item', () => { let $httpBackend; let $scope; let controller; - let $element; let $timeout; beforeEach(ngModule('item')); @@ -13,10 +12,10 @@ describe('Item', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { $httpBackend = _$httpBackend_; $timeout = _$timeout_; - $element = angular.element(`
`); $scope = $rootScope.$new(); $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnItemDescriptorPopover', {$scope, $element}); + const $element = angular.element(''); + controller = $componentController('vnItemDescriptorPopover', {$element, $scope}); })); describe('itemFk()', () => { diff --git a/modules/item/front/descriptor/index.js b/modules/item/front/descriptor/index.js index c4e66dfe3..e04fdb595 100644 --- a/modules/item/front/descriptor/index.js +++ b/modules/item/front/descriptor/index.js @@ -1,14 +1,10 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; import './style.scss'; -class Controller { - constructor($state, $scope, $http, vnApp, $translate, vnConfig) { - this.$state = $state; - this.$scope = $scope; - this.$http = $http; - this.vnApp = vnApp; - this.$translate = $translate; - this.vnConfig = vnConfig; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.moreOptions = [ {callback: this.showRegularizeDialog, name: 'Regularize stock'} ]; @@ -64,7 +60,7 @@ class Controller { } showRegularizeDialog() { - this.$scope.regularize.show(); + this.$.regularize.show(); } set quicklinks(value = {}) { @@ -94,7 +90,7 @@ class Controller { } } -Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemDescriptor', { template: require('./index.html'), diff --git a/modules/item/front/diary/index.js b/modules/item/front/diary/index.js index 6d9f80641..f2430748d 100644 --- a/modules/item/front/diary/index.js +++ b/modules/item/front/diary/index.js @@ -1,16 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, $state, $window, $translate, $stateParams) { - this.$scope = $scope; - this.$http = $http; - this.$state = $state; - this.$stateParams = $stateParams; - this.$window = $window; - this.$translate = $translate; - } - +class Controller extends Section { get item() { return this._item; } @@ -19,17 +11,17 @@ class Controller { this._item = value; this.filter = { - where: {itemFk: this.$stateParams.id} + where: {itemFk: this.$params.id} }; - this.$scope.$applyAsync(() => { - if (this.$stateParams.warehouseFk) - this.warehouseFk = this.$stateParams.warehouseFk; + this.$.$applyAsync(() => { + if (this.$params.warehouseFk) + this.warehouseFk = this.$params.warehouseFk; else if (value) this.warehouseFk = value.itemType.warehouseFk; - if (this.$stateParams.ticketFk) - this.ticketFk = this.$stateParams.ticketFk; + if (this.$params.ticketFk) + this.ticketFk = this.$params.ticketFk; }); } @@ -42,7 +34,7 @@ class Controller { }); this.filter.where.warehouseFk = value; - this.$scope.model.refresh(); + this.$.model.refresh(); } } @@ -51,27 +43,25 @@ class Controller { } get freeLineIndex() { - let lines = this.$scope.model.data; + let lines = this.$.model.data; let minDate = new Date(); minDate.setHours(0, 0, 0, 0); let maxDate = new Date(); maxDate.setHours(23, 59, 59, 59); - for (let i = 0; i < lines.length; i++) { const dated = new Date(lines[i].date); let isForFuture = dated > maxDate; let isForToday = (dated >= minDate && dated <= maxDate); - if (isForFuture || isForToday) return i; } } get onPreparationLineIndex() { - let lines = this.$scope.model.data; + let lines = this.$.model.data; for (let i = this.freeLineIndex; i >= 0; i--) { let line = lines[i]; @@ -87,7 +77,7 @@ class Controller { } get givenTicketIndex() { - let lines = this.$scope.model.data; + let lines = this.$.model.data; for (let i = lines.length - 1; i > 0; i--) { let line = lines[i]; @@ -102,20 +92,17 @@ class Controller { let selectedTicketLineIndex = this.givenTicketIndex; let lineIndex = this.onPreparationLineIndex; - let lines = body.querySelector('vn-tbody').children; if (lineIndex == undefined || !lines.length) return; - let onPreparationLine = lines[lineIndex]; - - let balance = onPreparationLine.querySelector('.balanceSpan'); + let balance = onPreparationLine.uerySelector('.balanceSpan'); balance.classList.add('message'); - balance.title = this.$translate.instant('Visible quantity'); + balance.title = this.$translate.instant('Visble quantity'); - let headerOffset = body.querySelector('vn-topbar').getBoundingClientRect(); + let headerOffset = body.qurySelector('vn-topbar').getBoundingClientRect(); let headerHeight = headerOffset.height; let offsetTop; @@ -150,9 +137,9 @@ class Controller { showDescriptor(event, sale) { if (!sale.isTicket) return; - this.$scope.descriptor.ticketFk = sale.origin; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.ticketFk = sale.origin; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); event.preventDefault(); } @@ -160,20 +147,18 @@ class Controller { showClientDescriptor(event, sale) { if (!sale.isTicket) return; - this.$scope.clientDescriptor.clientFk = sale.clientFk; - this.$scope.clientDescriptor.parent = event.target; - this.$scope.clientDescriptor.show(); + this.$.clientDescriptor.clientFk = sale.clientFk; + this.$.clientDescriptor.parent = event.target; + this.$.clientDescriptor.show(); event.preventDefault(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$state', '$window', '$translate', '$stateParams']; - ngModule.component('vnItemDiary', { template: require('./index.html'), controller: Controller, diff --git a/modules/item/front/diary/index.spec.js b/modules/item/front/diary/index.spec.js index 9e7f0cf0c..94458a569 100644 --- a/modules/item/front/diary/index.spec.js +++ b/modules/item/front/diary/index.spec.js @@ -3,18 +3,17 @@ import crudModel from 'core/mocks/crud-model'; describe('Item', () => { describe('Component vnItemDiary', () => { - let $stateParams; let $scope; let controller; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$stateParams_) => { - $stateParams = _$stateParams_; - $stateParams.id = 1; + beforeEach(angular.mock.inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); - controller = $componentController('vnItemDiary', {$scope, $stateParams}); - controller.$scope.model = crudModel; + const $element = angular.element(''); + controller = $componentController('vnItemDiary', {$element, $scope}); + controller.$.model = crudModel; + controller.$params = {id: 1}; })); describe('isToday()', () => { @@ -40,7 +39,7 @@ describe('Item', () => { let currentDate = new Date(); currentDate.setDate(currentDate.getDate() + 1); - controller.$scope.model = {data: [ + controller.$.model = {data: [ {name: 'My item 1', alertLevel: 3, date: '2018-05-02'}, {name: 'My item 2', alertLevel: 1, date: '2018-05-03'}, {name: 'My item 3', alertLevel: 0, date: currentDate}] @@ -55,7 +54,7 @@ describe('Item', () => { it(`should call onPreparationLineIndex() and return an index from line with alertLevel 1 and isPicked true`, () => { let currentDate = new Date(); currentDate.setDate(currentDate.getDate() + 1); - controller.$scope.model = {data: [ + controller.$.model = {data: [ {name: 'My item 1', alertLevel: 3, isPicked: true, date: currentDate}, {name: 'My item 3', alertLevel: 1, isPicked: true, date: currentDate}, {name: 'My item 4', alertLevel: 1, isPicked: false, date: currentDate}, @@ -69,10 +68,10 @@ describe('Item', () => { describe('set item()', () => { it('should set warehouseFk property based on itemType warehouseFk', () => { - jest.spyOn(controller.$scope, '$applyAsync'); + jest.spyOn(controller.$, '$applyAsync'); controller.item = {id: 1, itemType: {warehouseFk: 1}}; - expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); + expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); $scope.$apply(); expect(controller.warehouseFk).toEqual(1); @@ -80,11 +79,11 @@ describe('Item', () => { }); it(`should set warehouseFk property based on url query warehouseFk`, () => { - jest.spyOn(controller.$scope, '$applyAsync'); - controller.$stateParams.warehouseFk = 4; + jest.spyOn(controller.$, '$applyAsync'); + controller.$params.warehouseFk = 4; controller.item = {id: 1, itemType: {warehouseFk: 1}}; - expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); + expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); $scope.$apply(); expect(controller.warehouseFk).toEqual(4); @@ -94,7 +93,7 @@ describe('Item', () => { describe('givenTicketIndex() setter', () => { it(`should return the index position of the line of a given ticket fk`, () => { - controller.$scope.model = {data: [ + controller.$.model = {data: [ {name: 'My item 1', origin: 1, alertLevel: 3, isPicked: true, date: '2018-05-02'}, {name: 'My item 3', origin: 2, alertLevel: 1, isPicked: true, date: '2018-05-03'}, {name: 'My item 4', origin: 3, alertLevel: 1, isPicked: false, date: '2018-05-03'}] @@ -103,7 +102,7 @@ describe('Item', () => { let index = controller.givenTicketIndex; - expect(controller.$scope.model.data[index].origin).toEqual(2); + expect(controller.$.model.data[index].origin).toEqual(2); }); }); }); diff --git a/modules/item/front/fetched-tags/index.js b/modules/item/front/fetched-tags/index.js index b88e853b4..d687339d2 100644 --- a/modules/item/front/fetched-tags/index.js +++ b/modules/item/front/fetched-tags/index.js @@ -1,8 +1,10 @@ import ngModule from '../module'; +import Component from 'core/lib/Component'; import './style.scss'; ngModule.component('vnFetchedTags', { template: require('./index.html'), + controller: Component, bindings: { maxLength: '<', item: '<', diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index 087021577..54f04f065 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -1,15 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($http, $state, $scope, aclService) { - this.aclService = aclService; - this.$http = $http; - this.$state = $state; - this.$ = $scope; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.itemSelected = null; this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; - this.showFields = { id: false, actions: false @@ -39,9 +36,8 @@ class Controller { this.$.itemDescriptor.show(); } - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; + if (event.defaltPrevented) return; event.preventDefault(); event.stopPropagation(); @@ -75,7 +71,8 @@ class Controller { this.$.preview.show(); } } -Controller.$inject = ['$http', '$state', '$scope', 'aclService']; + +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemIndex', { template: require('./index.html'), diff --git a/modules/item/front/index/index.spec.js b/modules/item/front/index/index.spec.js index aa8523b79..de07cd04d 100644 --- a/modules/item/front/index/index.spec.js +++ b/modules/item/front/index/index.spec.js @@ -2,16 +2,17 @@ import './index.js'; describe('Item', () => { describe('Component vnItemIndex', () => { - let $state; let controller; let $httpBackend; + let $scope; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { - $state = _$state_; + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnItemIndex', {$state}); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnItemIndex', {$element, $scope}); })); describe('onCloneAccept()', () => { diff --git a/modules/item/front/last-entries/index.js b/modules/item/front/last-entries/index.js index 3ef89f086..752f1b035 100644 --- a/modules/item/front/last-entries/index.js +++ b/modules/item/front/last-entries/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); let defaultDate = new Date(); defaultDate.setDate(defaultDate.getDate() - 75); @@ -12,7 +12,7 @@ class Controller { this.filter = { where: { - itemFk: $stateParams.id, + itemFk: this.$params.id, date: defaultDate } }; @@ -25,7 +25,7 @@ class Controller { if (!value) return; this.filter.where.date = value; - this.$scope.model.refresh(); + this.$.model.refresh(); } get date() { @@ -33,7 +33,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$stateParams']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnItemLastEntries', { template: require('./index.html'), diff --git a/modules/item/front/log/index.html b/modules/item/front/log/index.html index 3a6bb92ad..280a2b839 100644 --- a/modules/item/front/log/index.html +++ b/modules/item/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/item/front/log/index.js b/modules/item/front/log/index.js index 9253147c7..4433b2460 100644 --- a/modules/item/front/log/index.js +++ b/modules/item/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnItemLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/item/front/niche/index.html b/modules/item/front/niche/index.html index 70dabe671..572d81a2e 100644 --- a/modules/item/front/niche/index.html +++ b/modules/item/front/niche/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemNiches" fields="['id', 'itemFk', 'warehouseFk', 'code']" - link="{itemFk: $ctrl.$stateParams.id}" + link="{itemFk: $ctrl.$params.id}" data="niches" auto-load="true">
diff --git a/modules/item/front/niche/index.js b/modules/item/front/niche/index.js index 5d2442c58..0da3d5dd0 100644 --- a/modules/item/front/niche/index.js +++ b/modules/item/front/niche/index.js @@ -1,22 +1,15 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; - } - +export default class Controller extends Section { onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); - }); + this.$.watcher.check(); + this.$.model.save().then(() => + this.$.watcher.notifySaved() + ); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnItemNiche', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index 3684a1911..ab40779ee 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -export default class Controller extends Component { +export default class Controller extends Section { constructor($element, $) { super($element, $); diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index aaaade566..d0718139e 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -4,7 +4,6 @@ import crudModel from 'core/mocks/crud-model'; describe('Item', () => { describe('Component vnItemRequest', () => { let $scope; - let $element; let controller; let $httpBackend; @@ -15,7 +14,7 @@ describe('Item', () => { $scope = $rootScope.$new(); $scope.model = crudModel; $scope.denyReason = {hide: () => {}}; - $element = angular.element(''); + const $element = angular.element(''); controller = $componentController('vnItemRequest', {$element, $scope}); })); @@ -84,7 +83,6 @@ describe('Item', () => { let request = {saleFk: 1, saleQuantity: 1}; jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond(); $httpBackend.expect('PATCH', `Sales/${request.saleFk}/`).respond(); controller.changeQuantity(request); diff --git a/modules/item/front/summary/index.js b/modules/item/front/summary/index.js index 7e12abda0..d38f1f29a 100644 --- a/modules/item/front/summary/index.js +++ b/modules/item/front/summary/index.js @@ -1,11 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($http) { - this.$http = $http; - } - +class Controller extends Section { getSummary() { this.$http.get(`Items/${this.item.id}/getSummary`).then(response => { this.summary = response.data; @@ -18,8 +15,6 @@ class Controller { } } -Controller.$inject = ['$http']; - ngModule.component('vnItemSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/item/front/summary/index.spec.js b/modules/item/front/summary/index.spec.js index 8058ece10..069c24512 100644 --- a/modules/item/front/summary/index.spec.js +++ b/modules/item/front/summary/index.spec.js @@ -4,12 +4,15 @@ describe('Item', () => { describe('Component summary', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnItemSummary'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnItemSummary', {$element, $scope}); controller.item = {id: 1}; })); diff --git a/modules/item/front/tags/index.html b/modules/item/front/tags/index.html index 834d4c977..888efd8d0 100644 --- a/modules/item/front/tags/index.html +++ b/modules/item/front/tags/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemTags" fields="['id', 'itemFk', 'tagFk', 'value', 'priority']" - link="{itemFk: $ctrl.$stateParams.id}" + link="{itemFk: $ctrl.$params.id}" include="$ctrl.include" order="priority ASC" data="$ctrl.itemTags" diff --git a/modules/item/front/tags/index.js b/modules/item/front/tags/index.js index c12e1b9b5..eec67d5d9 100644 --- a/modules/item/front/tags/index.js +++ b/modules/item/front/tags/index.js @@ -1,9 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; +class Controller extends Section { + constructor($element, $scope) { + super($element, $scope); this.include = { relation: 'tag', scope: { @@ -47,15 +47,15 @@ class Controller { } add() { - this.$scope.model.insert({ - itemFk: this.$stateParams.id, + this.$.model.insert({ + itemFk: this.$params.id, priority: this.getHighestPriority() }); } getHighestPriority() { let max = 0; - this.$scope.model.data.forEach(tag => { + this.$.model.data.forEach(tag => { if (tag.priority > max) max = tag.priority; }); @@ -63,17 +63,15 @@ class Controller { } onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.watcher.updateOriginalData(); + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); this.card.reload(); }); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnItemTags', { template: require('./index.html'), controller: Controller, diff --git a/modules/item/front/tags/index.spec.js b/modules/item/front/tags/index.spec.js index a59f0b6e0..10128e4f0 100644 --- a/modules/item/front/tags/index.spec.js +++ b/modules/item/front/tags/index.spec.js @@ -12,7 +12,8 @@ describe('Item', () => { $scope = $rootScope.$new(); $scope.model = crudModel; $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; - controller = $componentController('vnItemTags', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnItemTags', {$element, $scope}); })); describe('itemTags setter', () => { diff --git a/modules/item/front/tax/index.js b/modules/item/front/tax/index.js index e0c2428de..251e0802d 100644 --- a/modules/item/front/tax/index.js +++ b/modules/item/front/tax/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($stateParams, $http, $translate, $scope) { - this.$ = $scope; - this.$http = $http; - this.$stateParams = $stateParams; - this._ = $translate; - } - +export default class Controller extends Section { $onInit() { this.getTaxes(); } @@ -21,7 +15,7 @@ export default class Controller { }] }; - let url = `Items/${this.$stateParams.id}/taxes`; + let url = `Items/${this.$params.id}/taxes`; this.$http.get(url, {params: {filter}}).then(json => { this.taxes = json.data; }); @@ -41,8 +35,6 @@ export default class Controller { } } -Controller.$inject = ['$stateParams', '$http', '$translate', '$scope']; - ngModule.component('vnItemTax', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/waste/index.js b/modules/item/front/waste/index.js index 9344c2222..d1a10fbf4 100644 --- a/modules/item/front/waste/index.js +++ b/modules/item/front/waste/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; ngModule.component('vnItemWaste', { template: require('./index.html'), - controller: Component + controller: Section }); From 526a92fd32421ff471a832457f5cc00a31630dd7 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 17 Mar 2020 15:18:02 +0100 Subject: [PATCH 04/44] Order refactor --- modules/item/front/fetched-tags/index.js | 2 +- modules/order/front/basic-data/index.js | 16 +++++------ modules/order/front/catalog-view/index.js | 1 - modules/order/front/catalog/index.js | 30 ++++++++------------ modules/order/front/catalog/index.spec.js | 3 +- modules/order/front/create/card.js | 21 ++++++-------- modules/order/front/create/card.spec.js | 7 +++-- modules/order/front/create/index.js | 10 ++----- modules/order/front/create/index.spec.js | 3 +- modules/order/front/descriptor/index.js | 13 +++------ modules/order/front/descriptor/index.spec.js | 9 ++++-- modules/order/front/index/index.js | 12 ++------ modules/order/front/prices-popover/index.js | 1 - modules/order/front/summary/index.js | 22 +++++--------- modules/order/front/summary/index.spec.js | 3 +- modules/order/front/volume/index.html | 4 +-- modules/order/front/volume/index.js | 26 ++++++++--------- modules/order/front/volume/index.spec.js | 19 +++++++------ 18 files changed, 85 insertions(+), 117 deletions(-) diff --git a/modules/item/front/fetched-tags/index.js b/modules/item/front/fetched-tags/index.js index d687339d2..9140abcf4 100644 --- a/modules/item/front/fetched-tags/index.js +++ b/modules/item/front/fetched-tags/index.js @@ -1,5 +1,5 @@ import ngModule from '../module'; -import Component from 'core/lib/Component'; +import Component from 'core/lib/component'; import './style.scss'; ngModule.component('vnFetchedTags', { diff --git a/modules/order/front/basic-data/index.js b/modules/order/front/basic-data/index.js index 81aef8304..d1f1fc225 100644 --- a/modules/order/front/basic-data/index.js +++ b/modules/order/front/basic-data/index.js @@ -1,18 +1,20 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope) { +class Controller extends Section { + constructor($element, $) { + super($element, $); let isDirty = false; - $scope.$watch('$ctrl.selection', newValue => { + this.$.$watch('$ctrl.selection', newValue => { if (newValue) { - $scope.addressModel.where = {clientFk: newValue.id}; - $scope.addressModel.refresh(); + this.$.addressModel.where = {clientFk: newValue.id}; + this.$.addressModel.refresh(); if (isDirty) this.order.addressFk = newValue.defaultAddressFk; isDirty = true; } else { - $scope.addressModel.clear(); + this.$.addressModel.clear(); if (isDirty) this.order.addressFk = null; } @@ -20,8 +22,6 @@ class Controller { } } -Controller.$inject = ['$scope']; - ngModule.component('vnOrderBasicData', { controller: Controller, template: require('./index.html'), diff --git a/modules/order/front/catalog-view/index.js b/modules/order/front/catalog-view/index.js index fe1f1c712..838da05ea 100644 --- a/modules/order/front/catalog-view/index.js +++ b/modules/order/front/catalog-view/index.js @@ -2,7 +2,6 @@ import ngModule from '../module'; import Component from 'core/lib/component'; import './style.scss'; - class Controller extends Component { preview(event, item) { event.preventDefault(); diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index e0ed61175..bd9a07f13 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -1,14 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($http, $scope, $state, $compile, $transitions) { - this.$http = $http; - this.$ = $scope; - this.$state = $state; - this.$stateParams = $state.params; - this.$compile = $compile; - this.$transitions = $transitions; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.itemTypes = []; this._tags = []; @@ -52,17 +48,17 @@ class Controller { if (!value) return; this.$.$applyAsync(() => { - if (this.$stateParams.itemId) - this.itemId = parseInt(this.$stateParams.itemId); + if (this.$params.itemId) + this.itemId = parseInt(this.$params.itemId); - if (this.$stateParams.categoryId) - this.categoryId = parseInt(this.$stateParams.categoryId); + if (this.$params.categoryId) + this.categoryId = parseInt(this.$params.categoryId); - if (this.$stateParams.typeId) - this.typeId = parseInt(this.$stateParams.typeId); + if (this.$params.typeId) + this.typeId = parseInt(this.$params.typeId); - if (this.$stateParams.tags) - this.tags = JSON.parse(this.$stateParams.tags); + if (this.$params.tags) + this.tags = JSON.parse(this.$params.tags); }); } @@ -350,8 +346,6 @@ class Controller { } } -Controller.$inject = ['$http', '$scope', '$state', '$compile', '$transitions']; - ngModule.component('vnOrderCatalog', { template: require('./index.html'), controller: Controller, diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index e2d2d0aff..f01712110 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -20,7 +20,8 @@ describe('Order', () => { $state.params.categoryId = 1; $state.params.typeId = 2; $state.current.name = 'my.current.state'; - controller = $componentController('vnOrderCatalog', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnOrderCatalog', {$element, $scope}); controller._order = {id: 4}; })); diff --git a/modules/order/front/create/card.js b/modules/order/front/create/card.js index 7f1bb6133..158ad9a10 100644 --- a/modules/order/front/create/card.js +++ b/modules/order/front/create/card.js @@ -1,19 +1,16 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, vnApp, $translate, $state, $stateParams) { - this.$stateParams = $stateParams; - this.$http = $http; - this.translate = $translate; - this.vnApp = vnApp; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.order = {}; - this.$state = $state; - this.clientFk = $stateParams.clientFk; + this.clientFk = this.$params.clientFk; } $onInit() { - if (this.$stateParams && this.$stateParams.clientFk) - this.clientFk = this.$stateParams.clientFk; + if (this.$params && this.$params.clientFk) + this.clientFk = this.$params.clientFk; } set order(value) { @@ -102,14 +99,12 @@ class Controller { agencyModeId: this.order.agencyModeFk }; this.$http.post(`Orders/new`, params).then(res => { - this.vnApp.showSuccess(this.translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$state.go('order.card.catalog', {id: res.data}); }); } } -Controller.$inject = ['$http', 'vnApp', '$translate', '$state', '$stateParams']; - ngModule.component('vnOrderCreateCard', { template: require('./card.html'), controller: Controller, diff --git a/modules/order/front/create/card.spec.js b/modules/order/front/create/card.spec.js index ef2bba529..f8f0653a7 100644 --- a/modules/order/front/create/card.spec.js +++ b/modules/order/front/create/card.spec.js @@ -4,12 +4,15 @@ describe('Order', () => { describe('Component vnOrderCreateCard', () => { let controller; let $httpBackend; + let $scope; beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _vnApp_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _vnApp_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnOrderCreateCard'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnOrderCreateCard', {$element, $scope}); controller.item = {id: 3}; })); diff --git a/modules/order/front/create/index.js b/modules/order/front/create/index.js index 9c8d7ce6b..5c02e8225 100644 --- a/modules/order/front/create/index.js +++ b/modules/order/front/create/index.js @@ -1,18 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - } - +class Controller extends Section { async onSubmit() { let newOrderID = await this.$.card.createOrder(); this.$state.go('order.card.summary', {id: newOrderID}); } } -Controller.$inject = ['$scope', '$http', '$state']; ngModule.component('vnOrderCreate', { template: require('./index.html'), diff --git a/modules/order/front/create/index.spec.js b/modules/order/front/create/index.spec.js index 80a8341ec..82834a987 100644 --- a/modules/order/front/create/index.spec.js +++ b/modules/order/front/create/index.spec.js @@ -10,7 +10,8 @@ describe('Order', () => { beforeEach(angular.mock.inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); $scope.card = {createOrder: () => {}}; - controller = $componentController('vnOrderCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnOrderCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/order/front/descriptor/index.js b/modules/order/front/descriptor/index.js index 0d8a1e14a..1bce67bb1 100644 --- a/modules/order/front/descriptor/index.js +++ b/modules/order/front/descriptor/index.js @@ -1,12 +1,9 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($translate, $scope, vnApp, $http, $state) { - this.$state = $state; - this.$scope = $scope; - this.vnApp = vnApp; - this.$http = $http; - this.$translate = $translate; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.moreOptions = [ {name: 'Delete order', callback: () => this.showDeleteOrderDialog()} ]; @@ -59,8 +56,6 @@ class Controller { } } -Controller.$inject = ['$translate', '$scope', 'vnApp', '$http', '$state']; - ngModule.component('vnOrderDescriptor', { template: require('./index.html'), bindings: { diff --git a/modules/order/front/descriptor/index.spec.js b/modules/order/front/descriptor/index.spec.js index 924ea4a97..5bb2ac087 100644 --- a/modules/order/front/descriptor/index.spec.js +++ b/modules/order/front/descriptor/index.spec.js @@ -2,13 +2,16 @@ import './index.js'; describe('Order Component vnOrderDescriptor', () => { let $httpBackend; + let $scope; let controller; - beforeEach(ngModule('order')); + beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnOrderDescriptor'); + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnOrderDescriptor', {$element, $scope}); controller.order = {id: 1}; })); diff --git a/modules/order/front/index/index.js b/modules/order/front/index/index.js index 8cf289796..abfb1cd30 100644 --- a/modules/order/front/index/index.js +++ b/modules/order/front/index/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state, $stateParams) { - this.$stateParams = $stateParams; - this.$state = $state; - this.$ = $scope; - this.ticketSelected = null; - } - +export default class Controller extends Section { onSearch(params) { if (params) this.$.model.applyFilter(null, params); @@ -43,8 +37,6 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$state', '$stateParams']; - ngModule.component('vnOrderIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/order/front/prices-popover/index.js b/modules/order/front/prices-popover/index.js index b732f2090..307cbc8d6 100644 --- a/modules/order/front/prices-popover/index.js +++ b/modules/order/front/prices-popover/index.js @@ -103,7 +103,6 @@ class Controller extends Component { return; } - let params = { orderFk: this.order.id, items: filledLines diff --git a/modules/order/front/summary/index.js b/modules/order/front/summary/index.js index 42b71d90e..ca6c29522 100644 --- a/modules/order/front/summary/index.js +++ b/modules/order/front/summary/index.js @@ -1,14 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http, $state) { - this.$scope = $scope; - this.$http = $http; - this.$state = $state; - this.order = {}; - } - +class Controller extends Section { setSummary() { this.$http.get(`Orders/${this.order.id}/summary`).then(res => { if (res && res.data) @@ -17,7 +11,7 @@ class Controller { } get formattedAddress() { - if (!this.summary) return; + if (!this.summary) return null; let address = this.summary.address; let province = address.province ? `(${address.province.name})` : ''; @@ -31,18 +25,16 @@ class Controller { } showDescriptor(event, itemFk) { - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$state']; - ngModule.component('vnOrderSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/order/front/summary/index.spec.js b/modules/order/front/summary/index.spec.js index f693db35d..2fa7c1c93 100644 --- a/modules/order/front/summary/index.spec.js +++ b/modules/order/front/summary/index.spec.js @@ -9,7 +9,8 @@ describe('Order', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnOrderSummary'); + const $element = angular.element(''); + controller = $componentController('vnOrderSummary', {$element}); controller.order = {id: 1}; })); diff --git a/modules/order/front/volume/index.html b/modules/order/front/volume/index.html index 9dc1b811f..36451f517 100644 --- a/modules/order/front/volume/index.html +++ b/modules/order/front/volume/index.html @@ -3,12 +3,12 @@ vn-id="model" url="OrderRows" filter="::$ctrl.filter" - link="{orderFk: $ctrl.$stateParams.id}" + link="{orderFk: $ctrl.$params.id}" limit="20" data="rows" on-data-change="$ctrl.onDataChange()">
- + { - if (response.data) - this.$scope.model.data.forEach(order => { + if (response.data) { + this.$.model.data.forEach(order => { response.data.volumes.forEach(volume => { if (order.itemFk === volume.itemFk) order.volume = volume.volume; }); }); + } }); } showDescriptor(event, itemFk) { - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$stateParams']; - ngModule.component('vnOrderVolume', { template: require('./index.html'), controller: Controller, diff --git a/modules/order/front/volume/index.spec.js b/modules/order/front/volume/index.spec.js index c5fe0f2cf..194592406 100644 --- a/modules/order/front/volume/index.spec.js +++ b/modules/order/front/volume/index.spec.js @@ -21,7 +21,8 @@ describe('Order', () => { $scope.popover = {relocate: () => {}}; $state = _$state_; $state.params.id = 1; - controller = $componentController('vnOrderVolume', {$scope}, {$httpBackend}, {$state}); + const $element = angular.element(''); + controller = $componentController('vnOrderVolume', {$element, $scope}); })); it('should join the sale volumes to its respective sale', () => { @@ -31,29 +32,29 @@ describe('Order', () => { controller.onDataChange(); $httpBackend.flush(); - expect(controller.$scope.model.data[0].volume).toBe(0.008); - expect(controller.$scope.model.data[1].volume).toBe(0.003); + expect(controller.$.model.data[0].volume).toBe(0.008); + expect(controller.$.model.data[1].volume).toBe(0.003); }); describe('showDescriptor()', () => { it('should set $scope.descriptor.itemFk, $scope.descriptor.parent and call $scope.descriptor.show()', () => { let event = {target: 1}; let itemFk = 1; - jest.spyOn(controller.$scope.descriptor, 'show'); + jest.spyOn(controller.$.descriptor, 'show'); controller.showDescriptor(event, itemFk); - expect(controller.$scope.descriptor.itemFk).toBe(1); - expect(controller.$scope.descriptor.parent).toBe(1); - expect(controller.$scope.descriptor.show).toHaveBeenCalledWith(); + expect(controller.$.descriptor.itemFk).toBe(1); + expect(controller.$.descriptor.parent).toBe(1); + expect(controller.$.descriptor.show).toHaveBeenCalledWith(); }); }); describe('onDescriptorLoad()', () => { it('should call $scope.popover.relocate()', () => { - jest.spyOn(controller.$scope.popover, 'relocate'); + jest.spyOn(controller.$.popover, 'relocate'); controller.onDescriptorLoad(); - expect(controller.$scope.popover.relocate).toHaveBeenCalledWith(); + expect(controller.$.popover.relocate).toHaveBeenCalledWith(); }); }); }); From 3cb98eaf5fba02a25bec84ed917dd9db80b1c768 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 17 Mar 2020 15:24:55 +0100 Subject: [PATCH 05/44] Route refactor --- modules/route/front/basic-data/index.js | 16 +++++----------- modules/route/front/create/index.js | 11 +++-------- modules/route/front/descriptor-popover/index.js | 8 ++------ modules/route/front/descriptor/index.js | 4 ++-- modules/route/front/index/index.js | 9 ++------- modules/route/front/log/index.js | 12 ++---------- modules/route/front/summary/index.js | 10 ++-------- modules/route/front/summary/index.spec.js | 3 ++- modules/route/front/tickets/index.js | 8 -------- 9 files changed, 20 insertions(+), 61 deletions(-) diff --git a/modules/route/front/basic-data/index.js b/modules/route/front/basic-data/index.js index d4a481dc5..cced46f55 100644 --- a/modules/route/front/basic-data/index.js +++ b/modules/route/front/basic-data/index.js @@ -1,19 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, vnApp, $translate) { - this.$ = $scope; - this.vnApp = vnApp; - this.$translate = $translate; - } - +class Controller extends Section { onSubmit() { - this.$.watcher.submit().then(() => { - this.card.reload(); - }); + this.$.watcher.submit().then(() => + this.card.reload() + ); } } -Controller.$inject = ['$scope', 'vnApp', '$translate']; ngModule.component('vnRouteBasicData', { template: require('./index.html'), diff --git a/modules/route/front/create/index.js b/modules/route/front/create/index.js index 03fe574fc..703ecb49a 100644 --- a/modules/route/front/create/index.js +++ b/modules/route/front/create/index.js @@ -1,18 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; - } - +export default class Controller extends Section { onSubmit() { - this.$scope.watcher.submit().then( + this.$.watcher.submit().then( res => this.$state.go('route.card.summary', {id: res.data.id}) ); } } -Controller.$inject = ['$scope', '$state']; ngModule.component('vnRouteCreate', { template: require('./index.html'), diff --git a/modules/route/front/descriptor-popover/index.js b/modules/route/front/descriptor-popover/index.js index 7d5cd3d91..a0363839f 100644 --- a/modules/route/front/descriptor-popover/index.js +++ b/modules/route/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.route = null; this._quicklinks = {}; } @@ -118,7 +115,6 @@ class Controller extends Component { }); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnRouteDescriptorPopover', { template: require('./index.html'), diff --git a/modules/route/front/descriptor/index.js b/modules/route/front/descriptor/index.js index e28654b99..df2cd21a1 100644 --- a/modules/route/front/descriptor/index.js +++ b/modules/route/front/descriptor/index.js @@ -2,8 +2,8 @@ import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { - constructor($element, $scope, $httpParamSerializer) { - super($element, $scope); + constructor($element, $, $httpParamSerializer) { + super($element, $); this.$httpParamSerializer = $httpParamSerializer; this.moreOptions = [ diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 8fdde810c..9c6962f8f 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -1,11 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, vnToken) { - this.$ = $scope; - this.accessToken = vnToken.token; - } - +export default class Controller extends Section { showWorkerDescriptor(event, workerFk) { if (event.defaultPrevented) return; event.preventDefault(); @@ -32,7 +28,6 @@ export default class Controller { this.$.model.clear(); } } -Controller.$inject = ['$scope', 'vnToken']; ngModule.component('vnRouteIndex', { template: require('./index.html'), diff --git a/modules/route/front/log/index.js b/modules/route/front/log/index.js index ff0a2a9d1..b7d456b23 100644 --- a/modules/route/front/log/index.js +++ b/modules/route/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnRouteLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/route/front/summary/index.js b/modules/route/front/summary/index.js index b1d42e6f1..a922ad008 100644 --- a/modules/route/front/summary/index.js +++ b/modules/route/front/summary/index.js @@ -1,12 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $http) { - this.$http = $http; - this.$ = $scope; - } - +class Controller extends Section { set route(value) { this._route = value; if (value && value.id) @@ -47,8 +43,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http']; - ngModule.component('vnRouteSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/route/front/summary/index.spec.js b/modules/route/front/summary/index.spec.js index 0dfc016b4..99c029394 100644 --- a/modules/route/front/summary/index.spec.js +++ b/modules/route/front/summary/index.spec.js @@ -9,7 +9,8 @@ describe('Route', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnRouteSummary'); + const $element = angular.element(''); + controller = $componentController('vnRouteSummary', {$element}); controller.route = {id: 1}; })); diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index f36330235..556ad0b6c 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -3,12 +3,6 @@ import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { - constructor($element, $scope, $filter) { - super($element, $scope); - - this.$filter = $filter; - } - get route() { return this._route; } @@ -200,8 +194,6 @@ class Controller extends Section { } } -Controller.$inject = ['$element', '$scope', '$filter']; - ngModule.component('vnRouteTickets', { template: require('./index.html'), controller: Controller, From f25c8bb644fb26482b7621b05399aa3b8390f811 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 18 Mar 2020 08:35:59 +0100 Subject: [PATCH 06/44] Ticket refactor --- modules/client/front/balance/create/index.js | 9 +- modules/ticket/front/basic-data/index.js | 10 +-- .../ticket/front/basic-data/step-one/index.js | 12 +-- .../front/basic-data/step-one/index.spec.js | 3 +- .../ticket/front/basic-data/step-two/index.js | 14 +-- .../front/basic-data/step-two/index.spec.js | 3 +- modules/ticket/front/component/index.html | 2 +- modules/ticket/front/component/index.js | 20 ++--- modules/ticket/front/component/index.spec.js | 3 +- modules/ticket/front/create/card.js | 20 ++--- modules/ticket/front/create/index.js | 10 +-- .../ticket/front/descriptor-popover/index.js | 6 +- .../ticket/front/descriptor/addStowaway.html | 2 +- .../ticket/front/descriptor/addStowaway.js | 13 +-- modules/ticket/front/descriptor/index.js | 3 +- modules/ticket/front/dms/create/index.js | 14 +-- modules/ticket/front/dms/create/index.spec.js | 3 +- modules/ticket/front/dms/edit/index.js | 18 +--- modules/ticket/front/dms/edit/index.spec.js | 6 +- modules/ticket/front/dms/index/index.html | 4 +- modules/ticket/front/dms/index/index.js | 14 +-- modules/ticket/front/dms/index/index.spec.js | 7 +- modules/ticket/front/expedition/index.html | 2 +- modules/ticket/front/expedition/index.js | 11 +-- modules/ticket/front/expedition/index.spec.js | 7 +- modules/ticket/front/index/index.js | 14 +-- modules/ticket/front/index/index.spec.js | 3 +- modules/ticket/front/log/index.js | 12 +-- modules/ticket/front/note/index.html | 2 +- modules/ticket/front/note/index.js | 19 ++-- modules/ticket/front/package/index.html | 2 +- modules/ticket/front/package/index.js | 21 ++--- modules/ticket/front/picture/index.html | 2 +- modules/ticket/front/picture/index.js | 19 ++-- modules/ticket/front/request/create/index.js | 16 ++-- modules/ticket/front/request/index/index.html | 2 +- modules/ticket/front/request/index/index.js | 12 ++- .../ticket/front/request/index/index.spec.js | 8 +- modules/ticket/front/sale-checked/index.html | 2 +- modules/ticket/front/sale-checked/index.js | 18 ++-- modules/ticket/front/sale-tracking/index.html | 2 +- modules/ticket/front/sale-tracking/index.js | 10 +-- modules/ticket/front/sale/editDiscount.js | 15 +--- modules/ticket/front/sale/index.html | 2 +- modules/ticket/front/sale/index.js | 86 +++++++++---------- .../front/sale/specs/editDiscount.spec.js | 3 +- modules/ticket/front/sale/specs/index.spec.js | 19 ++-- modules/ticket/front/services/index.html | 2 +- modules/ticket/front/services/index.js | 30 +++---- modules/ticket/front/sms/index.js | 15 +--- modules/ticket/front/sms/index.spec.js | 7 +- modules/ticket/front/summary/index.js | 33 +++---- modules/ticket/front/summary/index.spec.js | 3 +- modules/ticket/front/tracking/edit/index.js | 16 ++-- .../ticket/front/tracking/edit/index.spec.js | 3 +- .../ticket/front/tracking/index/index.html | 2 +- modules/ticket/front/tracking/index/index.js | 10 +-- modules/ticket/front/volume/index.html | 6 +- modules/ticket/front/volume/index.js | 20 ++--- modules/ticket/front/volume/index.spec.js | 3 +- modules/ticket/front/weekly/index.js | 15 +--- 61 files changed, 243 insertions(+), 427 deletions(-) diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index f4c103bb4..1a7d8b97b 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -7,9 +7,9 @@ class Controller extends Section { super($element, $); this.receipt = { payed: new Date(), - clientFk: this.$state.params.id, - companyFk: vnConfig.companyFk, - bankFk: vnConfig.bankFk + clientFk: this.$params.id, + companyFk: this.vnConfig.companyFk, + bankFk: this.vnConfig.bankFk }; } @@ -53,7 +53,7 @@ class Controller extends Section { getAmountPaid() { let filter = { where: { - clientFk: this.$state.params.id, + clientFk: this.$params.id, companyFk: this.receipt.companyFk } }; @@ -82,7 +82,6 @@ class Controller extends Section { }); } } -Controller.$inject = ['$element', '$scope']; ngModule.component('vnClientBalanceCreate', { template: require('./index.html'), diff --git a/modules/ticket/front/basic-data/index.js b/modules/ticket/front/basic-data/index.js index 4965ee61e..4deebff17 100644 --- a/modules/ticket/front/basic-data/index.js +++ b/modules/ticket/front/basic-data/index.js @@ -1,11 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; - } - +class Controller extends Section { set ticket(data) { if (!data) return; @@ -25,8 +21,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$state']; - ngModule.component('vnTicketBasicData', { template: require('./index.html'), bindings: { diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js index b8fffd2c1..f6655a221 100644 --- a/modules/ticket/front/basic-data/step-one/index.js +++ b/modules/ticket/front/basic-data/step-one/index.js @@ -1,14 +1,8 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; import './style.scss'; -class Controller { - constructor($scope, $http, $translate, vnApp) { - this.$scope = $scope; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Component { $onInit() { this.basicData.registerChild(this); } @@ -247,8 +241,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$translate', 'vnApp']; - ngModule.component('vnTicketBasicDataStepOne', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/basic-data/step-one/index.spec.js b/modules/ticket/front/basic-data/step-one/index.spec.js index b1931d0bb..a0673cbbe 100644 --- a/modules/ticket/front/basic-data/step-one/index.spec.js +++ b/modules/ticket/front/basic-data/step-one/index.spec.js @@ -13,7 +13,8 @@ describe('Ticket', () => { $state = _$state_; $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTicketBasicDataStepOne', {$state}); + const $element = angular.element(''); + controller = $componentController('vnTicketBasicDataStepOne', {$element}); controller.ticket = { addressFk: 121, agencyModeFk: 7, diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index f766f5726..00556350b 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -1,13 +1,7 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, $state, $translate, vnApp) { - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Component { $onInit() { this.data.registerChild(this); } @@ -92,13 +86,11 @@ class Controller { this.$translate.instant(`The ticket has been unrouted`) ); this.card.reload(); - this.$state.go('ticket.card.summary', {id: this.$state.params.id}); + this.$state.go('ticket.card.summary', {id: this.$params.id}); }); } } -Controller.$inject = ['$http', '$state', '$translate', 'vnApp']; - ngModule.component('vnTicketBasicDataStepTwo', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/basic-data/step-two/index.spec.js b/modules/ticket/front/basic-data/step-two/index.spec.js index 1ca89fd90..e67389f9d 100644 --- a/modules/ticket/front/basic-data/step-two/index.spec.js +++ b/modules/ticket/front/basic-data/step-two/index.spec.js @@ -7,7 +7,8 @@ describe('Ticket', () => { beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject($componentController => { - controller = $componentController('vnTicketBasicDataStepTwo'); + const $element = angular.element(''); + controller = $componentController('vnTicketBasicDataStepTwo', {$element}); })); describe('getTotalPrice()', () => { diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 16db43a2e..e555eb8d7 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -1,7 +1,7 @@ diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 027fdad77..d0b6ed880 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $stateParams) { - this.$stateParams = $stateParams; - this.$scope = $scope; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { order: 'concept ASC', include: [{ @@ -32,7 +32,7 @@ class Controller { } base() { - let sales = this.$scope.model.data; + let sales = this.$.model.data; let sum = 0; if (!sales) return; @@ -59,18 +59,16 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketComponents', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/component/index.spec.js b/modules/ticket/front/component/index.spec.js index 4dd361b27..3547a4905 100644 --- a/modules/ticket/front/component/index.spec.js +++ b/modules/ticket/front/component/index.spec.js @@ -75,7 +75,8 @@ describe('ticket', () => { ], quantity: 5 }]; - controller = $componentController('vnTicketComponents', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketComponents', {$element, $scope}); })); describe('base()', () => { diff --git a/modules/ticket/front/create/card.js b/modules/ticket/front/create/card.js index 54cc56c68..ef1dfb771 100644 --- a/modules/ticket/front/create/card.js +++ b/modules/ticket/front/create/card.js @@ -1,20 +1,16 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, vnApp, $translate, $state, $stateParams, vnConfig) { - this.$stateParams = $stateParams; - this.$http = $http; - this.translate = $translate; - this.vnApp = vnApp; - this.vnConfig = vnConfig; +class Controller extends Component { + constructor($element, $) { + super($element, $); this.ticket = {}; - this.$state = $state; - this.clientFk = $stateParams.clientFk; + this.clientFk = this.$params.clientFk; } $onInit() { - if (this.$stateParams && this.$stateParams.clientFk) - this.clientId = parseInt(this.$stateParams.clientFk); + if (this.$params && this.$params.clientFk) + this.clientId = parseInt(this.$params.clientFk); this.warehouseId = this.vnConfig.warehouseFk; } @@ -130,8 +126,6 @@ class Controller { } } -Controller.$inject = ['$http', 'vnApp', '$translate', '$state', '$stateParams', 'vnConfig']; - ngModule.component('vnTicketCreateCard', { template: require('./card.html'), controller: Controller, diff --git a/modules/ticket/front/create/index.js b/modules/ticket/front/create/index.js index bb9b4c76e..c93051d7a 100644 --- a/modules/ticket/front/create/index.js +++ b/modules/ticket/front/create/index.js @@ -1,18 +1,12 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - } - +class Controller extends Section { async onSubmit() { let newTicketID = await this.$.card.createTicket(); this.$state.go('ticket.card.summary', {id: newTicketID}); } } -Controller.$inject = ['$scope', '$http', '$state']; ngModule.component('vnTicketCreate', { template: require('./index.html'), diff --git a/modules/ticket/front/descriptor-popover/index.js b/modules/ticket/front/descriptor-popover/index.js index 5b94f3c14..622222e21 100644 --- a/modules/ticket/front/descriptor-popover/index.js +++ b/modules/ticket/front/descriptor-popover/index.js @@ -3,11 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { + constructor($element, $scope) { super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; this.ticket = null; this._quicklinks = {}; } @@ -106,7 +103,6 @@ class Controller extends Component { ); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnTicketDescriptorPopover', { template: require('./index.html'), diff --git a/modules/ticket/front/descriptor/addStowaway.html b/modules/ticket/front/descriptor/addStowaway.html index ec7005e79..d15d7185d 100644 --- a/modules/ticket/front/descriptor/addStowaway.html +++ b/modules/ticket/front/descriptor/addStowaway.html @@ -1,5 +1,5 @@ this.vnApp.showMessage(this.$translate.instant('Notification sent!')) ); } diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index f1b59f6c0..e745d98b8 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -1,13 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp, vnConfig) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - this.vnConfig = vnConfig; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.dms = { files: [], hasFile: false, @@ -103,8 +99,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig']; - ngModule.component('vnTicketDmsCreate', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/dms/create/index.spec.js b/modules/ticket/front/dms/create/index.spec.js index f0d7ad7c5..c6cb1da5a 100644 --- a/modules/ticket/front/dms/create/index.spec.js +++ b/modules/ticket/front/dms/create/index.spec.js @@ -13,7 +13,8 @@ describe('Ticket', () => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTicketDmsCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketDmsCreate', {$element}); controller._ticket = { id: 15, client: {id: 101, name: 'Bruce wayne'}, diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js index 9ff967816..44e3890f8 100644 --- a/modules/ticket/front/dms/edit/index.js +++ b/modules/ticket/front/dms/edit/index.js @@ -1,15 +1,7 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$stateParams = $state.params; - this.$translate = $translate; - this.vnApp = vnApp; - } - +class Controller extends Section { get ticket() { return this._ticket; } @@ -37,7 +29,7 @@ class Controller { } setDefaultParams() { - const path = `Dms/${this.$stateParams.dmsId}`; + const path = `Dms/${this.$params.dmsId}`; this.$http.get(path).then(res => { const dms = res.data && res.data; this.dms = { @@ -54,7 +46,7 @@ class Controller { } onSubmit() { - const query = `dms/${this.$stateParams.dmsId}/updateFile`; + const query = `dms/${this.$params.dmsId}/updateFile`; const options = { method: 'POST', url: query, @@ -92,8 +84,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp']; - ngModule.component('vnTicketDmsEdit', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/dms/edit/index.spec.js b/modules/ticket/front/dms/edit/index.spec.js index 757ca24ef..20224a4b9 100644 --- a/modules/ticket/front/dms/edit/index.spec.js +++ b/modules/ticket/front/dms/edit/index.spec.js @@ -5,16 +5,16 @@ describe('Ticket', () => { let controller; let $scope; let $httpBackend; - let $state; beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - $state = {params: {dmsId: 1}}; - controller = $componentController('vnTicketDmsEdit', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketDmsEdit', {$element}); controller._ticket = {id: 1, ticketFk: 16}; + controller.$params = {dmsId: 1}; })); describe('ticket() setter', () => { diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 4e4834510..090d5298a 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -54,7 +54,7 @@
+ href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> {{::document.dms.file}}
@@ -68,7 +68,7 @@ + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> diff --git a/modules/ticket/front/dms/index/index.js b/modules/ticket/front/dms/index/index.js index c6ceb6b0d..a37d15426 100644 --- a/modules/ticket/front/dms/index/index.js +++ b/modules/ticket/front/dms/index/index.js @@ -1,14 +1,10 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($stateParams, $scope, $http, $translate, vnToken, vnApp) { - this.$stateParams = $stateParams; - this.$ = $scope; - this.$http = $http; - this.$translate = $translate; - this.accessToken = vnToken.token; - this.vnApp = vnApp; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: { relation: 'dms', @@ -71,8 +67,6 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnToken', 'vnApp']; - ngModule.component('vnTicketDmsIndex', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/dms/index/index.spec.js b/modules/ticket/front/dms/index/index.spec.js index 8916a5c63..1cb231965 100644 --- a/modules/ticket/front/dms/index/index.spec.js +++ b/modules/ticket/front/dms/index/index.spec.js @@ -4,17 +4,16 @@ import crudModel from 'core/mocks/crud-model'; describe('Ticket', () => { describe('Component vnTicketDmsIndex', () => { let $componentController; - let $scope; let $httpBackend; let controller; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => { + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { $componentController = _$componentController_; $httpBackend = _$httpBackend_; - $scope = $rootScope.$new(); - controller = $componentController('vnTicketDmsIndex', {$: $scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketDmsIndex', {$element}); controller.$.model = crudModel; })); diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index b2e859970..a90d48670 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -1,7 +1,7 @@ { describe('Component vnTicketExpedition', () => { let controller; let $scope; - let $state; let $httpBackend; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_, _$httpBackend_) => { - $state = _$state_; + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $scope.model = { refresh: () => {} }; - controller = $componentController('vnTicketExpedition', {$state, $scope}); + const $element = angular.element(''); + controller = $componentController('vnTicketExpedition', {$element, $scope}); })); describe('returnDialog()', () => { diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 563265ab3..deb9a9aea 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -1,17 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; import './style.scss'; -export default class Controller { - constructor($scope, $state, $stateParams, $translate, $http) { - this.$ = $scope; - this.$http = $http; - this.$translate = $translate; - this.$stateParams = $stateParams; - this.$state = $state; - this.selectedTicket = null; - } - +export default class Controller extends Section { openBalanceDialog() { const checkedTickets = this.checked; const description = []; @@ -147,8 +139,6 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$state', '$stateParams', '$translate', '$http']; - ngModule.component('vnTicketIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 6b0b42ffd..1cb57926b 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -23,7 +23,8 @@ describe('Component vnTicketIndex', () => { beforeEach(inject(($componentController, _$window_) => { $window = _$window_; - controller = $componentController('vnTicketIndex'); + const $element = angular.element(''); + controller = $componentController('vnTicketIndex', {$element}); })); describe('compareDate()', () => { diff --git a/modules/ticket/front/log/index.js b/modules/ticket/front/log/index.js index 6a486d3d0..df2584481 100644 --- a/modules/ticket/front/log/index.js +++ b/modules/ticket/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnTicketLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/ticket/front/note/index.html b/modules/ticket/front/note/index.html index 617cf2f7d..32d93c630 100644 --- a/modules/ticket/front/note/index.html +++ b/modules/ticket/front/note/index.html @@ -2,7 +2,7 @@ vn-id="model" url="TicketObservations" fields="['id', 'ticketFk', 'observationTypeFk', 'description']" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" data="observations" auto-load="true"> diff --git a/modules/ticket/front/note/index.js b/modules/ticket/front/note/index.js index 4a74b3b98..399284abd 100644 --- a/modules/ticket/front/note/index.js +++ b/modules/ticket/front/note/index.js @@ -1,22 +1,15 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($stateParams, $scope) { - this.$stateParams = $stateParams; - this.$scope = $scope; - } - +class Controller extends Section { onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); - }); + this.$.watcher.check(); + this.$.model.save().then(() => + this.$.watcher.notifySaved() + ); } } -Controller.$inject = ['$stateParams', '$scope']; - ngModule.component('vnTicketObservation', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/package/index.html b/modules/ticket/front/package/index.html index 12ac13862..84d79fce3 100644 --- a/modules/ticket/front/package/index.html +++ b/modules/ticket/front/package/index.html @@ -2,7 +2,7 @@ vn-id="model" url="TicketPackagings" fields="['id', 'ticketFk', 'packagingFk', 'quantity', 'created']" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" data="packages" auto-load="true"> diff --git a/modules/ticket/front/package/index.js b/modules/ticket/front/package/index.js index d73c000c7..3ad64202e 100644 --- a/modules/ticket/front/package/index.js +++ b/modules/ticket/front/package/index.js @@ -1,13 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } - +class Controller extends Section { add() { - this.$scope.model.insert({ + this.$.model.insert({ packagingFk: null, quantity: null, created: new Date(), @@ -16,16 +12,13 @@ class Controller { } onSubmit() { - this.$scope.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); - }); + this.$.watcher.check(); + this.$.model.save().then(() => + this.$.watcher.notifySaved() + ); } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketPackage', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/picture/index.html b/modules/ticket/front/picture/index.html index 67ce5464e..58e13a451 100644 --- a/modules/ticket/front/picture/index.html +++ b/modules/ticket/front/picture/index.html @@ -1,7 +1,7 @@ this.$state.go('ticket.card.request.index', {id: this.$state.params.id}) + this.$.watcher.submit().then(() => + this.$state.go('ticket.card.request.index', {id: this.$params.id}) ); } } -Controller.$inject = ['$state', '$scope']; - ngModule.component('vnTicketRequestCreate', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/request/index/index.html b/modules/ticket/front/request/index/index.html index 395338116..0acb661e3 100644 --- a/modules/ticket/front/request/index/index.html +++ b/modules/ticket/front/request/index/index.html @@ -3,7 +3,7 @@ url="TicketRequests" fields="['id', 'description', 'created', 'requesterFk', 'attenderFk', 'quantity', 'price', 'saleFk', 'isOk']" order="created ASC" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" filter="::$ctrl.filter" data="purchaseRequests" auto-load="true"> diff --git a/modules/ticket/front/request/index/index.js b/modules/ticket/front/request/index/index.js index e8cb54f22..c2e6dc123 100644 --- a/modules/ticket/front/request/index/index.js +++ b/modules/ticket/front/request/index/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$stateParams = $stateParams; - this.$ = $scope; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [ { @@ -50,7 +50,7 @@ class Controller { icon: 'icon-transaction', state: `item.card.diary({ id: ${itemFk}, - ticketFk: ${this.$stateParams.id} + ticketFk: ${this.$params.id} })`, tooltip: 'Item diary' } @@ -94,8 +94,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketRequestIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/request/index/index.spec.js b/modules/ticket/front/request/index/index.spec.js index 90d71f062..17f085010 100644 --- a/modules/ticket/front/request/index/index.spec.js +++ b/modules/ticket/front/request/index/index.spec.js @@ -3,14 +3,12 @@ import './index'; describe('Ticket', () => { describe('Component vnTicketRequestIndex', () => { let controller; - let $scope; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - - controller = $componentController('vnTicketRequestIndex', {$scope}); + beforeEach(angular.mock.inject($componentController => { + const $element = angular.element(''); + controller = $componentController('vnTicketRequestIndex', {$element}); })); describe('getRequestState()', () => { diff --git a/modules/ticket/front/sale-checked/index.html b/modules/ticket/front/sale-checked/index.html index c7e060e4e..a2afd3b8f 100644 --- a/modules/ticket/front/sale-checked/index.html +++ b/modules/ticket/front/sale-checked/index.html @@ -2,7 +2,7 @@ vn-id="model" url="sales" filter="::$ctrl.filter" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" limit="20" data="sales" order="concept ASC" diff --git a/modules/ticket/front/sale-checked/index.js b/modules/ticket/front/sale-checked/index.js index 08157bc9d..1fd9b662b 100644 --- a/modules/ticket/front/sale-checked/index.js +++ b/modules/ticket/front/sale-checked/index.js @@ -1,9 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [{ relation: 'item' @@ -29,18 +29,16 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketSaleChecked', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index 0186fb935..b365ef1ca 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -1,7 +1,7 @@ { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.clearDiscount(); @@ -79,8 +72,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', 'vnApp', '$translate']; - ngModule.component('vnTicketSaleEditDiscount', { template: require('./editDiscount.html'), controller: Controller, diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index b050d3579..e120ad942 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -1,6 +1,6 @@ { + if (!this.$params.id || !this.sales) return; + this.$http.get(`Tickets/${this.$params.id}/subtotal`).then(res => { this.subtotal = res.data || 0.0; }); } @@ -88,8 +84,8 @@ class Controller { loadVAT() { this.VAT = 0.0; - if (!this.$stateParams.id || !this.sales) return; - this.$http.get(`Tickets/${this.$stateParams.id}/getVAT`).then(res => { + if (!this.$params.id || !this.sales) return; + this.$http.get(`Tickets/${this.$params.id}/getVAT`).then(res => { this.VAT = res.data || 0.0; }); } @@ -106,7 +102,7 @@ class Controller { return (shouldShow && (option.always || this.isChecked)); }); - this.$scope.moreButton.data = options; + this.$.moreButton.data = options; } onMoreChange(callback) { @@ -191,7 +187,7 @@ class Controller { }); if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); this.refreshTotal(); } @@ -211,7 +207,7 @@ class Controller { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -234,13 +230,13 @@ class Controller { } showRemoveLinesDialog() { - this.$scope.deleteLines.show(); + this.$.deleteLines.show(); } showTransferPopover(event) { this.setTransferParams(); - this.$scope.transfer.parent = event.target; - this.$scope.transfer.show(); + this.$.transfer.parent = event.target; + this.$.transfer.show(); } setTransferParams() { @@ -264,7 +260,7 @@ class Controller { sales: this.transfer.sales }; - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); const query = `tickets/${this.ticket.id}/transferSales`; this.$http.post(query, params).then(res => { @@ -281,7 +277,7 @@ class Controller { const sales = this.checkedLines(); if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); this.$http.post(`Claims/createFromSales`, {claim: claim, sales: sales}).then(res => { this.$state.go('claim.card.basicData', {id: res.data.id}); @@ -312,13 +308,13 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } showEditPricePopover(event, sale) { @@ -330,8 +326,8 @@ class Controller { id: sale.id, quantity: sale.quantity }; - this.$scope.editPricePopover.parent = event.target; - this.$scope.editPricePopover.show(); + this.$.editPricePopover.parent = event.target; + this.$.editPricePopover.show(); } updatePrice() { @@ -342,11 +338,11 @@ class Controller { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } - this.$scope.editPricePopover.hide(); + this.$.editPricePopover.hide(); } updateNewPrice() { @@ -364,23 +360,23 @@ class Controller { price: sale.price, discount: sale.discount }]; - this.$scope.editPopover.parent = event.target; - this.$scope.editPopover.show(); + this.$.editPopover.parent = event.target; + this.$.editPopover.show(); } showEditDialog() { this.edit = this.checkedLines(); - this.$scope.editDialog.show(); + this.$.editDialog.show(); } hideEditDialog() { - this.$scope.model.refresh(); - this.$scope.editDialog.hide(); + this.$.model.refresh(); + this.$.editDialog.hide(); } hideEditPopover() { - this.$scope.model.refresh(); - this.$scope.editPopover.hide(); + this.$.model.refresh(); + this.$.editPopover.hide(); } /* @@ -416,7 +412,7 @@ class Controller { }); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -449,14 +445,14 @@ class Controller { destination: phone, message: this.$translate.instant('Product not available', params) }; - this.$scope.sms.open(); + this.$.sms.open(); } /** * Inserts a new instance */ add() { - this.$scope.model.insert({}); + this.$.model.insert({}); } /* @@ -481,11 +477,11 @@ class Controller { this.$http.post(query, data).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).catch(e => { - this.$scope.model.refresh(); + this.$.model.refresh(); throw e; }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -498,11 +494,11 @@ class Controller { this.$http.post(query, data).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).catch(e => { - this.$scope.model.refresh(); + this.$.model.refresh(); throw e; }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -532,7 +528,7 @@ class Controller { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) - this.$scope.watcher.updateOriginalData(); + this.$.watcher.updateOriginalData(); }); } @@ -559,7 +555,7 @@ class Controller { const query = `Sales/${sale.id}/recalculatePrice`; this.$http.post(query).then(res => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$scope.model.refresh(); + this.$.model.refresh(); }); } @@ -570,8 +566,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; - ngModule.component('vnTicketSale', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/sale/specs/editDiscount.spec.js b/modules/ticket/front/sale/specs/editDiscount.spec.js index 8937d25c6..8eccfe74f 100644 --- a/modules/ticket/front/sale/specs/editDiscount.spec.js +++ b/modules/ticket/front/sale/specs/editDiscount.spec.js @@ -19,7 +19,8 @@ describe('Ticket', () => { }}; $state = _$state_; $state.params.id = 11; - controller = $componentController('vnTicketSaleEditDiscount', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketSaleEditDiscount', {$element, $scope}); controller._edit = [{id: 3}]; controller.onHide = () => {}; })); diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index 3b0f04a82..1c8fbda53 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -53,7 +53,8 @@ describe('Ticket', () => { writable: false } }); - controller = $componentController('vnTicketSale', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketSale', {$element, $scope}); controller.card = {reload: () => {}}; controller.ticket = ticket; controller.sales = sales; @@ -196,12 +197,12 @@ describe('Ticket', () => { describe('showSMSDialog()', () => { it('should open an SMS dialog with specified data', () => { - jest.spyOn(controller.$scope.sms, 'open'); + jest.spyOn(controller.$.sms, 'open'); controller.sales[0].checked = true; controller.showSMSDialog(); - expect(controller.$scope.sms.open).toHaveBeenCalledWith(); + expect(controller.$.sms.open).toHaveBeenCalledWith(); expect(controller.newSMS.destination).toEqual(111111111); expect(controller.newSMS.message).not.toEqual(''); }); @@ -242,7 +243,7 @@ describe('Ticket', () => { describe('updateQuantity()', () => { it('should make a POST query saving sale quantity', () => { - jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); const data = {quantity: 10}; const sale = sales[0]; sale.quantity = 10; @@ -256,13 +257,13 @@ describe('Ticket', () => { controller.updateQuantity(sale); $httpBackend.flush(); - expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith(); }); }); describe('updateConcept()', () => { it('should make a POST query saving sale concept', () => { - jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); const data = {newConcept: 'My new weapon'}; const sale = sales[0]; sale.concept = 'My new weapon'; @@ -276,13 +277,13 @@ describe('Ticket', () => { controller.updateConcept(sale); $httpBackend.flush(); - expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith(); }); }); describe('addSale()', () => { it('should make a POST query adding a new sale', () => { - jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); const newSale = {itemFk: 4, quantity: 10}; const params = {itemId: 4, quantity: 10}; @@ -307,7 +308,7 @@ describe('Ticket', () => { controller.addSale(newSale); $httpBackend.flush(); - expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith(); }); }); diff --git a/modules/ticket/front/services/index.html b/modules/ticket/front/services/index.html index 0cbcbe5df..419110eac 100644 --- a/modules/ticket/front/services/index.html +++ b/modules/ticket/front/services/index.html @@ -1,7 +1,7 @@ diff --git a/modules/ticket/front/services/index.js b/modules/ticket/front/services/index.js index fca4cd070..8627360c6 100644 --- a/modules/ticket/front/services/index.js +++ b/modules/ticket/front/services/index.js @@ -1,18 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; -class Controller { - constructor($http, $scope, $stateParams, vnApp, $translate, $element) { - this.$http = $http; - this.$scope = $scope; - this.$stateParams = $stateParams; - this.vnApp = vnApp; - this.$translate = $translate; - this.$element = $element; - this.services = []; - } - +class Controller extends Section { $onInit() { + this.services = []; this.getDefaultTaxClass(); } @@ -26,10 +18,10 @@ class Controller { add() { if (this.defaultTaxClass) { - this.$scope.model.insert({ + this.$.model.insert({ taxClassFk: this.defaultTaxClass.id, quantity: 1, - ticketFk: this.$stateParams.id + ticketFk: this.$params.id }); } } @@ -40,7 +32,7 @@ class Controller { newServiceTypeDialog(elementIndex, event) { event.preventDefault(); - this.$scope.createServiceTypeDialog.show(); + this.$.createServiceTypeDialog.show(); this.currentServiceIndex = elementIndex; } @@ -56,17 +48,15 @@ class Controller { } onSubmit() { - this.$scope.watcher.check(); + this.$.watcher.check(); - this.$scope.model.save().then(() => { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.model.refresh(); }); } } -Controller.$inject = ['$http', '$scope', '$stateParams', 'vnApp', '$translate', '$element']; - ngModule.component('vnTicketService', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/sms/index.js b/modules/ticket/front/sms/index.js index ac1131513..56959e3ee 100644 --- a/modules/ticket/front/sms/index.js +++ b/modules/ticket/front/sms/index.js @@ -3,21 +3,12 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope, $http, $translate, vnApp) { - super($element, $scope); - - this.$scope = $scope; - this.$http = $http; - this.$translate = $translate; - this.vnApp = vnApp; - } - open() { - this.$scope.SMSDialog.show(); + this.$.SMSDialog.show(); } charactersRemaining() { - const element = this.$scope.message; + const element = this.$.message; const value = element.input.value; const maxLength = 160; @@ -49,8 +40,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp']; - ngModule.component('vnTicketSms', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/sms/index.spec.js b/modules/ticket/front/sms/index.spec.js index cd397b9fa..45e7765d1 100644 --- a/modules/ticket/front/sms/index.spec.js +++ b/modules/ticket/front/sms/index.spec.js @@ -4,17 +4,16 @@ describe('Ticket', () => { describe('Component vnTicketSms', () => { let controller; let $httpBackend; - let $element; beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; let $scope = $rootScope.$new(); - $element = angular.element(''); + const $element = angular.element(''); controller = $componentController('vnTicketSms', {$element, $scope}); controller.$params = {id: 11}; - controller.$scope.message = { + controller.$.message = { input: { value: 'My SMS' } @@ -58,7 +57,7 @@ describe('Ticket', () => { describe('charactersRemaining()', () => { it('should return the characters remaining in a element', () => { - controller.$scope.message = { + controller.$.message = { input: { value: 'My message 0€' } diff --git a/modules/ticket/front/summary/index.js b/modules/ticket/front/summary/index.js index 010110340..7e892b265 100644 --- a/modules/ticket/front/summary/index.js +++ b/modules/ticket/front/summary/index.js @@ -1,15 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($scope, $state, $http, vnApp, $translate) { - this.$scope = $scope; - this.vnApp = vnApp; - this.$translate = $translate; - this.$http = $http; - this.$state = $state; - } - +class Controller extends Section { get ticket() { return this._ticket; } @@ -46,9 +39,9 @@ class Controller { tooltip: 'Route summary' } }; - this.$scope.routeDescriptor.routeFk = this.summary.routeFk; - this.$scope.routeDescriptor.parent = event.target; - this.$scope.routeDescriptor.show(); + this.$.routeDescriptor.routeFk = this.summary.routeFk; + this.$.routeDescriptor.parent = event.target; + this.$.routeDescriptor.show(); } showDescriptor(event, itemFk) { @@ -63,13 +56,13 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } get isEditable() { @@ -83,10 +76,10 @@ class Controller { setOkState() { let params = {}; - if (this.$state.params.id) - params = {ticketFk: this.$state.params.id}; + if (this.$params.id) + params = {ticketFk: this.$params.id}; - if (!this.$state.params.id) + if (!this.$params.id) params = {ticketFk: this.ticket.id}; params.code = 'OK'; @@ -112,8 +105,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; - ngModule.component('vnTicketSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/summary/index.spec.js b/modules/ticket/front/summary/index.spec.js index 08557e36e..e1f0e8836 100644 --- a/modules/ticket/front/summary/index.spec.js +++ b/modules/ticket/front/summary/index.spec.js @@ -9,7 +9,8 @@ describe('Ticket', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnTicketSummary'); + const $element = angular.element(''); + controller = $componentController('vnTicketSummary', {$element}); controller.ticket = {id: 1}; })); diff --git a/modules/ticket/front/tracking/edit/index.js b/modules/ticket/front/tracking/edit/index.js index 03c5c6c0f..f2de08389 100644 --- a/modules/ticket/front/tracking/edit/index.js +++ b/modules/ticket/front/tracking/edit/index.js @@ -1,16 +1,13 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state, vnApp, $translate, $http) { - this.$http = $http; - this.$ = $scope; - this.$state = $state; - this.vnApp = vnApp; - this.$translate = $translate; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.ticket = { - ticketFk: $state.params.id + ticketFk: this.$params.id }; - this.params = {ticketFk: $state.params.id}; + this.params = {ticketFk: this.$params.id}; } $onInit() { @@ -64,7 +61,6 @@ class Controller { }); } } -Controller.$inject = ['$scope', '$state', 'vnApp', '$translate', '$http']; ngModule.component('vnTicketTrackingEdit', { template: require('./index.html'), diff --git a/modules/ticket/front/tracking/edit/index.spec.js b/modules/ticket/front/tracking/edit/index.spec.js index 313a25b73..cf8036814 100644 --- a/modules/ticket/front/tracking/edit/index.spec.js +++ b/modules/ticket/front/tracking/edit/index.spec.js @@ -9,7 +9,8 @@ describe('Ticket', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $translate, vnApp) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnTicketTrackingEdit'); + const $element = angular.element(''); + controller = $componentController('vnTicketTrackingEdit', {$element}); controller.ticket = {id: 1}; controller.$ = {watcher: {updateOriginalData: () => {}}}; controller.card = {reload: () => {}}; diff --git a/modules/ticket/front/tracking/index/index.html b/modules/ticket/front/tracking/index/index.html index 8398a0602..f66c62449 100644 --- a/modules/ticket/front/tracking/index/index.html +++ b/modules/ticket/front/tracking/index/index.html @@ -2,7 +2,7 @@ vn-id="model" url="TicketTrackings" filter="::$ctrl.filter" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" limit="20" data="trackings" order="created DESC" diff --git a/modules/ticket/front/tracking/index/index.js b/modules/ticket/front/tracking/index/index.js index adc1ac5a2..e58dc4300 100644 --- a/modules/ticket/front/tracking/index/index.js +++ b/modules/ticket/front/tracking/index/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $stateParams) { - this.$ = $scope; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [ { @@ -37,8 +37,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$stateParams']; - ngModule.component('vnTicketTrackingIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/ticket/front/volume/index.html b/modules/ticket/front/volume/index.html index 0006b8854..977f76513 100644 --- a/modules/ticket/front/volume/index.html +++ b/modules/ticket/front/volume/index.html @@ -2,15 +2,15 @@ vn-id="model" url="sales" filter="::$ctrl.filter" - link="{ticketFk: $ctrl.$stateParams.id}" + link="{ticketFk: $ctrl.$params.id}" data="$ctrl.sales" limit="20"> - + diff --git a/modules/ticket/front/volume/index.js b/modules/ticket/front/volume/index.js index 914c9819d..bf616cb24 100644 --- a/modules/ticket/front/volume/index.js +++ b/modules/ticket/front/volume/index.js @@ -1,10 +1,9 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $stateParams) { - this.$scope = $scope; - this.$http = $http; - this.$stateParams = $stateParams; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.filter = { include: [{ relation: 'item' @@ -34,7 +33,6 @@ class Controller { if (value) this.applyVolumes(); } - applyVolumes() { if (!this.sales || !this.volumes) return; @@ -58,18 +56,16 @@ class Controller { tooltip: 'Item diary' } }; - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); } onDescriptorLoad() { - this.$scope.popover.relocate(); + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$http', '$stateParams']; - ngModule.component('vnTicketVolume', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/volume/index.spec.js b/modules/ticket/front/volume/index.spec.js index 6c2a808eb..2f6efee21 100644 --- a/modules/ticket/front/volume/index.spec.js +++ b/modules/ticket/front/volume/index.spec.js @@ -19,7 +19,8 @@ describe('ticket', () => { }}; $state = _$state_; $state.params.id = 101; - controller = $componentController('vnTicketVolume', {$scope, $httpBackend, $state}); + const $element = angular.element(''); + controller = $componentController('vnTicketVolume', {$element, $scope}); })); describe('sales() setter', () => { diff --git a/modules/ticket/front/weekly/index.js b/modules/ticket/front/weekly/index.js index 7668264f6..fd889cf65 100644 --- a/modules/ticket/front/weekly/index.js +++ b/modules/ticket/front/weekly/index.js @@ -1,14 +1,11 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, vnApp, $translate, $http) { - this.$ = $scope; - this.vnApp = vnApp; - this.$translate = $translate; - this.$http = $http; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); this.ticketSelected = null; - this.weekdays = [ {id: 0, name: 'Monday'}, {id: 1, name: 'Tuesday'}, @@ -40,7 +37,6 @@ export default class Controller { this.$.model.clear(); } - showClientDescriptor(event, clientFk) { this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; @@ -85,9 +81,6 @@ export default class Controller { } } - -Controller.$inject = ['$scope', 'vnApp', '$translate', '$http']; - ngModule.component('vnTicketWeeklyIndex', { template: require('./index.html'), controller: Controller From 934e057a6754089d69eb380c0af0a649d233750c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 18 Mar 2020 09:41:23 +0100 Subject: [PATCH 07/44] Fixed watcher changes --- modules/client/front/contact/index.js | 7 ++++--- modules/item/front/barcode/index.js | 7 ++++--- modules/item/front/niche/index.js | 7 ++++--- modules/ticket/front/note/index.js | 7 ++++--- modules/ticket/front/package/index.js | 7 ++++--- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/client/front/contact/index.js b/modules/client/front/contact/index.js index aaf64d768..4f29ddb8c 100644 --- a/modules/client/front/contact/index.js +++ b/modules/client/front/contact/index.js @@ -12,9 +12,10 @@ class Controller extends Section { onSubmit() { this.$.watcher.check(); - this.$.model.save().then(() => - this.$.watcher.notifySaved() - ); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + }); } } diff --git a/modules/item/front/barcode/index.js b/modules/item/front/barcode/index.js index a2d03616c..d9e17a42a 100644 --- a/modules/item/front/barcode/index.js +++ b/modules/item/front/barcode/index.js @@ -4,9 +4,10 @@ import Section from 'salix/components/section'; export default class Controller extends Section { onSubmit() { this.$.watcher.check(); - this.$.model.save().then(() => - this.$.watcher.notifySaved() - ); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + }); } } diff --git a/modules/item/front/niche/index.js b/modules/item/front/niche/index.js index 0da3d5dd0..f4e7cd0be 100644 --- a/modules/item/front/niche/index.js +++ b/modules/item/front/niche/index.js @@ -4,9 +4,10 @@ import Section from 'salix/components/section'; export default class Controller extends Section { onSubmit() { this.$.watcher.check(); - this.$.model.save().then(() => - this.$.watcher.notifySaved() - ); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + }); } } diff --git a/modules/ticket/front/note/index.js b/modules/ticket/front/note/index.js index 399284abd..3eda4561b 100644 --- a/modules/ticket/front/note/index.js +++ b/modules/ticket/front/note/index.js @@ -4,9 +4,10 @@ import Section from 'salix/components/section'; class Controller extends Section { onSubmit() { this.$.watcher.check(); - this.$.model.save().then(() => - this.$.watcher.notifySaved() - ); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + }); } } diff --git a/modules/ticket/front/package/index.js b/modules/ticket/front/package/index.js index 3ad64202e..60f033ac5 100644 --- a/modules/ticket/front/package/index.js +++ b/modules/ticket/front/package/index.js @@ -13,9 +13,10 @@ class Controller extends Section { onSubmit() { this.$.watcher.check(); - this.$.model.save().then(() => - this.$.watcher.notifySaved() - ); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + }); } } From a9c622377e00677d19303ee9a162975f6e2be35d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 18 Mar 2020 12:55:22 +0100 Subject: [PATCH 08/44] Refactor --- modules/route/front/log/index.html | 2 +- modules/ticket/front/log/index.html | 2 +- modules/travel/front/basic-data/index.js | 14 +++++--------- modules/travel/front/basic-data/index.spec.js | 8 ++++---- modules/travel/front/create/index.js | 11 ++--------- modules/travel/front/create/index.spec.js | 7 +++---- .../travel/front/descriptor-popover/index.js | 8 ++------ modules/travel/front/descriptor/index.js | 11 ++--------- modules/travel/front/index/index.js | 11 ++--------- modules/travel/front/index/index.spec.js | 6 +++--- modules/travel/front/log/index.html | 2 +- modules/travel/front/log/index.js | 12 ++---------- modules/travel/front/summary/index.js | 13 ++++--------- modules/travel/front/summary/index.spec.js | 3 +-- .../travel/front/thermograph/create/index.js | 14 ++++---------- .../front/thermograph/create/index.spec.js | 7 +++---- modules/travel/front/thermograph/edit/index.js | 4 ++-- .../travel/front/thermograph/edit/index.spec.js | 3 +-- modules/travel/front/thermograph/index/index.js | 10 +++------- modules/worker/front/basic-data/index.js | 8 ++------ modules/worker/front/calendar/index.js | 9 ++++----- modules/worker/front/calendar/index.spec.js | 8 +------- modules/worker/front/department/index.js | 12 ++---------- .../worker/front/descriptor-popover/index.js | 8 ++------ .../front/descriptor-popover/index.spec.js | 5 ++--- modules/worker/front/descriptor/index.js | 11 ++--------- modules/worker/front/dms/create/index.js | 7 +++---- modules/worker/front/dms/edit/index.js | 4 ++-- modules/worker/front/dms/index/index.js | 5 +---- modules/worker/front/index/index.js | 14 +++----------- modules/worker/front/log/index.js | 9 ++++----- modules/worker/front/pbx/index.js | 4 ++-- modules/worker/front/summary/index.js | 12 ++---------- modules/worker/front/time-control/index.js | 5 +++-- modules/zone/front/basic-data/index.js | 16 +++++----------- modules/zone/front/create/index.js | 14 ++++++-------- modules/zone/front/create/index.spec.js | 3 ++- modules/zone/front/descriptor/index.js | 12 ++++-------- modules/zone/front/index/index.js | 10 +++------- modules/zone/front/index/index.spec.js | 3 ++- modules/zone/front/location/index.js | 4 ++-- modules/zone/front/summary/index.js | 17 ++++------------- modules/zone/front/summary/index.spec.js | 16 +--------------- modules/zone/front/warehouses/index.js | 4 ++-- 44 files changed, 112 insertions(+), 256 deletions(-) diff --git a/modules/route/front/log/index.html b/modules/route/front/log/index.html index 6a6adf250..7df2e30ae 100644 --- a/modules/route/front/log/index.html +++ b/modules/route/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/ticket/front/log/index.html b/modules/ticket/front/log/index.html index 4fe26c871..91109d3eb 100644 --- a/modules/ticket/front/log/index.html +++ b/modules/ticket/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/basic-data/index.js b/modules/travel/front/basic-data/index.js index 7406598b0..139ef46e8 100644 --- a/modules/travel/front/basic-data/index.js +++ b/modules/travel/front/basic-data/index.js @@ -1,17 +1,13 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope) { - this.$ = $scope; - } - +class Controller extends Section { onSubmit() { - return this.$.watcher.submit().then(() => { - this.card.reload(); - }); + return this.$.watcher.submit().then(() => + this.card.reload() + ); } } -Controller.$inject = ['$scope']; ngModule.component('vnTravelBasicData', { template: require('./index.html'), diff --git a/modules/travel/front/basic-data/index.spec.js b/modules/travel/front/basic-data/index.spec.js index ed874d7e8..aaad487ef 100644 --- a/modules/travel/front/basic-data/index.spec.js +++ b/modules/travel/front/basic-data/index.spec.js @@ -2,14 +2,14 @@ import './index.js'; describe('Travel Component vnTravelBasicData', () => { let controller; - let $scope; + beforeEach(angular.mock.module('travel', $translateProvider => { $translateProvider.translations('en', {}); })); - beforeEach(angular.mock.inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - controller = $componentController('vnTravelBasicData', $scope); + beforeEach(angular.mock.inject($componentController => { + const $element = angular.element(''); + controller = $componentController('vnTravelBasicData', {$element}); controller.card = {reload: () => {}}; controller.$.watcher = {submit: () => {}}; })); diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index 0d5a2cc01..286d508de 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -2,14 +2,9 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - constructor($element, $, $stateParams) { - super($element, $); - this.$stateParams = $stateParams; - } - $onChanges() { - if (this.$stateParams && this.$stateParams.q) - this.travel = JSON.parse(this.$stateParams.q); + if (this.$params && this.$params.q) + this.travel = JSON.parse(this.$params.q); } onSubmit() { @@ -19,8 +14,6 @@ class Controller extends Section { } } -Controller.$inject = ['$element', '$scope', '$stateParams']; - ngModule.component('vnTravelCreate', { template: require('./index.html'), controller: Controller diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index a6fa5a9b1..e47f30bd3 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -2,7 +2,6 @@ import './index'; import watcher from 'core/mocks/watcher'; describe('Travel Component vnTravelCreate', () => { - let $element; let $scope; let $state; let controller; @@ -13,7 +12,7 @@ describe('Travel Component vnTravelCreate', () => { $scope = $rootScope.$new(); $state = _$state_; $scope.watcher = watcher; - $element = angular.element('
'); + const $element = angular.element(''); controller = $componentController('vnTravelCreate', {$element, $scope}); })); @@ -28,8 +27,8 @@ describe('Travel Component vnTravelCreate', () => { }); describe('$onChanges()', () => { - it('should update the travel data when stateParams.q is defined', () => { - controller.$stateParams = {q: '{"ref": 1,"agencyModeFk": 1}'}; + it('should update the travel data when $params.q is defined', () => { + controller.$params = {q: '{"ref": 1,"agencyModeFk": 1}'}; const params = {q: '{"ref": 1, "agencyModeFk": 1}'}; const json = JSON.parse(params.q); diff --git a/modules/travel/front/descriptor-popover/index.js b/modules/travel/front/descriptor-popover/index.js index cb13d7f06..cb7e29bda 100644 --- a/modules/travel/front/descriptor-popover/index.js +++ b/modules/travel/front/descriptor-popover/index.js @@ -2,11 +2,8 @@ import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.travel = null; this._quicklinks = {}; } @@ -76,7 +73,6 @@ class Controller extends Component { }); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnTravelDescriptorPopover', { template: require('./index.html'), diff --git a/modules/travel/front/descriptor/index.js b/modules/travel/front/descriptor/index.js index 187a7ed8f..911cae010 100644 --- a/modules/travel/front/descriptor/index.js +++ b/modules/travel/front/descriptor/index.js @@ -1,20 +1,13 @@ import ngModule from '../module'; - -class Controller { - constructor($scope) { - this.$ = $scope; - } -} - -Controller.$inject = ['$scope']; +import Component from 'core/lib/component'; ngModule.component('vnTravelDescriptor', { template: require('./index.html'), + controller: Component, bindings: { travel: '<' }, require: { card: '^?vnTravelCard' }, - controller: Controller }); diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index b3e24e0e6..f97d922af 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -1,12 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state) { - this.$ = $scope; - this.ticketSelected = null; - this.$state = $state; - } - +export default class Controller extends Section { getScopeDates(days) { const today = new Date(); today.setHours(0, 0, 0, 0); @@ -66,8 +61,6 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$state']; - ngModule.component('vnTravelIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index 8e180e168..ae6aa043d 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -25,10 +25,10 @@ describe('Travel Component vnTravelIndex', () => { $translateProvider.translations('en', {}); })); - beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { + beforeEach(angular.mock.inject(_$componentController_ => { $componentController = _$componentController_; - let $scope = $rootScope.$new(); - controller = $componentController('vnTravelIndex', $scope); + const $element = angular.element(''); + controller = $componentController('vnTravelIndex', {$element}); controller.$.summary = {show: jasmine.createSpy('show')}; })); diff --git a/modules/travel/front/log/index.html b/modules/travel/front/log/index.html index 8b442f671..fc4622e5a 100644 --- a/modules/travel/front/log/index.html +++ b/modules/travel/front/log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/log/index.js b/modules/travel/front/log/index.js index a9a07aaf6..742488058 100644 --- a/modules/travel/front/log/index.js +++ b/modules/travel/front/log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnTravelLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); diff --git a/modules/travel/front/summary/index.js b/modules/travel/front/summary/index.js index 8ee2da49d..af940aa6c 100644 --- a/modules/travel/front/summary/index.js +++ b/modules/travel/front/summary/index.js @@ -1,12 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -import Component from 'core/lib/component'; -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); +class Controller extends Section { + $onInit() { this.entries = []; - this.$httpParamSerializer = $httpParamSerializer; } get travel() { @@ -50,8 +48,7 @@ class Controller extends Component { } }; - const serializedParams = this.$httpParamSerializer(params); - return this.$http.get(`TravelThermographs?${serializedParams}`).then(res => { + return this.$http.get(`TravelThermographs`, {params}).then(res => { this.travelThermographs = res.data; }); } @@ -66,8 +63,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.component('vnTravelSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/travel/front/summary/index.spec.js b/modules/travel/front/summary/index.spec.js index 9b041f22b..7f5c68aec 100644 --- a/modules/travel/front/summary/index.spec.js +++ b/modules/travel/front/summary/index.spec.js @@ -4,7 +4,6 @@ describe('component vnTravelSummary', () => { let controller; let $httpBackend; let $scope; - let $element; let $httpParamSerializer; beforeEach(angular.mock.module('travel', $translateProvider => { @@ -15,7 +14,7 @@ describe('component vnTravelSummary', () => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); - $element = angular.element(``); + const $element = angular.element(``); controller = $componentController('vnTravelSummary', {$element, $scope}); })); diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index b35313fc8..6c0464991 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -1,13 +1,9 @@ import ngModule from '../../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, $state, $translate, vnApp, vnConfig) { - this.$ = $scope; - this.$http = $http; - this.$state = $state; - this.$translate = $translate; - this.vnApp = vnApp; - this.vnConfig = vnConfig; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.dms = {files: [], state: 'Ok'}; } @@ -86,8 +82,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig']; - ngModule.component('vnTravelThermographCreate', { template: require('./index.html'), controller: Controller, diff --git a/modules/travel/front/thermograph/create/index.spec.js b/modules/travel/front/thermograph/create/index.spec.js index 625f5bb20..58fbe3991 100644 --- a/modules/travel/front/thermograph/create/index.spec.js +++ b/modules/travel/front/thermograph/create/index.spec.js @@ -3,7 +3,6 @@ import './index'; describe('Ticket', () => { describe('Component vnTravelThermographCreate', () => { let controller; - let $scope; let $httpBackend; let $httpParamSerializer; const travelId = 3; @@ -11,11 +10,11 @@ describe('Ticket', () => { beforeEach(ngModule('travel')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { - $scope = $rootScope.$new(); + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTravelThermographCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnTravelThermographCreate', {$element}); controller._travel = { id: travelId }; diff --git a/modules/travel/front/thermograph/edit/index.js b/modules/travel/front/thermograph/edit/index.js index 018098312..90e0cc7b1 100644 --- a/modules/travel/front/thermograph/edit/index.js +++ b/modules/travel/front/thermograph/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { +class Controller extends Section { get travel() { return this._travel; } diff --git a/modules/travel/front/thermograph/edit/index.spec.js b/modules/travel/front/thermograph/edit/index.spec.js index eac92ba0f..180827134 100644 --- a/modules/travel/front/thermograph/edit/index.spec.js +++ b/modules/travel/front/thermograph/edit/index.spec.js @@ -5,7 +5,6 @@ describe('Worker', () => { describe('Component vnTravelThermographEdit', () => { let controller; let $scope; - let $element; let $httpBackend; let $httpParamSerializer; @@ -15,7 +14,7 @@ describe('Worker', () => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(` this.card.reload()); } } -Controller.$inject = ['$scope']; ngModule.component('vnWorkerBasicData', { template: require('./index.html'), diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 1860f6bdd..6b849d19f 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller { - constructor($element, $http) { - this.element = $element[0]; - this.$http = $http; +class Controller extends Section { + constructor($element, $) { + super($element, $); this.date = new Date(); this.events = {}; } @@ -103,7 +103,6 @@ class Controller { dayNumber.style.color = 'rgba(0, 0, 0, 0.7)'; } } -Controller.$inject = ['$element', '$http']; ngModule.component('vnWorkerCalendar', { template: require('./index.html'), diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index 2f85e3a1a..da49b8f0f 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -4,7 +4,6 @@ describe('Worker', () => { describe('Component vnWorkerCalendar', () => { let $httpBackend; let $scope; - let $element; let controller; let year = new Date().getFullYear(); @@ -13,15 +12,10 @@ describe('Worker', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; - $element = angular.element('
'); + const $element = angular.element(''); controller = $componentController('vnWorkerCalendar', {$element, $scope}); })); - afterEach(() => { - $element.remove(); - $scope.$destroy(); - }); - describe('started property', () => { it(`should return first day and month of current year`, () => { let started = new Date(year, 0, 1); diff --git a/modules/worker/front/department/index.js b/modules/worker/front/department/index.js index 28c2cfa99..35dc650f6 100644 --- a/modules/worker/front/department/index.js +++ b/modules/worker/front/department/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $http, vnApp, $translate) { - this.$ = $scope; - this.$http = $http; - this.vnApp = vnApp; - this.$translate = $translate; - } - +class Controller extends Section { $postLink() { this.$.treeview.fetch(); } @@ -87,8 +81,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http', 'vnApp', '$translate']; - ngModule.component('vnWorkerDepartment', { template: require('./index.html'), controller: Controller diff --git a/modules/worker/front/descriptor-popover/index.js b/modules/worker/front/descriptor-popover/index.js index 55843a67d..6463853f9 100644 --- a/modules/worker/front/descriptor-popover/index.js +++ b/modules/worker/front/descriptor-popover/index.js @@ -2,11 +2,8 @@ import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { - constructor($element, $scope, $http, $timeout, $q) { - super($element, $scope); - this.$timeout = $timeout; - this.$http = $http; - this.$q = $q; + constructor($element, $) { + super($element, $); this.worker = null; this._quicklinks = {}; } @@ -84,7 +81,6 @@ class Controller extends Component { }); } } -Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; ngModule.component('vnWorkerDescriptorPopover', { template: require('./index.html'), diff --git a/modules/worker/front/descriptor-popover/index.spec.js b/modules/worker/front/descriptor-popover/index.spec.js index dc524bc2d..0b2746475 100644 --- a/modules/worker/front/descriptor-popover/index.spec.js +++ b/modules/worker/front/descriptor-popover/index.spec.js @@ -5,17 +5,16 @@ describe('worker Component vnWorkerDescriptorPopover', () => { let $httpParamSerializer; let $scope; let controller; - let $element; beforeEach(ngModule('worker')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(`
`); $scope = $rootScope.$new(); $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnWorkerDescriptorPopover', {$scope, $element}); + const $element = angular.element(``); + controller = $componentController('vnWorkerDescriptorPopover', {$element, $scope}); })); describe('workerFk()', () => { diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index 6dab06958..82cfd0886 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -1,11 +1,7 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($http, $state) { - this.$state = $state; - this.$http = $http; - } - +class Controller extends Component { get worker() { return this._worker; } @@ -33,9 +29,6 @@ class Controller { } } -Controller.$inject = ['$http', '$state']; - - ngModule.component('vnWorkerDescriptor', { template: require('./index.html'), controller: Controller, diff --git a/modules/worker/front/dms/create/index.js b/modules/worker/front/dms/create/index.js index e7bfe7bfd..388b9a333 100644 --- a/modules/worker/front/dms/create/index.js +++ b/modules/worker/front/dms/create/index.js @@ -1,11 +1,10 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { - constructor($element, $, vnConfig) { +class Controller extends Section { + constructor($element, $) { super($element, $); - this.vnConfig = vnConfig; this.dms = { files: [], hasFile: false, diff --git a/modules/worker/front/dms/edit/index.js b/modules/worker/front/dms/edit/index.js index 1a593414a..ac0104fa1 100644 --- a/modules/worker/front/dms/edit/index.js +++ b/modules/worker/front/dms/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { +class Controller extends Section { get worker() { return this._worker; } diff --git a/modules/worker/front/dms/index/index.js b/modules/worker/front/dms/index/index.js index ab3be3408..d322145a0 100644 --- a/modules/worker/front/dms/index/index.js +++ b/modules/worker/front/dms/index/index.js @@ -3,9 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $, vnToken) { + constructor($element, $) { super($element, $); - this.accessToken = vnToken.token; this.filter = { include: { relation: 'dms', @@ -68,8 +67,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope', 'vnToken']; - ngModule.component('vnWorkerDmsIndex', { template: require('./index.html'), controller: Controller, diff --git a/modules/worker/front/index/index.js b/modules/worker/front/index/index.js index 1cc9a8f92..903d4beee 100644 --- a/modules/worker/front/index/index.js +++ b/modules/worker/front/index/index.js @@ -1,14 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($, $state) { - this.$state = $state; - Object.assign(this, { - $, - selectedWorker: null, - }); - } - +export default class Controller extends Section { onSearch(params) { if (params) this.$.model.applyFilter(null, params); @@ -26,7 +19,6 @@ export default class Controller { this.$.preview.show(); } - goToTimeControl(event, workerId) { if (event.defaultPrevented) return; @@ -34,11 +26,11 @@ export default class Controller { event.stopPropagation(); this.$state.go('worker.card.timeControl', {id: workerId}, {absolute: true}); } + onMoreChange(callback) { callback.call(this); } } -Controller.$inject = ['$scope', '$state']; ngModule.component('vnWorkerIndex', { template: require('./index.html'), diff --git a/modules/worker/front/log/index.js b/modules/worker/front/log/index.js index 4a577658b..5e42687d3 100644 --- a/modules/worker/front/log/index.js +++ b/modules/worker/front/log/index.js @@ -1,9 +1,10 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -export default class Controller { - constructor($scope) { - this.$ = $scope; +export default class Controller extends Section { + constructor($element, $) { + super($element, $); this.actionsText = { 'insert': 'Creates', 'update': 'Updates', @@ -70,8 +71,6 @@ export default class Controller { } } -Controller.$inject = ['$scope']; - ngModule.component('vnLog', { controller: Controller, template: require('./index.html'), diff --git a/modules/worker/front/pbx/index.js b/modules/worker/front/pbx/index.js index aa869b895..a62280d9b 100644 --- a/modules/worker/front/pbx/index.js +++ b/modules/worker/front/pbx/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -class Controller extends Component { +class Controller extends Section { onSubmit() { const sip = this.worker.sip; const params = { diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index a3fbb34f5..f6ee85a5b 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -1,13 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($, $http) { - Object.assign(this, { - $, - $http - }); - } - +class Controller extends Section { get worker() { return this._worker; } @@ -60,8 +54,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$http']; - ngModule.component('vnWorkerSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 13829e0c5..14aeb541f 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -1,7 +1,8 @@ -import Component from 'core/lib/component'; import ngModule from '../module'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends Component { + +class Controller extends Section { constructor($element, $, vnWeekDays) { super($element, $); this.weekDays = []; diff --git a/modules/zone/front/basic-data/index.js b/modules/zone/front/basic-data/index.js index a730ed362..40e5b49dc 100644 --- a/modules/zone/front/basic-data/index.js +++ b/modules/zone/front/basic-data/index.js @@ -1,20 +1,14 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; - } - +class Controller extends Section { onSubmit() { - this.$scope.watcher.submit().then(() => { - this.card.reload(); - }); + this.$.watcher.submit().then(() => + this.card.reload() + ); } } -Controller.$inject = ['$scope', '$state']; - ngModule.component('vnZoneBasicData', { template: require('./index.html'), controller: Controller, diff --git a/modules/zone/front/create/index.js b/modules/zone/front/create/index.js index 98d377d0f..c0bce4f08 100644 --- a/modules/zone/front/create/index.js +++ b/modules/zone/front/create/index.js @@ -1,9 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; +export default class Controller extends Section { + $onInit() { this.zone = { travelingDays: 0, price: 0.20, @@ -13,12 +12,11 @@ export default class Controller { } onSubmit() { - return this.$scope.watcher.submit().then(res => { - this.$state.go('zone.card.location', {id: res.data.id}); - }); + return this.$.watcher.submit().then(res => + this.$state.go('zone.card.location', {id: res.data.id}) + ); } } -Controller.$inject = ['$scope', '$state']; ngModule.component('vnZoneCreate', { template: require('./index.html'), diff --git a/modules/zone/front/create/index.spec.js b/modules/zone/front/create/index.spec.js index c2956b6cf..79fe00ed8 100644 --- a/modules/zone/front/create/index.spec.js +++ b/modules/zone/front/create/index.spec.js @@ -19,7 +19,8 @@ describe('Zone Component vnZoneCreate', () => { } }; }; - controller = $componentController('vnZoneCreate', {$scope}); + const $element = angular.element(''); + controller = $componentController('vnZoneCreate', {$element, $scope}); })); describe('onSubmit()', () => { diff --git a/modules/zone/front/descriptor/index.js b/modules/zone/front/descriptor/index.js index 736d8dd31..b3808f256 100644 --- a/modules/zone/front/descriptor/index.js +++ b/modules/zone/front/descriptor/index.js @@ -1,10 +1,8 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -class Controller { - constructor($scope, $state, $http) { - this.$scope = $scope; - this.$state = $state; - this.$http = $http; +class Controller extends Component { + $onInit() { this.moreOptions = [ {callback: this.deleteZone, name: 'Delete'} ]; @@ -15,7 +13,7 @@ class Controller { } deleteZone() { - this.$scope.deleteZone.show(); + this.$.deleteZone.show(); } returnDialog(response) { @@ -27,8 +25,6 @@ class Controller { } } -Controller.$inject = ['$scope', '$state', '$http']; - ngModule.component('vnZoneDescriptor', { template: require('./index.html'), controller: Controller, diff --git a/modules/zone/front/index/index.js b/modules/zone/front/index/index.js index 4ee44ada0..79b7b7376 100644 --- a/modules/zone/front/index/index.js +++ b/modules/zone/front/index/index.js @@ -1,10 +1,8 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($scope, $http, $state) { - this.$scope = $scope; - this.$http = $http; - this.$state = $state; +export default class Controller extends Section { + $onInit() { this.filter = { include: { relation: 'agencyMode', @@ -73,8 +71,6 @@ export default class Controller { } } -Controller.$inject = ['$scope', '$http', '$state']; - ngModule.component('vnZoneIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/zone/front/index/index.spec.js b/modules/zone/front/index/index.spec.js index 69ce934cd..d89b1f52a 100644 --- a/modules/zone/front/index/index.spec.js +++ b/modules/zone/front/index/index.spec.js @@ -8,7 +8,8 @@ describe('Zone Component vnZoneIndex', () => { beforeEach(angular.mock.inject(_$componentController_ => { $componentController = _$componentController_; - controller = $componentController('vnZoneIndex'); + const $element = angular.element(''); + controller = $componentController('vnZoneIndex', {$element}); })); describe('exprBuilder()', () => { diff --git a/modules/zone/front/location/index.js b/modules/zone/front/location/index.js index 9fcd055b3..45fddefa3 100644 --- a/modules/zone/front/location/index.js +++ b/modules/zone/front/location/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/component/section'; import './style.scss'; -class Controller extends Component { +class Controller extends Section { $postLink() { this.onSearch(); } diff --git a/modules/zone/front/summary/index.js b/modules/zone/front/summary/index.js index 636e528be..47a6ba32a 100644 --- a/modules/zone/front/summary/index.js +++ b/modules/zone/front/summary/index.js @@ -1,12 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - - this.$httpParamSerializer = $httpParamSerializer; - } +class Controller extends Section { get zone() { return this._zone; } @@ -32,8 +27,7 @@ class Controller extends Component { } } }; - const serializedParams = this.$httpParamSerializer(params); - this.$http.get(`Zones/findOne?${serializedParams}`).then(res => { + this.$http.get(`Zones/findOne`, {params}).then(res => { this.summary = res.data; }); } @@ -47,15 +41,12 @@ class Controller extends Component { } } }; - const serializedParams = this.$httpParamSerializer(params); - this.$http.get(`Zones/${this.zone.id}/warehouses?${serializedParams}`).then(res => { + this.$http.get(`Zones/${this.zone.id}/warehouses`, {params}).then(res => { this.zoneWarehouses = res.data; }); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.component('vnZoneSummary', { template: require('./index.html'), controller: Controller, diff --git a/modules/zone/front/summary/index.spec.js b/modules/zone/front/summary/index.spec.js index 9025af766..0956fa8c6 100644 --- a/modules/zone/front/summary/index.spec.js +++ b/modules/zone/front/summary/index.spec.js @@ -1,7 +1,6 @@ import './index'; describe('component vnZoneSummary', () => { - let $element; let $scope; let controller; let $httpBackend; @@ -13,7 +12,7 @@ describe('component vnZoneSummary', () => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); - $element = angular.element(``); + const $element = angular.element(``); controller = $componentController('vnZoneSummary', {$element, $scope}); })); @@ -52,17 +51,4 @@ describe('component vnZoneSummary', () => { expect(controller.summary).toBeDefined(); }); }); - - xdescribe('getEntries()', () => { - it('should call the getEntries method to get the entries data', () => { - controller._travel = {id: 999}; - - const query = `/api/Travels/${controller._travel.id}/getEntries`; - $httpBackend.expectGET(query).respond('I am the entries'); - controller.getEntries(); - $httpBackend.flush(); - - expect(controller.entries).toEqual('I am the entries'); - }); - }); }); diff --git a/modules/zone/front/warehouses/index.js b/modules/zone/front/warehouses/index.js index 328f3a1b4..9191a1f49 100644 --- a/modules/zone/front/warehouses/index.js +++ b/modules/zone/front/warehouses/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; -class Controller extends Component { +class Controller extends Section { constructor($element, $) { super($element, $); From 3d23583e0b72d60da0e868e395273ade50b7b780 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 18 Mar 2020 14:08:04 +0100 Subject: [PATCH 09/44] Fixes --- modules/claim/front/descriptor/index.js | 4 ++-- modules/client/front/address/create/index.html | 2 +- modules/client/front/descriptor-popover/index.js | 4 ++-- modules/invoiceOut/front/descriptor-popover/index.js | 4 ++-- modules/item/front/barcode/index.html | 2 +- modules/item/front/diary/index.js | 6 +++--- modules/item/front/tags/index.js | 4 ++-- modules/ticket/front/create/card.js | 2 +- modules/ticket/front/descriptor-popover/index.js | 4 ++-- modules/ticket/front/dms/index/index.html | 2 +- modules/ticket/front/package/index.js | 2 +- modules/travel/front/thermograph/index/index.html | 2 +- modules/worker/front/dms/index/index.html | 4 ++-- modules/zone/front/location/index.js | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index fd00368b8..55048c20c 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -2,8 +2,8 @@ import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { - constructor($element, $scope, $httpParamSerializer) { - super($element, $scope); + constructor($element, $, $httpParamSerializer) { + super($element, $); this.$httpParamSerializer = $httpParamSerializer; this.moreOptions = [ diff --git a/modules/client/front/address/create/index.html b/modules/client/front/address/create/index.html index 519638d48..084af36e5 100644 --- a/modules/client/front/address/create/index.html +++ b/modules/client/front/address/create/index.html @@ -11,7 +11,7 @@ vn-id="model" url="AddressObservations" fields="['id', 'addressFk', 'observationTypeFk', 'description']" - link="{addressFk: $ctrl.$stateParams.addressId}" + link="{addressFk: $ctrl.$params.addressId}" data="observations" auto-load="true">
diff --git a/modules/client/front/descriptor-popover/index.js b/modules/client/front/descriptor-popover/index.js index 67e885ea0..1a1b41f76 100644 --- a/modules/client/front/descriptor-popover/index.js +++ b/modules/client/front/descriptor-popover/index.js @@ -3,8 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope) { - super($element, $scope); + constructor($element, $) { + super($element, $); this.client = null; this._quicklinks = {}; } diff --git a/modules/invoiceOut/front/descriptor-popover/index.js b/modules/invoiceOut/front/descriptor-popover/index.js index c171a687d..c530bdd0f 100644 --- a/modules/invoiceOut/front/descriptor-popover/index.js +++ b/modules/invoiceOut/front/descriptor-popover/index.js @@ -3,8 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope,) { - super($element, $scope); + constructor($element, $,) { + super($element, $); this.worker = null; this._quicklinks = {}; } diff --git a/modules/item/front/barcode/index.html b/modules/item/front/barcode/index.html index dba745d28..ade4c2f7d 100644 --- a/modules/item/front/barcode/index.html +++ b/modules/item/front/barcode/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemBarcodes" fields="['id', 'itemFk', 'code']" - link="{itemFk: $ctrl.$stateParams.id}" + link="{itemFk: $ctrl.$params.id}" data="barcodes" auto-load="true"> diff --git a/modules/item/front/diary/index.js b/modules/item/front/diary/index.js index f2430748d..e77ad1c2c 100644 --- a/modules/item/front/diary/index.js +++ b/modules/item/front/diary/index.js @@ -98,11 +98,11 @@ class Controller extends Section { let onPreparationLine = lines[lineIndex]; - let balance = onPreparationLine.uerySelector('.balanceSpan'); + let balance = onPreparationLine.querySelector('.balanceSpan'); balance.classList.add('message'); - balance.title = this.$translate.instant('Visble quantity'); + balance.title = this.$translate.instant('Visible quantity'); - let headerOffset = body.qurySelector('vn-topbar').getBoundingClientRect(); + let headerOffset = body.querySelector('vn-topbar').getBoundingClientRect(); let headerHeight = headerOffset.height; let offsetTop; diff --git a/modules/item/front/tags/index.js b/modules/item/front/tags/index.js index eec67d5d9..8737aeed4 100644 --- a/modules/item/front/tags/index.js +++ b/modules/item/front/tags/index.js @@ -2,8 +2,8 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - constructor($element, $scope) { - super($element, $scope); + constructor($element, $) { + super($element, $); this.include = { relation: 'tag', scope: { diff --git a/modules/ticket/front/create/card.js b/modules/ticket/front/create/card.js index ef1dfb771..01c5da4c9 100644 --- a/modules/ticket/front/create/card.js +++ b/modules/ticket/front/create/card.js @@ -120,7 +120,7 @@ class Controller extends Component { warehouseId: this.ticket.warehouseFk, }; this.$http.post(`Tickets/new`, params).then(res => { - this.vnApp.showSuccess(this.translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$state.go('ticket.card.summary', {id: res.data.id}); }); } diff --git a/modules/ticket/front/descriptor-popover/index.js b/modules/ticket/front/descriptor-popover/index.js index 622222e21..822296c5b 100644 --- a/modules/ticket/front/descriptor-popover/index.js +++ b/modules/ticket/front/descriptor-popover/index.js @@ -3,8 +3,8 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - constructor($element, $scope) { - super($element, $scope); + constructor($element, $) { + super($element, $); this.ticket = null; this._quicklinks = {}; } diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 090d5298a..3b690cfd3 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -1,7 +1,7 @@ {{::thermograph.created | date: 'dd/MM/yyyy'}}
+ href="api/dms/{{::thermograph.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 697d3d5aa..011d95a95 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -41,7 +41,7 @@ {{::document.dms.file}} + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}">{{::document.dms.file}} @@ -49,7 +49,7 @@ + href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.vnToken.token}}"> diff --git a/modules/zone/front/location/index.js b/modules/zone/front/location/index.js index 45fddefa3..c30ded3ad 100644 --- a/modules/zone/front/location/index.js +++ b/modules/zone/front/location/index.js @@ -1,5 +1,5 @@ import ngModule from '../module'; -import Section from 'salix/component/section'; +import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { From 40df1018e46a63bfe26cfd2943d3fe5b5a75beda Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 18 Mar 2020 15:47:38 +0100 Subject: [PATCH 10/44] Fixes --- modules/claim/front/action/index.js | 2 -- modules/claim/front/summary/index.js | 34 ++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index d4b3541e0..a847ef009 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -200,8 +200,6 @@ export default class Controller extends Section { } } -Controller.$inject = ['$element', '$scope']; - ngModule.component('vnClaimAction', { template: require('./index.html'), controller: Controller, diff --git a/modules/claim/front/summary/index.js b/modules/claim/front/summary/index.js index 06dedfbce..094aa49fe 100644 --- a/modules/claim/front/summary/index.js +++ b/modules/claim/front/summary/index.js @@ -3,22 +3,36 @@ import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { + $onChanges() { + if (this.claim && this.claim.id) + this.getSummary(); + } + + get claim() { + return this._claim; + } + + set claim(value) { + this._claim = value; + + // Get DMS on summary load + if (value) + this.$.$applyAsync(() => this.loadDms()); + } + + loadDms() { + this.$.model.where = { + claimFk: this.claim.id + }; + this.$.model.refresh(); + } + getSummary() { this.$http.get(`Claims/${this.claim.id}/getSummary`).then(response => { this.summary = response.data; }); } - $onChanges() { - if (this.claim && this.claim.id) { - this.getSummary(); - this.$.model.where = { - claimFk: this.claim.id - }; - this.$.model.refresh(); - } - } - showItemDescriptor(event, itemFk) { this.$.itemDescriptor.itemFk = itemFk; this.$.itemDescriptor.parent = event.target; From b998ed200c80ac2e5a60124d63041298ee9f9986 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 20 Mar 2020 09:01:14 +0100 Subject: [PATCH 11/44] Fixes --- modules/invoiceOut/front/descriptor/index.js | 4 +--- modules/order/front/catalog/index.html | 2 +- modules/order/front/descriptor/index.js | 2 +- modules/zone/front/index/index.js | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/invoiceOut/front/descriptor/index.js b/modules/invoiceOut/front/descriptor/index.js index c6d1a5810..fea3c8bad 100644 --- a/modules/invoiceOut/front/descriptor/index.js +++ b/modules/invoiceOut/front/descriptor/index.js @@ -17,7 +17,7 @@ class Controller extends Component { return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); }); - this.$scope.moreButton.data = options; + this.$.moreButton.data = options; } onMoreChange(callback) { @@ -89,8 +89,6 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope']; - ngModule.component('vnInvoiceOutDescriptor', { template: require('./index.html'), bindings: { diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 7131d6a6e..4c8786e13 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -7,7 +7,7 @@ diff --git a/modules/order/front/descriptor/index.js b/modules/order/front/descriptor/index.js index 1bce67bb1..b9d1e7973 100644 --- a/modules/order/front/descriptor/index.js +++ b/modules/order/front/descriptor/index.js @@ -52,7 +52,7 @@ class Controller extends Component { } showDeleteOrderDialog() { - this.$scope.deleteOrderConfirmation.show(); + this.$.deleteOrderConfirmation.show(); } } diff --git a/modules/zone/front/index/index.js b/modules/zone/front/index/index.js index 79b7b7376..513aa20fa 100644 --- a/modules/zone/front/index/index.js +++ b/modules/zone/front/index/index.js @@ -32,7 +32,7 @@ export default class Controller extends Section { clone(event, zone) { this.stopEvent(event); this.selectedZone = zone; - this.$scope.clone.show(); + this.$.clone.show(); } /** @@ -58,7 +58,7 @@ export default class Controller extends Section { preview(event, zone) { this.stopEvent(event); this.selectedZone = zone; - this.$scope.summary.show(); + this.$.summary.show(); } /** From 569f67ffbaf83d0dc8a9b4642246f0f249647576 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Fri, 20 Mar 2020 12:05:45 +0100 Subject: [PATCH 12/44] path unstable --- e2e/helpers/selectors.js | 7 ++ e2e/paths/05-ticket/18_index_payout.spec.js | 115 ++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 e2e/paths/05-ticket/18_index_payout.spec.js diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 0cee79405..0e8ffbfb8 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -368,6 +368,13 @@ export default { advancedSearchInvoiceOut: 'vn-ticket-search-panel vn-textfield[ng-model="filter.refFk"]', newTicketButton: 'vn-ticket-index a', searchResult: 'vn-ticket-index vn-card > vn-table > div > vn-tbody > a.vn-tr', + secondTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(2) > vn-td:nth-child(1) > vn-check', + thirdTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(3) > vn-td:nth-child(1) > vn-check', + sixthTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(6) > vn-td:nth-child(1) > vn-check', + payoutButton: 'vn-ticket-index vn-button[icon="icon-recovery"]', + payoutCompany: '.vn-dialog vn-autocomplete[ng-model="$ctrl.receipt.companyFk"]', + payoutBank: '.vn-dialog vn-autocomplete[ng-model="$ctrl.receipt.bankFk"]', + submitPayout: '.vn-dialog vn-button[label="Save"]', searchWeeklyResult: 'vn-ticket-weekly-index vn-table vn-tbody > vn-tr', searchResultDate: 'vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(5)', topbarSearch: 'vn-searchbar', diff --git a/e2e/paths/05-ticket/18_index_payout.spec.js b/e2e/paths/05-ticket/18_index_payout.spec.js new file mode 100644 index 000000000..46619b5ae --- /dev/null +++ b/e2e/paths/05-ticket/18_index_payout.spec.js @@ -0,0 +1,115 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +xdescribe('Ticket index payout path', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should navigate to the ticket index', async() => { + await page.loginAndModule('administrative', 'ticket'); + let url = await page.expectURL('#!/ticket/index'); + + expect(url).toBe(true); + }); + + it('should check three tickets 2 of a clinet and 1 of another', async() => { + await page.keyboard.press('Enter'); + await page.waitToClick(selectors.ticketsIndex.secondTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.sixthTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.payoutButton); + const result = await page.waitForLastSnackbar(); + + expect(result).toEqual('You cannot make a payment on account from multiple clients'); + }); + + it('should uncheck the sixth ticket result and check the third which is from the same client then open the payout form', async() => { + await page.waitToClick(selectors.ticketsIndex.sixthTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.thirdTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.payoutButton); + + await page.waitForSelector(selectors.ticketsIndex.payoutCompany); + }); + + it('should fill the company and bank to perform a payout', async() => { + await page.autocompleteSearch(selectors.ticketsIndex.payoutBank, 'cash'); + await page.waitToClick(selectors.ticketsIndex.submitPayout); + const result = await page.waitForLastSnackbar(); + + expect(result).toEqual('Data saved!'); + }); + + it('should navigate to the client balance section', async() => { + await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should B', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should C', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should D', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should E', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should F', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + expect(result).toEqual(4); + }); +}); From 6d4e83fa990e9944b22e5fd1abe80b92db5d3409 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 20 Mar 2020 12:42:06 +0100 Subject: [PATCH 13/44] E2E fixes --- e2e/helpers/selectors.js | 2 +- e2e/paths/04-item/09_regularize.spec.js | 1 - e2e/paths/09-invoice-out/02_descriptor.spec.js | 14 ++------------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 0cee79405..2ac6f4223 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -208,7 +208,7 @@ export default { createItemButton: `vn-float-button`, firstSearchResult: 'vn-item-index a:nth-child(1)', searchResult: 'vn-item-index a.vn-tr', - searchResultPreviewButton: 'vn-item-index .buttons > [icon="desktop_windows"]', + searchResultPreviewButton: 'vn-item-index vn-tbody > :nth-child(1) .buttons > [icon="desktop_windows"]', searchResultCloneButton: 'vn-item-index .buttons > [icon="icon-clone"]', acceptClonationAlertButton: '.vn-confirm.shown [response="accept"]', topbarSearch: 'vn-topbar', diff --git a/e2e/paths/04-item/09_regularize.spec.js b/e2e/paths/04-item/09_regularize.spec.js index 838b24cf0..18f182e74 100644 --- a/e2e/paths/04-item/09_regularize.spec.js +++ b/e2e/paths/04-item/09_regularize.spec.js @@ -78,7 +78,6 @@ describe('Item regularize path', () => { }); it('should search for the ticket with alias missing', async() => { - await page.accessToSearchResult('Carol Danvers'); await page.keyboard.press('Escape'); await page.accessToSearchResult('missing'); let url = await page.expectURL('/summary'); diff --git a/e2e/paths/09-invoice-out/02_descriptor.spec.js b/e2e/paths/09-invoice-out/02_descriptor.spec.js index e70c39ded..1290b9a88 100644 --- a/e2e/paths/09-invoice-out/02_descriptor.spec.js +++ b/e2e/paths/09-invoice-out/02_descriptor.spec.js @@ -20,10 +20,9 @@ describe('InvoiceOut descriptor path', () => { await page.waitToClick(selectors.ticketsIndex.openAdvancedSearchButton); await page.write(selectors.ticketsIndex.advancedSearchInvoiceOut, 'T2222222'); await page.waitToClick(selectors.ticketsIndex.advancedSearchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); + let url = await page.expectURL('#!/ticket/3/summary'); - expect(result).toEqual(1); + expect(url).toEqual(true); }); it('should navigate to the invoiceOut index', async() => { @@ -36,15 +35,6 @@ describe('InvoiceOut descriptor path', () => { expect(url).toBe(true); }); - it('should search for the target invoiceOut', async() => { - await page.write(selectors.invoiceOutIndex.topbarSearch, 'T2222222'); - await page.waitToClick(selectors.invoiceOutIndex.searchButton); - await page.waitForNumberOfElements(selectors.invoiceOutIndex.searchResult, 1); - const result = await page.countElement(selectors.invoiceOutIndex.searchResult); - - expect(result).toEqual(1); - }); - it(`should click on the search result to access to the invoiceOut summary`, async() => { await page.accessToSearchResult('T2222222'); let url = await page.expectURL('/summary'); From 0a7ce19fb99828423092bbf925bd3a1341666460 Mon Sep 17 00:00:00 2001 From: Bernat Date: Fri, 20 Mar 2020 16:18:38 +0100 Subject: [PATCH 14/44] small fix --- e2e/helpers/selectors.js | 2 +- e2e/paths/04-item/01_summary.spec.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 2ac6f4223..89857f770 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -208,7 +208,7 @@ export default { createItemButton: `vn-float-button`, firstSearchResult: 'vn-item-index a:nth-child(1)', searchResult: 'vn-item-index a.vn-tr', - searchResultPreviewButton: 'vn-item-index vn-tbody > :nth-child(1) .buttons > [icon="desktop_windows"]', + firstResultPreviewButton: 'vn-item-index vn-tbody > :nth-child(1) .buttons > [icon="desktop_windows"]', searchResultCloneButton: 'vn-item-index .buttons > [icon="icon-clone"]', acceptClonationAlertButton: '.vn-confirm.shown [response="accept"]', topbarSearch: 'vn-topbar', diff --git a/e2e/paths/04-item/01_summary.spec.js b/e2e/paths/04-item/01_summary.spec.js index 01e730668..6fd4e9c13 100644 --- a/e2e/paths/04-item/01_summary.spec.js +++ b/e2e/paths/04-item/01_summary.spec.js @@ -19,8 +19,8 @@ describe('Item summary path', () => { await page.write(selectors.itemsIndex.topbarSearch, 'Ranged weapon'); await page.waitToClick(selectors.itemsIndex.searchButton); await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 3); - await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon longbow 2m'); - await page.waitToClick(selectors.itemsIndex.searchResultPreviewButton); + await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon'); + await page.waitToClick(selectors.itemsIndex.firstResultPreviewButton); const isVisible = await page.isVisible(selectors.itemSummary.basicData); expect(isVisible).toBeTruthy(); @@ -68,11 +68,10 @@ describe('Item summary path', () => { it('should search for other item', async() => { await page.clearInput('vn-searchbar'); - await page.waitToClick(selectors.itemsIndex.searchButton); await page.write(selectors.itemsIndex.topbarSearch, 'Melee Reinforced'); - await page.waitToClick(selectors.itemsIndex.searchButton); + await page.keyboard.press('Enter'); await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2); - await page.waitToClick(selectors.itemsIndex.searchResultPreviewButton); + await page.waitToClick(selectors.itemsIndex.firstResultPreviewButton); await page.waitForSelector(selectors.itemSummary.basicData, {visible: true}); }); From 6dcee3516d357f80bfa82230e9e6faa3def46bd6 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 23 Mar 2020 10:40:09 +0100 Subject: [PATCH 15/44] ticket e2e fixes --- e2e/helpers/selectors.js | 2 +- e2e/paths/05-ticket/09_weekly.spec.js | 11 +---------- e2e/paths/05-ticket/12_descriptor.spec.js | 3 +-- front/core/components/searchbar/searchbar.js | 2 ++ 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 89857f770..88f7cb40d 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -369,7 +369,7 @@ export default { newTicketButton: 'vn-ticket-index a', searchResult: 'vn-ticket-index vn-card > vn-table > div > vn-tbody > a.vn-tr', searchWeeklyResult: 'vn-ticket-weekly-index vn-table vn-tbody > vn-tr', - searchResultDate: 'vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(5)', + searchResultDate: 'vn-ticket-summary [label=Landed] span', topbarSearch: 'vn-searchbar', advancedSearchButton: 'vn-ticket-search-panel button[type=submit]', searchButton: 'vn-searchbar vn-icon[icon="search"]', diff --git a/e2e/paths/05-ticket/09_weekly.spec.js b/e2e/paths/05-ticket/09_weekly.spec.js index 3e791dc18..9213afd1d 100644 --- a/e2e/paths/05-ticket/09_weekly.spec.js +++ b/e2e/paths/05-ticket/09_weekly.spec.js @@ -63,16 +63,7 @@ describe('Ticket descriptor path', () => { }); it('should now search for the ticket 11', async() => { - await page.write(selectors.ticketsIndex.topbarSearch, '11'); - await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should click on the search result to access to the ticket`, async() => { - await page.waitToClick(selectors.ticketsIndex.searchResult); + await page.accessToSearchResult('11'); let url = await page.expectURL('/summary'); expect(url).toBe(true); diff --git a/e2e/paths/05-ticket/12_descriptor.spec.js b/e2e/paths/05-ticket/12_descriptor.spec.js index 59691d380..0e3712c82 100644 --- a/e2e/paths/05-ticket/12_descriptor.spec.js +++ b/e2e/paths/05-ticket/12_descriptor.spec.js @@ -58,8 +58,7 @@ describe('Ticket descriptor path', () => { it(`should search for the deleted ticket and check it's date`, async() => { await page.write(selectors.ticketsIndex.topbarSearch, '18'); await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - await page.wait(selectors.ticketsIndex.searchResultDate); + await page.expectURL('/summary'); const result = await page.waitToGetProperty(selectors.ticketsIndex.searchResultDate, 'innerText'); expect(result).toContain(2000); diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index 640ed48d6..21e72f60d 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -239,6 +239,8 @@ export default class Searchbar extends Component { this.filter = filter; + if (!filter && this.model) + this.model.clear(); if (source != 'state') this.transition = this.$state.go(state, params, opts).transition; if (source != 'bar') From 27b13767993b5a71d47eac314c04b6eef4e78cb5 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 23 Mar 2020 11:21:25 +0100 Subject: [PATCH 16/44] changes --- db/dump/fixtures.sql | 22 +++++++++ modules/item/back/model-config.json | 3 ++ .../item/back/models/item-shelving-sale.json | 5 ++ modules/item/back/models/item-shelving.json | 40 +++++++++++++++ .../ticket/back/methods/ticket/setDeleted.js | 21 ++++++-- .../methods/ticket/specs/setDeleted.spec.js | 49 +++++++++++++++++-- modules/ticket/back/models/sale.json | 2 +- 7 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 modules/item/back/models/item-shelving.json diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7b2fd1cae..227291a68 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -101,6 +101,16 @@ INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPrepare (1, 'First sector', 1, 1, 'FIRST', 999, 999), (2, 'Second sector', 2, 0, 'SECOND', 100, 150); +INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingOrder`) + VALUES + ('1', '700', '01', '1', '700-01', '70001'), + ('2', '700', '02', '2', '700-02', '70002'); + +INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `parked`, `userFk`) + VALUES + ('GVC', '1', '0', '1', '0', '106'), + ('HEJ', '2', '0', '1', '0', '106'); + INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) VALUES (1, 'Main Warehouse'); @@ -928,6 +938,18 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) (32, 36, -92.324), (32, 39, 0.994); +INSERT INTO `vn`.`itemShelving` (`id`, `itemFk`, `shelvingFk`, `shelve`, `deep`, `quantity`, `visible`, `available`, `grouping`, `packing`, `level`, `userFk`) + VALUES + ('1', '2', 'GVC', 'A', '0', '1', '1', '1', '1', '1', '1', '106'), + ('2', '4', 'HEJ', 'A', '0', '2', '1', '1', '1', '1', '1', '106'); + +INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`) + VALUES + ('1', '1', '1', '', '106'), + ('2', '2', '5', '', '106'), + ('1', '7', '1', '', '106'), + ('2', '8', '5', '', '106'); + INSERT INTO `vncontrol`.`accion`(`accion_id`, `accion`) VALUES (3, 'ACTION ONE'), diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index d8ec5914a..c085e075a 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -44,6 +44,9 @@ "ItemTypeTag": { "dataSource": "vn" }, + "ItemShelving": { + "dataSource": "vn" + }, "ItemShelvingSale": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-shelving-sale.json b/modules/item/back/models/item-shelving-sale.json index 547c882a0..04f505ddd 100644 --- a/modules/item/back/models/item-shelving-sale.json +++ b/modules/item/back/models/item-shelving-sale.json @@ -25,6 +25,11 @@ "model": "Sale", "foreignKey": "saleFk" }, + "itemShelving": { + "type": "belongsTo", + "model": "ItemShelving", + "foreignKey": "itemShelvingFk" + }, "user": { "type": "belongsTo", "model": "Account", diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json new file mode 100644 index 000000000..0fcc00f7e --- /dev/null +++ b/modules/item/back/models/item-shelving.json @@ -0,0 +1,40 @@ +{ + "name": "ItemShelving", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemShelving" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "shelve": { + "type": "string" + }, + "deep": { + "type": "number" + }, + "quantity": { + "type": "number" + }, + "created": { + "type": "Date" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + }, + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + } +} diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 6daad7c39..0f7e0b57f 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -23,6 +23,7 @@ module.exports = Self => { Self.setDeleted = async(ctx, id) => { const models = Self.app.models; + const userId = ctx.req.accessToken.userId; const isEditable = await Self.isEditable(ctx, id); const $t = ctx.req.__; // $translate @@ -30,16 +31,30 @@ module.exports = Self => { throw new UserError(`The sales of this ticket can't be modified`); // Check if has sales with shelving + const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant'); const sales = await models.Sale.find({ - include: {relation: 'itemShelving'}, + include: {relation: 'itemShelvingSale'}, where: {ticketFk: id} }); const hasItemShelvingSales = sales.some(sale => { - return sale.itemShelving(); + return sale.itemShelvingSale(); }); - if (hasItemShelvingSales) + + if (hasItemShelvingSales && !isSalesAssistant) throw new UserError(`You cannot delete a ticket that part of it is being prepared`); + if (hasItemShelvingSales && isSalesAssistant) { + const promises = []; + for (let sale of sales) { + if (sale.itemShelvingSale()) { + const itemShelvingSale = sale.itemShelvingSale(); + const destroyedShelving = models.ItemShelvingSale.destroyById(itemShelvingSale.id); + promises.push(destroyedShelving); + } + } + await Promise.all(promises); + } + // Check for existing claim const claimOfATicket = await models.Claim.findOne({where: {ticketFk: id}}); if (claimOfATicket) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 890fc6c45..f756db771 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -1,13 +1,28 @@ const app = require('vn-loopback/server/server'); +const models = app.models; -describe('ticket deleted()', () => { +fdescribe('ticket deleted()', () => { let ticket; + let sale; let ctx; beforeAll(async done => { - let originalTicket = await app.models.Ticket.findOne({where: {id: 16}}); + let originalTicket = await models.Ticket.findOne({where: {id: 16}}); originalTicket.id = null; - ticket = await app.models.Ticket.create(originalTicket); + ticket = await models.Ticket.create(originalTicket); + sale = await models.Sale.create({ + ticketFk: ticket.id, + itemFk: 4, + concept: 'Melee weapon', + quantity: 10 + }); + + await models.ItemShelvingSale.create({ + itemShelvingFk: 1, + saleFk: sale.id, + quantity: 10, + userFk: 106 + }); ctx = { req: { @@ -23,7 +38,7 @@ describe('ticket deleted()', () => { }); afterAll(async done => { - await app.models.Ticket.destroyById(ticket.id); + await models.Ticket.destroyById(ticket.id); done(); }); @@ -32,6 +47,20 @@ describe('ticket deleted()', () => { expect(ticket.isDeleted).toEqual(false); }); + it('should make sure the ticket sale has an item shelving', async() => { + const sales = await models.Sale.find({ + include: {relation: 'itemShelvingSale'}, + where: {ticketFk: ticket.id} + }); + const hasItemShelvingSales = sales.some(sale => { + return sale.itemShelvingSale(); + }); + + expect(hasItemShelvingSales).toEqual(true); + }); + + // Try to delete ticket as userid 106, throws prepared error + // Try to delete ticket as userid 9 and succeed: it('should set a ticket to deleted', async() => { await app.models.Ticket.setDeleted(ctx, ticket.id); @@ -40,6 +69,18 @@ describe('ticket deleted()', () => { expect(deletedTicket.isDeleted).toEqual(true); }); + it('should not have any item shelving', async() => { + const sales = await models.Sale.find({ + include: {relation: 'itemShelvingSale'}, + where: {ticketFk: ticket.id} + }); + const hasItemShelvingSales = sales.some(sale => { + return sale.itemShelvingSale(); + }); + + expect(hasItemShelvingSales).toEqual(false); + }); + it('should throw an error if the given ticket has a claim', async() => { let ticketId = 16; let error; diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 1f2ea4bbf..767a3e59e 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -73,7 +73,7 @@ "model": "SaleTracking", "foreignKey": "saleFk" }, - "itemShelving": { + "itemShelvingSale": { "type": "hasOne", "model": "ItemShelvingSale", "foreignKey": "saleFk" From 9bae89a6728f679d87eb97fbbca2dbf825edf87c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 23 Mar 2020 16:03:27 +0100 Subject: [PATCH 17/44] Updated unit test --- .../methods/ticket/specs/setDeleted.spec.js | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index f756db771..2713bd700 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -1,10 +1,9 @@ const app = require('vn-loopback/server/server'); const models = app.models; -fdescribe('ticket deleted()', () => { +describe('ticket deleted()', () => { let ticket; let sale; - let ctx; beforeAll(async done => { let originalTicket = await models.Ticket.findOne({where: {id: 16}}); @@ -24,16 +23,6 @@ fdescribe('ticket deleted()', () => { userFk: 106 }); - ctx = { - req: { - accessToken: {userId: 106}, - headers: { - origin: 'http://localhost:5000' - }, - __: () => {} - } - }; - done(); }); @@ -59,12 +48,23 @@ fdescribe('ticket deleted()', () => { expect(hasItemShelvingSales).toEqual(true); }); - // Try to delete ticket as userid 106, throws prepared error - // Try to delete ticket as userid 9 and succeed: - it('should set a ticket to deleted', async() => { + it('should set a ticket to deleted and remove all item shelvings', async() => { + const salesAssistantId = 21; + const ctx = { + req: { + accessToken: {userId: salesAssistantId}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; await app.models.Ticket.setDeleted(ctx, ticket.id); - let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']}); + let deletedTicket = await app.models.Ticket.findOne({ + where: {id: ticket.id}, + fields: ['isDeleted'] + }); expect(deletedTicket.isDeleted).toEqual(true); }); @@ -82,7 +82,16 @@ fdescribe('ticket deleted()', () => { }); it('should throw an error if the given ticket has a claim', async() => { - let ticketId = 16; + const ticketId = 16; + const ctx = { + req: { + accessToken: {userId: 106}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; let error; try { From 84bf240e71dfc4e00dad308cb20cb3a9d057e5a2 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 23 Mar 2020 23:57:11 +0100 Subject: [PATCH 18/44] All tests passed, but some intermittence in e2e --- db/dump/fixtures.sql | 38 +- e2e/helpers/extensions.js | 330 +++++++++--------- e2e/helpers/puppeteer.js | 7 +- e2e/paths/01-login/01_login.spec.js | 56 +-- e2e/paths/02-client/01_create_client.spec.js | 5 +- .../12_lock_of_verified_data.spec.js | 2 +- .../05-ticket/02_expeditions_and_log.spec.js | 3 +- e2e/paths/05-ticket/13_services.spec.js | 3 - e2e/paths/05-ticket/14_create_ticket.spec.js | 5 +- e2e/paths/06-claim/01_basic_data.spec.js | 4 +- e2e/paths/06-claim/04_claim_action.spec.js | 2 +- e2e/paths/07-order/02_basic_data.spec.js | 3 +- e2e/paths/07-order/04_catalog.spec.js | 4 +- e2e/paths/08-route/02_basic_data.spec.js | 6 +- e2e/paths/08-route/03_create.spec.js | 2 +- .../10-travel/02_basic_data_and_log.spec.js | 5 +- e2e/paths/11-zone/01_basic-data.spec.js | 9 +- front/core/components/snackbar/snackbar.js | 133 ++++--- package-lock.json | 45 +-- 19 files changed, 338 insertions(+), 324 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7b2fd1cae..331d115a3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -471,19 +471,19 @@ INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaF INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `m3Max`) VALUES - (1, 'Zone pickup A', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 1, 0, 0, 0, 30.50), - (2, 'Zone pickup B', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 1, 0, 0, 0, 30.50), - (3, 'Zone 247 A', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 7, 1, 2, 0, 40.50), - (4, 'Zone 247 B', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 7, 1, 2, 0, 40.50), - (5, 'Zone expensive A', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 8, 1, 1000, 0, 50.50), - (6, 'Zone expensive B', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 8, 1, 1000, 0, 50.50), - (7, 'Zone refund', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 23, 0, 0, 0, 60.50), - (8, 'Zone others', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 10, 0, 0, 0, 60.50), - (9, 'Zone superMan', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 2, 0, 0, 0, NULL), - (10, 'Zone teleportation', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 3, 0, 0, 0, NULL), - (11, 'Zone pickup C', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 1, 0, 0, 0, NULL), - (12, 'Zone entanglement', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 4, 0, 0, 0, NULL), - (13, 'Zone quantum break', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 5, 0, 0, 0, NULL); + (1, 'Zone pickup A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 30.50), + (2, 'Zone pickup B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 30.50), + (3, 'Zone 247 A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 40.50), + (4, 'Zone 247 B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 40.50), + (5, 'Zone expensive A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 50.50), + (6, 'Zone expensive B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 50.50), + (7, 'Zone refund', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 23, 0, 0, 0, 60.50), + (8, 'Zone others', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 10, 0, 0, 0, 60.50), + (9, 'Zone superMan', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 2, 0, 0, 0, NULL), + (10, 'Zone teleportation', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 3, 0, 0, 0, NULL), + (11, 'Zone pickup C', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, NULL), + (12, 'Zone entanglement', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 4, 0, 0, 0, NULL), + (13, 'Zone quantum break', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 5, 0, 0, 0, NULL); INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`) VALUES @@ -1890,14 +1890,10 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`) (7, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)), (7, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)), (7, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)), - (7, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)), - (8, 'day', CURDATE()), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)), - (8, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)); + (7, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)); + +INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`) + VALUES (8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'); INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`) VALUES diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 5fe362043..cccf85391 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -1,45 +1,3 @@ -import {url as defaultURL} from './config'; - -function checkVisibility(selector) { - let selectorMatches = document.querySelectorAll(selector); - let element = selectorMatches[0]; - - if (selectorMatches.length > 1) - throw new Error(`Multiple matches of ${selector} found`); - - let isVisible = false; - if (element) { - let eventHandler = event => { - event.preventDefault(); - isVisible = true; - }; - element.addEventListener('mouseover', eventHandler); - let rect = element.getBoundingClientRect(); - let x = rect.left + rect.width / 2; - let y = rect.top + rect.height / 2; - let elementInCenter = document.elementFromPoint(x, y); - let elementInTopLeft = document.elementFromPoint(rect.left, rect.top); - let elementInBottomRight = document.elementFromPoint(rect.right, rect.bottom); - - let e = new MouseEvent('mouseover', { - view: window, - bubbles: true, - cancelable: true, - }); - - if (elementInCenter) - elementInCenter.dispatchEvent(e); - - if (elementInTopLeft) - elementInTopLeft.dispatchEvent(e); - - if (elementInBottomRight) - elementInBottomRight.dispatchEvent(e); - - element.removeEventListener('mouseover', eventHandler); - } - return isVisible; -} let actions = { clickIfExists: async function(selector) { @@ -65,12 +23,6 @@ let actions = { return true; }, - waitUntilNotPresent: async function(selector) { - await this.wait(selector => { - return document.querySelector(selector) == null; - }, selector); - }, - doLogin: async function(userName, password = 'nightmare') { await this.waitForSelector(`vn-login vn-textfield[ng-model="$ctrl.user"]`, {visible: true}); await this.clearInput(`vn-login vn-textfield[ng-model="$ctrl.user"]`); @@ -81,27 +33,31 @@ let actions = { }, login: async function(userName) { - await this.goto(`${defaultURL}/#!/login`); - let dialog = await this.evaluate(() => { - return document.querySelector('button[response="accept"]'); - }); - if (dialog) - await this.waitToClick('button[response="accept"]'); + let state = await this.getState(); + if (state != 'login') { + try { + await this.gotoState('login'); + } catch (err) { + let dialog = await this.evaluate( + () => document.querySelector('button[response="accept"]')); + + if (dialog) + await this.waitToClick('button[response="accept"]'); + else + throw err; + } + } + + await this.waitForState('login'); await this.doLogin(userName); - await this.waitForFunction(() => { - return document.location.hash === '#!/'; - }, {}); + await this.waitForState('home'); }, selectModule: async function(moduleName) { - let snakeName = moduleName.replace(/[\w]([A-Z])/g, m => { - return m[0] + '-' + m[1]; - }).toLowerCase(); - - let selector = `vn-home a[ui-sref="${moduleName}.index"]`; - await this.waitToClick(selector); - await this.expectURL(snakeName); + let state = `${moduleName}.index`; + await this.waitToClick(`vn-home a[ui-sref="${state}"]`); + await this.waitForState(state); }, loginAndModule: async function(userName, moduleName) { @@ -109,56 +65,73 @@ let actions = { await this.selectModule(moduleName); }, - datePicker: async function(selector, changeMonth, day) { - let date = new Date(); - if (changeMonth) date.setMonth(date.getMonth() + changeMonth); - date.setDate(day ? day : 16); - date = date.toISOString().substr(0, 10); - - await this.wait(selector); - await this.evaluate((selector, date) => { - let input = document.querySelector(selector).$ctrl.input; - input.value = date; - input.dispatchEvent(new Event('change')); - }, selector, date); + getState: async function() { + return await this.evaluate(() => { + let $state = angular.element(document.body).injector().get('$state'); + return $state.current.name; + }); }, - pickTime: async function(selector, time) { - await this.wait(selector); - await this.evaluate((selector, time) => { - let input = document.querySelector(selector).$ctrl.input; - input.value = time; - input.dispatchEvent(new Event('change')); - }, selector, time); + gotoState: async function(state, params) { + return await this.evaluate((state, params) => { + let $state = angular.element(document.body).injector().get('$state'); + return $state.go(state, params); + }, state, params); }, - clearTextarea: async function(selector) { - await this.waitForSelector(selector, {visible: true}); - await this.evaluate(inputSelector => { - return document.querySelector(`${inputSelector} textarea`).value = ''; - }, selector); + waitForState: async function(state) { + await this.waitFor(state => { + let $state = angular.element(document.body).injector().get('$state'); + return $state.is(state); + }, {}, state); }, - clearInput: async function(selector) { - await this.waitForSelector(selector); + waitForTransition: async function() { + await this.waitFor(() => { + const $state = angular.element(document.body).injector().get('$state'); + return !$state.transition; + }); + }, - let field = await this.evaluate(selector => { - return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field; - }, selector); + accessToSection: async function(state) { + await this.waitForSelector('vn-left-menu'); + let nested = await this.evaluate(state => { + return document.querySelector(`vn-left-menu li li > a[ui-sref="${state}"]`) != null; + }, state); - if ((field != null && field != '') || field == '0') { - let coords = await this.evaluate(selector => { - let rect = document.querySelector(selector).getBoundingClientRect(); - return {x: rect.x + (rect.width / 2), y: rect.y + (rect.height / 2), width: rect.width}; - }, selector); - await this.mouse.move(coords.x, coords.y); - await this.waitForSelector(`${selector} [icon="clear"]`, {visible: true}); - await this.waitToClick(`${selector} [icon="clear"]`); + if (nested) { + await this.waitToClick('vn-left-menu vn-item-section > vn-icon[icon=keyboard_arrow_down]'); + await this.wait('vn-left-menu .expanded'); } - await this.evaluate(selector => { - return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field == ''; - }, selector); + await this.evaluate(state => { + let navButton = document.querySelector(`vn-left-menu li > a[ui-sref="${state}"]`); + navButton.scrollIntoViewIfNeeded(); + return navButton.click(); + }, state); + + await this.waitForState(state); + await this.waitForContentLoaded(); + }, + + reloadSection: async function(state) { + await this.click('vn-icon[icon="desktop_windows"]'); + await this.accessToSection(state); + }, + + forceReloadSection: async function(sectionRoute) { + await this.waitToClick('vn-icon[icon="desktop_windows"]'); + await this.waitToClick('button[response="accept"]'); + await this.wait('vn-card.summary'); + await this.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`); + }, + + accessToSearchResult: async function(searchValue) { + await this.clearInput('vn-searchbar'); + await this.write('vn-searchbar', searchValue); + await this.waitToClick('vn-searchbar vn-icon[icon="search"]'); + await this.waitForTransition(); + await this.waitForContentLoaded(); }, getProperty: async function(selector, property) { @@ -216,7 +189,7 @@ let actions = { waitToClick: async function(selector) { await this.waitForSelector(selector); - await this.waitForFunction(checkVisibility, {}, selector); + await this.checkVisibility(selector); return await this.click(selector); }, @@ -236,9 +209,52 @@ let actions = { }, selector); }, + checkVisibility: async function(selector) { + return await this.evaluate(function(selector) { + let selectorMatches = document.querySelectorAll(selector); + let element = selectorMatches[0]; + + if (selectorMatches.length > 1) + throw new Error(`Multiple matches of ${selector} found`); + + let isVisible = false; + if (element) { + let eventHandler = event => { + event.preventDefault(); + isVisible = true; + }; + element.addEventListener('mouseover', eventHandler); + let rect = element.getBoundingClientRect(); + let x = rect.left + rect.width / 2; + let y = rect.top + rect.height / 2; + let elementInCenter = document.elementFromPoint(x, y); + let elementInTopLeft = document.elementFromPoint(rect.left, rect.top); + let elementInBottomRight = document.elementFromPoint(rect.right, rect.bottom); + + let e = new MouseEvent('mouseover', { + view: window, + bubbles: true, + cancelable: true, + }); + + if (elementInCenter) + elementInCenter.dispatchEvent(e); + + if (elementInTopLeft) + elementInTopLeft.dispatchEvent(e); + + if (elementInBottomRight) + elementInBottomRight.dispatchEvent(e); + + element.removeEventListener('mouseover', eventHandler); + } + return isVisible; + }, selector); + }, + isVisible: async function(selector) { await this.waitForSelector(selector); - return await this.evaluate(checkVisibility, selector); + return await this.checkVisibility(selector); }, waitImgLoad: async function(selector) { @@ -320,12 +336,13 @@ let actions = { }, hideSnackbar: async function() { - await this.waitFor(750); // holds up for the snackbar to be visible for a small period of time. + await this.waitFor(300); // holds up for the snackbar to be visible for a small period of time. await this.evaluate(() => { let hideButton = document.querySelector('#shapes .shown button'); if (hideButton) return document.querySelector('#shapes .shown button').click(); }); + await this.waitFor('#shapes > .shape', {hidden: true}); }, waitForLastSnackbar: async function() { @@ -341,37 +358,59 @@ let actions = { return snackBarText; }, - accessToSearchResult: async function(searchValue) { - await this.clearInput('vn-searchbar'); - await this.write('vn-searchbar', searchValue); - await this.waitToClick('vn-searchbar vn-icon[icon="search"]'); - await this.waitForContentLoaded(); + pickDate: async function(selector, date) { + date = date || new Date(); + date = date.toISOString().substr(0, 10); + + await this.wait(selector); + await this.evaluate((selector, date) => { + let input = document.querySelector(selector).$ctrl.input; + input.value = date; + input.dispatchEvent(new Event('change')); + }, selector, date); }, - accessToSection: async function(sectionRoute) { - await this.waitForSelector('vn-left-menu'); - let nested = await this.evaluate(sectionRoute => { - return document.querySelector(`vn-left-menu li li > a[ui-sref="${sectionRoute}"]`) != null; - }, sectionRoute); + pickTime: async function(selector, time) { + await this.wait(selector); + await this.evaluate((selector, time) => { + let input = document.querySelector(selector).$ctrl.input; + input.value = time; + input.dispatchEvent(new Event('change')); + }, selector, time); + }, - if (nested) { - await this.waitToClick('vn-left-menu vn-item-section > vn-icon[icon=keyboard_arrow_down]'); - await this.wait('vn-left-menu .expanded'); + clearTextarea: async function(selector) { + await this.waitForSelector(selector, {visible: true}); + await this.evaluate(inputSelector => { + return document.querySelector(`${inputSelector} textarea`).value = ''; + }, selector); + }, + + clearInput: async function(selector) { + await this.waitForSelector(selector); + + let field = await this.evaluate(selector => { + return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field; + }, selector); + + if ((field != null && field != '') || field == '0') { + let coords = await this.evaluate(selector => { + let rect = document.querySelector(selector).getBoundingClientRect(); + return {x: rect.x + (rect.width / 2), y: rect.y + (rect.height / 2), width: rect.width}; + }, selector); + await this.mouse.move(coords.x, coords.y); + await this.waitForSelector(`${selector} [icon="clear"]`, {visible: true}); + await this.waitToClick(`${selector} [icon="clear"]`); } - await this.evaluate(sectionRoute => { - let navButton = document.querySelector(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`); - navButton.scrollIntoViewIfNeeded(); - return navButton.click(); - }, sectionRoute); - await this.waitForNavigation({waitUntil: ['networkidle0']}); - await this.waitForContentLoaded(); + await this.evaluate(selector => { + return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field == ''; + }, selector); }, autocompleteSearch: async function(selector, searchValue) { let builtSelector = await this.selectorFormater(selector); - await this.waitForContentLoaded(); await this.waitToClick(selector); await this.waitForSelector(selector => { document @@ -402,28 +441,7 @@ let actions = { }, {}, builtSelector, searchValue); await this.waitForMutation('.vn-drop-down', 'childList'); - await this.waitForContentLoaded(); - }, - - reloadSection: async function(sectionRoute) { - await this.waitForContentLoaded(); - await Promise.all([ - this.waitForNavigation({waitUntil: 'networkidle0'}), - this.click('vn-icon[icon="desktop_windows"]', {}), - ]); - - await Promise.all([ - this.waitForNavigation({waitUntil: 'networkidle0'}), - this.click(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`, {}), - ]); - await this.waitForContentLoaded(); - }, - - forceReloadSection: async function(sectionRoute) { - await this.waitToClick('vn-icon[icon="desktop_windows"]'); - await this.waitToClick('button[response="accept"]'); - await this.wait('vn-card.summary'); - await this.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`); + await this.waitFor('.vn-drop-down', {hidden: true}); }, checkboxState: async function(selector) { @@ -457,7 +475,7 @@ let actions = { }, waitForSpinnerLoad: async function() { - await this.waitUntilNotPresent('vn-topbar vn-spinner'); + await this.waitFor('vn-topbar vn-spinner', {hidden: true}); }, waitForWatcherData: async function(selector) { @@ -509,14 +527,10 @@ let actions = { closePopup: async function(selector) { await Promise.all([ this.keyboard.press('Escape'), - this.waitForSelector('.vn-popup', {hidden: true}), + this.waitFor('.vn-popup', {hidden: true}), ]); }, - waitForContentLoaded: async function() { - await this.waitFor(1000); - }, - respondToDialog: async function(response) { await this.waitForSelector('.vn-dialog.vn-popup.shown'); const firstCount = await this.evaluate(text => { @@ -531,6 +545,10 @@ let actions = { const dialogs = document.querySelectorAll('.vn-dialog.vn-popup'); return dialogs.length < firstCount; }, {}, firstCount); + }, + + waitForContentLoaded: async function() { + await this.waitFor(250); } }; diff --git a/e2e/helpers/puppeteer.js b/e2e/helpers/puppeteer.js index 1ca0726c0..8aa3f72f8 100644 --- a/e2e/helpers/puppeteer.js +++ b/e2e/helpers/puppeteer.js @@ -8,7 +8,8 @@ export async function getBrowser() { const browser = await Puppeteer.launch({ args: [ '--no-sandbox', - `--window-size=${ 1920 },${ 1080 }` + `--window-size=${ 1920 },${ 1080 }`, + // '--auto-open-devtools-for-tabs' ], defaultViewport: null, headless: headless, @@ -28,8 +29,8 @@ export async function getBrowser() { }); }); page = extendPage(page); - page.setDefaultTimeout(10000); - await page.goto(defaultURL, {waitUntil: 'networkidle0'}); + page.setDefaultTimeout(4000); + await page.goto(defaultURL, {waitUntil: 'load'}); return {page, close: browser.close.bind(browser)}; } diff --git a/e2e/paths/01-login/01_login.spec.js b/e2e/paths/01-login/01_login.spec.js index abb022011..6b101b00b 100644 --- a/e2e/paths/01-login/01_login.spec.js +++ b/e2e/paths/01-login/01_login.spec.js @@ -12,32 +12,42 @@ describe('Login path', async() => { await browser.close(); }); - it('should receive an error when the username is incorrect', async() => { - await page.doLogin('badUser', ''); - const result = await page.waitForLastSnackbar(); + describe('Bad login', async() => { + it('should receive an error when the username is incorrect', async() => { + await page.doLogin('badUser', ''); + const result = await page.waitForLastSnackbar(); + const state = await page.getState(); - expect(result.length).toBeGreaterThan(0); + expect(result.length).toBeGreaterThan(0); + expect(state).toBe('login'); + }); + + it('should receive an error when the username is blank', async() => { + await page.doLogin('', ''); + const result = await page.waitForLastSnackbar(); + const state = await page.getState(); + + expect(result.length).toBeGreaterThan(0); + expect(state).toBe('login'); + }); + + it('should receive an error when the password is incorrect', async() => { + await page.doLogin('employee', 'badPassword'); + const result = await page.waitForLastSnackbar(); + const state = await page.getState(); + + expect(result.length).toBeGreaterThan(0); + expect(state).toBe('login'); + }); }); - it('should receive an error when the username is blank', async() => { - await page.doLogin('', ''); - const result = await page.waitForLastSnackbar(); + describe('Successful login', async() => { + it('should log in', async() => { + await page.doLogin('employee', 'nightmare'); + await page.waitForNavigation(); + const state = await page.getState(); - expect(result.length).toBeGreaterThan(0); - }); - - it('should receive an error when the password is incorrect', async() => { - await page.doLogin('employee', 'badPassword'); - const result = await page.waitForLastSnackbar(); - - expect(result.length).toBeGreaterThan(0); - }); - - it('should log in', async() => { - await page.doLogin('employee', 'nightmare'); - await page.waitForNavigation(); - let url = await page.expectURL('#!/'); - - expect(url).toBe(true); + expect(state).toBe('home'); + }); }); }); diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js index 65db9e7c6..2de38d421 100644 --- a/e2e/paths/02-client/01_create_client.spec.js +++ b/e2e/paths/02-client/01_create_client.spec.js @@ -25,10 +25,7 @@ describe('Client create path', async() => { it('should now access to the create client view by clicking the create-client floating button', async() => { await page.waitToClick(selectors.clientsIndex.createClientButton); - await page.wait(selectors.createClientView.createButton); - let url = await page.expectURL('#!/client/create'); - - expect(url).toBe(true); + await page.waitForState('client.create'); }); it('should receive an error when clicking the create button having all the form fields empty', async() => { diff --git a/e2e/paths/02-client/12_lock_of_verified_data.spec.js b/e2e/paths/02-client/12_lock_of_verified_data.spec.js index 870ce7cb1..c8e590c34 100644 --- a/e2e/paths/02-client/12_lock_of_verified_data.spec.js +++ b/e2e/paths/02-client/12_lock_of_verified_data.spec.js @@ -109,7 +109,7 @@ describe('Client lock verified data path', () => { await page.waitToClick(selectors.clientFiscalData.saveButton); const result = await page.waitForLastSnackbar(); - expect(result).toEqual(jasmine.arrayContaining([`You can't make changes on a client with verified data`])); + expect(result).toEqual(`You can't make changes on a client with verified data`); }); }); diff --git a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js index 94fad9b69..f0accedaf 100644 --- a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js +++ b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js @@ -19,8 +19,9 @@ describe('Ticket expeditions and log path', () => { it(`should delete a former expedition and confirm the remaining expedition are the expected ones`, async() => { await page.waitToClick(selectors.ticketExpedition.secondExpeditionRemoveButton); - await page.waitToClick(selectors.ticketExpedition.acceptDeleteRowButton), + await page.waitToClick(selectors.ticketExpedition.acceptDeleteRowButton); await page.reloadSection('ticket.card.expedition'); + await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {}); const result = await page .countElement(selectors.ticketExpedition.expeditionRow); diff --git a/e2e/paths/05-ticket/13_services.spec.js b/e2e/paths/05-ticket/13_services.spec.js index 07a0a5768..1a32ea944 100644 --- a/e2e/paths/05-ticket/13_services.spec.js +++ b/e2e/paths/05-ticket/13_services.spec.js @@ -44,9 +44,6 @@ describe('Ticket services path', () => { await page.loginAndModule('administrative', 'ticket'); await page.accessToSearchResult(editableTicketId); await page.accessToSection('ticket.card.service'); - let url = await page.expectURL('/service'); - - expect(url).toBe(true); }); it('should click on the add button to prepare the form to create a new service', async() => { diff --git a/e2e/paths/05-ticket/14_create_ticket.spec.js b/e2e/paths/05-ticket/14_create_ticket.spec.js index e501ea0ef..c44125120 100644 --- a/e2e/paths/05-ticket/14_create_ticket.spec.js +++ b/e2e/paths/05-ticket/14_create_ticket.spec.js @@ -23,9 +23,12 @@ describe('Ticket create path', () => { }); it('should succeed to create a ticket', async() => { + const nextMonth = new Date(); + nextMonth.setMonth(nextMonth.getMonth() + 1); + await page.autocompleteSearch(selectors.createTicketView.client, 'Tony Stark'); await page.autocompleteSearch(selectors.createTicketView.address, 'Tony Stark'); - await page.datePicker(selectors.createTicketView.deliveryDate, 1, null); + await page.pickDate(selectors.createTicketView.deliveryDate, nextMonth); await page.autocompleteSearch(selectors.createTicketView.warehouse, 'Warehouse One'); await page.autocompleteSearch(selectors.createTicketView.agency, 'Silla247'); await page.waitToClick(selectors.createTicketView.createButton); diff --git a/e2e/paths/06-claim/01_basic_data.spec.js b/e2e/paths/06-claim/01_basic_data.spec.js index 9718fb583..2eb35b078 100644 --- a/e2e/paths/06-claim/01_basic_data.spec.js +++ b/e2e/paths/06-claim/01_basic_data.spec.js @@ -27,7 +27,7 @@ describe('Claim edit basic data path', () => { await page.waitToClick(selectors.claimBasicData.saveButton); const result = await page.waitForLastSnackbar(); - expect(result).toEqual(jasmine.arrayContaining(['Data saved!'])); + expect(result).toEqual('Data saved!'); }); it(`should have been redirected to the next section of claims as the role is salesAssistant`, async() => { @@ -58,6 +58,6 @@ describe('Claim edit basic data path', () => { await page.waitToClick(selectors.claimBasicData.saveButton); const result = await page.waitForLastSnackbar(); - expect(result).toEqual(jasmine.arrayContaining(['Data saved!'])); + expect(result).toEqual('Data saved!'); }); }); diff --git a/e2e/paths/06-claim/04_claim_action.spec.js b/e2e/paths/06-claim/04_claim_action.spec.js index 1db3938d5..a482e21c3 100644 --- a/e2e/paths/06-claim/04_claim_action.spec.js +++ b/e2e/paths/06-claim/04_claim_action.spec.js @@ -67,7 +67,7 @@ describe('Claim action path', () => { await page.waitToClick(selectors.claimAction.isPaidWithManaCheckbox); const result = await page.waitForLastSnackbar(); - expect(result).toEqual(jasmine.arrayContaining(['Data saved!'])); + expect(result).toEqual('Data saved!'); }); it('should confirm the "is paid with mana" checkbox is checked', async() => { diff --git a/e2e/paths/07-order/02_basic_data.spec.js b/e2e/paths/07-order/02_basic_data.spec.js index 768985628..733ccaa1a 100644 --- a/e2e/paths/07-order/02_basic_data.spec.js +++ b/e2e/paths/07-order/02_basic_data.spec.js @@ -4,7 +4,6 @@ import getBrowser from '../../helpers/puppeteer'; describe('Order edit basic data path', () => { let browser; let page; - const today = new Date().getDate(); beforeAll(async() => { browser = await getBrowser(); @@ -67,7 +66,7 @@ describe('Order edit basic data path', () => { it('should now create a new one', async() => { await page.autocompleteSearch(selectors.createOrderView.client, 'Jessica Jones'); - await page.datePicker(selectors.createOrderView.landedDatePicker, 0, today); + await page.pickDate(selectors.createOrderView.landedDatePicker); await page.autocompleteSearch(selectors.createOrderView.agency, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); let url = await page.expectURL('/catalog'); diff --git a/e2e/paths/07-order/04_catalog.spec.js b/e2e/paths/07-order/04_catalog.spec.js index ca6489779..8c3106f6c 100644 --- a/e2e/paths/07-order/04_catalog.spec.js +++ b/e2e/paths/07-order/04_catalog.spec.js @@ -23,10 +23,8 @@ describe('Order catalog', () => { }); it('should create a new order', async() => { - let today = new Date().getDate(); - await page.autocompleteSearch(selectors.createOrderView.client, 'Tony Stark'); - await page.datePicker(selectors.createOrderView.landedDatePicker, 0, today); + await page.pickDate(selectors.createOrderView.landedDatePicker); await page.autocompleteSearch(selectors.createOrderView.agency, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); let url = await page.expectURL('/catalog'); diff --git a/e2e/paths/08-route/02_basic_data.spec.js b/e2e/paths/08-route/02_basic_data.spec.js index 91688b3ff..66e516366 100644 --- a/e2e/paths/08-route/02_basic_data.spec.js +++ b/e2e/paths/08-route/02_basic_data.spec.js @@ -18,9 +18,12 @@ describe('Route basic Data path', () => { }); it('should edit the route basic data', async() => { + const nextMonth = new Date(); + nextMonth.setMonth(nextMonth.getMonth() + 1); + await page.autocompleteSearch(selectors.routeBasicData.worker, 'adminBossNick'); await page.autocompleteSearch(selectors.routeBasicData.vehicle, '1111-IMK'); - await page.datePicker(selectors.routeBasicData.createdDate, 1, null); + await page.pickDate(selectors.routeBasicData.createdDate, nextMonth); await page.clearInput(selectors.routeBasicData.kmStart); await page.write(selectors.routeBasicData.kmStart, '1'); await page.clearInput(selectors.routeBasicData.kmEnd); @@ -37,7 +40,6 @@ describe('Route basic Data path', () => { await page.reloadSection('route.card.basicData'); const worker = await page.waitToGetProperty(selectors.routeBasicData.worker, 'value'); - expect(worker).toEqual('adminBoss - adminBossNick'); }); diff --git a/e2e/paths/08-route/03_create.spec.js b/e2e/paths/08-route/03_create.spec.js index 11ffd500b..c929e647f 100644 --- a/e2e/paths/08-route/03_create.spec.js +++ b/e2e/paths/08-route/03_create.spec.js @@ -48,7 +48,7 @@ describe('Route create path', () => { it(`should create a new route`, async() => { await page.autocompleteSearch(selectors.createRouteView.worker, 'teamManagerNick'); - await page.datePicker(selectors.createRouteView.createdDatePicker, 0, null); + await page.pickDate(selectors.createRouteView.createdDatePicker); await page.autocompleteSearch(selectors.createRouteView.vehicleAuto, '4444-IMK'); await page.autocompleteSearch(selectors.createRouteView.agency, 'Teleportation device'); await page.write(selectors.createRouteView.description, 'faster faster!!'); diff --git a/e2e/paths/10-travel/02_basic_data_and_log.spec.js b/e2e/paths/10-travel/02_basic_data_and_log.spec.js index a835df2a2..c6287a8a0 100644 --- a/e2e/paths/10-travel/02_basic_data_and_log.spec.js +++ b/e2e/paths/10-travel/02_basic_data_and_log.spec.js @@ -24,7 +24,10 @@ describe('Travel basic data path', () => { }); it('should set a wrong delivery date then receive an error on submit', async() => { - await page.datePicker(selectors.travelBasicDada.deliveryDate, -1, null); + const lastMonth = new Date(); + lastMonth.setMonth(lastMonth.getMonth() - 1); + + await page.pickDate(selectors.travelBasicDada.deliveryDate, lastMonth); await page.waitToClick(selectors.travelBasicDada.save); const result = await page.waitForLastSnackbar(); diff --git a/e2e/paths/11-zone/01_basic-data.spec.js b/e2e/paths/11-zone/01_basic-data.spec.js index c63bb8321..4bb89e459 100644 --- a/e2e/paths/11-zone/01_basic-data.spec.js +++ b/e2e/paths/11-zone/01_basic-data.spec.js @@ -31,7 +31,7 @@ describe('Zone basic data path', () => { await page.clearInput(selectors.zoneBasicData.travelingDays); await page.write(selectors.zoneBasicData.travelingDays, '1'); await page.clearInput(selectors.zoneBasicData.closing); - await page.type(selectors.zoneBasicData.closing, '2100'); + await page.type(selectors.zoneBasicData.closing, '09:00PM'); await page.clearInput(selectors.zoneBasicData.price); await page.write(selectors.zoneBasicData.price, '999'); await page.clearInput(selectors.zoneBasicData.bonus); @@ -40,14 +40,13 @@ describe('Zone basic data path', () => { await page.write(selectors.zoneBasicData.inflation, '200'); await page.waitToClick(selectors.zoneBasicData.volumetric); await page.waitToClick(selectors.zoneBasicData.saveButton); - await page.waitForContentLoaded(); + const result = await page.waitForLastSnackbar(); + + expect(result).toEqual('Data saved!'); }); it('should now reload the section', async() => { await page.reloadSection('zone.card.basicData'); - let url = await page.expectURL('#!/zone/10/basic-data'); - - expect(url).toBe(true); }); it('should confirm the name was updated', async() => { diff --git a/front/core/components/snackbar/snackbar.js b/front/core/components/snackbar/snackbar.js index eb75f9ab8..9439198f0 100644 --- a/front/core/components/snackbar/snackbar.js +++ b/front/core/components/snackbar/snackbar.js @@ -6,9 +6,8 @@ import './style.scss'; * A simple component to show non-obstructive notifications to the user. */ export default class Controller extends Component { - constructor($element, $translate) { - super($element); - this.$translate = $translate; + constructor($element, $) { + super($element, $); this.snackbar = $element[0].firstChild; this.$snackbar = angular.element(this.snackbar); } @@ -19,38 +18,54 @@ export default class Controller extends Component { * @return {Object} Created snackbar shape */ createShape(data) { - let shape = document.createElement('div'); - shape.className = 'shape'; + let shape = Object.assign({ + nMessages: 1 + }, data); + + let element = document.createElement('div'); + element.className = 'shape'; + setTimeout(() => element.classList.add('shown'), 30); + shape.element = element; + + if (shape.type) + element.classList.add(shape.type); let button = document.createElement('button'); + button.addEventListener('click', () => this.onButtonClick(shape)); + element.appendChild(button); - let buttonText = data.actionText || this.$translate.instant('Hide'); + let buttonText = shape.actionText || this.$t('Hide'); buttonText = document.createTextNode(buttonText); button.appendChild(buttonText); - button.addEventListener('click', () => { - this.onButtonClick(shape); - }); - - shape.appendChild(button); - let shapeText = document.createElement('div'); shapeText.setAttribute('class', 'text'); - shape.appendChild(shapeText); + element.appendChild(shapeText); - let text = document.createTextNode(data.message); + let text = document.createTextNode(shape.message); shapeText.appendChild(text); - if (data.shapeType) - shape.classList.add(data.shapeType); + let chip = document.createElement('vn-chip'); + chip.className = 'warning small'; + chip.style.visibility = 'hidden'; - let parent = this.snackbar.querySelectorAll('.shape')[0]; + let chipWrapper = document.createElement('div'); + chip.append(chipWrapper); + + let span = document.createElement('span'); + chipWrapper.append(span); + + let chipText = document.createTextNode(shape.nMessages); + span.append(chipText); + + shapeText.appendChild(chip); + + let parent = this.snackbar.querySelector('.shape'); if (parent) - this.snackbar.insertBefore(shape, parent); + this.snackbar.insertBefore(element, parent); else - this.snackbar.appendChild(shape); - + this.snackbar.appendChild(element); return shape; } @@ -61,58 +76,28 @@ export default class Controller extends Component { * @param {Object} data The message data */ show(data) { - this.actionHandler = data.actionHandler; + let shape = this.lastShape; - let shape; + const isEqual = shape + && shape.type == data.type + && shape.message == data.message; - const lastShape = this.lastShape; - const lastShapeData = lastShape && lastShape.data; - const isEqual = lastShape && (lastShapeData.shapeType == data.shapeType && lastShapeData.message == data.message); + if (isEqual) { + shape.nMessages++; - if (lastShape && isEqual) { - shape = lastShape.element; + const chip = shape.element.querySelector('.text vn-chip'); + chip.style.visibility = 'visible'; - const shapeText = shape.querySelector('.text'); - let chip = shapeText.querySelector('vn-chip'); - - if (chip) { - const text = chip.querySelector('span'); - const number = parseInt(text.innerHTML); - - text.innerHTML = number + 1; - } else { - chip = document.createElement('vn-chip'); - chip.setAttribute('class', 'warning small'); - let parent = document.createElement('div'); - let span = document.createElement('span'); - let text = document.createTextNode(1); - span.append(text); - parent.append(span); - chip.append(parent); - - shapeText.appendChild(chip); - } - - lastShape.element.classList.add('shown'); - - if (this.hideTimeout) - clearTimeout(this.hideTimeout); - } else { + const span = chip.querySelector('span'); + span.innerHTML = shape.nMessages; + } else shape = this.createShape(data); - setTimeout(() => - shape.classList.add('shown'), 30); - } + clearTimeout(shape.hideTimeout); + shape.hideTimeout = setTimeout( + () => this.hide(shape), shape.timeout || 3000); - this.hideTimeout = setTimeout(() => { - this.hide(shape); - this.lastShape = null; - }, data.timeout || 3000); - - this.lastShape = { - data: data, - element: shape - }; + this.lastShape = shape; } /** @@ -121,8 +106,7 @@ export default class Controller extends Component { * @param {Object} data The message data */ showError(data) { - data.shapeType = 'error'; - + data.type = 'error'; this.show(data); } @@ -132,8 +116,7 @@ export default class Controller extends Component { * @param {Object} data The message data */ showSuccess(data) { - data.shapeType = 'success'; - + data.type = 'success'; this.show(data); } @@ -142,8 +125,11 @@ export default class Controller extends Component { * @param {Object} shape Snackbar element */ hide(shape) { - setTimeout(() => shape.classList.remove('shown'), 30); - setTimeout(() => shape.remove(), 250); + if (this.lastShape == shape) + this.lastShape = null; + + shape.element.classList.remove('shown'); + setTimeout(() => shape.element.remove(), 250); } onSnackbarClick(event) { @@ -151,13 +137,12 @@ export default class Controller extends Component { } onButtonClick(shape) { - if (this.actionHandler) - this.actionHandler(); + if (shape.actionHandler) + shape.actionHandler(); else this.hide(shape); } } -Controller.$inject = ['$element', '$translate']; ngModule.component('vnSnackbar', { template: require('./snackbar.html'), diff --git a/package-lock.json b/package-lock.json index 8648fe476..dd10182e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2098,6 +2098,13 @@ "extend": "^3.0.1", "split-array-stream": "^2.0.0", "stream-events": "^1.0.4" + }, + "dependencies": { + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" + } } }, "@google-cloud/projectify": { @@ -2138,6 +2145,11 @@ "xdg-basedir": "^3.0.0" }, "dependencies": { + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" + }, "mime": { "version": "2.4.4", "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", @@ -3210,7 +3222,8 @@ "arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=" + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true }, "asn1": { "version": "0.2.4", @@ -7972,6 +7985,12 @@ "pinkie-promise": "^2.0.0" }, "dependencies": { + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", @@ -8327,20 +8346,6 @@ "kind-of": "^1.1.0" } }, - "glob": { - "version": "7.1.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", - "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, "jasmine": { "version": "2.99.0", "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-2.99.0.tgz", @@ -8354,7 +8359,7 @@ }, "kind-of": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", "integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=", "dev": true }, @@ -8382,9 +8387,9 @@ } }, "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", "dev": true } } @@ -9990,7 +9995,7 @@ }, "jasmine-core": { "version": "2.99.1", - "resolved": "http://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", "integrity": "sha1-5kAN8ea1bhMLYcS80JPap/boyhU=", "dev": true }, From c254604572446d254a9a264a8b52108a7c3ebc99 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 24 Mar 2020 00:54:12 +0100 Subject: [PATCH 19/44] E2E fixes --- e2e/helpers/extensions.js | 109 +++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index cccf85391..820a1e1f0 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -1,4 +1,45 @@ +function checkVisibility(selector) { + let selectorMatches = document.querySelectorAll(selector); + let element = selectorMatches[0]; + + if (selectorMatches.length > 1) + throw new Error(`Multiple matches of ${selector} found`); + + let isVisible = false; + if (element) { + let eventHandler = event => { + event.preventDefault(); + isVisible = true; + }; + element.addEventListener('mouseover', eventHandler); + let rect = element.getBoundingClientRect(); + let x = rect.left + rect.width / 2; + let y = rect.top + rect.height / 2; + let elementInCenter = document.elementFromPoint(x, y); + let elementInTopLeft = document.elementFromPoint(rect.left, rect.top); + let elementInBottomRight = document.elementFromPoint(rect.right, rect.bottom); + + let e = new MouseEvent('mouseover', { + view: window, + bubbles: true, + cancelable: true, + }); + + if (elementInCenter) + elementInCenter.dispatchEvent(e); + + if (elementInTopLeft) + elementInTopLeft.dispatchEvent(e); + + if (elementInBottomRight) + elementInBottomRight.dispatchEvent(e); + + element.removeEventListener('mouseover', eventHandler); + } + return isVisible; +} + let actions = { clickIfExists: async function(selector) { let exists; @@ -189,7 +230,7 @@ let actions = { waitToClick: async function(selector) { await this.waitForSelector(selector); - await this.checkVisibility(selector); + await this.waitForFunction(checkVisibility, {}, selector); return await this.click(selector); }, @@ -209,52 +250,9 @@ let actions = { }, selector); }, - checkVisibility: async function(selector) { - return await this.evaluate(function(selector) { - let selectorMatches = document.querySelectorAll(selector); - let element = selectorMatches[0]; - - if (selectorMatches.length > 1) - throw new Error(`Multiple matches of ${selector} found`); - - let isVisible = false; - if (element) { - let eventHandler = event => { - event.preventDefault(); - isVisible = true; - }; - element.addEventListener('mouseover', eventHandler); - let rect = element.getBoundingClientRect(); - let x = rect.left + rect.width / 2; - let y = rect.top + rect.height / 2; - let elementInCenter = document.elementFromPoint(x, y); - let elementInTopLeft = document.elementFromPoint(rect.left, rect.top); - let elementInBottomRight = document.elementFromPoint(rect.right, rect.bottom); - - let e = new MouseEvent('mouseover', { - view: window, - bubbles: true, - cancelable: true, - }); - - if (elementInCenter) - elementInCenter.dispatchEvent(e); - - if (elementInTopLeft) - elementInTopLeft.dispatchEvent(e); - - if (elementInBottomRight) - elementInBottomRight.dispatchEvent(e); - - element.removeEventListener('mouseover', eventHandler); - } - return isVisible; - }, selector); - }, - isVisible: async function(selector) { await this.waitForSelector(selector); - return await this.checkVisibility(selector); + return await this.evaluate(checkVisibility, selector); }, waitImgLoad: async function(selector) { @@ -360,14 +358,17 @@ let actions = { pickDate: async function(selector, date) { date = date || new Date(); - date = date.toISOString().substr(0, 10); + + const tzoffset = date.getTimezoneOffset() * 60000; + const localIso = (new Date(date.getTime() - tzoffset)) + .toISOString(); await this.wait(selector); - await this.evaluate((selector, date) => { + await this.evaluate((selector, localIso) => { let input = document.querySelector(selector).$ctrl.input; - input.value = date; + input.value = localIso.substr(0, 10); input.dispatchEvent(new Event('change')); - }, selector, date); + }, selector, localIso); }, pickTime: async function(selector, time) { @@ -418,7 +419,7 @@ let actions = { .querySelectorAll('li'); }, selector); - await this.write('.vn-drop-down.vn-popover.vn-popup.shown vn-textfield', searchValue); + await this.write('.vn-drop-down.shown vn-textfield', searchValue); try { await this.waitForFunction((selector, searchValue) => { @@ -430,7 +431,7 @@ let actions = { }, {}, selector, searchValue); } catch (error) { let inputValue = await this.evaluate(() => { - return document.querySelector('.vn-drop-down.vn-popover.vn-popup.shown vn-textfield input').value; + return document.querySelector('.vn-drop-down.shown vn-textfield input').value; }); throw new Error(`${builtSelector} value is ${inputValue}! ${error}`); } @@ -532,9 +533,9 @@ let actions = { }, respondToDialog: async function(response) { - await this.waitForSelector('.vn-dialog.vn-popup.shown'); + await this.waitForSelector('.vn-dialog.shown'); const firstCount = await this.evaluate(text => { - const dialogs = document.querySelectorAll('.vn-dialog.vn-popup'); + const dialogs = document.querySelectorAll('.vn-dialog'); const dialogOnTop = dialogs[dialogs.length - 1]; const button = dialogOnTop.querySelector(`div.buttons [response="${text}"]`); button.click(); @@ -542,7 +543,7 @@ let actions = { }, response); this.waitForFunction(firstCount => { - const dialogs = document.querySelectorAll('.vn-dialog.vn-popup'); + const dialogs = document.querySelectorAll('.vn-dialog'); return dialogs.length < firstCount; }, {}, firstCount); }, From acf8c117b02cd185b6fdb33f0031916a2bc9c405 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 24 Mar 2020 10:48:16 +0100 Subject: [PATCH 20/44] small spec fixes --- e2e/paths/05-ticket/12_descriptor.spec.js | 2 +- e2e/paths/11-zone/01_basic-data.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/paths/05-ticket/12_descriptor.spec.js b/e2e/paths/05-ticket/12_descriptor.spec.js index 0e3712c82..0302b9c86 100644 --- a/e2e/paths/05-ticket/12_descriptor.spec.js +++ b/e2e/paths/05-ticket/12_descriptor.spec.js @@ -58,7 +58,7 @@ describe('Ticket descriptor path', () => { it(`should search for the deleted ticket and check it's date`, async() => { await page.write(selectors.ticketsIndex.topbarSearch, '18'); await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.expectURL('/summary'); + await page.waitForState('ticket.card.summary'); const result = await page.waitToGetProperty(selectors.ticketsIndex.searchResultDate, 'innerText'); expect(result).toContain(2000); diff --git a/e2e/paths/11-zone/01_basic-data.spec.js b/e2e/paths/11-zone/01_basic-data.spec.js index 4bb89e459..41b3782aa 100644 --- a/e2e/paths/11-zone/01_basic-data.spec.js +++ b/e2e/paths/11-zone/01_basic-data.spec.js @@ -31,7 +31,7 @@ describe('Zone basic data path', () => { await page.clearInput(selectors.zoneBasicData.travelingDays); await page.write(selectors.zoneBasicData.travelingDays, '1'); await page.clearInput(selectors.zoneBasicData.closing); - await page.type(selectors.zoneBasicData.closing, '09:00PM'); + await page.pickTime(selectors.zoneBasicData.closing, '21:00'); await page.clearInput(selectors.zoneBasicData.price); await page.write(selectors.zoneBasicData.price, '999'); await page.clearInput(selectors.zoneBasicData.bonus); From 68a4ed0f103200784b5ab110c2838f80d5a17f9a Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 24 Mar 2020 11:12:59 +0100 Subject: [PATCH 21/44] Some E2E timeouts removed --- e2e/helpers/extensions.js | 17 ++++++++++------- e2e/helpers/puppeteer.js | 17 +++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 820a1e1f0..1ff0119fd 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -58,9 +58,9 @@ let actions = { return document.location.hash.includes(expectedHash); }, {}, expectedHash); } catch (error) { - throw new Error(`failed to reach URL containing: ${expectedHash}`); + throw new Error(`Failed to reach URL containing: ${expectedHash}`); } - await this.waitForContentLoaded(); + await this.waitForSpinnerLoad(); return true; }, @@ -123,8 +123,9 @@ let actions = { waitForState: async function(state) { await this.waitFor(state => { let $state = angular.element(document.body).injector().get('$state'); - return $state.is(state); + return !$state.transition && $state.is(state); }, {}, state); + await this.waitForSpinnerLoad(state); }, waitForTransition: async function() { @@ -152,7 +153,6 @@ let actions = { }, state); await this.waitForState(state); - await this.waitForContentLoaded(); }, reloadSection: async function(state) { @@ -172,7 +172,7 @@ let actions = { await this.write('vn-searchbar', searchValue); await this.waitToClick('vn-searchbar vn-icon[icon="search"]'); await this.waitForTransition(); - await this.waitForContentLoaded(); + await this.waitFor('.vn-descriptor'); }, getProperty: async function(selector, property) { @@ -334,7 +334,10 @@ let actions = { }, hideSnackbar: async function() { - await this.waitFor(300); // holds up for the snackbar to be visible for a small period of time. + // Holds up for the snackbar to be visible for a small period of time. + if (process.env.DEBUG) + await this.waitFor(300); + await this.evaluate(() => { let hideButton = document.querySelector('#shapes .shown button'); if (hideButton) @@ -549,7 +552,7 @@ let actions = { }, waitForContentLoaded: async function() { - await this.waitFor(250); + // await this.waitFor(250); } }; diff --git a/e2e/helpers/puppeteer.js b/e2e/helpers/puppeteer.js index 8aa3f72f8..1ea3c1c90 100644 --- a/e2e/helpers/puppeteer.js +++ b/e2e/helpers/puppeteer.js @@ -4,17 +4,22 @@ import {extendPage} from './extensions'; import {url as defaultURL} from './config'; export async function getBrowser() { - let headless = !process.env.E2E_SHOW; + const args = [ + `--no-sandbox`, + `--window-size=${ 1920 },${ 1080 }` + ]; + + if (process.env.DEBUG) + args.push('--auto-open-devtools-for-tabs'); + + const headless = !process.env.E2E_SHOW; const browser = await Puppeteer.launch({ - args: [ - '--no-sandbox', - `--window-size=${ 1920 },${ 1080 }`, - // '--auto-open-devtools-for-tabs' - ], + args, defaultViewport: null, headless: headless, slowMo: 0, // slow down by ms }); + let page = (await browser.pages())[0]; await page.evaluateOnNewDocument(() => { Object.defineProperty(navigator, 'language', { From 423f59dfb04d6e8c1a0da9e4bf1e03cd72d7c5ec Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 24 Mar 2020 12:20:53 +0100 Subject: [PATCH 22/44] worker log --- db/changes/10162-fallas/00-acl.sql | 1 + db/changes/10162-fallas/00-workerLog.sql | 6 +++ modules/travel/back/models/travel.json | 2 +- modules/worker/back/model-config.json | 6 +++ modules/worker/back/models/worker-log.json | 58 ++++++++++++++++++++++ modules/worker/back/models/worker.json | 6 ++- modules/worker/front/basic-data/index.html | 5 +- modules/worker/front/basic-data/index.js | 2 +- modules/worker/front/index.js | 1 + modules/worker/front/locale/es.yml | 1 + modules/worker/front/routes.json | 8 ++- modules/worker/front/worker-log/index.html | 1 + modules/worker/front/worker-log/index.js | 15 ++++++ 13 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 db/changes/10162-fallas/00-acl.sql create mode 100644 db/changes/10162-fallas/00-workerLog.sql create mode 100644 modules/worker/back/models/worker-log.json create mode 100644 modules/worker/front/worker-log/index.html create mode 100644 modules/worker/front/worker-log/index.js diff --git a/db/changes/10162-fallas/00-acl.sql b/db/changes/10162-fallas/00-acl.sql new file mode 100644 index 000000000..376788af1 --- /dev/null +++ b/db/changes/10162-fallas/00-acl.sql @@ -0,0 +1 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('WorkerLog', '*', 'READ', 'ALLOW', 'ROLE', 'hr'); diff --git a/db/changes/10162-fallas/00-workerLog.sql b/db/changes/10162-fallas/00-workerLog.sql new file mode 100644 index 000000000..730b60aa5 --- /dev/null +++ b/db/changes/10162-fallas/00-workerLog.sql @@ -0,0 +1,6 @@ +ALTER TABLE `vn`.`workerLog` + ADD COLUMN `changedModel` VARCHAR(45) NULL DEFAULT NULL AFTER `description`, + ADD COLUMN `oldInstance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci, + ADD COLUMN `newInstance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci, + ADD COLUMN `changedModelId` int(11) DEFAULT NULL, + ADD COLUMN `changedModelValue` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL; \ No newline at end of file diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index 0eafe4010..aebf4e3cd 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -7,7 +7,7 @@ }, "options": { "mysql": { - "table": "travel" + "table": "travel" } }, "properties": { diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 884759bc9..e91e8b0fc 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -52,5 +52,11 @@ }, "Device": { "dataSource": "vn" + }, + "WorkerLog": { + "dataSource": "vn" } } + + + diff --git a/modules/worker/back/models/worker-log.json b/modules/worker/back/models/worker-log.json new file mode 100644 index 000000000..f100f3486 --- /dev/null +++ b/modules/worker/back/models/worker-log.json @@ -0,0 +1,58 @@ +{ + "name": "WorkerLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerLog" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "originFk": { + "type": "Number", + "required": true + }, + "userFk": { + "type": "Number" + }, + "action": { + "type": "String", + "required": true + }, + "changedModel": { + "type": "String" + }, + "oldInstance": { + "type": "Object" + }, + "newInstance": { + "type": "Object" + }, + "creationDate": { + "type": "Date" + }, + "changedModelId": { + "type": "String" + }, + "changedModelValue": { + "type": "String" + }, + "description": { + "type": "String" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + }, + "scope": { + "order": ["creationDate DESC", "id DESC"] + } +} diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 7456a3caa..6af7e8608 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -1,7 +1,11 @@ { "name": "Worker", "description": "Company employees", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"WorkerLog", + "showField": "firstName" + }, "options": { "mysql": { "table": "worker" diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index 67439b350..bdc309c00 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -1,10 +1,9 @@ + + save="patch">
diff --git a/modules/worker/front/basic-data/index.js b/modules/worker/front/basic-data/index.js index 28107dc12..bf38ce848 100644 --- a/modules/worker/front/basic-data/index.js +++ b/modules/worker/front/basic-data/index.js @@ -6,7 +6,7 @@ class Controller { } onSubmit() { - this.$.watcher.submit() + return this.$.watcher.submit() .then(() => this.card.reload()); } } diff --git a/modules/worker/front/index.js b/modules/worker/front/index.js index f703e7c21..00b4bdaa8 100644 --- a/modules/worker/front/index.js +++ b/modules/worker/front/index.js @@ -13,6 +13,7 @@ import './department'; import './calendar'; import './time-control'; import './log'; +import './worker-log'; import './dms/index'; import './dms/create'; import './dms/edit'; diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index 3fa727801..82535fe4e 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -18,3 +18,4 @@ Calendar: Calendario Search workers by id, firstName, lastName or user name: Buscar trabajadores por el identificador, nombre, apellidos o nombre de usuario Time control: Control de horario Data saved! User must access web: ¡Datos guardados! El usuario deberá acceder con su contraseña a la web para que los cambios surtan efecto. +Log: Historial \ No newline at end of file diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index d7eded94b..9aa214c5c 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -13,7 +13,8 @@ {"state": "worker.card.pbx", "icon": "icon-pbx"}, {"state": "worker.card.calendar", "icon": "icon-calendar"}, {"state": "worker.card.timeControl", "icon": "access_time"}, - {"state": "worker.card.dms.index", "icon": "cloud_upload"} + {"state": "worker.card.dms.index", "icon": "cloud_upload"}, + {"state": "worker.card.workerLog", "icon": "history"} ] }, "routes": [ @@ -51,6 +52,11 @@ "worker": "$ctrl.worker" }, "acl": ["hr"] + }, { + "url" : "/log", + "state": "worker.card.workerLog", + "component": "vn-worker-log", + "description": "Log" }, { "url": "/pbx", "state": "worker.card.pbx", diff --git a/modules/worker/front/worker-log/index.html b/modules/worker/front/worker-log/index.html new file mode 100644 index 000000000..b38a456cb --- /dev/null +++ b/modules/worker/front/worker-log/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/worker/front/worker-log/index.js b/modules/worker/front/worker-log/index.js new file mode 100644 index 000000000..bd1e987c9 --- /dev/null +++ b/modules/worker/front/worker-log/index.js @@ -0,0 +1,15 @@ +import ngModule from '../module'; + +class Controller { + constructor($scope, $stateParams) { + this.$scope = $scope; + this.$stateParams = $stateParams; + } +} + +Controller.$inject = ['$scope', '$stateParams']; + +ngModule.component('vnWorkerLog', { + template: require('./index.html'), + controller: Controller, +}); From a52fcb587a6febada016fae8e940f32e8cac40d4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 24 Mar 2020 14:10:07 +0100 Subject: [PATCH 23/44] drop-down e2e fix --- front/core/components/drop-down/index.js | 33 +++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/front/core/components/drop-down/index.js b/front/core/components/drop-down/index.js index 9f2dfe424..ed7de7179 100644 --- a/front/core/components/drop-down/index.js +++ b/front/core/components/drop-down/index.js @@ -29,13 +29,16 @@ export default class DropDown extends Popover { } set search(value) { - let oldValue = this._search; + function nullify(value) { + return value == '' || value == undefined ? null : value; + } + + let oldValue = nullify(this._search); this._search = value; if (!this.shown) return; - value = value == '' || value == null ? null : value; - oldValue = oldValue == '' || oldValue == null ? null : oldValue; + value = nullify(value); if (value === oldValue && this.modelData != null) return; if (value != null) @@ -45,7 +48,8 @@ export default class DropDown extends Popover { if (this.model) { this.model.clear(); - if (!this.data) { + + if (this.model instanceof CrudModel) { this.searchTimeout = this.$timeout(() => { this.refreshModel(); this.searchTimeout = null; @@ -353,6 +357,7 @@ export default class DropDown extends Popover { set model(value) { this.linkEvents({_model: value}, {dataChange: this.onDataChange}); this.onDataChange(); + this.search = this.search; } get url() { @@ -362,10 +367,9 @@ export default class DropDown extends Popover { set url(value) { this._url = value; if (value) { - this.model = new CrudModel(this.$q, this.$http); - this.model.autoLoad = false; - this.model.url = value; - this.model.$onInit(); + let model = new CrudModel(this.$q, this.$http); + model.url = value; + this.initModel(model); } } @@ -376,13 +380,18 @@ export default class DropDown extends Popover { set data(value) { this._data = value; if (value) { - this.model = new ArrayModel(this.$q, this.$filter); - this.model.autoLoad = false; - this.model.orgData = value; - this.model.$onInit(); + let model = new ArrayModel(this.$q, this.$filter); + model.orgData = value; + this.initModel(model); } } + initModel(model) { + model.autoLoad = false; + model.$onInit(); + this.model = model; + } + refreshModel() { let model = this.model; From 4f7e56788e81fee14f48aad47de48e15590e5c65 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 24 Mar 2020 16:49:36 +0100 Subject: [PATCH 24/44] replaced expectURL for waitForState in most cases --- e2e/helpers/extensions.js | 6 ---- e2e/paths/02-client/01_create_client.spec.js | 8 ++--- .../02-client/03_edit_fiscal_data.spec.js | 12 ++------ e2e/paths/02-client/05_add_address.spec.js | 16 +++------- .../02-client/06_add_address_notes.spec.js | 4 +-- e2e/paths/02-client/08_add_notes.spec.js | 8 ++--- e2e/paths/02-client/09_add_credit.spec.js | 4 +-- e2e/paths/02-client/10_add_greuge.spec.js | 4 +-- e2e/paths/02-client/13_log.spec.js | 5 +--- e2e/paths/02-client/14_balance.spec.js | 12 ++------ e2e/paths/02-client/19_summary.spec.js | 4 +-- e2e/paths/03-worker/01_summary.spec.js | 4 +-- e2e/paths/03-worker/04_time_control.spec.js | 8 ++--- e2e/paths/04-item/01_summary.spec.js | 4 +-- e2e/paths/04-item/08_create_and_clone.spec.js | 20 ++++--------- e2e/paths/04-item/09_regularize.spec.js | 28 +++++------------- e2e/paths/04-item/11_item_log.spec.js | 12 ++------ e2e/paths/04-item/13_request.spec.js | 4 +-- e2e/paths/05-ticket/05_tracking_state.spec.js | 8 ++--- .../05-ticket/06_basic_data_steps.spec.js | 8 ++--- e2e/paths/05-ticket/09_weekly.spec.js | 16 +++------- e2e/paths/05-ticket/10_request.spec.js | 5 +--- e2e/paths/05-ticket/11_diary.spec.js | 4 +-- e2e/paths/05-ticket/12_descriptor.spec.js | 20 ++++--------- e2e/paths/05-ticket/14_create_ticket.spec.js | 8 ++--- .../15_create_ticket_from_client.spec.js | 5 +--- e2e/paths/05-ticket/16_summary.spec.js | 8 ++--- e2e/paths/05-ticket/17_log.spec.js | 8 ++--- e2e/paths/06-claim/01_basic_data.spec.js | 4 +-- e2e/paths/06-claim/02_development.spec.js | 4 +-- e2e/paths/06-claim/03_detail.spec.js | 4 +-- e2e/paths/06-claim/05_summary.spec.js | 4 +-- e2e/paths/06-claim/06_descriptor.spec.js | 12 ++------ e2e/paths/07-order/01_summary.spec.js | 4 +-- e2e/paths/07-order/02_basic_data.spec.js | 16 +++------- e2e/paths/07-order/03_lines.spec.js | 7 ++--- e2e/paths/07-order/04_catalog.spec.js | 8 ++--- e2e/paths/08-route/01_summary.spec.js | 4 +-- e2e/paths/08-route/03_create.spec.js | 12 ++------ e2e/paths/09-invoice-out/01_summary.spec.js | 4 +-- .../09-invoice-out/02_descriptor.spec.js | 29 +++++-------------- e2e/paths/10-travel/01_thermograph.spec.js | 8 ++--- .../10-travel/02_basic_data_and_log.spec.js | 8 ++--- e2e/paths/11-zone/01_basic-data.spec.js | 4 +-- e2e/paths/12-entry/01_summary.spec.js | 4 +-- e2e/paths/12-entry/02_descriptor.spec.js | 28 +++++------------- 46 files changed, 105 insertions(+), 312 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 1ff0119fd..136a24905 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -416,12 +416,6 @@ let actions = { let builtSelector = await this.selectorFormater(selector); await this.waitToClick(selector); - await this.waitForSelector(selector => { - document - .querySelector(`${selector} vn-drop-down`).$ctrl.content - .querySelectorAll('li'); - }, selector); - await this.write('.vn-drop-down.shown vn-textfield', searchValue); try { diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js index 2de38d421..29a27884f 100644 --- a/e2e/paths/02-client/01_create_client.spec.js +++ b/e2e/paths/02-client/01_create_client.spec.js @@ -102,15 +102,11 @@ describe('Client create path', async() => { await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.clientsButton); await page.wait(selectors.clientsIndex.createClientButton); - let url = await page.expectURL('#!/client/index'); - - expect(url).toBe(true); + await page.waitForState('lient.index'); }); it(`should search for the user Carol Danvers to confirm it exists`, async() => { await page.accessToSearchResult('Carol Danvers'); - let url = await page.expectURL('#!/client/114/summary'); - - expect(url).toBe(true); + await page.waitForState('client.card.summary'); }); }); diff --git a/e2e/paths/02-client/03_edit_fiscal_data.spec.js b/e2e/paths/02-client/03_edit_fiscal_data.spec.js index 4cd54b87d..10a29cdfa 100644 --- a/e2e/paths/02-client/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client/03_edit_fiscal_data.spec.js @@ -36,9 +36,7 @@ describe('Client Edit fiscalData path', () => { it(`should click on the fiscal data button`, async() => { await page.waitToClick(selectors.clientFiscalData.fiscalDataButton); - let url = await page.expectURL('fiscal-data'); - - expect(url).toBe(true); + await page.waitForState('client.card.fiscalData'); }); it('should not be able to edit the verified data checkbox', async() => { @@ -124,9 +122,7 @@ describe('Client Edit fiscalData path', () => { // confirm all addresses have now EQtax checked step 1 it(`should click on the addresses button to access to the client's addresses`, async() => { await page.waitToClick(selectors.clientAddresses.addressesButton); - let url = await page.expectURL('/address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); // confirm all addresses have now EQtax checked step 2 @@ -261,9 +257,7 @@ describe('Client Edit fiscalData path', () => { // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 1 it(`should click on the addresses button to access to the client's addresses`, async() => { await page.waitToClick(selectors.clientAddresses.addressesButton); - let url = await page.expectURL('/address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); // confirm invoice by address checkbox gets checked if the EQtax differs between addresses step 2 diff --git a/e2e/paths/02-client/05_add_address.spec.js b/e2e/paths/02-client/05_add_address.spec.js index c9228e1cf..f22798453 100644 --- a/e2e/paths/02-client/05_add_address.spec.js +++ b/e2e/paths/02-client/05_add_address.spec.js @@ -18,9 +18,7 @@ describe('Client Add address path', () => { it(`should click on the add new address button to access to the new address form`, async() => { await page.waitToClick(selectors.clientAddresses.createAddress); - let url = await page.expectURL('address/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.create'); }); it('should receive an error after clicking save button as consignee, street and town fields are empty', async() => { @@ -72,9 +70,7 @@ describe('Client Add address path', () => { }); it(`should navigate back to the addresses index`, async() => { - let url = await page.expectURL('/address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); it(`should confirm the new address exists and it's the default one`, async() => { @@ -101,9 +97,7 @@ describe('Client Add address path', () => { it(`should click on the edit icon of the default address`, async() => { await page.waitForTextInElement(selectors.clientAddresses.defaultAddress, 'Somewhere in Thailand'); await page.waitToClick(selectors.clientAddresses.firstEditAddress); - let url = await page.expectURL('/edit'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.edit'); }); it(`should click on the active checkbox and receive an error to save it because it is the default address`, async() => { @@ -119,8 +113,6 @@ describe('Client Add address path', () => { await page.waitForSelector('#shapes .shown', {hidden: true}); await page.waitToClick(selectors.clientAddresses.cancelEditAddressButton); await page.waitToClick('.vn-confirm.shown button[response="accept"]'); - let url = await page.expectURL('address/index'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.index'); }); }); diff --git a/e2e/paths/02-client/06_add_address_notes.spec.js b/e2e/paths/02-client/06_add_address_notes.spec.js index 58a949698..abfa1ae34 100644 --- a/e2e/paths/02-client/06_add_address_notes.spec.js +++ b/e2e/paths/02-client/06_add_address_notes.spec.js @@ -19,9 +19,7 @@ describe('Client add address notes path', () => { it(`should click on the edit icon of the default address`, async() => { await page.waitForTextInElement(selectors.clientAddresses.defaultAddress, '20 Ingram Street'); await page.waitToClick(selectors.clientAddresses.firstEditAddress); - let url = await page.expectURL('/edit'); - - expect(url).toBe(true); + await page.waitForState('client.card.address.edit'); }); it('should not save a description without observation type', async() => { diff --git a/e2e/paths/02-client/08_add_notes.spec.js b/e2e/paths/02-client/08_add_notes.spec.js index b759cbd07..3d6a8a915 100644 --- a/e2e/paths/02-client/08_add_notes.spec.js +++ b/e2e/paths/02-client/08_add_notes.spec.js @@ -17,16 +17,12 @@ describe('Client Add notes path', () => { }); it(`should reach the notes index`, async() => { - let url = await page.expectURL('/note'); - - expect(url).toBe(true); + await page.waitForState('client.card.note.index'); }); it(`should click on the add note button`, async() => { await page.waitToClick(selectors.clientNotes.addNoteFloatButton); - let url = await page.expectURL('/note/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.note.create'); }); it(`should create a note`, async() => { diff --git a/e2e/paths/02-client/09_add_credit.spec.js b/e2e/paths/02-client/09_add_credit.spec.js index 05c50e809..639d850f6 100644 --- a/e2e/paths/02-client/09_add_credit.spec.js +++ b/e2e/paths/02-client/09_add_credit.spec.js @@ -18,9 +18,7 @@ describe('Client Add credit path', () => { it(`should click on the add credit button`, async() => { await page.waitToClick(selectors.clientCredit.addCreditFloatButton); - let url = await page.expectURL('/credit/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.credit.create'); }); it(`should edit the credit`, async() => { diff --git a/e2e/paths/02-client/10_add_greuge.spec.js b/e2e/paths/02-client/10_add_greuge.spec.js index c934a42f1..1dda319be 100644 --- a/e2e/paths/02-client/10_add_greuge.spec.js +++ b/e2e/paths/02-client/10_add_greuge.spec.js @@ -18,9 +18,7 @@ describe('Client Add greuge path', () => { it(`should click on the add greuge button`, async() => { await page.waitToClick(selectors.clientGreuge.addGreugeFloatButton); - let url = await page.expectURL('greuge/create'); - - expect(url).toBe(true); + await page.waitForState('client.card.greuge.create'); }); it(`should receive an error if all fields are empty but date and type on submit`, async() => { diff --git a/e2e/paths/02-client/13_log.spec.js b/e2e/paths/02-client/13_log.spec.js index 462d66347..fc4b98b8b 100644 --- a/e2e/paths/02-client/13_log.spec.js +++ b/e2e/paths/02-client/13_log.spec.js @@ -27,9 +27,7 @@ describe('Client log path', () => { it('should navigate to the log section', async() => { await page.waitToClick(selectors.clientLog.logButton); - let url = await page.expectURL('log'); - - expect(url).toBe(true); + await page.waitForState('client.card.log'); }); it('should check the previous value of the last logged change', async() => { @@ -46,7 +44,6 @@ describe('Client log path', () => { let lastModificationCurrentValue = await page. waitToGetProperty(selectors.clientLog.lastModificationCurrentValue, 'innerText'); - expect(lastModificationPreviousValue).toEqual('name: DavidCharlesHaller'); expect(lastModificationCurrentValue).toEqual('name: this is a test'); }); diff --git a/e2e/paths/02-client/14_balance.spec.js b/e2e/paths/02-client/14_balance.spec.js index ef7930c8d..87dc84a8e 100644 --- a/e2e/paths/02-client/14_balance.spec.js +++ b/e2e/paths/02-client/14_balance.spec.js @@ -41,9 +41,7 @@ describe('Client balance path', () => { it('should click the new payment button', async() => { await page.closePopup(); await page.reloadSection('client.card.balance.index'); - let url = await page.expectURL('/balance'); - - expect(url).toBe(true); + await page.waitForState('client.card.balance.index'); }); it('should create a new payment that clears the debt', async() => { @@ -110,17 +108,13 @@ describe('Client balance path', () => { await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.clientsButton); await page.wait(selectors.clientsIndex.createClientButton); - let url = await page.expectURL('#!/client/index'); - - expect(url).toBe(true); + await page.waitForState('client.index'); }); it('should now search for the user Petter Parker', async() => { await page.accessToSearchResult('Petter Parker'); await page.waitToClick(selectors.clientBalance.balanceButton); - let url = await page.expectURL('/balance'); - - expect(url).toBe(true); + await page.waitForState('client.card.balance.index'); }); it('should not be able to click the new payment button as it isnt present', async() => { diff --git a/e2e/paths/02-client/19_summary.spec.js b/e2e/paths/02-client/19_summary.spec.js index 11b5a298e..ab39154cf 100644 --- a/e2e/paths/02-client/19_summary.spec.js +++ b/e2e/paths/02-client/19_summary.spec.js @@ -17,9 +17,7 @@ describe('Client summary path', () => { }); it('should reach the first route summary section', async() => { - let url = await page.expectURL('#!/client/102/summary'); - - expect(url).toBe(true); + await page.waitForState('client.card.summary'); }); it('should display details from the client on the header', async() => { diff --git a/e2e/paths/03-worker/01_summary.spec.js b/e2e/paths/03-worker/01_summary.spec.js index 86a95eee3..4ea87481a 100644 --- a/e2e/paths/03-worker/01_summary.spec.js +++ b/e2e/paths/03-worker/01_summary.spec.js @@ -16,9 +16,7 @@ describe('Worker summary path', () => { }); it('should reach the employee summary section', async() => { - const url = await page.expectURL('#!/worker/3/summary'); - - expect(url).toBe(true); + await page.waitForState('worker.card.summary'); }); it('should check the summary contains the name and userName on the header', async() => { diff --git a/e2e/paths/03-worker/04_time_control.spec.js b/e2e/paths/03-worker/04_time_control.spec.js index 36aaca61e..36340e880 100644 --- a/e2e/paths/03-worker/04_time_control.spec.js +++ b/e2e/paths/03-worker/04_time_control.spec.js @@ -316,16 +316,12 @@ describe('Worker time control path', () => { it('should search for a worker and access to its summary', async() => { await page.accessToSearchResult('HankPym'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('worker.card.summary'); }); it('should access to the time control section', async() => { await page.accessToSection('worker.card.timeControl'); - let url = await page.expectURL('/time-control'); - - expect(url).toBe(true); + await page.waitForState('worker.card.timeControl'); }); it('should lovingly scan in Hank Pym', async() => { diff --git a/e2e/paths/04-item/01_summary.spec.js b/e2e/paths/04-item/01_summary.spec.js index 6fd4e9c13..6f2c2c926 100644 --- a/e2e/paths/04-item/01_summary.spec.js +++ b/e2e/paths/04-item/01_summary.spec.js @@ -103,9 +103,7 @@ describe('Item summary path', () => { it(`should navigate to the one of the items detailed section`, async() => { await page.accessToSearchResult('Melee weapon combat fist 15cm'); - let url = await page.expectURL('summary'); - - expect(url).toBe(true); + await page.waitForState('item.card.summary'); }); it(`should check the descritor edit button is not visible for employee`, async() => { diff --git a/e2e/paths/04-item/08_create_and_clone.spec.js b/e2e/paths/04-item/08_create_and_clone.spec.js index d06ef4682..73249a0b9 100644 --- a/e2e/paths/04-item/08_create_and_clone.spec.js +++ b/e2e/paths/04-item/08_create_and_clone.spec.js @@ -27,23 +27,17 @@ describe('Item Create/Clone path', () => { it('should access to the create item view by clicking the create floating button', async() => { await page.waitToClick(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/create'); - - expect(url).toBe(true); + await page.waitForState('item.create'); }); it('should return to the item index by clickig the cancel button', async() => { await page.waitToClick(selectors.itemCreateView.cancelButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it('should now access to the create item view by clicking the create floating button', async() => { await page.waitToClick(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/create'); - - expect(url).toBe(true); + await page.waitForState('item.create'); }); it('should create the Infinity Gauntlet item', async() => { @@ -87,9 +81,7 @@ describe('Item Create/Clone path', () => { it('should return to the items index by clicking the return to items button', async() => { await page.waitToClick(selectors.itemBasicData.goToItemIndexButton); await page.wait(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it(`should search for the item Infinity Gauntlet`, async() => { @@ -106,9 +98,7 @@ describe('Item Create/Clone path', () => { await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Infinity Gauntlet'); await page.waitToClick(selectors.itemsIndex.searchResultCloneButton); await page.waitToClick(selectors.itemsIndex.acceptClonationAlertButton); - let url = await page.expectURL('tags'); - - expect(url).toBe(true); + await page.waitForState('item.tags'); }); it('should search for the item Infinity Gauntlet and find two', async() => { diff --git a/e2e/paths/04-item/09_regularize.spec.js b/e2e/paths/04-item/09_regularize.spec.js index 18f182e74..a37d97fa3 100644 --- a/e2e/paths/04-item/09_regularize.spec.js +++ b/e2e/paths/04-item/09_regularize.spec.js @@ -34,9 +34,7 @@ describe('Item regularize path', () => { it('should search for an specific item', async() => { await page.accessToSearchResult('Ranged weapon pistol 9mm'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('item.card.summary'); }); it('should open the regularize dialog and check the warehouse matches the local user settings', async() => { @@ -63,9 +61,7 @@ describe('Item regularize path', () => { page.waitForNavigation({waitUntil: ['load', 'networkidle0', 'domcontentloaded']}), page.waitToClick(selectors.globalItems.ticketsButton) ]); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should clear the user local settings now', async() => { @@ -80,9 +76,7 @@ describe('Item regularize path', () => { it('should search for the ticket with alias missing', async() => { await page.keyboard.press('Escape'); await page.accessToSearchResult('missing'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should check the ticket sale quantity is showing a negative value`, async() => { @@ -104,16 +98,12 @@ describe('Item regularize path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.itemsButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it('should search for the item once again', async() => { await page.accessToSearchResult('Ranged weapon pistol 9mm'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('item.card.summary'); }); it('should regularize the item once more', async() => { @@ -135,16 +125,12 @@ describe('Item regularize path', () => { page.waitToClick(selectors.globalItems.ticketsButton) ]); await page.waitForTransitionEnd('vn-searchbar'); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should search for the ticket with id 25 once again', async() => { await page.accessToSearchResult('25'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should check the ticket contains now two sales`, async() => { diff --git a/e2e/paths/04-item/11_item_log.spec.js b/e2e/paths/04-item/11_item_log.spec.js index 213365c12..82800b9b8 100644 --- a/e2e/paths/04-item/11_item_log.spec.js +++ b/e2e/paths/04-item/11_item_log.spec.js @@ -25,9 +25,7 @@ describe('Item log path', () => { it('should access to the create item view by clicking the create floating button', async() => { await page.waitToClick(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/create'); - - expect(url).toBe(true); + await page.waitForState('item.create'); }); it('should create the Knowledge artifact item', async() => { @@ -44,17 +42,13 @@ describe('Item log path', () => { it('should return to the items index by clicking the return to items button', async() => { await page.waitToClick(selectors.itemBasicData.goToItemIndexButton); await page.wait(selectors.itemsIndex.createItemButton); - let url = await page.expectURL('#!/item/index'); - - expect(url).toBe(true); + await page.waitForState('item.index'); }); it(`should search for the created item and navigate to it's log section`, async() => { await page.accessToSearchResult('Knowledge artifact'); await page.accessToSection('item.card.log'); - let url = await page.expectURL('/log'); - - expect(url).toBe(true); + await page.waitForState('item.card.log'); }); it(`should confirm the log is showing 5 entries`, async() => { diff --git a/e2e/paths/04-item/13_request.spec.js b/e2e/paths/04-item/13_request.spec.js index d6aecbb48..2deabb20b 100644 --- a/e2e/paths/04-item/13_request.spec.js +++ b/e2e/paths/04-item/13_request.spec.js @@ -16,9 +16,7 @@ describe('Item request path', () => { }); it('should reach the item request section', async() => { - const result = await page.expectURL('/item/request'); - - expect(result).toBe(true); + await page.waitForState('item.request'); }); it('should fill the id and quantity then check the concept was updated', async() => { diff --git a/e2e/paths/05-ticket/05_tracking_state.spec.js b/e2e/paths/05-ticket/05_tracking_state.spec.js index 108e8776f..2623966be 100644 --- a/e2e/paths/05-ticket/05_tracking_state.spec.js +++ b/e2e/paths/05-ticket/05_tracking_state.spec.js @@ -21,9 +21,7 @@ describe('Ticket Create new tracking state path', () => { it('should access to the create state view by clicking the create floating button', async() => { await page.waitToClick(selectors.ticketTracking.createStateButton); await page.waitForSelector(selectors.createStateView.state, {visible: true}); - let url = await page.expectURL('tracking/edit'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.tracking.edit'); }); it(`should attempt create a new state but receive an error if state is empty`, async() => { @@ -51,9 +49,7 @@ describe('Ticket Create new tracking state path', () => { it('should now access to the create state view by clicking the create floating button', async() => { await page.waitToClick(selectors.ticketTracking.createStateButton); - let url = await page.expectURL('tracking/edit'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.tracking.edit'); }); it(`should attemp to create an state for which salesPerson doesn't have permissions`, async() => { diff --git a/e2e/paths/05-ticket/06_basic_data_steps.spec.js b/e2e/paths/05-ticket/06_basic_data_steps.spec.js index de78b9fa7..3191673a5 100644 --- a/e2e/paths/05-ticket/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket/06_basic_data_steps.spec.js @@ -68,9 +68,7 @@ describe('Ticket Edit basic data path', () => { it(`should click next`, async() => { await page.waitToClick(selectors.ticketBasicData.nextStepButton); - let url = await page.expectURL('data/step-two'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.basicData.stepTwo'); }); it(`should have a price diference`, async() => { @@ -83,8 +81,6 @@ describe('Ticket Edit basic data path', () => { 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); - let url = await page.expectURL('summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); }); diff --git a/e2e/paths/05-ticket/09_weekly.spec.js b/e2e/paths/05-ticket/09_weekly.spec.js index 9213afd1d..1629107fb 100644 --- a/e2e/paths/05-ticket/09_weekly.spec.js +++ b/e2e/paths/05-ticket/09_weekly.spec.js @@ -41,9 +41,7 @@ describe('Ticket descriptor path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should confirm the ticket 11 was added to thursday', async() => { @@ -57,16 +55,12 @@ describe('Ticket descriptor path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should now search for the ticket 11', async() => { await page.accessToSearchResult('11'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it('should add the ticket to saturday turn using the descriptor more menu', async() => { @@ -82,9 +76,7 @@ describe('Ticket descriptor path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should confirm the ticket 11 was added on saturday', async() => { diff --git a/e2e/paths/05-ticket/10_request.spec.js b/e2e/paths/05-ticket/10_request.spec.js index 737d69048..2bb0cbb73 100644 --- a/e2e/paths/05-ticket/10_request.spec.js +++ b/e2e/paths/05-ticket/10_request.spec.js @@ -30,13 +30,10 @@ describe('Ticket purchase request path', () => { }); it('should have been redirected to the request index', async() => { - let url = await page.expectURL('/request'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.request.index'); }); it(`should edit the third request quantity as it's state is still new`, async() => { - await page.waitFor(2000); // looks like it needs more than a single second some times to load await page.write(selectors.ticketRequests.thirdRequestQuantity, '9'); await page.keyboard.press('Enter'); const result = await page.waitForLastSnackbar(); diff --git a/e2e/paths/05-ticket/11_diary.spec.js b/e2e/paths/05-ticket/11_diary.spec.js index b529ee1ff..5e900fd25 100644 --- a/e2e/paths/05-ticket/11_diary.spec.js +++ b/e2e/paths/05-ticket/11_diary.spec.js @@ -28,7 +28,7 @@ xdescribe('Ticket diary path', () => { it(`should click on the search result to access to the ticket summary`, async() => { await page.waitForTextInElement(selectors.ticketsIndex.searchResult, 'Bat cave'); await page.waitToClick(selectors.ticketsIndex.searchResult); - let url = await page.expectURL('/summary'); + let url = await page.expectURL('/summary'); // use waitForState instead expect(url).toBe(true); }); @@ -37,7 +37,7 @@ xdescribe('Ticket diary path', () => { await page.waitToClick(selectors.ticketSummary.firstSaleItemId); await page.waitForTransitionEnd('.vn-popover'); await page.waitToClick(selectors.ticketSummary.popoverDiaryButton); - let url = await page.expectURL('/diary'); + let url = await page.expectURL('/diary'); // use waitForState instead expect(url).toBe(true); }); diff --git a/e2e/paths/05-ticket/12_descriptor.spec.js b/e2e/paths/05-ticket/12_descriptor.spec.js index 0302b9c86..ce9f064dd 100644 --- a/e2e/paths/05-ticket/12_descriptor.spec.js +++ b/e2e/paths/05-ticket/12_descriptor.spec.js @@ -18,9 +18,7 @@ describe('Ticket descriptor path', () => { describe('Delete ticket', () => { it('should search for an specific ticket', async() => { await page.accessToSearchResult('18'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should update the shipped hour using the descriptor menu`, async() => { @@ -50,9 +48,7 @@ describe('Ticket descriptor path', () => { }); it('should have been relocated to the ticket index', async() => { - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it(`should search for the deleted ticket and check it's date`, async() => { @@ -68,9 +64,7 @@ describe('Ticket descriptor path', () => { describe('add stowaway', () => { it('should search for a ticket', async() => { await page.accessToSearchResult('16'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it('should open the add stowaway dialog', async() => { @@ -101,9 +95,7 @@ describe('Ticket descriptor path', () => { it(`should navigate back to the added ticket using the descriptors ship button`, async() => { await page.waitToClick(selectors.ticketDescriptor.shipButton); - let url = await page.expectURL('#!/ticket/17/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it('should delete the stowaway', async() => { @@ -127,9 +119,7 @@ describe('Ticket descriptor path', () => { await page.loginAndModule('adminBoss', 'ticket'); await page.accessToSearchResult(invoiceableTicketId); - let url = await page.expectURL(`ticket/${invoiceableTicketId}/summary`); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should make sure the ticket doesn't have an invoiceOutFk yet`, async() => { diff --git a/e2e/paths/05-ticket/14_create_ticket.spec.js b/e2e/paths/05-ticket/14_create_ticket.spec.js index c44125120..176e89930 100644 --- a/e2e/paths/05-ticket/14_create_ticket.spec.js +++ b/e2e/paths/05-ticket/14_create_ticket.spec.js @@ -17,9 +17,7 @@ describe('Ticket create path', () => { it('should open the new ticket form', async() => { await page.waitToClick(selectors.ticketsIndex.newTicketButton); - let url = await page.expectURL('#!/ticket/create'); - - expect(url).toBe(true); + await page.waitForState('ticket.create'); }); it('should succeed to create a ticket', async() => { @@ -38,8 +36,6 @@ describe('Ticket create path', () => { }); it('should check the url is now the summary of the ticket', async() => { - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); }); diff --git a/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js b/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js index 28c11de3a..a68ce894e 100644 --- a/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js +++ b/e2e/paths/05-ticket/15_create_ticket_from_client.spec.js @@ -19,9 +19,7 @@ describe('Ticket create from client path', () => { it('should click the create simple ticket on the descriptor menu', async() => { await page.waitToClick(selectors.clientDescriptor.moreMenu); await page.waitToClick(selectors.clientDescriptor.simpleTicketButton); - let url = await page.expectURL('clientFk=102'); - - expect(url).toBe(true); + await page.waitForState('ticket.create'); }); it('should check if the client details are the expected ones', async() => { @@ -31,7 +29,6 @@ describe('Ticket create from client path', () => { const address = await page .waitToGetProperty(selectors.createTicketView.address, 'value'); - expect(client).toContain('Petter Parker'); expect(address).toContain('20 Ingram Street'); }); diff --git a/e2e/paths/05-ticket/16_summary.spec.js b/e2e/paths/05-ticket/16_summary.spec.js index e7c6507d7..7ead648a2 100644 --- a/e2e/paths/05-ticket/16_summary.spec.js +++ b/e2e/paths/05-ticket/16_summary.spec.js @@ -18,9 +18,7 @@ describe('Ticket Summary path', () => { it('should navigate to the target ticket summary section', async() => { await page.loginAndModule('employee', 'ticket'); await page.accessToSearchResult(ticketId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it(`should display details from the ticket and it's client on the top of the header`, async() => { @@ -75,9 +73,7 @@ describe('Ticket Summary path', () => { it('should log in as production then navigate to the summary of the same ticket', async() => { await page.loginAndModule('production', 'ticket'); await page.accessToSearchResult(ticketId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.summary'); }); it('should click on the SET OK button', async() => { diff --git a/e2e/paths/05-ticket/17_log.spec.js b/e2e/paths/05-ticket/17_log.spec.js index 2008d022e..c677d2e62 100644 --- a/e2e/paths/05-ticket/17_log.spec.js +++ b/e2e/paths/05-ticket/17_log.spec.js @@ -19,9 +19,7 @@ describe('Ticket log path', () => { await page.loginAndModule('employee', 'ticket'); await page.accessToSearchResult(ticketId); await page.accessToSection('ticket.card.observation'); - let url = await page.expectURL('/observation'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.observation'); }); it('should create a new note for the test', async() => { @@ -36,9 +34,7 @@ describe('Ticket log path', () => { it('should navigate to the log section', async() => { await page.accessToSection('ticket.card.log'); - let url = await page.expectURL('/log'); - - expect(url).toBe(true); + await page.waitForState('ticket.card.log'); }); it('should set the viewport width to 1920 to see the table full width', async() => { diff --git a/e2e/paths/06-claim/01_basic_data.spec.js b/e2e/paths/06-claim/01_basic_data.spec.js index 2eb35b078..222cb558b 100644 --- a/e2e/paths/06-claim/01_basic_data.spec.js +++ b/e2e/paths/06-claim/01_basic_data.spec.js @@ -31,9 +31,7 @@ describe('Claim edit basic data path', () => { }); it(`should have been redirected to the next section of claims as the role is salesAssistant`, async() => { - let url = await page.expectURL('/detail'); - - expect(url).toBe(true); + await page.waitForState('claim.card.detail'); }); it('should confirm the claim state was edited', async() => { diff --git a/e2e/paths/06-claim/02_development.spec.js b/e2e/paths/06-claim/02_development.spec.js index 346f88581..970a801ee 100644 --- a/e2e/paths/06-claim/02_development.spec.js +++ b/e2e/paths/06-claim/02_development.spec.js @@ -32,9 +32,7 @@ describe('Claim development', () => { }); it(`should redirect to the next section of claims as the role is salesAssistant`, async() => { - let url = await page.expectURL('/action'); - - expect(url).toBe(true); + await page.waitForState('claim.card.action'); }); it('should edit a development', async() => { diff --git a/e2e/paths/06-claim/03_detail.spec.js b/e2e/paths/06-claim/03_detail.spec.js index cf758919e..93d2cba4c 100644 --- a/e2e/paths/06-claim/03_detail.spec.js +++ b/e2e/paths/06-claim/03_detail.spec.js @@ -56,7 +56,7 @@ xdescribe('Claim detail', () => { await page.loginAndModule('salesAssistant', 'claim'); await page.accessToSearchResult('1'); await page.accessToSection('claim.card.detail'); - let url = await page.expectURL('/detail'); + let url = await page.expectURL('/detail'); // replace with waitForState expect(url).toBe(true); }); @@ -99,7 +99,7 @@ xdescribe('Claim detail', () => { }); it(`should have been redirected to the next section in claims`, async() => { - let url = await page.expectURL('development'); + let url = await page.expectURL('development'); // replace with waitForState expect(url).toBe(true); }); diff --git a/e2e/paths/06-claim/05_summary.spec.js b/e2e/paths/06-claim/05_summary.spec.js index 9dab65954..c63e686cb 100644 --- a/e2e/paths/06-claim/05_summary.spec.js +++ b/e2e/paths/06-claim/05_summary.spec.js @@ -18,9 +18,7 @@ describe('claim Summary path', () => { it('should navigate to the target claim summary section', async() => { await page.loginAndModule('employee', 'claim'); await page.accessToSearchResult(claimId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('claim.card.summary'); }); it(`should display details from the claim and it's client on the top of the header`, async() => { diff --git a/e2e/paths/06-claim/06_descriptor.spec.js b/e2e/paths/06-claim/06_descriptor.spec.js index 104f63945..ee49fe245 100644 --- a/e2e/paths/06-claim/06_descriptor.spec.js +++ b/e2e/paths/06-claim/06_descriptor.spec.js @@ -18,9 +18,7 @@ describe('claim Descriptor path', () => { it('should now navigate to the target claim summary section', async() => { await page.loginAndModule('employee', 'claim'); await page.accessToSearchResult(claimId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('claim.card.summary'); }); it(`should not be able to see the delete claim button of the descriptor more menu`, async() => { @@ -31,9 +29,7 @@ describe('claim Descriptor path', () => { it(`should log in as salesAssistant and navigate to the target claim`, async() => { await page.loginAndModule('salesAssistant', 'claim'); await page.accessToSearchResult(claimId); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('claim.card.summary'); }); it(`should be able to see the delete claim button of the descriptor more menu`, async() => { @@ -50,9 +46,7 @@ describe('claim Descriptor path', () => { }); it(`should have been relocated to the claim index`, async() => { - let url = await page.expectURL('/claim/index'); - - expect(url).toBe(true); + await page.waitForState('claim.index'); }); it(`should search for the deleted claim to find no results`, async() => { diff --git a/e2e/paths/07-order/01_summary.spec.js b/e2e/paths/07-order/01_summary.spec.js index cba56bf70..f4bc44827 100644 --- a/e2e/paths/07-order/01_summary.spec.js +++ b/e2e/paths/07-order/01_summary.spec.js @@ -16,9 +16,7 @@ describe('Order summary path', () => { }); it('should reach the order summary section', async() => { - const url = await page.expectURL('#!/order/16/summary'); - - expect(url).toBe(true); + await page.waitForState('order.card.summary'); }); it('should check the summary contains the order id', async() => { diff --git a/e2e/paths/07-order/02_basic_data.spec.js b/e2e/paths/07-order/02_basic_data.spec.js index 733ccaa1a..d7bd01208 100644 --- a/e2e/paths/07-order/02_basic_data.spec.js +++ b/e2e/paths/07-order/02_basic_data.spec.js @@ -39,9 +39,7 @@ describe('Order edit basic data path', () => { await page.accessToSearchResult(orderId); await page.accessToSection('order.card.basicData'); await page.waitForSelector(selectors.orderBasicData.observation, {visible: true}); - let url = await page.expectURL(`#!/order/${orderId}/basic-data`); - - expect(url).toBe(true); + await page.waitForState('order.card.basicData'); }); it('should not be able to change anything', async() => { @@ -59,9 +57,7 @@ describe('Order edit basic data path', () => { await page.waitToClick(selectors.orderBasicData.acceptButton); await page.waitForContentLoaded(); await page.waitToClick(selectors.ordersIndex.createOrderButton); - let url = await page.expectURL('#!/order/create'); - - expect(url).toBe(true); + await page.waitForState('order.create'); }); it('should now create a new one', async() => { @@ -69,16 +65,12 @@ describe('Order edit basic data path', () => { await page.pickDate(selectors.createOrderView.landedDatePicker); await page.autocompleteSearch(selectors.createOrderView.agency, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); - let url = await page.expectURL('/catalog'); - - expect(url).toBe(true); + await page.waitForState('order.card.catalog'); }); it('should navigate to the basic data section of the new order', async() => { await page.accessToSection('order.card.basicData'); - let url = await page.expectURL('/basic-data'); - - expect(url).toBe(true); + await page.waitForState('order.card.basicData'); }); it('should be able to modify all the properties', async() => { diff --git a/e2e/paths/07-order/03_lines.spec.js b/e2e/paths/07-order/03_lines.spec.js index 21fceac44..450e1b9c9 100644 --- a/e2e/paths/07-order/03_lines.spec.js +++ b/e2e/paths/07-order/03_lines.spec.js @@ -41,10 +41,7 @@ describe('Order lines', () => { it('should confirm the whole order and redirect to ticket index filtered by clientFk', async() => { await page.waitToClick(selectors.orderLine.confirmOrder); - let hashPartOne = await page.expectURL('ticket/index'); - let hashPartTwo = await page.expectURL('clientFk'); - - expect(hashPartOne).toBe(true); - expect(hashPartTwo).toBe(true); + await page.expectURL('ticket/index'); + await page.expectURL('clientFk'); }); }); diff --git a/e2e/paths/07-order/04_catalog.spec.js b/e2e/paths/07-order/04_catalog.spec.js index 8c3106f6c..0db313088 100644 --- a/e2e/paths/07-order/04_catalog.spec.js +++ b/e2e/paths/07-order/04_catalog.spec.js @@ -17,9 +17,7 @@ describe('Order catalog', () => { it('should open the create new order form', async() => { await page.waitToClick(selectors.ordersIndex.createOrderButton); - let url = await page.expectURL('order/create'); - - expect(url).toBe(true); + await page.waitForState('order.create'); }); it('should create a new order', async() => { @@ -27,9 +25,7 @@ describe('Order catalog', () => { await page.pickDate(selectors.createOrderView.landedDatePicker); await page.autocompleteSearch(selectors.createOrderView.agency, 'Other agency'); await page.waitToClick(selectors.createOrderView.createButton); - let url = await page.expectURL('/catalog'); - - expect(url).toBe(true); + await page.waitForState('order.card.catalog'); }); it('should add the realm and type filters and obtain results', async() => { diff --git a/e2e/paths/08-route/01_summary.spec.js b/e2e/paths/08-route/01_summary.spec.js index c062b9b08..02cc71f2f 100644 --- a/e2e/paths/08-route/01_summary.spec.js +++ b/e2e/paths/08-route/01_summary.spec.js @@ -17,9 +17,7 @@ describe('Route summary path', () => { }); it('should reach the first route summary section', async() => { - let url = await page.expectURL('#!/route/1/summary'); - - expect(url).toBe(true); + await page.waitForState('route.card.summary'); }); it(`should display details from the route on the header`, async() => { diff --git a/e2e/paths/08-route/03_create.spec.js b/e2e/paths/08-route/03_create.spec.js index c929e647f..dafccff7f 100644 --- a/e2e/paths/08-route/03_create.spec.js +++ b/e2e/paths/08-route/03_create.spec.js @@ -19,9 +19,7 @@ describe('Route create path', () => { it('should click on the add new route button and open the creation form', async() => { await page.waitForContentLoaded(); await page.waitToClick(selectors.routeIndex.addNewRouteButton); - let url = await page.expectURL('#!/route/create'); - - expect(url).toBe(true); + await page.waitForState('route.create'); }); it(`should attempt to create a new route but fail since employee has no access rights`, async() => { @@ -41,9 +39,7 @@ describe('Route create path', () => { it('should again click on the add new route button and open the creation form', async() => { await page.waitToClick(selectors.routeIndex.addNewRouteButton); - let url = await page.expectURL('#!/route/create'); - - expect(url).toBe(true); + await page.waitForState('route.create'); }); it(`should create a new route`, async() => { @@ -59,9 +55,7 @@ describe('Route create path', () => { }); it(`should confirm the redirection to the created route summary`, async() => { - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('route.card.summary'); }); }); }); diff --git a/e2e/paths/09-invoice-out/01_summary.spec.js b/e2e/paths/09-invoice-out/01_summary.spec.js index 126c745d3..728f0130a 100644 --- a/e2e/paths/09-invoice-out/01_summary.spec.js +++ b/e2e/paths/09-invoice-out/01_summary.spec.js @@ -17,9 +17,7 @@ describe('InvoiceOut summary path', () => { }); it('should reach the summary section', async() => { - const result = await page.expectURL('/summary'); - - expect(result).toBe(true); + await page.waitForState('invoiceOut.card.summary'); }); it('should contain the company from which the invoice is emited', async() => { diff --git a/e2e/paths/09-invoice-out/02_descriptor.spec.js b/e2e/paths/09-invoice-out/02_descriptor.spec.js index 1290b9a88..ceb2175e2 100644 --- a/e2e/paths/09-invoice-out/02_descriptor.spec.js +++ b/e2e/paths/09-invoice-out/02_descriptor.spec.js @@ -20,9 +20,7 @@ describe('InvoiceOut descriptor path', () => { await page.waitToClick(selectors.ticketsIndex.openAdvancedSearchButton); await page.write(selectors.ticketsIndex.advancedSearchInvoiceOut, 'T2222222'); await page.waitToClick(selectors.ticketsIndex.advancedSearchButton); - let url = await page.expectURL('#!/ticket/3/summary'); - - expect(url).toEqual(true); + await page.waitForState('ticket.card.summary'); }); it('should navigate to the invoiceOut index', async() => { @@ -30,16 +28,12 @@ describe('InvoiceOut descriptor path', () => { await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.invoiceOutButton); await page.wait(selectors.invoiceOutIndex.topbarSearch); - let url = await page.expectURL('#!/invoice-out/index'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.index'); }); it(`should click on the search result to access to the invoiceOut summary`, async() => { await page.accessToSearchResult('T2222222'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.card.summary'); }); it('should delete the invoiceOut using the descriptor more menu', async() => { @@ -52,9 +46,7 @@ describe('InvoiceOut descriptor path', () => { }); it('should have been relocated to the invoiceOut index', async() => { - let url = await page.expectURL('#!/invoice-out/index'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.index'); }); it(`should search for the deleted invouceOut to find no results`, async() => { @@ -70,13 +62,10 @@ describe('InvoiceOut descriptor path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.ticketsButton); - let url = await page.expectURL('#!/ticket/index'); - - expect(url).toBe(true); + await page.waitForState('ticket.index'); }); it('should search for tickets with an specific invoiceOut to find no results', async() => { - await page.waitFor(2000); await page.waitToClick(selectors.ticketsIndex.openAdvancedSearchButton); await page.write(selectors.ticketsIndex.advancedSearchInvoiceOut, 'T2222222'); await page.waitToClick(selectors.ticketsIndex.advancedSearchButton); @@ -91,16 +80,12 @@ describe('InvoiceOut descriptor path', () => { await page.waitToClick(selectors.globalItems.applicationsMenuButton); await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.invoiceOutButton); - let url = await page.expectURL('#!/invoice-out/index'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.index'); }); it(`should search and access to the invoiceOut summary`, async() => { await page.accessToSearchResult('T1111111'); - let url = await page.expectURL('/summary'); - - expect(url).toBe(true); + await page.waitForState('invoiceOut.card.summary'); }); it(`should check the invoiceOut is booked in the summary data`, async() => { diff --git a/e2e/paths/10-travel/01_thermograph.spec.js b/e2e/paths/10-travel/01_thermograph.spec.js index efa2295a6..67a62381a 100644 --- a/e2e/paths/10-travel/01_thermograph.spec.js +++ b/e2e/paths/10-travel/01_thermograph.spec.js @@ -18,16 +18,12 @@ describe('Travel thermograph path', () => { }); it('should reach the thermograph section', async() => { - const result = await page.expectURL('/thermograph/index'); - - expect(result).toBe(true); + await page.waitForState('travel.card.thermograph.index'); }); it('should click the add thermograph floating button', async() => { await page.waitToClick(selectors.travelThermograph.add); - const result = await page.expectURL('/thermograph/create'); - - expect(result).toBe(true); + await page.waitForState('travel.card.thermograph.create'); }); it('should select the thermograph and then the file to upload', async() => { diff --git a/e2e/paths/10-travel/02_basic_data_and_log.spec.js b/e2e/paths/10-travel/02_basic_data_and_log.spec.js index c6287a8a0..85c7231c8 100644 --- a/e2e/paths/10-travel/02_basic_data_and_log.spec.js +++ b/e2e/paths/10-travel/02_basic_data_and_log.spec.js @@ -18,9 +18,7 @@ describe('Travel basic data path', () => { }); it('should reach the thermograph section', async() => { - const result = await page.expectURL('/basic-data'); - - expect(result).toBe(true); + await page.waitForState('travel.card.basicData'); }); it('should set a wrong delivery date then receive an error on submit', async() => { @@ -92,9 +90,7 @@ describe('Travel basic data path', () => { it('should navigate to the travel logs', async() => { await page.accessToSection('travel.card.log'); - const result = await page.expectURL('/log'); - - expect(result).toBe(true); + await page.waitForState('travel.card.log'); }); it('should check the 1st log contains details from the changes made', async() => { diff --git a/e2e/paths/11-zone/01_basic-data.spec.js b/e2e/paths/11-zone/01_basic-data.spec.js index 41b3782aa..7044ab70c 100644 --- a/e2e/paths/11-zone/01_basic-data.spec.js +++ b/e2e/paths/11-zone/01_basic-data.spec.js @@ -18,9 +18,7 @@ describe('Zone basic data path', () => { }); it('should reach the basic data section', async() => { - let url = await page.expectURL('#!/zone/10/basic-data'); - - expect(url).toBe(true); + await page.waitForState('zone.card.basicData'); }); it('should edit de form and then save', async() => { diff --git a/e2e/paths/12-entry/01_summary.spec.js b/e2e/paths/12-entry/01_summary.spec.js index 39b12b840..e57654f94 100644 --- a/e2e/paths/12-entry/01_summary.spec.js +++ b/e2e/paths/12-entry/01_summary.spec.js @@ -17,9 +17,7 @@ describe('Entry summary path', () => { }); it('should reach the second entry summary section', async() => { - let url = await page.expectURL('#!/entry/2/summary'); - - expect(url).toBe(true); + await page.waitForState('entry.card.summary'); }); it(`should display details from the entry on the header`, async() => { diff --git a/e2e/paths/12-entry/02_descriptor.spec.js b/e2e/paths/12-entry/02_descriptor.spec.js index 8fa0d2a4f..699d00517 100644 --- a/e2e/paths/12-entry/02_descriptor.spec.js +++ b/e2e/paths/12-entry/02_descriptor.spec.js @@ -17,9 +17,7 @@ describe('Entry descriptor path', () => { }); it('should reach the second entry summary section', async() => { - let url = await page.expectURL('#!/entry/2/summary'); - - expect(url).toBe(true); + await page.waitForState('entry.card.summary'); }); it('should show some entry information', async() => { @@ -30,32 +28,22 @@ describe('Entry descriptor path', () => { it('should click the travels button to be redirected to the travels index filtered by the current agency', async() => { await page.waitToClick(selectors.entryDescriptor.travelsQuicklink); - const url = await page.expectURL('/travel/index'); - const filter = await page.expectURL('agencyFk'); - - expect(url).toBe(true); - expect(filter).toBe(true); + await page.expectURL('/travel/index'); + await page.expectURL('agencyFk'); }); it('should go back to the entry summary', async() => { await page.waitToClick(selectors.globalItems.homeButton); await page.selectModule('entry'); await page.accessToSearchResult('2'); - let url = await page.expectURL('#!/entry/2/summary'); - - expect(url).toBe(true); + await page.waitForState('entry.card.summary'); }); it('should click the entries button to be redirected to the entries index filtered by the current supplier', async() => { await page.waitToClick(selectors.entryDescriptor.entriesQuicklink); - const url = await page.expectURL('/entry/index'); - const supplierFilter = await page.expectURL('supplierFk'); - const toFilter = await page.expectURL('to'); - const fromFilter = await page.expectURL('from'); - - expect(url).toBe(true); - expect(supplierFilter).toBe(true); - expect(toFilter).toBe(true); - expect(fromFilter).toBe(true); + await page.expectURL('/entry/index'); + await page.expectURL('supplierFk'); + await page.expectURL('to'); + await page.expectURL('from'); }); }); From 3283f957bac2a67a15de462f4099cfa0296f1ec9 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 24 Mar 2020 16:51:21 +0100 Subject: [PATCH 25/44] corrected a typo --- e2e/paths/02-client/01_create_client.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js index 29a27884f..0b8c96c16 100644 --- a/e2e/paths/02-client/01_create_client.spec.js +++ b/e2e/paths/02-client/01_create_client.spec.js @@ -102,7 +102,7 @@ describe('Client create path', async() => { await page.wait(selectors.globalItems.applicationsMenuVisible); await page.waitToClick(selectors.globalItems.clientsButton); await page.wait(selectors.clientsIndex.createClientButton); - await page.waitForState('lient.index'); + await page.waitForState('client.index'); }); it(`should search for the user Carol Danvers to confirm it exists`, async() => { From 12c2b577e683a6c36701f042e26d9a14cebeeaec Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 24 Mar 2020 17:01:11 +0100 Subject: [PATCH 26/44] minor refactor --- modules/order/front/card/index.js | 2 +- modules/order/front/line/index.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/order/front/card/index.js b/modules/order/front/card/index.js index e79167761..80fa99d1d 100644 --- a/modules/order/front/card/index.js +++ b/modules/order/front/card/index.js @@ -47,7 +47,7 @@ class Controller extends ModuleCard { ] }; - this.$q.all([ + return this.$q.all([ this.$http.get(`Orders/${this.$params.id}`, {filter}) .then(res => this.order = res.data), this.$http.get(`Orders/${this.$params.id}/getTotal`) diff --git a/modules/order/front/line/index.js b/modules/order/front/line/index.js index 149251c87..9351c5df8 100644 --- a/modules/order/front/line/index.js +++ b/modules/order/front/line/index.js @@ -43,10 +43,9 @@ class Controller extends Section { rows: [row.id], actualOrderId: this.$params.id }; - return this.$http.post(`OrderRows/removes`, params).then(() => { - this.card.reload(); - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + return this.$http.post(`OrderRows/removes`, params) + .then(() => this.card.reload()) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } showDescriptor(event, itemFk) { From 8eb6590285ae9d592d624d3f0a54e8d84f91c3de Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 24 Mar 2020 17:27:21 +0100 Subject: [PATCH 27/44] E2E fixes --- e2e/helpers/extensions.js | 11 ++++++++-- e2e/helpers/puppeteer.js | 2 +- e2e/helpers/selectors.js | 1 - e2e/paths/04-item/13_request.spec.js | 5 ++--- modules/item/front/request/index.html | 7 +++--- modules/item/front/request/index.js | 27 ++++++++++++------------ modules/item/front/request/index.spec.js | 21 +++++++++--------- 7 files changed, 40 insertions(+), 34 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 1ff0119fd..a7f4cc42c 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -545,7 +545,7 @@ let actions = { return dialogs.length; }, response); - this.waitForFunction(firstCount => { + await this.waitForFunction(firstCount => { const dialogs = document.querySelectorAll('.vn-dialog'); return dialogs.length < firstCount; }, {}, firstCount); @@ -559,7 +559,14 @@ let actions = { export function extendPage(page) { for (let name in actions) { page[name] = async(...args) => { - return await actions[name].call(page, ...args); + try { + return await actions[name].apply(page, args); + } catch (err) { + let stringArgs = args + .map(i => typeof i == 'function' ? 'Function' : i) + .join(', '); + throw new Error(`.${name}(${stringArgs}): ${err.message}`); + } }; } diff --git a/e2e/helpers/puppeteer.js b/e2e/helpers/puppeteer.js index 1ea3c1c90..67f9da427 100644 --- a/e2e/helpers/puppeteer.js +++ b/e2e/helpers/puppeteer.js @@ -12,7 +12,7 @@ export async function getBrowser() { if (process.env.DEBUG) args.push('--auto-open-devtools-for-tabs'); - const headless = !process.env.E2E_SHOW; + const headless = !(process.env.E2E_SHOW || process.env.DEBUG); const browser = await Puppeteer.launch({ args, defaultViewport: null, diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 88f7cb40d..5469c09df 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -260,7 +260,6 @@ export default { secondRequestDecline: 'vn-item-request vn-tbody > vn-tr:nth-child(1) vn-icon-button[icon="thumb_down"]', declineReason: 'vn-textarea[ng-model="$ctrl.denyObservation"]', acceptDeclineReason: 'button[response="accept"]', - }, itemBasicData: { basicDataButton: 'vn-left-menu a[ui-sref="item.card.basicData"]', diff --git a/e2e/paths/04-item/13_request.spec.js b/e2e/paths/04-item/13_request.spec.js index d6aecbb48..aa4a57bc0 100644 --- a/e2e/paths/04-item/13_request.spec.js +++ b/e2e/paths/04-item/13_request.spec.js @@ -38,9 +38,8 @@ describe('Item request path', () => { it('should now click on the second declain request icon then type the reason', async() => { await page.waitToClick(selectors.itemRequest.secondRequestDecline); - await page.write(selectors.itemRequest.declineReason, 'not quite as expected'); - await page.waitToClick(selectors.itemRequest.acceptDeclineReason); - await page.waitForContentLoaded(); + await page.write(selectors.itemRequest.declineReason, 'Not quite as expected'); + await page.respondToDialog('accept'); let status = await page.waitToGetProperty(selectors.itemRequest.firstRequestStatus, 'innerText'); expect(status).toContain('Denegada'); diff --git a/modules/item/front/request/index.html b/modules/item/front/request/index.html index 20da8946d..0516e7ff5 100644 --- a/modules/item/front/request/index.html +++ b/modules/item/front/request/index.html @@ -91,7 +91,7 @@ @@ -111,8 +111,9 @@ vn-id="itemDescriptor"> + vn-id="deny-dialog" + on-accept="$ctrl.onDenyAccept($data)" + on-close="$ctrl.onDenyClose()">
Specify the reasons to deny this request
diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index 3684a1911..51035c468 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Section from 'salix/components/section'; import './style.scss'; -export default class Controller extends Component { +export default class Controller extends Section { constructor($element, $) { super($element, $); @@ -33,7 +33,7 @@ export default class Controller extends Component { getState(isOk) { if (isOk === null) return 'Nueva'; - else if (isOk === -1 || isOk) + else if (isOk) return 'Aceptada'; else return 'Denegada'; @@ -102,25 +102,26 @@ export default class Controller extends Component { delete this.denyRequestId; } - denyRequest(response) { - if (response !== 'accept') return; - + onDenyAccept(request) { let params = { observation: this.denyObservation }; - let query = `TicketRequests/${this.selectedRequest.id}/deny`; - this.$http.post(query, params).then(res => { - const request = res.data; - this.selectedRequest.isOk = request.isOk; - this.selectedRequest.attenderFk = request.attenderFk; - this.selectedRequest.response = request.response; + let query = `TicketRequests/${request.id}/deny`; + return this.$http.post(query, params).then(res => { + const newRequest = res.data; + request.isOk = newRequest.isOk; + request.attenderFk = newRequest.attenderFk; + request.response = newRequest.response; this.vnApp.showSuccess(this.$t('Data saved!')); - this.denyObservation = null; }); } + onDenyClose() { + this.denyObservation = null; + } + showTicketDescriptor(event, ticketFk) { this.$.ticketDescriptor.ticketFk = ticketFk; this.$.ticketDescriptor.parent = event.target; diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index aaaade566..c988627ea 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -84,7 +84,6 @@ describe('Item', () => { let request = {saleFk: 1, saleQuantity: 1}; jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond(); $httpBackend.expect('PATCH', `Sales/${request.saleFk}/`).respond(); controller.changeQuantity(request); @@ -112,20 +111,20 @@ describe('Item', () => { }); }); - describe('denyRequest()', () => { - it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => { - jest.spyOn(controller.vnApp, 'showSuccess'); + describe('onDenyAccept()', () => { + it(`should deny the request`, () => { + const request = { + id: 1, + response: 'new' + }; - const request = {id: 1}; - const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'}; - controller.selectedRequest = request; + const url = `TicketRequests/:id/deny`; + $httpBackend.expectRoute('POST', url).respond({response: 'denied'}); - $httpBackend.when('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult); - $httpBackend.expect('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult); - controller.denyRequest('accept'); + controller.onDenyAccept(request); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(request.response).toBe('denied'); }); }); }); From a30a4bf961e59b25c6cab4bc01e528716275c4f8 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 24 Mar 2020 17:32:30 +0100 Subject: [PATCH 28/44] quitado el campo provincia --- .../10170-NOFallas/00-zone_getEvents.sql | 115 ++++++++++++++++++ modules/worker/front/dms/index/locale/es.yml | 12 +- modules/worker/front/locale/es.yml | 33 +++-- modules/zone/back/methods/zone/getEvents.js | 15 +-- modules/zone/front/delivery-days/index.html | 39 +++--- modules/zone/front/delivery-days/index.js | 19 +++ modules/zone/front/locale/es.yml | 54 ++++---- 7 files changed, 215 insertions(+), 72 deletions(-) create mode 100644 db/changes/10170-NOFallas/00-zone_getEvents.sql diff --git a/db/changes/10170-NOFallas/00-zone_getEvents.sql b/db/changes/10170-NOFallas/00-zone_getEvents.sql new file mode 100644 index 000000000..5911abdc3 --- /dev/null +++ b/db/changes/10170-NOFallas/00-zone_getEvents.sql @@ -0,0 +1,115 @@ +USE `vn`; +DROP procedure IF EXISTS `zone_getEvents`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents`( + vGeoFk INT, + vDeliveryMethodFk VARCHAR(255), + vAgencyModeFk INT) +BEGIN +/** + * Returns available events for the passed province/postcode and agency. + * + * @param vGeoFk The geo id + * @param vAgencyModeFk The agency mode id + */ + DROP TEMPORARY TABLE IF EXISTS tmp.auxZone; + + CREATE TEMPORARY TABLE tmp.auxZone + (id INT(11) PRIMARY KEY) + ENGINE = MEMORY; + + IF vDeliveryMethodFk = 'pickUp' THEN + INSERT INTO tmp.auxZone + SELECT id + FROM zone + WHERE agencyModeFk = vAgencyModeFk; + ELSE + CALL zone_getFromGeo(vGeoFk); + + IF vAgencyModeFk IS NOT NULL THEN + INSERT INTO tmp.auxZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + WHERE z.agencyModeFk = vAgencyModeFk; + ELSE + INSERT INTO tmp.auxZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.`code` IN ('AGENCY', 'DELIVERY'); + END IF; + DROP TEMPORARY TABLE tmp.zone; + END IF; + + SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays + FROM tmp.auxZone t + JOIN zoneEvent e ON e.zoneFk = t.id; + + SELECT e.zoneFk, e.dated + FROM tmp.auxZone t + JOIN zoneExclusion e ON e.zoneFk = t.id; + + DROP TEMPORARY TABLE IF EXISTS tmp.auxZone; + +END$$ + +DELIMITER ; + +USE `vn`; +DROP procedure IF EXISTS `zone_getEvents__`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents__`( + vProvinceFk INT, + vPostCode VARCHAR(255), + vAgencyModeFk INT) +BEGIN +/** + * Returns available events for the passed province/postcode and agency. + * + * @param vAgencyModeFk The agency mode id + * @param vProvinceFk The province id + * @param vPostCode The postcode or %NULL to use the province + */ + + DECLARE vGeoFk INT; + + IF vPostCode IS NOT NULL THEN + SELECT p.geoFk INTO vGeoFk + FROM postCode p + JOIN town t ON t.id = p.townFk + WHERE p.`code` = vPostCode + AND t.provinceFk = vProvinceFk; + ELSE + SELECT geoFk INTO vGeoFk + FROM province + WHERE id = vProvinceFk; + END IF; + + CALL zone_getFromGeo(vGeoFk); + + IF vAgencyModeFk IS NOT NULL THEN + DELETE t FROM tmp.zone t + JOIN zone z ON z.id = t.id + WHERE z.agencyModeFk != vAgencyModeFk; + END IF; + + SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays + FROM tmp.zone t + JOIN zoneEvent e ON e.zoneFk = t.id; + + SELECT e.zoneFk, e.dated + FROM tmp.zone t + JOIN zoneExclusion e ON e.zoneFk = t.id; + + DROP TEMPORARY TABLE tmp.zone; +END$$ + +DELIMITER ; + diff --git a/modules/worker/front/dms/index/locale/es.yml b/modules/worker/front/dms/index/locale/es.yml index 0994c7d86..b6feb4206 100644 --- a/modules/worker/front/dms/index/locale/es.yml +++ b/modules/worker/front/dms/index/locale/es.yml @@ -1,9 +1,9 @@ -Type: Tipo -File management: Gestión documental -File: Fichero -Hard copy: Copia -This file will be deleted: Este fichero va a ser borrado Are you sure?: Estas seguro? +Download file: Descargar fichero +File: Fichero File deleted: Fichero eliminado +Hard copy: Copia +My documentation: Mi documentacion Remove file: Eliminar fichero -Download file: Descargar fichero \ No newline at end of file +This file will be deleted: Este fichero va a ser borrado +Type: Tipo \ No newline at end of file diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index 3fa727801..172844aa3 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -1,20 +1,19 @@ -Workers: Trabajadores -Last name: Apellidos -User data: Datos de usuario -Fiscal identifier: NIF -Email: E-mail -Department: Departamento -User id: Id de usuario -Role: Rol -Extension: Extensión -Go to client: Ir al cliente -Private Branch Exchange: Centralita -View worker: Ver trabajador -Worker id: Id trabajador -Fiscal Identifier: NIF -User name: Usuario -Departments: Departamentos Calendar: Calendario +Data saved! User must access web: ¡Datos guardados! El usuario deberá acceder con su contraseña a la web para que los cambios surtan efecto. +Department: Departamento +Departments: Departamentos +Email: E-mail +Extension: Extensión +Fiscal identifier: NIF +Go to client: Ir al cliente +Last name: Apellidos +Private Branch Exchange: Centralita +Role: Rol Search workers by id, firstName, lastName or user name: Buscar trabajadores por el identificador, nombre, apellidos o nombre de usuario Time control: Control de horario -Data saved! User must access web: ¡Datos guardados! El usuario deberá acceder con su contraseña a la web para que los cambios surtan efecto. +User data: Datos de usuario +User name: Usuario +User id: Id de usuario +View worker: Ver trabajador +Worker id: Id trabajador +Workers: Trabajadores diff --git a/modules/zone/back/methods/zone/getEvents.js b/modules/zone/back/methods/zone/getEvents.js index abf3d7e19..2555fec83 100644 --- a/modules/zone/back/methods/zone/getEvents.js +++ b/modules/zone/back/methods/zone/getEvents.js @@ -4,19 +4,20 @@ module.exports = Self => { description: 'Returns delivery days for a postcode', accepts: [ { - arg: 'provinceFk', + arg: 'geoFk', type: 'Number', - description: 'The province id', - required: true + description: 'The geo id' }, { - arg: 'postCode', + arg: 'deliveryMethodFk', type: 'String', - description: 'The postcode' + description: 'The delivery Method code', + required: true }, { arg: 'agencyModeFk', type: 'Number', description: 'The agency mode id' } + ], returns: { type: 'Object', @@ -28,10 +29,10 @@ module.exports = Self => { } }); - Self.getEvents = async(provinceFk, postCode, agencyModeFk) => { + Self.getEvents = async(geoFk, deliveryMethodFk, agencyModeFk) => { let [events, exclusions] = await Self.rawSql( `CALL zone_getEvents(?, ?, ?)`, - [provinceFk, postCode, agencyModeFk] + [geoFk, deliveryMethodFk, agencyModeFk] ); return {events, exclusions}; }; diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 589208caf..28e2c565a 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -6,28 +6,35 @@ - + + + + + -
{{name}}
-
- {{country.country}} -
+ {{code}} - {{town.name}} ({{town.province.name}}, + {{town.province.country.country}})
- - + url="AgencyModes/isActive" + where="$ctrl.agencyFilter"> diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 006252a69..c433f525a 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -5,6 +5,7 @@ import './style.scss'; class Controller extends Section { $onInit() { this.$.params = {}; + this.$.params.deliveryMethodFk = 'delivery'; } onSubmit() { @@ -18,6 +19,24 @@ class Controller extends Section { }); } + get deliveryMethodFk() { + return this._deliveryMethod; + } + + set deliveryMethodFk(value) { + this._deliveryMethod = value; + let filter; + if (value === 'pickUp') + filter = {where: {code: 'PICKUP'}}; + else + filter = {where: {code: {neq: 'PICKUP'}}}; + let json = encodeURIComponent(JSON.stringify(filter)); + this.$http.get(`DeliveryMethods?filter=${json}`).then(json => { + let deliveryMethods = json.data.map(deliveryMethod => deliveryMethod.id); + this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}}; + }); + } + onSelection($event, $events) { if (!$events.length) return; diff --git a/modules/zone/front/locale/es.yml b/modules/zone/front/locale/es.yml index 852703576..d525491e2 100644 --- a/modules/zone/front/locale/es.yml +++ b/modules/zone/front/locale/es.yml @@ -1,29 +1,31 @@ Agency: Agencia +Are you sure you want to delete this zone?: ¿Seguro de que quieres eliminar esta zona? +Clone: Clonar +Exceptions: Excepciones +Closing: Cierre +Delivery days: Días de entrega +Delivery: Entrega +Everyday: Todos los días +Exclusions: Exclusiones +From: Desde +Hour: Hora +Indefinitely: Indefinido +Inflation: Inflación +Locations: Localizaciones +Maximum m³: M³ máximo +New zone: Nueva zona +One day: Un día +Pick up: Recogida +Postcode: Código postal +Price: Precio +Query: Consultar +Province: Provincia +Range of dates: Rango de fechas +Search zone by id or name: Buscar zonas por identificador o nombre +This zone will be removed: La zona será eliminada +To: Hasta +Volumetric: Volumétrico +Warehouse: Almacén Warehouses: Almacenes Week days: Días de la semana -Exceptions: Excepciones -Exclusions: Exclusiones -Warehouse: Almacén -Hour: Hora -Price: Precio -Locations: Localizaciones -This zone will be removed: La zona será eliminada -Are you sure you want to delete this zone?: ¿Seguro de que quieres eliminar esta zona? -Zones: Zonas -New zone: Nueva zona -Volumetric: Volumétrico -Clone: Clonar -Search zone by id or name: Buscar zonas por identificador o nombre -From: Desde -To: Hasta -Closing: Cierre -One day: Un día -Range of dates: Rango de fechas -Indefinitely: Indefinido -Everyday: Todos los días -Delivery days: Días de entrega -Province: Provincia -Postcode: Código postal -Inflation: Inflación -Query: Consultar -Maximum m³: M³ máximo \ No newline at end of file +Zones: Zonas \ No newline at end of file From dcdae825d273ea10d143624f6d07b7d8030ea87f Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 25 Mar 2020 08:43:49 +0100 Subject: [PATCH 29/44] fixex pull request --- modules/worker/front/worker-log/index.html | 2 +- modules/worker/front/worker-log/index.js | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/modules/worker/front/worker-log/index.html b/modules/worker/front/worker-log/index.html index b38a456cb..090dbf2e3 100644 --- a/modules/worker/front/worker-log/index.html +++ b/modules/worker/front/worker-log/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/modules/worker/front/worker-log/index.js b/modules/worker/front/worker-log/index.js index bd1e987c9..1f1a4f2f8 100644 --- a/modules/worker/front/worker-log/index.js +++ b/modules/worker/front/worker-log/index.js @@ -1,15 +1,7 @@ import ngModule from '../module'; - -class Controller { - constructor($scope, $stateParams) { - this.$scope = $scope; - this.$stateParams = $stateParams; - } -} - -Controller.$inject = ['$scope', '$stateParams']; +import Section from 'salix/components/section'; ngModule.component('vnWorkerLog', { template: require('./index.html'), - controller: Controller, + controller: Section, }); From 61c85cfb9e1364cf1b60cb627eb37c955db8c232 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 09:20:26 +0100 Subject: [PATCH 30/44] Updated tests --- modules/order/front/catalog/index.html | 10 +++- modules/order/front/catalog/index.js | 60 ++++++++++++++++------- modules/order/front/catalog/index.spec.js | 22 +++++++-- modules/order/front/routes.json | 2 +- 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 7131d6a6e..0349c1358 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -11,6 +11,12 @@ limit="50" data="$ctrl.items"> + + + + + @@ -77,13 +83,13 @@ - - + --> { - if (this.$stateParams.itemId) - this.itemId = parseInt(this.$stateParams.itemId); + if (this.$params.categoryId) + this.categoryId = parseInt(this.$params.categoryId); - if (this.$stateParams.categoryId) - this.categoryId = parseInt(this.$stateParams.categoryId); + if (this.$params.typeId) + this.typeId = parseInt(this.$params.typeId); - if (this.$stateParams.typeId) - this.typeId = parseInt(this.$stateParams.typeId); - - if (this.$stateParams.tags) - this.tags = JSON.parse(this.$stateParams.tags); + if (this.$params.tags) + this.tags = JSON.parse(this.$params.tags); }); } @@ -126,6 +120,17 @@ class Controller { this.applyFilters(); } + get itemName() { + return this._itemName; + } + + set itemName(value) { + this._itemName = value; + + this.updateStateParams(); + this.applyFilters(); + } + get tags() { return this._tags; } @@ -248,8 +253,11 @@ class Controller { if (this.itemId) newFilter = {'i.id': this.itemId}; + if (this.itemName) + newFilter = {'i.name': {like: `%${this.itemName}%`}}; + newParams = { - orderFk: this.order.id, + orderFk: this.$params.id, orderBy: this.getOrderBy(), tags: this.tags, }; @@ -290,6 +298,10 @@ class Controller { if (this.itemId) params.itemId = this.itemId; + params.itemName = undefined; + if (this.itemName) + params.itemName = this.itemName; + params.tags = undefined; if (this.tags.length) { const tags = []; @@ -348,9 +360,21 @@ class Controller { newFilterList = newFilterList.concat(tags); this.orderFields = newFilterList; } + + onSearch(params) { + if (params.search) { + if (/^\d+$/.test(params.search)) { + this.itemId = params.search; + this.itemName = null; + } else { + this.itemId = null; + this.itemName = params.search; + } + } + } } -Controller.$inject = ['$http', '$scope', '$state', '$compile', '$transitions']; +Controller.$inject = ['$element', '$scope', '$transitions']; ngModule.component('vnOrderCatalog', { template: require('./index.html'), diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index e2d2d0aff..86fb7c179 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -17,11 +17,15 @@ describe('Order', () => { $scope.search = {}; $scope.itemId = {}; $state = _$state_; - $state.params.categoryId = 1; - $state.params.typeId = 2; $state.current.name = 'my.current.state'; - controller = $componentController('vnOrderCatalog', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnOrderCatalog', {$element, $scope, $state}); controller._order = {id: 4}; + controller.$params = { + categoryId: 1, + typeId: 2, + id: 4 + }; })); describe('order() setter', () => { @@ -123,6 +127,18 @@ describe('Order', () => { }); }); + describe('itemName() setter', () => { + it(`should set itemName property and then call updateStateParams() and applyFilters() methods`, () => { + jest.spyOn(controller, 'updateStateParams'); + jest.spyOn(controller, 'applyFilters'); + + controller.itemName = 'Bow'; + + expect(controller.updateStateParams).toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith(); + }); + }); + describe('tags() setter', () => { it(`should set tags property and then call updateStateParams() and applyFilters() methods`, () => { jest.spyOn(controller, 'updateStateParams'); diff --git a/modules/order/front/routes.json b/modules/order/front/routes.json index b607aef9d..2f7c2c63a 100644 --- a/modules/order/front/routes.json +++ b/modules/order/front/routes.json @@ -41,7 +41,7 @@ "order": "$ctrl.order" } }, { - "url": "/catalog?categoryId&typeId&itemId&tags", + "url": "/catalog?q&categoryId&typeId&itemId&itemName&tags", "state": "order.card.catalog", "component": "vn-order-catalog", "description": "Catalog", From c8b6c3f7f3aaedafb43e8994a1f2d8298fef2e3e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 13:44:51 +0100 Subject: [PATCH 31/44] Fixed conflicts --- e2e/paths/07-order/02_basic_data.spec.js | 2 +- e2e/paths/07-order/04_catalog.spec.js | 5 +- modules/order/front/catalog/index.html | 28 +++++----- modules/order/front/catalog/index.js | 67 ++++++++++------------- modules/order/front/catalog/locale/es.yml | 2 + 5 files changed, 50 insertions(+), 54 deletions(-) create mode 100644 modules/order/front/catalog/locale/es.yml diff --git a/e2e/paths/07-order/02_basic_data.spec.js b/e2e/paths/07-order/02_basic_data.spec.js index d7bd01208..2c3292b61 100644 --- a/e2e/paths/07-order/02_basic_data.spec.js +++ b/e2e/paths/07-order/02_basic_data.spec.js @@ -81,7 +81,7 @@ describe('Order edit basic data path', () => { await page.waitToClick(selectors.orderBasicData.saveButton); const result = await page.waitForLastSnackbar(); - expect(result).toEqual('Data saved!'); + expect(result).toContain('Data saved!'); }); it('should now confirm the client have been edited', async() => { diff --git a/e2e/paths/07-order/04_catalog.spec.js b/e2e/paths/07-order/04_catalog.spec.js index 0db313088..bd502ce5b 100644 --- a/e2e/paths/07-order/04_catalog.spec.js +++ b/e2e/paths/07-order/04_catalog.spec.js @@ -69,8 +69,9 @@ describe('Order catalog', () => { }); it('should search for an item by id', async() => { - await page.write(selectors.orderCatalog.itemId, '2'); - await page.keyboard.press('Enter'); + // await page.write(selectors.orderCatalog.itemId, '2'); + await page.accessToSearchResult('2'); + // await page.keyboard.press('Enter'); await page.waitForNumberOfElements('section.product', 1); const result = await page.countElement('section.product'); diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 0349c1358..06ccfb1dd 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -12,11 +12,12 @@ data="$ctrl.items"> - + + - - @@ -83,14 +84,6 @@ - - Id: {{$ctrl.itemId}} + + Name + : {{$ctrl.itemName}} + Date: Wed, 25 Mar 2020 14:06:13 +0100 Subject: [PATCH 32/44] Updated unit tests --- modules/order/front/catalog/index.js | 20 --------- modules/order/front/catalog/index.spec.js | 49 +++++++---------------- 2 files changed, 14 insertions(+), 55 deletions(-) diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index 5ebbba3d3..00913caa4 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -182,18 +182,6 @@ class Controller extends Section { this.itemTypes = res.data); } - /** - * Search by item id filter - * @param {object} event - */ - onSearchById(event) { - const value = this.$.itemId.value; - if (event.key === 'Enter' && value) { - this.itemId = value; - this.$.itemId.value = null; - } - } - /** * Search by tag value * @param {object} event @@ -238,20 +226,12 @@ class Controller extends Section { if (this.typeId) newFilter.typeFk = this.typeId; - /* if (this.itemId) - newFilter = {'i.id': this.itemId}; - - if (this.itemName) - newFilter = {'i.name': {like: `%${this.itemName}%`}}; */ - newParams = { orderFk: this.$params.id, orderBy: this.getOrderBy(), tags: this.tags, }; - console.log(newFilter); - return model.applyFilter({where: newFilter}, newParams); } diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index 86fb7c179..9a9742f7f 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -115,30 +115,6 @@ describe('Order', () => { }); }); - describe('itemId() setter', () => { - it(`should set itemId property and then call updateStateParams() and applyFilters() methods`, () => { - jest.spyOn(controller, 'updateStateParams'); - jest.spyOn(controller, 'applyFilters'); - - controller.itemId = 1; - - expect(controller.updateStateParams).toHaveBeenCalledWith(); - expect(controller.applyFilters).toHaveBeenCalledWith(); - }); - }); - - describe('itemName() setter', () => { - it(`should set itemName property and then call updateStateParams() and applyFilters() methods`, () => { - jest.spyOn(controller, 'updateStateParams'); - jest.spyOn(controller, 'applyFilters'); - - controller.itemName = 'Bow'; - - expect(controller.updateStateParams).toHaveBeenCalledWith(); - expect(controller.applyFilters).toHaveBeenCalledWith(); - }); - }); - describe('tags() setter', () => { it(`should set tags property and then call updateStateParams() and applyFilters() methods`, () => { jest.spyOn(controller, 'updateStateParams'); @@ -173,23 +149,27 @@ describe('Order', () => { }); }); - describe('onSearchById()', () => { - it(`should not filter by id if the event key code doesn't equals to 'Enter'`, () => { + describe('onSearch()', () => { + it(`should apply a filter by item id an then call the applyFilters method`, () => { jest.spyOn(controller, 'applyFilters'); - controller.$.itemId.value = 1; - controller.onSearchById({key: 'Tab'}); + const itemId = 1; + controller.onSearch({search: itemId}); - expect(controller.applyFilters).not.toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith({ + 'i.id': itemId + }); }); - it(`should filter by id if the event key code equals to 'Enter' an then call applyFilters()`, () => { + it(`should apply a filter by item name an then call the applyFilters method`, () => { jest.spyOn(controller, 'applyFilters'); - controller.$.itemId.value = 1; - controller.onSearchById({key: 'Enter'}); + const itemName = 'Bow'; + controller.onSearch({search: itemName}); - expect(controller.applyFilters).toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith({ + 'i.name': {like: `%${itemName}%`} + }); }); }); @@ -239,7 +219,6 @@ describe('Order', () => { controller._categoryId = 2; controller._typeId = 4; - controller._itemId = 1; controller._tags = [ {tagFk: 11, value: 'Precission', tagSelection: {name: 'Category'}} ]; @@ -247,7 +226,7 @@ describe('Order', () => { value: 'Precission', tagFk: 11, tagSelection: {name: 'Category'}} ]); - let result = {categoryId: 2, typeId: 4, itemId: 1, tags: tags}; + let result = {categoryId: 2, typeId: 4, tags: tags}; controller.updateStateParams(); expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result); From e94cb7fecd713d1b9ecabf5d42e9800f26ad3443 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 14:07:35 +0100 Subject: [PATCH 33/44] Removed commented lines --- e2e/paths/07-order/04_catalog.spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/e2e/paths/07-order/04_catalog.spec.js b/e2e/paths/07-order/04_catalog.spec.js index bd502ce5b..34fdbbec0 100644 --- a/e2e/paths/07-order/04_catalog.spec.js +++ b/e2e/paths/07-order/04_catalog.spec.js @@ -69,9 +69,7 @@ describe('Order catalog', () => { }); it('should search for an item by id', async() => { - // await page.write(selectors.orderCatalog.itemId, '2'); await page.accessToSearchResult('2'); - // await page.keyboard.press('Enter'); await page.waitForNumberOfElements('section.product', 1); const result = await page.countElement('section.product'); From 2b7ff6fec006445a665d4e70cfff4502d8f72051 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 14:08:45 +0100 Subject: [PATCH 34/44] Removed state vars --- modules/order/front/routes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/front/routes.json b/modules/order/front/routes.json index 2f7c2c63a..eec628b89 100644 --- a/modules/order/front/routes.json +++ b/modules/order/front/routes.json @@ -41,7 +41,7 @@ "order": "$ctrl.order" } }, { - "url": "/catalog?q&categoryId&typeId&itemId&itemName&tags", + "url": "/catalog?q&categoryId&typeId&tags", "state": "order.card.catalog", "component": "vn-order-catalog", "description": "Catalog", From 9b4546edadbfaff47d1c808673ea96581a40fedc Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 25 Mar 2020 14:18:51 +0100 Subject: [PATCH 35/44] minor refactor plus path fix after merge --- e2e/paths/05-ticket/18_index_payout.spec.js | 61 +-------------------- modules/ticket/front/index/index.js | 2 +- 2 files changed, 4 insertions(+), 59 deletions(-) diff --git a/e2e/paths/05-ticket/18_index_payout.spec.js b/e2e/paths/05-ticket/18_index_payout.spec.js index 46619b5ae..749428c44 100644 --- a/e2e/paths/05-ticket/18_index_payout.spec.js +++ b/e2e/paths/05-ticket/18_index_payout.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -xdescribe('Ticket index payout path', () => { +describe('Ticket index payout path', () => { let browser; let page; @@ -47,67 +47,12 @@ xdescribe('Ticket index payout path', () => { expect(result).toEqual('Data saved!'); }); - it('should navigate to the client balance section', async() => { + it('should navigate to the client balance section and check a new balance line was entered', async() => { await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should B', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should C', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should D', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); + await page.accessToSearchResult('101'); await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should E', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should F', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); expect(result).toEqual(4); diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index e9f522839..3f0146846 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -37,7 +37,7 @@ export default class Controller { } get checked() { - const tickets = this.$.tickets || []; + const tickets = this.$.model.data || []; const checkedLines = []; for (let ticket of tickets) { if (ticket.checked) From f06c7d3d479242dbddfcf08983718a329d3e3095 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 25 Mar 2020 15:17:43 +0100 Subject: [PATCH 36/44] front test --- modules/ticket/front/index/index.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 6b0b42ffd..d66c9f49d 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -87,7 +87,7 @@ describe('Component vnTicketIndex', () => { controller.$.balanceCreateDialog = {show: () => {}}; jest.spyOn(controller.$.balanceCreateDialog, 'show').mockReturnThis(); - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; controller.$.balanceCreateDialog.amountPaid = 0; controller.openBalanceDialog(); @@ -101,7 +101,7 @@ describe('Component vnTicketIndex', () => { describe('checked()', () => { it('should return an array of checked tickets', () => { - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; const result = controller.checked; const firstRow = result[0]; const secondRow = result[1]; @@ -114,7 +114,7 @@ describe('Component vnTicketIndex', () => { describe('totalChecked()', () => { it('should return the total number of checked tickets', () => { - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; const result = controller.checked; expect(result.length).toEqual(2); From 81d0f5bf073092df36afac1a4fd040bf105d599d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 16:08:18 +0100 Subject: [PATCH 37/44] Removed focus --- e2e/paths/05-ticket/09_weekly.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/05-ticket/09_weekly.spec.js b/e2e/paths/05-ticket/09_weekly.spec.js index d2751be82..1629107fb 100644 --- a/e2e/paths/05-ticket/09_weekly.spec.js +++ b/e2e/paths/05-ticket/09_weekly.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -fdescribe('Ticket descriptor path', () => { +describe('Ticket descriptor path', () => { let browser; let page; From 92ffccc9a2f7726189f792f9a60baec5debc3497 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 26 Mar 2020 09:07:17 +0100 Subject: [PATCH 38/44] 2206 - Refactor popover table --- modules/zone/front/delivery-days/index.html | 53 ++++++++++++++++++- modules/zone/front/delivery-days/index.js | 9 +++- .../zone/front/delivery-days/index.spec.js | 8 +-- modules/zone/front/delivery-days/style.scss | 6 +-- 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 589208caf..b0874c66c 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -33,10 +33,59 @@
+ + +
Zones
- + + + + + + Id + Name + Agency + Closing + Price + + + + + + {{::zone.id}} + {{::zone.name}} + {{::zone.agencyMode.name}} + {{::zone.hour | date: 'HH:mm'}} + {{::zone.price | currency: 'EUR':2}} + + + + + + + + + + +
-
\ No newline at end of file + + + + \ No newline at end of file diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 006252a69..363186543 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -26,8 +26,7 @@ class Controller extends Section { zones.push(event.zoneFk); this.$.zoneEvents.show($event.target); - const zoneIndex = this.$.zoneIndex; - const zoneModel = zoneIndex.$scope.model; + const zoneModel = this.$.zoneModel; zoneModel.applyFilter({ include: { relation: 'agencyMode', @@ -38,6 +37,12 @@ class Controller extends Section { } }); } + + preview(event, zone) { + this.stopEvent(event); + this.selectedZone = zone; + this.$.summary.show(); + } } ngModule.component('vnZoneDeliveryDays', { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 125e14f2d..6dc270b9a 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -14,11 +14,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { $element = angular.element(' { @@ -60,7 +56,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { }); it('should call the show() method and then call the applyFilter() method with the expected ids', () => { - const zoneModel = controller.$.zoneIndex.$scope.model; + const zoneModel = controller.$.zoneModel; jest.spyOn(controller.$.zoneEvents, 'show'); jest.spyOn(zoneModel, 'applyFilter'); diff --git a/modules/zone/front/delivery-days/style.scss b/modules/zone/front/delivery-days/style.scss index 531b51795..a279ca0b9 100644 --- a/modules/zone/front/delivery-days/style.scss +++ b/modules/zone/front/delivery-days/style.scss @@ -19,11 +19,7 @@ vn-zone-delivery-days { .zoneEvents { width: 700px; max-height: 450px; - - vn-float-button { - display: none - } - + vn-data-viewer { margin-bottom: 0; vn-pagination { From 69280925944e03f1db0006ca2b60aaf3017caf63 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 26 Mar 2020 12:00:07 +0100 Subject: [PATCH 39/44] fix ticket.sale state autocomplete --- modules/ticket/back/methods/state/editableStates.js | 8 ++++++-- .../ticket/back/methods/state/specs/editableState.spec.js | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/state/editableStates.js b/modules/ticket/back/methods/state/editableStates.js index 4979f4819..c1cbda799 100644 --- a/modules/ticket/back/methods/state/editableStates.js +++ b/modules/ticket/back/methods/state/editableStates.js @@ -3,6 +3,10 @@ module.exports = Self => { Self.remoteMethodCtx('editableStates', { description: 'Gets the editable states according the user role ', accessType: 'READ', + accepts: { + arg: 'filter', + type: 'object' + }, returns: { type: ['Object'], root: true @@ -13,10 +17,10 @@ module.exports = Self => { } }); - Self.editableStates = async ctx => { + Self.editableStates = async(ctx, filter) => { let userId = ctx.req.accessToken.userId; let models = Self.app.models; - let statesList = await models.State.find(); + let statesList = await models.State.find({where: filter.where}); let isProduction = await models.Account.hasRole(userId, 'production'); let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); diff --git a/modules/ticket/back/methods/state/specs/editableState.spec.js b/modules/ticket/back/methods/state/specs/editableState.spec.js index 54dbdfcae..03cb7616c 100644 --- a/modules/ticket/back/methods/state/specs/editableState.spec.js +++ b/modules/ticket/back/methods/state/specs/editableState.spec.js @@ -1,10 +1,12 @@ const app = require('vn-loopback/server/server'); describe('ticket editableStates()', () => { + const filter = {where: {name: {like: '%%'}}}; it('should return the expected state for the given role', async() => { const productionRole = 49; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); expect(deliveredState).toBeTruthy(); @@ -13,7 +15,7 @@ describe('ticket editableStates()', () => { it(`should returns the expected states by a specific role`, async() => { const productionRole = 18; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); @@ -24,7 +26,7 @@ describe('ticket editableStates()', () => { it(`should return again the expected state by a specific role`, async() => { const employeeRole = 1; const ctx = {req: {accessToken: {userId: employeeRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); expect(pickerDesignedState).toBeFalsy(); From 835c415ba7e952b5e4b6f3a2fa173405b29d2966 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 26 Mar 2020 14:45:38 +0100 Subject: [PATCH 40/44] 1934 - Moved procedure logic to method --- loopback/locale/en.json | 1 + loopback/locale/es.json | 1 + .../back/methods/ticket/deleteStowaway.js | 61 ++++++++++++++++--- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index b8c31020b..dc62e35f4 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -62,6 +62,7 @@ "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})", "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "This ticket is not an stowaway anymore": "The ticket id [#{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5f41c9931..da62a6a7d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -125,6 +125,7 @@ "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}}})", "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "This ticket is not an stowaway anymore": "El ticket id [#{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "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", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", diff --git a/modules/ticket/back/methods/ticket/deleteStowaway.js b/modules/ticket/back/methods/ticket/deleteStowaway.js index 6f3a1760f..cf9626c14 100644 --- a/modules/ticket/back/methods/ticket/deleteStowaway.js +++ b/modules/ticket/back/methods/ticket/deleteStowaway.js @@ -1,6 +1,6 @@ module.exports = Self => { - Self.remoteMethod('deleteStowaway', { + Self.remoteMethodCtx('deleteStowaway', { description: 'Deletes an stowaway', accessType: 'WRITE', accepts: [{ @@ -19,21 +19,66 @@ module.exports = Self => { } }); - Self.deleteStowaway = async id => { + Self.deleteStowaway = async(ctx, id) => { + const models = Self.app.models; + const $t = ctx.req.__; // $translate const ticket = await Self.findById(id, { include: [{ relation: 'ship' }, { relation: 'stowaway' + }, { + relation: 'client', + scope: { + include: { + relation: 'salesPerson' + } + } }] }); - let params; - if (ticket.stowaway()) - params = [ticket.stowaway().shipFk, ticket.stowaway().id]; - else if (ticket.ship()) - params = [ticket.ship().shipFk, ticket.ship().id]; + let stowawayFk; + let shipFk; + if (ticket.stowaway()) { + shipFk = ticket.stowaway().shipFk; + stowawayFk = ticket.stowaway().id; + } else if (ticket.ship()) { + shipFk = ticket.ship().shipFk; + stowawayFk = ticket.ship().id; + } - return Self.rawSql(`CALL vn.stowaway_unboarding(?, ?)`, params); + const stowaway = await models.Stowaway.findOne({ + where: { + id: stowawayFk, + shipFk: shipFk + } + }); + const result = await stowaway.destroy(); + + const state = await models.State.findOne({ + where: { + code: 'BOARDING' + } + }); + const ticketTracking = await models.TicketTracking.findOne({ + where: { + ticketFk: shipFk, + stateFk: state.id + } + }); + + await ticketTracking.destroy(); + + const salesPerson = ticket.client().salesPerson(); + if (salesPerson) { + const origin = ctx.req.headers.origin; + const message = $t('This ticket is not an stowaway anymore', { + ticketId: stowawayFk, + ticketUrl: `${origin}/#!/ticket/${stowawayFk}/summary` + }); + await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); + } + + return result; }; }; From d53cedd5d4e1de46806ca315489a629e106dad57 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 26 Mar 2020 17:41:40 +0100 Subject: [PATCH 41/44] preparado para PR --- .../10170-NOFallas/00-zone_getEvents.sql | 30 +++++++++++-------- db/dump/fixtures.sql | 2 +- front/core/directives/specs/focus.spec.js | 1 - modules/zone/back/methods/zone/getEvents.js | 11 ++----- modules/zone/front/delivery-days/index.html | 21 ++++++++----- modules/zone/front/delivery-days/index.js | 22 ++++++++------ .../zone/front/delivery-days/index.spec.js | 22 +++++++++++++- 7 files changed, 68 insertions(+), 41 deletions(-) diff --git a/db/changes/10170-NOFallas/00-zone_getEvents.sql b/db/changes/10170-NOFallas/00-zone_getEvents.sql index 5911abdc3..991150db7 100644 --- a/db/changes/10170-NOFallas/00-zone_getEvents.sql +++ b/db/changes/10170-NOFallas/00-zone_getEvents.sql @@ -5,7 +5,6 @@ DELIMITER $$ USE `vn`$$ CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents`( vGeoFk INT, - vDeliveryMethodFk VARCHAR(255), vAgencyModeFk INT) BEGIN /** @@ -14,14 +13,20 @@ BEGIN * @param vGeoFk The geo id * @param vAgencyModeFk The agency mode id */ - DROP TEMPORARY TABLE IF EXISTS tmp.auxZone; - - CREATE TEMPORARY TABLE tmp.auxZone - (id INT(11) PRIMARY KEY) + DECLARE vDeliveryMethodFk VARCHAR(255); + + DROP TEMPORARY TABLE IF EXISTS tZone; + CREATE TEMPORARY TABLE tZone + (id INT PRIMARY KEY) ENGINE = MEMORY; - IF vDeliveryMethodFk = 'pickUp' THEN - INSERT INTO tmp.auxZone + SELECT dm.`code` INTO vDeliveryMethodFk + FROM agencyMode am + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE am.id = vAgencyModeFk; + + IF vDeliveryMethodFk = 'PICKUP' THEN + INSERT INTO tZone SELECT id FROM zone WHERE agencyModeFk = vAgencyModeFk; @@ -29,13 +34,13 @@ BEGIN CALL zone_getFromGeo(vGeoFk); IF vAgencyModeFk IS NOT NULL THEN - INSERT INTO tmp.auxZone + INSERT INTO tZone SELECT t.id FROM tmp.zone t JOIN zone z ON z.id = t.id WHERE z.agencyModeFk = vAgencyModeFk; ELSE - INSERT INTO tmp.auxZone + INSERT INTO tZone SELECT t.id FROM tmp.zone t JOIN zone z ON z.id = t.id @@ -47,15 +52,14 @@ BEGIN END IF; SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays - FROM tmp.auxZone t + FROM tZone t JOIN zoneEvent e ON e.zoneFk = t.id; SELECT e.zoneFk, e.dated - FROM tmp.auxZone t + FROM tZone t JOIN zoneExclusion e ON e.zoneFk = t.id; - DROP TEMPORARY TABLE IF EXISTS tmp.auxZone; - + DROP TEMPORARY TABLE tZone; END$$ DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7b2fd1cae..c32e8475f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -156,7 +156,7 @@ UPDATE `vn`.`agencyMode` SET `id` = 8 WHERE `name` = 'Silla247Expensive'; UPDATE `vn`.`agencyMode` SET `id` = 23 WHERE `name` = 'Refund'; UPDATE `vn`.`agencyMode` SET `id` = 10 WHERE `name` = 'Other agency'; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 1; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 3 WHERE `id` = 1; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 2; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 3; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 4; diff --git a/front/core/directives/specs/focus.spec.js b/front/core/directives/specs/focus.spec.js index 82cd7d84d..11c60688a 100644 --- a/front/core/directives/specs/focus.spec.js +++ b/front/core/directives/specs/focus.spec.js @@ -27,7 +27,6 @@ describe('Directive focus', () => { expect($element[0].firstChild.focus).toHaveBeenCalledWith(); }); - it('should call focus function on the element', () => { let html = ``; compile(html); diff --git a/modules/zone/back/methods/zone/getEvents.js b/modules/zone/back/methods/zone/getEvents.js index 2555fec83..406ef0103 100644 --- a/modules/zone/back/methods/zone/getEvents.js +++ b/modules/zone/back/methods/zone/getEvents.js @@ -7,11 +7,6 @@ module.exports = Self => { arg: 'geoFk', type: 'Number', description: 'The geo id' - }, { - arg: 'deliveryMethodFk', - type: 'String', - description: 'The delivery Method code', - required: true }, { arg: 'agencyModeFk', type: 'Number', @@ -29,10 +24,10 @@ module.exports = Self => { } }); - Self.getEvents = async(geoFk, deliveryMethodFk, agencyModeFk) => { + Self.getEvents = async(geoFk, agencyModeFk) => { let [events, exclusions] = await Self.rawSql( - `CALL zone_getEvents(?, ?, ?)`, - [geoFk, deliveryMethodFk, agencyModeFk] + `CALL zone_getEvents(?, ?)`, + [geoFk, agencyModeFk] ); return {events, exclusions}; }; diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 28e2c565a..f2d4ee27d 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -9,22 +9,26 @@ + ng-model="$ctrl.deliveryMethodFk"> + label="Delivery" + val="delivery" + ng-model="$ctrl.deliveryMethodFk" + class="vn-mb-sm"> - + show-field="code" + > {{code}} - {{town.name}} ({{town.province.name}}, {{town.province.country.country}}) @@ -34,7 +38,8 @@ label="Agency" ng-model="params.agencyModeFk" url="AgencyModes/isActive" - where="$ctrl.agencyFilter"> + where="$ctrl.agencyFilter" + vn-id="agencymode"> diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index c433f525a..8afe8060a 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -5,9 +5,11 @@ import './style.scss'; class Controller extends Section { $onInit() { this.$.params = {}; - this.$.params.deliveryMethodFk = 'delivery'; } + $postLink() { + this.deliveryMethodFk = 'delivery'; + } onSubmit() { this.$.data = null; this.$http.get(`Zones/getEvents`, {params: this.$.params}) @@ -20,19 +22,21 @@ class Controller extends Section { } get deliveryMethodFk() { - return this._deliveryMethod; + return this._deliveryMethodFk; } set deliveryMethodFk(value) { - this._deliveryMethod = value; + this._deliveryMethodFk = value; + this.$.params.agencyModeFk = null; let filter; - if (value === 'pickUp') + if (value === 'pickUp') { filter = {where: {code: 'PICKUP'}}; - else - filter = {where: {code: {neq: 'PICKUP'}}}; - let json = encodeURIComponent(JSON.stringify(filter)); - this.$http.get(`DeliveryMethods?filter=${json}`).then(json => { - let deliveryMethods = json.data.map(deliveryMethod => deliveryMethod.id); + this.$.agencymode.focus(); + } else + filter = {where: {code: {inq: ['DELIVERY', 'AGENCY']}}}; + + this.$http.get(`DeliveryMethods`, {filter}).then(res => { + let deliveryMethods = res.data.map(deliveryMethod => deliveryMethod.id); this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}}; }); } diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 35171ab94..71021223d 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -21,8 +21,28 @@ describe('Zone Component vnZoneDeliveryDays', () => { model: crudModel } }; + controller.$.params = {}; })); + describe('deliveryMethodFk() setter', () => { + it(`should set the deliveryMethodFk property and check just agencymode focus`, () => { + controller.$.agencymode = {focus: jasmine.createSpy('focus')}; + + controller.deliveryMethodFk = 'pickUp'; + + expect(controller.$.agencymode.focus).toHaveBeenCalledWith(); + }); + + it(`should set the deliveryMethodFk property, call method http and sets the agencyfilter`, () => { + $httpBackend.when('GET', 'DeliveryMethods').respond([{id: 'id'}]); + + controller.deliveryMethodFk = 'no pickUp'; + $httpBackend.flush(); + + expect(controller.agencyFilter).toEqual({deliveryMethodFk: {inq: ['id']}}); + }); + }); + describe('onSubmit()', () => { it('should make an HTTP GET query and then call the showMessage() method', () => { jest.spyOn(controller.vnApp, 'showMessage'); @@ -48,7 +68,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { }); }); - describe('onSelection()', () => { + xdescribe('onSelection()', () => { it('should not call the show popover method if events array is empty', () => { jest.spyOn(controller.$.zoneEvents, 'show'); From d4ca58edad0cba6c827415d5e32582ba70a9f0da Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 27 Mar 2020 09:10:30 +0100 Subject: [PATCH 42/44] Updated back unit test --- db/dump/fixtures.sql | 4 ++ .../ticket/specs/deleteStowaway.spec.js | 72 +++++++++++++++++-- modules/ticket/back/model-config.json | 3 + .../ticket/back/models/ticket-last-state.json | 34 +++++++++ 4 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 modules/ticket/back/models/ticket-last-state.json diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 331d115a3..4218e15d1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -554,6 +554,10 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des (10, 23, 4, 'Reclama ticket: 8'), (11, 24, 4, 'Reclama ticket: 7'); +-- FIX for state hours on local, inter_afterInsert +UPDATE vncontrol.inter SET odbc_date = DATE_ADD(CURDATE(), INTERVAL -10 SECOND); + + INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) VALUES (1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)), diff --git a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js index 3c8097e37..bd6fd327a 100644 --- a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js +++ b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js @@ -3,40 +3,100 @@ const app = require('vn-loopback/server/server'); describe('ticket deleteStowaway()', () => { const shipId = 16; const stowawayId = 17; + const ctx = { + req: { + accessToken: {userId: 18}, + headers: {origin: 'http://localhost'} + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + + afterAll(async() => { + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'OK']); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'OK']); + }); it('should create an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) `, [stowawayId, shipId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'BOARDING']); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(1); }); + it('should confirm that the ship ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('Embarcando'); + }); + it('should delete the stowaway from the ship ticket', async() => { - await app.models.Ticket.deleteStowaway(shipId); + await app.models.Ticket.deleteStowaway(ctx, shipId); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(0); }); + it('should confirm that the ship ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('OK'); + }); + it('should create again an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) - `, [stowawayId, shipId]); + `, [shipId, stowawayId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'BOARDING']); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(1); }); - it('should delete the stowaway from the stowaway ticket', async() => { - await app.models.Ticket.deleteStowaway(stowawayId); + it('should confirm that the stowaway ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + expect(shipState.name).toEqual('Embarcando'); + }); + + it('should delete the stowaway from the stowaway ticket', async() => { + await app.models.Ticket.deleteStowaway(ctx, stowawayId); + + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(0); }); + + it('should confirm that the stowaway ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); + + expect(shipState.name).toEqual('OK'); + }); }); diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 10c10b134..ac6f4f100 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -56,6 +56,9 @@ "TicketState":{ "dataSource": "vn" }, + "TicketLastState":{ + "dataSource": "vn" + }, "TicketService":{ "dataSource": "vn" }, diff --git a/modules/ticket/back/models/ticket-last-state.json b/modules/ticket/back/models/ticket-last-state.json new file mode 100644 index 000000000..890d800af --- /dev/null +++ b/modules/ticket/back/models/ticket-last-state.json @@ -0,0 +1,34 @@ +{ + "name": "TicketLastState", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketLastState" + } + }, + "properties": { + "name": { + "type": "string" + }, + "ticketFk": { + "id": 1, + "type": "Number" + }, + "ticketTrackingFk": { + "id": 2, + "type": "Number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "ticketTracking": { + "type": "belongsTo", + "model": "TicketTracking", + "foreignKey": "ticketTrackingFk" + } + } +} From 74b27778ab9fb75808269e8916095b0e4b312491 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Fri, 27 Mar 2020 11:10:20 +0100 Subject: [PATCH 43/44] add phones in ticket summary --- e2e/helpers/selectors.js | 2 +- modules/ticket/back/methods/ticket/summary.js | 4 +-- modules/ticket/front/summary/index.html | 29 ++++++++++++++----- modules/ticket/front/summary/locale/es.yml | 4 +++ 4 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 modules/ticket/front/summary/locale/es.yml diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 5469c09df..34869cc87 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -359,7 +359,7 @@ export default { popoverDiaryButton: '.vn-popover.shown vn-item-descriptor vn-icon[icon="icon-transaction"]', firstSaleQuantity: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3)', firstSaleDiscount: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6)', - invoiceOutRef: 'vn-ticket-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(6) > section > span', + invoiceOutRef: 'vn-ticket-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(7) > section > span', setOk: 'vn-ticket-summary vn-button[label="SET OK"] > button' }, ticketsIndex: { diff --git a/modules/ticket/back/methods/ticket/summary.js b/modules/ticket/back/methods/ticket/summary.js index d1037f251..b0a612bf3 100644 --- a/modules/ticket/back/methods/ticket/summary.js +++ b/modules/ticket/back/methods/ticket/summary.js @@ -55,7 +55,7 @@ module.exports = Self => { { relation: 'client', scope: { - fields: ['salesPersonFk', 'name'], + fields: ['salesPersonFk', 'name', 'phone', 'mobile'], include: { relation: 'salesPerson', scope: { @@ -73,7 +73,7 @@ module.exports = Self => { { relation: 'address', scope: { - fields: ['street', 'city', 'provinceFk', 'phone'], + fields: ['street', 'city', 'provinceFk', 'phone', 'mobile'], include: { relation: 'province', scope: { diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html index decb01023..be5ff6d92 100644 --- a/modules/ticket/front/summary/index.html +++ b/modules/ticket/front/summary/index.html @@ -30,6 +30,13 @@ + + + {{$ctrl.summary.routeFk}} + + @@ -41,22 +48,28 @@ - - - {{$ctrl.summary.routeFk}} - - - + + + + + + Date: Fri, 27 Mar 2020 12:01:09 +0100 Subject: [PATCH 44/44] test front arreglados por el cambio de hora --- modules/travel/front/main/index.spec.js | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/travel/front/main/index.spec.js b/modules/travel/front/main/index.spec.js index 2abcb0a33..27dfa0392 100644 --- a/modules/travel/front/main/index.spec.js +++ b/modules/travel/front/main/index.spec.js @@ -12,13 +12,29 @@ describe('Travel Component vnTravel', () => { describe('fetchParams()', () => { it('should return a range of dates with passed scope days', () => { + /** + * Calculates the difference in days between two dates, it also + * accounts for cases where the two dates in question span a + * daylight saving time (DST) change. + * + * @param {Date} a The start date + * @param {Date} b The end date + * @return {Number} The difference in days + */ + function diffInDays(a, b) { + const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate()); + const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()); + const msInDay = 86400 * 1000; + return Math.floor((utc2 - utc1) / msInDay); + } + let params = controller.fetchParams({scopeDays: 2}); + const diff = diffInDays( + params.shippedFrom, + new Date(params.shippedTo.getTime() + 1) + ); - let from = params.shippedFrom.getTime(); - let to = params.shippedTo.getTime() + 1; - let msInDay = 86400 * 1000; - - expect(to - from).toEqual(3 * msInDay); + expect(diff).toEqual(3); }); }); });