From 58260996019e3fd04ed78188b6d3c3fa09bb421c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sat, 25 Apr 2020 11:50:04 +0200 Subject: [PATCH] #1882 First step, front tests passed --- front/core/components/confirm/confirm.html | 20 +-- front/core/components/confirm/confirm.js | 10 +- front/core/components/dialog/index.html | 46 +++--- front/core/components/dialog/index.js | 21 +-- front/core/components/dialog/style.scss | 3 + front/core/components/drop-down/index.html | 44 +++--- front/core/components/drop-down/index.js | 3 +- front/core/components/form-input/index.js | 6 - front/core/components/popover/index.js | 9 +- front/core/components/popup/index.js | 12 +- front/core/directives/click-stop.js | 23 +++ front/core/directives/index.js | 1 + front/core/lib/component.js | 142 ++++++++++++------ front/core/module.js | 50 +++--- front/core/styles/layout.scss | 27 +--- .../components/descriptor-popover/index.html | 11 ++ .../components/descriptor-popover/index.js | 83 ++++++++++ .../components/descriptor-popover/style.scss | 13 ++ front/salix/components/descriptor/index.js | 23 ++- .../components/descriptor/quick-links.html | 8 + .../components/descriptor/quick-links.js | 11 ++ front/salix/components/index.js | 1 + front/salix/components/layout/index.html | 3 +- front/salix/components/layout/style.scss | 4 +- front/salix/components/module-card/index.js | 5 - front/salix/components/module-main/index.js | 7 +- front/salix/components/section/index.js | 12 +- front/salix/components/user-popover/index.js | 13 +- front/salix/config.json | 25 +++ front/salix/module.js | 21 ++- modules/claim/front/action/index.html | 10 +- modules/claim/front/action/index.js | 15 -- modules/claim/front/descriptor/index.js | 19 +-- modules/claim/front/detail/index.html | 21 +-- modules/claim/front/detail/index.js | 7 - modules/claim/front/detail/index.spec.js | 19 --- modules/claim/front/development/index.html | 8 +- modules/claim/front/index/index.html | 21 +-- modules/claim/front/index/index.js | 26 +--- modules/claim/front/summary/index.html | 23 +-- modules/claim/front/summary/index.js | 18 --- .../client/front/balance/create/index.html | 82 +++++----- modules/client/front/balance/create/index.js | 4 +- modules/client/front/balance/index/index.html | 33 ++-- modules/client/front/balance/index/index.js | 23 --- .../front/descriptor-popover/index.html | 12 +- .../client/front/descriptor-popover/index.js | 67 ++------- .../front/descriptor-popover/index.spec.js | 87 +++-------- .../front/descriptor-popover/style.scss | 9 -- modules/client/front/descriptor/index.html | 75 ++++++--- modules/client/front/descriptor/index.js | 64 +++----- modules/client/front/sample/index/index.html | 3 +- modules/entry/front/descriptor/index.js | 21 +-- .../front/descriptor-popover/index.html | 12 +- .../front/descriptor-popover/index.js | 65 ++------ .../front/descriptor-popover/style.scss | 11 -- modules/invoiceOut/front/descriptor/index.js | 21 +-- modules/invoiceOut/front/index/index.html | 6 +- modules/invoiceOut/front/index/index.js | 20 +-- modules/invoiceOut/front/summary/index.html | 4 +- modules/invoiceOut/front/summary/index.js | 25 +-- .../item/front/descriptor-popover/index.html | 10 +- .../item/front/descriptor-popover/index.js | 72 ++------- .../front/descriptor-popover/index.spec.js | 88 +++-------- .../item/front/descriptor-popover/style.scss | 5 - modules/item/front/descriptor/index.html | 4 +- modules/item/front/descriptor/index.js | 11 +- modules/item/front/diary/index.html | 12 +- modules/item/front/diary/index.js | 32 +--- modules/item/front/index/index.html | 40 ++--- modules/item/front/index/index.js | 53 +------ modules/item/front/index/index.spec.js | 33 +--- modules/item/front/summary/index.html | 4 +- modules/order/front/catalog-view/index.html | 4 +- modules/order/front/descriptor/index.js | 18 +-- modules/order/front/index/index.html | 23 +-- modules/order/front/index/index.js | 24 +-- modules/order/front/line/index.html | 4 +- .../route/front/descriptor-popover/index.html | 12 +- .../route/front/descriptor-popover/index.js | 78 ++-------- .../front/descriptor-popover/index.spec.js | 70 ++------- .../route/front/descriptor-popover/style.scss | 9 -- modules/route/front/descriptor/index.js | 21 +-- modules/route/front/index/index.html | 3 +- modules/route/front/main/index.js | 6 - modules/route/front/summary/index.html | 4 +- modules/route/front/summary/index.js | 14 -- modules/route/front/tickets/index.html | 10 +- modules/route/front/tickets/index.js | 14 -- modules/route/front/tickets/index.spec.js | 30 ---- .../front/descriptor-popover/index.html | 10 +- .../ticket/front/descriptor-popover/index.js | 90 +++-------- .../front/descriptor-popover/index.spec.js | 119 ++------------- .../front/descriptor-popover/style.scss | 11 -- .../ticket/front/descriptor/addStowaway.js | 2 +- modules/ticket/front/descriptor/index.js | 18 +-- modules/ticket/front/expedition/index.html | 3 +- modules/ticket/front/index/index.html | 28 ++-- modules/ticket/front/index/index.js | 29 +--- modules/ticket/front/index/index.spec.js | 15 -- modules/ticket/front/picture/index.html | 8 +- modules/ticket/front/request/index/index.html | 3 +- modules/ticket/front/sale-tracking/index.html | 6 +- modules/ticket/front/sale/index.html | 4 +- modules/ticket/front/sale/index.js | 1 - .../ticket/front/tracking/index/index.html | 3 +- modules/ticket/front/volume/index.html | 3 +- modules/ticket/front/weekly/index.html | 29 ++-- modules/ticket/front/weekly/index.js | 30 +--- .../front/descriptor-popover/index.html | 12 +- .../travel/front/descriptor-popover/index.js | 61 ++------ .../front/descriptor-popover/index.spec.js | 93 ++---------- modules/travel/front/descriptor/index.js | 6 +- modules/travel/front/index/index.html | 7 +- modules/travel/front/index/index.js | 8 +- modules/travel/front/summary/index.html | 32 ++-- modules/travel/front/summary/index.js | 33 ++-- modules/travel/front/summary/index.spec.js | 22 +-- .../front/descriptor-popover/index.html | 12 +- .../worker/front/descriptor-popover/index.js | 70 ++------- .../front/descriptor-popover/index.spec.js | 97 ++---------- modules/worker/front/descriptor/index.js | 15 +- modules/worker/front/dms/create/index.js | 2 +- modules/worker/front/log/index.html | 3 +- modules/zone/front/delivery-days/index.html | 2 +- modules/zone/front/delivery-days/index.js | 3 +- modules/zone/front/descriptor/index.html | 28 ++-- modules/zone/front/descriptor/index.js | 25 ++- modules/zone/front/index/index.html | 4 +- modules/zone/front/index/index.js | 8 +- 130 files changed, 1039 insertions(+), 2112 deletions(-) create mode 100644 front/core/directives/click-stop.js create mode 100644 front/salix/components/descriptor-popover/index.html create mode 100644 front/salix/components/descriptor-popover/index.js create mode 100644 front/salix/components/descriptor-popover/style.scss create mode 100644 front/salix/components/descriptor/quick-links.html create mode 100644 front/salix/components/descriptor/quick-links.js create mode 100644 front/salix/config.json delete mode 100644 modules/client/front/descriptor-popover/style.scss delete mode 100644 modules/invoiceOut/front/descriptor-popover/style.scss delete mode 100644 modules/item/front/descriptor-popover/style.scss delete mode 100644 modules/route/front/descriptor-popover/style.scss delete mode 100644 modules/ticket/front/descriptor-popover/style.scss diff --git a/front/core/components/confirm/confirm.html b/front/core/components/confirm/confirm.html index 5ef8fde75..be839078a 100644 --- a/front/core/components/confirm/confirm.html +++ b/front/core/components/confirm/confirm.html @@ -1,10 +1,10 @@ -
- -
{{::$ctrl.message}}
- {{::$ctrl.question}} -
- - - - -
\ No newline at end of file + + {{::$ctrl.message}} + + + {{::$ctrl.question}} + + + + + \ No newline at end of file diff --git a/front/core/components/confirm/confirm.js b/front/core/components/confirm/confirm.js index c0a1cc0c5..e4a9683f4 100644 --- a/front/core/components/confirm/confirm.js +++ b/front/core/components/confirm/confirm.js @@ -1,18 +1,12 @@ import ngModule from '../../module'; import Dialog from '../dialog'; -import template from './confirm.html'; import './style.scss'; -export default class Confirm extends Dialog { - constructor($element, $, $transclude) { - super($element, $, $transclude); - this.fillSlots(template); - } -} +export default class Confirm extends Dialog {} ngModule.vnComponent('vnConfirm', { + slotTemplate: require('./confirm.html'), controller: Confirm, - transclude: true, bindings: { question: '@', message: '@?' diff --git a/front/core/components/dialog/index.html b/front/core/components/dialog/index.html index c213042e1..669db60fd 100644 --- a/front/core/components/dialog/index.html +++ b/front/core/components/dialog/index.html @@ -1,22 +1,28 @@ -
- -
- - -
+
+ ng-if="$ctrl.loading" + class="loading-overlap shown"> +
-
-
- \ No newline at end of file + + +
+
+
+
+
+
+
+
+
diff --git a/front/core/components/dialog/index.js b/front/core/components/dialog/index.js index dfc1e5d3a..d19a3223d 100644 --- a/front/core/components/dialog/index.js +++ b/front/core/components/dialog/index.js @@ -1,6 +1,5 @@ import ngModule from '../../module'; import Popup from '../popup'; -import template from './index.html'; import './style.scss'; /** @@ -16,22 +15,6 @@ import './style.scss'; * @slot buttons The dialog HTML buttons */ export default class Dialog extends Popup { - constructor($element, $, $transclude) { - super($element, $, $transclude); - this.fillDefaultSlot(template); - } - - /** - * Fills the dialog slots, it is intended to be used by child classes. - * - * @param {String} template The HTML template string - */ - fillSlots(template) { - let $template = angular.element(template); - this.fillSlot('body', $template.find('tpl-body')); - this.fillSlot('buttons', $template.find('tpl-buttons')); - } - /** * Shows the dialog and optionally registers a handler for the response. * @@ -149,9 +132,11 @@ export default class Dialog extends Popup { } ngModule.vnComponent('vnDialog', { + slotTemplate: require('./index.html'), controller: Dialog, transclude: { - body: 'tplBody', + title: '?tplTitle', + body: '?tplBody', buttons: '?tplButtons' }, bindings: { diff --git a/front/core/components/dialog/style.scss b/front/core/components/dialog/style.scss index e4884c362..47837af7e 100644 --- a/front/core/components/dialog/style.scss +++ b/front/core/components/dialog/style.scss @@ -18,6 +18,9 @@ & > form { padding: $spacing-lg; + & > h6 { + margin-bottom: $spacing-md; + } & > .body > tpl-body { display: block; min-width: 256px; diff --git a/front/core/components/drop-down/index.html b/front/core/components/drop-down/index.html index 52ceeeaae..ab868f7b5 100644 --- a/front/core/components/drop-down/index.html +++ b/front/core/components/drop-down/index.html @@ -1,22 +1,24 @@ -
- - -
-
- -
- {{$ctrl.statusText}} + +
+ +
-
\ No newline at end of file +
+ +
+ {{$ctrl.statusText}} +
+
+ \ No newline at end of file diff --git a/front/core/components/drop-down/index.js b/front/core/components/drop-down/index.js index ed7de7179..dfdfbe18d 100644 --- a/front/core/components/drop-down/index.js +++ b/front/core/components/drop-down/index.js @@ -1,7 +1,6 @@ import './style.scss'; import ngModule from '../../module'; import Popover from '../popover'; -import template from './index.html'; import ArrayModel from '../array-model/array-model'; import CrudModel from '../crud-model/crud-model'; import {mergeWhere} from 'vn-loopback/util/filter'; @@ -21,7 +20,6 @@ export default class DropDown extends Popover { this.showLoadMore = true; this.showFilter = true; this.searchDelay = 300; - this.fillDefaultSlot(template); } get search() { @@ -458,6 +456,7 @@ function getPosition(parent, event) { } ngModule.vnComponent('vnDropDown', { + slotTemplate: require('./index.html'), controller: DropDown, transclude: { tplItem: '?tplItem' diff --git a/front/core/components/form-input/index.js b/front/core/components/form-input/index.js index 0395922c7..c50102e8a 100644 --- a/front/core/components/form-input/index.js +++ b/front/core/components/form-input/index.js @@ -9,12 +9,6 @@ import Component from '../../lib/component'; * @property {Boolean} disabled Put component in disabled mode */ export default class FormInput extends Component { - constructor($element, $scope) { - super($element, $scope); - this.classList = this.element.classList; - this.classList.add(...this.constructor.$classNames); - } - $onInit() { // XXX: Compatibility with old inputs let attrs = this.$element[0].attributes; diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index 7c54ce494..f7ab30b62 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -13,8 +13,8 @@ import './style.scss'; * @event close Thrown when popover is hidden */ export default class Popover extends Popup { - constructor($element, $, $transclude) { - super($element, $, $transclude); + constructor(...args) { + super(...args); this.displayMode = isMobile ? 'centered' : 'relative'; this.template = template; } @@ -23,9 +23,12 @@ export default class Popover extends Popup { * Shows the popover emitting the open signal. If a parent is specified * it is shown in a visible relative position to it. * - * @param {HTMLElement} parent Overrides the parent property + * @param {HTMLElement|Event} parent Overrides the parent property */ show(parent) { + if (parent instanceof Event) + parent = event.target; + if (parent) this.parent = parent; super.show(); this.content = this.popup.querySelector('.content'); diff --git a/front/core/components/popup/index.js b/front/core/components/popup/index.js index 0dea66254..6e8c4df75 100644 --- a/front/core/components/popup/index.js +++ b/front/core/components/popup/index.js @@ -7,9 +7,8 @@ import './style.scss'; * Base class for windows displayed over application content. */ export default class Popup extends Component { - constructor($element, $scope, $transclude) { - super($element, $scope); - this.$transclude = $transclude; + constructor(...args) { + super(...args); this._shown = false; this.displayMode = 'centered'; this.template = template; @@ -45,11 +44,13 @@ export default class Popup extends Component { this.onClose(); } - let linkFn = this.$compile(this.template); this.$contentScope = this.$.$new(); + + let linkFn = this.$compile(this.template); this.popup = linkFn(this.$contentScope, null, {parentBoundTranscludeFn: this.$transclude} )[0]; + this.windowEl = this.popup.querySelector('.window'); this.windowEl.focus(); @@ -127,5 +128,6 @@ ngModule.vnComponent('vnPopup', { transclude: true, bindings: { shown: '=?' - } + }, + installClasses: false }); diff --git a/front/core/directives/click-stop.js b/front/core/directives/click-stop.js new file mode 100644 index 000000000..c13bbecae --- /dev/null +++ b/front/core/directives/click-stop.js @@ -0,0 +1,23 @@ +import ngModule from '../module'; + +/* + * Registers a handler for the click event and stops propagation when event + * is thrown, mainly when nesting clickable elements wich ignore the + * Event.defaultPrevented property, like ui-sref. + */ +export function directive($parse) { + return { + restrict: 'A', + link: function(scope, element, attrs) { + const fn = $parse(attrs.vnClickStop); + element.on('click', function(event) { + fn(scope, {$event: event}); + event.stopPropagation(); + event.preventDefault(); + }); + } + }; +} +directive.$inject = ['$parse']; + +ngModule.directive('vnClickStop', directive); diff --git a/front/core/directives/index.js b/front/core/directives/index.js index 185046a3c..4377afe8c 100644 --- a/front/core/directives/index.js +++ b/front/core/directives/index.js @@ -2,6 +2,7 @@ import './id'; import './focus'; import './dialog'; import './popover'; +import './click-stop'; import './rule'; import './acl'; import './on-error-src'; diff --git a/front/core/lib/component.js b/front/core/lib/component.js index 4552dfbe7..39d593cf0 100644 --- a/front/core/lib/component.js +++ b/front/core/lib/component.js @@ -11,14 +11,29 @@ export default class Component extends EventEmitter { * * @param {HTMLElement} $element The main component element * @param {$rootScope.Scope} $scope The element scope + * @param {Function} $transclude The transclusion function */ - constructor($element, $scope) { + constructor($element, $scope, $transclude) { super(); + this.$ = $scope; + if (!$element) return; this.element = $element[0]; this.element.$ctrl = this; this.$element = $element; - this.$ = $scope; + this.$transclude = $transclude; + this.classList = this.element.classList; + + const constructor = this.constructor; + const $options = constructor.$options; + + if ($options && $options.installClasses) + this.classList.add(...this.constructor.$classNames); + + if ($transclude && constructor.slotTemplates) { + for (let slotTemplate of constructor.slotTemplates) + this.fillSlots(slotTemplate); + } } $postLink() { @@ -26,7 +41,7 @@ export default class Component extends EventEmitter { let attrs = this.$element[0].attributes; let $scope = this.$; for (let attr of attrs) { - if (attr.name.substr(0, 2) !== 'on') continue; + if (!attr.name.startsWith('on-')) continue; let eventName = kebabToCamel(attr.name.substr(3)); let callback = locals => $scope.$parent.$eval(attr.nodeValue, locals); this.on(eventName, callback); @@ -58,6 +73,72 @@ export default class Component extends EventEmitter { return this.$translate.instant(string, params); } + /** + * Fills the default transclude slot. + * + * @param {JQElement|String} template The slot template + */ + fillDefaultSlot(template) { + const linkFn = this.$compile(template); + this.$transclude.$$boundTransclude = this.createBoundTranscludeFn(linkFn); + } + + /** + * Fills a named transclude slot. + * + * @param {String} slot The trasnclude slot name + * @param {JQElement|String} template The slot name + */ + fillSlot(slot, template) { + const linkFn = this.$compile(template); + const slots = this.$transclude.$$boundTransclude.$$slots; + slots[slot] = this.createBoundTranscludeFn(linkFn); + } + + /** + * Fills component transclude slots using the passed HTML template string + * as source. + * + * @param {String} template The HTML template string + */ + fillSlots(template) { + const name = this.constructor.$options.name; + const transclude = this.constructor.$options.transclude; + + if (!transclude) + throw new Error(`No transclusion option defined in '${name}'`); + if (!this.$transclude) + throw new Error(`No $transclude injected in '${name}'`); + + let slotMap = {}; + for (let slotName in transclude) { + let slotTag = transclude[slotName].match(/\w+$/)[0]; + slotMap[slotTag] = slotName; + } + + const $template = angular.element(template); + for (let i = 0; i < $template.length; i++) { + let slotElement = $template[i]; + if (slotElement.nodeType != Node.ELEMENT_NODE) continue; + let tagName = kebabToCamel(slotElement.tagName.toLowerCase()); + + if (tagName == 'default') + this.fillDefaultSlot(slotElement.childNodes); + else { + let slotName = slotMap[tagName]; + if (!slotName) + throw new Error(`No slot found for '${tagName}' in '${name}'`); + this.fillSlot(slotName, slotElement); + } + } + } + + /** + * Creates a bounded transclude function from a linking function. + * + * @param {Function} linkFn The linking function + * @return {Function} The bounded transclude function + */ createBoundTranscludeFn(linkFn) { let scope = this.$; let previousBoundTranscludeFn = this.$transclude.$$boundTransclude; @@ -78,17 +159,6 @@ export default class Component extends EventEmitter { return vnBoundTranscludeFn; } - fillDefaultSlot(template) { - let linkFn = this.$compile(template); - this.$transclude.$$boundTransclude = this.createBoundTranscludeFn(linkFn); - } - - fillSlot(slot, template) { - let slots = this.$transclude.$$boundTransclude.$$slots; - let linkFn = this.$compile(template); - slots[slot] = this.createBoundTranscludeFn(linkFn); - } - copySlot(slot, $transclude) { this.$transclude.$$boundTransclude.$$slots[slot] = $transclude.$$boundTransclude.$$slots[slot]; @@ -96,38 +166,18 @@ export default class Component extends EventEmitter { } Component.$inject = ['$element', '$scope']; -function runFn( - $translate, - $q, - $http, - $state, - $stateParams, - $timeout, - $transitions, - $compile, - $filter, - $interpolate, - $window, - vnApp, - vnToken, - vnConfig, - aclService) { - Object.assign(Component.prototype, { - $translate, - $q, - $http, - $state, - $params: $stateParams, - $timeout, - $transitions, - $compile, - $filter, - $interpolate, - $window, - vnApp, - vnToken, - vnConfig, - aclService +/* + * Automatically adds the most used services to the prototype, so they are + * available as component properties. + */ +function runFn(...args) { + const proto = Component.prototype; + + for (let i = 0; i < runFn.$inject.length; i++) + proto[runFn.$inject[i]] = args[i]; + + Object.assign(proto, { + $params: proto.$stateParams }); } runFn.$inject = [ diff --git a/front/core/module.js b/front/core/module.js index 82a954892..f80f11853 100644 --- a/front/core/module.js +++ b/front/core/module.js @@ -1,6 +1,16 @@ import {ng, ngDeps} from './vendor'; import {camelToKebab} from './lib/string'; +/** + * Extended component options. + * + * @property {Boolean} installClassses Whether to install CSS classes equivalent to the component's and parents name + * @property {String} slotTemplate HTML template used to fill component transclude slots + */ +const defaultOptions = { + installClasses: true +}; + /** * Acts like native Module.component() function but merging component options * with parent component options. This method establishes the $options property @@ -17,7 +27,7 @@ import {camelToKebab} from './lib/string'; function vnComponent(name, options) { let controller = options.controller; let parent = Object.getPrototypeOf(controller); - let parentOptions = parent.$options || {}; + let parentOptions = parent.$options || defaultOptions; let parentTransclude = parentOptions.transclude; let transclude = parentTransclude instanceof Object @@ -32,10 +42,11 @@ function vnComponent(name, options) { } else if (options.transclude !== undefined) transclude = options.transclude; - let mergedOptions = Object.assign({}, + let $options = Object.assign({}, parentOptions, options, { + name, transclude, bindings: Object.assign({}, parentOptions.bindings, @@ -47,13 +58,17 @@ function vnComponent(name, options) { ) } ); - controller.$options = mergedOptions; + + let parentSlotTemplates = parent.slotTemplates || []; + if (options.slotTemplate) + controller.slotTemplates = parentSlotTemplates.concat([options.slotTemplate]); let classNames = [camelToKebab(name)]; if (parent.$classNames) classNames = classNames.concat(parent.$classNames); controller.$classNames = classNames; - return this.component(name, mergedOptions); + controller.$options = $options; + return this.component(name, $options); } const ngModuleFn = ng.module; @@ -72,33 +87,12 @@ export function config($translateProvider, $translatePartialLoaderProvider, $ani // For CSS browser targeting document.documentElement.setAttribute('data-browser', navigator.userAgent); - $translatePartialLoaderProvider.addPart('core'); - - let conf = {urlTemplate: '/locale/{part}/{lang}.json'}; - - let fallbackLang = 'es'; - let langs = ['en', 'es']; - let langAliases = { - en_US: 'en', - en_GB: 'en', - es_ES: 'es', - es_AR: 'es' - }; - $translateProvider .useSanitizeValueStrategy('escape') - .useLoader('$translatePartialLoader', conf) - .registerAvailableLanguageKeys(langs, langAliases) - // FIXME: Circular dependency due to vnInterceptor - // .fallbackLanguage(fallbackLang) - .determinePreferredLanguage(() => { - let locale = $translateProvider.resolveClientLocale(); - if (langs.indexOf(locale) !== -1) - return locale; - if (langAliases[locale]) - return langAliases[locale]; - return fallbackLang; + .useLoader('$translatePartialLoader', { + urlTemplate: '/locale/{part}/{lang}.json' }); + $translatePartialLoaderProvider.addPart('core'); $animateProvider.customFilter( node => node.tagName == 'UI-VIEW'); diff --git a/front/core/styles/layout.scss b/front/core/styles/layout.scss index 85088db6a..8be4d1c73 100644 --- a/front/core/styles/layout.scss +++ b/front/core/styles/layout.scss @@ -4,17 +4,19 @@ html [vn-horizontal], vn-horizontal, .vn-horizontal, html [vn-vertical], vn-vertical, .vn-vertical { display: flex; + + & > * { + flex: 1; + } } html [vn-horizontal], vn-horizontal, .vn-horizontal { flex-direction: row; } -vn-horizontal[reverse] { - flex-direction: row-reverse; -} html [vn-vertical], vn-vertical, .vn-vertical { flex-direction: column; } -vn-vertical[reverse] { + +html [reverse] { flex-direction: column-reverse; } html [wrap] { @@ -26,27 +28,12 @@ html [wrap-reverse] { /* Horizontal & vertical childs */ -html [vn-auto], -html [vn-none], -html [vn-one], -html [vn-two], -html [vn-three], -html [vn-four], -html [vn-five], -html [vn-six], -html [vn-seven], -html [vn-eight], -html [vn-nine], -html [vn-ten], -html [vn-eleven], -html [vn-twelve]{ - flex-basis: .1px; -} html [vn-auto], vn-auto, .vn-auto { flex-basis: auto; } html [vn-none], vn-none, .vn-none { flex: none; + flex-basis: .1px; } html [vn-one], vn-one, .vn-one { flex: 1; diff --git a/front/salix/components/descriptor-popover/index.html b/front/salix/components/descriptor-popover/index.html new file mode 100644 index 000000000..bedb32f0f --- /dev/null +++ b/front/salix/components/descriptor-popover/index.html @@ -0,0 +1,11 @@ + + + +
+
+
\ No newline at end of file diff --git a/front/salix/components/descriptor-popover/index.js b/front/salix/components/descriptor-popover/index.js new file mode 100644 index 000000000..7de04a64b --- /dev/null +++ b/front/salix/components/descriptor-popover/index.js @@ -0,0 +1,83 @@ +import ngModule from '../../module'; +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 => { + this.canceler = null; + this.$.$applyAsync(() => this.relocate()); + return res; + }); + } +} + +ngModule.vnComponent('vnDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: DescriptorPopover, + bindings: { + id: ' vn-spinner { + padding: $spacing-md; + display: block; + margin: 0 auto; + height: 45px; + } + .descriptor-wrapper { + width: 260px; + } +} \ No newline at end of file diff --git a/front/salix/components/descriptor/index.js b/front/salix/components/descriptor/index.js index 504812b15..844e33542 100644 --- a/front/salix/components/descriptor/index.js +++ b/front/salix/components/descriptor/index.js @@ -1,12 +1,21 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; +import './quick-links'; import './style.scss'; -export default class QuickLinks {} - -ngModule.component('vnQuickLinks', { - template: require('./index.html'), - controller: QuickLinks, - bindings: { - links: ' + + + \ No newline at end of file diff --git a/front/salix/components/descriptor/quick-links.js b/front/salix/components/descriptor/quick-links.js new file mode 100644 index 000000000..e7f9bdb24 --- /dev/null +++ b/front/salix/components/descriptor/quick-links.js @@ -0,0 +1,11 @@ +import ngModule from '../../module'; + +export default class QuickLinks {} + +ngModule.component('vnQuickLinks', { + template: require('./quick-links.html'), + controller: QuickLinks, + bindings: { + links: ' - \ No newline at end of file + + \ No newline at end of file diff --git a/front/salix/components/layout/style.scss b/front/salix/components/layout/style.scss index 14af8ac23..680ed3e41 100644 --- a/front/salix/components/layout/style.scss +++ b/front/salix/components/layout/style.scss @@ -32,7 +32,7 @@ vn-layout { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; - padding-left: 6px; + padding-left: 10px; } & > vn-spinner { padding: 0 6px; @@ -80,7 +80,7 @@ vn-layout { padding-right: $menu-width; } [fixed-bottom-right] { - right: 64px + $menu-width; + right: 32px + $menu-width; } } & > .main-view { diff --git a/front/salix/components/module-card/index.js b/front/salix/components/module-card/index.js index 9131cc772..9e547445f 100644 --- a/front/salix/components/module-card/index.js +++ b/front/salix/components/module-card/index.js @@ -6,11 +6,6 @@ import './style.scss'; * Base class for module cards. */ export default class ModuleCard extends Component { - constructor($element, $) { - super($element, $); - this.element.classList.add('vn-module-card'); - } - $onInit() { this.reload(); } diff --git a/front/salix/components/module-main/index.js b/front/salix/components/module-main/index.js index 39fbe42b8..ab292273c 100644 --- a/front/salix/components/module-main/index.js +++ b/front/salix/components/module-main/index.js @@ -2,12 +2,7 @@ import ngModule from '../../module'; import Component from 'core/lib/component'; import './style.scss'; -export default class ModuleMain extends Component { - constructor($element, $) { - super($element, $); - this.element.classList.add('vn-module-main'); - } -} +export default class ModuleMain extends Component {} ngModule.vnComponent('vnModuleMain', { template: require('./index.html'), diff --git a/front/salix/components/section/index.js b/front/salix/components/section/index.js index c34459147..f2440964c 100644 --- a/front/salix/components/section/index.js +++ b/front/salix/components/section/index.js @@ -2,17 +2,7 @@ import ngModule from '../../module'; import Component from 'core/lib/component'; import './style.scss'; -export default class Section extends Component { - constructor($element, $) { - super($element, $); - this.element.classList.add('vn-section'); - } - - stopEvent(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } -} +export default class Section extends Component {} ngModule.vnComponent('vnSection', { controller: Section diff --git a/front/salix/components/user-popover/index.js b/front/salix/components/user-popover/index.js index 764b0cae9..88efb26d1 100644 --- a/front/salix/components/user-popover/index.js +++ b/front/salix/components/user-popover/index.js @@ -1,15 +1,6 @@ import ngModule from '../../module'; import './style.scss'; - -let languages = { - es: 'Español', - en: 'English', - ca: 'Català', - pt: 'Português', - fr: 'Français', - nl: 'Nederlands', - mn: 'Монгол хэл' -}; +import config from '../../config.json'; class Controller { constructor($, $translate, vnConfig, vnAuth) { @@ -25,7 +16,7 @@ class Controller { for (let code of $translate.getAvailableLanguageKeys()) { this.langs.push({ code: code, - name: languages[code] ? languages[code] : code + name: config.languages[code] ? config.languages[code] : code }); } diff --git a/front/salix/config.json b/front/salix/config.json new file mode 100644 index 000000000..d87b70ae9 --- /dev/null +++ b/front/salix/config.json @@ -0,0 +1,25 @@ +{ + "imagePath": "//verdnatura.es/vn-image-data", + "langOptions": { + "fallbackLang": "es", + "langs": [ + "en", + "es" + ], + "langAliases": { + "en_US": "en", + "en_GB": "en", + "es_ES": "es", + "es_AR": "es" + } + }, + "languages": { + "es": "Español", + "en": "English", + "ca": "Català", + "pt": "Português", + "fr": "Français", + "nl": "Nederlands", + "mn": "Монгол хэл" + } +} diff --git a/front/salix/module.js b/front/salix/module.js index 34e53b8bd..c3e8dcb8a 100644 --- a/front/salix/module.js +++ b/front/salix/module.js @@ -1,4 +1,5 @@ import {ng} from 'core/vendor'; +import appConfig from './config.json'; import 'core'; export const appName = 'salix'; @@ -8,6 +9,8 @@ export default ngModule; run.$inject = ['$window', '$rootScope', 'vnAuth', 'vnApp', '$state']; export function run($window, $rootScope, vnAuth, vnApp, $state) { + $rootScope.imagePath = appConfig.imagePath; + $window.validations = {}; vnApp.name = appName; @@ -57,8 +60,22 @@ export function run($window, $rootScope, vnAuth, vnApp, $state) { } ngModule.run(run); -config.$inject = ['$translatePartialLoaderProvider', '$httpProvider', '$compileProvider']; -export function config($translatePartialLoaderProvider, $httpProvider, $compileProvider) { +config.$inject = ['$translateProvider', '$translatePartialLoaderProvider', '$httpProvider', '$compileProvider']; +export function config($translateProvider, $translatePartialLoaderProvider, $httpProvider, $compileProvider) { + const langOptions = appConfig.langOptions; + $translateProvider + .registerAvailableLanguageKeys(langOptions.langs, langOptions.langAliases) + // TODO: Circular dependency due to vnInterceptor + // .fallbackLanguage(langOptions.fallbackLang) + .determinePreferredLanguage(() => { + const locale = $translateProvider.resolveClientLocale(); + if (langOptions.langs.indexOf(locale) !== -1) + return locale; + if (langOptions.langAliases[locale]) + return langOptions.langAliases[locale]; + return fallbackLang; + }); + $translatePartialLoaderProvider.addPart(appName); $httpProvider.interceptors.push('vnInterceptor'); diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 31db6dabd..19cb5c06e 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -6,19 +6,16 @@ auto-save="true" on-save="$ctrl.onSave()"> - - -
@@ -53,7 +50,6 @@ on-change="$ctrl.saveMana(value)">
- @@ -75,7 +71,7 @@ vn-repeat-last on-last="$ctrl.focusLastInput()"> {{::saleClaimed.sale.itemFk | zeroFill:6}} @@ -83,7 +79,7 @@ + ng-click="ticketDescriptor.show($event, saleClaimed.sale.ticketFk)"> {{::saleClaimed.sale.ticketFk}} @@ -117,7 +113,6 @@ -
- diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index a847ef009..fe9bb78df 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -63,14 +63,6 @@ export default class Controller extends Section { }); } - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - - event.preventDefault(); - } - focusLastInput() { let inputs = document.querySelectorAll('#claimDestinationFk'); inputs[inputs.length - 1].querySelector('input').focus(); @@ -172,13 +164,6 @@ export default class Controller extends Section { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); } - // Item Descriptor - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - saveResponsibility(value) { let query = `Claims/${this.$params.id}/updateClaimAction`; diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index 55048c20c..b65fc870b 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { constructor($element, $, $httpParamSerializer) { super($element, $); this.$httpParamSerializer = $httpParamSerializer; @@ -49,14 +49,6 @@ class Controller extends Component { }; } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - showPickupOrder() { const params = { clientId: this.claim.clientFk, @@ -80,7 +72,7 @@ class Controller extends Component { claimId: this.claim.id }; this.$http.get(`email/claim-pickup-order`, {params}).then( - () => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) + () => this.vnApp.showMessage(this.$t('Notification sent!')) ); } } @@ -101,12 +93,11 @@ class Controller extends Component { Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; -ngModule.component('vnClaimDescriptor', { +ngModule.vnComponent('vnClaimDescriptor', { template: require('./index.html'), controller: Controller, bindings: { claim: '<', - tags: '<', - quicklinks: '<' + tags: '<' } }); diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html index 7e225b16a..794003e12 100644 --- a/modules/claim/front/detail/index.html +++ b/modules/claim/front/detail/index.html @@ -46,9 +46,9 @@ - + {{::saleClaimed.sale.concept}} @@ -98,14 +98,17 @@ - + {{sale.landed | date: 'dd/MM/yyyy'}} {{sale.quantity}} - - {{sale.concept}} + + {{sale.itemFk}} - {{sale.concept}} {{sale.price | currency: 'EUR':2}} @@ -120,7 +123,7 @@ + vn-id="itemDescriptor"> { }); }); - describe('showItemDescriptor()', () => { - it('should configure the descriptor then show it', () => { - const itemId = 500; - const event = { - stopImmediatePropagation: () => {}, - target: 'the target element' - }; - jest.spyOn(event, 'stopImmediatePropagation'); - jest.spyOn(controller.$.descriptor, 'show'); - - controller.showItemDescriptor(event, itemId); - - expect(event.stopImmediatePropagation).toHaveBeenCalledWith(); - expect(controller.$.descriptor.itemFk).toEqual(itemId); - expect(controller.$.descriptor.parent).toEqual(event.target); - expect(controller.$.descriptor.show).toHaveBeenCalledWith(); - }); - }); - describe('isClaimEditable()', () => { it('should check if the claim is editable', () => { controller.isClaimEditable(); diff --git a/modules/claim/front/development/index.html b/modules/claim/front/development/index.html index 2b504be11..3a78e6374 100644 --- a/modules/claim/front/development/index.html +++ b/modules/claim/front/development/index.html @@ -42,7 +42,6 @@
- {{::claim.id}} - + {{::claim.name}} {{::claim.created | date:'dd/MM/yyyy'}} - + {{::claim.nickName}} @@ -42,7 +44,7 @@ @@ -56,10 +58,11 @@ vn-id="clientDescriptor"> + vn-id="workerDescriptor"> - - + + + \ No newline at end of file diff --git a/modules/claim/front/index/index.js b/modules/claim/front/index/index.js index df6d15b38..773c6a999 100644 --- a/modules/claim/front/index/index.js +++ b/modules/claim/front/index/index.js @@ -13,31 +13,9 @@ export default class Controller extends Section { } } - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - preview(event, claim) { + preview(claim) { this.claimSelected = claim; - this.$.dialogSummaryClaim.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); + this.$.summary.show(); } } diff --git a/modules/claim/front/summary/index.html b/modules/claim/front/summary/index.html index 6f639c709..1c99d4119 100644 --- a/modules/claim/front/summary/index.html +++ b/modules/claim/front/summary/index.html @@ -6,16 +6,20 @@
{{::$ctrl.summary.claim.id}} - {{::$ctrl.summary.claim.client.name}}
- - - - @@ -61,7 +65,7 @@ {{::saleClaimed.sale.itemFk | zeroFill:6}} @@ -113,7 +117,7 @@ + ng-click="workerDescriptor.show($event, development.workerFk)"> {{::development.worker.user.nickname}} @@ -144,14 +148,14 @@ {{::action.sale.itemFk | zeroFill:6}} {{::action.sale.ticket.id | zeroFill:6}} @@ -177,8 +181,7 @@ vn-id="itemDescriptor"> + vn-id="workerDescriptor"> diff --git a/modules/claim/front/summary/index.js b/modules/claim/front/summary/index.js index 094aa49fe..0ccf6dcd2 100644 --- a/modules/claim/front/summary/index.js +++ b/modules/claim/front/summary/index.js @@ -32,24 +32,6 @@ class Controller extends Section { this.summary = response.data; }); } - - showItemDescriptor(event, itemFk) { - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - showTicketDescriptor(event, ticketId) { - this.$.ticketDescriptor.ticketFk = ticketId; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - } } ngModule.component('vnClaimSummary', { diff --git a/modules/client/front/balance/create/index.html b/modules/client/front/balance/create/index.html index 07c4de531..506e86f4b 100644 --- a/modules/client/front/balance/create/index.html +++ b/modules/client/front/balance/create/index.html @@ -1,44 +1,38 @@ -
- -
New payment
-
- - - - - - - - - - - - -
-
- - - - -
\ No newline at end of file + + New payment + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index 5844e2204..880774f55 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -1,11 +1,9 @@ import ngModule from '../../module'; import Dialog from 'core/components/dialog'; -import template from './index.html'; class Controller extends Dialog { constructor($element, $, $transclude) { super($element, $, $transclude); - this.fillSlots(template); this.receipt = { payed: new Date(), @@ -76,8 +74,8 @@ class Controller extends Dialog { } ngModule.vnComponent('vnClientBalanceCreate', { + slotTemplate: require('./index.html'), controller: Controller, - transclude: true, bindings: { payed: ' @@ -66,19 +66,26 @@
+ vn-click-stop="workerDescriptor.show($event, balance.workerFk)" + class="link"> {{::balance.userNickname}} - - {{balance.isInvoice ? 'BILL' : balance.ref | translate: {ref: balance.ref} }} - +
+ + {{'BILL' | translate: {ref: balance.ref} }} + + + {{::balance.ref}} + +
{{::balance.bankFk}} {{::balance.debit | currency: 'EUR':2}} @@ -121,10 +128,8 @@ company-fk="$ctrl.companyId"> + vn-id="workerDescriptor"> + vn-id="invoiceOutDescriptor"> \ No newline at end of file diff --git a/modules/client/front/balance/index/index.js b/modules/client/front/balance/index/index.js index 381800ad9..4030539ac 100644 --- a/modules/client/front/balance/index/index.js +++ b/modules/client/front/balance/index/index.js @@ -72,29 +72,6 @@ class Controller extends Section { } }); } - - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - showInvoiceOutDescriptor(event, balance) { - if (!balance.isInvoice) return; - if (event.defaultPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedInvoiceOut = balance.id; - this.$.invoiceOutDescriptor.parent = event.target; - this.$.invoiceOutDescriptor.show(); - } } Controller.$inject = ['$element', '$scope']; diff --git a/modules/client/front/descriptor-popover/index.html b/modules/client/front/descriptor-popover/index.html index e7b2f583a..714cc3d54 100644 --- a/modules/client/front/descriptor-popover/index.html +++ b/modules/client/front/descriptor-popover/index.html @@ -1,12 +1,6 @@ - - - - + - \ No newline at end of file + \ 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 1a1b41f76..5b0ca0d20 100644 --- a/modules/client/front/descriptor-popover/index.js +++ b/modules/client/front/descriptor-popover/index.js @@ -1,67 +1,18 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; - -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.client = null; - this._quicklinks = {}; - } - - set clientFk(id) { - if (id == this._clientFk) return; - - this._clientFk = id; - this.client = null; - this.getCard(); - } - - set client(value) { - this._client = value; - this.$timeout(() => this.$.popover.relocate()); - } +import DescriptorPopover from 'salix/components/descriptor-popover'; +class Controller extends DescriptorPopover { get client() { - return this._client; + return this.entity; } - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let options = {timeout: this.canceler.promise}; - this.$http.get(`Clients/${this._clientFk}/getCard`, options).then( - response => { - this.client = response.data; - this.canceler = null; - } - ); + loadData() { + return this.getData(`Clients/${this.id}/getCard`) + .then(res => this.entity = res.data); } } -ngModule.component('vnClientDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - clientFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnClientDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/client/front/descriptor-popover/index.spec.js b/modules/client/front/descriptor-popover/index.spec.js index ff8ffceff..a3cee8249 100644 --- a/modules/client/front/descriptor-popover/index.spec.js +++ b/modules/client/front/descriptor-popover/index.spec.js @@ -1,80 +1,29 @@ import './index'; -describe('Client', () => { - describe('Component vnClientDescriptorPopover', () => { - let $httpBackend; - let $scope; - let controller; - let $element; - let $timeout; +describe('vnClientDescriptorPopover', () => { + let controller; + let $httpBackend; - beforeEach(ngModule('client')); + beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { - $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnClientDescriptorPopover', {$scope, $element}); - })); - - describe('clientFk()', () => { - it(`should not apply any changes if the received id is the same stored in _clientFk`, () => { - controller.client = 'I exist!'; - controller._clientFk = 1; - jest.spyOn(controller, 'getCard'); - controller.clientFk = 1; - - expect(controller.client).toEqual('I exist!'); - expect(controller._clientFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _clientFk, set the client to null and then call getCard()`, () => { - controller.client = `Please don't`; - controller._clientFk = 1; - jest.spyOn(controller, 'getCard'); - controller.clientFk = 999; - - expect(controller.client).toBeNull(); - expect(controller._clientFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnClientDescriptorPopover', { + $element: null, + $transclude: null }); + })); - describe('client()', () => { - it(`should save the client into _client and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - controller.client = `i'm the client!`; - $timeout.flush(); + describe('loadData()', () => { + it(`should perform a get query to store the client data into the controller`, () => { + const id = 1; + const response = 'foo'; - expect(controller._client).toEqual(`i'm the client!`); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); + $httpBackend.expectGET(`Clients/${id}/getCard`).respond(response); + controller.id = id; + $httpBackend.flush(); - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { - it(`should perform a get query to store the client data into the controller`, () => { - controller.clientFk = 1; - controller.canceler = null; - let response = {}; - $httpBackend.when('GET', `Clients/${controller._clientFk}/getCard`).respond(response); - $httpBackend.expect('GET', `Clients/${controller._clientFk}/getCard`); - controller.getCard(); - $httpBackend.flush(); - - expect(controller.client).toEqual(response); - }); + expect(controller.client).toEqual(response); }); }); }); diff --git a/modules/client/front/descriptor-popover/style.scss b/modules/client/front/descriptor-popover/style.scss deleted file mode 100644 index 8de03b90b..000000000 --- a/modules/client/front/descriptor-popover/style.scss +++ /dev/null @@ -1,9 +0,0 @@ -vn-client-descriptor-popover { - vn-client-descriptor { - display: block; - width: 256px; - & > vn-card{ - margin: 0!important; - } - } -} diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index d8e035942..082030b30 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -6,33 +6,32 @@ - - + vn-popover="menu"> +
{{$ctrl.client.name}}
- - - - -
@@ -63,17 +62,57 @@ ng-class="{bright: $ctrl.client.isTaxDataChecked == false}">
+ + - - - + + + + + + on-accept="$ctrl.onConsumerReportAccept()">
diff --git a/modules/client/front/descriptor/index.js b/modules/client/front/descriptor/index.js index 4cf35d1e9..2255a557c 100644 --- a/modules/client/front/descriptor/index.js +++ b/modules/client/front/descriptor/index.js @@ -1,20 +1,10 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { constructor($element, $, $httpParamSerializer) { super($element, $); this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - {name: 'Simple ticket', callback: this.newTicket}, - {name: 'Send SMS', callback: this.showSMSDialog}, - {name: 'Send consumer report', callback: this.showConsumerReportDialog} - ]; - } - - onMoreChange(callback) { - callback.call(this); } get client() { @@ -23,7 +13,6 @@ class Controller extends Component { set client(value) { this._client = value; - if (!value) return; if (this.$params.sendSMS) @@ -43,56 +32,37 @@ class Controller extends Component { }; } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - - newTicket() { - this.$state.go('ticket.create', {clientFk: this.client.id}); + get filter() { + return this.client ? JSON.stringify({clientFk: this.client.id}) : null; } showSMSDialog() { - const client = this.client; - const phone = this.$params.phone || client.mobile || client.phone; - const message = this.$params.message || ''; + const client = this.client || {}; this.newSMS = { destinationFk: client.id, - destination: phone, - message: message + destination: this.$params.phone || client.mobile || client.phone, + message: this.$params.message || '' }; this.$.sms.open(); } - showConsumerReportDialog() { - this.$.consumerReportDialog.show(); - } - - sendConsumerReport(response) { - if (response === 'accept') { - const params = { - authorization: this.vnToken.token, - clientId: this.client.id, - from: this.from, - to: this.to, - }; - const serializedParams = this.$httpParamSerializer(params); - const url = `api/report/campaign-metrics?${serializedParams}`; - window.open(url); - } + onConsumerReportAccept() { + const params = this.$httpParamSerializer({ + authorization: this.vnToken.token, + clientId: this.client.id, + from: this.from, + to: this.to, + }); + window.open(`api/report/campaign-metrics?${params}`); } } Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; -ngModule.component('vnClientDescriptor', { +ngModule.vnComponent('vnClientDescriptor', { template: require('./index.html'), bindings: { - client: '<', - quicklinks: '<' + client: '<' }, controller: Controller }); diff --git a/modules/client/front/sample/index/index.html b/modules/client/front/sample/index/index.html index dfd662ba5..78d46f56a 100644 --- a/modules/client/front/sample/index/index.html +++ b/modules/client/front/sample/index/index.html @@ -41,8 +41,7 @@ + vn-id="workerDescriptor"> - - - + - \ No newline at end of file + \ 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 c530bdd0f..918707fb6 100644 --- a/modules/invoiceOut/front/descriptor-popover/index.js +++ b/modules/invoiceOut/front/descriptor-popover/index.js @@ -1,55 +1,20 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $,) { - super($element, $); - this.worker = null; - this._quicklinks = {}; - } - - set invoiceOutId(id) { - if (id == this._invoiceOutId) return; - - this._invoiceOutId = id; - this.invoiceOut = null; - this.loadData(); - } - - get invoiceOutId() { - return this._invoiceOutId; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); +class Controller extends DescriptorPopover { + get invoiceOut() { + return this.entity; } loadData() { - let query = `InvoiceOuts/findOne`; - let filter = { - where: { - id: this._invoiceOutId - }, + const filter = { include: [ { relation: 'company', scope: { fields: ['id', 'code'] } - }, - { + }, { relation: 'client', scope: { fields: ['id', 'name'] @@ -58,20 +23,12 @@ class Controller extends Component { ] }; - this.$http.get(query, {params: {filter}}).then(res => { - this.invoiceOut = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); + return this.getData(`InvoiceOuts/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -ngModule.component('vnInvoiceOutDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - invoiceOutId: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnInvoiceOutDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/invoiceOut/front/descriptor-popover/style.scss b/modules/invoiceOut/front/descriptor-popover/style.scss deleted file mode 100644 index f50481083..000000000 --- a/modules/invoiceOut/front/descriptor-popover/style.scss +++ /dev/null @@ -1,11 +0,0 @@ -vn-ticket-descriptor-popover { - vn-ticket-descriptor { - display: block; - width: 256px; - max-height: 448px; - - & > vn-card { - margin: 0!important; - } - } -} \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor/index.js b/modules/invoiceOut/front/descriptor/index.js index b813214bc..fd9f786d3 100644 --- a/modules/invoiceOut/front/descriptor/index.js +++ b/modules/invoiceOut/front/descriptor/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { constructor($element, $) { super($element, $); this.moreOptions = [ @@ -82,21 +82,12 @@ class Controller extends Component { .then(() => this.$state.reload()) .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked'))); } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } } -ngModule.component('vnInvoiceOutDescriptor', { +ngModule.vnComponent('vnInvoiceOutDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { - invoiceOut: '<', - quicklinks: '<' - }, - controller: Controller + invoiceOut: '<' + } }); diff --git a/modules/invoiceOut/front/index/index.html b/modules/invoiceOut/front/index/index.html index ad7c363ce..52d296e86 100644 --- a/modules/invoiceOut/front/index/index.html +++ b/modules/invoiceOut/front/index/index.html @@ -29,7 +29,7 @@ + vn-click-stop="clientDescriptor.show($event, invoiceOut.clientFk)"> {{::invoiceOut.clientSocialName | dashIfEmpty}} @@ -39,7 +39,7 @@ @@ -47,7 +47,7 @@ diff --git a/modules/invoiceOut/front/index/index.js b/modules/invoiceOut/front/index/index.js index d5c0fde3a..17eb44fec 100644 --- a/modules/invoiceOut/front/index/index.js +++ b/modules/invoiceOut/front/index/index.js @@ -2,30 +2,14 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - preview(event, invoiceOut) { + preview(invoiceOut) { this.selectedInvoiceOut = invoiceOut; this.$.summary.show(); - event.preventDefault(); - event.stopImmediatePropagation(); } - onDescriptorLoad() { - this.$.popover.relocate(); - } - - openPdf(id, event) { + openPdf(id) { let url = `api/InvoiceOuts/${id}/download?access_token=${this.vnToken.token}`; window.open(url, '_blank'); - event.preventDefault(); - event.stopImmediatePropagation(); } } diff --git a/modules/invoiceOut/front/summary/index.html b/modules/invoiceOut/front/summary/index.html index 19ceeb3ab..8deb7ddf8 100644 --- a/modules/invoiceOut/front/summary/index.html +++ b/modules/invoiceOut/front/summary/index.html @@ -54,14 +54,14 @@ {{ticket.id}} {{ticket.nickname}} diff --git a/modules/invoiceOut/front/summary/index.js b/modules/invoiceOut/front/summary/index.js index 7b9bb9efd..ef76768de 100644 --- a/modules/invoiceOut/front/summary/index.js +++ b/modules/invoiceOut/front/summary/index.js @@ -14,29 +14,8 @@ class Controller extends Section { } getSummary() { - this.$http.get(`InvoiceOuts/${this.invoiceOut.id}/summary`).then(response => { - this.summary = response.data; - }); - } - - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - } - - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - } - - preview(event, invoiceOut) { - this.selectedInvoiceOut = invoiceOut; - this.$.invoiceOutSummaryDialog.show(); - event.preventDefault(); + return this.$http.get(`InvoiceOuts/${this.invoiceOut.id}/summary`) + .then(res => this.summary = res.data); } } diff --git a/modules/item/front/descriptor-popover/index.html b/modules/item/front/descriptor-popover/index.html index 41b4badb4..ccc2b899f 100644 --- a/modules/item/front/descriptor-popover/index.html +++ b/modules/item/front/descriptor-popover/index.html @@ -1,12 +1,6 @@ - - - + - + diff --git a/modules/item/front/descriptor-popover/index.js b/modules/item/front/descriptor-popover/index.js index c7a62baae..35918a171 100644 --- a/modules/item/front/descriptor-popover/index.js +++ b/modules/item/front/descriptor-popover/index.js @@ -1,77 +1,29 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.item = null; - this._quicklinks = {}; - } - - set itemFk(id) { - if (id == this._itemFk) return; - - this._itemFk = id; - this.item = null; +class Controller extends DescriptorPopover { + constructor(...args) { + super(...args); this._quicklinks = { btnThree: { icon: 'icon-transaction', - state: `item.card.diary({ - id: ${id}, - })`, + state: `item.card.diary({id: $ctrl.id})`, tooltip: 'Item diary' } }; - this.getCard(); - } - - set item(value) { - this._item = value; - this.$timeout(() => this.$.popover.relocate()); } get item() { - return this._item; + return this.entity; } - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let options = {timeout: this.canceler.promise}; - this.$http.get(`Items/${this._itemFk}/getCard`, options).then( - response => { - this.item = response.data; - this.canceler = null; - } - ); + loadData() { + return this.getData(`Items/${this.id}/getCard`) + .then(res => this.entity = res.data); } } -Controller.$inject = ['$element', '$scope']; -ngModule.component('vnItemDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - itemFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnItemDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/item/front/descriptor-popover/index.spec.js b/modules/item/front/descriptor-popover/index.spec.js index dfc673b0b..3d9ae3b8f 100644 --- a/modules/item/front/descriptor-popover/index.spec.js +++ b/modules/item/front/descriptor-popover/index.spec.js @@ -1,79 +1,29 @@ -import './index.js'; +import './index'; -describe('Item', () => { - describe('Component vnItemDescriptorPopover', () => { - let $httpBackend; - let $scope; - let controller; - let $timeout; +describe('vnItemDescriptorPopover', () => { + let controller; + let $httpBackend; - beforeEach(ngModule('item')); + beforeEach(ngModule('item')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { - $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - const $element = angular.element(''); - controller = $componentController('vnItemDescriptorPopover', {$element, $scope}); - })); - - describe('itemFk()', () => { - it(`should not apply any changes if the received id is the same stored in _itemFk`, () => { - controller.item = 'I exist!'; - controller._itemFk = 1; - jest.spyOn(controller, 'getCard'); - controller.itemFk = 1; - - expect(controller.item).toEqual('I exist!'); - expect(controller._itemFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _itemFk, set the item to null and then call getCard()`, () => { - controller.item = `Please don't`; - controller._itemFk = 1; - jest.spyOn(controller, 'getCard'); - controller.itemFk = 999; - - expect(controller.item).toBeNull(); - expect(controller._itemFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnItemDescriptorPopover', { + $element: null, + $transclude: null }); + })); - describe('item()', () => { - it(`should save the item into _item and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - controller.item = `i'm the item!`; - $timeout.flush(); + describe('loadData()', () => { + it(`should perform a get query to store the item data into the controller`, () => { + const id = 1; + const response = 'foo'; - expect(controller._item).toEqual(`i'm the item!`); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); + $httpBackend.expectGET(`Items/${id}/getCard`).respond(response); + controller.id = id; + $httpBackend.flush(); - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { - it(`should perform a get query to store the item data into the controller`, () => { - controller.itemFk = 1; - controller.canceler = null; - let response = {}; - $httpBackend.when('GET', `Items/${controller._itemFk}/getCard`).respond(response); - $httpBackend.expect('GET', `Items/${controller._itemFk}/getCard`); - controller.getCard(); - $httpBackend.flush(); - - expect(controller.item).toEqual(response); - }); + expect(controller.item).toEqual(response); }); }); }); diff --git a/modules/item/front/descriptor-popover/style.scss b/modules/item/front/descriptor-popover/style.scss deleted file mode 100644 index 219e68bae..000000000 --- a/modules/item/front/descriptor-popover/style.scss +++ /dev/null @@ -1,5 +0,0 @@ -body > .vn-popover vn-item-descriptor { - display: block; - width: 256px; - min-height: 448px; -} \ No newline at end of file diff --git a/modules/item/front/descriptor/index.html b/modules/item/front/descriptor/index.html index 81f8299b0..d8e569491 100644 --- a/modules/item/front/descriptor/index.html +++ b/modules/item/front/descriptor/index.html @@ -20,8 +20,8 @@
{{::sale.origin | dashIfEmpty}} @@ -57,9 +57,13 @@ {{::sale.stateName | dashIfEmpty}} {{::sale.reference | dashIfEmpty}} - + + {{::sale.name | dashIfEmpty}} + + {{::sale.name | dashIfEmpty}} diff --git a/modules/item/front/diary/index.js b/modules/item/front/diary/index.js index e77ad1c2c..370039e1f 100644 --- a/modules/item/front/diary/index.js +++ b/modules/item/front/diary/index.js @@ -119,10 +119,10 @@ class Controller extends Section { } /** - * Compares a date with the current one - * @param {Object} date - Date to compare - * @return {Boolean} - Returns true if the two dates equals - */ + * Compares a date with the current one + * @param {Object} date - Date to compare + * @return {Boolean} - Returns true if the two dates equals + */ isToday(date) { let today = new Date(); today.setHours(0, 0, 0, 0); @@ -133,30 +133,6 @@ class Controller extends Section { if (!(today - comparedDate)) return true; } - - showDescriptor(event, sale) { - if (!sale.isTicket) return; - - this.$.descriptor.ticketFk = sale.origin; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - - event.preventDefault(); - } - - showClientDescriptor(event, sale) { - if (!sale.isTicket) return; - - this.$.clientDescriptor.clientFk = sale.clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - - event.preventDefault(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnItemDiary', { diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index 154c64bb1..0ee6a8815 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -35,15 +35,15 @@ ui-sref="item.card.summary({id: item.id})"> - + {{::item.id | zeroFill:6}} @@ -73,7 +73,7 @@ + vn-click-stop="workerDescriptor.show($event, item.buyerFk)"> {{::item.userNickname}} @@ -87,12 +87,12 @@ @@ -106,18 +106,20 @@ - - - + + + + - - - - \ No newline at end of file + + + + \ No newline at end of file diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index ad978e0aa..e852d7985 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -5,68 +5,25 @@ import './style.scss'; class Controller extends Section { constructor($element, $) { super($element, $); - this.itemSelected = null; - this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; this.showFields = { id: false, actions: false }; } - stopEvent(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showItemDescriptor(event, itemFk) { - if (event.defaultPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - if (event.defaltPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - cloneItem(event, item) { - this.stopEvent(event); - this.itemSelected = item; - this.$.clone.show(); - } - - onCloneAccept(response) { - if (!(response == 'accept' && this.itemSelected)) - return; - - this.$http.post(`Items/${this.itemSelected.id}/clone`).then(res => { - if (res && res.data && res.data.id) + onCloneAccept(itemFk) { + return this.$http.post(`Items/${itemFk}/clone`) + .then(res => { this.$state.go('item.card.tags', {id: res.data.id}); - }); - - this.itemSelected = null; + }); } - preview(event, item) { - this.stopEvent(event); + preview(item) { this.itemSelected = item; this.$.preview.show(); } } -Controller.$inject = ['$element', '$scope']; - ngModule.component('vnItemIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/index/index.spec.js b/modules/item/front/index/index.spec.js index de07cd04d..f8cf07fe3 100644 --- a/modules/item/front/index/index.spec.js +++ b/modules/item/front/index/index.spec.js @@ -16,43 +16,14 @@ describe('Item', () => { })); describe('onCloneAccept()', () => { - it('should do nothing if response is not accept', () => { - jest.spyOn(controller.$state, 'go'); - - let response = 'ERROR!'; - controller.itemSelected = 'check me'; - - controller.onCloneAccept(response); - - expect(controller.$state.go).not.toHaveBeenCalledWith(); - expect(controller.itemSelected).toEqual('check me'); - }); - - it('should do nothing if response is accept but itemSelected is not defined in the controller', () => { - jest.spyOn(controller.$state, 'go'); - - let response = 'accept'; - controller.itemSelected = undefined; - - controller.onCloneAccept(response); - - expect(controller.$state.go).not.toHaveBeenCalledWith(); - expect(controller.itemSelected).toBeUndefined(); - }); - it('should perform a post query and then call go() then update itemSelected in the controller', () => { jest.spyOn(controller.$state, 'go'); - let response = 'accept'; - controller.itemSelected = {id: 1}; - - $httpBackend.when('POST', `Items/1/clone`).respond({id: 99}); - $httpBackend.expect('POST', `Items/1/clone`); - controller.onCloneAccept(response); + $httpBackend.expectRoute('POST', `Items/:id/clone`).respond({id: 99}); + controller.onCloneAccept(1); $httpBackend.flush(); expect(controller.$state.go).toHaveBeenCalledWith('item.card.tags', {id: 99}); - expect(controller.itemSelected).toBeNull(); }); }); }); diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index bee9df310..938005828 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -3,8 +3,8 @@ + ng-src="{{::$root.imagePath}}/catalog/200x200/{{$ctrl.item.image}}" + zoom-image="{{::$root.imagePath}}/catalog/1600x900/{{$ctrl.item.image}}" on-error-src/>

Visible

diff --git a/modules/order/front/catalog-view/index.html b/modules/order/front/catalog-view/index.html index 7a588a464..bc01dcc6c 100644 --- a/modules/order/front/catalog-view/index.html +++ b/modules/order/front/catalog-view/index.html @@ -5,8 +5,8 @@
diff --git a/modules/order/front/descriptor/index.js b/modules/order/front/descriptor/index.js index b9d1e7973..b60d44e78 100644 --- a/modules/order/front/descriptor/index.js +++ b/modules/order/front/descriptor/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { constructor($element, $) { super($element, $); this.moreOptions = [ @@ -33,14 +33,6 @@ class Controller extends Component { return this._order; } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - deleteOrder(response) { if (response === 'accept') { const params = {id: this.order.id}; @@ -56,10 +48,10 @@ class Controller extends Component { } } -ngModule.component('vnOrderDescriptor', { +ngModule.vnComponent('vnOrderDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { order: '<' - }, - controller: Controller + } }); diff --git a/modules/order/front/index/index.html b/modules/order/front/index/index.html index b16a1b25d..1633b0ea1 100644 --- a/modules/order/front/index/index.html +++ b/modules/order/front/index/index.html @@ -27,14 +27,16 @@ ui-sref="order.card.summary({id: {{::order.id}}})"> {{::order.id}} - + {{::order.clientName}} - + {{::order.workerNickname | dashIfEmpty}} @@ -51,9 +53,9 @@ {{::order.total | currency: 'EUR': 2 | dashIfEmpty}} + vn-click-stop="$ctrl.preview(order)" + icon="desktop_windows" + vn-tooltip="Preview"> @@ -72,10 +74,11 @@ vn-id="clientDescriptor"> + vn-id="workerDescriptor"> - + + \ No newline at end of file diff --git a/modules/order/front/index/index.js b/modules/order/front/index/index.js index 99f00733e..40781bcdd 100644 --- a/modules/order/front/index/index.js +++ b/modules/order/front/index/index.js @@ -2,29 +2,7 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } - - preview(event, order) { - event.preventDefault(); - event.stopImmediatePropagation(); + preview(order) { this.selectedOrder = order; this.$.summary.show(); } diff --git a/modules/order/front/line/index.html b/modules/order/front/line/index.html index 72d019fe9..fcfb5b6ec 100644 --- a/modules/order/front/line/index.html +++ b/modules/order/front/line/index.html @@ -32,8 +32,8 @@ diff --git a/modules/route/front/descriptor-popover/index.html b/modules/route/front/descriptor-popover/index.html index a0295c138..75233bd77 100644 --- a/modules/route/front/descriptor-popover/index.html +++ b/modules/route/front/descriptor-popover/index.html @@ -1,12 +1,6 @@ - - - - + - \ No newline at end of file + \ 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 a0363839f..ce62ee853 100644 --- a/modules/route/front/descriptor-popover/index.js +++ b/modules/route/front/descriptor-popover/index.js @@ -1,59 +1,13 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; - -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.route = null; - this._quicklinks = {}; - } - - set routeFk(id) { - if (id == this._routeFk) return; - - this._routeFk = id; - this.route = null; - this.getCard(); - } - - get routeFk() { - return this._routeFk; - } - - set route(value) { - this._route = value; - this.$timeout(() => this.$.popover.relocate()); - } +import DescriptorPopover from 'salix/components/descriptor-popover'; +class Controller extends DescriptorPopover { get route() { - return this._route; + return this.entity; } - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let query = 'Routes/findOne'; - - let filter = { + loadData() { + const filter = { fields: [ 'id', 'workerFk', @@ -86,8 +40,7 @@ class Controller extends Component { scope: { fields: ['id', 'name'] } - }, - { + }, { relation: 'worker', scope: { fields: ['userFk'], @@ -107,20 +60,13 @@ class Controller extends Component { } ] }; - this.$http.get(query, {params: {filter}}).then(res => { - this.route = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); + + return this.getData(`Routes/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -ngModule.component('vnRouteDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - routeFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnRouteDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/route/front/descriptor-popover/index.spec.js b/modules/route/front/descriptor-popover/index.spec.js index e3277a9c1..971a101fe 100644 --- a/modules/route/front/descriptor-popover/index.spec.js +++ b/modules/route/front/descriptor-popover/index.spec.js @@ -1,74 +1,26 @@ import './index'; describe('vnRouteDescriptorPopover', () => { - let $httpBackend; - let $scope; let controller; - let $element; - let $timeout; + let $httpBackend; beforeEach(ngModule('route')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnRouteDescriptorPopover', {$scope, $element}); + controller = $componentController('vnRouteDescriptorPopover', { + $element: null, + $transclude: null + }); })); - describe('routeFk()', () => { - it(`should do nothing if the received id isn't a new one`, () => { - controller.route = 'I exist!'; - controller._routeFk = 1; - jest.spyOn(controller, 'getCard'); - controller.routeFk = 1; - - expect(controller.route).toEqual('I exist!'); - expect(controller._routeFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id, set the route null and then call getCard()`, () => { - controller.route = `Please don't`; - controller._routeFk = 1; - jest.spyOn(controller, 'getCard'); - controller.routeFk = 999; - - expect(controller.route).toBeNull(); - expect(controller._routeFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); - }); - - describe('route()', () => { - it(`should save the client on the controller and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - let route = `i'm the route!`; - controller.route = route; - $timeout.flush(); - - expect(controller.route).toEqual(route); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the popover show() method`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { + describe('loadData()', () => { it(`should perform a get query to store the client data into the controller`, () => { - let response = {the: 'route'}; + const id = 1; + const response = 'foo'; - $httpBackend.whenRoute('GET', 'Routes/findOne').respond(response); - controller.routeFk = 1; + $httpBackend.expectGET(`Routes/${id}`).respond(response); + controller.id = id; $httpBackend.flush(); expect(controller.route).toEqual(response); diff --git a/modules/route/front/descriptor-popover/style.scss b/modules/route/front/descriptor-popover/style.scss deleted file mode 100644 index 163a032e3..000000000 --- a/modules/route/front/descriptor-popover/style.scss +++ /dev/null @@ -1,9 +0,0 @@ -vn-route-descriptor-popover { - vn-route-descriptor { - display: block; - width: 256px; - & > vn-card{ - margin: 0!important; - } - } -} diff --git a/modules/route/front/descriptor/index.js b/modules/route/front/descriptor/index.js index 558d236b7..c4f4d17f2 100644 --- a/modules/route/front/descriptor/index.js +++ b/modules/route/front/descriptor/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { constructor($element, $, $httpParamSerializer) { super($element, $); @@ -22,14 +22,6 @@ class Controller extends Component { this.$.moreButton.data = options; } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - onMoreChange(callback) { callback.call(this); } @@ -73,12 +65,11 @@ class Controller extends Component { Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; -ngModule.component('vnRouteDescriptor', { +ngModule.vnComponent('vnRouteDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { route: '<', - cardReload: '&?', - quicklinks: '<' - }, - controller: Controller + cardReload: '&?' + } }); diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index ab8b1364b..b2b8484ac 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -53,8 +53,7 @@ + vn-id="workerDescriptor"> {{ticket.priority | dashIfEmpty}}
{{ticket.id | zeroFill:6}} {{ticket.nickname}} diff --git a/modules/route/front/summary/index.js b/modules/route/front/summary/index.js index a922ad008..95e208b84 100644 --- a/modules/route/front/summary/index.js +++ b/modules/route/front/summary/index.js @@ -16,20 +16,6 @@ class Controller extends Section { }); } - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - } - - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - } - get route() { return this._route; } diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index c4e4f8d7e..ef88f6d9e 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -60,14 +60,14 @@ {{ticket.id}} {{ticket.nickname}} @@ -118,10 +118,10 @@ + + Tickets to add + -
-
Tickets to add
-
diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index 556ad0b6c..e7c6cb7b1 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -128,20 +128,6 @@ class Controller extends Section { }); } - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - } - - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - } - openPossibleTicketsDialog() { this.$.possibleTicketsModel.refresh(); this.$.possibleTicketsDialog.show(); diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index f3c02cf51..c2671c3d7 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -213,36 +213,6 @@ describe('Route', () => { }); }); - describe('showTicketDescriptor()', () => { - it('should call the descriptor show function after setting the parent and the ticket id', () => { - controller.$.ticketDescriptor = {show: () => {}}; - jest.spyOn(controller.$.ticketDescriptor, 'show'); - const event = {target: {}, preventDefault: () => {}}; - jest.spyOn(event, 'preventDefault'); - const ticketId = 999; - controller.showTicketDescriptor(event, ticketId); - - expect(controller.$.ticketDescriptor.ticketFk).toEqual(ticketId); - expect(controller.$.ticketDescriptor.show).toHaveBeenCalledWith(); - expect(event.preventDefault).toHaveBeenCalledWith(); - }); - }); - - describe('showClientDescriptor()', () => { - it('should call the descriptor show method after setting the parent and the client id', () => { - controller.$.clientDescriptor = {show: () => {}}; - jest.spyOn(controller.$.clientDescriptor, 'show'); - const event = {target: {}, preventDefault: () => {}}; - jest.spyOn(event, 'preventDefault'); - const clientId = 999; - controller.showClientDescriptor(event, clientId); - - expect(controller.$.clientDescriptor.clientFk).toEqual(clientId); - expect(controller.$.clientDescriptor.show).toHaveBeenCalledWith(); - expect(event.preventDefault).toHaveBeenCalledWith(); - }); - }); - describe('openPossibleTicketsDialog()', () => { it('should call both refresh and show methods in posible tickets model and dialog', () => { controller.$.possibleTicketsModel = {refresh: () => {}}; diff --git a/modules/ticket/front/descriptor-popover/index.html b/modules/ticket/front/descriptor-popover/index.html index 00d387f73..d76a41380 100644 --- a/modules/ticket/front/descriptor-popover/index.html +++ b/modules/ticket/front/descriptor-popover/index.html @@ -1,12 +1,6 @@ - - - + - \ No newline at end of file + \ 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 822296c5b..fc61bc6ca 100644 --- a/modules/ticket/front/descriptor-popover/index.js +++ b/modules/ticket/front/descriptor-popover/index.js @@ -1,72 +1,34 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; - -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.ticket = null; - this._quicklinks = {}; - } - - set ticketFk(id) { - if (id == this._ticketFk) return; - - this._ticketFk = id; - this.ticket = null; - this.getCard(); - } - - set ticket(value) { - this._ticket = value; - this.$timeout(() => this.$.popover.relocate()); - } +import DescriptorPopover from 'salix/components/descriptor-popover'; +class Controller extends DescriptorPopover { get ticket() { - return this._ticket; + return this.entity; } - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let options = {timeout: this.canceler.promise}; - - let filter = { + loadData() { + const filter = { include: [ { relation: 'warehouse', scope: { fields: ['name'] } - }, - { + }, { relation: 'agencyMode', scope: { fields: ['name'] } - }, - { + }, { relation: 'client', scope: { - fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'], + fields: [ + 'salesPersonFk', + 'name', + 'isActive', + 'isFreezed', + 'isTaxDataChecked' + ], include: { relation: 'salesPerson', scope: { @@ -80,8 +42,7 @@ class Controller extends Component { } } } - }, - { + }, { relation: 'state', scope: { fields: ['stateFk'], @@ -93,22 +54,13 @@ class Controller extends Component { } ] }; - let json = encodeURIComponent(JSON.stringify(filter)); - let query = `Tickets/${this._ticketFk}?filter=${json}`; - this.$http.get(query, options).then( - response => { - this.ticket = response.data; - this.canceler = null; - } - ); + + return this.getData(`Tickets/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -ngModule.component('vnTicketDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - ticketFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnTicketDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/ticket/front/descriptor-popover/index.spec.js b/modules/ticket/front/descriptor-popover/index.spec.js index 17682e5de..fccdb5f96 100644 --- a/modules/ticket/front/descriptor-popover/index.spec.js +++ b/modules/ticket/front/descriptor-popover/index.spec.js @@ -1,121 +1,26 @@ import './index.js'; -describe('ticket Component vnTicketDescriptorPopover', () => { - let $httpBackend; - let $scope; +describe('vnTicketDescriptorPopover', () => { let controller; - let $element; - let $timeout; + let $httpBackend; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnTicketDescriptorPopover', {$scope, $element}); + controller = $componentController('vnTicketDescriptorPopover', { + $element: null, + $transclude: null + }); })); - describe('ticketFk()', () => { - it(`should not apply any changes if the received id is the same stored in _ticketFk`, () => { - controller.ticket = 'I exist!'; - controller._ticketFk = 1; - jest.spyOn(controller, 'getCard'); - controller.ticketFk = 1; - - expect(controller.ticket).toEqual('I exist!'); - expect(controller._ticketFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _ticketFk, set the ticket to null and then call getCard()`, () => { - controller.ticket = `Please don't`; - controller._ticketFk = 1; - jest.spyOn(controller, 'getCard'); - controller.ticketFk = 999; - - expect(controller.ticket).toBeNull(); - expect(controller._ticketFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); - }); - - describe('ticket()', () => { - it(`should save the ticket into _ticket and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - controller.ticket = `i'm the ticket!`; - $timeout.flush(); - - expect(controller._ticket).toEqual(`i'm the ticket!`); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { + describe('loadData()', () => { it(`should perform a get query to store the ticket data into the controller`, () => { - controller.ticketFk = 1; - controller.canceler = null; - let response = {}; + const id = 1; + const response = 'foo'; - let 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'], - } - } - } - ] - }; - let json = encodeURIComponent(JSON.stringify(filter)); - $httpBackend.when('GET', `Tickets/${controller._ticketFk}?filter=${json}`).respond(response); - $httpBackend.expect('GET', `Tickets/${controller._ticketFk}?filter=${json}`); - controller.getCard(); + $httpBackend.expectGET(`Tickets/${id}`).respond(response); + controller.id = id; $httpBackend.flush(); expect(controller.ticket).toEqual(response); diff --git a/modules/ticket/front/descriptor-popover/style.scss b/modules/ticket/front/descriptor-popover/style.scss deleted file mode 100644 index f50481083..000000000 --- a/modules/ticket/front/descriptor-popover/style.scss +++ /dev/null @@ -1,11 +0,0 @@ -vn-ticket-descriptor-popover { - vn-ticket-descriptor { - display: block; - width: 256px; - max-height: 448px; - - & > vn-card { - margin: 0!important; - } - } -} \ No newline at end of file diff --git a/modules/ticket/front/descriptor/addStowaway.js b/modules/ticket/front/descriptor/addStowaway.js index 28286386b..4497fef82 100644 --- a/modules/ticket/front/descriptor/addStowaway.js +++ b/modules/ticket/front/descriptor/addStowaway.js @@ -6,8 +6,8 @@ class Controller extends Component { addStowaway(stowaway) { let params = {id: stowaway.id, shipFk: this.ticket.id}; this.$http.post(`Stowaways/`, params) + .then(() => this.cardReload()) .then(() => { - this.cardReload(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$.dialog.hide(); }); diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 5dc7a3f70..2be4cf9b9 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -1,7 +1,7 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { constructor($element, $, $httpParamSerializer) { super($element, $); this.$httpParamSerializer = $httpParamSerializer; @@ -95,14 +95,6 @@ class Controller extends Component { this._quicklinks = links; } - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - showChangeShipped() { if (!this.isEditable) { this.vnApp.showError(this.$t(`This ticket can't be modified`)); @@ -356,11 +348,11 @@ class Controller extends Component { Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; -ngModule.component('vnTicketDescriptor', { +ngModule.vnComponent('vnTicketDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { ticket: '<', cardReload: '&' - }, - controller: Controller + } }); diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index a90d48670..3beb6ecde 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -63,8 +63,7 @@ quicklinks="$ctrl.quicklinks"> + vn-id="workerDescriptor"> + vn-click-stop>
@@ -67,9 +67,9 @@ {{::ticket.id}} - + {{::ticket.userNickname | dashIfEmpty}} @@ -80,9 +80,9 @@ {{::ticket.shipped | date: 'HH:mm'}} - + {{::ticket.nickname}} @@ -103,12 +103,12 @@ @@ -118,7 +118,6 @@ -
- - + + + vn-id="workerDescriptor"> diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 4803f40ff..59e5d949d 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -43,12 +43,6 @@ export default class Controller extends Section { return this.checked.length; } - goToLines(event, ticketFk) { - this.preventDefault(event); - let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); - window.open(url, '_blank'); - } - onMoreOpen() { let options = this.moreOptions.filter(o => o.always || this.isChecked); this.$.moreButton.data = options; @@ -89,30 +83,15 @@ export default class Controller extends Section { return 'warning'; } - showClientDescriptor(event, clientFk) { - this.preventDefault(event); - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); + goToLines(ticketFk) { + let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); + window.open(url, '_blank'); } - showWorkerDescriptor(event, workerFk) { - this.preventDefault(event); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - preview(event, ticket) { - this.preventDefault(event); + preview(ticket) { this.selectedTicket = ticket; this.$.summary.show(); } - - preventDefault(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } } ngModule.component('vnTicketIndex', { diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 10bd88d3d..de619ef26 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -52,21 +52,6 @@ describe('Component vnTicketIndex', () => { }); }); - describe('showClientDescriptor()', () => { - it('should show the client descriptor popover', () => { - controller.$.clientDescriptor = {show: () => {}}; - controller.$.clientDescriptor.show = jasmine.createSpy('show'); - let event = new MouseEvent('click', { - view: $window, - bubbles: true, - cancelable: true - }); - controller.showClientDescriptor(event, tickets[0].clientFk); - - expect(controller.$.clientDescriptor.show).toHaveBeenCalledWith(); - }); - }); - describe('preview()', () => { it('should show the dialog summary', () => { controller.$.summary = {show: () => {}}; diff --git a/modules/ticket/front/picture/index.html b/modules/ticket/front/picture/index.html index 58e13a451..e240d28ac 100644 --- a/modules/ticket/front/picture/index.html +++ b/modules/ticket/front/picture/index.html @@ -19,8 +19,8 @@
@@ -62,4 +62,6 @@ - + + diff --git a/modules/ticket/front/request/index/index.html b/modules/ticket/front/request/index/index.html index 0acb661e3..3dd8691d5 100644 --- a/modules/ticket/front/request/index/index.html +++ b/modules/ticket/front/request/index/index.html @@ -105,8 +105,7 @@ quicklinks="$ctrl.quicklinks"> + vn-id="workerDescriptor"> - + vn-id="workerDescriptor"> \ No newline at end of file diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index e120ad942..51798537f 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -100,8 +100,8 @@ diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index fe19696f3..0bf960b1e 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -32,7 +32,6 @@ class Controller extends Section { }, ]; this._sales = []; - this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; } get ticket() { diff --git a/modules/ticket/front/tracking/index/index.html b/modules/ticket/front/tracking/index/index.html index f66c62449..99d0b838a 100644 --- a/modules/ticket/front/tracking/index/index.html +++ b/modules/ticket/front/tracking/index/index.html @@ -38,6 +38,5 @@ + vn-id="workerDescriptor"> \ No newline at end of file diff --git a/modules/ticket/front/volume/index.html b/modules/ticket/front/volume/index.html index 977f76513..610e517c9 100644 --- a/modules/ticket/front/volume/index.html +++ b/modules/ticket/front/volume/index.html @@ -58,7 +58,8 @@ - diff --git a/modules/ticket/front/weekly/index.html b/modules/ticket/front/weekly/index.html index e97d47eef..8411d4f72 100644 --- a/modules/ticket/front/weekly/index.html +++ b/modules/ticket/front/weekly/index.html @@ -32,23 +32,27 @@ - + - + {{weekly.ticketFk}} - + {{::weekly.clientName}} - + - + {{::weekly.warehouseName}} - + {{::weekly.nickName}} diff --git a/modules/ticket/front/weekly/index.js b/modules/ticket/front/weekly/index.js index a89dbbc2e..0c373eae3 100644 --- a/modules/ticket/front/weekly/index.js +++ b/modules/ticket/front/weekly/index.js @@ -19,36 +19,10 @@ export default class Controller extends Section { onUpdate(ticketFk, field, value) { const params = {ticketFk, [field]: value}; - this.$http.patch('TicketWeeklies', params).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + this.$http.patch('TicketWeeklies', params) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - this.stopEvent(event); - } - - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - this.stopEvent(event); - } - - showWorkerDescriptor(event, workerFk) { - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - this.stopEvent(event); - } - - deleteWeekly(event, ticketFk) { - this.$.deleteWeekly.show(ticketFk); - this.stopEvent(event); - } onDeleteWeeklyAccept(ticketFk) { return this.$http.delete(`TicketWeeklies/${ticketFk}`).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); diff --git a/modules/travel/front/descriptor-popover/index.html b/modules/travel/front/descriptor-popover/index.html index fc0fb0301..46fb787a0 100644 --- a/modules/travel/front/descriptor-popover/index.html +++ b/modules/travel/front/descriptor-popover/index.html @@ -1,12 +1,6 @@ - - - - + - \ No newline at end of file + \ 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 cb7e29bda..b9839b04b 100644 --- a/modules/travel/front/descriptor-popover/index.js +++ b/modules/travel/front/descriptor-popover/index.js @@ -1,43 +1,13 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.travel = null; - this._quicklinks = {}; - } - - set travelId(travelId) { - if (travelId == this._travelId) return; - - this._travelId = travelId; - this.travel = null; - this.loadData(); - } - - get travelId() { - return this._travelId; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); +class Controller extends DescriptorPopover { + get travel() { + return this.entity; } loadData() { - let query = `Travels/findOne`; - let filter = { + const filter = { fields: [ 'id', 'ref', @@ -47,9 +17,6 @@ class Controller extends Component { 'warehouseInFk', 'warehouseOutFk' ], - where: { - id: this._travelId - }, include: [ { relation: 'warehouseIn', @@ -65,20 +32,12 @@ class Controller extends Component { ] }; - this.$http.get(query, {params: {filter}}).then(res => { - this.travel = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); + return this.getData(`Travels/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -ngModule.component('vnTravelDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - travelId: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnTravelDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/travel/front/descriptor-popover/index.spec.js b/modules/travel/front/descriptor-popover/index.spec.js index 0403c902a..c191414c9 100644 --- a/modules/travel/front/descriptor-popover/index.spec.js +++ b/modules/travel/front/descriptor-popover/index.spec.js @@ -1,97 +1,26 @@ import './index.js'; -describe('travel Component vnTravelDescriptorPopover', () => { - let $httpBackend; - let $httpParamSerializer; - let $scope; +describe('vnTravelDescriptorPopover', () => { let controller; - let $element; + let $httpBackend; beforeEach(ngModule('travel')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnTravelDescriptorPopover', {$scope, $element}); + controller = $componentController('vnTravelDescriptorPopover', { + $element: null, + $transclude: null + }); })); - describe('travelId()', () => { - it(`should not apply any changes if the received id is the same stored in _travelId`, () => { - controller.travel = 'I exist!'; - controller._travelId = 1; - jest.spyOn(controller, 'loadData'); - controller.travelId = 1; - - expect(controller.travel).toEqual('I exist!'); - expect(controller._travelId).toEqual(1); - expect(controller.loadData).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _travelId, set the travel to null and then call loadData()`, () => { - controller.travel = `Please don't`; - controller._travelId = 1; - jest.spyOn(controller, 'loadData'); - controller.travelId = 999; - - expect(controller.travel).toBeNull(); - expect(controller._travelId).toEqual(999); - expect(controller.loadData).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - describe('loadData()', () => { it(`should perform a get query to store the worker data into the controller`, () => { - controller.travelId = 1; - controller.canceler = null; - let response = {}; + const id = 1; + const response = 'foo'; - let config = { - filter: { - fields: [ - 'id', - 'ref', - 'shipped', - 'landed', - 'totalEntries', - 'warehouseInFk', - 'warehouseOutFk' - ], - where: { - id: controller.travelId - }, - include: [ - { - relation: 'warehouseIn', - scope: { - fields: ['name'] - } - }, { - relation: 'warehouseOut', - scope: { - fields: ['name'] - } - } - ] - } - }; - - let json = $httpParamSerializer(config); - - $httpBackend.whenGET(`Travels/findOne?${json}`).respond(response); - $httpBackend.expectGET(`Travels/findOne?${json}`); - controller.loadData(); + $httpBackend.expectGET(`Travels/${id}`).respond(response); + controller.id = id; $httpBackend.flush(); expect(controller.travel).toEqual(response); diff --git a/modules/travel/front/descriptor/index.js b/modules/travel/front/descriptor/index.js index 911cae010..c38dd91a2 100644 --- a/modules/travel/front/descriptor/index.js +++ b/modules/travel/front/descriptor/index.js @@ -1,9 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -ngModule.component('vnTravelDescriptor', { +ngModule.vnComponent('vnTravelDescriptor', { template: require('./index.html'), - controller: Component, + controller: Descriptor, bindings: { travel: '<' }, diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 1cb176d13..b1af5c8dd 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -37,12 +37,12 @@ @@ -70,5 +70,4 @@ on-accept="$ctrl.onCloneAccept($data)" question="Do you want to clone this travel?" message="All it's properties will be copied"> - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index 707f320cb..1115af2c3 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -2,17 +2,11 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - preview(event, travel) { - this.stopEvent(event); + preview(travel) { this.travelSelected = travel; this.$.summary.show(); } - cloneTravel(event, travel) { - this.stopEvent(event); - this.$.clone.show(travel); - } - onCloneAccept(travel) { const params = JSON.stringify({ ref: travel.ref, diff --git a/modules/travel/front/summary/index.html b/modules/travel/front/summary/index.html index 5397c72ca..16afc9ed6 100644 --- a/modules/travel/front/summary/index.html +++ b/modules/travel/front/summary/index.html @@ -2,10 +2,12 @@
{{$ctrl.travelData.id}} - {{$ctrl.travelData.ref}}
- - - - - - - - @@ -131,10 +139,4 @@ - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/summary/index.js b/modules/travel/front/summary/index.js index af940aa6c..1f2d14e58 100644 --- a/modules/travel/front/summary/index.js +++ b/modules/travel/front/summary/index.js @@ -22,35 +22,30 @@ class Controller extends Section { } getTravel() { - return this.$http.get(`/api/Travels/${this.travel.id}/getTravel`).then(response => { - this.travelData = response.data; - }); + return this.$http.get(`Travels/${this.travel.id}/getTravel`) + .then(res => this.travelData = res.data); } getEntries() { - return this.$http.get(`/api/Travels/${this.travel.id}/getEntries`).then(response => { - this.entries = response.data; - }); + return this.$http.get(`Travels/${this.travel.id}/getEntries`) + .then(res => this.entries = res.data); } getThermographs() { - const params = { - filter: { - include: { - relation: 'warehouse', - scope: { - fields: ['id', 'name'] - } - }, - where: { - travelFk: this.travel.id + const filter = { + include: { + relation: 'warehouse', + scope: { + fields: ['id', 'name'] } + }, + where: { + travelFk: this.travel.id } }; - return this.$http.get(`TravelThermographs`, {params}).then(res => { - this.travelThermographs = res.data; - }); + return this.$http.get(`TravelThermographs`, {filter}) + .then(res => this.travelThermographs = res.data); } total(field) { diff --git a/modules/travel/front/summary/index.spec.js b/modules/travel/front/summary/index.spec.js index 7f5c68aec..95f98bb85 100644 --- a/modules/travel/front/summary/index.spec.js +++ b/modules/travel/front/summary/index.spec.js @@ -36,7 +36,7 @@ describe('component vnTravelSummary', () => { it('should perform a get and then store data on the controller', () => { controller._travel = {id: 999}; - const query = `/api/Travels/${controller._travel.id}/getTravel`; + const query = `Travels/${controller._travel.id}/getTravel`; $httpBackend.expectGET(query).respond('I am the travelData'); controller.getTravel(); $httpBackend.flush(); @@ -49,7 +49,7 @@ describe('component vnTravelSummary', () => { it('should call the getEntries method to get the entries data', () => { controller._travel = {id: 999}; - const query = `/api/Travels/${controller._travel.id}/getEntries`; + const query = `Travels/${controller._travel.id}/getEntries`; $httpBackend.expectGET(query).respond('I am the entries'); controller.getEntries(); $httpBackend.flush(); @@ -61,22 +61,8 @@ describe('component vnTravelSummary', () => { describe('getThermographs()', () => { it('should call the getThermographs method to get the thermographs', () => { controller._travel = {id: 2}; - const params = { - filter: { - include: { - relation: 'warehouse', - scope: { - fields: ['id', 'name'] - } - }, - where: { - travelFk: controller._travel.id - } - } - }; - const serializedParams = $httpParamSerializer(params); - const query = `TravelThermographs?${serializedParams}`; - $httpBackend.expectGET(query).respond('I am the thermographs'); + + $httpBackend.expectGET(`TravelThermographs`).respond('I am the thermographs'); controller.getThermographs(); $httpBackend.flush(); diff --git a/modules/worker/front/descriptor-popover/index.html b/modules/worker/front/descriptor-popover/index.html index 21f32f0c2..7c9155dda 100644 --- a/modules/worker/front/descriptor-popover/index.html +++ b/modules/worker/front/descriptor-popover/index.html @@ -1,12 +1,6 @@ - - - - + - \ No newline at end of file + \ 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 6463853f9..eedcebe48 100644 --- a/modules/worker/front/descriptor-popover/index.js +++ b/modules/worker/front/descriptor-popover/index.js @@ -1,46 +1,13 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.worker = null; - this._quicklinks = {}; - } - - set workerFk(workerFk) { - if (workerFk == this._workerFk) return; - - this._workerFk = workerFk; - this.worker = null; - this.loadData(); - } - - get workerFk() { - return this._workerFk; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); +class Controller extends DescriptorPopover { + get worker() { + return this.entity; } loadData() { - let query = `Workers/findOne`; - let filter = { - where: { - id: this._workerFk - }, + const filter = { include: [ { relation: 'user', @@ -53,16 +20,13 @@ class Controller extends Component { } } } - }, - { + }, { relation: 'client', scope: {fields: ['fi']} - }, - { + }, { relation: 'sip', scope: {fields: ['extension']} - }, - { + }, { relation: 'department', scope: { include: { @@ -73,20 +37,12 @@ class Controller extends Component { ] }; - this.$http.get(query, {params: {filter}}).then(res => { - this.worker = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); + return this.getData(`Workers/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -ngModule.component('vnWorkerDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - workerFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnWorkerDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/worker/front/descriptor-popover/index.spec.js b/modules/worker/front/descriptor-popover/index.spec.js index 0b2746475..4b9a17e8a 100644 --- a/modules/worker/front/descriptor-popover/index.spec.js +++ b/modules/worker/front/descriptor-popover/index.spec.js @@ -1,101 +1,26 @@ import './index.js'; -describe('worker Component vnWorkerDescriptorPopover', () => { - let $httpBackend; - let $httpParamSerializer; - let $scope; +describe('vnWorkerDescriptorPopover', () => { let controller; + let $httpBackend; beforeEach(ngModule('worker')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - const $element = angular.element(``); - controller = $componentController('vnWorkerDescriptorPopover', {$element, $scope}); + controller = $componentController('vnWorkerDescriptorPopover', { + $element: null, + $transclude: null + }); })); - describe('workerFk()', () => { - it(`should not apply any changes if the received id is the same stored in _workerFk`, () => { - controller.worker = 'I exist!'; - controller._workerFk = 1; - jest.spyOn(controller, 'loadData'); - controller.workerFk = 1; - - expect(controller.worker).toEqual('I exist!'); - expect(controller._workerFk).toEqual(1); - expect(controller.loadData).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _workerFk, set the worker to null and then call loadData()`, () => { - controller.worker = `Please don't`; - controller._workerFk = 1; - jest.spyOn(controller, 'loadData'); - controller.workerFk = 999; - - expect(controller.worker).toBeNull(); - expect(controller._workerFk).toEqual(999); - expect(controller.loadData).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - describe('loadData()', () => { it(`should perform a get query to store the worker data into the controller`, () => { - controller.workerFk = 1; - controller.canceler = null; - let response = {}; + const id = 1; + const response = 'foo'; - let config = { - filter: { - where: { - id: controller.workerFk - }, - 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' - } - } - } - ] - } - }; - - let json = $httpParamSerializer(config); - - $httpBackend.whenGET(`Workers/findOne?${json}`).respond(response); - $httpBackend.expectGET(`Workers/findOne?${json}`); - controller.loadData(); + $httpBackend.expectGET(`Workers/${id}`).respond(response); + controller.id = id; $httpBackend.flush(); expect(controller.worker).toEqual(response); diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index 82cfd0886..e92a967c9 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -1,14 +1,13 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { get worker() { return this._worker; } set worker(value) { this._worker = value; - if (!value) return; this._quicklinks = { @@ -19,17 +18,9 @@ class Controller extends Component { } }; } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } } -ngModule.component('vnWorkerDescriptor', { +ngModule.vnComponent('vnWorkerDescriptor', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/worker/front/dms/create/index.js b/modules/worker/front/dms/create/index.js index 388b9a333..79d7c5fdd 100644 --- a/modules/worker/front/dms/create/index.js +++ b/modules/worker/front/dms/create/index.js @@ -102,7 +102,7 @@ class Controller extends Section { } } -Controller.$inject = ['$element', '$scope', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnWorkerDmsCreate', { template: require('./index.html'), diff --git a/modules/worker/front/log/index.html b/modules/worker/front/log/index.html index 8aa693924..bfa60a8c3 100644 --- a/modules/worker/front/log/index.html +++ b/modules/worker/front/log/index.html @@ -99,6 +99,5 @@ + vn-id="workerDescriptor"> diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 59ed5c944..ebecef899 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -85,7 +85,7 @@ diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index cf7ef14da..eb6d7795d 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -61,8 +61,7 @@ class Controller extends Section { }); } - preview(event, zone) { - this.stopEvent(event); + preview(zone) { this.selectedZone = zone; this.$.summary.show(); } diff --git a/modules/zone/front/descriptor/index.html b/modules/zone/front/descriptor/index.html index 58441d10d..90f4effea 100644 --- a/modules/zone/front/descriptor/index.html +++ b/modules/zone/front/descriptor/index.html @@ -18,36 +18,44 @@
- - - - - - - -
\ No newline at end of file diff --git a/modules/zone/front/descriptor/index.js b/modules/zone/front/descriptor/index.js index b3808f256..5c0c4dcce 100644 --- a/modules/zone/front/descriptor/index.js +++ b/modules/zone/front/descriptor/index.js @@ -1,10 +1,13 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { $onInit() { this.moreOptions = [ - {callback: this.deleteZone, name: 'Delete'} + { + name: 'Delete', + callback: () => this.$.deleteZone.show(), + } ]; } @@ -12,20 +15,14 @@ class Controller extends Component { callback.call(this); } - deleteZone() { - this.$.deleteZone.show(); - } - - returnDialog(response) { - if (response === 'accept') { - this.$http.delete(`Zones/${this.zone.id}`).then(() => { - this.$state.go('zone.index'); - }); - } + onDeleteAccept() { + return this.$http.delete(`Zones/${this.zone.id}`).then(() => { + this.$state.go('zone.index'); + }); } } -ngModule.component('vnZoneDescriptor', { +ngModule.vnComponent('vnZoneDescriptor', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/zone/front/index/index.html b/modules/zone/front/index/index.html index 64450e451..39d5446d1 100644 --- a/modules/zone/front/index/index.html +++ b/modules/zone/front/index/index.html @@ -29,14 +29,14 @@ diff --git a/modules/zone/front/index/index.js b/modules/zone/front/index/index.js index 9750a949f..b39c6139a 100644 --- a/modules/zone/front/index/index.js +++ b/modules/zone/front/index/index.js @@ -2,17 +2,11 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - preview(event, zone) { - this.stopEvent(event); + preview(zone) { this.selectedZone = zone; this.$.summary.show(); } - clone(event, zone) { - this.stopEvent(event); - this.$.clone.show(zone); - } - onCloneAccept(zone) { return this.$http.post(`Zones/${zone.id}/clone`) .then(res => {