From 6412f2968580d82bdbc898f44e248c1b8ab43a04 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 16 Oct 2020 10:40:45 +0200 Subject: [PATCH 1/5] 2428 - Added anchor directive --- front/core/directives/anchor.js | 32 +++++++++++++++++++++++++++ front/core/directives/index.js | 1 + modules/client/front/index/index.html | 5 +++-- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 front/core/directives/anchor.js diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js new file mode 100644 index 000000000..48c2da493 --- /dev/null +++ b/front/core/directives/anchor.js @@ -0,0 +1,32 @@ +import ngModule from '../module'; + +/** + * Allows changing state for nested anchor + * + * @param {Object} $parse + * @param {Object} $state + * @return {Object} The directive + */ +export function directive($parse, $state) { + return { + restrict: 'A', + link: function($scope, $element, $attrs) { + const state = $scope.$eval($attrs.vnAnchor); + // const element = $element[0]; + $element.on('click', event => { + const params = []; + + for (let param in state.params) + console.log(param); + + // $state.go(state.url, state.params); + event.preventDefault(); + event.stopPropagation(); + }); + } + }; +} + +directive.$inject = ['$parse', '$state']; + +ngModule.directive('vnAnchor', directive); diff --git a/front/core/directives/index.js b/front/core/directives/index.js index af05c9b38..e0f42aef5 100644 --- a/front/core/directives/index.js +++ b/front/core/directives/index.js @@ -15,3 +15,4 @@ import './smart-table'; import './droppable'; import './http-click'; import './http-submit'; +import './anchor'; diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index 7493ecace..dc65d6025 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -40,8 +40,7 @@ vn-tooltip="Client frozen" icon="icon-frozen"> - @@ -51,6 +50,8 @@ icon="desktop_windows"> + + From cf8ed6f8d3de07a42982611c476c939707da0b95 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 19 Oct 2020 07:35:24 +0200 Subject: [PATCH 2/5] Anchor directive functionality --- front/core/directives/anchor.js | 57 ++++++++++++++++++---- front/core/directives/specs/anchor.spec.js | 22 +++++++++ 2 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 front/core/directives/specs/anchor.spec.js diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index 48c2da493..a0ae62a98 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -7,26 +7,63 @@ import ngModule from '../module'; * @param {Object} $state * @return {Object} The directive */ -export function directive($parse, $state) { +export function directive($state, $window) { + let ctrlPressed = false; + + $window.addEventListener('keydown', event => { + if (event.key == 'Control') + ctrlPressed = true; + }); + + $window.addEventListener('keyup', event => { + if (event.key == 'Control') + ctrlPressed = false; + }); + + function changeState(event, state) { + const params = stringifyParams(state); + $state.go(state.url, params); + + event.preventDefault(); + event.stopPropagation(); + } + + function newTab(event, state) { + const params = stringifyParams(state); + const url = $state.href(state.url, params); + $window.open(url); + + event.preventDefault(); + event.stopPropagation(); + } + + function stringifyParams(state) { + const params = Object.assign({}, state.params); + for (let param in params) + params[param] = JSON.stringify(params[param]); + + return params; + } + return { restrict: 'A', link: function($scope, $element, $attrs) { const state = $scope.$eval($attrs.vnAnchor); - // const element = $element[0]; $element.on('click', event => { - const params = []; + if (ctrlPressed) + newTab(event, state); + else + changeState(event, state); + }); - for (let param in state.params) - console.log(param); - - // $state.go(state.url, state.params); - event.preventDefault(); - event.stopPropagation(); + $element.on('mousedown', event => { + if (event.button == 1) + newTab(event, state); }); } }; } -directive.$inject = ['$parse', '$state']; +directive.$inject = ['$state', '$window']; ngModule.directive('vnAnchor', directive); diff --git a/front/core/directives/specs/anchor.spec.js b/front/core/directives/specs/anchor.spec.js new file mode 100644 index 000000000..fc3c053b3 --- /dev/null +++ b/front/core/directives/specs/anchor.spec.js @@ -0,0 +1,22 @@ + +fdescribe('Directive vnAnchor', () => { + let $scope; + let $element; + let compile; + + beforeEach(ngModule('vnCore')); + + compile = _element => { + inject(($compile, $rootScope) => { + $scope = $rootScope.$new(); + $element = angular.element(_element); + $compile($element)($scope); + $scope.$digest(); + }); + }; + + it(`should throw an error when there's no id defined`, () => { + let html = ``; + compile(html); + }); +}); From 011bba16606101ad786087c3dfd0125f45ddde9c Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 19 Oct 2020 09:05:38 +0200 Subject: [PATCH 3/5] Added vn-anchor to client and ticket index --- front/core/directives/anchor.js | 26 +++++++++---------- modules/client/front/descriptor/locale/es.yml | 3 ++- modules/client/front/index/index.html | 2 +- modules/ticket/front/index/index.html | 2 +- modules/ticket/front/index/index.js | 5 ---- modules/worker/front/index/index.html | 2 +- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index a0ae62a98..4b35f1475 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -20,25 +20,25 @@ export function directive($state, $window) { ctrlPressed = false; }); - function changeState(event, state) { - const params = stringifyParams(state); - $state.go(state.url, params); + function changeState(event, data) { + const params = stringifyParams(data); + $state.go(data.state, params); event.preventDefault(); event.stopPropagation(); } - function newTab(event, state) { - const params = stringifyParams(state); - const url = $state.href(state.url, params); - $window.open(url); + function newTab(event, data) { + const params = stringifyParams(data); + const href = $state.href(data.state, params); + $window.open(href); event.preventDefault(); event.stopPropagation(); } - function stringifyParams(state) { - const params = Object.assign({}, state.params); + function stringifyParams(data) { + const params = Object.assign({}, data.params); for (let param in params) params[param] = JSON.stringify(params[param]); @@ -48,17 +48,17 @@ export function directive($state, $window) { return { restrict: 'A', link: function($scope, $element, $attrs) { - const state = $scope.$eval($attrs.vnAnchor); + const data = $scope.$eval($attrs.vnAnchor); $element.on('click', event => { if (ctrlPressed) - newTab(event, state); + newTab(event, data); else - changeState(event, state); + changeState(event, data); }); $element.on('mousedown', event => { if (event.button == 1) - newTab(event, state); + newTab(event, data); }); } }; diff --git a/modules/client/front/descriptor/locale/es.yml b/modules/client/front/descriptor/locale/es.yml index 3f59aede8..03cf17e7b 100644 --- a/modules/client/front/descriptor/locale/es.yml +++ b/modules/client/front/descriptor/locale/es.yml @@ -1,4 +1,5 @@ Simple ticket: Ticket simple View consumer report: Ver informe de consumo From date: Fecha desde -To date: Fecha hasta \ No newline at end of file +To date: Fecha hasta +Go to user: Ir al usuario \ No newline at end of file diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index dc65d6025..3c64fe55f 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -40,7 +40,7 @@ vn-tooltip="Client frozen" icon="icon-frozen"> - diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index e9066a41b..902d1f5a4 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -119,7 +119,7 @@ diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 32c2f0baa..cae9c403c 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -114,11 +114,6 @@ export default class Controller extends Section { return 'warning'; } - goToLines(ticketFk) { - let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); - window.open(url, '_blank'); - } - preview(ticket) { this.selectedTicket = ticket; this.$.summary.show(); diff --git a/modules/worker/front/index/index.html b/modules/worker/front/index/index.html index 3d383ae04..c994e7a7b 100644 --- a/modules/worker/front/index/index.html +++ b/modules/worker/front/index/index.html @@ -29,7 +29,7 @@ Date: Tue, 20 Oct 2020 07:43:36 +0200 Subject: [PATCH 4/5] Added unit test --- front/core/directives/anchor.js | 58 ++++++++++++---------- front/core/directives/specs/anchor.spec.js | 39 ++++++++++++--- modules/client/front/index/index.html | 2 - 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index 4b35f1475..58d5a688f 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -1,5 +1,32 @@ import ngModule from '../module'; +export function newTab($state, $window, event, data) { + const params = stringifyParams(data); + const href = $state.href(data.state, params); + $window.open(href); + + event.preventDefault(); + event.stopPropagation(); +} + +export function stringifyParams(data) { + console.log('stringifyParams', 'called'); + const params = Object.assign({}, data.params); + for (let param in params) + params[param] = JSON.stringify(params[param]); + + return params; +} + +export function changeState($state, event, data) { + // console.log('changeState called!'); + const params = stringifyParams(data); + $state.go(data.state, params); + + event.preventDefault(); + event.stopPropagation(); +} + /** * Allows changing state for nested anchor * @@ -20,40 +47,17 @@ export function directive($state, $window) { ctrlPressed = false; }); - function changeState(event, data) { - const params = stringifyParams(data); - $state.go(data.state, params); - - event.preventDefault(); - event.stopPropagation(); - } - - function newTab(event, data) { - const params = stringifyParams(data); - const href = $state.href(data.state, params); - $window.open(href); - - event.preventDefault(); - event.stopPropagation(); - } - - function stringifyParams(data) { - const params = Object.assign({}, data.params); - for (let param in params) - params[param] = JSON.stringify(params[param]); - - return params; - } - return { restrict: 'A', link: function($scope, $element, $attrs) { const data = $scope.$eval($attrs.vnAnchor); $element.on('click', event => { + // console.log('evento click'); + if (ctrlPressed) - newTab(event, data); + newTab($state, $window, event, data); else - changeState(event, data); + changeState($state, event, data); }); $element.on('mousedown', event => { diff --git a/front/core/directives/specs/anchor.spec.js b/front/core/directives/specs/anchor.spec.js index fc3c053b3..2eea2cac6 100644 --- a/front/core/directives/specs/anchor.spec.js +++ b/front/core/directives/specs/anchor.spec.js @@ -1,22 +1,47 @@ +// import {changeState} from '../anchor'; +import * as vnAnchor from '../anchor'; -fdescribe('Directive vnAnchor', () => { +xdescribe('Directive vnAnchor', () => { let $scope; - let $element; + let element; let compile; beforeEach(ngModule('vnCore')); - compile = _element => { + compile = (_element, _childElement) => { inject(($compile, $rootScope) => { $scope = $rootScope.$new(); - $element = angular.element(_element); - $compile($element)($scope); + element = angular.element(_element); + $compile(element)($scope); $scope.$digest(); + element = $element[0]; }); }; - it(`should throw an error when there's no id defined`, () => { - let html = ``; + xit(`should throw an error when there's no id defined`, () => { + let html = `
`; + jest.spyOn(anchor, 'changeState'); compile(html); + + // element[0].click(); + + element[0].changeState = anchor.changeState; + element[0].dispatchEvent(new Event('click')); + + expect(element[0].changeState).toHaveBeenCalledWith(); + }); + + xit(`changeState()`, () => { + jest.spyOn(vnAnchor, 'stringifyParams'); + + const $state = { + go: () => {} + }; + const $event = new Event('click'); + const data = {state: 'hey', params: {}}; + + vnAnchor.changeState($state, $event, data); + + expect(vnAnchor.stringifyParams).toHaveBeenCalledWith(); }); }); diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index 3c64fe55f..abbbe60e5 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -50,8 +50,6 @@ icon="desktop_windows">
- - From adfeb2c358cf08194b34b1b21c134bfadd348963 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 21 Oct 2020 10:26:28 +0200 Subject: [PATCH 5/5] Updated directive --- front/core/directives/anchor.js | 31 +++++++------- front/core/directives/specs/anchor.spec.js | 47 ---------------------- 2 files changed, 14 insertions(+), 64 deletions(-) delete mode 100644 front/core/directives/specs/anchor.spec.js diff --git a/front/core/directives/anchor.js b/front/core/directives/anchor.js index 58d5a688f..9a079affd 100644 --- a/front/core/directives/anchor.js +++ b/front/core/directives/anchor.js @@ -1,16 +1,6 @@ import ngModule from '../module'; -export function newTab($state, $window, event, data) { - const params = stringifyParams(data); - const href = $state.href(data.state, params); - $window.open(href); - - event.preventDefault(); - event.stopPropagation(); -} - export function stringifyParams(data) { - console.log('stringifyParams', 'called'); const params = Object.assign({}, data.params); for (let param in params) params[param] = JSON.stringify(params[param]); @@ -19,7 +9,6 @@ export function stringifyParams(data) { } export function changeState($state, event, data) { - // console.log('changeState called!'); const params = stringifyParams(data); $state.go(data.state, params); @@ -27,11 +16,20 @@ export function changeState($state, event, data) { event.stopPropagation(); } +export function openNewTab($state, $window, event, data) { + const params = stringifyParams(data); + const href = $state.href(data.state, params); + $window.open(href); + + event.preventDefault(); + event.stopPropagation(); +} + /** * Allows changing state for nested anchor * - * @param {Object} $parse * @param {Object} $state + * @param {Object} $window * @return {Object} The directive */ export function directive($state, $window) { @@ -52,17 +50,16 @@ export function directive($state, $window) { link: function($scope, $element, $attrs) { const data = $scope.$eval($attrs.vnAnchor); $element.on('click', event => { - // console.log('evento click'); - if (ctrlPressed) - newTab($state, $window, event, data); + openNewTab($state, $window, event, data); else changeState($state, event, data); }); $element.on('mousedown', event => { - if (event.button == 1) - newTab(event, data); + const mouseWheel = 1; + if (event.button == mouseWheel) + openNewTab($state, $window, event, data); }); } }; diff --git a/front/core/directives/specs/anchor.spec.js b/front/core/directives/specs/anchor.spec.js deleted file mode 100644 index 2eea2cac6..000000000 --- a/front/core/directives/specs/anchor.spec.js +++ /dev/null @@ -1,47 +0,0 @@ -// import {changeState} from '../anchor'; -import * as vnAnchor from '../anchor'; - -xdescribe('Directive vnAnchor', () => { - let $scope; - let element; - let compile; - - beforeEach(ngModule('vnCore')); - - compile = (_element, _childElement) => { - inject(($compile, $rootScope) => { - $scope = $rootScope.$new(); - element = angular.element(_element); - $compile(element)($scope); - $scope.$digest(); - element = $element[0]; - }); - }; - - xit(`should throw an error when there's no id defined`, () => { - let html = `
`; - jest.spyOn(anchor, 'changeState'); - compile(html); - - // element[0].click(); - - element[0].changeState = anchor.changeState; - element[0].dispatchEvent(new Event('click')); - - expect(element[0].changeState).toHaveBeenCalledWith(); - }); - - xit(`changeState()`, () => { - jest.spyOn(vnAnchor, 'stringifyParams'); - - const $state = { - go: () => {} - }; - const $event = new Event('click'); - const data = {state: 'hey', params: {}}; - - vnAnchor.changeState($state, $event, data); - - expect(vnAnchor.stringifyParams).toHaveBeenCalledWith(); - }); -});