From 5547193a3152bb2ea699eb2b4fd4b51894feb9b1 Mon Sep 17 00:00:00 2001 From: Bernat Date: Fri, 25 Oct 2019 13:26:38 +0200 Subject: [PATCH 1/3] #1776 travel.basicData --- modules/travel/back/models/travel.json | 13 +++- modules/travel/front/basic-data/index.html | 72 +++++++++++++++++++ modules/travel/front/basic-data/index.js | 25 +++++++ modules/travel/front/basic-data/index.spec.js | 28 ++++++++ modules/travel/front/basic-data/locale/es.yml | 1 + modules/travel/front/card/index.js | 10 --- modules/travel/front/index.js | 2 + modules/travel/front/routes.json | 17 +++++ 8 files changed, 156 insertions(+), 12 deletions(-) create mode 100644 modules/travel/front/basic-data/index.html create mode 100644 modules/travel/front/basic-data/index.js create mode 100644 modules/travel/front/basic-data/index.spec.js create mode 100644 modules/travel/front/basic-data/locale/es.yml diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index fd881dd10..b4f154525 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -1,6 +1,9 @@ { "name": "Travel", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"TravelLog" + }, "options": { "mysql": { "table": "travel" @@ -32,12 +35,18 @@ }, "m3": { "type": "Number" + }, + "agencyModeFk": { + "type": "Number", + "mysql": { + "columnName": "agencyFk" + } } }, "relations": { "agency": { "type": "belongsTo", - "model": "Agency", + "model": "AgencyMode", "foreignKey": "agencyFk" }, "warehouseIn": { diff --git a/modules/travel/front/basic-data/index.html b/modules/travel/front/basic-data/index.html new file mode 100644 index 000000000..b85168ac3 --- /dev/null +++ b/modules/travel/front/basic-data/index.html @@ -0,0 +1,72 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/modules/travel/front/basic-data/index.js b/modules/travel/front/basic-data/index.js new file mode 100644 index 000000000..7406598b0 --- /dev/null +++ b/modules/travel/front/basic-data/index.js @@ -0,0 +1,25 @@ +import ngModule from '../module'; + +class Controller { + constructor($scope) { + this.$ = $scope; + } + + onSubmit() { + return this.$.watcher.submit().then(() => { + this.card.reload(); + }); + } +} +Controller.$inject = ['$scope']; + +ngModule.component('vnTravelBasicData', { + template: require('./index.html'), + controller: Controller, + bindings: { + travel: '<' + }, + require: { + card: '^vnTravelCard' + } +}); diff --git a/modules/travel/front/basic-data/index.spec.js b/modules/travel/front/basic-data/index.spec.js new file mode 100644 index 000000000..ed5c287b1 --- /dev/null +++ b/modules/travel/front/basic-data/index.spec.js @@ -0,0 +1,28 @@ +import './index.js'; + +describe('Travel Component vnTravelBasicData', () => { + let controller; + let $scope; + beforeEach(angular.mock.module('travel', $translateProvider => { + $translateProvider.translations('en', {}); + })); + + beforeEach(angular.mock.inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + controller = $componentController('vnTravelBasicData', $scope); + controller.card = {reload: () => {}}; + controller.$.watcher = {submit: () => {}}; + })); + + describe('onSubmit()', () => { + it('should call the card reload method after the watcher submits', done => { + spyOn(controller.card, 'reload'); + spyOn(controller.$.watcher, 'submit').and.returnValue(Promise.resolve()); + + controller.onSubmit().then(() => { + expect(controller.card.reload).toHaveBeenCalledWith(); + done(); + }).catch(done.fail); + }); + }); +}); diff --git a/modules/travel/front/basic-data/locale/es.yml b/modules/travel/front/basic-data/locale/es.yml new file mode 100644 index 000000000..d95675612 --- /dev/null +++ b/modules/travel/front/basic-data/locale/es.yml @@ -0,0 +1 @@ +Undo changes: Deshacer cambios diff --git a/modules/travel/front/card/index.js b/modules/travel/front/card/index.js index 677e944c2..b67902e16 100644 --- a/modules/travel/front/card/index.js +++ b/modules/travel/front/card/index.js @@ -6,16 +6,6 @@ export default class Controller { this.$stateParams = $stateParams; this.travel = null; this.filter = { - fields: [ - 'id', - 'ref', - 'warehouseInFk', - 'warehouseOutFk', - 'shipped', - 'landed', - 'totalEntries' - ], - where: {id: $stateParams.id}, include: [ { diff --git a/modules/travel/front/index.js b/modules/travel/front/index.js index 82795940d..1017a431b 100644 --- a/modules/travel/front/index.js +++ b/modules/travel/front/index.js @@ -5,3 +5,5 @@ import './search-panel'; import './descriptor'; import './card'; import './summary'; +import './basic-data'; +import './log'; diff --git a/modules/travel/front/routes.json b/modules/travel/front/routes.json index 070785831..55643c937 100644 --- a/modules/travel/front/routes.json +++ b/modules/travel/front/routes.json @@ -3,6 +3,9 @@ "name": "Travels", "validations": true, "dependencies": ["worker"], + "menu": [ + {"state": "travel.card.basicData", "icon": "settings"}, + {"state": "travel.card.log", "icon": "history"}], "routes": [ { "url": "/travel", @@ -29,6 +32,20 @@ "params": { "travel": "$ctrl.travel" } + }, { + "url": "/basic-data", + "state": "travel.card.basicData", + "component": "vn-travel-basic-data", + "description": "Basic data", + "acl": ["buyer","logistic"], + "params": { + "travel": "$ctrl.travel" + } + }, { + "url" : "/log", + "state": "travel.card.log", + "component": "vn-travel-log", + "description": "Log" } ] } \ No newline at end of file From 9fd0ab0bd3bfe906bf68d8b6c996d8c0e36deb01 Mon Sep 17 00:00:00 2001 From: Bernat Date: Fri, 25 Oct 2019 13:28:12 +0200 Subject: [PATCH 2/3] =?UTF-8?q?#1775=20travel.log=20crear=20secci=C3=B3n?= =?UTF-8?q?=20historial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/changes/10100-AllSaints/00-travelLog.sql | 18 +++++++ modules/travel/back/model-config.json | 2 + modules/travel/back/models/travel-log.json | 58 +++++++++++++++++++++ modules/travel/front/locale/es.yml | 3 +- modules/travel/front/log/index.html | 1 + modules/travel/front/log/index.js | 15 ++++++ modules/worker/front/log/index.html | 8 +-- 7 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 db/changes/10100-AllSaints/00-travelLog.sql create mode 100644 modules/travel/back/models/travel-log.json create mode 100644 modules/travel/front/log/index.html create mode 100644 modules/travel/front/log/index.js diff --git a/db/changes/10100-AllSaints/00-travelLog.sql b/db/changes/10100-AllSaints/00-travelLog.sql new file mode 100644 index 000000000..bd7035fd1 --- /dev/null +++ b/db/changes/10100-AllSaints/00-travelLog.sql @@ -0,0 +1,18 @@ +CREATE TABLE `vn`.`travelLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(10) unsigned NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `description` text CHARACTER SET utf8, + `changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `oldInstance` text COLLATE utf8_unicode_ci, + `newInstance` text COLLATE utf8_unicode_ci, + `changedModelId` int(11) DEFAULT NULL, + `changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `travelLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `travelLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; \ No newline at end of file diff --git a/modules/travel/back/model-config.json b/modules/travel/back/model-config.json index ed089d755..d2c2841d1 100644 --- a/modules/travel/back/model-config.json +++ b/modules/travel/back/model-config.json @@ -3,5 +3,7 @@ "dataSource": "vn" },"Entry": { "dataSource": "vn" + },"TravelLog": { + "dataSource": "vn" } } diff --git a/modules/travel/back/models/travel-log.json b/modules/travel/back/models/travel-log.json new file mode 100644 index 000000000..d21821127 --- /dev/null +++ b/modules/travel/back/models/travel-log.json @@ -0,0 +1,58 @@ +{ + "name": "TravelLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "travelLog" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "originFk": { + "type": "Number", + "required": true + }, + "userFk": { + "type": "Number" + }, + "action": { + "type": "String", + "required": true + }, + "changedModel": { + "type": "String" + }, + "oldInstance": { + "type": "Object" + }, + "newInstance": { + "type": "Object" + }, + "creationDate": { + "type": "Date" + }, + "changedModelId": { + "type": "Number" + }, + "changedModelValue": { + "type": "String" + }, + "description": { + "type": "String" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + }, + "scope": { + "order": ["creationDate DESC", "id DESC"] + } +} diff --git a/modules/travel/front/locale/es.yml b/modules/travel/front/locale/es.yml index d474130ae..452897b8a 100644 --- a/modules/travel/front/locale/es.yml +++ b/modules/travel/front/locale/es.yml @@ -10,4 +10,5 @@ Travel id: Id envío Search travels by id: Buscar envios por identificador # Sections -Travels: Envíos \ No newline at end of file +Travels: Envíos +Log: Historial \ No newline at end of file diff --git a/modules/travel/front/log/index.html b/modules/travel/front/log/index.html new file mode 100644 index 000000000..48279d648 --- /dev/null +++ b/modules/travel/front/log/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/travel/front/log/index.js b/modules/travel/front/log/index.js new file mode 100644 index 000000000..a9a07aaf6 --- /dev/null +++ b/modules/travel/front/log/index.js @@ -0,0 +1,15 @@ +import ngModule from '../module'; + +class Controller { + constructor($scope, $stateParams) { + this.$scope = $scope; + this.$stateParams = $stateParams; + } +} + +Controller.$inject = ['$scope', '$stateParams']; + +ngModule.component('vnTravelLog', { + template: require('./index.html'), + controller: Controller, +}); diff --git a/modules/worker/front/log/index.html b/modules/worker/front/log/index.html index 674e5a200..0f65a30be 100644 --- a/modules/worker/front/log/index.html +++ b/modules/worker/front/log/index.html @@ -19,8 +19,8 @@ Model Action Name - Before - After + Before + After @@ -66,7 +66,7 @@ {{::log.changedModelValue}} - +
{{::old.key}}: @@ -74,7 +74,7 @@
- + Date: Fri, 25 Oct 2019 13:29:05 +0200 Subject: [PATCH 3/3] #1774 travel.index test and refactor --- modules/agency/front/index/index.spec.js | 2 +- modules/route/front/basic-data/index.html | 10 +++---- modules/route/front/basic-data/index.js | 9 ++++--- modules/travel/front/index/index.html | 4 +-- modules/travel/front/index/index.js | 2 +- modules/travel/front/index/index.spec.js | 33 +++++++++++++++++++++++ 6 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 modules/travel/front/index/index.spec.js diff --git a/modules/agency/front/index/index.spec.js b/modules/agency/front/index/index.spec.js index c4ffb975e..6ffdf3170 100644 --- a/modules/agency/front/index/index.spec.js +++ b/modules/agency/front/index/index.spec.js @@ -22,7 +22,7 @@ describe('Agency Component vnZoneIndex', () => { expect(result).toEqual({id: 1}); }); - it('should return a formated object with the warehouseFk in case of agencyModeFk', () => { + it('should return a formated object with the agencyModeFk in case of agencyModeFk', () => { let param = 'agencyModeFk'; let value = 'My Delivery'; let result = controller.exprBuilder(param, value); diff --git a/modules/route/front/basic-data/index.html b/modules/route/front/basic-data/index.html index daad13a56..67accfff5 100644 --- a/modules/route/front/basic-data/index.html +++ b/modules/route/front/basic-data/index.html @@ -1,4 +1,4 @@ - + @@ -36,7 +36,7 @@ @@ -73,7 +73,7 @@ ng-model="$ctrl.route.description" rule vn-focus> - + diff --git a/modules/route/front/basic-data/index.js b/modules/route/front/basic-data/index.js index 3c64200f4..810fd7511 100644 --- a/modules/route/front/basic-data/index.js +++ b/modules/route/front/basic-data/index.js @@ -1,17 +1,18 @@ import ngModule from '../module'; class Controller { - constructor($scope, $state) { - this.$scope = $scope; - this.$state = $state; + constructor($scope) { + this.$ = $scope; } onSubmit() { - this.$scope.watcher.submit().then(() => { + this.$.watcher.submit().then(() => { this.card.reload(); }); } } +Controller.$inject = ['$scope']; + ngModule.component('vnRouteBasicData', { template: require('./index.html'), controller: Controller, diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 6af3ddad0..3534fd0bd 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -41,10 +41,10 @@ {{::travel.id}} {{::travel.ref}} {{::travel.agency.name}} - {{::travel.warehouseOut.name}} + {{::travel.warehouseOut.name}} {{::travel.shipped | date:'dd/MM/yyyy'}} - {{::travel.warehouseIn.name}} + {{::travel.warehouseIn.name}} {{::travel.landed | date:'dd/MM/yyyy'}} diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index 068569c0b..b080ed8ec 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -40,7 +40,7 @@ export default class Controller { case 'landed': return {landed: {gte: value}}; case 'id': - case 'agencyFk': + case 'agencyModeFk': case 'warehouseOutFk': case 'warehouseInFk': case 'totalEntries': diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js new file mode 100644 index 000000000..321109003 --- /dev/null +++ b/modules/travel/front/index/index.spec.js @@ -0,0 +1,33 @@ +import './index.js'; + +describe('Travel Component vnTravelIndex', () => { + let $componentController; + let controller; + + beforeEach(angular.mock.module('travel', $translateProvider => { + $translateProvider.translations('en', {}); + })); + + beforeEach(angular.mock.inject(_$componentController_ => { + $componentController = _$componentController_; + controller = $componentController('vnTravelIndex'); + })); + + describe('exprBuilder()', () => { + it('should return a formated object with the travel id in case of search', () => { + let param = 'search'; + let value = 2; + let result = controller.exprBuilder(param, value); + + expect(result).toEqual({id: 2}); + }); + + it('should return a formated object with the warehouseInFk in case of warehouseInFk', () => { + let param = 'warehouseInFk'; + let value = 3; + let result = controller.exprBuilder(param, value); + + expect(result).toEqual({warehouseInFk: 3}); + }); + }); +});