refs #5900 Small fixes & code clean
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2023-06-25 17:06:38 +02:00
parent f70df714df
commit 98301f8e70
5 changed files with 39 additions and 19 deletions

View File

@ -5,8 +5,8 @@ const $ = {
userName: 'vn-client-web-access vn-textfield[ng-model="$ctrl.account.name"]',
email: 'vn-client-web-access vn-textfield[ng-model="$ctrl.account.email"]',
saveButton: 'vn-client-web-access button[type=submit]',
nameValue: 'vn-client-log .change:nth-child(1) .basic-json:nth-child(2) vn-json-value',
activeValue: 'vn-client-log .change:nth-child(2) .basic-json:nth-child(1) vn-json-value'
nameValue: 'vn-client-log .changes-log:nth-child(2) .basic-json:nth-child(2) vn-json-value',
activeValue: 'vn-client-log .changes-log:nth-child(3) .basic-json:nth-child(1) vn-json-value'
};
describe('Client web access path', () => {

View File

@ -33,16 +33,16 @@
ng-src="/api/Images/user/160x160/{{::userLog.userFk}}/download?access_token={{::$ctrl.vnToken.token}}">
</img>
</vn-avatar>
<div class="arrow bg-panel" ng-if="::$ctrl.byEntity"></div>
<div class="arrow bg-panel" ng-if="::$ctrl.byRecord"></div>
<div class="line"></div>
</div>
<div class="user-changes">
<div class="model-log" ng-repeat="modelLog in ::userLog.logs">
<div class="model-info vn-mb-sm" ng-if="::!$ctrl.byEntity">
<div class="model-info vn-mb-sm" ng-if="::!$ctrl.byRecord">
<vn-icon
icon="filter_alt"
translate-attr="{title: 'Show all record changes'}"
ng-click="$ctrl.filterByEntity(modelLog)">
ng-click="$ctrl.filterByRecord(modelLog)">
</vn-icon>
<span class="model-name"
ng-if="::$ctrl.showModelName && modelLog.model"
@ -63,7 +63,7 @@
<div>
<vn-icon
class="pit vn-ml-xs"
icon="visibility"
icon="preview"
translate-attr="::{title: 'View record at this point in time'}"
ng-click="$ctrl.viewPitInstance($event, log.id, modelLog)">
</vn-icon>

View File

@ -67,8 +67,7 @@ export default class Controller extends Section {
$onInit() {
const match = this.url?.match(/(.*)Logs$/);
this.model = match && match[1];
this.modelI18n = this.translateModel(this.model);
this.modelI18n = this.translateModel(match && match[1]);
}
$postLink() {
@ -279,7 +278,7 @@ export default class Controller extends Section {
if (value == null || value == '') return null;
switch (prop) {
case 'search':
if (/^\s*[0-9]+\s*$/.test(value) || this.byEntity)
if (/^\s*[0-9]+\s*$/.test(value) || this.byRecord)
return {changedModelId: value.trim()};
else
return {changedModelValue: {like: `%${value}%`}};
@ -332,8 +331,8 @@ export default class Controller extends Section {
const and = [];
if (!filter.search || !filter.changedModel)
this.byEntity = false;
if (!this.byEntity)
this.byRecord = false;
if (!this.byRecord)
and.push({originFk: this.originId});
for (const prop in filter) {
@ -348,8 +347,8 @@ export default class Controller extends Section {
return this.$.model.applyFilter(lbFilter);
}
filterByEntity(modelLog) {
this.byEntity = true;
filterByRecord(modelLog) {
this.byRecord = true;
this.$.filter = {
who: 'all',
search: modelLog.id,

View File

@ -74,7 +74,8 @@ vn-log {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin-top: 6px;
margin-top: 5px;
min-height: 22px;
& > .model-name {
display: inline-block;
@ -131,7 +132,7 @@ vn-log {
& > vn-icon.pit {
@extend %clickable-light;
vertical-align: middle;
font-size: 18px;
font-size: 20px;
color: $color-font-secondary;
display: none;

View File

@ -1,3 +1,5 @@
const NotFoundError = require('vn-loopback/util/not-found-error');
module.exports = Self => {
Self.remoteMethod('pitInstance', {
description: 'Gets the status of instance at specific point in time',
@ -21,24 +23,40 @@ module.exports = Self => {
Self.pitInstance = async function(id) {
const log = await Self.findById(id, {
fields: ['changedModel', 'changedModelId']
fields: [
'changedModel',
'changedModelId',
'creationDate'
]
});
if (!log)
throw new NotFoundError();
const where = {
changedModel: log.changedModel,
changedModelId: log.changedModelId
};
const createdWhere = {action: 'insert'};
const createdWhere = {
action: 'insert',
creationDate: {lte: log.creationDate}
};
const createdLog = await Self.findOne({
fields: ['id'],
where: Object.assign(createdWhere, where)
fields: ['id', 'creationDate'],
where: Object.assign(createdWhere, where),
order: 'creationDate 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 logs = await Self.find({
@ -46,6 +64,8 @@ module.exports = Self => {
where: Object.assign(logsWhere, where),
order: 'creationDate'
});
if (!logs.length)
throw new NotFoundError('No logs found for record');
const instance = {};
for (const log of logs)