From b536c8291ae2b274e30fff6e5a1b1bf611ed402e Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 28 Apr 2020 14:26:02 +0200 Subject: [PATCH] #1882 Popover::show() boilerplate code removed --- .eslintrc.yml | 5 +- .../components/descriptor-popover/index.js | 4 +- front/salix/components/descriptor/index.html | 17 +- front/salix/components/descriptor/index.js | 24 +- .../components/descriptor/quick-link.html | 8 + .../salix/components/descriptor/quick-link.js | 13 + front/salix/components/descriptor/style.scss | 10 +- modules/claim/front/photos/index.html | 17 +- modules/claim/front/photos/index.js | 37 +- modules/claim/front/photos/index.spec.js | 36 +- modules/client/front/descriptor/index.html | 152 ++++---- modules/client/front/descriptor/index.js | 15 +- modules/client/front/dms/index/index.html | 6 +- modules/client/front/dms/index/index.js | 30 +- modules/client/front/dms/index/index.spec.js | 18 +- modules/client/front/sample/index/index.html | 7 +- modules/client/front/sample/index/index.js | 18 +- modules/entry/front/index/index.html | 15 +- modules/entry/front/index/index.js | 11 +- modules/entry/front/index/style.scss | 6 +- modules/item/front/request/index.html | 35 +- modules/item/front/request/index.js | 78 +--- modules/item/front/request/index.spec.js | 27 +- modules/order/front/line/index.html | 2 +- modules/order/front/line/index.js | 7 - modules/order/front/line/index.spec.js | 16 +- modules/order/front/summary/index.html | 2 +- modules/order/front/summary/index.js | 16 +- modules/order/front/summary/index.spec.js | 11 +- modules/order/front/volume/index.html | 2 +- modules/order/front/volume/index.js | 24 +- modules/order/front/volume/index.spec.js | 51 +-- modules/route/front/index/index.html | 7 +- modules/route/front/index/index.js | 16 +- modules/ticket/front/component/index.js | 3 +- modules/ticket/front/dms/index/index.html | 6 +- modules/ticket/front/dms/index/index.js | 27 +- modules/ticket/front/dms/index/index.spec.js | 18 +- modules/ticket/front/expedition/index.html | 8 +- modules/ticket/front/expedition/index.js | 26 +- modules/ticket/front/expedition/index.spec.js | 13 +- modules/ticket/front/picture/index.html | 2 +- modules/ticket/front/picture/index.js | 10 - modules/ticket/front/request/index/index.html | 4 +- modules/ticket/front/request/index/index.js | 14 +- .../ticket/front/request/index/index.spec.js | 5 +- modules/ticket/front/sale-checked/index.js | 4 - modules/ticket/front/sale-tracking/index.html | 2 +- modules/ticket/front/sale-tracking/index.js | 12 - modules/ticket/front/sale/index.html | 338 +++++++++--------- modules/ticket/front/sale/index.js | 14 - modules/ticket/front/summary/index.js | 4 - .../ticket/front/tracking/index/index.html | 2 +- modules/ticket/front/tracking/index/index.js | 11 +- modules/ticket/front/volume/index.js | 4 - modules/ticket/front/volume/index.spec.js | 15 +- modules/worker/front/dms/index/index.html | 11 +- modules/worker/front/dms/index/index.js | 62 ++-- modules/worker/front/dms/index/index.spec.js | 21 +- modules/worker/front/log/index.html | 4 +- modules/worker/front/log/index.js | 12 - 61 files changed, 556 insertions(+), 839 deletions(-) create mode 100644 front/salix/components/descriptor/quick-link.html create mode 100644 front/salix/components/descriptor/quick-link.js diff --git a/.eslintrc.yml b/.eslintrc.yml index 380cf915b..82a1af501 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -31,6 +31,7 @@ rules: curly: [error, multi-or-nest] indent: [error, 4] arrow-parens: [error, as-needed] - jasmine/no-focused-tests: 0 no-multiple-empty-lines: ["error", { "max": 1, "maxEOF": 1 }] - space-in-parens: ["error", "never"] \ No newline at end of file + space-in-parens: ["error", "never"] + jasmine/no-focused-tests: 0 + jasmine/prefer-toHaveBeenCalledWith: 0 \ No newline at end of file diff --git a/front/salix/components/descriptor-popover/index.js b/front/salix/components/descriptor-popover/index.js index 7de04a64b..db2ae80c9 100644 --- a/front/salix/components/descriptor-popover/index.js +++ b/front/salix/components/descriptor-popover/index.js @@ -63,10 +63,10 @@ export default class DescriptorPopover extends Popover { this.relocate(); return this.$http.get(url, options) .then(res => { - this.canceler = null; this.$.$applyAsync(() => this.relocate()); return res; - }); + }) + .finally(() => this.canceler = null); } } diff --git a/front/salix/components/descriptor/index.html b/front/salix/components/descriptor/index.html index 4a50be430..d44e0eaba 100644 --- a/front/salix/components/descriptor/index.html +++ b/front/salix/components/descriptor/index.html @@ -1,8 +1,9 @@ - - - - \ No newline at end of file + + +
+
\ No newline at end of file diff --git a/front/salix/components/descriptor/index.js b/front/salix/components/descriptor/index.js index 844e33542..11742b509 100644 --- a/front/salix/components/descriptor/index.js +++ b/front/salix/components/descriptor/index.js @@ -1,21 +1,39 @@ import ngModule from '../../module'; import Component from 'core/lib/component'; -import './quick-links'; import './style.scss'; +import './quick-links'; +import './quick-link'; export default class Descriptor extends Component { - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); + get entity() { + return this._entity; + } + + set entity(value) { + this._entity = value; } get quicklinks() { return this._quicklinks; } + + set quicklinks(value = {}) { + this._quicklinks = Object.assign(value, this._quicklinks); + } } +Descriptor.$inject = ['$element', '$scope'/* , '$transclude'*/]; ngModule.vnComponent('vnDescriptor', { + template: require('./index.html'), controller: Descriptor, bindings: { + entity: ' + + + \ No newline at end of file diff --git a/front/salix/components/descriptor/quick-link.js b/front/salix/components/descriptor/quick-link.js new file mode 100644 index 000000000..9dae0f9d5 --- /dev/null +++ b/front/salix/components/descriptor/quick-link.js @@ -0,0 +1,13 @@ +import ngModule from '../../module'; + +export default class QuickLink {} + +ngModule.component('vnQuickLink', { + template: require('./quick-link.html'), + controller: QuickLink, + bindings: { + state: '@?', + icon: '@?', + tooltip: '@?' + } +}); diff --git a/front/salix/components/descriptor/style.scss b/front/salix/components/descriptor/style.scss index a048c12b3..1082f406b 100644 --- a/front/salix/components/descriptor/style.scss +++ b/front/salix/components/descriptor/style.scss @@ -2,7 +2,9 @@ @import "./effects"; @import "./variables"; -.vn-descriptor { +.vn-descriptor, +.vn-descriptor slot-body { + display: block; box-shadow: 0 1px 3px $color-shadow; & > .header { @@ -65,7 +67,11 @@ align-items: center; justify-content: center; - & > a { + & > a, + vn-quick-link > a { + display: flex; + align-items: center; + justify-content: center; padding: 0 $spacing-md; margin: 0 $spacing-sm; diff --git a/modules/claim/front/photos/index.html b/modules/claim/front/photos/index.html index 4a6e3e7b2..cb3f55b65 100644 --- a/modules/claim/front/photos/index.html +++ b/modules/claim/front/photos/index.html @@ -1,4 +1,6 @@ - @@ -25,19 +27,16 @@ - - - + on-accept="$ctrl.deleteDms($data)"> - + ng-click="$ctrl.openUploadDialog()" + fixed-bottom-right> diff --git a/modules/claim/front/photos/index.js b/modules/claim/front/photos/index.js index baf5fd154..0389e2d63 100644 --- a/modules/claim/front/photos/index.js +++ b/modules/claim/front/photos/index.js @@ -3,28 +3,13 @@ import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const dmsFk = this.photos[this.dmsIndex].dmsFk; - const query = `claimDms/${dmsFk}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Photo deleted')); + deleteDms(index) { + const dmsFk = this.photos[index].dmsFk; + return this.$http.post(`ClaimDms/${dmsFk}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Photo deleted')); }); - } } onDrop($event) { @@ -36,10 +21,10 @@ class Controller extends Section { } setDefaultParams() { - const params = {filter: { + const filter = { where: {code: 'claim'} - }}; - return this.$http.get('DmsTypes/findOne', {params}).then(res => { + }; + return this.$http.get('DmsTypes/findOne', {filter}).then(res => { const dmsTypeId = res.data && res.data.id; const companyId = this.vnConfig.companyFk; const warehouseId = this.vnConfig.warehouseFk; @@ -50,7 +35,7 @@ class Controller extends Section { warehouseId: warehouseId, companyId: companyId, dmsTypeId: dmsTypeId, - description: this.$translate.instant('FileDescription', { + description: this.$t('FileDescription', { claimId: this.claim.id, clientId: this.claim.client.id, clientName: this.claim.client.name @@ -91,7 +76,7 @@ class Controller extends Section { data: this.dms.files }; this.$http(options).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Photo uploaded!')); + this.vnApp.showSuccess(this.$t('Photo uploaded!')); this.$.model.refresh(); }); } diff --git a/modules/claim/front/photos/index.spec.js b/modules/claim/front/photos/index.spec.js index 1172800f6..9cb893bae 100644 --- a/modules/claim/front/photos/index.spec.js +++ b/modules/claim/front/photos/index.spec.js @@ -6,16 +6,13 @@ describe('Claim', () => { let $scope; let $httpBackend; let controller; - let $httpParamSerializer; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { - $httpParamSerializer = _$httpParamSerializer_; + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnClaimPhotos', {$element, $scope}); + controller = $componentController('vnClaimPhotos', {$element: null, $scope}); controller.$.model = crudModel; controller.claim = { id: 1, @@ -25,31 +22,25 @@ describe('Claim', () => { describe('deleteDms()', () => { it('should make an HTTP Post query', () => { - const dmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.photos = [{dmsFk: 1}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `claimDms/${dmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `claimDms/${dmsId}/removeFile`); - controller.deleteDms('accept'); + const dmsId = 1; + const dmsIndex = 0; + controller.photos = [{dmsFk: 1}]; + + $httpBackend.expectPOST(`ClaimDms/${dmsId}/removeFile`).respond(); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo deleted'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('setDefaultParams()', () => { it('should make an HTTP GET query, then set all dms properties', () => { - const params = {filter: { - where: {code: 'claim'} - }}; - let serializedParams = $httpParamSerializer(params); - $httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({}); - $httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`); + $httpBackend.expectRoute('GET', `DmsTypes/findOne`).respond({}); controller.setDefaultParams(); $httpBackend.flush(); @@ -67,13 +58,12 @@ describe('Claim', () => { controller.dmsIndex = dmsIndex; controller.dms = {files: []}; - $httpBackend.when('POST', `claims/${claimId}/uploadFile`).respond({}); - $httpBackend.expect('POST', `claims/${claimId}/uploadFile`); + $httpBackend.expectPOST(`claims/${claimId}/uploadFile`).respond({}); controller.create(); $httpBackend.flush(); - expect(controller.$.model.refresh).toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo uploaded!'); + expect(controller.$.model.refresh).toHaveBeenCalled(); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index 082030b30..e9ceb796f 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -1,9 +1,13 @@ -
+ - -
- - - - - - - -
-
- Send consumer report -
- + + + + + + + +
+
+ Send consumer report +
+ + + - - -
-
- - - - -
\ No newline at end of file +
+
+ + + + +
+ \ No newline at end of file diff --git a/modules/client/front/descriptor/index.js b/modules/client/front/descriptor/index.js index 2255a557c..f7b6bdda0 100644 --- a/modules/client/front/descriptor/index.js +++ b/modules/client/front/descriptor/index.js @@ -2,17 +2,17 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { - constructor($element, $, $httpParamSerializer) { - super($element, $); + constructor($element, $, $transclude, $httpParamSerializer) { + super($element, $, $transclude); this.$httpParamSerializer = $httpParamSerializer; } get client() { - return this._client; + return this.entity; } set client(value) { - this._client = value; + this.entity = value; if (!value) return; if (this.$params.sendSMS) @@ -33,7 +33,7 @@ class Controller extends Descriptor { } get filter() { - return this.client ? JSON.stringify({clientFk: this.client.id}) : null; + return JSON.stringify({clientFk: this.client.id}); } showSMSDialog() { @@ -56,11 +56,10 @@ class Controller extends Descriptor { window.open(`api/report/campaign-metrics?${params}`); } } - -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; +Controller.$inject = ['$element', '$scope', '$transclude', '$httpParamSerializer']; ngModule.vnComponent('vnClientDescriptor', { - template: require('./index.html'), + slotTemplate: require('./index.html'), bindings: { client: '<' }, diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index 987613d72..fd1527e23 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -62,7 +62,7 @@ + ng-click="workerDescriptor.show($event, document.dms.workerFk)"> {{::document.dms.worker.user.nickname | dashIfEmpty}} @@ -86,7 +86,7 @@ @@ -109,5 +109,5 @@ vn-id="confirm" message="This file will be deleted" question="Are you sure you want to continue?" - on-response="$ctrl.deleteDms($response)"> + on-accept="$ctrl.deleteDms($data)"> \ No newline at end of file diff --git a/modules/client/front/dms/index/index.js b/modules/client/front/dms/index/index.js index 2b47c3e57..577aff5be 100644 --- a/modules/client/front/dms/index/index.js +++ b/modules/client/front/dms/index/index.js @@ -24,8 +24,7 @@ class Controller extends Section { scope: { fields: ['name'] } - }, - { + }, { relation: 'worker', scope: { fields: ['userFk'], @@ -42,28 +41,13 @@ class Controller extends Section { }; } - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const dmsFk = this.clientDms[this.dmsIndex].dmsFk; - const query = `clientDms/${dmsFk}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + deleteDms(index) { + const dmsFk = this.clientDms[index].dmsFk; + return this.$http.post(`ClientDms/${dmsFk}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Data saved!')); }); - } } } diff --git a/modules/client/front/dms/index/index.spec.js b/modules/client/front/dms/index/index.spec.js index 816e8a25d..e94cca806 100644 --- a/modules/client/front/dms/index/index.spec.js +++ b/modules/client/front/dms/index/index.spec.js @@ -12,27 +12,25 @@ describe('Client', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnClientDmsIndex', {$element, $scope}); + controller = $componentController('vnClientDmsIndex', {$element: null, $scope}); controller.$.model = crudModel; })); describe('deleteDms()', () => { it('should make an HTTP Post query', () => { - const dmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.clientDms = [{dmsFk: 1}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `clientDms/${dmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `clientDms/${dmsId}/removeFile`); - controller.deleteDms('accept'); + const dmsId = 1; + const dmsIndex = 0; + controller.clientDms = [{dmsFk: 1}]; + + $httpBackend.expectPOST(`ClientDms/${dmsId}/removeFile`).respond(); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/client/front/sample/index/index.html b/modules/client/front/sample/index/index.html index 78d46f56a..bd7fc6e4a 100644 --- a/modules/client/front/sample/index/index.html +++ b/modules/client/front/sample/index/index.html @@ -29,9 +29,10 @@ {{::sample.type.description}} - - {{::sample.worker.user.nickname}} + + {{::sample.worker.user.nickname}} {{::sample.company.code}} diff --git a/modules/client/front/sample/index/index.js b/modules/client/front/sample/index/index.js index 48f9319ce..c5e8a72cd 100644 --- a/modules/client/front/sample/index/index.js +++ b/modules/client/front/sample/index/index.js @@ -11,8 +11,7 @@ class Controller extends Section { scope: { fields: ['code', 'description'] } - }, - { + }, { relation: 'worker', scope: { fields: ['userFk'], @@ -23,8 +22,7 @@ class Controller extends Section { } } } - }, - { + }, { relation: 'company', scope: { fields: ['code'] @@ -33,20 +31,8 @@ class Controller extends Section { ] }; } - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; - - event.preventDefault(); - event.stopImmediatePropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } } -Controller.$inject = ['$element', '$scope']; - ngModule.component('vnClientSampleIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/entry/front/index/index.html b/modules/entry/front/index/index.html index 70601e104..99af23ee6 100644 --- a/modules/entry/front/index/index.html +++ b/modules/entry/front/index/index.html @@ -43,7 +43,7 @@ + vn-click-stop="travelDescriptor.show($event, entry.travelFk)"> {{::entry.landed | date:'dd/MM/yyyy'}} @@ -64,15 +64,8 @@ - + - - - - - - \ No newline at end of file + vn-id="travelDescriptor"> + \ No newline at end of file diff --git a/modules/entry/front/index/index.js b/modules/entry/front/index/index.js index ab0a901b7..c10308bf7 100644 --- a/modules/entry/front/index/index.js +++ b/modules/entry/front/index/index.js @@ -1,17 +1,8 @@ import ngModule from '../module'; import Section from 'salix/components/section'; import './style.scss'; -export default class Controller extends Section { - showTravelDescriptor(event, travelFk) { - if (event.defaultPrevented) return; - event.preventDefault(); - event.stopPropagation(); - this.selectedTravel = travelFk; - this.$.travelDescriptor.parent = event.target; - this.$.travelDescriptor.show(); - } -} +export default class Controller extends Section {} ngModule.component('vnEntryIndex', { template: require('./index.html'), diff --git a/modules/entry/front/index/style.scss b/modules/entry/front/index/style.scss index ab759d2cc..bb8f48df5 100644 --- a/modules/entry/front/index/style.scss +++ b/modules/entry/front/index/style.scss @@ -1,5 +1,5 @@ @import "variables"; - vn-icon[icon=insert_drive_file]{ - color: $color-font-secondary; - } +vn-icon[icon=insert_drive_file] { + color: $color-font-secondary; +} diff --git a/modules/item/front/request/index.html b/modules/item/front/request/index.html index 0516e7ff5..f75ee2df4 100644 --- a/modules/item/front/request/index.html +++ b/modules/item/front/request/index.html @@ -3,18 +3,18 @@ url="TicketRequests/filter" limit="20" data="requests" - order="shipped DESC, isOk ASC"> + order="shipped DESC, isOk ASC" + auto-load="true">
- + info="Search request by id or alias" + model="model" + auto-state="false"> - - @@ -36,7 +36,7 @@ + ng-click="ticketDescriptor.show($event, request.ticketFk)"> {{request.ticketFk}} @@ -52,7 +52,7 @@ + ng-click="workerDescriptor.show($event, request.attenderFk)"> {{::request.atenderNickname}} @@ -76,7 +76,7 @@ {{request.itemDescription}} @@ -111,16 +111,17 @@ vn-id="itemDescriptor"> + on-close="$ctrl.denyObservation = null"> + + Specify the reasons to deny this request + -
Specify the reasons to deny this request
- - - - + +
diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index 51035c468..8383343de 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -25,11 +25,6 @@ export default class Controller extends Section { } } - $postLink() { - if (this.filter) - this.onSearch(this.filter); - } - getState(isOk) { if (isOk === null) return 'Nueva'; @@ -62,11 +57,11 @@ export default class Controller extends Section { quantity: request.saleQuantity }; - let endpoint = `Sales/${request.saleFk}/`; + let endpoint = `Sales/${request.saleFk}`; - this.$http.patch(endpoint, params).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); - }).then(() => this.confirmRequest(request)); + this.$http.patch(endpoint, params) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) + .then(() => this.confirmRequest(request)); } else this.confirmRequest(request); } @@ -85,69 +80,20 @@ export default class Controller extends Section { return 'success'; } - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } - - showDenyReason(event, requestId) { - this.selectedRequest = requestId; - this.$.denyReason.parent = event.target; - this.$.denyReason.show(); - } - - clear() { - delete this.denyRequestId; - } - onDenyAccept(request) { let params = { observation: this.denyObservation }; - 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; + return this.$http.post(`TicketRequests/${request.id}/deny`, 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!')); - }); - } - - onDenyClose() { - this.denyObservation = null; - } - - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showItemDescriptor(event, itemFk) { - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } - - preventNavigation(event) { - event.preventDefault(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); } } diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index 042b20996..8e384b04e 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -1,5 +1,4 @@ import './index.js'; -import crudModel from 'core/mocks/crud-model'; describe('Item', () => { describe('Component vnItemRequest', () => { @@ -12,10 +11,7 @@ describe('Item', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $scope.model = crudModel; - $scope.denyReason = {hide: () => {}}; - const $element = angular.element(''); - controller = $componentController('vnItemRequest', {$element, $scope}); + controller = $componentController('vnItemRequest', {$element: null, $scope}); })); afterAll(() => { @@ -49,23 +45,20 @@ describe('Item', () => { controller.confirmRequest(request); - expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).not.toHaveBeenCalled(); }); it('should perform a query and call vnApp.showSuccess() and refresh if the conditions are met', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - let model = controller.$.model; - jest.spyOn(model, 'refresh'); const expectedResult = {concept: 'Melee Weapon'}; let request = {itemFk: 1, saleQuantity: 1, id: 1}; - $httpBackend.when('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult); - $httpBackend.expect('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult); + $httpBackend.expectPOST(`TicketRequests/${request.id}/confirm`).respond(expectedResult); controller.confirmRequest(request); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); @@ -83,19 +76,17 @@ 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(); + $httpBackend.expectPATCH(`Sales/${request.saleFk}`).respond(); controller.changeQuantity(request); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('compareDate()', () => { it(`should return "success" if receives a future date`, () => { let date = '3019-02-18T11:00:00.000Z'; - let result = controller.compareDate(date); expect(result).toEqual('success'); @@ -103,7 +94,6 @@ describe('Item', () => { it(`should return "warning" if date is today`, () => { let date = new Date(); - let result = controller.compareDate(date); expect(result).toEqual('warning'); @@ -117,9 +107,8 @@ describe('Item', () => { response: 'new' }; - const url = `TicketRequests/:id/deny`; - $httpBackend.expectRoute('POST', url).respond({response: 'denied'}); - + $httpBackend.expectPOST(`TicketRequests/${request.id}/deny`) + .respond({response: 'denied'}); controller.onDenyAccept(request); $httpBackend.flush(); diff --git a/modules/order/front/line/index.html b/modules/order/front/line/index.html index fcfb5b6ec..80aca98ec 100644 --- a/modules/order/front/line/index.html +++ b/modules/order/front/line/index.html @@ -37,7 +37,7 @@ on-error-src/>
- {{::row.itemFk | zeroFill:6}} diff --git a/modules/order/front/line/index.js b/modules/order/front/line/index.js index 9351c5df8..bd41acedc 100644 --- a/modules/order/front/line/index.js +++ b/modules/order/front/line/index.js @@ -48,13 +48,6 @@ class Controller extends Section { .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } - showDescriptor(event, itemFk) { - let descriptor = this.$.descriptor; - descriptor.itemFk = itemFk; - descriptor.parent = event.target; - descriptor.show(); - } - save() { this.$http.post(`Orders/${this.$params.id}/confirm`).then(() => { this.vnApp.showSuccess(this.$t('Order confirmed')); diff --git a/modules/order/front/line/index.spec.js b/modules/order/front/line/index.spec.js index 543ffeedc..458bbbdd8 100644 --- a/modules/order/front/line/index.spec.js +++ b/modules/order/front/line/index.spec.js @@ -6,7 +6,8 @@ describe('Order', () => { let controller; let $httpBackend; - let rows = [ + const vat = 10.5; + const rows = [ { quantity: 4, price: 10.5 @@ -23,11 +24,10 @@ describe('Order', () => { $httpBackend = _$httpBackend_; $state.params.id = 1; - $httpBackend.whenRoute('GET', `OrderRows`).respond(rows); - $httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, 10.5); + $httpBackend.whenGET(`OrderRows`).respond(rows); + $httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, vat); - let $element = angular.element('
'); - controller = $componentController('vnOrderLine', {$element}); + controller = $componentController('vnOrderLine', {$element: null}); })); describe('getRows()', () => { @@ -35,7 +35,7 @@ describe('Order', () => { controller.getRows(); $httpBackend.flush(); - expect(controller.rows).toBeDefined(); + expect(controller.rows).toEqual(rows); }); }); @@ -44,7 +44,7 @@ describe('Order', () => { controller.getVAT(); $httpBackend.flush(); - expect(controller.VAT).toBeDefined(); + expect(controller.VAT).toBe(vat); }); }); @@ -59,7 +59,7 @@ describe('Order', () => { $httpBackend.flush(); expect(controller.rows.length).toBe(1); - expect(controller.card.reload).toHaveBeenCalledWith(); + expect(controller.card.reload).toHaveBeenCalled(); }); }); }); diff --git a/modules/order/front/summary/index.html b/modules/order/front/summary/index.html index c7ee5b4b6..cafd49f8a 100644 --- a/modules/order/front/summary/index.html +++ b/modules/order/front/summary/index.html @@ -63,7 +63,7 @@
{{::row.itemFk | zeroFill:6}} diff --git a/modules/order/front/summary/index.js b/modules/order/front/summary/index.js index ca6c29522..bff80638d 100644 --- a/modules/order/front/summary/index.js +++ b/modules/order/front/summary/index.js @@ -4,10 +4,8 @@ import './style.scss'; class Controller extends Section { setSummary() { - this.$http.get(`Orders/${this.order.id}/summary`).then(res => { - if (res && res.data) - this.summary = res.data; - }); + this.$http.get(`Orders/${this.order.id}/summary`) + .then(res => this.summary = res.data); } get formattedAddress() { @@ -23,16 +21,6 @@ class Controller extends Section { if (this.order && this.order.id) this.setSummary(); } - - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnOrderSummary', { diff --git a/modules/order/front/summary/index.spec.js b/modules/order/front/summary/index.spec.js index 2fa7c1c93..f0e831aab 100644 --- a/modules/order/front/summary/index.spec.js +++ b/modules/order/front/summary/index.spec.js @@ -16,14 +16,15 @@ describe('Order', () => { describe('getSummary()', () => { it('should now perform a GET query and define the summary property', () => { - let res = {id: 1, nickname: 'Batman'}; - $httpBackend.when('GET', `Orders/1/summary`).respond(200, res); - $httpBackend.expect('GET', `Orders/1/summary`); + let res = { + id: 1, + nickname: 'Batman' + }; + $httpBackend.expectGET(`Orders/1/summary`).respond(res); controller.setSummary(); $httpBackend.flush(); - expect(controller.summary).toBeDefined(); - expect(controller.summary.nickname).toEqual('Batman'); + expect(controller.summary).toEqual(res); }); }); diff --git a/modules/order/front/volume/index.html b/modules/order/front/volume/index.html index 36451f517..f15e4897b 100644 --- a/modules/order/front/volume/index.html +++ b/modules/order/front/volume/index.html @@ -34,7 +34,7 @@ {{::row.itemFk}} diff --git a/modules/order/front/volume/index.js b/modules/order/front/volume/index.js index f28763612..5941611ee 100644 --- a/modules/order/front/volume/index.js +++ b/modules/order/front/volume/index.js @@ -16,27 +16,15 @@ class Controller extends Section { onDataChange() { this.$http.get(`Orders/${this.$params.id}/getVolumes`) - .then(response => { - if (response.data) { - this.$.model.data.forEach(order => { - response.data.volumes.forEach(volume => { - if (order.itemFk === volume.itemFk) - order.volume = volume.volume; - }); + .then(res => { + this.$.model.data.forEach(order => { + res.data.volumes.forEach(volume => { + if (order.itemFk === volume.itemFk) + order.volume = volume.volume; }); - } + }); }); } - - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnOrderVolume', { diff --git a/modules/order/front/volume/index.spec.js b/modules/order/front/volume/index.spec.js index 194592406..241277d78 100644 --- a/modules/order/front/volume/index.spec.js +++ b/modules/order/front/volume/index.spec.js @@ -4,58 +4,39 @@ describe('Order', () => { describe('Component vnOrderVolume', () => { let controller; let $httpBackend; - let $state; let $scope; beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => { + beforeEach(angular.mock.inject(($componentController, $state, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $scope.model = {data: [{itemFk: 1}, {itemFk: 2}], accept: () => { - return { - then: () => {} - }; - }}; - $scope.descriptor = {show: () => {}}; - $scope.popover = {relocate: () => {}}; - $state = _$state_; + $scope.model = { + data: [ + {itemFk: 1}, + {itemFk: 2} + ] + }; + $state.params.id = 1; const $element = angular.element(''); controller = $componentController('vnOrderVolume', {$element, $scope}); })); it('should join the sale volumes to its respective sale', () => { - let response = {volumes: [{itemFk: 1, volume: 0.008}, {itemFk: 2, volume: 0.003}]}; - $httpBackend.whenGET(`Orders/1/getVolumes`).respond(response); - $httpBackend.expectGET(`Orders/1/getVolumes`); + let response = { + volumes: [ + {itemFk: 1, volume: 0.008}, + {itemFk: 2, volume: 0.003} + ] + }; + + $httpBackend.expectGET(`Orders/1/getVolumes`).respond(response); controller.onDataChange(); $httpBackend.flush(); 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.$.descriptor, 'show'); - controller.showDescriptor(event, itemFk); - - 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.$.popover, 'relocate'); - controller.onDescriptorLoad(); - - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); }); }); diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index b2b8484ac..16f6ad827 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -26,7 +26,7 @@ + vn-click-stop="workerDescriptor.show($event, route.workerFk)"> {{::route.workerNickname}} @@ -37,7 +37,7 @@ {{::route.description | dashIfEmpty}} @@ -60,5 +60,4 @@ vn-bind="+" fixed-bottom-right> - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 0349af293..7014bc609 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -2,21 +2,7 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - preview(event, route) { - if (event.defaultPrevented) return; - event.preventDefault(); - event.stopPropagation(); - + preview(route) { this.routeSelected = route; this.$.summary.show(); } diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index d0b6ed880..43e295d53 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -9,8 +9,7 @@ class Controller extends Section { order: 'concept ASC', include: [{ relation: 'item', - }, - { + }, { relation: 'components', scope: { fields: ['componentFk', 'value'], diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 3b690cfd3..176eed754 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -60,7 +60,7 @@ + ng-click="workerDescriptor.show($event, document.dms.workerFk)"> {{::document.dms.worker.user.nickname | dashIfEmpty}} @@ -83,7 +83,7 @@ @@ -106,5 +106,5 @@ vn-id="confirm" message="This file will be deleted" question="Are you sure you want to continue?" - on-response="$ctrl.deleteDms($response)"> + on-accept="$ctrl.deleteDms($data)"> \ No newline at end of file diff --git a/modules/ticket/front/dms/index/index.js b/modules/ticket/front/dms/index/index.js index a37d15426..85349f59e 100644 --- a/modules/ticket/front/dms/index/index.js +++ b/modules/ticket/front/dms/index/index.js @@ -42,28 +42,13 @@ class Controller extends Section { }; } - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const dmsFk = this.ticketDms[this.dmsIndex].dmsFk; - const query = `ticketDms/${dmsFk}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + deleteDms(index) { + const dmsFk = this.ticketDms[index].dmsFk; + this.$http.post(`ticketDms/${dmsFk}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Data saved!')); }); - } } } diff --git a/modules/ticket/front/dms/index/index.spec.js b/modules/ticket/front/dms/index/index.spec.js index cd1fd0125..2cd63462a 100644 --- a/modules/ticket/front/dms/index/index.spec.js +++ b/modules/ticket/front/dms/index/index.spec.js @@ -10,27 +10,25 @@ describe('Ticket', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - const $element = angular.element(''); - controller = $componentController('vnTicketDmsIndex', {$element}); + controller = $componentController('vnTicketDmsIndex', {$element: null}); controller.$.model = crudModel; })); describe('deleteDms()', () => { it('should make an HTTP Post query', () => { - const dmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.ticketDms = [{dmsFk: 1}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `ticketDms/${dmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `ticketDms/${dmsId}/removeFile`); - controller.deleteDms('accept'); + const dmsId = 1; + const dmsIndex = 0; + controller.ticketDms = [{dmsFk: 1}]; + + $httpBackend.expectPOST(`ticketDms/${dmsId}/removeFile`).respond({}); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 3beb6ecde..8a33e051e 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -28,7 +28,7 @@ @@ -48,7 +48,7 @@ + ng-click="workerDescriptor.show($event, expedition.workerFk)"> {{::expedition.userNickname | dashIfEmpty}} @@ -66,8 +66,8 @@ vn-id="workerDescriptor"> \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 1079e0b21..090bbdfa3 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -2,17 +2,9 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - deleteExpedition(expedition) { - this.expeditionId = expedition.id; - this.$.deleteExpedition.show(); - } - - returnDialog(response) { - if (response === 'accept') { - this.$http.delete(`Expeditions/${this.expeditionId}`).then( - () => this.$.model.refresh() - ); - } + onDialogAccept(id) { + return this.$http.delete(`Expeditions/${id}`) + .then(() => this.$.model.refresh()); } showItemDescriptor(event, itemFk) { @@ -32,18 +24,6 @@ class Controller extends Section { this.$.itemDescriptor.parent = event.target; this.$.itemDescriptor.show(); } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketExpedition', { diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 839108df7..761dc1fb6 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -14,20 +14,17 @@ describe('Ticket', () => { $scope.model = { refresh: () => {} }; - const $element = angular.element(''); - controller = $componentController('vnTicketExpedition', {$element, $scope}); + controller = $componentController('vnTicketExpedition', {$element: null, $scope}); })); - describe('returnDialog()', () => { + describe('onDialogAccept()', () => { it('should perform a DELETE query', () => { jest.spyOn($scope.model, 'refresh'); - let response = 'accept'; - controller.expeditionId = 1; + const id = 1; - $httpBackend.when('DELETE', `Expeditions/1`).respond(200); - $httpBackend.expect('DELETE', `Expeditions/1`); - controller.returnDialog(response); + $httpBackend.expectDELETE(`Expeditions/${id}`).respond(200); + controller.onDialogAccept(id); $httpBackend.flush(); expect($scope.model.refresh).toHaveBeenCalledWith(); diff --git a/modules/ticket/front/picture/index.html b/modules/ticket/front/picture/index.html index e240d28ac..e4e8c1d0b 100644 --- a/modules/ticket/front/picture/index.html +++ b/modules/ticket/front/picture/index.html @@ -25,7 +25,7 @@

- + {{::sale.item.name}}

diff --git a/modules/ticket/front/picture/index.js b/modules/ticket/front/picture/index.js index 257a53e6c..50d7cc777 100644 --- a/modules/ticket/front/picture/index.js +++ b/modules/ticket/front/picture/index.js @@ -13,16 +13,6 @@ class Controller extends Section { } }; } - - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketPicture', { diff --git a/modules/ticket/front/request/index/index.html b/modules/ticket/front/request/index/index.html index 3dd8691d5..670470ccf 100644 --- a/modules/ticket/front/request/index/index.html +++ b/modules/ticket/front/request/index/index.html @@ -43,14 +43,14 @@ + ng-click="workerDescriptor.show($event, request.requesterFk)"> {{::request.requester.user.nickname | dashIfEmpty}} + ng-click="workerDescriptor.show($event, request.attenderFk)"> {{::request.atender.user.nickname | dashIfEmpty}} diff --git a/modules/ticket/front/request/index/index.js b/modules/ticket/front/request/index/index.js index c2e6dc123..122feae1c 100644 --- a/modules/ticket/front/request/index/index.js +++ b/modules/ticket/front/request/index/index.js @@ -16,8 +16,7 @@ class Controller extends Section { } } } - }, - { + }, { relation: 'requester', scope: { include: { @@ -27,8 +26,7 @@ class Controller extends Section { } } } - }, - { + }, { relation: 'sale' } ] @@ -60,14 +58,6 @@ class Controller extends Section { this.$.itemDescriptor.show(); } - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - getRequestState(state) { switch (state) { case null: diff --git a/modules/ticket/front/request/index/index.spec.js b/modules/ticket/front/request/index/index.spec.js index 17f085010..b62447fd5 100644 --- a/modules/ticket/front/request/index/index.spec.js +++ b/modules/ticket/front/request/index/index.spec.js @@ -6,9 +6,8 @@ describe('Ticket', () => { beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject($componentController => { - const $element = angular.element(''); - controller = $componentController('vnTicketRequestIndex', {$element}); + beforeEach(inject($componentController => { + controller = $componentController('vnTicketRequestIndex', {$element: null}); })); describe('getRequestState()', () => { diff --git a/modules/ticket/front/sale-checked/index.js b/modules/ticket/front/sale-checked/index.js index 1fd9b662b..9bb5fd19a 100644 --- a/modules/ticket/front/sale-checked/index.js +++ b/modules/ticket/front/sale-checked/index.js @@ -33,10 +33,6 @@ class Controller extends Section { this.$.descriptor.parent = event.target; this.$.descriptor.show(); } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketSaleChecked', { diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index b097653eb..967160915 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -52,7 +52,7 @@ + ng-click="workerDescriptor.show($event, sale.workerFk)"> {{::sale.userNickname | dashIfEmpty}} diff --git a/modules/ticket/front/sale-tracking/index.js b/modules/ticket/front/sale-tracking/index.js index 8dca9c026..bd41add25 100644 --- a/modules/ticket/front/sale-tracking/index.js +++ b/modules/ticket/front/sale-tracking/index.js @@ -18,18 +18,6 @@ class Controller extends Section { this.$.itemDescriptor.parent = event.target; this.$.itemDescriptor.show(); } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketSaleTracking', { diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 51798537f..efa4f0285 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -9,176 +9,175 @@ - - - - - - - - - - - - - - - -

Subtotal {{$ctrl.subtotal | currency: 'EUR':2}}

-

VAT {{$ctrl.VAT | currency: 'EUR':2}}

-

Total {{$ctrl.total | currency: 'EUR':2}}

-
-
- - - - - - - - - - Id - Quantity - Item - Price - Disc - Amount - - - - - - - - - - - - - - - - - - - - - - - - {{sale.itemFk}} - - - - {{id}} - {{name}} - - - - - {{sale.quantity}} - - - - - - - - - - - - - - - - - - - - - - {{sale.price | currency: 'EUR':2}} - - - - - {{(sale.discount / 100) | percentage}} - - - - {{$ctrl.getSaleTotal(sale) | currency: 'EUR':2}} - + + + + + + + + + + + + + + +

Subtotal {{$ctrl.subtotal | currency: 'EUR':2}}

+

VAT {{$ctrl.VAT | currency: 'EUR':2}}

+

Total {{$ctrl.total | currency: 'EUR':2}}

+
+
+ + + + + + + + + + Id + Quantity + Item + Price + Disc + Amount + + + + + + + + + + + + + + + + + + + + + + + {{sale.itemFk}} + + + + {{id}} - {{name}} + + + + + {{sale.quantity}} + + + + + + + + + + + + + + + + + + + + + + {{sale.price | currency: 'EUR':2}} + + + + + {{(sale.discount / 100) | percentage}} + + + + {{$ctrl.getSaleTotal(sale) | currency: 'EUR':2}} + + @@ -200,7 +199,6 @@ vn-bind="+" fixed-bottom-right> - diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 0bf960b1e..78cedc7f2 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -228,16 +228,6 @@ class Controller extends Section { } } - showRemoveLinesDialog() { - this.$.deleteLines.show(); - } - - showTransferPopover(event) { - this.setTransferParams(); - this.$.transfer.parent = event.target; - this.$.transfer.show(); - } - setTransferParams() { const checkedSales = JSON.stringify(this.checkedLines()); const sales = JSON.parse(checkedSales); @@ -312,10 +302,6 @@ class Controller extends Section { this.$.descriptor.show(); } - onDescriptorLoad() { - this.$.popover.relocate(); - } - showEditPricePopover(event, sale) { if (!this.isEditable) return; this.sale = sale; diff --git a/modules/ticket/front/summary/index.js b/modules/ticket/front/summary/index.js index 7e892b265..1ad9cf4b3 100644 --- a/modules/ticket/front/summary/index.js +++ b/modules/ticket/front/summary/index.js @@ -61,10 +61,6 @@ class Controller extends Section { this.$.descriptor.show(); } - onDescriptorLoad() { - this.$.popover.relocate(); - } - get isEditable() { try { return !this.ticket.state.state.alertLevel; diff --git a/modules/ticket/front/tracking/index/index.html b/modules/ticket/front/tracking/index/index.html index 99d0b838a..bf22bfb98 100644 --- a/modules/ticket/front/tracking/index/index.html +++ b/modules/ticket/front/tracking/index/index.html @@ -24,7 +24,7 @@ + ng-click="workerDescriptor.show($event, tracking.worker.user.id)"> {{::tracking.worker.user.nickname | dashIfEmpty}} diff --git a/modules/ticket/front/tracking/index/index.js b/modules/ticket/front/tracking/index/index.js index e58dc4300..2826cbf26 100644 --- a/modules/ticket/front/tracking/index/index.js +++ b/modules/ticket/front/tracking/index/index.js @@ -17,8 +17,7 @@ class Controller extends Section { } } } - }, - { + }, { relation: 'state', scope: { fields: ['name'] @@ -27,14 +26,6 @@ class Controller extends Section { ] }; } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } } ngModule.component('vnTicketTrackingIndex', { diff --git a/modules/ticket/front/volume/index.js b/modules/ticket/front/volume/index.js index bf616cb24..0395afa8d 100644 --- a/modules/ticket/front/volume/index.js +++ b/modules/ticket/front/volume/index.js @@ -60,10 +60,6 @@ class Controller extends Section { this.$.descriptor.parent = event.target; this.$.descriptor.show(); } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketVolume', { diff --git a/modules/ticket/front/volume/index.spec.js b/modules/ticket/front/volume/index.spec.js index 2f6efee21..7807bfe10 100644 --- a/modules/ticket/front/volume/index.spec.js +++ b/modules/ticket/front/volume/index.spec.js @@ -66,16 +66,21 @@ describe('ticket', () => { }); }); - /* it('should join the sale volumes to its respective sale', () => { + /* + it('should join the sale volumes to its respective sale', () => { controller.ticket = {id: 1}; - let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]}; - $httpBackend.whenGET(`tickets/1/getVolume`).respond(response); - $httpBackend.expectGET(`tickets/1/getVolume`); + let response = {volumes: [ + {saleFk: 1, m3: 0.008}, + {saleFk: 2, m3: 0.003} + ]}; + + $httpBackend.expectGET(`tickets/1/getVolume`).respond(response); controller.onDataChange(); $httpBackend.flush(); expect($scope.model.data[0].volume.m3).toBe(0.008); expect($scope.model.data[1].volume.m3).toBe(0.003); - }); */ + }); + */ }); }); diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 1bf1af61e..e1cc1c90f 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -56,7 +56,7 @@ - @@ -64,7 +64,7 @@ @@ -74,10 +74,7 @@
- - - @@ -87,5 +84,5 @@ vn-id="confirm" message="This file will be deleted" question="Are you sure you want to continue?" - on-response="$ctrl.deleteDms($response)"> + on-accept="$ctrl.deleteDms($data)"> \ No newline at end of file diff --git a/modules/worker/front/dms/index/index.js b/modules/worker/front/dms/index/index.js index d322145a0..a950c1a42 100644 --- a/modules/worker/front/dms/index/index.js +++ b/modules/worker/front/dms/index/index.js @@ -19,51 +19,37 @@ class Controller extends Component { 'file', 'created', ], - include: [{ - relation: 'dmsType', - scope: { - fields: ['name'] + include: [ + { + relation: 'dmsType', + scope: { + fields: ['name'] + } + }, { + relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + }, + } } - }, - { - relation: 'worker', - scope: { - fields: ['userFk'], - include: { - relation: 'user', - scope: { - fields: ['nickname'] - } - }, - } - }] + ] }, } }; } - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const workerDmsId = this.workerDms[this.dmsIndex].id; - const query = `WorkerDms/${workerDmsId}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + deleteDms(index) { + const workerDmsId = this.workerDms[index].dmsFk; + return this.$http.post(`WorkerDms/${workerDmsId}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Data saved!')); }); - } } } diff --git a/modules/worker/front/dms/index/index.spec.js b/modules/worker/front/dms/index/index.spec.js index 074f11524..9c1e87011 100644 --- a/modules/worker/front/dms/index/index.spec.js +++ b/modules/worker/front/dms/index/index.spec.js @@ -4,36 +4,33 @@ import crudModel from 'core/mocks/crud-model'; describe('Worker', () => { describe('Component vnWorkerDmsIndex', () => { let $scope; - let $element; let $httpBackend; let controller; beforeEach(ngModule('worker')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { + beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $element = angular.element(` { it('should make an HTTP Post query', () => { - const workerDmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.workerDms = [{id: 1, dmsFk: 4}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `WorkerDms/${workerDmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `WorkerDms/${workerDmsId}/removeFile`); - controller.deleteDms('accept'); + const workerDmsId = 4; + const dmsIndex = 0; + controller.workerDms = [{id: 1, dmsFk: 4}]; + + $httpBackend.expectPOST(`WorkerDms/${workerDmsId}/removeFile`).respond(); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/worker/front/log/index.html b/modules/worker/front/log/index.html index bfa60a8c3..7b2ffa445 100644 --- a/modules/worker/front/log/index.html +++ b/modules/worker/front/log/index.html @@ -32,7 +32,7 @@ Changed by: {{::log.user.name | dashIfEmpty}}
@@ -53,7 +53,7 @@ {{::log.user.name | dashIfEmpty}} diff --git a/modules/worker/front/log/index.js b/modules/worker/front/log/index.js index 5e42687d3..421ffec63 100644 --- a/modules/worker/front/log/index.js +++ b/modules/worker/front/log/index.js @@ -42,18 +42,6 @@ export default class Controller extends Section { } } - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; - if (!workerFk) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - getInstance(instance) { const properties = []; let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/;