Allow disable log on model properties
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
parent
9bf54f34dd
commit
e16d43b2fc
|
@ -211,6 +211,9 @@ module.exports = function(Self) {
|
|||
|
||||
let action = setActionType(ctx);
|
||||
|
||||
removeUnloggableProperties(definition, oldInstance);
|
||||
removeUnloggableProperties(definition, newInstance);
|
||||
|
||||
let logRecord = {
|
||||
originFk: originId,
|
||||
userFk: userFk,
|
||||
|
@ -223,12 +226,38 @@ module.exports = function(Self) {
|
|||
};
|
||||
|
||||
let logsToSave = setLogsToSave(where, changedModelId, logRecord, ctx);
|
||||
|
||||
let logModel = definition.settings.log.model;
|
||||
|
||||
await ctx.Model.app.models[logModel].create(logsToSave, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes unwanted properties
|
||||
* @param {*} definition Model definition
|
||||
* @param {*} properties Modified object properties
|
||||
*/
|
||||
function removeUnloggableProperties(definition, properties) {
|
||||
const propList = Object.keys(properties);
|
||||
const propDefs = new Map();
|
||||
|
||||
for (let property in definition.properties) {
|
||||
const propertyDef = definition.properties[property];
|
||||
|
||||
propDefs.set(property, propertyDef);
|
||||
}
|
||||
|
||||
for (let property of propList) {
|
||||
const propertyDef = propDefs.get(property);
|
||||
|
||||
if (!propertyDef) return;
|
||||
|
||||
if (propertyDef.log === false)
|
||||
delete properties[property];
|
||||
else if (propertyDef.logValue === false)
|
||||
properties[property] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// this function retuns all the instances changed in case this is an updateAll
|
||||
function setLogsToSave(changedInstances, changedInstancesIds, logRecord, ctx) {
|
||||
let promises = [];
|
||||
|
|
|
@ -96,6 +96,11 @@
|
|||
vn-tooltip="Add">
|
||||
</vn-icon-button>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<div class="price" style="font-size: 8px">
|
||||
<span>asdasdd</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</vn-card>
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue