From 553b8e681bce8b8f81da12e9ad8ee574f8c05cf3 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 3 Jul 2019 11:08:44 +0200 Subject: [PATCH 1/2] #1567 refactor logs - worker descriptor --- back/models/account.json | 7 ++++- modules/client/front/log/index.html | 10 +----- modules/client/front/log/index.js | 38 ---------------------- modules/item/front/log/index.html | 10 +----- modules/item/front/log/index.js | 38 ---------------------- modules/route/front/log/index.html | 10 +----- modules/route/front/log/index.js | 38 ---------------------- modules/ticket/front/log/index.html | 10 +----- modules/ticket/front/log/index.js | 39 ----------------------- modules/worker/front/log/index.html | 19 ++++++++--- modules/worker/front/log/index.js | 49 ++++++++++++++++++++++++++++- 11 files changed, 72 insertions(+), 196 deletions(-) diff --git a/back/models/account.json b/back/models/account.json index ad0c8aa5d..7186621b4 100644 --- a/back/models/account.json +++ b/back/models/account.json @@ -51,7 +51,12 @@ "type": "hasOne", "model": "EmailUser", "foreignKey": "userFk" - } + }, + "worker": { + "type": "hasOne", + "model": "Worker", + "foreignKey": "userFk" + } }, "acls": [ { diff --git a/modules/client/front/log/index.html b/modules/client/front/log/index.html index cc571ec08..b491db602 100644 --- a/modules/client/front/log/index.html +++ b/modules/client/front/log/index.html @@ -1,9 +1 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/client/front/log/index.js b/modules/client/front/log/index.js index 4552588e4..2f01d229c 100644 --- a/modules/client/front/log/index.js +++ b/modules/client/front/log/index.js @@ -4,44 +4,6 @@ class Controller { constructor($scope, $stateParams) { this.$scope = $scope; this.$stateParams = $stateParams; - this.filter = { - include: [{ - relation: 'user', - scope: { - fields: ['name'], - }, - }], - }; - } - - get logs() { - return this._logs; - } - - set logs(value) { - this._logs = value; - - if (this.logs) { - this.logs.forEach(log => { - log.oldProperties = this.getInstance(log.oldInstance); - log.newProperties = this.getInstance(log.newInstance); - }); - } - } - - getInstance(instance) { - let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; - const properties = []; - if (typeof instance == 'object' && instance != null) { - Object.keys(instance).forEach(property => { - if (validDate.test(instance[property])) - instance[property] = new Date(instance[property]).toLocaleString('es-ES'); - - properties.push({key: property, value: instance[property]}); - }); - return properties; - } - return null; } } diff --git a/modules/item/front/log/index.html b/modules/item/front/log/index.html index 3734ba056..209cf9e56 100644 --- a/modules/item/front/log/index.html +++ b/modules/item/front/log/index.html @@ -1,9 +1 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/item/front/log/index.js b/modules/item/front/log/index.js index edb540760..9253147c7 100644 --- a/modules/item/front/log/index.js +++ b/modules/item/front/log/index.js @@ -4,44 +4,6 @@ class Controller { constructor($scope, $stateParams) { this.$scope = $scope; this.$stateParams = $stateParams; - this.filter = { - include: [{ - relation: 'user', - scope: { - fields: ['name'], - }, - }], - }; - } - - get logs() { - return this._logs; - } - - set logs(value) { - this._logs = value; - - if (this.logs) { - this.logs.forEach(log => { - log.oldProperties = this.getInstance(log.oldInstance); - log.newProperties = this.getInstance(log.newInstance); - }); - } - } - - getInstance(instance) { - let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; - const properties = []; - if (typeof instance == 'object' && instance != null) { - Object.keys(instance).forEach(property => { - if (validDate.test(instance[property])) - instance[property] = new Date(instance[property]).toLocaleString('es-ES'); - - properties.push({key: property, value: instance[property]}); - }); - return properties; - } - return null; } } diff --git a/modules/route/front/log/index.html b/modules/route/front/log/index.html index 925ea1d14..45a41fc0f 100644 --- a/modules/route/front/log/index.html +++ b/modules/route/front/log/index.html @@ -1,9 +1 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/route/front/log/index.js b/modules/route/front/log/index.js index 85358bd72..ff0a2a9d1 100644 --- a/modules/route/front/log/index.js +++ b/modules/route/front/log/index.js @@ -4,44 +4,6 @@ class Controller { constructor($scope, $stateParams) { this.$scope = $scope; this.$stateParams = $stateParams; - this.filter = { - include: [{ - relation: 'user', - scope: { - fields: ['name'], - }, - }], - }; - } - - get logs() { - return this._logs; - } - - set logs(value) { - this._logs = value; - - if (this.logs) { - this.logs.forEach(log => { - log.oldProperties = this.getInstance(log.oldInstance); - log.newProperties = this.getInstance(log.newInstance); - }); - } - } - - getInstance(instance) { - let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; - const properties = []; - if (typeof instance == 'object' && instance != null) { - Object.keys(instance).forEach(property => { - if (validDate.test(instance[property])) - instance[property] = new Date(instance[property]).toLocaleString('es-ES'); - - properties.push({key: property, value: instance[property]}); - }); - return properties; - } - return null; } } diff --git a/modules/ticket/front/log/index.html b/modules/ticket/front/log/index.html index facc14fa2..9e975cceb 100644 --- a/modules/ticket/front/log/index.html +++ b/modules/ticket/front/log/index.html @@ -1,9 +1 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/ticket/front/log/index.js b/modules/ticket/front/log/index.js index fb1177162..6a486d3d0 100644 --- a/modules/ticket/front/log/index.js +++ b/modules/ticket/front/log/index.js @@ -4,45 +4,6 @@ class Controller { constructor($scope, $stateParams) { this.$scope = $scope; this.$stateParams = $stateParams; - this.filter = { - include: [{ - relation: 'user', - scope: { - fields: ['name'], - }, - }], - }; - } - - get logs() { - return this._logs; - } - - set logs(value) { - this._logs = value; - - if (this.logs) { - this.logs.forEach(log => { - log.oldProperties = this.getInstance(log.oldInstance); - log.newProperties = this.getInstance(log.newInstance); - }); - } - } - - getInstance(instance) { - const properties = []; - let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; - - if (typeof instance == 'object' && instance != null) { - Object.keys(instance).forEach(property => { - if (validDate.test(instance[property])) - instance[property] = new Date(instance[property]).toLocaleString('es-ES'); - - properties.push({key: property, value: instance[property]}); - }); - return properties; - } - return null; } } diff --git a/modules/worker/front/log/index.html b/modules/worker/front/log/index.html index 1c3c76459..8ba6b285b 100644 --- a/modules/worker/front/log/index.html +++ b/modules/worker/front/log/index.html @@ -1,8 +1,17 @@ + + History - + Date @@ -15,7 +24,7 @@ - + {{::log.creationDate | dateTime:'dd/MM/yyyy HH:mm'}}
@@ -23,7 +32,7 @@ Changed by: {{::log.user.name | dashIfEmpty}} @@ -45,7 +54,7 @@ {{::log.user.name | dashIfEmpty}} @@ -89,7 +98,7 @@ - + { + log.oldProperties = this.getInstance(log.oldInstance); + log.newProperties = this.getInstance(log.newInstance); + }); + } } showWorkerDescriptor(event, workerFk) { @@ -22,6 +51,22 @@ export default class Controller { this.$.workerDescriptor.parent = event.target; this.$.workerDescriptor.show(); } + + getInstance(instance) { + const properties = []; + let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; + + if (typeof instance == 'object' && instance != null) { + Object.keys(instance).forEach(property => { + if (validDate.test(instance[property])) + instance[property] = new Date(instance[property]).toLocaleString('es-ES'); + + properties.push({key: property, value: instance[property]}); + }); + return properties; + } + return null; + } } Controller.$inject = ['$scope']; @@ -30,6 +75,8 @@ ngModule.component('vnLog', { controller: Controller, template: require('./index.html'), bindings: { - model: '<' + model: '<', + originId: '<', + url: '@' } }); From 6b5acf5fe3aab1ff9ca31c5ce3150e33d5fd7ab5 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 3 Jul 2019 11:51:42 +0200 Subject: [PATCH 2/2] removed unused spec files --- modules/client/front/log/index.spec.js | 37 -------------------------- modules/route/front/log/index.spec.js | 37 -------------------------- modules/ticket/front/log/index.spec.js | 37 -------------------------- 3 files changed, 111 deletions(-) delete mode 100644 modules/client/front/log/index.spec.js delete mode 100644 modules/route/front/log/index.spec.js delete mode 100644 modules/ticket/front/log/index.spec.js diff --git a/modules/client/front/log/index.spec.js b/modules/client/front/log/index.spec.js deleted file mode 100644 index 6071f2510..000000000 --- a/modules/client/front/log/index.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -import './index'; - -describe('Client', () => { - describe('Component vnClientLog', () => { - let $componentController; - let $scope; - let controller; - - beforeEach(ngModule('client')); - - beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { - $componentController = _$componentController_; - $scope = $rootScope.$new(); - controller = $componentController('vnClientLog', {$scope: $scope}); - controller.$scope.model = {data: [{newInstance: {id: 1}, oldInstance: {id: 2}}]}; - })); - - describe('logs setter', () => { - it('should call the function getInstance() twice', () => { - spyOn(controller, 'getInstance'); - controller.logs = [{newInstance: {id: 1}, oldInstance: {id: 2}}]; - - expect(controller.getInstance.calls.count()).toBe(2); - expect(controller.getInstance).toHaveBeenCalledWith({id: 1}); - expect(controller.getInstance).toHaveBeenCalledWith({id: 2}); - }); - }); - - describe('getInstance(instance)', () => { - it('should transform the object given in to an array', () => { - let newInstance = controller.getInstance(controller.$scope.model.data[0].newInstance); - - expect(newInstance).toEqual([{key: 'id', value: 1}]); - }); - }); - }); -}); diff --git a/modules/route/front/log/index.spec.js b/modules/route/front/log/index.spec.js deleted file mode 100644 index f8b6f8272..000000000 --- a/modules/route/front/log/index.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -import './index'; - -describe('Route', () => { - describe('Component vnRouteLog', () => { - let $componentController; - let $scope; - let controller; - - beforeEach(ngModule('route')); - - beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { - $componentController = _$componentController_; - $scope = $rootScope.$new(); - controller = $componentController('vnRouteLog', {$scope: $scope}); - controller.$scope.model = {data: [{newInstance: {id: 1}, oldInstance: {id: 2}}]}; - })); - - describe('logs setter', () => { - it('should call the function getInstance() twice', () => { - spyOn(controller, 'getInstance'); - controller.logs = [{newInstance: {id: 1}, oldInstance: {id: 2}}]; - - expect(controller.getInstance.calls.count()).toBe(2); - expect(controller.getInstance).toHaveBeenCalledWith({id: 1}); - expect(controller.getInstance).toHaveBeenCalledWith({id: 2}); - }); - }); - - describe('getInstance(instance)', () => { - it('should transform the object given in to an array', () => { - let newInstance = controller.getInstance(controller.$scope.model.data[0].newInstance); - - expect(newInstance).toEqual([{key: 'id', value: 1}]); - }); - }); - }); -}); diff --git a/modules/ticket/front/log/index.spec.js b/modules/ticket/front/log/index.spec.js deleted file mode 100644 index ef4c72ef6..000000000 --- a/modules/ticket/front/log/index.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -import './index'; - -describe('Ticket', () => { - describe('Component vnTicketLog', () => { - let $componentController; - let $scope; - let controller; - - beforeEach(ngModule('ticket')); - - beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { - $componentController = _$componentController_; - $scope = $rootScope.$new(); - controller = $componentController('vnTicketLog', {$scope: $scope}); - controller.$scope.model = {data: [{newInstance: {id: 1}, oldInstance: {id: 2}}]}; - })); - - describe('logs setter', () => { - it('should call the function getInstance() twice', () => { - spyOn(controller, 'getInstance'); - controller.logs = [{newInstance: {id: 1}, oldInstance: {id: 2}}]; - - expect(controller.getInstance.calls.count()).toBe(2); - expect(controller.getInstance).toHaveBeenCalledWith({id: 1}); - expect(controller.getInstance).toHaveBeenCalledWith({id: 2}); - }); - }); - - describe('getInstance(instance)', () => { - it('should transform the object given in to an array', () => { - const newInstance = controller.getInstance(controller.$scope.model.data[0].newInstance); - - expect(newInstance).toEqual([{key: 'id', value: 1}]); - }); - }); - }); -});