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