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