From 66685e7541c12d02a0786e003d4c950913c43953 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 4 May 2022 10:35:31 +0200 Subject: [PATCH 1/5] feat(ticket.expedition): add popover --- .../10451-april/00-aclExpeditionState.sql | 2 + db/dump/fixtures.sql | 39 +++++++---- .../back/methods/expedition-state/filter.js | 41 ++++++++++++ .../expedition-state/specs/filter.spec.js | 21 ++++++ .../ticket/back/methods/expedition/filter.js | 7 +- modules/ticket/back/model-config.json | 3 + .../ticket/back/models/expedition-state.js | 3 + .../ticket/back/models/expedition-state.json | 28 ++++++++ modules/ticket/front/expedition/index.html | 66 ++++++++++++++----- modules/ticket/front/expedition/index.js | 5 ++ modules/ticket/front/expedition/index.spec.js | 22 ++++++- modules/ticket/front/expedition/locale/es.yml | 1 + 12 files changed, 207 insertions(+), 31 deletions(-) create mode 100644 db/changes/10451-april/00-aclExpeditionState.sql create mode 100644 modules/ticket/back/methods/expedition-state/filter.js create mode 100644 modules/ticket/back/methods/expedition-state/specs/filter.spec.js create mode 100644 modules/ticket/back/models/expedition-state.js create mode 100644 modules/ticket/back/models/expedition-state.json create mode 100644 modules/ticket/front/expedition/locale/es.yml diff --git a/db/changes/10451-april/00-aclExpeditionState.sql b/db/changes/10451-april/00-aclExpeditionState.sql new file mode 100644 index 000000000..d26117bbf --- /dev/null +++ b/db/changes/10451-april/00-aclExpeditionState.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) +VALUES('ExpeditionState', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 0849e6708..076c6f566 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -883,18 +883,35 @@ INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPack ('cc', 1640038.00, 56.00, 220.00, 128.00, 1, CURDATE(), 15, 90.00), ('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, CURDATE(), 16, 0.00); -INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`) +INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) VALUES - (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94), - (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94), - (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94), - (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94), - (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94), - (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94), - (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94), - (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94), - (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94), - (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94); + (1, 'En reparto', 'ON DELIVERY'), + (2, 'Entregada', 'DELIVERED'), + (3, 'Perdida', 'LOST'); + + +INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`) + VALUES + (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94, 1), + (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94, 1), + (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94, 2), + (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94, 2), + (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 3), + (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94, 3), + (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94, NULL), + (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94, 1), + (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 2), + (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94, 3); + + +INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) + VALUES + (1, CURDATE(), 1, 1, 1), + (2, CURDATE(), 2, 1, 1), + (3, CURDATE(), 3, 1, 1), + (4, CURDATE(), 3, 2, 1106), + (5, CURDATE(), 5, 1, 1106), + (6, CURDATE(), 5, 3, 1106); INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) VALUES diff --git a/modules/ticket/back/methods/expedition-state/filter.js b/modules/ticket/back/methods/expedition-state/filter.js new file mode 100644 index 000000000..43c293d7d --- /dev/null +++ b/modules/ticket/back/methods/expedition-state/filter.js @@ -0,0 +1,41 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; + +module.exports = Self => { + Self.remoteMethod('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'}, + }, + ], + returns: { + type: ['object'], + root: true, + }, + http: { + path: `/filter`, + verb: 'GET', + }, + }); + + Self.filter = async(filter, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const stmt = new ParameterizedSQL( + `SELECT es.created, u.name, u.id workerFk, est.description + FROM vn.expeditionState es + JOIN vn.expeditionStateType est ON est.id = es.typeFk + JOIN account.user u ON u.id = es.userFk + `); + stmt.merge(Self.buildSuffix(filter, 'es')); + + return Self.rawStmt(stmt, myOptions); + }; +}; diff --git a/modules/ticket/back/methods/expedition-state/specs/filter.spec.js b/modules/ticket/back/methods/expedition-state/specs/filter.spec.js new file mode 100644 index 000000000..f144606eb --- /dev/null +++ b/modules/ticket/back/methods/expedition-state/specs/filter.spec.js @@ -0,0 +1,21 @@ +const models = require('vn-loopback/server/server').models; + +describe('expeditionState filter()', () => { + it('should return the expedition states matching the filter', async() => { + const tx = await models.ExpeditionState.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const filter = {where: {expeditionFk: 5}}; + const response = await models.ExpeditionState.filter(filter, options); + + expect(response.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/expedition/filter.js b/modules/ticket/back/methods/expedition/filter.js index 5eb7510b7..508e55617 100644 --- a/modules/ticket/back/methods/expedition/filter.js +++ b/modules/ticket/back/methods/expedition/filter.js @@ -47,9 +47,10 @@ module.exports = Self => { e.packagingFk, es.workerFk expeditionScanWorkerFk, su.name scannerUserName, - es.scanned - FROM - vn.expedition e + es.scanned, + est.description + FROM vn.expedition e + LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk LEFT JOIN vn.item i2 ON i2.id = e.itemFk INNER JOIN vn.item i1 ON i1.id = e.isBox LEFT JOIN vn.packaging p ON p.id = e.packagingFk diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 5d5f08694..41885ee33 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -14,6 +14,9 @@ "Expedition": { "dataSource": "vn" }, + "ExpeditionState": { + "dataSource": "vn" + }, "Packaging": { "dataSource": "vn" }, diff --git a/modules/ticket/back/models/expedition-state.js b/modules/ticket/back/models/expedition-state.js new file mode 100644 index 000000000..af76af718 --- /dev/null +++ b/modules/ticket/back/models/expedition-state.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/expedition-state/filter')(Self); +}; diff --git a/modules/ticket/back/models/expedition-state.json b/modules/ticket/back/models/expedition-state.json new file mode 100644 index 000000000..262eb2e38 --- /dev/null +++ b/modules/ticket/back/models/expedition-state.json @@ -0,0 +1,28 @@ +{ + "name": "ExpeditionState", + "base": "VnModel", + "options": { + "mysql": { + "table": "expeditionState" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "created": { + "type": "date" + }, + "expeditionFk": { + "type": "number" + }, + "typeFk": { + "type": "number" + }, + "userFk": { + "type": "number" + } + } +} diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index bdbb2c3e8..946e923ba 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -19,10 +19,9 @@ Package type Counter externalId - Packager Created - Palletizer - Scanned + State + @@ -33,7 +32,7 @@ vn-tooltip="Delete expedition"> - {{expedition.id | zeroFill:6}} + {{expedition.id | zeroFill:6}} {{::expedition.freightItemName}} {{::expedition.counter}} {{::expedition.externalId}} - - - {{::expedition.userName | dashIfEmpty}} - - {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} + {{::expedition.description}} - - {{::expedition.scannerUserName | dashIfEmpty}} - + + - {{::expedition.scanned | date:'dd/MM/yyyy HH:mm'}} @@ -77,4 +71,44 @@ on-accept="$ctrl.onDialogAccept($data)" question="Delete expedition" message="Are you sure you want to delete this expedition?"> - \ No newline at end of file + + + + + + + + + + + State + Worker + Created + + + + + {{::expeditionState.description}} + + + {{::expeditionState.name || 'System' | translate}} + + + {{::expeditionState.created | date:'dd/MM/yyyy HH:mm'}} + + + + + + + + \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 0c395e6ce..120d89bb2 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -6,6 +6,11 @@ class Controller extends Section { return this.$http.delete(`Expeditions/${id}`) .then(() => this.$.model.refresh()); } + + showLog(expedition) { + this.expedition = expedition; + this.$.statusLog.show(); + } } ngModule.vnComponent('vnTicketExpedition', { diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 425539aef..586ef2109 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -5,10 +5,12 @@ describe('Ticket', () => { let controller; let $scope; let $httpBackend; + let $window; beforeEach(ngModule('ticket')); - beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { + beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$window_) => { + $window = _$window_; $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $scope.model = { @@ -30,5 +32,23 @@ describe('Ticket', () => { expect($scope.model.refresh).toHaveBeenCalledWith(); }); }); + + describe('showLog()', () => { + it('should show the popover status log', () => { + controller.$.statusLog = {show: () => {}}; + jest.spyOn(controller.$.statusLog, 'show'); + + const expedition = {id: 1}; + + const event = new MouseEvent('click', { + view: $window, + bubbles: true, + cancelable: true + }); + controller.showLog(event, expedition); + + expect(controller.$.statusLog.show).toHaveBeenCalledWith(); + }); + }); }); }); diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml new file mode 100644 index 000000000..d23cf25af --- /dev/null +++ b/modules/ticket/front/expedition/locale/es.yml @@ -0,0 +1 @@ +Status log: Hitorial de estados \ No newline at end of file From 38f5541ef49f112c0874b818c24da771908e97ac Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 4 May 2022 11:27:03 +0200 Subject: [PATCH 2/5] execute jenkins test --- modules/ticket/front/expedition/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 946e923ba..e5b84509f 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -72,7 +72,7 @@ question="Delete expedition" message="Are you sure you want to delete this expedition?"> - + Date: Wed, 4 May 2022 12:00:39 +0200 Subject: [PATCH 3/5] comment frontTest --- modules/ticket/front/expedition/index.spec.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 586ef2109..bb2604132 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -33,22 +33,22 @@ describe('Ticket', () => { }); }); - describe('showLog()', () => { - it('should show the popover status log', () => { - controller.$.statusLog = {show: () => {}}; - jest.spyOn(controller.$.statusLog, 'show'); + // describe('showLog()', () => { + // it('should show the popover status log', () => { + // controller.$.statusLog = {show: () => {}}; + // jest.spyOn(controller.$.statusLog, 'show'); - const expedition = {id: 1}; + // const expedition = {id: 1}; - const event = new MouseEvent('click', { - view: $window, - bubbles: true, - cancelable: true - }); - controller.showLog(event, expedition); + // const event = new MouseEvent('click', { + // view: $window, + // bubbles: true, + // cancelable: true + // }); + // controller.showLog(event, expedition); - expect(controller.$.statusLog.show).toHaveBeenCalledWith(); - }); - }); + // expect(controller.$.statusLog.show).toHaveBeenCalledWith(); + // }); + // }); }); }); From 93e3ea103acc002b37cb933e768086cc9ad55a4f Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 4 May 2022 12:05:46 +0200 Subject: [PATCH 4/5] added frontTest --- modules/ticket/front/expedition/index.spec.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index bb2604132..586ef2109 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -33,22 +33,22 @@ describe('Ticket', () => { }); }); - // describe('showLog()', () => { - // it('should show the popover status log', () => { - // controller.$.statusLog = {show: () => {}}; - // jest.spyOn(controller.$.statusLog, 'show'); + describe('showLog()', () => { + it('should show the popover status log', () => { + controller.$.statusLog = {show: () => {}}; + jest.spyOn(controller.$.statusLog, 'show'); - // const expedition = {id: 1}; + const expedition = {id: 1}; - // const event = new MouseEvent('click', { - // view: $window, - // bubbles: true, - // cancelable: true - // }); - // controller.showLog(event, expedition); + const event = new MouseEvent('click', { + view: $window, + bubbles: true, + cancelable: true + }); + controller.showLog(event, expedition); - // expect(controller.$.statusLog.show).toHaveBeenCalledWith(); - // }); - // }); + expect(controller.$.statusLog.show).toHaveBeenCalledWith(); + }); + }); }); }); From 644139324978d74a39249e9dd635fdf87c550e22 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 12 May 2022 08:47:17 +0200 Subject: [PATCH 5/5] refactor: pull request changes --- modules/ticket/back/methods/expedition-state/filter.js | 2 +- modules/ticket/back/methods/expedition/filter.js | 2 +- modules/ticket/front/expedition/index.html | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/expedition-state/filter.js b/modules/ticket/back/methods/expedition-state/filter.js index 43c293d7d..1483780f7 100644 --- a/modules/ticket/back/methods/expedition-state/filter.js +++ b/modules/ticket/back/methods/expedition-state/filter.js @@ -29,7 +29,7 @@ module.exports = Self => { Object.assign(myOptions, options); const stmt = new ParameterizedSQL( - `SELECT es.created, u.name, u.id workerFk, est.description + `SELECT es.created, u.name, u.id workerFk, est.description state FROM vn.expeditionState es JOIN vn.expeditionStateType est ON est.id = es.typeFk JOIN account.user u ON u.id = es.userFk diff --git a/modules/ticket/back/methods/expedition/filter.js b/modules/ticket/back/methods/expedition/filter.js index 508e55617..538e19938 100644 --- a/modules/ticket/back/methods/expedition/filter.js +++ b/modules/ticket/back/methods/expedition/filter.js @@ -48,7 +48,7 @@ module.exports = Self => { es.workerFk expeditionScanWorkerFk, su.name scannerUserName, es.scanned, - est.description + est.description state FROM vn.expedition e LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk LEFT JOIN vn.item i2 ON i2.id = e.itemFk diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index e5b84509f..a41d368f6 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -20,7 +20,7 @@ Counter externalId Created - State + State @@ -45,7 +45,7 @@ {{::expedition.counter}} {{::expedition.externalId}} {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} - {{::expedition.description}} + {{::expedition.state}} - {{::expeditionState.description}} + {{::expeditionState.state}}