#1567 refactor logs - worker descriptor

This commit is contained in:
Carlos Jimenez Ruiz 2019-07-03 11:08:44 +02:00
parent 65ec629221
commit a2a9dfd7e5
11 changed files with 72 additions and 196 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,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,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,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: '@'
}
});