refs #5900 Code clean, refactor & accurated
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
544445c4ae
commit
c42b38c5cc
|
@ -3,7 +3,7 @@
|
|||
url="{{$ctrl.url}}"
|
||||
filter="$ctrl.filter"
|
||||
data="$ctrl.logs"
|
||||
order="creationDate DESC, originFk DESC, id DESC"
|
||||
order="creationDate DESC, id DESC"
|
||||
limit="20">
|
||||
</vn-crud-model>
|
||||
<vn-crud-model
|
||||
|
@ -228,9 +228,6 @@
|
|||
</vn-date-picker>
|
||||
</form>
|
||||
</vn-side-menu>
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="worker-descriptor">
|
||||
</vn-worker-descriptor-popover>
|
||||
<vn-popover vn-id="instance-popover">
|
||||
<tpl-body class="vn-log-instance">
|
||||
<vn-spinner
|
||||
|
@ -240,9 +237,9 @@
|
|||
</vn-spinner>
|
||||
<div
|
||||
ng-if="!$ctrl.instance.canceler" class="instance">
|
||||
<div class="header vn-pa-sm">
|
||||
<h6 class="header vn-pa-sm">
|
||||
{{$ctrl.instance.modelLog.modelI18n}} #{{$ctrl.instance.modelLog.id}}
|
||||
</div>
|
||||
</h6>
|
||||
<div class="change-detail vn-pa-sm">
|
||||
<div ng-if="$ctrl.instance.props"
|
||||
ng-repeat="prop in $ctrl.instance.props">
|
||||
|
@ -258,3 +255,6 @@
|
|||
</div>
|
||||
</tpl-body>
|
||||
</vn-popover>
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="worker-descriptor">
|
||||
</vn-worker-descriptor-popover>
|
||||
|
|
|
@ -67,7 +67,7 @@ export default class Controller extends Section {
|
|||
|
||||
$onInit() {
|
||||
const match = this.url?.match(/(.*)Logs$/);
|
||||
this.modelI18n = this.translateModel(match && match[1]);
|
||||
this.modelI18n = match && this.translateModel(match[1]);
|
||||
}
|
||||
|
||||
$postLink() {
|
||||
|
@ -116,7 +116,7 @@ export default class Controller extends Section {
|
|||
|
||||
const userChanged = originChanged
|
||||
|| log.userFk != prevLog.userFk
|
||||
|| nLogs >= 6;
|
||||
|| nLogs >= 5;
|
||||
if (userChanged) {
|
||||
originLog.logs.push(userLog = {
|
||||
user: log.user,
|
||||
|
@ -181,8 +181,8 @@ export default class Controller extends Section {
|
|||
props.push({
|
||||
name: prop,
|
||||
nameI18n: firstUpper(locale.columns?.[prop]) || prop,
|
||||
old: getVal(olds, prop),
|
||||
val: getVal(vals, prop)
|
||||
val: getVal(vals, prop),
|
||||
old: olds && getVal(olds, prop)
|
||||
});
|
||||
}
|
||||
props.sort(
|
||||
|
@ -220,7 +220,7 @@ export default class Controller extends Section {
|
|||
const instance = res.data;
|
||||
const propNames = Object.keys(instance);
|
||||
const locale = window.validations[modelLog.model]?.locale || {};
|
||||
this.instance.props = this.parseProps(propNames, locale, instance, {});
|
||||
this.instance.props = this.parseProps(propNames, locale, instance);
|
||||
})
|
||||
.finally(() => {
|
||||
this.instance.canceler = null;
|
||||
|
|
|
@ -228,6 +228,7 @@ vn-log {
|
|||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
margin: 0;
|
||||
}
|
||||
& > .change-detail {
|
||||
color: $color-font-light;
|
||||
|
|
|
@ -37,37 +37,52 @@ module.exports = Self => {
|
|||
changedModelId: log.changedModelId
|
||||
};
|
||||
|
||||
// Fetch creation and all update logs for record up to requested log
|
||||
|
||||
const createdWhere = {
|
||||
action: 'insert',
|
||||
creationDate: {lte: log.creationDate}
|
||||
};
|
||||
const createdLog = await Self.findOne({
|
||||
fields: ['id', 'creationDate'],
|
||||
fields: ['id', 'creationDate', 'newInstance'],
|
||||
where: Object.assign(createdWhere, where),
|
||||
order: 'creationDate DESC'
|
||||
order: 'creationDate DESC, id DESC'
|
||||
});
|
||||
if (!createdLog)
|
||||
throw new NotFoundError('Cannot find creation log');
|
||||
|
||||
const logsWhere = {
|
||||
id: {between: [
|
||||
Math.min(id, createdLog.id),
|
||||
Math.max(id, createdLog.id)
|
||||
]},
|
||||
creationDate: {between: [
|
||||
createdLog.creationDate,
|
||||
log.creationDate
|
||||
]}
|
||||
const instance = {};
|
||||
|
||||
let logsWhere = {
|
||||
action: 'update'
|
||||
};
|
||||
if (createdLog) {
|
||||
Object.assign(instance, createdLog.newInstance);
|
||||
Object.assign(logsWhere, {
|
||||
creationDate: {between: [
|
||||
createdLog.creationDate,
|
||||
log.creationDate
|
||||
]},
|
||||
id: {between: [
|
||||
Math.min(id, createdLog.id),
|
||||
Math.max(id, createdLog.id)
|
||||
]}
|
||||
});
|
||||
} else {
|
||||
Object.assign(logsWhere, {
|
||||
creationDate: {lte: log.creationDate},
|
||||
id: {lte: id}
|
||||
});
|
||||
}
|
||||
|
||||
const logs = await Self.find({
|
||||
fields: ['newInstance'],
|
||||
where: Object.assign(logsWhere, where),
|
||||
order: 'creationDate'
|
||||
order: 'creationDate, id'
|
||||
});
|
||||
if (!logs.length)
|
||||
if (!logs.length && !createdLog)
|
||||
throw new NotFoundError('No logs found for record');
|
||||
|
||||
const instance = {};
|
||||
// Merge all logs in order into one instance
|
||||
|
||||
for (const log of logs)
|
||||
Object.assign(instance, log.newInstance);
|
||||
|
||||
|
|
Loading…
Reference in New Issue