Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into test
gitea/salix/test This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-07-03 12:45:56 +02:00
commit a15f6e2573
14 changed files with 72 additions and 307 deletions

View File

@ -51,7 +51,12 @@
"type": "hasOne",
"model": "EmailUser",
"foreignKey": "userFk"
}
},
"worker": {
"type": "hasOne",
"model": "Worker",
"foreignKey": "userFk"
}
},
"acls": [
{

View File

@ -1,9 +1 @@
<vn-crud-model
vn-id="model"
url="/client/api/ClientLogs"
link="{originFk: $ctrl.$stateParams.id}"
filter="$ctrl.filter"
limit="20"
data="$ctrl.logs" auto-load="false">
</vn-crud-model>
<vn-log model="model"></vn-log>
<vn-log url="/api/ClientLogs" origin-id="$ctrl.$stateParams.id"></vn-log>

View File

@ -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;
}
}

View File

@ -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}]);
});
});
});
});

View File

@ -1,9 +1 @@
<vn-crud-model
vn-id="model"
url="/api/ItemLogs"
link="{originFk: $ctrl.$stateParams.id}"
filter="$ctrl.filter"
limit="20"
data="$ctrl.logs" auto-load="false">
</vn-crud-model>
<vn-log model="model"></vn-log>
<vn-log url="/api/ItemLogs" origin-id="$ctrl.$stateParams.id"></vn-log>

View File

@ -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;
}
}

View File

@ -1,9 +1 @@
<vn-crud-model
vn-id="model"
url="/api/RouteLogs"
link="{originFk: $ctrl.$stateParams.id}"
filter="$ctrl.filter"
limit="20"
data="$ctrl.logs" auto-load="false">
</vn-crud-model>
<vn-log model="model"></vn-log>
<vn-log url="/api/RouteLogs" origin-id="$ctrl.$stateParams.id"></vn-log>

View File

@ -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;
}
}

View File

@ -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}]);
});
});
});
});

View File

@ -1,9 +1 @@
<vn-crud-model auto-load="false"
vn-id="model"
url="/ticket/api/TicketLogs"
link="{originFk: $ctrl.$stateParams.id}"
filter="$ctrl.filter"
limit="20"
data="$ctrl.logs">
</vn-crud-model>
<vn-log model="model"></vn-log>
<vn-log url="/api/TicketLogs" origin-id="$ctrl.$stateParams.id"></vn-log>

View File

@ -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;
}
}

View File

@ -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}]);
});
});
});
});

View File

@ -1,8 +1,17 @@
<vn-crud-model
vn-id="model"
url="{{$ctrl.url}}"
filter="$ctrl.filter"
link="{originFk: $ctrl.originId}"
data="$ctrl.logs"
limit="20"
auto-load="true">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
<vn-title>History</vn-title>
<vn-table model="$ctrl.model">
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th field="creationDate">Date</vn-th>
@ -15,7 +24,7 @@
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="log in $ctrl.model.data">
<vn-tr ng-repeat="log in $ctrl.logs">
<vn-td>
{{::log.creationDate | dateTime:'dd/MM/yyyy HH:mm'}}
<div class="changes">
@ -23,7 +32,7 @@
<span translate class="label">Changed by</span><span class="label">: </span>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.id)"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)"
translate
class="value">{{::log.user.name | dashIfEmpty}}
</span>
@ -45,7 +54,7 @@
<vn-td class="expendable">
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.id)"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)"
translate
class="value">{{::log.user.name | dashIfEmpty}}
</span>
@ -89,7 +98,7 @@
</vn-tbody>
</vn-table>
</vn-vertical>
<vn-pagination model="$ctrl.model"></vn-pagination>
<vn-pagination model="model"></vn-pagination>
</vn-card>
</vn-vertical>
<vn-worker-descriptor-popover

View File

@ -10,6 +10,35 @@ export default class Controller {
'delete': 'Deletes',
'select': 'Views'
};
this.filter = {
include: [{
relation: 'user',
scope: {
fields: ['name'],
include: {
relation: 'worker',
scope: {
fields: ['id']
}
}
},
}],
};
}
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);
});
}
}
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: '@'
}
});