fixes #3302 log front modificaciones #1198
|
@ -52,16 +52,14 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="prop in ::log.props">
|
<tr ng-repeat="prop in ::log.props">
|
||||||
<td class="field">{{prop.name}}</td>
|
<td class="field">{{prop.name}}</td>
|
||||||
<td class="before">{{::$ctrl.formatValue(prop.old)}}</td>
|
<td class="before">{{prop.old}}</td>
|
||||||
<td class="after">{{::$ctrl.formatValue(prop.new)}}</td>
|
<td class="after">{{prop.new}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<vn-one ng-if="!log.newProperties" id="description">
|
<div ng-if="log.description != null">
|
||||||
<div>
|
{{::log.description}}
|
||||||
<span no-ellipsize>{{::log.description}}</span>
|
</div>
|
||||||
</div>
|
|
||||||
</vn-one>
|
|
||||||
</vn-td>
|
</vn-td>
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-tbody>
|
</vn-tbody>
|
||||||
|
|
|
@ -2,6 +2,8 @@ import ngModule from '../../module';
|
||||||
import Section from '../section';
|
import Section from '../section';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
|
const 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)?$/;
|
||||||
|
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
constructor($element, $) {
|
constructor($element, $) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
|
@ -10,7 +12,7 @@ export default class Controller extends Section {
|
||||||
'update': 'Updates',
|
'update': 'Updates',
|
||||||
'delete': 'Deletes',
|
'delete': 'Deletes',
|
||||||
'select': 'Views'
|
'select': 'Views'
|
||||||
}; ``;
|
};
|
||||||
this.filter = {
|
this.filter = {
|
||||||
include: [{
|
include: [{
|
||||||
relation: 'user',
|
relation: 'user',
|
||||||
|
@ -34,52 +36,44 @@ export default class Controller extends Section {
|
||||||
set logs(value) {
|
set logs(value) {
|
||||||
this._logs = value;
|
this._logs = value;
|
||||||
if (!this.logs) return;
|
if (!this.logs) return;
|
||||||
|
const empty = {};
|
||||||
const validations = window.validations;
|
const validations = window.validations;
|
||||||
for (const log of value) {
|
for (const log of value) {
|
||||||
const locale = validations[log.changedModel] && validations[log.changedModel].locale
|
const oldValues = log.oldInstance || empty;
|
||||||
? validations[log.changedModel].locale : {};
|
const newValues = log.newInstance || empty;
|
||||||
log.oldProperties = this.getInstance(log.oldInstance, locale);
|
const locale = validations[log.changedModel]?.locale || empty;
|
||||||
log.newProperties = this.getInstance(log.newInstance, locale);
|
|
||||||
let props = [].concat(log.oldProperties.map(p => p.key), log.newProperties.map(p => p.key));
|
let props = Object.keys(oldValues).concat(Object.keys(newValues));
|
||||||
props = [...new Set(props)];
|
props = [...new Set(props)];
|
||||||
|
|
||||||
log.props = [];
|
log.props = [];
|
||||||
for (const prop of props) {
|
for (const prop of props) {
|
||||||
const matchOldProp = log.oldProperties.find(p => p.key === prop);
|
|
||||||
const matchNewProp = log.newProperties.find(p => p.key === prop);
|
|
||||||
log.props.push({
|
log.props.push({
|
||||||
name: prop,
|
name: locale[prop] || prop,
|
||||||
old: matchOldProp ? matchOldProp.value : null,
|
old: this.formatValue(oldValues[prop]),
|
||||||
new: matchNewProp ? matchNewProp.value : null,
|
new: this.formatValue(newValues[prop])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
formatValue(value) {
|
formatValue(value) {
|
||||||
|
if (typeof value === 'string' && validDate.test(value))
|
||||||
|
value = new Date(value);
|
||||||
|
|
||||||
switch (typeof value) {
|
switch (typeof value) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return value ? '✓' : '✗';
|
return value ? '✓' : '✗';
|
||||||
|
case 'object':
|
||||||
|
if (value instanceof Date)
|
||||||
|
return this.$filter('date')(value, 'dd/MM/yyyy HH:mm:ss');
|
||||||
|
else
|
||||||
|
return value;
|
||||||
default:
|
default:
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getInstance(instance, locale) {
|
|
||||||
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');
|
|
||||||
const key = locale[property] || property;
|
|
||||||
properties.push({key, value: instance[property]});
|
|
||||||
});
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
showWorkerDescriptor(event, workerId) {
|
showWorkerDescriptor(event, workerId) {
|
||||||
if (!workerId) return;
|
if (!workerId) return;
|
||||||
this.$.workerDescriptor.show(event.target, workerId);
|
this.$.workerDescriptor.show(event.target, workerId);
|
||||||
|
|
Loading…
Reference in New Issue