From 5bf20683445bf3ef82374a063b259f8728041a79 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 8 Oct 2019 13:51:16 +0200 Subject: [PATCH 01/17] added invoiceOut alias --- modules/invoiceOut/back/methods/invoiceOut/filter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/filter.js b/modules/invoiceOut/back/methods/invoiceOut/filter.js index 001fe077d..092d298d0 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/filter.js +++ b/modules/invoiceOut/back/methods/invoiceOut/filter.js @@ -86,8 +86,9 @@ module.exports = Self => { return {'i.hasPdf': value}; case 'created': return {'i.created': value}; - case 'amount': case 'clientFk': + return {'i.clientFk': value}; + case 'amount': case 'companyFk': case 'issued': case 'dued': From f8ba4d38b786e8a83eb7c6ee174da420dc7dbc08 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 8 Oct 2019 14:36:02 +0200 Subject: [PATCH 02/17] stowaway changed to correct field name --- modules/ticket/back/methods/ticket/getPossibleStowaways.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/getPossibleStowaways.js b/modules/ticket/back/methods/ticket/getPossibleStowaways.js index f692c9f23..3565d64ab 100644 --- a/modules/ticket/back/methods/ticket/getPossibleStowaways.js +++ b/modules/ticket/back/methods/ticket/getPossibleStowaways.js @@ -45,7 +45,7 @@ module.exports = Self => { clientFk: ship.clientFk, addressFk: ship.addressFk, agencyModeFk: ship.agencyModeFk, - warehouse: {neq: ship.warehouseFk}, + warehouseFk: {neq: ship.warehouseFk}, shipped: { between: [lowestDate.toJSON(), highestDate.toJSON()] } From 0c097718c15cfc0d364a82d9091aa19e60b976e4 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 10 Oct 2019 08:33:22 +0200 Subject: [PATCH 03/17] added transaction options to findOne() --- back/methods/dms/uploadFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index b50aaf824..41d551f2b 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -94,7 +94,7 @@ module.exports = Self => { const models = Self.app.models; const storageConnector = Self.app.dataSources.storage.connector; const myUserId = ctx.req.accessToken.userId; - const myWorker = await models.Worker.findOne({where: {userFk: myUserId}}); + const myWorker = await models.Worker.findOne({where: {userFk: myUserId}}, myOptions); const args = ctx.args; const newDms = await Self.create({ From 777baf38a84f1f54376b27a25edce7b11ffd60fd Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 10 Oct 2019 09:58:34 +0200 Subject: [PATCH 04/17] changed warehouse from ticket id 17 --- db/dump/fixtures.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f701c4121..f00a98759 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -471,7 +471,7 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (14, 1, 2, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Malibu Point', 4, NULL, 0, 9, CURDATE()), (15, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, 3, CURDATE()), (16, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), - (17, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), + (17, 1, 7, 2, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), (18, 1, 4, 4, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 108, 'Cerebro', 128, NULL, 0, 12, CURDATE()), (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, 13, CURDATE()), (20, 1, 5, 5, 3, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), From 9899edffc63090d9913b7f730885a2f8bc996208 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 10 Oct 2019 09:59:28 +0200 Subject: [PATCH 05/17] changed state to stowaway ticket --- modules/ticket/back/models/stowaway.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/models/stowaway.js b/modules/ticket/back/models/stowaway.js index aa21e8680..780b6b31c 100644 --- a/modules/ticket/back/models/stowaway.js +++ b/modules/ticket/back/models/stowaway.js @@ -14,7 +14,7 @@ module.exports = function(Self) { code: 'BOARDING' }; let state = await models.State.findOne({where}); - let params = {ticketFk: ctx.instance.id, stateFk: state.id}; + let params = {ticketFk: ctx.instance.shipFk, stateFk: state.id}; const loopBackContext = LoopBackContext.getCurrentContext(); let httpCtx = {req: loopBackContext.active}; From 2a3d6dcd76ee5e5e3005ded1c524533c769f12b4 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 14 Oct 2019 11:50:45 +0200 Subject: [PATCH 06/17] fixed transaction params --- back/methods/message/send.js | 4 ++-- modules/client/back/methods/address/createDefaultAddress.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/back/methods/message/send.js b/back/methods/message/send.js index f7b7ad76e..c8849774b 100644 --- a/back/methods/message/send.js +++ b/back/methods/message/send.js @@ -29,8 +29,8 @@ module.exports = Self => { const accessToken = ctx.options && ctx.options.accessToken || ctx.req && ctx.req.accessToken; const userId = accessToken.userId; const models = Self.app.models; - const sender = await models.Account.findById(userId, options); - const recipient = await models.Account.findById(data.recipientFk, options); + const sender = await models.Account.findById(userId, null, options); + const recipient = await models.Account.findById(data.recipientFk, null, options); await Self.create({ sender: sender.name, diff --git a/modules/client/back/methods/address/createDefaultAddress.js b/modules/client/back/methods/address/createDefaultAddress.js index c757f9f85..e524a6017 100644 --- a/modules/client/back/methods/address/createDefaultAddress.js +++ b/modules/client/back/methods/address/createDefaultAddress.js @@ -26,7 +26,7 @@ module.exports = function(Self) { let address = data.address; let newAddress = await Address.create(address, options); - let client = await Client.findById(address.clientFk, options); + let client = await Client.findById(address.clientFk, null, options); if (data.isDefaultAddress) { await client.updateAttributes({ From c33906ca103b843864c7ba0ec5150a2f1f61cdef Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 15 Oct 2019 08:50:11 +0200 Subject: [PATCH 07/17] descuadre de horas #1766 rollback --- .../worker/back/methods/worker-time-control/addTime.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/addTime.js b/modules/worker/back/methods/worker-time-control/addTime.js index 9864142bf..5548654bc 100644 --- a/modules/worker/back/methods/worker-time-control/addTime.js +++ b/modules/worker/back/methods/worker-time-control/addTime.js @@ -33,7 +33,13 @@ module.exports = Self => { const subordinate = await Worker.findById(data.workerFk); - return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ - subordinate.userFk, null, data.timed, true]); + return Self.create({ + userFk: subordinate.userFk, + timed: data.timed, + manual: 1 + }); + + /* return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ + subordinate.userFk, null, data.timed, true]); */ }; }; From 7aaa8f4a5e3d83a8cd84929f78a347b04083bfe1 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 16 Oct 2019 08:56:13 +0200 Subject: [PATCH 08/17] refactor drag & drop treeview --- front/core/components/treeview/child.html | 20 +++ .../treeview/{content.js => child.js} | 30 +++- front/core/components/treeview/childs.html | 33 +---- front/core/components/treeview/index.js | 129 ++++++++++++++++-- front/core/components/treeview/style.scss | 41 +++--- front/core/directives/draggable.js | 43 ------ front/core/directives/droppable.js | 93 +++++-------- front/core/directives/droppable.scss | 18 ++- front/core/directives/index.js | 1 - front/core/lib/event-emitter.js | 15 +- loopback/locale/es.json | 4 +- modules/claim/front/dms/index/index.html | 2 +- modules/claim/front/dms/index/index.js | 5 +- .../back/methods/department/moveChild.js | 42 ++++++ modules/worker/back/models/department.js | 1 + modules/worker/back/models/department.json | 9 ++ modules/worker/front/department/index.html | 5 +- modules/worker/front/department/index.js | 29 ++-- 18 files changed, 331 insertions(+), 189 deletions(-) create mode 100644 front/core/components/treeview/child.html rename front/core/components/treeview/{content.js => child.js} (51%) delete mode 100644 front/core/directives/draggable.js create mode 100644 modules/worker/back/methods/department/moveChild.js diff --git a/front/core/components/treeview/child.html b/front/core/components/treeview/child.html new file mode 100644 index 000000000..1b928d5ea --- /dev/null +++ b/front/core/components/treeview/child.html @@ -0,0 +1,20 @@ +
+ + +
+
+ + + + +
+
diff --git a/front/core/components/treeview/content.js b/front/core/components/treeview/child.js similarity index 51% rename from front/core/components/treeview/content.js rename to front/core/components/treeview/child.js index 506117d4f..9e4edef35 100644 --- a/front/core/components/treeview/content.js +++ b/front/core/components/treeview/child.js @@ -2,22 +2,33 @@ import ngModule from '../../module'; class Controller { constructor($element, $scope, $compile) { - this.$element = $element; this.$scope = $scope; this.$compile = $compile; + this.element = $element[0]; + + this.element.$ctrl = this; + this.element.droppable = true; + this.dropCount = 0; + this.element.classList.add('vn-droppable'); } $onInit() { + const transcludeElement = this.element.querySelector('.content'); + const content = angular.element(transcludeElement); + if (this.item.parent) { this.treeview.$transclude(($clone, $scope) => { this.$contentScope = $scope; $scope.item = this.item; - this.$element.append($clone); + content.append($clone); }); + + this.element.draggable = true; + this.element.classList.add('vn-draggable'); } else { let template = `{{$ctrl.treeview.rootLabel}}`; let $clone = this.$compile(template)(this.$scope); - this.$element.append($clone); + content.append($clone); } } @@ -25,10 +36,21 @@ class Controller { if (this.$contentScope) this.$contentScope.$destroy(); } + + dragEnter() { + this.dropCount++; + + if (element != this.dropping) { + this.undrop(); + if (element) element.classList.add('dropping'); + this.dropping = element; + } + } } Controller.$inject = ['$element', '$scope', '$compile']; -ngModule.component('vnTreeviewContent', { +ngModule.component('vnTreeviewChild', { + template: require('./child.html'), controller: Controller, bindings: { item: '<' diff --git a/front/core/components/treeview/childs.html b/front/core/components/treeview/childs.html index 2dd7e77ef..de69ffb89 100644 --- a/front/core/components/treeview/childs.html +++ b/front/core/components/treeview/childs.html @@ -1,34 +1,11 @@
    -
  • -
    - - - - -
    - - - - -
    -
    +
  • + + + items="item.childs">
\ No newline at end of file diff --git a/front/core/components/treeview/index.js b/front/core/components/treeview/index.js index d9da39215..22d6739f7 100644 --- a/front/core/components/treeview/index.js +++ b/front/core/components/treeview/index.js @@ -1,18 +1,113 @@ import ngModule from '../../module'; import Component from '../../lib/component'; import './style.scss'; - import './childs'; -import './content'; +import './child'; /** * Treeview */ export default class Treeview extends Component { - constructor($element, $scope, $transclude) { + constructor($element, $scope, $transclude, $window) { super($element, $scope); this.$transclude = $transclude; + this.$window = $window; this.readOnly = true; + + this.element.addEventListener('dragstart', + event => this.dragStart(event)); + this.element.addEventListener('dragend', + event => this.dragEnd(event)); + + this.element.addEventListener('dragover', + event => this.dragOver(event)); + this.element.addEventListener('drop', + event => this.drop(event)); + this.element.addEventListener('dragenter', + event => this.dragEnter(event)); + this.element.addEventListener('dragleave', + event => this.dragLeave(event)); + + this.dropCount = 0; + } + + undrop() { + if (!this.dropping) return; + this.dropping.classList.remove('dropping'); + this.dropping = null; + } + + findDroppable(event) { + let element = event.target; + while (element != this.element && !element.droppable) + element = element.parentNode; + if (element == this.element) + return null; + return element; + } + + dragOver(event) { + let scrollY = this.$window.scrollY; + + if (event.clientY < this.draggingY) + scrollY -= 2; + else scrollY += 2; + + this.draggingY = event.clientY; + this.$window.scrollTo(0, scrollY); + + // Prevents page reload + event.preventDefault(); + } + + dragStart(event) { + event.target.classList.add('dragging'); + event.dataTransfer.setData('text', event.target.id); + + const element = this.findDroppable(event); + this.dragging = element; + } + + dragEnd(event) { + event.target.classList.remove('dragging'); + this.undrop(); + this.dropCount = 0; + this.dragging = null; + } + + dragEnter(event) { + let element = this.findDroppable(event); + if (element) this.dropCount++; + + if (element != this.dropping) { + this.undrop(); + if (element) element.classList.add('dropping'); + this.dropping = element; + } + } + + dragLeave(event) { + let element = this.findDroppable(event); + + if (element) { + this.dropCount--; + if (this.dropCount == 0) this.undrop(); + } + } + + drop(event) { + event.preventDefault(); + this.element.classList.remove('dropping'); + + const $dropped = this.dropping.$ctrl.item; + const $dragged = this.dragging.$ctrl.item; + + if (!$dropped.active && $dropped.sons) { + this.unfold($dropped).then(() => { + this.emit('drop', {$dropped, $dragged}); + }); + } else + this.emit('drop', {$dropped, $dragged}); } get data() { @@ -100,8 +195,14 @@ export default class Treeview extends Component { } onCreate(parent) { - if (this.createFunc) - this.createFunc({$parent: parent}); + if (this.createFunc) { + if (!parent.active && parent.sons) { + this.unfold(parent).then(() => { + this.createFunc({$parent: parent}); + }); + } else + this.createFunc({$parent: parent}); + } } create(item) { @@ -120,12 +221,24 @@ export default class Treeview extends Component { if (parent) parent.sons++; } - onDrop(item, dragged, dropped) { - this.emit('drop', {item, dragged, dropped}); + move(item, newParent) { + if (newParent == item) return; + + if (item.parent) { + const parent = item.parent; + const childs = parent.childs; + const index = childs.indexOf(item); + parent.sons--; + + childs.splice(index, 1); + } + + item.parent = newParent; + this.create(item); } } -Treeview.$inject = ['$element', '$scope', '$transclude']; +Treeview.$inject = ['$element', '$scope', '$transclude', '$window']; ngModule.component('vnTreeview', { template: require('./index.html'), diff --git a/front/core/components/treeview/style.scss b/front/core/components/treeview/style.scss index b3724a9f1..e39d1708d 100644 --- a/front/core/components/treeview/style.scss +++ b/front/core/components/treeview/style.scss @@ -10,22 +10,6 @@ vn-treeview-childs { li { list-style: none; - & > .node { - @extend %clickable; - display: flex; - padding: 5px; - align-items: center; - } - - & > div > .arrow { - min-width: 24px; - margin-right: 10px; - transition: transform 200ms; - } - - & > div.expanded > .arrow { - transform: rotate(180deg); - } ul { padding-left: 2.2em; } @@ -45,8 +29,27 @@ vn-treeview-childs { .node:hover > .buttons { display: block } + + .content { + flex-grow: 1 + } } -vn-treeview-content { - flex-grow: 1 -} \ No newline at end of file +vn-treeview-child { + display: block; + + .node { + @extend %clickable; + display: flex; + padding: 5px; + align-items: center; + } + & > div > .arrow { + min-width: 24px; + margin-right: 10px; + transition: transform 200ms; + } + &.expanded > div > .arrow { + transform: rotate(180deg); + } +} \ No newline at end of file diff --git a/front/core/directives/draggable.js b/front/core/directives/draggable.js deleted file mode 100644 index 3b68a6cb6..000000000 --- a/front/core/directives/draggable.js +++ /dev/null @@ -1,43 +0,0 @@ -import ngModule from '../module'; - -/** - * Enables a draggable element and his drag events - * - * @return {Object} The directive - */ -export function directive() { - return { - restrict: 'A', - link: function($scope, $element, $attrs) { - const element = $element[0]; - const isDraggable = $attrs.vnDraggable === 'true'; - - if (!isDraggable) return; - - // Set draggable style properties - element.style.cursor = 'move'; - - - // Enable as draggable element - element.setAttribute('draggable', true); - - /** - * Fires when a drag event starts - */ - element.addEventListener('dragstart', event => { - element.style.opacity = 0.5; - event.stopPropagation(); - }); - - /** - * Fires when a drag event ends - */ - element.addEventListener('dragend', event => { - element.style.opacity = 1; - event.stopPropagation(); - }); - } - }; -} - -ngModule.directive('vnDraggable', directive); diff --git a/front/core/directives/droppable.js b/front/core/directives/droppable.js index 483282418..929b64be7 100644 --- a/front/core/directives/droppable.js +++ b/front/core/directives/droppable.js @@ -1,68 +1,43 @@ import ngModule from '../module'; import './droppable.scss'; -export function directive($parse) { - return { - restrict: 'A', - link: function($scope, $element, $attrs) { - const element = $element[0]; - const onDropEvent = $parse($attrs.onDrop); - const isDroppable = $attrs.vnDroppable === 'true'; +class Controller { + constructor($element, $, $attrs) { + this.element = $element[0]; + this.$ = $; + this.$attrs = $attrs; - if (!isDroppable) return; + this.element.addEventListener('dragover', + event => event.preventDefault()); // Prevents page reload + this.element.addEventListener('drop', + event => this.drop(event)); + this.element.addEventListener('dragenter', + event => this.dragEnter(event)); + this.element.addEventListener('dragleave', + event => this.dragLeave(event)); + } - /** - * Captures current dragging element - */ - element.addEventListener('dragstart', () => { - this.dragged = element; - }); + dragEnter(event) { + this.droppedElement = event.target; + this.element.classList.add('dropping'); + } - /** - * Enter droppable area event - */ - element.addEventListener('dragenter', event => { - element.classList.add('active'); + dragLeave(event) { + if (this.droppedElement === event.target) + this.element.classList.remove('dropping'); + } - event.stopImmediatePropagation(); - event.preventDefault(); - }, false); - - - /** - * Exit droppable area event - */ - element.addEventListener('dragleave', event => { - element.classList.remove('active'); - - event.stopImmediatePropagation(); - event.preventDefault(); - }); - - /** - * Prevent dragover for allowing - * dispatch drop event - */ - element.addEventListener('dragover', event => { - event.stopPropagation(); - event.preventDefault(); - }); - - /** - * Fires when a drop events - */ - element.addEventListener('drop', event => { - element.classList.remove('active'); - - onDropEvent($scope, {event}); - - event.stopPropagation(); - event.preventDefault(); - }); - } - }; + drop(event) { + if (event.defaultPrevented) return; + event.preventDefault(); + this.element.classList.remove('dropping'); + this.$.$eval(this.$attrs.vnDroppable, {$event: event}); + } } +Controller.$inject = ['$element', '$scope', '$attrs']; -directive.$inject = ['$parse']; - -ngModule.directive('vnDroppable', directive); +ngModule.directive('vnDroppable', () => { + return { + controller: Controller + }; +}); diff --git a/front/core/directives/droppable.scss b/front/core/directives/droppable.scss index 749bc9a12..97e6f8a19 100644 --- a/front/core/directives/droppable.scss +++ b/front/core/directives/droppable.scss @@ -1,11 +1,25 @@ @import "./variables"; + +.vn-droppable, +.vn-draggable, [vn-droppable] { border: 2px dashed transparent; + border-radius: 0.5em; transition: all 0.5s; +} - &.active { +.vn-droppable, +[vn-droppable] { + display: block; + + &.dropping { background-color: $color-hover-cd; - border: 2px dashed $color-bg-dark; + border-color: $color-bg-dark; } +} + +.vn-draggable.dragging { + background-color: $color-main-light; + border-color: $color-main; } \ No newline at end of file diff --git a/front/core/directives/index.js b/front/core/directives/index.js index 08adfac07..7ee63220b 100644 --- a/front/core/directives/index.js +++ b/front/core/directives/index.js @@ -11,7 +11,6 @@ import './bind'; import './repeat-last'; import './title'; import './uvc'; -import './draggable'; import './droppable'; import './http-click'; import './http-submit'; diff --git a/front/core/lib/event-emitter.js b/front/core/lib/event-emitter.js index 2dede42ab..022e4e98c 100644 --- a/front/core/lib/event-emitter.js +++ b/front/core/lib/event-emitter.js @@ -24,10 +24,12 @@ export default class EventEmitter { */ off(callback) { if (!this.$events) return; - for (let event in this.$events) - for (let i = 0; i < event.length; i++) + for (let event in this.$events) { + for (let i = 0; i < event.length; i++) { if (event[i].callback === callback) event.splice(i--, 1); + } + } } /** @@ -37,10 +39,12 @@ export default class EventEmitter { */ disconnect(thisArg) { if (!this.$events) return; - for (let event in this.$events) - for (let i = 0; i < event.length; i++) + for (let event in this.$events) { + for (let i = 0; i < event.length; i++) { if (event[i].thisArg === thisArg) event.splice(i--, 1); + } + } } /** @@ -72,9 +76,10 @@ export default class EventEmitter { if (this[prop]) this[prop].disconnect(this); this[prop] = value; - if (value) + if (value) { for (let event in handlers) value.on(event, handlers[event], this); + } } } } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 07c95af32..aa135d520 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -108,5 +108,7 @@ "This postal code is not valid": "This postal code is not valid", "is invalid": "is invalid", "The postcode doesn't exists. Ensure you put the correct format": "El código postal no existe. Asegúrate de ponerlo con el formato correcto", - "The department name can't be repeated": "El nombre del departamento no puede repetirse" + "The department name can't be repeated": "El nombre del departamento no puede repetirse", + "You cannot move a parent to any of its sons": "You cannot move a parent to any of its sons", + "You cannot move a parent to its own sons": "You cannot move a parent to its own sons" } \ No newline at end of file diff --git a/modules/claim/front/dms/index/index.html b/modules/claim/front/dms/index/index.html index 10e35e58e..81bd088a7 100644 --- a/modules/claim/front/dms/index/index.html +++ b/modules/claim/front/dms/index/index.html @@ -5,7 +5,7 @@ data="$ctrl.photos"> -
+
Drag & Drop files here...
diff --git a/modules/claim/front/dms/index/index.js b/modules/claim/front/dms/index/index.js index f60feab6c..f382e4d67 100644 --- a/modules/claim/front/dms/index/index.js +++ b/modules/claim/front/dms/index/index.js @@ -35,8 +35,9 @@ class Controller { } } - onDrop(event) { - const files = event.dataTransfer.files; + onDrop($event) { + console.log($event); + const files = $event.dataTransfer.files; this.setDefaultParams().then(() => { this.dms.files = files; this.create(); diff --git a/modules/worker/back/methods/department/moveChild.js b/modules/worker/back/methods/department/moveChild.js new file mode 100644 index 000000000..97206f198 --- /dev/null +++ b/modules/worker/back/methods/department/moveChild.js @@ -0,0 +1,42 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethod('moveChild', { + description: 'Changes the parent of a child department', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'Number', + description: 'The department id', + http: {source: 'path'} + }, { + arg: 'parentId', + type: 'Number', + description: 'New parent id', + }], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/:id/moveChild`, + verb: 'POST' + } + }); + + Self.moveChild = async(id, parentId = null) => { + const models = Self.app.models; + const child = await models.Department.findById(id); + + if (id == parentId) return; + + if (parentId) { + const parent = await models.Department.findById(parentId); + + if (child.lft < parent.lft && child.rgt > parent.rgt) + throw new UserError('You cannot move a parent to its own sons'); + } + + return child.updateAttribute('parentFk', parentId); + }; +}; diff --git a/modules/worker/back/models/department.js b/modules/worker/back/models/department.js index e6905d273..5a927fc64 100644 --- a/modules/worker/back/models/department.js +++ b/modules/worker/back/models/department.js @@ -2,4 +2,5 @@ module.exports = Self => { require('../methods/department/getLeaves')(Self); require('../methods/department/createChild')(Self); require('../methods/department/removeChild')(Self); + require('../methods/department/moveChild')(Self); }; diff --git a/modules/worker/back/models/department.json b/modules/worker/back/models/department.json index bb5d5e943..7de76e039 100644 --- a/modules/worker/back/models/department.json +++ b/modules/worker/back/models/department.json @@ -16,6 +16,15 @@ }, "parentFk": { "type": "Number" + }, + "lft": { + "type": "Number" + }, + "rgt": { + "type": "Number" + }, + "sons": { + "type": "Number" } } } diff --git a/modules/worker/front/department/index.html b/modules/worker/front/department/index.html index 773662032..c7abaf3f8 100644 --- a/modules/worker/front/department/index.html +++ b/modules/worker/front/department/index.html @@ -10,7 +10,10 @@ fetch-func="$ctrl.onFetch($item)" remove-func="$ctrl.onRemove($item)" create-func="$ctrl.onCreate($parent)" - sort-func="$ctrl.onSort($a, $b)"> + sort-func="$ctrl.onSort($a, $b)" + on-drop="$ctrl.onDrop($dropped, $dragged)" + on-drag-start="$ctrl.onDragStart(item)" + on-drag-end="$ctrl.onDragEnd(item)"> {{::item.name}} diff --git a/modules/worker/front/department/index.js b/modules/worker/front/department/index.js index 1a72681bc..b103efff9 100644 --- a/modules/worker/front/department/index.js +++ b/modules/worker/front/department/index.js @@ -23,19 +23,21 @@ class Controller { return a.name.localeCompare(b.name); } - /* onDrop(item, dragged, dropped) { - if (dropped.scope.item) { - const droppedItem = dropped.scope.item; - const draggedItem = dragged.scope.item; + onDrop(dropped, dragged) { + if (!dropped.active) { + this.$.treeview.unfold(dropped).then(() => + this.move(dropped, dragged)); + } else + this.move(dropped, dragged); + } - if (droppedItem.childs) - droppedItem.childs.push(Object.assign({}, draggedItem)); - - dragged.element.remove(); - - this.$scope.$apply(); - } - } */ + move(dropped, dragged) { + const params = dropped ? {parentId: dropped.id} : null; + const query = `/api/departments/${dragged.id}/moveChild`; + this.$http.post(query, params).then(() => { + this.$.treeview.move(dragged, dropped); + }); + } onCreate(parent) { this.newChild = { @@ -62,9 +64,6 @@ class Controller { if (parent && parent.id) params.parentId = parent.id; - if (!parent.active) - this.$.treeview.unfold(parent); - const query = `/api/departments/createChild`; this.$http.post(query, params).then(res => { const parent = this.newChild.parent; From 6d159c50a082076248460ceabb78a9d52c19de27 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 16 Oct 2019 09:52:46 +0200 Subject: [PATCH 09/17] css fixes --- front/core/components/treeview/index.js | 47 +++++++++++------------ front/core/components/treeview/style.scss | 1 + modules/agency/front/location/style.scss | 6 +-- modules/worker/front/department/index.js | 9 ----- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/front/core/components/treeview/index.js b/front/core/components/treeview/index.js index 22d6739f7..9ecbf52e6 100644 --- a/front/core/components/treeview/index.js +++ b/front/core/components/treeview/index.js @@ -47,25 +47,25 @@ export default class Treeview extends Component { } dragOver(event) { - let scrollY = this.$window.scrollY; - - if (event.clientY < this.draggingY) - scrollY -= 2; - else scrollY += 2; - - this.draggingY = event.clientY; - this.$window.scrollTo(0, scrollY); + this.dragClientY = event.clientY; // Prevents page reload event.preventDefault(); } + onDragInterval() { + if (this.dragClientY > 0 && this.dragClientY < 75) + this.$window.scrollTo(0, this.$window.scrollY - 25); + } + dragStart(event) { event.target.classList.add('dragging'); event.dataTransfer.setData('text', event.target.id); const element = this.findDroppable(event); this.dragging = element; + + this.interval = setInterval(() => this.onDragInterval(), 100); } dragEnd(event) { @@ -73,6 +73,7 @@ export default class Treeview extends Component { this.undrop(); this.dropCount = 0; this.dragging = null; + clearInterval(this.interval); } dragEnter(event) { @@ -102,12 +103,7 @@ export default class Treeview extends Component { const $dropped = this.dropping.$ctrl.item; const $dragged = this.dragging.$ctrl.item; - if (!$dropped.active && $dropped.sons) { - this.unfold($dropped).then(() => { - this.emit('drop', {$dropped, $dragged}); - }); - } else - this.emit('drop', {$dropped, $dragged}); + this.emit('drop', {$dropped, $dragged}); } get data() { @@ -195,14 +191,8 @@ export default class Treeview extends Component { } onCreate(parent) { - if (this.createFunc) { - if (!parent.active && parent.sons) { - this.unfold(parent).then(() => { - this.createFunc({$parent: parent}); - }); - } else - this.createFunc({$parent: parent}); - } + if (this.createFunc) + this.createFunc({$parent: parent}); } create(item) { @@ -210,7 +200,10 @@ export default class Treeview extends Component { let childs = parent.childs; if (!childs) childs = []; - childs.push(item); + if (!parent.active) + this.unfold(parent); + else + childs.push(item); if (this.sortFunc) { childs = childs.sort((a, b) => @@ -234,7 +227,13 @@ export default class Treeview extends Component { } item.parent = newParent; - this.create(item); + + if (!newParent.active) { + this.unfold(newParent).then(() => { + item.parent.sons++; + }); + } else + this.create(item); } } diff --git a/front/core/components/treeview/style.scss b/front/core/components/treeview/style.scss index e39d1708d..bd6175021 100644 --- a/front/core/components/treeview/style.scss +++ b/front/core/components/treeview/style.scss @@ -36,6 +36,7 @@ vn-treeview-childs { } vn-treeview-child { + font-size: 16px; display: block; .node { diff --git a/modules/agency/front/location/style.scss b/modules/agency/front/location/style.scss index a3b237b13..d1597e460 100644 --- a/modules/agency/front/location/style.scss +++ b/modules/agency/front/location/style.scss @@ -1,14 +1,14 @@ @import "variables"; -vn-treeview-content { - & > vn-check:not(.indeterminate) { +vn-treeview-child { + .content > vn-check:not(.indeterminate) { color: $color-main; & > .btn { border-color: $color-main; } } - & > vn-check.checked { + .content > vn-check.checked { color: $color-main; } } \ No newline at end of file diff --git a/modules/worker/front/department/index.js b/modules/worker/front/department/index.js index b103efff9..383fee74b 100644 --- a/modules/worker/front/department/index.js +++ b/modules/worker/front/department/index.js @@ -24,14 +24,6 @@ class Controller { } onDrop(dropped, dragged) { - if (!dropped.active) { - this.$.treeview.unfold(dropped).then(() => - this.move(dropped, dragged)); - } else - this.move(dropped, dragged); - } - - move(dropped, dragged) { const params = dropped ? {parentId: dropped.id} : null; const query = `/api/departments/${dragged.id}/moveChild`; this.$http.post(query, params).then(() => { @@ -66,7 +58,6 @@ class Controller { const query = `/api/departments/createChild`; this.$http.post(query, params).then(res => { - const parent = this.newChild.parent; const item = res.data; item.parent = parent; From e0d9f69aefbcb082b6fca92ec390080bffbaa8db Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 16 Oct 2019 10:59:42 +0200 Subject: [PATCH 10/17] corrected a description --- modules/ticket/front/routes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/routes.json b/modules/ticket/front/routes.json index cda0b7536..55922fdde 100644 --- a/modules/ticket/front/routes.json +++ b/modules/ticket/front/routes.json @@ -216,7 +216,7 @@ "url" : "/create", "state": "ticket.card.request.create", "component": "vn-ticket-request-create", - "description": "Purchase request", + "description": "New purchase request", "acl": ["salesPerson"] }, { "url": "/create?clientFk", From 79f9e616d21a2b8fcd9a745df5d2c8a3fcccd163 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 17 Oct 2019 11:08:40 +0200 Subject: [PATCH 11/17] added treeview unit tests --- front/core/components/treeview/childs.js | 4 - front/core/components/treeview/index.js | 3 +- front/core/components/treeview/index.spec.js | 260 +++++++++++++++++++ modules/claim/front/action/index.html | 2 + 4 files changed, 264 insertions(+), 5 deletions(-) create mode 100644 front/core/components/treeview/index.spec.js diff --git a/front/core/components/treeview/childs.js b/front/core/components/treeview/childs.js index a9bd42077..d94c88df9 100644 --- a/front/core/components/treeview/childs.js +++ b/front/core/components/treeview/childs.js @@ -7,10 +7,6 @@ class Controller extends Component { event.preventDefault(); this.treeview.onToggle(item); } - - onDrop(item, dragged, dropped) { - this.treeview.onDrop(item, dragged, dropped); - } } ngModule.component('vnTreeviewChilds', { diff --git a/front/core/components/treeview/index.js b/front/core/components/treeview/index.js index 9ecbf52e6..728ea182e 100644 --- a/front/core/components/treeview/index.js +++ b/front/core/components/treeview/index.js @@ -103,7 +103,8 @@ export default class Treeview extends Component { const $dropped = this.dropping.$ctrl.item; const $dragged = this.dragging.$ctrl.item; - this.emit('drop', {$dropped, $dragged}); + if ($dropped != $dragged.parent) + this.emit('drop', {$dropped, $dragged}); } get data() { diff --git a/front/core/components/treeview/index.spec.js b/front/core/components/treeview/index.spec.js new file mode 100644 index 000000000..75c35fb25 --- /dev/null +++ b/front/core/components/treeview/index.spec.js @@ -0,0 +1,260 @@ +describe('Component vnTreeview', () => { + let controller; + let $element; + + beforeEach(angular.mock.module('vnCore', $translateProvider => { + $translateProvider.translations('en', {}); + })); + + beforeEach(inject(($compile, $rootScope) => { + $element = $compile(``)($rootScope); + controller = $element.controller('vnTreeview'); + + const promise = new Promise(() => { + return {name: 'My item'}; + }); + + controller.fetchFunc = () => { + return promise; + }; + + controller.createFunc = () => { + return promise; + }; + + controller.removeFunc = () => { + return promise; + }; + + controller.sortFunc = () => { + return promise; + }; + })); + + afterEach(() => { + $element.remove(); + }); + + // See how to test DOM element in Jest + xdescribe('undrop()', () => { + it(`should reset all drop events and properties`, () => { + controller.dropping = angular.element(``); + spyOn(controller.dropping.classList, 'remove'); + + controller.undrop(); + + expect(controller.dropping).toBeNull(); + }); + }); + + describe('dragOver()', () => { + it(`should set the dragClientY property`, () => { + const event = new Event('dragover'); + event.clientY = 100; + + controller.dragOver(event); + + expect(controller.dragClientY).toEqual(100); + }); + }); + + describe('data() setter', () => { + it(`should set the items property nested into a root element`, () => { + const items = [{name: 'Item1'}, {name: 'Item2'}]; + controller.data = items; + + const rootItem = controller.items[0]; + + expect(rootItem.childs).toEqual(items); + }); + }); + + describe('fetch()', () => { + it(`should call the fetchFunc() method`, () => { + spyOn(controller, 'fetchFunc').and.returnValue( + new Promise(resolve => resolve()) + ); + controller.fetch().then(() => { + expect(controller.data).toBeDefined(); + }); + + expect(controller.fetchFunc).toHaveBeenCalledWith(); + }); + }); + + describe('setParent()', () => { + it(`should set the parent property recursively to each element of an item list`, () => { + spyOn(controller, 'setParent').and.callThrough(); + const items = [{name: 'Item1'}, {name: 'Item2', childs: [ + {name: 'Item3'} + ]}]; + const rootItem = {name: 'Nested tree', sons: items}; + controller.setParent(rootItem, items); + + expect(items[0].parent).toEqual(rootItem); + expect(items[1].parent).toEqual(rootItem); + expect(controller.setParent).toHaveBeenCalledWith(rootItem, items[1].childs); + }); + }); + + describe('onToggle()', () => { + it(`should call the fold() or unfold() methods`, () => { + spyOn(controller, 'fold'); + spyOn(controller, 'unfold'); + + const item = {name: 'My item'}; + + controller.onToggle(item); + item.active = true; + controller.onToggle(item); + + expect(controller.unfold).toHaveBeenCalledWith(item); + expect(controller.fold).toHaveBeenCalledWith(item); + }); + }); + + describe('fold()', () => { + it(`should remove the childs and set the active property to false`, () => { + const item = {name: 'My item', childs: [{name: 'Item 1'}], active: true}; + + controller.fold(item); + + expect(item.childs).toBeUndefined(); + expect(item.active).toBeFalsy(); + }); + }); + + describe('unfold()', () => { + it(`should unfold a parent item`, () => { + const expectedResponse = [{name: 'Item 1'}, {name: 'Item 2'}]; + spyOn(controller, 'fetchFunc').and.returnValue( + new Promise(resolve => resolve(expectedResponse)) + ); + spyOn(controller, 'setParent'); + spyOn(controller, 'sortFunc'); + const parent = {name: 'My item', sons: 1}; + const child = {name: 'Item 1'}; + child.parent = parent; + parent.childs = [child]; + + controller.unfold(parent).then(() => { + expect(controller.fetchFunc).toHaveBeenCalledWith({$item: parent}); + expect(controller.setParent).toHaveBeenCalledWith(parent, expectedResponse); + expect(controller.sortFunc).toHaveBeenCalledWith(jasmine.any(Object)); + expect(parent.active).toBeTruthy(); + }); + }); + }); + + describe('onRemove()', () => { + it(`should call the removeFunc() method`, () => { + spyOn(controller, 'removeFunc'); + const item = {name: 'My item'}; + controller.onRemove(item); + + expect(controller.removeFunc).toHaveBeenCalledWith({$item: item}); + }); + }); + + describe('remove()', () => { + it(`should remove a child element`, () => { + const parent = {name: 'My item', sons: 1}; + const child = {name: 'Item 1'}; + child.parent = parent; + parent.childs = [child]; + + controller.remove(child); + + expect(parent.childs).toEqual([]); + expect(parent.sons).toEqual(0); + }); + }); + + describe('onCreate()', () => { + it(`should call the createFunc() method`, () => { + spyOn(controller, 'createFunc'); + const parent = {name: 'My item'}; + controller.onCreate(parent); + + expect(controller.createFunc).toHaveBeenCalledWith({$parent: parent}); + }); + }); + + describe('create()', () => { + it(`should unfold an inactive parent and then create a child`, () => { + spyOn(controller, 'unfold'); + spyOn(controller, 'sortFunc'); + const parent = {name: 'My item', sons: 2, childs: [ + {name: 'Item 1'}, + {name: 'Item 2'} + ]}; + const child = {name: 'Item 3'}; + child.parent = parent; + parent.childs.push(child); + + controller.create(child); + + expect(parent.sons).toEqual(3); + expect(controller.unfold).toHaveBeenCalledWith(parent); + expect(controller.sortFunc).toHaveBeenCalledWith(jasmine.any(Object)); + expect(controller.sortFunc).toHaveBeenCalledTimes(2); + }); + + it(`should create a child on an active parent`, () => { + spyOn(controller, 'unfold'); + spyOn(controller, 'sortFunc'); + const parent = {name: 'My item', sons: 2, childs: [ + {name: 'Item 1'}, + {name: 'Item 2'} + ], active: true}; + const child = {name: 'Item 3'}; + child.parent = parent; + + controller.create(child); + + expect(parent.sons).toEqual(3); + expect(controller.unfold).not.toHaveBeenCalledWith(parent); + expect(controller.sortFunc).toHaveBeenCalledWith(jasmine.any(Object)); + expect(controller.sortFunc).toHaveBeenCalledTimes(2); + }); + }); + + describe('move()', () => { + it(`should move an item to anocher parent and then unfold the parent`, () => { + spyOn(controller, 'unfold').and.returnValue( + new Promise(resolve => resolve()) + ); + const newParent = {name: 'My item 2', sons: 0}; + const parent = {name: 'My item', sons: 3, childs: [ + {name: 'Item 1'}, + {name: 'Item 2'} + ]}; + const child = {name: 'Item 3'}; + child.parent = parent; + parent.childs.push(child); + + controller.move(child, newParent); + + expect(parent.sons).toEqual(2); + expect(controller.unfold).toHaveBeenCalledWith(newParent); + }); + + it(`should move an item to anocher parent`, () => { + spyOn(controller, 'unfold'); + spyOn(controller, 'create'); + const newParent = {name: 'My item 2', sons: 0, active: true}; + const parent = {name: 'My item', sons: 3, childs: [ + {name: 'Item 1'}, + {name: 'Item 2'} + ]}; + const child = {name: 'Item 3'}; + child.parent = parent; + parent.childs.push(child); + + controller.move(child, newParent); + + expect(parent.sons).toEqual(2); + expect(controller.unfold).not.toHaveBeenCalledWith(newParent); + }); + }); +}); diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 65467d349..35a0e56e2 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -50,6 +50,7 @@ + @@ -114,6 +115,7 @@ + From b2b76b05d81fd42a460ec9afd2aeafad40e5fd08 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 17 Oct 2019 13:27:50 +0200 Subject: [PATCH 12/17] css fixes + back unit tests --- front/core/components/treeview/index.spec.js | 2 +- modules/claim/front/action/index.html | 227 +++++++++--------- modules/claim/front/action/style.scss | 15 ++ modules/ticket/front/services/index.spec.js | 2 +- .../department/specs/createChild.spec.js | 18 ++ .../department/specs/moveChild.spec.js | 23 ++ .../department/specs/removeChild.spec.js | 21 ++ 7 files changed, 187 insertions(+), 121 deletions(-) create mode 100644 modules/worker/back/methods/department/specs/createChild.spec.js create mode 100644 modules/worker/back/methods/department/specs/moveChild.spec.js create mode 100644 modules/worker/back/methods/department/specs/removeChild.spec.js diff --git a/front/core/components/treeview/index.spec.js b/front/core/components/treeview/index.spec.js index 75c35fb25..12cdc16e7 100644 --- a/front/core/components/treeview/index.spec.js +++ b/front/core/components/treeview/index.spec.js @@ -72,7 +72,7 @@ describe('Component vnTreeview', () => { describe('fetch()', () => { it(`should call the fetchFunc() method`, () => { spyOn(controller, 'fetchFunc').and.returnValue( - new Promise(resolve => resolve()) + new Promise(resolve => resolve([{name: 'My item'}])) ); controller.fetch().then(() => { expect(controller.data).toBeDefined(); diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 35a0e56e2..d12399c55 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -1,123 +1,116 @@ - - - - - -
- - -
-
- - - - - - - - - - - - - - - - - - - Id - Ticket - Destination - Landed - Quantity - Description - Price - Disc. - Total - - - - - - - {{saleClaimed.sale.itemFk | zeroFill:6}} - - - - - {{::saleClaimed.sale.ticketFk}} + + + + + + + +
+ + + + + + + + + + +
+ + + + + + Id + Ticket + Destination + Landed + Quantity + Description + Price + Disc. + Total + + + + + + + {{::saleClaimed.sale.itemFk | zeroFill:6}} - - - - - - {{saleClaimed.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} - {{saleClaimed.sale.quantity}} - {{saleClaimed.sale.concept}} - {{saleClaimed.sale.price | currency: 'EUR':2}} - {{saleClaimed.sale.discount}} % - - {{saleClaimed.sale.quantity * saleClaimed.sale.price * - ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} - - - - - - - - - -
-
+ + + + {{::saleClaimed.sale.ticketFk}} + + + + + + + {{::saleClaimed.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} + {{::saleClaimed.sale.quantity}} + {{::saleClaimed.sale.concept}} + {{::saleClaimed.sale.price | currency: 'EUR':2}} + {{::saleClaimed.sale.discount}} % + + {{saleClaimed.sale.quantity * saleClaimed.sale.price * + ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} + + + + + + + + + + - + diff --git a/modules/claim/front/action/style.scss b/modules/claim/front/action/style.scss index 3d54485e7..0124b716b 100644 --- a/modules/claim/front/action/style.scss +++ b/modules/claim/front/action/style.scss @@ -1,4 +1,19 @@ vn-claim-action { + .header { + display: flex; + justify-content: space-between; + align-items: center; + align-content: center; + + vn-tool-bar { + flex: 1 + } + + vn-check { + flex: none; + } + } + vn-dialog[vn-id=addSales] { tpl-body { width: 950px; diff --git a/modules/ticket/front/services/index.spec.js b/modules/ticket/front/services/index.spec.js index 97ce890d9..cf416f84d 100644 --- a/modules/ticket/front/services/index.spec.js +++ b/modules/ticket/front/services/index.spec.js @@ -1,6 +1,6 @@ import './index.js'; -fdescribe('Ticket component vnTicketService', () => { +describe('Ticket component vnTicketService', () => { let controller; let $httpBackend; let $httpParamSerializer; diff --git a/modules/worker/back/methods/department/specs/createChild.spec.js b/modules/worker/back/methods/department/specs/createChild.spec.js new file mode 100644 index 000000000..305732f58 --- /dev/null +++ b/modules/worker/back/methods/department/specs/createChild.spec.js @@ -0,0 +1,18 @@ +const app = require('vn-loopback/server/server'); + +describe('department createChild()', () => { + let createdChild; + + afterAll(async done => { + await createdChild.destroy(); + done(); + }); + + it('should create a new child', async() => { + const parentId = null; + createdChild = await app.models.Department.createChild(parentId, 'My new department'); + + expect(createdChild.name).toEqual('My new department'); + expect(createdChild.parentFk).toBeNull(); + }); +}); diff --git a/modules/worker/back/methods/department/specs/moveChild.spec.js b/modules/worker/back/methods/department/specs/moveChild.spec.js new file mode 100644 index 000000000..3358ebf77 --- /dev/null +++ b/modules/worker/back/methods/department/specs/moveChild.spec.js @@ -0,0 +1,23 @@ +const app = require('vn-loopback/server/server'); + +describe('department moveChild()', () => { + let updatedChild; + + afterAll(async done => { + const child = await app.models.Department.findById(updatedChild.id); + await child.updateAttribute('parentFk', null); + done(); + }); + + it('should move a child department to a new parent', async() => { + const childId = 22; + const parentId = 1; + + const child = await app.models.Department.findById(childId); + + expect(child.parentFk).toBeNull(); + updatedChild = await app.models.Department.moveChild(childId, parentId); + + expect(updatedChild.parentFk).toEqual(1); + }); +}); diff --git a/modules/worker/back/methods/department/specs/removeChild.spec.js b/modules/worker/back/methods/department/specs/removeChild.spec.js new file mode 100644 index 000000000..1fe3d10ef --- /dev/null +++ b/modules/worker/back/methods/department/specs/removeChild.spec.js @@ -0,0 +1,21 @@ +const app = require('vn-loopback/server/server'); + +describe('department removeChild()', () => { + let removedChild; + + afterAll(async done => { + await app.models.Department.create(removedChild); + done(); + }); + + it('should remove a child department', async() => { + const childId = 1; + + removedChild = await app.models.Department.findById(childId); + const result = await app.models.Department.removeChild(childId); + const existsChild = await app.models.Department.findById(childId); + + expect(result.count).toEqual(1); + expect(existsChild).toBeNull(); + }); +}); From e1cea99cc09f093d693cc971fad95b417e7d8901 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 17 Oct 2019 14:01:23 +0200 Subject: [PATCH 13/17] insert timeControl from procedure --- .../back/methods/worker-time-control/addTime.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/addTime.js b/modules/worker/back/methods/worker-time-control/addTime.js index 5548654bc..516519359 100644 --- a/modules/worker/back/methods/worker-time-control/addTime.js +++ b/modules/worker/back/methods/worker-time-control/addTime.js @@ -32,14 +32,12 @@ module.exports = Self => { throw new UserError(`You don't have enough privileges`); const subordinate = await Worker.findById(data.workerFk); + const timed = new Date(data.timed); - return Self.create({ - userFk: subordinate.userFk, - timed: data.timed, - manual: 1 - }); + let offset = timed.getTimezoneOffset() * 60000; + timed.setTime(timed.getTime() - offset); - /* return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ - subordinate.userFk, null, data.timed, true]); */ + return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ + subordinate.userFk, null, timed, true]); }; }; From 6f691353a384cee36e7831494e6c9a68014126e4 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 17 Oct 2019 14:01:23 +0200 Subject: [PATCH 14/17] solved conflicts --- .../back/methods/worker-time-control/addTime.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/addTime.js b/modules/worker/back/methods/worker-time-control/addTime.js index cb639f9af..516519359 100644 --- a/modules/worker/back/methods/worker-time-control/addTime.js +++ b/modules/worker/back/methods/worker-time-control/addTime.js @@ -32,11 +32,12 @@ module.exports = Self => { throw new UserError(`You don't have enough privileges`); const subordinate = await Worker.findById(data.workerFk); + const timed = new Date(data.timed); - return Self.create({ - userFk: subordinate.userFk, - timed: data.timed, - manual: 1 - }); + let offset = timed.getTimezoneOffset() * 60000; + timed.setTime(timed.getTime() - offset); + + return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ + subordinate.userFk, null, timed, true]); }; }; From 43a2c2e939b7dcf2fe4b2378b6566fd818e58ee1 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 17 Oct 2019 14:01:23 +0200 Subject: [PATCH 15/17] insert timeControl from procedure --- .../back/methods/worker-time-control/addTime.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/addTime.js b/modules/worker/back/methods/worker-time-control/addTime.js index 5548654bc..516519359 100644 --- a/modules/worker/back/methods/worker-time-control/addTime.js +++ b/modules/worker/back/methods/worker-time-control/addTime.js @@ -32,14 +32,12 @@ module.exports = Self => { throw new UserError(`You don't have enough privileges`); const subordinate = await Worker.findById(data.workerFk); + const timed = new Date(data.timed); - return Self.create({ - userFk: subordinate.userFk, - timed: data.timed, - manual: 1 - }); + let offset = timed.getTimezoneOffset() * 60000; + timed.setTime(timed.getTime() - offset); - /* return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ - subordinate.userFk, null, data.timed, true]); */ + return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ + subordinate.userFk, null, timed, true]); }; }; From bdbadaf61afed8cea94f7ad5489b080e34112620 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 17 Oct 2019 14:30:52 +0200 Subject: [PATCH 16/17] #1819 fixtures --- db/dump/fixtures.sql | 68 +++++++++---------- .../03-worker-module/02_time_control.spec.js | 2 +- .../06_basic_data_steps.spec.js | 1 + .../back/methods/route/specs/filter.spec.js | 2 +- .../methods/route/specs/getTickets.spec.js | 2 +- .../methods/route/specs/guessPriority.spec.js | 24 +++---- .../back/methods/route/specs/summary.spec.js | 4 +- .../methods/route/specs/updateVolume.spec.js | 13 ++-- 8 files changed, 58 insertions(+), 58 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 2624f1768..3aec7d82c 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -351,16 +351,6 @@ INSERT INTO `vn`.`creditInsurance`(`id`, `creditClassification`, `credit`, `crea (2, 2, 6000, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL), (3, 3, 10000, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL); -INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`) - VALUES - (1, '1899-12-30 12:15:00', 56, CURDATE(), 1, 7, 'first route', 2.7, 10, CURDATE(), CURDATE()), - (2, '1899-12-30 13:20:00', 56, CURDATE(), 1, 7, 'second route', 0.9, 20, CURDATE(), CURDATE()), - (3, '1899-12-30 14:30:00', 56, CURDATE(), 2, 7, 'third route', 1.1, 30, CURDATE(), CURDATE()), - (4, '1899-12-30 15:45:00', 56, CURDATE(), 3, 7, 'fourth route', 0.1, 40, CURDATE(), CURDATE()), - (5, '1899-12-30 16:00:00', 56, CURDATE(), 4, 8, 'fifth route', NULL, 50, CURDATE(), CURDATE()), - (6, NULL, 57, CURDATE(), 5, 8, 'sixth route', NULL, 60, CURDATE(), CURDATE()), - (7, NULL, 57, CURDATE(), 6, NULL, 'seventh route', NULL, 70, CURDATE(), CURDATE()); - INSERT INTO `vn2008`.`empresa_grupo`(`empresa_grupo_id`, `grupo`) VALUES (1, 'Wayne Industries'); @@ -456,32 +446,42 @@ INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `warehouseFk`, `agencyModeFk`, `t (12, 'Zone entanglement', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 4, 4, 0, 0, 0), (13, 'Zone quantum break', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), 5, 5, 0, 0, 0); +INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`) + VALUES + (1, '1899-12-30 12:15:00', 56, CURDATE(), 1, 1, 'first route', 1.8, 10, CURDATE(), CURDATE(), 1), + (2, '1899-12-30 13:20:00', 56, CURDATE(), 1, 2, 'second route', 0.2, 20, CURDATE(), CURDATE(), 9), + (3, '1899-12-30 14:30:00', 56, CURDATE(), 2, 3, 'third route', 0.5, 30, CURDATE(), CURDATE(), 10), + (4, '1899-12-30 15:45:00', 56, CURDATE(), 3, 4, 'fourth route', 0, 40, CURDATE(), CURDATE(), 12), + (5, '1899-12-30 16:00:00', 56, CURDATE(), 4, 5, 'fifth route', 0.1, 50, CURDATE(), CURDATE(), 13), + (6, NULL, 57, CURDATE(), 5, 7, 'sixth route', 1.7, 60, CURDATE(), CURDATE(), 3), + (7, NULL, 57, CURDATE(), 6, 8, 'seventh route', 0, 70, CURDATE(), CURDATE(), 5); + INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `created`) VALUES - (1 , 3, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Bat cave', 121, 'T1111111', 0, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (2 , 1, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T1111111', 0, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (3 , 1, 7, 1, 1, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T2222222', 0, 3, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), - (4 , 3, 2, 1, 1, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T3333333', 0, 9, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), - (5 , 3, 3, 3, 1, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T4444444', 0, 10, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)), - (6 , 1, 3, 3, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Mountain Drive Gotham', 1, 'A1111111', 0, 10, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (7 , NULL, 7, 1, 2, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Mountain Drive Gotham', 1, NULL, 0, 3, CURDATE()), - (8 , NULL, 7, 1, 2, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Bat cave', 121, NULL, 0, 3, CURDATE()), - (9 , NULL, 7, 1, 2, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Stark tower', 124, NULL, 0, 3, CURDATE()), - (10, 1, 1, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'Ingram Street', 2, NULL, 0, 11, CURDATE()), - (11, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'NY roofs', 122, NULL, 0, 3, CURDATE()), - (12, 1, 1, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 1, CURDATE()), - (13, 1, 7, 1, 2, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 1, CURDATE()), - (14, 1, 2, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Malibu Point', 4, NULL, 0, 9, CURDATE()), - (15, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, 3, CURDATE()), - (16, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), - (17, 1, 7, 2, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), - (18, 1, 4, 4, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 108, 'Cerebro', 128, NULL, 0, 12, CURDATE()), - (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, 13, CURDATE()), - (20, 1, 5, 5, 3, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (21, NULL, 5, 5, NULL, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Holland', 102, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (22, NULL, 5, 5, NULL, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Japan', 103, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (23, NULL, 10, 1, NULL, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'address 21', 121, NULL, 0, 8, CURDATE()), - (24 ,NULL, 10, 1, NULL, CURDATE(), CURDATE(), 101, 'Bruce Wayne', 1, NULL, 0, 8, CURDATE()); + (1 , 3, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Bat cave', 121, 'T1111111', 0, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (2 , 1, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T1111111', 0, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (3 , 1, 7, 1, 6, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T2222222', 0, 3, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), + (4 , 3, 2, 1, 2, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T3333333', 0, 9, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), + (5 , 3, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T4444444', 0, 10, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)), + (6 , 1, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Mountain Drive Gotham', 1, 'A1111111', 0, 10, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (7 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Mountain Drive Gotham', 1, NULL, 0, 3, CURDATE()), + (8 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Bat cave', 121, NULL, 0, 3, CURDATE()), + (9 , NULL, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Stark tower', 124, NULL, 0, 3, CURDATE()), + (10, 1, 1, 5, 1, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'Ingram Street', 2, NULL, 0, 1, CURDATE()), + (11, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'NY roofs', 122, NULL, 0, 3, CURDATE()), + (12, 1, 1, 1, 1, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 1, CURDATE()), + (13, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 3, CURDATE()), + (14, 1, 2, 1, NULL, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Malibu Point', 4, NULL, 0, 9, CURDATE()), + (15, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, 3, CURDATE()), + (16, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), + (17, 1, 7, 2, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()), + (18, 1, 4, 4, 4, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 108, 'Cerebro', 128, NULL, 0, 12, CURDATE()), + (19, 1, 5, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 1, 13, CURDATE()), + (20, 1, 5, 5, 3, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Thailand', 129, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (21, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Holland', 102, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (22, NULL, 5, 5, 5, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 109, 'Somewhere in Japan', 103, NULL, 0, 13, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (23, NULL, 8, 1, 7, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'address 21', 121, NULL, 0, 5, CURDATE()), + (24 ,NULL, 8, 1, 7, CURDATE(), CURDATE(), 101, 'Bruce Wayne', 1, NULL, 0, 5, CURDATE()); INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES diff --git a/e2e/paths/03-worker-module/02_time_control.spec.js b/e2e/paths/03-worker-module/02_time_control.spec.js index 42be3e9e0..be48b13dd 100644 --- a/e2e/paths/03-worker-module/02_time_control.spec.js +++ b/e2e/paths/03-worker-module/02_time_control.spec.js @@ -358,7 +358,7 @@ describe('Worker time control path', () => { it(`should check Hank Pym doesn't have hours set on the next months first week`, async() => { const wholeWeekHours = await nightmare .waitToClick(selectors.workerTimeControl.nextMonthButton) - .waitToClick(selectors.workerTimeControl.nextMonthButton) + .waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '00:00 Hours') .waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText'); expect(wholeWeekHours).toEqual('00:00 Hours'); diff --git a/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js b/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js index 0f02c6af7..3dcac0765 100644 --- a/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket-module/06_basic_data_steps.spec.js @@ -30,6 +30,7 @@ describe('Ticket Edit basic data path', () => { it(`should confirm the zone autocomplete is enabled for the role productionBoss`, async() => { const disabled = await nightmare + .waitForSpinnerLoad() .wait(selectors.ticketBasicData.zoneAutocomplete) .evaluate(selector => { return document.querySelector(selector).disabled; diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index ba32c956c..a4742c128 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -117,6 +117,6 @@ describe('Route filter()', () => { let result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(4); + expect(result.length).toEqual(1); }); }); diff --git a/modules/route/back/methods/route/specs/getTickets.spec.js b/modules/route/back/methods/route/specs/getTickets.spec.js index 3888156b6..15028309f 100644 --- a/modules/route/back/methods/route/specs/getTickets.spec.js +++ b/modules/route/back/methods/route/specs/getTickets.spec.js @@ -4,6 +4,6 @@ describe('route getTickets()', () => { it('should return the tickets for a given route', async() => { let result = await app.models.Route.getTickets(2); - expect(result.length).toEqual(4); + expect(result.length).toEqual(1); }); }); diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js index cc536787a..075ea05c8 100644 --- a/modules/route/back/methods/route/specs/guessPriority.spec.js +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('route guessPriority()', () => { - const targetRouteId = 2; + const targetRouteId = 7; let routeTicketsToRestore; afterAll(async done => { @@ -17,25 +17,23 @@ describe('route guessPriority()', () => { it('should confirm the tickets in the target route have no priority yet', async() => { routeTicketsToRestore = await app.models.Ticket.find({where: {routeFk: targetRouteId}}); - expect(routeTicketsToRestore.length).toEqual(4); + expect(routeTicketsToRestore.length).toEqual(2); + + expect(routeTicketsToRestore[0].id).toEqual(23); expect(routeTicketsToRestore[0].priority).toBeNull(); - expect(routeTicketsToRestore[0].id).toEqual(7); + expect(routeTicketsToRestore[1].id).toEqual(24); expect(routeTicketsToRestore[1].priority).toBeNull(); - expect(routeTicketsToRestore[1].id).toEqual(8); - expect(routeTicketsToRestore[2].priority).toBeNull(); - expect(routeTicketsToRestore[2].id).toEqual(9); }); it('should call guessPriority() and then check the tickets in the target route now have their priorities defined', async() => { await app.models.Route.guessPriority(targetRouteId); let routeTickets = await app.models.Ticket.find({where: {routeFk: targetRouteId}, fields: ['id', 'priority']}); - expect(routeTickets.length).toEqual(4); - expect(routeTickets[0].priority).toEqual(1); - expect(routeTickets[0].id).toEqual(7); - expect(routeTickets[1].priority).toEqual(3); - expect(routeTickets[1].id).toEqual(8); - expect(routeTickets[2].priority).toEqual(2); - expect(routeTickets[2].id).toEqual(9); + expect(routeTickets.length).toEqual(2); + + expect(routeTickets[0].id).toEqual(23); + expect(routeTickets[0].priority).toEqual(3); + expect(routeTickets[1].id).toEqual(24); + expect(routeTickets[1].priority).toEqual(1); }); }); diff --git a/modules/route/back/methods/route/specs/summary.spec.js b/modules/route/back/methods/route/specs/summary.spec.js index 5b31ff19f..ba976ae94 100644 --- a/modules/route/back/methods/route/specs/summary.spec.js +++ b/modules/route/back/methods/route/specs/summary.spec.js @@ -11,7 +11,7 @@ describe('route summary()', () => { const result = await app.models.Route.summary(1); const agency = result.route.agencyMode(); - expect(agency.name).toEqual('Silla247'); + expect(agency.name).toEqual('inhouse pickup'); }); it(`should return a summary object containing it's vehicle`, async() => { @@ -31,6 +31,6 @@ describe('route summary()', () => { it(`should return a summary object containing data from the tickets`, async() => { const result = await app.models.Route.summary(2); - expect(result.tickets.length).toEqual(4); + expect(result.tickets.length).toEqual(1); }); }); diff --git a/modules/route/back/methods/route/specs/updateVolume.spec.js b/modules/route/back/methods/route/specs/updateVolume.spec.js index 75ee3c139..a1ff67acc 100644 --- a/modules/route/back/methods/route/specs/updateVolume.spec.js +++ b/modules/route/back/methods/route/specs/updateVolume.spec.js @@ -10,8 +10,8 @@ describe('route updateVolume()', () => { afterAll(async done => { - await originalRoute.updateAttributes({m3: 2.7}); - await ticketToRestore.updateAttributes({routeFk: 2}); + await originalRoute.updateAttributes({m3: 1.8}); + await ticketToRestore.updateAttributes({routeFk: null}); await app.models.RouteLog.destroyById(logIdToDestroy); done(); }); @@ -19,12 +19,12 @@ describe('route updateVolume()', () => { it('should confirm the original volume of the route is the expected', async() => { originalRoute = await app.models.Route.findById(routeId); - expect(originalRoute.m3).toEqual(2.7); + expect(originalRoute.m3).toEqual(1.8); }); it('should confirm the route volume is updated when a ticket is added', async() => { - ticketToRestore = await app.models.Ticket.findById(8); - let updatedTicket = await app.models.Ticket.findById(8); + ticketToRestore = await app.models.Ticket.findById(14); + let updatedTicket = await app.models.Ticket.findById(14); await updatedTicket.updateAttributes({routeFk: routeId}); await app.models.Route.updateVolume(ctx, routeId); @@ -36,8 +36,9 @@ describe('route updateVolume()', () => { it('should confirm the change is logged', async() => { let logs = await app.models.RouteLog.find({fields: ['id', 'newInstance']}); + let m3Log = logs.filter(log => { - return log.newInstance.m3 === 3.1; + return log.newInstance.m3 === 1.9; }); logIdToDestroy = m3Log[0].id; From 18b0ae034c181710e771e77af248c92253efaca3 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 18 Oct 2019 09:53:30 +0200 Subject: [PATCH 17/17] #1815 - show summary correct photos on claim index --- e2e/helpers/selectors.js | 6 +- modules/claim/front/detail/index.html | 152 +++++++-------- modules/claim/front/summary/index.html | 222 +++++++++++----------- modules/claim/front/summary/index.js | 20 ++ modules/claim/front/summary/index.spec.js | 2 + modules/worker/front/log/index.html | 2 +- 6 files changed, 215 insertions(+), 189 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index bc68f96e4..1abe93ace 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -530,13 +530,13 @@ export default { header: 'vn-claim-summary > vn-card > div > h5', state: 'vn-claim-summary vn-label-value[label="State"] > section > span', observation: 'vn-claim-summary vn-textarea[ng-model="$ctrl.summary.claim.observation"] textarea', - firstSaleItemId: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(4) > vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(1) > span', + firstSaleItemId: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(4) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(1) > span', firstSaleDescriptorImage: '.vn-popover.shown vn-item-descriptor img', itemDescriptorPopover: '.vn-popover.shown vn-item-descriptor', itemDescriptorPopoverItemDiaryButton: '.vn-popover.shown vn-item-descriptor a[href="#!/item/2/diary"]', - firstDevelopmentWorker: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(5) > vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span', + firstDevelopmentWorker: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(5) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span', firstDevelopmentWorkerGoToClientButton: '.vn-popover.shown vn-worker-descriptor div.quicklinks > a[href="#!/client/21/summary"]', - firstActionTicketId: 'vn-claim-summary > vn-card > div > vn-horizontal > vn-auto:nth-child(6) > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', + firstActionTicketId: 'vn-claim-summary > vn-card > div > vn-horizontal > vn-auto:nth-child(6) vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', firstActionTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor' }, claimBasicData: { diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html index 90e7b5914..4a5767194 100644 --- a/modules/claim/front/detail/index.html +++ b/modules/claim/front/detail/index.html @@ -1,84 +1,84 @@ - - - - - -
- - - - -
-
- - - - Landed - Quantity - Claimed - Description - Price - Disc. - Total - - - - - - {{::saleClaimed.sale.ticket.landed | dateTime:'dd/MM/yyyy'}} - {{::saleClaimed.sale.quantity}} - - - - - - - {{::saleClaimed.sale.concept}} - - - {{::saleClaimed.sale.price | currency: 'EUR':2}} - - - {{::saleClaimed.sale.discount}} % - - - - {{::$ctrl.getSaleTotal(saleClaimed.sale) | currency: 'EUR':2}} - - - - - - - - -
-
- - - -
+ + + + + + + + + + + + + + Landed + Quantity + Claimed + Description + Price + Disc. + Total + + + + + + {{::saleClaimed.sale.ticket.landed | dateTime:'dd/MM/yyyy'}} + {{::saleClaimed.sale.quantity}} + + + + + + + {{::saleClaimed.sale.concept}} + + + {{::saleClaimed.sale.price | currency: 'EUR':2}} + + + {{::saleClaimed.sale.discount}} % + + + + {{::$ctrl.getSaleTotal(saleClaimed.sale) | currency: 'EUR':2}} + + + + + + + + + + + + + + + diff --git a/modules/claim/front/summary/index.html b/modules/claim/front/summary/index.html index 314d71bc9..8d837dd73 100644 --- a/modules/claim/front/summary/index.html +++ b/modules/claim/front/summary/index.html @@ -1,11 +1,9 @@ - + data="photos"> -
{{$ctrl.summary.claim.id}} - {{$ctrl.summary.claim.client.name}}
+
{{::$ctrl.summary.claim.id}} - {{::$ctrl.summary.claim.client.name}}

Detail

- - - - Item - Landed - Quantity - Claimed - Description - Price - Disc. - Total - - - - - - - {{saleClaimed.sale.itemFk | zeroFill:6}} - - - {{saleClaimed.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} - {{saleClaimed.sale.quantity}} - {{saleClaimed.quantity}} - {{saleClaimed.sale.concept}} - {{saleClaimed.sale.price | currency: 'EUR':2}} - {{saleClaimed.sale.discount}} % - - {{saleClaimed.sale.quantity * saleClaimed.sale.price * - ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} - - - - + + + + + Item + Landed + Quantity + Claimed + Description + Price + Disc. + Total + + + + + + + {{::saleClaimed.sale.itemFk | zeroFill:6}} + + + {{::saleClaimed.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} + {{::saleClaimed.sale.quantity}} + {{::saleClaimed.quantity}} + {{::saleClaimed.sale.concept}} + {{::saleClaimed.sale.price | currency: 'EUR':2}} + {{::saleClaimed.sale.discount}} % + + {{saleClaimed.sale.quantity * saleClaimed.sale.price * + ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} + + + + +

Photos

@@ -92,78 +92,82 @@

Development

- - - - Reason - Result - Responsible - Worker - Redelivery - - - - - {{development.claimReason.description}} - {{development.claimResult.description}} - {{development.claimResponsible.description}} - - - {{::development.worker.user.nickname}} - - - {{development.claimRedelivery.description}} - - - + + + + + Reason + Result + Responsible + Worker + Redelivery + + + + + {{::development.claimReason.description}} + {{::development.claimResult.description}} + {{::development.claimResponsible.description}} + + + {{::development.worker.user.nickname}} + + + {{::development.claimRedelivery.description}} + + + +

Action

- - - - Item - Ticket - Destination - Landed - Quantity - Description - Price - Disc. - Total - - - - - - - {{action.sale.itemFk | zeroFill:6}} - - - - - {{action.sale.ticket.id | zeroFill:6}} - - - {{action.claimBeggining.description}} - {{action.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} - {{action.sale.quantity}} - {{action.sale.concept}} - {{action.sale.price}} - {{action.sale.discount}} % - - {{action.sale.quantity * action.sale.price * - ((100 - action.sale.discount) / 100) | currency: 'EUR':2}} - - - - + + + + + Item + Ticket + Destination + Landed + Quantity + Description + Price + Disc. + Total + + + + + + + {{::action.sale.itemFk | zeroFill:6}} + + + + + {{::action.sale.ticket.id | zeroFill:6}} + + + {{::action.claimBeggining.description}} + {{::action.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} + {{::action.sale.quantity}} + {{::action.sale.concept}} + {{::action.sale.price}} + {{::action.sale.discount}} % + + {{action.sale.quantity * action.sale.price * + ((100 - action.sale.discount) / 100) | currency: 'EUR':2}} + + + + +
diff --git a/modules/claim/front/summary/index.js b/modules/claim/front/summary/index.js index 257be55e0..7d9e3716f 100644 --- a/modules/claim/front/summary/index.js +++ b/modules/claim/front/summary/index.js @@ -9,6 +9,26 @@ class Controller { this.accessToken = vnToken.token; } + get claim() { + return this._claim; + } + + + set claim(value) { + this._claim = value; + + // Get DMS on summary load + /* if (value) + this.$.$applyAsync(() => this.loadDms()); */ + } + + loadDms() { + this.$.model.where = { + claimFk: this.claim.id + }; + this.$.model.refresh(); + } + getSummary() { this.$http.get(`/claim/api/Claims/${this.claim.id}/getSummary`).then(response => { this.summary = response.data; diff --git a/modules/claim/front/summary/index.spec.js b/modules/claim/front/summary/index.spec.js index c56b91251..87b3caac0 100644 --- a/modules/claim/front/summary/index.spec.js +++ b/modules/claim/front/summary/index.spec.js @@ -1,4 +1,5 @@ import './index.js'; +import crudModel from 'core/mocks/crud-model'; describe('Claim', () => { describe('Component summary', () => { @@ -13,6 +14,7 @@ describe('Claim', () => { $httpBackend = _$httpBackend_; controller = $componentController('vnClaimSummary'); controller.claim = {id: 1}; + controller.$.model = crudModel; })); describe('getSummary()', () => { diff --git a/modules/worker/front/log/index.html b/modules/worker/front/log/index.html index 4f170ac35..91166f045 100644 --- a/modules/worker/front/log/index.html +++ b/modules/worker/front/log/index.html @@ -88,7 +88,7 @@ ng-if="!log.newProperties" id="description">
- {{log.description}} + {{::log.description}}