diff --git a/client/client/routes.json b/client/client/routes.json index 153c1449b..42ac8e101 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -341,6 +341,15 @@ "menu": { "icon": "web" } + }, + { + "url" : "/history", + "state": "client.card.history", + "component": "vn-client-history", + "description": "History", + "menu": { + "icon": "history" + } } ] } diff --git a/client/client/src/client.js b/client/client/src/client.js index f6e2eff9f..a6cc97716 100644 --- a/client/client/src/client.js +++ b/client/client/src/client.js @@ -32,3 +32,4 @@ import './contact'; import './sample/index'; import './sample/create'; import './web-payment'; +import './history'; diff --git a/client/client/src/history/index.html b/client/client/src/history/index.html new file mode 100644 index 000000000..0eb658fe8 --- /dev/null +++ b/client/client/src/history/index.html @@ -0,0 +1,65 @@ + + + + + + + History + + + + Date + Model + Action + Changed by + Before + After + + + + + + {{::clientLog.creationDate | date:'dd/MM/yyyy HH:mm'}} + + + {{::clientLog.model}} + + + {{::clientLog.action}} + + + {{::clientLog.user.name}} + + + + + + + + + + + + + + + + + No results + + + + + + + diff --git a/client/client/src/history/index.js b/client/client/src/history/index.js new file mode 100644 index 000000000..dbabcbfe0 --- /dev/null +++ b/client/client/src/history/index.js @@ -0,0 +1,42 @@ +import ngModule from '../module'; + +class Controller { + constructor($scope, $stateParams) { + this.$scope = $scope; + this.$stateParams = $stateParams; + this.filter = { + include: [{ + relation: "user", + scope: { + fields: ["name"] + } + }] + }; + } + + onDataChange() { + let logs = this.$scope.model.data; + + logs.forEach(log => { + log.oldProperties = this.getInstance(log.oldInstance); + log.newProperties = this.getInstance(log.newInstance); + }); + } + + getInstance(instance) { + let properties = []; + + Object.keys(instance).forEach(property => { + properties.push({key: property, value: instance[property]}); + }); + + return properties; + } +} + +Controller.$inject = ['$scope', '$stateParams']; + +ngModule.component('vnClientHistory', { + template: require('./index.html'), + controller: Controller +}); diff --git a/client/client/src/history/index.spec.js b/client/client/src/history/index.spec.js new file mode 100644 index 000000000..1ffc51758 --- /dev/null +++ b/client/client/src/history/index.spec.js @@ -0,0 +1,39 @@ +import './index'; + +fdescribe('Client', () => { + describe('Component vnClientHistory', () => { + let $componentController; + let $scope; + let controller; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { + $componentController = _$componentController_; + $scope = $rootScope.$new(); + controller = $componentController('vnClientHistory', {$scope: $scope}); + controller.$scope.model = {data: [{newInstance: {id: 1}, oldInstance: {id: 2}}]} + })); + + describe('onDataChange()', () => { + it('should call the function getInstance() twice', () => { + spyOn(controller, 'getInstance').and.callFake(() => {}); + controller.onDataChange(); + + 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/client/client/src/history/locale/es.yml b/client/client/src/history/locale/es.yml new file mode 100644 index 000000000..cbdb947ea --- /dev/null +++ b/client/client/src/history/locale/es.yml @@ -0,0 +1,8 @@ +Model: Modelo +Action: Acción +Changed by: Cambiado por +Before: Antes +After: Despues +update: Actualizar +Create: Crear +History: Historial \ No newline at end of file