From f6bfec13774e1f48ab9e15576e1b37a4ed87e11b Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 28 Mar 2023 15:22:05 +0200 Subject: [PATCH] refs #5394 propuesta --- front/salix/components/log/index.html | 14 ++++++++---- front/salix/components/log/index.js | 24 ++++++++++++++++---- loopback/common/methods/schema/model-info.js | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/front/salix/components/log/index.html b/front/salix/components/log/index.html index 79dfcef8c..4bb5afd22 100644 --- a/front/salix/components/log/index.html +++ b/front/salix/components/log/index.html @@ -29,7 +29,7 @@ {{::log.user.name || 'System' | translate}} @@ -54,8 +54,8 @@ {{prop.name}} - {{prop.old}} - {{prop.new}} + {{prop.old}} + {{prop.new}} @@ -69,5 +69,11 @@ - + + + + + + + diff --git a/front/salix/components/log/index.js b/front/salix/components/log/index.js index 1c54aa9b8..03745a0e7 100644 --- a/front/salix/components/log/index.js +++ b/front/salix/components/log/index.js @@ -7,6 +7,7 @@ const validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[ export default class Controller extends Section { constructor($element, $) { super($element, $); + this.descriptors = new Map(); this.actionsText = { insert: 'Creates', update: 'Updates', @@ -39,24 +40,37 @@ export default class Controller extends Section { const empty = {}; const validations = window.validations; for (const log of value) { + if(log.changedModel && !this.descriptors.get(log.changedModel)) + this.fillDescriptorsMap(log.changedModel); + 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 descriptor = this.descriptors.get(log.changedModel).get(prop); log.props.push({ name: locale[prop] || prop, old: this.formatValue(oldValues[prop]), - new: this.formatValue(newValues[prop]) + new: this.formatValue(newValues[prop]), + descriptor }); } } } + fillDescriptorsMap(changedModel) { + const relations = new Map(); + Object.values(window.validations[changedModel].relations).forEach(relation => { + if(relation.type == "belongsTo") + relations.set(relation.keyFrom, relation.modelTo); + }); + this.descriptors.set(changedModel, relations); + } + get showModelName() { return !(this.changedModel && this.changedModelId); } @@ -88,9 +102,9 @@ export default class Controller extends Section { } } - showWorkerDescriptor(event, workerId) { - if (!workerId) return; - this.$.workerDescriptor.show(event.target, workerId); + showDescriptor(descriptor, event, id) { + if (!descriptor || !this.$[descriptor]) return; + this.$[descriptor].show(event.target, id); } } diff --git a/loopback/common/methods/schema/model-info.js b/loopback/common/methods/schema/model-info.js index 6a4db033d..4601b1ed5 100644 --- a/loopback/common/methods/schema/model-info.js +++ b/loopback/common/methods/schema/model-info.js @@ -93,6 +93,7 @@ module.exports = Self => { json[modelName] = { properties: model.definition.rawProperties, + relations: model.relations, validations: jsonValidations, locale };