From 6a8e1bf6b5a2685239f744971b02f3a32bfe3a9c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 30 Apr 2020 12:48:52 +0200 Subject: [PATCH] #1882 Boileplate code removed, declarative quicklinks --- front/core/components/debug-info/index.js | 10 +- front/core/components/debug-info/style.scss | 7 +- front/core/components/popover/index.js | 1 + front/core/directives/specs/focus.spec.js | 2 +- front/core/lib/component.js | 1 + front/core/styles/layout.scss | 5 +- front/salix/components/app/app.html | 3 +- .../components/descriptor-popover/index.html | 5 - .../components/descriptor-popover/index.js | 64 +-- .../components/descriptor-popover/style.scss | 5 +- front/salix/components/descriptor/index.html | 27 +- front/salix/components/descriptor/index.js | 105 ++++- .../components/descriptor/quick-link.html | 2 +- .../salix/components/descriptor/quick-link.js | 2 +- .../components/descriptor/quick-links.html | 8 - .../components/descriptor/quick-links.js | 11 - front/salix/components/descriptor/style.scss | 139 +++--- front/salix/styles/order-product.scss | 1 + modules/claim/front/descriptor/index.html | 104 +++-- modules/claim/front/descriptor/index.js | 92 +--- modules/claim/front/descriptor/index.spec.js | 84 ++-- modules/claim/front/index/index.html | 1 - .../front/descriptor-popover/index.html | 5 +- .../client/front/descriptor-popover/index.js | 11 +- modules/client/front/descriptor/index.html | 147 +++--- modules/client/front/descriptor/index.js | 51 +-- .../index.spec.js | 7 +- modules/entry/front/descriptor/index.html | 58 +-- modules/entry/front/descriptor/index.js | 71 +-- modules/entry/front/descriptor/index.spec.js | 23 +- .../front/descriptor-popover/index.html | 4 +- .../front/descriptor-popover/index.js | 27 +- .../invoiceOut/front/descriptor/index.html | 87 ++-- modules/invoiceOut/front/descriptor/index.js | 92 ++-- modules/invoiceOut/front/index/index.html | 1 - .../item/front/descriptor-popover/index.html | 11 +- .../item/front/descriptor-popover/index.js | 28 +- .../front/descriptor-popover/index.spec.js | 29 -- modules/item/front/descriptor/index.html | 146 +++--- modules/item/front/descriptor/index.js | 101 ++--- modules/item/front/descriptor/index.spec.js | 36 ++ modules/item/front/diary/index.html | 2 - modules/order/front/catalog-view/index.html | 94 ++-- modules/order/front/catalog-view/index.js | 11 +- modules/order/front/descriptor/index.html | 88 ++-- modules/order/front/descriptor/index.js | 43 +- modules/order/front/descriptor/index.spec.js | 30 +- modules/order/front/index/index.html | 1 - .../route/front/descriptor-popover/index.html | 11 +- .../route/front/descriptor-popover/index.js | 65 +-- modules/route/front/descriptor/index.html | 75 ++-- modules/route/front/descriptor/index.js | 118 +++-- .../index.spec.js | 7 +- modules/route/front/summary/index.html | 2 +- modules/route/front/tickets/index.html | 2 +- modules/ticket/front/component/index.html | 5 +- modules/ticket/front/component/index.js | 21 - .../front/descriptor-popover/index.html | 4 +- .../ticket/front/descriptor-popover/index.js | 59 +-- .../front/descriptor-popover/index.spec.js | 30 -- modules/ticket/front/descriptor/index.html | 262 +++++++---- modules/ticket/front/descriptor/index.js | 420 +++++++----------- modules/ticket/front/descriptor/index.spec.js | 204 +++------ modules/ticket/front/expedition/index.html | 5 +- modules/ticket/front/expedition/index.js | 18 - modules/ticket/front/index/index.html | 1 - modules/ticket/front/picture/index.html | 2 +- modules/ticket/front/request/index/index.html | 4 +- modules/ticket/front/request/index/index.js | 16 - modules/ticket/front/sale-checked/index.html | 3 +- modules/ticket/front/sale-checked/index.js | 34 +- modules/ticket/front/sale-tracking/index.html | 5 +- modules/ticket/front/sale-tracking/index.js | 19 +- modules/ticket/front/sale/index.html | 5 +- modules/ticket/front/sale/index.js | 18 - modules/ticket/front/summary/index.html | 12 +- modules/ticket/front/summary/index.js | 32 -- modules/ticket/front/volume/index.html | 5 +- modules/ticket/front/volume/index.js | 17 - .../front/descriptor-popover/index.html | 4 +- .../travel/front/descriptor-popover/index.js | 36 +- modules/travel/front/descriptor/index.html | 38 +- modules/travel/front/descriptor/index.js | 47 +- .../index.spec.js | 9 +- .../front/descriptor-popover/index.html | 4 +- .../worker/front/descriptor-popover/index.js | 41 +- modules/worker/front/descriptor/index.html | 49 +- modules/worker/front/descriptor/index.js | 48 +- .../index.spec.js | 9 +- modules/zone/front/descriptor/index.html | 36 +- modules/zone/front/descriptor/index.js | 18 +- 91 files changed, 1558 insertions(+), 2145 deletions(-) delete mode 100644 front/salix/components/descriptor/quick-links.html delete mode 100644 front/salix/components/descriptor/quick-links.js rename modules/client/front/{descriptor-popover => descriptor}/index.spec.js (77%) delete mode 100644 modules/item/front/descriptor-popover/index.spec.js create mode 100644 modules/item/front/descriptor/index.spec.js rename modules/route/front/{descriptor-popover => descriptor}/index.spec.js (73%) delete mode 100644 modules/ticket/front/descriptor-popover/index.spec.js rename modules/travel/front/{descriptor-popover => descriptor}/index.spec.js (68%) rename modules/worker/front/{descriptor-popover => descriptor}/index.spec.js (68%) diff --git a/front/core/components/debug-info/index.js b/front/core/components/debug-info/index.js index 5e3d2e1ea..caac8126a 100644 --- a/front/core/components/debug-info/index.js +++ b/front/core/components/debug-info/index.js @@ -1,27 +1,31 @@ import ngModule from '../../module'; +import Component from '../../lib/component'; import './style.scss'; /** * Floating box displaying debugging information. * Enabled only in development environment. */ -export default class Controller { +export default class Controller extends Component { constructor($element, $) { + super($element, $); this.env = process.env.NODE_ENV || 'development'; if (this.env == 'development') this.interval = setInterval(() => $.$digest(), 2000); else $element[0].style.display = 'none'; + + $element[0].addEventListener('mouseover', + () => this.classList.toggle('right')); } $onDestroy() { clearInterval(this.interval); } } -Controller.$inject = ['$element', '$scope']; -ngModule.component('vnDebugInfo', { +ngModule.vnComponent('vnDebugInfo', { template: require('./index.html'), controller: Controller }); diff --git a/front/core/components/debug-info/style.scss b/front/core/components/debug-info/style.scss index b6171d4da..290b84890 100644 --- a/front/core/components/debug-info/style.scss +++ b/front/core/components/debug-info/style.scss @@ -1,6 +1,6 @@ @import "variables"; -vn-debug-info { +.vn-debug-info { position: fixed; bottom: 16px; left: 16px; @@ -13,8 +13,9 @@ vn-debug-info { box-shadow: $shadow; transition: opacity 400ms ease-in-out; - &:hover { - opacity: .5; + &.right { + left: auto; + right: 16px; } & > h6 { font-weight: normal; diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index f7ab30b62..c4cb5e9f7 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -8,6 +8,7 @@ import './style.scss'; * A simple popover. * * @property {HTMLElement} parent The parent element to show drop down relative to + * @property {HTMLElement} content Element holding the popover content * * @event open Thrown when popover is displayed * @event close Thrown when popover is hidden diff --git a/front/core/directives/specs/focus.spec.js b/front/core/directives/specs/focus.spec.js index dd917dc29..af88e7942 100644 --- a/front/core/directives/specs/focus.spec.js +++ b/front/core/directives/specs/focus.spec.js @@ -15,6 +15,7 @@ describe('Directive focus', () => { $element[0].focus = jasmine.createSpy('focus'); $element[0].select = jasmine.createSpy('select'); $compile($element)($scope); + $scope.$apply(); $flushPendingTasks(); }); }; @@ -37,7 +38,6 @@ describe('Directive focus', () => { it('should call select function on the element', () => { let html = ``; compile(html); - $scope.$apply(); expect($element[0].select).toHaveBeenCalledWith(); }); diff --git a/front/core/lib/component.js b/front/core/lib/component.js index 39d593cf0..e133519bb 100644 --- a/front/core/lib/component.js +++ b/front/core/lib/component.js @@ -184,6 +184,7 @@ runFn.$inject = [ '$translate', '$q', '$http', + '$httpParamSerializer', '$state', '$stateParams', '$timeout', diff --git a/front/core/styles/layout.scss b/front/core/styles/layout.scss index 8be4d1c73..5e77a02cb 100644 --- a/front/core/styles/layout.scss +++ b/front/core/styles/layout.scss @@ -29,11 +29,10 @@ html [wrap-reverse] { /* Horizontal & vertical childs */ html [vn-auto], vn-auto, .vn-auto { - flex-basis: auto; + flex: initial; } html [vn-none], vn-none, .vn-none { - flex: none; - flex-basis: .1px; + flex: none 0 1px; } html [vn-one], vn-one, .vn-one { flex: 1; diff --git a/front/salix/components/app/app.html b/front/salix/components/app/app.html index 310ce8166..d32c9f68b 100644 --- a/front/salix/components/app/app.html +++ b/front/salix/components/app/app.html @@ -6,5 +6,4 @@ ng-if="!$ctrl.showLayout"> - - + diff --git a/front/salix/components/descriptor-popover/index.html b/front/salix/components/descriptor-popover/index.html index bedb32f0f..224a81152 100644 --- a/front/salix/components/descriptor-popover/index.html +++ b/front/salix/components/descriptor-popover/index.html @@ -1,10 +1,5 @@ - -
diff --git a/front/salix/components/descriptor-popover/index.js b/front/salix/components/descriptor-popover/index.js index db2ae80c9..a96cb4b0d 100644 --- a/front/salix/components/descriptor-popover/index.js +++ b/front/salix/components/descriptor-popover/index.js @@ -3,70 +3,14 @@ import Popover from 'core/components/popover'; import './style.scss'; export default class DescriptorPopover extends Popover { - constructor(...args) { - super(...args); - this._quicklinks = {}; - this.entity = null; - } - - get id() { - return this._id; - } - - set id(value) { - if (value == this._id) return; - this._id = value; - this.loadData(); - } - - get entity() { - return this._entity; - } - - set entity(value) { - this._entity = value; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - show(parent, id) { - if (id !== undefined) - this.id = id; super.show(parent); - } - /** - * Reloads the descriptor data. Should be implemented or overriden by child - * classes. - */ - loadData() { - throw new Error('DescriptorPopover::loadData() method not implemented'); - } - - getData(url, options) { - if (this.canceler) this.canceler.resolve(); - this.canceler = this.$q.defer(); - this.entity = null; - - options = Object.assign(options || {}, { - timeout: this.canceler.promise - }); - - this.relocate(); - return this.$http.get(url, options) - .then(res => { + const descriptor = this.content.querySelector('.vn-descriptor'); + descriptor.$ctrl.load(id) + .then(() => { this.$.$applyAsync(() => this.relocate()); - return res; - }) - .finally(() => this.canceler = null); + }); } } diff --git a/front/salix/components/descriptor-popover/style.scss b/front/salix/components/descriptor-popover/style.scss index 9d99f77bc..1ffaeb548 100644 --- a/front/salix/components/descriptor-popover/style.scss +++ b/front/salix/components/descriptor-popover/style.scss @@ -10,4 +10,7 @@ .descriptor-wrapper { width: 260px; } -} \ No newline at end of file + .vn-descriptor > .header > a:first-child { + visibility: hidden; + } +} diff --git a/front/salix/components/descriptor/index.html b/front/salix/components/descriptor/index.html index d44e0eaba..29dcd3d57 100644 --- a/front/salix/components/descriptor/index.html +++ b/front/salix/components/descriptor/index.html @@ -1,9 +1,26 @@ -
+
+
+ + + + + + + + +
+ +
+
+
\ No newline at end of file diff --git a/front/salix/components/descriptor/index.js b/front/salix/components/descriptor/index.js index 11742b509..eadb3f7c7 100644 --- a/front/salix/components/descriptor/index.js +++ b/front/salix/components/descriptor/index.js @@ -1,39 +1,126 @@ import ngModule from '../../module'; import Component from 'core/lib/component'; import './style.scss'; -import './quick-links'; import './quick-link'; export default class Descriptor extends Component { + $postLink() { + const content = this.element.querySelector('vn-descriptor-content'); + + if (content) { + angular.element(content) + .controller('vnDescriptorContent') + .descriptor = this; + } + } + + get id() { + return this._id; + } + + set id(value) { + this.load(value); + } + get entity() { return this._entity; } set entity(value) { this._entity = value; + this._id = value && value.id; } - get quicklinks() { - return this._quicklinks; + load(id) { + if (id == this._id) + return this.$q.resolve(); + + this._id = id; + + if (!id) { + this.entity = null; + return this.$q.resolve(); + } + + return this.loadData(); } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); + /** + * Reloads the descriptor data. Should be implemented or overriden by child + * classes. + */ + loadData() { + throw new Error('DescriptorPopover::loadData() method not implemented'); + } + + /** + * Performs a cancellable request. + * + * @param {String} url The http path + * @param {Object} options The request options + * @return {Promise} Resolved with request response + */ + getData(url, options) { + if (this.canceler) this.canceler.resolve(); + this.canceler = this.$q.defer(); + this.entity = null; + + options = Object.assign(options || {}, { + timeout: this.canceler.promise + }); + + return this.$http.get(url, options) + .finally(() => this.canceler = null); + } + + /** + * Shows a report in another window, automatically adds the authorization + * token to params. + * + * @param {String} report The report name + * @param {Object} params The report parameters + */ + showReport(report, params) { + params = Object.assign({ + authorization: this.vnToken.token + }, params); + const serializedParams = this.$httpParamSerializer(params); + window.open(`api/report/${report}?${serializedParams}`); + } + + /** + * Sends an email displaying a notification when it's sent. + * + * @param {String} report The email report name + * @param {Object} params The email parameters + * @return {Promise} Promise resolved when it's sent + */ + sendEmail(report, params) { + return this.$http.get(`email/${report}`, {params}) + .then(() => this.vnApp.showMessage(this.$t('Notification sent!'))); } } -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-links.js b/front/salix/components/descriptor/quick-links.js deleted file mode 100644 index e7f9bdb24..000000000 --- a/front/salix/components/descriptor/quick-links.js +++ /dev/null @@ -1,11 +0,0 @@ -import ngModule from '../../module'; - -export default class QuickLinks {} - -ngModule.component('vnQuickLinks', { - template: require('./quick-links.html'), - controller: QuickLinks, - bindings: { - links: ' vn-descriptor-content { + & > div { + display: block; + box-shadow: 0 1px 3px $color-shadow; - & > .header { - display: flex; - background: $color-main; - justify-content: space-between; - align-items: stretch; - color: $color-font-dark; - - & > * { - @extend %clickable; - min-width: 45px; - height: 45px; - box-sizing: border-box; + & > .header { display: flex; - align-items: center; - justify-content: center; - color: inherit; + background: $color-main; + justify-content: space-between; + align-items: stretch; + color: $color-font-dark; - & > vn-icon { - padding: 10px; - } - vn-icon { - font-size: 1.75rem; - } - } - } - & > .body { - padding: $spacing-sm; - - & > * { - padding: $spacing-sm; - } - & > .attributes > h5 { - padding-bottom: $spacing-sm; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - } - & > .icons { - display: flex; - align-items: center; - justify-content: center; - padding: 0; - - & > vn-icon { - padding: $spacing-sm; - color: $color-marginal; - font-size: 1.5rem; - - &.bright { - color: $color-main; - opacity: 1; - } - } - } - .quicklinks, - vn-quick-links { - display: flex; - align-items: center; - justify-content: center; - - & > a, - vn-quick-link > a { + & > * { + @extend %clickable; + min-width: 45px; + height: 45px; + box-sizing: border-box; display: flex; align-items: center; justify-content: center; - padding: 0 $spacing-md; - margin: 0 $spacing-sm; + color: inherit; & > vn-icon { + padding: 10px; + } + vn-icon { font-size: 1.75rem; - padding: 0; + } + } + } + & > div > slot-body { + display: block; + padding: $spacing-sm; + + & > * { + padding: $spacing-sm; + } + & > .attributes > h5 { + padding-bottom: $spacing-sm; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + } + & > .icons { + display: flex; + align-items: center; + justify-content: center; + padding: 0; + + & > vn-icon { + padding: $spacing-sm; + color: $color-marginal; + font-size: 1.5rem; + + &.bright { + color: $color-main; + opacity: 1; + } + } + } + & > .quicklinks { + display: flex; + align-items: center; + justify-content: center; + + vn-quick-link > a { + display: flex; + align-items: center; + justify-content: center; + padding: 0 $spacing-md; + margin: 0 $spacing-sm; + + & > vn-icon { + font-size: 1.75rem; + padding: 0; + } } } } } } -.vn-popover { - .vn-descriptor > .header > a:first-child { - visibility: hidden; - } -} \ No newline at end of file diff --git a/front/salix/styles/order-product.scss b/front/salix/styles/order-product.scss index bd77144f2..11be8ebe0 100644 --- a/front/salix/styles/order-product.scss +++ b/front/salix/styles/order-product.scss @@ -6,6 +6,7 @@ justify-content: center; & > .product { + flex: initial; box-sizing: border-box; padding: $spacing-sm; width: 448px; diff --git a/modules/claim/front/descriptor/index.html b/modules/claim/front/descriptor/index.html index 789df37d6..752dff80f 100644 --- a/modules/claim/front/descriptor/index.html +++ b/modules/claim/front/descriptor/index.html @@ -1,61 +1,89 @@ -
-
- - - - - - - - -
-
+ + + + +
{{$ctrl.claim.id}}
- + - - + - - - + - +
- - -
-
+ + + diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index b65fc870b..ea7784f72 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -2,102 +2,42 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - {callback: this.showPickupOrder, name: 'Show Pickup order'}, - {callback: this.confirmPickupOrder, name: 'Send Pickup order'}, - {callback: this.confirmDeleteClaim, name: 'Delete claim', acl: 'salesAssistant'} - ]; - } - - onMoreOpen() { - let options = this.moreOptions.filter(option => { - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - - return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - }); - this.$.moreButton.data = options; - } - - onMoreChange(callback) { - callback.call(this); - } - get claim() { - return this._claim; + return this.entity; } set claim(value) { - this._claim = value; - - if (!value) return; - - this._quicklinks = { - btnOne: { - icon: 'person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - }, - btnTwo: { - icon: 'icon-ticket', - state: `ticket.card.summary({id: ${this.claim.ticketFk}})`, - tooltip: 'Claimed ticket' - } - }; + this.entity = value; } showPickupOrder() { - const params = { + this.showReport('claim-pickup-order', { clientId: this.claim.clientFk, - claimId: this.claim.id, - authorization: this.vnToken.token - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/claim-pickup-order?${serializedParams}`; - window.open(url); + claimId: this.claim.id + }); } - confirmPickupOrder() { - this.$.confirmPickupOrder.show(); + sendPickupOrder() { + return this.sendEmail('claim-pickup-order', { + recipient: this.claim.client.email, + clientId: this.claim.clientFk, + claimId: this.claim.id + }); } - sendPickupOrder(response) { - if (response === 'accept') { - const params = { - recipient: this.claim.client.email, - clientId: this.claim.clientFk, - claimId: this.claim.id - }; - this.$http.get(`email/claim-pickup-order`, {params}).then( - () => this.vnApp.showMessage(this.$t('Notification sent!')) - ); - } - } - - confirmDeleteClaim() { - this.$.confirmDeleteClaim.show(); - } - - deleteClaim(response) { - if (response === 'accept') { - this.$http.delete(`Claims/${this.claim.id}`).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Claim deleted!')); + deleteClaim() { + return this.$http.delete(`Claims/${this.claim.id}`) + .then(() => { + this.vnApp.showSuccess(this.$t('Claim deleted!')); this.$state.go('claim.index'); }); - } } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.vnComponent('vnClaimDescriptor', { template: require('./index.html'), controller: Controller, bindings: { - claim: '<', - tags: '<' + claim: '<' } }); diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js index 4a78bda5a..1a18141ca 100644 --- a/modules/claim/front/descriptor/index.spec.js +++ b/modules/claim/front/descriptor/index.spec.js @@ -1,96 +1,62 @@ import './index.js'; describe('Item Component vnClaimDescriptor', () => { - let $httpParamSerializer; let $httpBackend; - let $element; - let $scope; let controller; + const claim = { + id: 2, + clientFk: 101, + client: {email: 'client@email'} + }; + beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - $scope = $rootScope.$new(); - $element = angular.element(''); - controller = $componentController('vnClaimDescriptor', {$element, $scope}); - controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}}; + controller = $componentController('vnClaimDescriptor', {$element: null}, {claim}); })); describe('showPickupOrder()', () => { it('should open a new window showing a pickup order PDF document', () => { + controller.showReport = jest.fn(); + const params = { - clientId: controller.claim.clientFk, - claimId: controller.claim.id + clientId: claim.clientFk, + claimId: claim.id }; - const serializedParams = $httpParamSerializer(params); - let expectedPath = `api/report/claim-pickup-order?${serializedParams}`; - jest.spyOn(window, 'open').mockReturnThis(); controller.showPickupOrder(); - expect(window.open).toHaveBeenCalledWith(expectedPath); + expect(controller.showReport).toHaveBeenCalledWith('claim-pickup-order', params); }); }); - describe('confirmPickupOrder()', () => { - it('should call confirmPickupOrder.show()', () => { - controller.$.confirmPickupOrder = { - show: jasmine.createSpy('show') - }; - controller.claim = {id: 2}; - controller.confirmPickupOrder(); - - expect(controller.$.confirmPickupOrder.show).toHaveBeenCalledWith(); - }); - }); - - describe('sendPickupOrder(response)', () => { + describe('sendPickupOrder()', () => { it('should make a query and call vnApp.showMessage() if the response is accept', () => { - jest.spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller, 'sendEmail'); const params = { - recipient: 'client@email', - clientId: controller.claim.clientFk, - claimId: controller.claim.id + recipient: claim.client.email, + clientId: claim.clientFk, + claimId: claim.id }; - const serializedParams = $httpParamSerializer(params); + controller.sendPickupOrder(); - $httpBackend.when('GET', `email/claim-pickup-order?${serializedParams}`).respond(); - $httpBackend.expect('GET', `email/claim-pickup-order?${serializedParams}`).respond(); - controller.sendPickupOrder('accept'); - $httpBackend.flush(); - - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!'); + expect(controller.sendEmail).toHaveBeenCalledWith('claim-pickup-order', params); }); }); - describe('confirmDeleteClaim()', () => { - it('should call confirmDeleteClaim.show()', () => { - controller.$.confirmDeleteClaim = { - show: jasmine.createSpy('show') - }; - controller.claim = {id: 2}; - controller.confirmDeleteClaim(); - - expect(controller.$.confirmDeleteClaim.show).toHaveBeenCalledWith(); - }); - }); - - describe('deleteClaime(response)', () => { + describe('deleteClaim()', () => { it('should perform a query and call showSuccess if the response is accept', () => { - let response = 'accept'; - controller.claim = {id: 2}; - jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$state, 'go'); - $httpBackend.when('DELETE', `Claims/2`).respond(200); - $httpBackend.expect('DELETE', `Claims/2`); - controller.deleteClaim(response); + + $httpBackend.expectDELETE(`Claims/${claim.id}`).respond(); + controller.deleteClaim(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Claim deleted!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.$state.go).toHaveBeenCalledWith('claim.index'); }); }); diff --git a/modules/claim/front/index/index.html b/modules/claim/front/index/index.html index 98d283be7..42ae87971 100644 --- a/modules/claim/front/index/index.html +++ b/modules/claim/front/index/index.html @@ -65,4 +65,3 @@ claim="$ctrl.claimSelected"> - \ No newline at end of file diff --git a/modules/client/front/descriptor-popover/index.html b/modules/client/front/descriptor-popover/index.html index 714cc3d54..28c271abc 100644 --- a/modules/client/front/descriptor-popover/index.html +++ b/modules/client/front/descriptor-popover/index.html @@ -1,6 +1,3 @@ - - + \ No newline at end of file diff --git a/modules/client/front/descriptor-popover/index.js b/modules/client/front/descriptor-popover/index.js index 5b0ca0d20..12f7a1664 100644 --- a/modules/client/front/descriptor-popover/index.js +++ b/modules/client/front/descriptor-popover/index.js @@ -1,16 +1,7 @@ import ngModule from '../module'; import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends DescriptorPopover { - get client() { - return this.entity; - } - - loadData() { - return this.getData(`Clients/${this.id}/getCard`) - .then(res => this.entity = res.data); - } -} +class Controller extends DescriptorPopover {} ngModule.vnComponent('vnClientDescriptorPopover', { slotTemplate: require('./index.html'), diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index e9ceb796f..1c0791121 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -1,21 +1,30 @@ - -
- - - - - - - - -
-
+ + + + +
{{$ctrl.client.name}}
- - - - - - - - -
-
- 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 f7b6bdda0..9948eab43 100644 --- a/modules/client/front/descriptor/index.js +++ b/modules/client/front/descriptor/index.js @@ -2,9 +2,15 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { - constructor($element, $, $transclude, $httpParamSerializer) { - super($element, $, $transclude); - this.$httpParamSerializer = $httpParamSerializer; + get entity() { + return super.entity; + } + + set entity(value) { + super.entity = value; + + if (this.$params.sendSMS) + this.showSMSDialog(); } get client() { @@ -13,33 +19,21 @@ class Controller extends Descriptor { set client(value) { this.entity = value; - if (!value) return; - - if (this.$params.sendSMS) - this.showSMSDialog(); - - this._quicklinks = { - btnOne: { - icon: 'icon-ticket', - state: `ticket.index({q: '{"clientFk": ${value.id}}'})`, - tooltip: 'Client ticket list' - }, - btnTwo: { - icon: 'icon-basketadd', - state: `order.create({clientFk: ${value.id}})`, - tooltip: 'New order' - } - }; } get filter() { - return JSON.stringify({clientFk: this.client.id}); + return JSON.stringify({clientFk: this.id}); + } + + loadData() { + return this.getData(`Clients/${this.id}/getCard`) + .then(res => this.entity = res.data); } showSMSDialog() { const client = this.client || {}; this.newSMS = { - destinationFk: client.id, + destinationFk: this.id, destination: this.$params.phone || client.mobile || client.phone, message: this.$params.message || '' }; @@ -47,21 +41,18 @@ class Controller extends Descriptor { } onConsumerReportAccept() { - const params = this.$httpParamSerializer({ - authorization: this.vnToken.token, - clientId: this.client.id, + this.showReport('campaign-metrics', { + clientId: this.id, from: this.from, to: this.to, }); - window.open(`api/report/campaign-metrics?${params}`); } } -Controller.$inject = ['$element', '$scope', '$transclude', '$httpParamSerializer']; ngModule.vnComponent('vnClientDescriptor', { - slotTemplate: require('./index.html'), + template: require('./index.html'), + controller: Controller, bindings: { client: '<' - }, - controller: Controller + } }); diff --git a/modules/client/front/descriptor-popover/index.spec.js b/modules/client/front/descriptor/index.spec.js similarity index 77% rename from modules/client/front/descriptor-popover/index.spec.js rename to modules/client/front/descriptor/index.spec.js index a3cee8249..1a123d901 100644 --- a/modules/client/front/descriptor-popover/index.spec.js +++ b/modules/client/front/descriptor/index.spec.js @@ -1,6 +1,6 @@ import './index'; -describe('vnClientDescriptorPopover', () => { +describe('vnClientDescriptor', () => { let controller; let $httpBackend; @@ -8,10 +8,7 @@ describe('vnClientDescriptorPopover', () => { beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnClientDescriptorPopover', { - $element: null, - $transclude: null - }); + controller = $componentController('vnClientDescriptor', {$element: null}); })); describe('loadData()', () => { diff --git a/modules/entry/front/descriptor/index.html b/modules/entry/front/descriptor/index.html index 917c5d721..a2b097785 100644 --- a/modules/entry/front/descriptor/index.html +++ b/modules/entry/front/descriptor/index.html @@ -1,23 +1,16 @@ -
-
- - - - - - - - -
-
+ + +
    +
  • +
    + Show entry report +
    +
  • +
+
+
@@ -47,8 +40,23 @@ ng-class="{bright: $ctrl.entry.isRaid}">
- - -
-
+ +
+
diff --git a/modules/entry/front/descriptor/index.js b/modules/entry/front/descriptor/index.js index 40ec6c026..338ccbfbc 100644 --- a/modules/entry/front/descriptor/index.js +++ b/modules/entry/front/descriptor/index.js @@ -2,74 +2,47 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - {name: 'Show entry report', callback: this.showEntryReport} - ]; - } - - onMoreChange(callback) { - callback.call(this); - } - get entry() { - return this._entry; + return this.entity; } set entry(value) { - this._entry = value; - if (!value) return; + this.entity = value; + } - const date = value.travel.landed; - let to = new Date(date); - let from = new Date(date); + get travelFilter() { + return JSON.stringify({agencyFk: this.entry.travel.agencyFk}); + } + + get entryFilter() { + const date = new Date(this.entry.travel.landed); + date.setHours(0, 0, 0, 0); + + const from = new Date(date.getTime()); + from.setDate(from.getDate() - 10); + + const to = new Date(date.getTime()); to.setDate(to.getDate() + 10); - to.setHours(0, 0, 0, 0); - - from.setDate(from.getDate() - 10); - from.setHours(0, 0, 0, 0); - - let links = { - btnOne: { - icon: 'local_airport', - state: `travel.index({q: '{"agencyFk": ${value.travel.agencyFk}}'})`, - tooltip: 'All travels with current agency' - }}; - - links.btnTwo = { - icon: 'icon-entry', - state: `entry.index({q: '{"supplierFk": ${value.supplierFk}, "to": "${to}", "from": "${from}"}'})`, - tooltip: 'All entries with current supplier' - }; - - this._quicklinks = links; + return JSON.stringify({ + supplierFk: this.entry.travel.supplierFk, + from, + to + }); } showEntryReport() { - const params = { - authorization: this.vnToken.token, + this.showReport('entry-order', { clientId: this.vnConfig.storage.currentUserWorkerId, entryId: this.entry.id - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/entry-order?${serializedParams}`; - window.open(url); + }); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.vnComponent('vnEntryDescriptor', { template: require('./index.html'), controller: Controller, bindings: { entry: '<' - }, - require: { - card: '^?vnEntryCard' } }); diff --git a/modules/entry/front/descriptor/index.spec.js b/modules/entry/front/descriptor/index.spec.js index f73604d51..c25755bcd 100644 --- a/modules/entry/front/descriptor/index.spec.js +++ b/modules/entry/front/descriptor/index.spec.js @@ -1,35 +1,26 @@ import './index.js'; describe('Entry Component vnEntryDescriptor', () => { - let $httpParamSerializer; let controller; - let $element; + const entry = {id: 2}; beforeEach(ngModule('entry')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$httpParamSerializer_) => { - $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(``); - controller = $componentController('vnEntryDescriptor', {$element}); - controller._entry = {id: 2}; - controller.vnConfig.storage = {currentUserWorkerId: 9}; - controller.cardReload = ()=> { - return true; - }; + beforeEach(inject($componentController => { + controller = $componentController('vnEntryDescriptor', {$element: null}, {entry}); })); describe('showEntryReport()', () => { it('should open a new window showing a delivery note PDF document', () => { + controller.showReport = jest.fn(); + const params = { clientId: controller.vnConfig.storage.currentUserWorkerId, - entryId: controller.entry.id + entryId: entry.id }; - const serializedParams = $httpParamSerializer(params); - let expectedPath = `api/report/entry-order?${serializedParams}`; - jest.spyOn(window, 'open').mockReturnThis(); controller.showEntryReport(); - expect(window.open).toHaveBeenCalledWith(expectedPath); + expect(controller.showReport).toHaveBeenCalledWith('entry-order', params); }); }); }); diff --git a/modules/invoiceOut/front/descriptor-popover/index.html b/modules/invoiceOut/front/descriptor-popover/index.html index 1c25a8257..2bd912133 100644 --- a/modules/invoiceOut/front/descriptor-popover/index.html +++ b/modules/invoiceOut/front/descriptor-popover/index.html @@ -1,6 +1,4 @@ - + \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor-popover/index.js b/modules/invoiceOut/front/descriptor-popover/index.js index 918707fb6..fc9899da0 100644 --- a/modules/invoiceOut/front/descriptor-popover/index.js +++ b/modules/invoiceOut/front/descriptor-popover/index.js @@ -1,32 +1,7 @@ import ngModule from '../module'; import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends DescriptorPopover { - get invoiceOut() { - return this.entity; - } - - loadData() { - const filter = { - include: [ - { - relation: 'company', - scope: { - fields: ['id', 'code'] - } - }, { - relation: 'client', - scope: { - fields: ['id', 'name'] - } - } - ] - }; - - return this.getData(`InvoiceOuts/${this.id}`, {filter}) - .then(res => this.entity = res.data); - } -} +class Controller extends DescriptorPopover {} ngModule.vnComponent('vnInvoiceOutDescriptorPopover', { slotTemplate: require('./index.html'), diff --git a/modules/invoiceOut/front/descriptor/index.html b/modules/invoiceOut/front/descriptor/index.html index 1c18d92ed..bdc7a18f5 100644 --- a/modules/invoiceOut/front/descriptor/index.html +++ b/modules/invoiceOut/front/descriptor/index.html @@ -1,43 +1,70 @@ -
-
- - - - - - - - -
-
+ + + + +
{{$ctrl.invoiceOut.ref}}
- - - + -
- - -
-
+ + + { - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - - return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - }); - this.$.moreButton.data = options; - } - - onMoreChange(callback) { - callback.call(this); + get invoiceOut() { + return this.entity; } set invoiceOut(value) { - this._invoiceOut = value; - - if (value) { - this._quicklinks = { - btnOne: { - icon: 'icon-person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - }, - btnTwo: { - icon: 'icon-ticket', - state: `ticket.index({q: '{"refFk": "${value.ref}"}'})`, - tooltip: 'Invoice ticket list' - } - }; - } - } - - get invoiceOut() { - return this._invoiceOut; - } - - showInvoiceOutPdf() { - let url = `api/InvoiceOuts/${this.invoiceOut.id}/download?access_token=${this.accessToken}`; - window.open(url, '_blank'); - } - - showDeleteInvoiceOutDialog() { - this.$.deleteConfirmation.show(); - } - - showBookInvoiceOutDialog() { - this.$.bookConfirmation.show(); + this.entity = value; } deleteInvoiceOut() { - const query = `InvoiceOuts/${this.invoiceOut.id}/delete`; - return this.$http.post(query) + return this.$http.post(`InvoiceOuts/${this.id}/delete`) .then(() => this.$state.go('invoiceOut.index')) .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted'))); } bookInvoiceOut() { - const query = `InvoiceOuts/${this.invoiceOut.ref}/book`; - return this.$http.post(query) + return this.$http.post(`InvoiceOuts/${this.invoiceOut.ref}/book`) .then(() => this.$state.reload()) .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked'))); } + + loadData() { + const filter = { + include: [ + { + relation: 'company', + scope: { + fields: ['id', 'code'] + } + }, { + relation: 'client', + scope: { + fields: ['id', 'name'] + } + } + ] + }; + + return this.getData(`InvoiceOuts/${this.id}`, {filter}) + .then(res => this.entity = res.data); + } } ngModule.vnComponent('vnInvoiceOutDescriptor', { diff --git a/modules/invoiceOut/front/index/index.html b/modules/invoiceOut/front/index/index.html index 52d296e86..d5b911153 100644 --- a/modules/invoiceOut/front/index/index.html +++ b/modules/invoiceOut/front/index/index.html @@ -65,4 +65,3 @@ - \ No newline at end of file diff --git a/modules/item/front/descriptor-popover/index.html b/modules/item/front/descriptor-popover/index.html index ccc2b899f..a1a1ec363 100644 --- a/modules/item/front/descriptor-popover/index.html +++ b/modules/item/front/descriptor-popover/index.html @@ -1,6 +1,11 @@ - + + + + + diff --git a/modules/item/front/descriptor-popover/index.js b/modules/item/front/descriptor-popover/index.js index 35918a171..a84fbafe1 100644 --- a/modules/item/front/descriptor-popover/index.js +++ b/modules/item/front/descriptor-popover/index.js @@ -2,28 +2,20 @@ import ngModule from '../module'; import DescriptorPopover from 'salix/components/descriptor-popover'; class Controller extends DescriptorPopover { - constructor(...args) { - super(...args); - this._quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({id: $ctrl.id})`, - tooltip: 'Item diary' - } + get diaryParams() { + return { + id: this.descriptor && this.descriptor.id, + warehouseFk: this.warehouseFk, + ticketFk: this.ticketFk }; } - - get item() { - return this.entity; - } - - loadData() { - return this.getData(`Items/${this.id}/getCard`) - .then(res => this.entity = res.data); - } } ngModule.vnComponent('vnItemDescriptorPopover', { slotTemplate: require('./index.html'), - controller: Controller + controller: Controller, + bindings: { + warehouseFk: ' { - let controller; - let $httpBackend; - - beforeEach(ngModule('item')); - - beforeEach(inject(($componentController, _$httpBackend_) => { - $httpBackend = _$httpBackend_; - controller = $componentController('vnItemDescriptorPopover', { - $element: null, - $transclude: null - }); - })); - - describe('loadData()', () => { - it(`should perform a get query to store the item data into the controller`, () => { - const id = 1; - const response = 'foo'; - - $httpBackend.expectGET(`Items/${id}/getCard`).respond(response); - controller.id = id; - $httpBackend.flush(); - - expect(controller.item).toEqual(response); - }); - }); -}); diff --git a/modules/item/front/descriptor/index.html b/modules/item/front/descriptor/index.html index d8e569491..2a849b70e 100644 --- a/modules/item/front/descriptor/index.html +++ b/modules/item/front/descriptor/index.html @@ -1,60 +1,56 @@ -
-
- - - - - - - - -
-
-
- - - - - + + +
    +
  • +
    + Regularize stock +
    +
  • +
+
+ +
+
+ + + + + +
+ + +

Visible

+

{{$ctrl.visible | dashIfEmpty}}

+
+ +

Available

+

{{$ctrl.available | dashIfEmpty}}

+
+
- - -

Visible

-

{{$ctrl.visible | dashIfEmpty}}

-
- -

Available

-

{{$ctrl.available | dashIfEmpty}}

-
-
-
-
{{$ctrl.item.id}}
- + - + ng-repeat="tag in $ctrl.item.tags | limitTo:4" + label="{{tag.tag.name}}" + value="{{tag.value}}">
@@ -64,36 +60,32 @@ ng-class="{bright: $ctrl.item.isActive == false}">
- - -
-
+ + + + on-open="$ctrl.warehouseFk = $ctrl.vnConfig.warehouseFk" + on-close="$ctrl.clearRegularizeDialog()" + on-accept="$ctrl.saveRegularize()"> + + Regularize stock + -
-
- Regularize stock -
- - - - -
+ + + +
diff --git a/modules/item/front/descriptor/index.js b/modules/item/front/descriptor/index.js index 81b14aeee..ab901faf5 100644 --- a/modules/item/front/descriptor/index.js +++ b/modules/item/front/descriptor/index.js @@ -3,85 +3,56 @@ import Descriptor from 'salix/components/descriptor'; import './style.scss'; class Controller extends Descriptor { - constructor($element, $) { - super($element, $); - this.moreOptions = [ - {callback: this.showRegularizeDialog, name: 'Regularize stock'} - ]; - } - - set quantity(value) { - this._quantity = parseInt(value); - } - - get quantity() { - return this._quantity; - } - - set warehouseFk(value) { - if (value) - this._warehouseFk = value; - } - get warehouseFk() { - if (!this._warehouseFk) - this._warehouseFk = this.vnConfig.warehouseFk; - - return this._warehouseFk; + get item() { + return this.entity; } set item(value) { - this._item = value; - if (value && value.itemType && value.itemType.warehouseFk) - this.updateStock(value.itemType.warehouseFk); + this.entity = value; } - get item() { - return this._item; + get entity() { + return super.entity; } - updateStock(warehouseFk) { + set entity(value) { + super.entity = value; + this.updateStock(); + } + + loadData() { + return this.getData(`Items/${this.id}/getCard`) + .then(res => this.entity = res.data); + } + + updateStock() { this.available = null; this.visible = null; - if (this._item && this._item.id) { - let options = { - params: { - warehouseFk: warehouseFk - } - }; - this.$http.get(`Items/${this._item.id}/getVisibleAvailable`, options).then(response => { - this.available = response.data.available; - this.visible = response.data.visible; + if (!this.item) return; + + const params = { + warehouseFk: this.item.itemType.warehouseFk + }; + + return this.$http.get(`Items/${this.id}/getVisibleAvailable`, {params}) + .then(res => { + this.available = res.data.available; + this.visible = res.data.visible; }); - } } - onMoreChange(callback) { - callback.call(this); - } + saveRegularize() { + const params = { + itemFk: this.id, + quantity: parseInt(this.quantity), + warehouseFk: this.warehouseFk + }; - showRegularizeDialog() { - this.$.regularize.show(); - } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - - saveRegularize(response) { - if (response == 'accept') { - this.$http.post(`Items/regularize`, { - itemFk: this.item.id, - quantity: this.quantity, - warehouseFk: this.warehouseFk - }).then(res => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.updateStock(this.item.itemType.warehouseFk); + return this.$http.post(`Items/regularize`, params) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.updateStock(); }); - } } clearRegularizeDialog() { diff --git a/modules/item/front/descriptor/index.spec.js b/modules/item/front/descriptor/index.spec.js new file mode 100644 index 000000000..7406d1800 --- /dev/null +++ b/modules/item/front/descriptor/index.spec.js @@ -0,0 +1,36 @@ +import './index'; + +describe('vnItemDescriptor', () => { + let controller; + let $httpBackend; + + const item = { + id: 1, + itemType: { + warehouseFk: 1 + } + }; + const stock = { + visible: 1, + available: 5 + }; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + $httpBackend.whenRoute('GET', `Items/${item.id}/getVisibleAvailable`).respond(stock); + + controller = $componentController('vnItemDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the item data into the controller`, () => { + $httpBackend.expectGET(`Items/${item.id}/getCard`).respond(item); + controller.id = item.id; + $httpBackend.flush(); + + expect(controller.item).toEqual(item); + }); + }); +}); diff --git a/modules/item/front/diary/index.html b/modules/item/front/diary/index.html index 45e24610b..f7b32621c 100644 --- a/modules/item/front/diary/index.html +++ b/modules/item/front/diary/index.html @@ -86,5 +86,3 @@ - - \ No newline at end of file diff --git a/modules/order/front/catalog-view/index.html b/modules/order/front/catalog-view/index.html index bc01dcc6c..739fdfe8e 100644 --- a/modules/order/front/catalog-view/index.html +++ b/modules/order/front/catalog-view/index.html @@ -1,57 +1,57 @@ -
- -
- -
-
-

- {{::item.name}} -

-

- {{::item.subName}} -

-
- - - - - - +
+ +
+
-
diff --git a/modules/order/front/catalog-view/index.js b/modules/order/front/catalog-view/index.js index 838da05ea..37a2b70a2 100644 --- a/modules/order/front/catalog-view/index.js +++ b/modules/order/front/catalog-view/index.js @@ -2,16 +2,7 @@ import ngModule from '../module'; import Component from 'core/lib/component'; import './style.scss'; -class Controller extends Component { - preview(event, item) { - event.preventDefault(); - this.$.pricesPopover.show(event, item); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } -} +class Controller extends Component {} ngModule.component('vnOrderCatalogView', { template: require('./index.html'), diff --git a/modules/order/front/descriptor/index.html b/modules/order/front/descriptor/index.html index 0a9e2ee38..a10923ae2 100644 --- a/modules/order/front/descriptor/index.html +++ b/modules/order/front/descriptor/index.html @@ -1,59 +1,77 @@ -
-
- - - - - - - - -
-
+ + +
    +
  • +
    + Delete order +
    +
  • +
+
+
- - - + - - - - - -
- - -
-
+ + + \ No newline at end of file diff --git a/modules/order/front/descriptor/index.js b/modules/order/front/descriptor/index.js index b60d44e78..5d22dd721 100644 --- a/modules/order/front/descriptor/index.js +++ b/modules/order/front/descriptor/index.js @@ -2,49 +2,24 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { - constructor($element, $) { - super($element, $); - this.moreOptions = [ - {name: 'Delete order', callback: () => this.showDeleteOrderDialog()} - ]; + get order() { + return this.entity; } set order(value) { - this._order = value; - if (!value) return; - - if (value.isConfirmed) { - this._quicklinks = { - btnOne: { - icon: 'icon-ticket', - state: `ticket.index({q: '{"orderFk": ${value.id}}'})`, - tooltip: 'Order ticket list' - }, - btnTwo: { - icon: 'person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - } - }; - } + this.entity = value; } - get order() { - return this._order; + get ticketFilter() { + return JSON.stringify({orderFk: this.id}); } - deleteOrder(response) { - if (response === 'accept') { - const params = {id: this.order.id}; - this.$http.delete(`Orders/${params.id}`).then(() => { + deleteOrder() { + return this.$http.delete(`Orders/${this.id}`) + .then(() => { this.$state.go('order.index'); - this.vnApp.showSuccess(this.$translate.instant('Order deleted')); + this.vnApp.showSuccess(this.$t('Order deleted')); }); - } - } - - showDeleteOrderDialog() { - this.$.deleteOrderConfirmation.show(); } } diff --git a/modules/order/front/descriptor/index.spec.js b/modules/order/front/descriptor/index.spec.js index 5bb2ac087..e6147faee 100644 --- a/modules/order/front/descriptor/index.spec.js +++ b/modules/order/front/descriptor/index.spec.js @@ -2,42 +2,26 @@ import './index.js'; describe('Order Component vnOrderDescriptor', () => { let $httpBackend; - let $scope; let controller; + const order = {id: 1}; beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnOrderDescriptor', {$element, $scope}); - controller.order = {id: 1}; + controller = $componentController('vnOrderDescriptor', {$element: null}, {order}); })); describe('deleteOrder()', () => { - it(`should do nothing if the response isn't accept`, () => { - let response = 'WAGH!'; - + it(`should perform a DELETE query`, () => { jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$state, 'go'); - controller.deleteOrder(response); - expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Order deleted!'); - expect(controller.$state.go).not.toHaveBeenCalledWith('order.index'); - }); - - it(`should perform a DELETE query if the response was accept`, () => { - let response = 'accept'; - - jest.spyOn(controller.vnApp, 'showSuccess'); - jest.spyOn(controller.$state, 'go'); - $httpBackend.when('DELETE', `Orders/${controller.order.id}`).respond(200); - $httpBackend.expect('DELETE', `Orders/${controller.order.id}`); - controller.deleteOrder(response); + $httpBackend.expectDELETE(`Orders/${order.id}`).respond(); + controller.deleteOrder(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order deleted'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.$state.go).toHaveBeenCalledWith('order.index'); }); }); diff --git a/modules/order/front/index/index.html b/modules/order/front/index/index.html index 1633b0ea1..148531f2d 100644 --- a/modules/order/front/index/index.html +++ b/modules/order/front/index/index.html @@ -81,4 +81,3 @@ order="$ctrl.selectedOrder"> - \ No newline at end of file diff --git a/modules/route/front/descriptor-popover/index.html b/modules/route/front/descriptor-popover/index.html index 75233bd77..a2da6ccae 100644 --- a/modules/route/front/descriptor-popover/index.html +++ b/modules/route/front/descriptor-popover/index.html @@ -1,6 +1,11 @@ - + + + + + \ No newline at end of file diff --git a/modules/route/front/descriptor-popover/index.js b/modules/route/front/descriptor-popover/index.js index ce62ee853..19696ad39 100644 --- a/modules/route/front/descriptor-popover/index.js +++ b/modules/route/front/descriptor-popover/index.js @@ -1,70 +1,7 @@ import ngModule from '../module'; import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends DescriptorPopover { - get route() { - return this.entity; - } - - loadData() { - const filter = { - fields: [ - 'id', - 'workerFk', - 'agencyModeFk', - 'created', - 'm3', - 'warehouseFk', - 'description', - 'vehicleFk', - 'kmStart', - 'kmEnd', - 'started', - 'finished', - 'cost', - 'zoneFk' - ], - include: [ - { - relation: 'agencyMode', - scope: { - fields: ['id', 'name'] - } - }, { - relation: 'vehicle', - scope: { - fields: ['id', 'm3'] - } - }, { - relation: 'zone', - scope: { - fields: ['id', 'name'] - } - }, { - relation: 'worker', - scope: { - fields: ['userFk'], - include: { - relation: 'user', - scope: { - fields: ['id'], - include: { - relation: 'emailUser', - scope: { - fields: ['email'] - } - } - } - } - } - } - ] - }; - - return this.getData(`Routes/${this.id}`, {filter}) - .then(res => this.entity = res.data); - } -} +class Controller extends DescriptorPopover {} ngModule.vnComponent('vnRouteDescriptorPopover', { slotTemplate: require('./index.html'), diff --git a/modules/route/front/descriptor/index.html b/modules/route/front/descriptor/index.html index f04632244..1707d0a78 100644 --- a/modules/route/front/descriptor/index.html +++ b/modules/route/front/descriptor/index.html @@ -1,41 +1,54 @@ -
-
- - - - - - - - -
-
+ + +
    +
  • +
    + Show route report +
    +
  • +
  • +
    + Send route report +
    +
  • +
  • +
    + Update volume +
    +
  • +
+
+
{{$ctrl.route.name}}
- - - - - -
@@ -46,13 +59,15 @@ ng-class="{bright: $ctrl.route.m3 > $ctrl.route.vehicle.m3 && $ctrl.route.vehicle.m3 != NULL}">
- - +
\ No newline at end of file diff --git a/modules/route/front/descriptor/index.js b/modules/route/front/descriptor/index.js index c4f4d17f2..0fbc3a5e6 100644 --- a/modules/route/front/descriptor/index.js +++ b/modules/route/front/descriptor/index.js @@ -2,69 +2,99 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { - constructor($element, $, $httpParamSerializer) { - super($element, $); - - this.$httpParamSerializer = $httpParamSerializer; - this.moreOptions = [ - {callback: this.showRouteReport, name: 'Show route report'}, - {callback: this.sendRouteReport, name: 'Send route report'}, - {callback: this.showUpdateVolumeDialog, name: 'Update volume', acl: 'deliveryBoss'} - ]; + get route() { + return this.entity; } - onMoreOpen() { - let options = this.moreOptions.filter(option => { - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - - return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - }); - this.$.moreButton.data = options; - } - - onMoreChange(callback) { - callback.call(this); + set route(value) { + this.entity = value; } showRouteReport() { - const params = { - authorization: this.vnToken.token, + this.showReport('driver-route', { clientId: this.vnConfig.storage.currentUserWorkerId, - routeId: this.route.id - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/driver-route?${serializedParams}`; - window.open(url); + routeId: this.id + }); } sendRouteReport() { const params = { recipient: user.emailUser.email, clientId: this.vnConfig.storage.currentUserWorkerId, - routeId: this.route.id + routeId: this.id }; - this.$http.get(`email/driver-route`, {params}).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Report sent')); - }); + return this.$http.get(`email/driver-route`, {params}) + .then(() => this.vnApp.showSuccess(this.$t('Report sent'))); } - showUpdateVolumeDialog() { - this.$.updateVolumeConfirmation.show(); - } - - updateVolume(response) { - if (response === 'accept') { - let url = `Routes/${this.route.id}/updateVolume`; - this.$http.post(url).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Volume updated')); - this.cardReload(); + updateVolume() { + this.$http.post(`Routes/${this.id}/updateVolume`) + .then(() => { + if (this.cardReload) this.cardReload(); + this.vnApp.showSuccess(this.$t('Volume updated')); }); - } + } + + loadData() { + const filter = { + fields: [ + 'id', + 'workerFk', + 'agencyModeFk', + 'created', + 'm3', + 'warehouseFk', + 'description', + 'vehicleFk', + 'kmStart', + 'kmEnd', + 'started', + 'finished', + 'cost', + 'zoneFk' + ], + include: [ + { + relation: 'agencyMode', + scope: { + fields: ['id', 'name'] + } + }, { + relation: 'vehicle', + scope: { + fields: ['id', 'm3'] + } + }, { + relation: 'zone', + scope: { + fields: ['id', 'name'] + } + }, { + relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['id'], + include: { + relation: 'emailUser', + scope: { + fields: ['email'] + } + } + } + } + } + } + ] + }; + + return this.getData(`Routes/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.vnComponent('vnRouteDescriptor', { template: require('./index.html'), controller: Controller, diff --git a/modules/route/front/descriptor-popover/index.spec.js b/modules/route/front/descriptor/index.spec.js similarity index 73% rename from modules/route/front/descriptor-popover/index.spec.js rename to modules/route/front/descriptor/index.spec.js index 971a101fe..ab996d9b0 100644 --- a/modules/route/front/descriptor-popover/index.spec.js +++ b/modules/route/front/descriptor/index.spec.js @@ -8,10 +8,7 @@ describe('vnRouteDescriptorPopover', () => { beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnRouteDescriptorPopover', { - $element: null, - $transclude: null - }); + controller = $componentController('vnRouteDescriptor', {$element: null}); })); describe('loadData()', () => { @@ -19,7 +16,7 @@ describe('vnRouteDescriptorPopover', () => { const id = 1; const response = 'foo'; - $httpBackend.expectGET(`Routes/${id}`).respond(response); + $httpBackend.expectRoute('GET', `Routes/${id}`).respond(response); controller.id = id; $httpBackend.flush(); diff --git a/modules/route/front/summary/index.html b/modules/route/front/summary/index.html index 5631a62d8..92e09fbe7 100644 --- a/modules/route/front/summary/index.html +++ b/modules/route/front/summary/index.html @@ -104,4 +104,4 @@ - \ No newline at end of file + diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index ef88f6d9e..037d25e7f 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -176,4 +176,4 @@ vn-acl-action="remove" vn-bind="+" fixed-bottom-right> - \ No newline at end of file + diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index e555eb8d7..8e5f74173 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -27,7 +27,7 @@ {{sale.itemFk | zeroFill:6}} @@ -66,5 +66,6 @@ + warehouse-fk="$ctrl.ticket.warehouseFk" + ticket-fk="$ctrl.ticket.id"> \ No newline at end of file diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 43e295d53..3efd7d56d 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -45,27 +45,6 @@ class Controller extends Section { return sum; } - - showDescriptor(event, itemFk) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - ticketFk: ${this.ticket.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketComponents', { diff --git a/modules/ticket/front/descriptor-popover/index.html b/modules/ticket/front/descriptor-popover/index.html index d76a41380..0dc0f8d00 100644 --- a/modules/ticket/front/descriptor-popover/index.html +++ b/modules/ticket/front/descriptor-popover/index.html @@ -1,6 +1,4 @@ - + \ No newline at end of file diff --git a/modules/ticket/front/descriptor-popover/index.js b/modules/ticket/front/descriptor-popover/index.js index fc61bc6ca..f6e66f3a1 100644 --- a/modules/ticket/front/descriptor-popover/index.js +++ b/modules/ticket/front/descriptor-popover/index.js @@ -1,64 +1,7 @@ import ngModule from '../module'; import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends DescriptorPopover { - get ticket() { - return this.entity; - } - - loadData() { - const filter = { - include: [ - { - relation: 'warehouse', - scope: { - fields: ['name'] - } - }, { - relation: 'agencyMode', - scope: { - fields: ['name'] - } - }, { - relation: 'client', - scope: { - fields: [ - 'salesPersonFk', - 'name', - 'isActive', - 'isFreezed', - 'isTaxDataChecked' - ], - include: { - relation: 'salesPerson', - scope: { - fields: ['userFk'], - include: { - relation: 'user', - scope: { - fields: ['nickname'] - } - } - } - } - } - }, { - relation: 'state', - scope: { - fields: ['stateFk'], - include: { - relation: 'state', - fields: ['id', 'name'], - } - } - } - ] - }; - - return this.getData(`Tickets/${this.id}`, {filter}) - .then(res => this.entity = res.data); - } -} +class Controller extends DescriptorPopover {} ngModule.vnComponent('vnTicketDescriptorPopover', { slotTemplate: require('./index.html'), diff --git a/modules/ticket/front/descriptor-popover/index.spec.js b/modules/ticket/front/descriptor-popover/index.spec.js deleted file mode 100644 index fccdb5f96..000000000 --- a/modules/ticket/front/descriptor-popover/index.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -import './index.js'; - -describe('vnTicketDescriptorPopover', () => { - let controller; - let $httpBackend; - - beforeEach(ngModule('ticket')); - - beforeEach(inject(($componentController, _$httpBackend_) => { - $httpBackend = _$httpBackend_; - controller = $componentController('vnTicketDescriptorPopover', { - $element: null, - $transclude: null - }); - })); - - describe('loadData()', () => { - it(`should perform a get query to store the ticket data into the controller`, () => { - const id = 1; - const response = 'foo'; - - $httpBackend.expectGET(`Tickets/${id}`).respond(response); - controller.id = id; - $httpBackend.flush(); - - expect(controller.ticket).toEqual(response); - }); - }); -}); - diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index 2ea87839b..d9883d6ba 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -1,80 +1,180 @@ -
-
- - - - - - - - -
-
+ + +
    +
  • +
    + Add turn +
    +
  • +
  • +
    + Show Delivery Note +
    +
  • +
  • +
    + Send Delivery Note +
    +
  • +
  • +
    + Delete ticket +
    +
  • +
  • +
    + Change shipped hour +
    +
  • +
  • +
    + SMS Pending payment +
    +
  • +
  • +
    + SMS Minimum import +
    +
  • +
  • +
    + Add stowaway +
    +
  • +
  • +
    + Delete stowaway +
    +
  • +
  • +
    + Make invoice +
    +
  • +
  • +
    + Regenerate invoice +
    +
  • +
  • +
    + Recalculate components +
    +
  • +
+
+
{{::$ctrl.client.name}}
- - - - - - - -
- - - - -
- - +
-
-
+ +
-
- In which day you want to add the ticket? +
+ In which day you want to add the ticket?
- - + + + + + + + + + + + + @@ -166,40 +294,4 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 2be4cf9b9..1b9048bd7 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -2,144 +2,24 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - { - name: 'Add turn', - callback: this.showAddTurnDialog, - acl: 'buyer' - }, { - name: 'Show Delivery Note', - callback: this.showDeliveryNote - }, { - name: 'Send Delivery Note', - callback: this.confirmDeliveryNote - }, { - name: 'Delete ticket', - callback: this.showDeleteTicketDialog - }, { - name: 'Change shipped hour', - callback: this.showChangeShipped - }, { - name: 'SMS Pending payment', - callback: this.sendPaymentSms - }, { - name: 'SMS Minimum import', - callback: this.sendImportSms - }, { - name: 'Add stowaway', - callback: this.showAddStowaway, - show: () => this.canShowStowaway - }, { - name: 'Delete stowaway', - callback: this.showDeleteStowaway, - show: () => this.shouldShowDeleteStowaway() - }, { - name: 'Make invoice', - callback: this.showMakeInvoiceDialog, - show: () => !this.hasInvoice(), - acl: 'invoicing' - }, { - name: 'Regenerate invoice', - callback: this.showRegenerateInvoiceDialog, - show: () => this.hasInvoice(), - acl: 'invoicing' - }, { - name: 'Recalculate components', - callback: this.comfirmRecalculateComponents, - show: () => this.isEditable - }, - ]; - } - get ticket() { - return this._ticket; + return this.entity; } set ticket(value) { - this._ticket = value; + this.entity = value; + } - if (!value) return; - - if (this.$params.sendSMS) - this.showSMSDialog(); + get entity() { + return super.entity; + } + set entity(value) { + super.entity = value; this.canStowaway(); - let links = { - btnOne: { - icon: 'person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - }}; - - if (value.stowaway) { - links.btnTwo = { - icon: 'icon-stowaway', - state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`, - tooltip: 'Ship stowaways' - }; - } - - if (value.ship) { - links.btnThree = { - icon: 'icon-stowaway', - state: `ticket.card.summary({id: ${value.ship.id}})`, - tooltip: 'Stowaway' - }; - } - - this._quicklinks = links; - } - - showChangeShipped() { - if (!this.isEditable) { - this.vnApp.showError(this.$t(`This ticket can't be modified`)); - return; - } - - this.newShipped = this.ticket.shipped; - this.$.changeShippedDialog.show(); - } - - changeShipped() { - let data = {shipped: this.newShipped}; - let query = `Tickets/${this.ticket.id}/updateEditableTicket`; - this.$http.post(query, data) - .then(() => this.cardReload()) - .then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated'))); - } - - isTicketModule() { - let path = this.$state.getCurrentPath(); - const isTicket = path[1].state.name === 'ticket'; - if (isTicket) - return true; - - return false; - } - - onMoreChange(callback) { - callback.call(this); - } - - goToTicket(ticketID) { - this.$state.go('ticket.card.sale', {id: ticketID}, {absolute: true}); - } - - onMoreOpen() { - let options = this.moreOptions.filter(option => { - const hasShowProperty = Object.hasOwnProperty.call(option, 'show'); - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - const hasAcl = !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - - return (!hasShowProperty || option.show === true || - typeof option.show === 'function' && option.show()) && hasAcl; - }); - this.$.moreButton.data = options; + if (value && this.$params.sendSMS) + this.showSMSDialog(); } get isEditable() { @@ -150,204 +30,204 @@ class Controller extends Descriptor { return true; } - showAddTurnDialog() { - this.$.addTurn.show(); + get isInvoiced() { + return this.ticket.refFk !== null; + } + + get isTicketModule() { + return this.$state.getCurrentPath()[1].state.name === 'ticket'; + } + + get shouldShowDeleteStowaway() { + if (!this.ticket || !this.isTicketModule) + return false; + + return this.ticket.stowaway || this.ticket.ship; + } + + showChangeShipped() { + this.newShipped = this.ticket.shipped; + this.$.changeShippedDialog.show(); + } + + changeShipped() { + let data = { + shipped: this.newShipped + }; + return this.$http.post(`Tickets/${this.id}/updateEditableTicket`, data) + .then(() => this.cardReload()) + .then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated'))); + } + + goToTicket(ticketId) { + this.$state.go('ticket.card.sale', {id: ticketId}, {absolute: true}); } addTurn(day) { let params = { - ticketFk: this.ticket.id, + ticketFk: this.id, weekDay: day, - agencyModeFk: this.ticket.agencyModeFk}; - this.$http.patch(`TicketWeeklies`, params).then(() => { - this.$.addTurn.hide(); - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + agencyModeFk: this.ticket.agencyModeFk + }; + return this.$http.patch(`TicketWeeklies`, params) + .then(() => { + this.$.addTurn.hide(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); } - showDeleteTicketDialog() { - if (!this.isEditable) { - this.vnApp.showError(this.$t('This ticket cant be deleted')); - return; - } - - this.$.deleteConfirmation.show(); - } - - deleteTicket(response) { - if (response === 'accept') { - const query = `Tickets/${this.ticket.id}/setDeleted`; - this.$http.post(query).then(() => { + deleteTicket() { + return this.$http.post(`Tickets/${this.id}/setDeleted`) + .then(() => { this.$state.go('ticket.index'); this.vnApp.showSuccess(this.$t('Ticket deleted')); }); - } } canStowaway() { - if (!this.isTicketModule()) return; + this.canShowStowaway = false; + if (!this.isTicketModule || !this.ticket) return; - this.$http.get(`Tickets/${this.ticket.id}/canHaveStowaway`).then(response => { - if (response.data === true) - return this.canShowStowaway = true; - - return this.canShowStowaway = false; - }); - } - - shouldShowDeleteStowaway() { - if (!this._ticket || !this.isTicketModule()) - return false; - - return this._ticket.stowaway || this._ticket.ship; - } - - showAddStowaway() { - this.$.addStowaway.show(); - } - - showDeleteStowaway() { - this.$.deleteStowaway.show(); + this.$http.get(`Tickets/${this.id}/canHaveStowaway`) + .then(res => this.canShowStowaway = !!res.data); } deleteStowaway() { - const query = `Tickets/${this.ticket.id}/deleteStowaway`; - this.$http.post(query).then(res => { - this.vnApp.showSuccess(this.$t('Data saved!')); - this.cardReload(); - }); + return this.$http.post(`Tickets/${this.id}/deleteStowaway`) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.cardReload(); + }); } showDeliveryNote() { - const params = { + this.showReport('delivery-note', { clientId: this.ticket.client.id, - ticketId: this.ticket.id, - authorization: this.vnToken.token - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/delivery-note?${serializedParams}`; - window.open(url); + ticketId: this.id, + }); } sendDeliveryNote() { - const params = { + return this.sendEmail('delivery-note', { recipient: this.ticket.client.email, clientId: this.ticket.client.id, - ticketId: this.ticket.id - }; - this.$http.get(`email/delivery-note`, {params}).then( - () => this.vnApp.showMessage(this.$t('Notification sent!')) - ); + ticketId: this.id + }); } sendImportSms() { const params = { - ticketId: this.ticket.id, + ticketId: this.id, created: this.ticket.created }; - const message = this.$params.message || this.$t('Minimum is needed', params); - this.newSMS = {message}; - this.showSMSDialog(); + this.showSMSDialog({ + message: this.$params.message || this.$t('Minimum is needed', params) + }); } sendPaymentSms() { - const message = this.$params.message || this.$t('Make a payment'); - this.newSMS = {message}; - this.showSMSDialog(); + this.showSMSDialog({ + message: this.$params.message || this.$t('Make a payment') + }); } - showSMSDialog() { + showSMSDialog(params) { const address = this.ticket.address; const client = this.ticket.client; - const phone = this.$params.phone || address.mobile || address.phone || - client.mobile || client.phone; + const phone = this.$params.phone + || address.mobile + || address.phone + || client.mobile + || client.phone; - this.newSMS.destinationFk = this.ticket.clientFk; - this.newSMS.destination = phone; + this.newSMS = Object.assign({ + destinationFk: this.ticket.clientFk, + destination: phone + }, params); this.$.sms.open(); } - /** - * Shows an invoice confirmation - */ - showMakeInvoiceDialog() { - this.$.makeInvoiceConfirmation.show(); - } - - /** - * Makes an invoice - * from current ticket - * - * @param {String} response - Response result - */ - makeInvoice(response) { - if (response === 'accept') { - const query = `Tickets/${this.ticket.id}/makeInvoice`; - this.$http.post(query).then(() => { + makeInvoice() { + return this.$http.post(`Tickets/${this.id}/makeInvoice`) + .then(() => { this.vnApp.showSuccess(this.$t('Ticket invoiced')); this.$state.reload(); }); - } } - /** - * Shows an invoice confirmation - */ - showRegenerateInvoiceDialog() { - this.$.regenerateInvoiceConfirmation.show(); - } - - /** - * Sends an invoice to a regeneration queue - * for the current ticket - * - * @param {String} response - Response result - */ - regenerateInvoice(response) { - if (response === 'accept') { - const invoiceId = this.ticket.invoiceOut.id; - const query = `InvoiceOuts/${invoiceId}/regenerate`; - this.$http.post(query).then(() => { + regenerateInvoice() { + const invoiceId = this.ticket.invoiceOut.id; + return this.$http.post(`InvoiceOuts/${invoiceId}/regenerate`) + .then(() => { const snackbarMessage = this.$t( `Invoice sent for a regeneration, will be available in a few minutes`); this.vnApp.showSuccess(snackbarMessage); }); - } - } - - /** - * Returns if the current ticket - * is already invoiced - * @return {Boolean} - True if invoiced - */ - hasInvoice() { - return this.ticket.refFk !== null; - } - - /** - * Shows a delivery-note send confirmation - */ - confirmDeliveryNote() { - this.$.confirmDeliveryNote.show(); - } - - /** - * Shows an invoice confirmation - */ - comfirmRecalculateComponents() { - this.$.recalculateComponentsConfirmation.show(); } recalculateComponents() { - const query = `Tickets/${this.ticket.id}/recalculateComponents`; - this.$http.post(query).then(res => { - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + return this.$http.post(`Tickets/${this.id}/recalculateComponents`) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); + } + + cardReload() { + // Prevents error when not defined + } + + loadData() { + const filter = { + include: [ + { + relation: 'warehouse', + scope: { + fields: ['name'] + } + }, { + relation: 'agencyMode', + scope: { + fields: ['name'] + } + }, { + relation: 'client', + scope: { + fields: [ + 'salesPersonFk', + 'name', + 'isActive', + 'isFreezed', + 'isTaxDataChecked' + ], + include: { + relation: 'salesPerson', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + } + } + } + } + }, { + relation: 'state', + scope: { + fields: ['stateFk'], + include: { + relation: 'state', + fields: ['id', 'name'], + } + } + } + ] + }; + + return this.getData(`Tickets/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - ngModule.vnComponent('vnTicketDescriptor', { template: require('./index.html'), controller: Controller, diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index 4f43ac010..f152f1f0f 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -1,47 +1,40 @@ import './index.js'; describe('Ticket Component vnTicketDescriptor', () => { - let $httpParamSerializer; let $httpBackend; let controller; let $state; + const ticket = { + id: 2, + clientFk: 101, + invoiceOut: {id: 1}, + client: { + id: 101, + email: 'client@email' + }, + address: { + id: 101, + mobile: 111111111, + phone: 2222222222 + }, + tracking: { + state: {alertLevel: 3} + } + }; + beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, $compile, _$state_, _$httpParamSerializer_) => { - let $element = $compile(``)($rootScope); - $state = _$state_; - $state.getCurrentPath = () => { - return [ - {state: {}}, - {state: {name: 'ticket'}} - ]; - }; + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$state_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTicketDescriptor', {$element}); - controller._ticket = { - id: 2, - clientFk: 101, - invoiceOut: {id: 1}, - client: {id: 101, email: 'client@email'}, - address: {id: 101, mobile: 111111111, phone: 2222222222} - }; - controller.cardReload = ()=> { - return true; - }; + $httpBackend.whenGET(`Tickets/${ticket.id}/canHaveStowaway`).respond(true); + + $state = _$state_; + $state.getCurrentPath = () => [null, {state: {name: 'ticket'}}]; + + controller = $componentController('vnTicketDescriptor', {$element: null}, {ticket}); })); - describe('showAddTurnDialog()', () => { - it('should call controller.$.addTurn.show()', () => { - controller.$.addTurn = {show: () => {}}; - jest.spyOn(controller.$.addTurn, 'show'); - controller.showAddTurnDialog(); - - expect(controller.$.addTurn.show).toHaveBeenCalledWith(); - }); - }); - describe('addTurn()', () => { it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => { controller.$.addTurn = {hide: () => {}}; @@ -55,176 +48,114 @@ describe('Ticket Component vnTicketDescriptor', () => { }); }); - describe('showDeleteTicketDialog()', () => { - it('should call vnApp.showError() if the ticket isnt editable', () => { - controller.ticket.tracking = {state: {alertLevel: 3}}; - jest.spyOn(controller.vnApp, 'showError'); - controller.showDeleteTicketDialog(); - - expect(controller.vnApp.showError).toHaveBeenCalledWith('This ticket cant be deleted'); - }); - - it('should call deleteConfirmation.show() if the ticket is editable', () => { - controller.ticket.tracking = {state: {alertLevel: 0}}; - controller.$.deleteConfirmation = {show: () => {}}; - jest.spyOn(controller.$.deleteConfirmation, 'show'); - controller.showDeleteTicketDialog(); - - expect(controller.$.deleteConfirmation.show).toHaveBeenCalledWith(); - }); - }); - describe('deleteTicket()', () => { - it('should make a query and call vnApp.showSuccess() if the response is accept', () => { + it('should make a query and call vnApp.showSuccess()', () => { jest.spyOn(controller.$state, 'go').mockReturnValue('ok'); jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expectPOST(`Tickets/2/setDeleted`).respond(); - controller.deleteTicket('accept'); + $httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond(); + controller.deleteTicket(); $httpBackend.flush(); expect(controller.$state.go).toHaveBeenCalledWith('ticket.index'); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket deleted'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('showDeliveryNote()', () => { it('should open a new window showing a delivery note PDF document', () => { + jest.spyOn(controller, 'showReport'); + const params = { - clientId: controller.ticket.client.id, - ticketId: controller.ticket.id + clientId: ticket.client.id, + ticketId: ticket.id }; - const serializedParams = $httpParamSerializer(params); - let expectedPath = `api/report/delivery-note?${serializedParams}`; - jest.spyOn(window, 'open').mockReturnThis(); controller.showDeliveryNote(); - expect(window.open).toHaveBeenCalledWith(expectedPath); + expect(controller.showReport).toHaveBeenCalledWith('delivery-note', params); }); }); describe('sendDeliveryNote()', () => { it('should make a query and call vnApp.showMessage()', () => { - jest.spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller, 'sendEmail'); const params = { - recipient: 'client@email', - clientId: controller.ticket.client.id, - ticketId: controller.ticket.id + recipient: ticket.client.email, + clientId: ticket.client.id, + ticketId: ticket.id }; - const serializedParams = $httpParamSerializer(params); - - $httpBackend.when('GET', `email/delivery-note?${serializedParams}`).respond(); - $httpBackend.expect('GET', `email/delivery-note?${serializedParams}`).respond(); controller.sendDeliveryNote(); - $httpBackend.flush(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!'); + expect(controller.sendEmail).toHaveBeenCalledWith('delivery-note', params); }); }); describe('makeInvoice()', () => { - it('should make a query and call $state.reload() method if the response is accept', () => { + it('should make a query and call $state.reload() method', () => { jest.spyOn(controller.$state, 'reload').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', 'Tickets/2/makeInvoice').respond(); - $httpBackend.expect('POST', 'Tickets/2/makeInvoice').respond(); - controller.makeInvoice('accept'); + $httpBackend.expectPOST(`Tickets/${ticket.id}/makeInvoice`).respond(); + controller.makeInvoice(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket invoiced'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.$state.reload).toHaveBeenCalledWith(); }); }); describe('regenerateInvoice()', () => { - it('should make a query and show a success snackbar if the response is accept', () => { + it('should make a query and show a success snackbar', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', 'InvoiceOuts/1/regenerate').respond(); - $httpBackend.expect('POST', 'InvoiceOuts/1/regenerate').respond(); - controller.regenerateInvoice('accept'); + $httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/regenerate`).respond(); + controller.regenerateInvoice(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Invoice sent for a regeneration, will be available in a few minutes'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('changeShipped()', () => { it('should make a query and change the shipped hour if the response is accept', () => { - controller.ticket.id = 12; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller, 'cardReload'); - $httpBackend.expectRoute('POST', 'Tickets/:id/updateEditableTicket').respond(); - controller.changeShipped('accept'); + $httpBackend.expectPOST(`Tickets/${ticket.id}/updateEditableTicket`).respond(); + controller.changeShipped(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Shipped hour updated'); - expect(controller.cardReload).toHaveBeenCalledWith(); - }); - }); - - describe('showAddStowaway()', () => { - it('should show a dialog with a list of tickets available for an stowaway', () => { - controller.$.addStowaway = {}; - controller.$.addStowaway.show = jasmine.createSpy('show'); - controller.showAddStowaway(); - - expect(controller.$.addStowaway.show).toHaveBeenCalledWith(); - }); - }); - - describe('showRemoveStowaway()', () => { - it('should show a dialog for an stowaway removal', () => { - controller.$.deleteStowaway = {}; - controller.$.deleteStowaway.show = jasmine.createSpy('show'); - controller.showDeleteStowaway(); - - expect(controller.$.deleteStowaway.show).toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.cardReload).toHaveBeenCalled(); }); }); describe('canStowaway()', () => { - it('should make a query and return if the ticket can be stowawayed', () => { - controller.ticket.id = 16; - jest.spyOn(controller, 'isTicketModule'); - $httpBackend.when('GET', 'Tickets/16/canHaveStowaway').respond(true); - $httpBackend.expect('GET', 'Tickets/16/canHaveStowaway').respond(true); + fit('should make a query and return if the ticket can be stowawayed', () => { controller.canStowaway(); $httpBackend.flush(); expect(controller.canShowStowaway).toBeTruthy(); - expect(controller.isTicketModule).toHaveBeenCalledWith(); }); it('should not make a query if is not on the ticket module', () => { - controller.ticket.id = 16; - $state.getCurrentPath = () => { - return [ - {state: {}}, - {state: {name: 'client'}} - ]; - }; - jest.spyOn(controller, 'isTicketModule'); + $state.getCurrentPath = () => [null, {state: {name: 'client'}}]; controller.canStowaway(); - expect(controller.canShowStowaway).toBeUndefined(); - expect(controller.isTicketModule).toHaveBeenCalledWith(); + expect(controller.canShowStowaway).toBeFalsy(); }); }); describe('recalculateComponents()', () => { - it('should make a query and show a success snackbar', () => { + it('should make a query and show a success message', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', 'Tickets/2/recalculateComponents').respond(); - $httpBackend.expect('POST', 'Tickets/2/recalculateComponents').respond(); + $httpBackend.expectPOST(`Tickets/${ticket.id}/recalculateComponents`).respond(); controller.recalculateComponents(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); @@ -233,14 +164,25 @@ describe('Ticket Component vnTicketDescriptor', () => { controller.$.sms = {open: () => {}}; jest.spyOn(controller.$.sms, 'open'); - const clientId = 101; - const expectedPhone = 111111111; - controller.newSMS = {}; controller.showSMSDialog(); - expect(controller.newSMS.destinationFk).toEqual(clientId); - expect(controller.newSMS.destination).toEqual(expectedPhone); expect(controller.$.sms.open).toHaveBeenCalledWith(); + expect(controller.newSMS).toEqual({ + destinationFk: ticket.clientFk, + destination: ticket.address.mobile + }); + }); + }); + + describe('loadData()', () => { + it(`should perform a get query to store the ticket data into the controller`, () => { + controller.ticket = null; + + $httpBackend.expectRoute('GET', `Tickets/${ticket.id}`).respond(ticket); + controller.id = ticket.id; + $httpBackend.flush(); + + expect(controller.ticket).toEqual(ticket); }); }); }); diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 8a33e051e..3b17a3b88 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -37,7 +37,7 @@ + ng-click="itemDescriptor.show($event, expedition.itemFk)"> {{expedition.itemFk | zeroFill:6}} @@ -60,7 +60,8 @@ + warehouse-fk="this.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 090bbdfa3..673c18e33 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -6,24 +6,6 @@ class Controller extends Section { return this.$http.delete(`Expeditions/${id}`) .then(() => this.$.model.refresh()); } - - showItemDescriptor(event, itemFk) { - if (!itemFk) return; - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - ticketFk: ${this.ticket.id} - })`, - tooltip: 'Item diary', - }, - }; - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } } ngModule.component('vnTicketExpedition', { diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index 703e2ea80..ab2501a13 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -151,4 +151,3 @@ - \ No newline at end of file diff --git a/modules/ticket/front/picture/index.html b/modules/ticket/front/picture/index.html index e4e8c1d0b..52cab5b31 100644 --- a/modules/ticket/front/picture/index.html +++ b/modules/ticket/front/picture/index.html @@ -15,7 +15,7 @@ No results -
+
{{::request.saleFk | zeroFill:6}} @@ -102,7 +102,7 @@ + ticket-fk="$ctrl.$params.id"> diff --git a/modules/ticket/front/request/index/index.js b/modules/ticket/front/request/index/index.js index 122feae1c..7ee1399e6 100644 --- a/modules/ticket/front/request/index/index.js +++ b/modules/ticket/front/request/index/index.js @@ -42,22 +42,6 @@ class Controller extends Section { }); } - showItemDescriptor(event, itemFk) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - ticketFk: ${this.$params.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - getRequestState(state) { switch (state) { case null: diff --git a/modules/ticket/front/sale-checked/index.html b/modules/ticket/front/sale-checked/index.html index a2afd3b8f..659d1b990 100644 --- a/modules/ticket/front/sale-checked/index.html +++ b/modules/ticket/front/sale-checked/index.html @@ -50,5 +50,6 @@ + warehouse-fk="$ctrl.ticket.warehouseFk" + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/sale-checked/index.js b/modules/ticket/front/sale-checked/index.js index 9bb5fd19a..5768785d8 100644 --- a/modules/ticket/front/sale-checked/index.js +++ b/modules/ticket/front/sale-checked/index.js @@ -5,34 +5,18 @@ class Controller extends Section { constructor($element, $) { super($element, $); this.filter = { - include: [{ - relation: 'item' - }, - { - relation: 'isChecked', - scope: { - fields: ['isChecked'] + include: [ + { + relation: 'item' + }, { + relation: 'isChecked', + scope: { + fields: ['isChecked'] + } } - }] + ] }; } - - showDescriptor(event, itemFk) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - ticketFk: ${this.ticket.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } } ngModule.component('vnTicketSaleChecked', { diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index 967160915..2faa13881 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -34,7 +34,7 @@ {{sale.itemFk | zeroFill:6}} @@ -65,7 +65,8 @@ + warehouse-fk="$ctrl.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/sale-tracking/index.js b/modules/ticket/front/sale-tracking/index.js index bd41add25..ebb6f9ada 100644 --- a/modules/ticket/front/sale-tracking/index.js +++ b/modules/ticket/front/sale-tracking/index.js @@ -1,24 +1,7 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -class Controller extends Section { - showItemDescriptor(event, itemFk) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - ticketFk: ${this.ticket.id} - })`, - tooltip: 'Item diary', - }, - }; - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } -} +class Controller extends Section {} ngModule.component('vnTicketSaleTracking', { template: require('./index.html'), diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index efa4f0285..5aee74d1e 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -105,7 +105,7 @@ + ng-click="descriptor.show($event, sale.itemFk)"> {{sale.itemFk}} + warehouse-fk="$ctrl.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 78cedc7f2..f422fefa1 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -284,24 +284,6 @@ class Controller extends Section { }); } - // Item Descriptor - showDescriptor(event, itemFk) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - ticketFk: ${this.ticket.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - showEditPricePopover(event, sale) { if (!this.isEditable) return; this.sale = sale; diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html index be5ff6d92..8e8f562e8 100644 --- a/modules/ticket/front/summary/index.html +++ b/modules/ticket/front/summary/index.html @@ -32,7 +32,7 @@ {{$ctrl.summary.routeFk}} @@ -117,7 +117,7 @@ {{sale.itemFk | zeroFill:6}} @@ -208,7 +208,7 @@ {{request.sale.itemFk | zeroFill:6}} @@ -228,10 +228,10 @@ + vn-id="routeDescriptor"> + warehouse-fk="$ctrl.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/summary/index.js b/modules/ticket/front/summary/index.js index 1ad9cf4b3..b8511a662 100644 --- a/modules/ticket/front/summary/index.js +++ b/modules/ticket/front/summary/index.js @@ -29,38 +29,6 @@ class Controller extends Section { }); } - showRouteDescriptor(event) { - this.routeQuicklinks = { - btnThree: { - icon: 'icon-delivery', - state: `route.card.summary({ - id: ${this.summary.routeFk}, - })`, - tooltip: 'Route summary' - } - }; - this.$.routeDescriptor.routeFk = this.summary.routeFk; - this.$.routeDescriptor.parent = event.target; - this.$.routeDescriptor.show(); - } - - showDescriptor(event, itemFk) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - ticketFk: ${this.ticket.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - get isEditable() { try { return !this.ticket.state.state.alertLevel; diff --git a/modules/ticket/front/volume/index.html b/modules/ticket/front/volume/index.html index 610e517c9..84abb67c1 100644 --- a/modules/ticket/front/volume/index.html +++ b/modules/ticket/front/volume/index.html @@ -37,7 +37,7 @@ {{sale.itemFk | zeroFill:6}} @@ -60,6 +60,7 @@ + warehouse-fk="$ctrl.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/volume/index.js b/modules/ticket/front/volume/index.js index 0395afa8d..3d690764f 100644 --- a/modules/ticket/front/volume/index.js +++ b/modules/ticket/front/volume/index.js @@ -43,23 +43,6 @@ class Controller extends Section { }); }); } - - showDescriptor(event, itemFk) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - ticketFk: ${this.ticket.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } } ngModule.component('vnTicketVolume', { diff --git a/modules/travel/front/descriptor-popover/index.html b/modules/travel/front/descriptor-popover/index.html index 46fb787a0..376423bbc 100644 --- a/modules/travel/front/descriptor-popover/index.html +++ b/modules/travel/front/descriptor-popover/index.html @@ -1,6 +1,4 @@ - + \ No newline at end of file diff --git a/modules/travel/front/descriptor-popover/index.js b/modules/travel/front/descriptor-popover/index.js index b9839b04b..12c5908ca 100644 --- a/modules/travel/front/descriptor-popover/index.js +++ b/modules/travel/front/descriptor-popover/index.js @@ -1,41 +1,7 @@ import ngModule from '../module'; import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends DescriptorPopover { - get travel() { - return this.entity; - } - - loadData() { - const filter = { - fields: [ - 'id', - 'ref', - 'shipped', - 'landed', - 'totalEntries', - 'warehouseInFk', - 'warehouseOutFk' - ], - include: [ - { - relation: 'warehouseIn', - scope: { - fields: ['name'] - } - }, { - relation: 'warehouseOut', - scope: { - fields: ['name'] - } - } - ] - }; - - return this.getData(`Travels/${this.id}`, {filter}) - .then(res => this.entity = res.data); - } -} +class Controller extends DescriptorPopover {} ngModule.vnComponent('vnTravelDescriptorPopover', { slotTemplate: require('./index.html'), diff --git a/modules/travel/front/descriptor/index.html b/modules/travel/front/descriptor/index.html index 3b932ef53..871be9150 100644 --- a/modules/travel/front/descriptor/index.html +++ b/modules/travel/front/descriptor/index.html @@ -1,36 +1,34 @@ -
-
- - - - - - - -
-
+ +
- - - - - - -
-
-
+ + diff --git a/modules/travel/front/descriptor/index.js b/modules/travel/front/descriptor/index.js index c38dd91a2..6136d5347 100644 --- a/modules/travel/front/descriptor/index.js +++ b/modules/travel/front/descriptor/index.js @@ -1,13 +1,50 @@ import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; +class Controller extends Descriptor { + get travel() { + return this.entity; + } + + set travel(value) { + this.entity = value; + } + + loadData() { + const filter = { + fields: [ + 'id', + 'ref', + 'shipped', + 'landed', + 'totalEntries', + 'warehouseInFk', + 'warehouseOutFk' + ], + include: [ + { + relation: 'warehouseIn', + scope: { + fields: ['name'] + } + }, { + relation: 'warehouseOut', + scope: { + fields: ['name'] + } + } + ] + }; + + return this.getData(`Travels/${this.id}`, {filter}) + .then(res => this.entity = res.data); + } +} + ngModule.vnComponent('vnTravelDescriptor', { template: require('./index.html'), - controller: Descriptor, + controller: Controller, bindings: { travel: '<' - }, - require: { - card: '^?vnTravelCard' - }, + } }); diff --git a/modules/travel/front/descriptor-popover/index.spec.js b/modules/travel/front/descriptor/index.spec.js similarity index 68% rename from modules/travel/front/descriptor-popover/index.spec.js rename to modules/travel/front/descriptor/index.spec.js index c191414c9..0a88c8607 100644 --- a/modules/travel/front/descriptor-popover/index.spec.js +++ b/modules/travel/front/descriptor/index.spec.js @@ -1,6 +1,6 @@ import './index.js'; -describe('vnTravelDescriptorPopover', () => { +describe('vnTravelDescriptor', () => { let controller; let $httpBackend; @@ -8,10 +8,7 @@ describe('vnTravelDescriptorPopover', () => { beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnTravelDescriptorPopover', { - $element: null, - $transclude: null - }); + controller = $componentController('vnTravelDescriptor', {$element: null}); })); describe('loadData()', () => { @@ -19,7 +16,7 @@ describe('vnTravelDescriptorPopover', () => { const id = 1; const response = 'foo'; - $httpBackend.expectGET(`Travels/${id}`).respond(response); + $httpBackend.expectRoute('GET', `Travels/${id}`).respond(response); controller.id = id; $httpBackend.flush(); diff --git a/modules/worker/front/descriptor-popover/index.html b/modules/worker/front/descriptor-popover/index.html index 7c9155dda..e98763d46 100644 --- a/modules/worker/front/descriptor-popover/index.html +++ b/modules/worker/front/descriptor-popover/index.html @@ -1,6 +1,4 @@ - + \ No newline at end of file diff --git a/modules/worker/front/descriptor-popover/index.js b/modules/worker/front/descriptor-popover/index.js index eedcebe48..5c027635f 100644 --- a/modules/worker/front/descriptor-popover/index.js +++ b/modules/worker/front/descriptor-popover/index.js @@ -1,46 +1,7 @@ import ngModule from '../module'; import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends DescriptorPopover { - get worker() { - return this.entity; - } - - loadData() { - const filter = { - include: [ - { - relation: 'user', - scope: { - fields: ['name'], - include: { - relation: 'emailUser', - scope: { - fields: ['email'] - } - } - } - }, { - relation: 'client', - scope: {fields: ['fi']} - }, { - relation: 'sip', - scope: {fields: ['extension']} - }, { - relation: 'department', - scope: { - include: { - relation: 'department' - } - } - } - ] - }; - - return this.getData(`Workers/${this.id}`, {filter}) - .then(res => this.entity = res.data); - } -} +class Controller extends DescriptorPopover {} ngModule.vnComponent('vnWorkerDescriptorPopover', { slotTemplate: require('./index.html'), diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index d26892bfd..3351ab7ab 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -1,40 +1,45 @@ -
- - - - - - - - - -
+ +
{{$ctrl.worker.firstName}} {{$ctrl.worker.lastName}}
- - - - - -
- - -
-
\ No newline at end of file + + + \ No newline at end of file diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index e92a967c9..98f8f2f72 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -3,20 +3,50 @@ import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { get worker() { - return this._worker; + return this.entity; } set worker(value) { - this._worker = value; - if (!value) return; + this.entity = value; + } - this._quicklinks = { - btnOne: { - icon: 'person', - state: `client.card.summary({id: ${value.userFk}})`, - tooltip: 'Go to client' - } + loadData() { + const filter = { + include: [ + { + relation: 'user', + scope: { + fields: ['name'], + include: { + relation: 'emailUser', + scope: { + fields: ['email'] + } + } + } + }, { + relation: 'client', + scope: { + fields: ['fi'] + } + }, { + relation: 'sip', + scope: { + fields: ['extension'] + } + }, { + relation: 'department', + scope: { + include: { + relation: 'department' + } + } + } + ] }; + + return this.getData(`Workers/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } diff --git a/modules/worker/front/descriptor-popover/index.spec.js b/modules/worker/front/descriptor/index.spec.js similarity index 68% rename from modules/worker/front/descriptor-popover/index.spec.js rename to modules/worker/front/descriptor/index.spec.js index 4b9a17e8a..dfb800415 100644 --- a/modules/worker/front/descriptor-popover/index.spec.js +++ b/modules/worker/front/descriptor/index.spec.js @@ -1,6 +1,6 @@ import './index.js'; -describe('vnWorkerDescriptorPopover', () => { +describe('vnWorkerDescriptor', () => { let controller; let $httpBackend; @@ -8,10 +8,7 @@ describe('vnWorkerDescriptorPopover', () => { beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - controller = $componentController('vnWorkerDescriptorPopover', { - $element: null, - $transclude: null - }); + controller = $componentController('vnWorkerDescriptor', {$element: null}); })); describe('loadData()', () => { @@ -19,7 +16,7 @@ describe('vnWorkerDescriptorPopover', () => { const id = 1; const response = 'foo'; - $httpBackend.expectGET(`Workers/${id}`).respond(response); + $httpBackend.expectRoute('GET', `Workers/${id}`).respond(response); controller.id = id; $httpBackend.flush(); diff --git a/modules/zone/front/descriptor/index.html b/modules/zone/front/descriptor/index.html index 90f4effea..c407ff661 100644 --- a/modules/zone/front/descriptor/index.html +++ b/modules/zone/front/descriptor/index.html @@ -1,22 +1,16 @@ -
- - - - - - - - - - -
+ + +
    +
  • +
    + Delete +
    +
  • +
+
+
-
-
+ + this.$.deleteZone.show(), - } - ]; + get zone() { + return this.entity; } - onMoreChange(callback) { - callback.call(this); + set zone(value) { + this.entity = value; } onDeleteAccept() { - return this.$http.delete(`Zones/${this.zone.id}`).then(() => { - this.$state.go('zone.index'); - }); + return this.$http.delete(`Zones/${this.id}`) + .then(() => this.$state.go('zone.index')); } }