parent
7660d76850
commit
f70df714df
|
@ -479,9 +479,6 @@ export default {
|
|||
fourthBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(4) > vn-td.balance > span',
|
||||
firstBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(1) > vn-td.balance'
|
||||
},
|
||||
itemLog: {
|
||||
anyLineCreated: 'vn-item-log > vn-log vn-tbody > vn-tr',
|
||||
},
|
||||
ticketSummary: {
|
||||
header: 'vn-ticket-summary > vn-card > h5',
|
||||
state: 'vn-ticket-summary vn-label-value[label="State"] > section > span',
|
||||
|
@ -667,15 +664,6 @@ export default {
|
|||
thirdRemoveRequestButton: 'vn-ticket-request-index vn-tr:nth-child(3) vn-icon[icon="delete"]',
|
||||
thirdRequestQuantity: 'vn-ticket-request-index vn-table vn-tr:nth-child(3) > vn-td:nth-child(6) vn-input-number',
|
||||
saveButton: 'vn-ticket-request-create button[type=submit]',
|
||||
|
||||
},
|
||||
ticketLog: {
|
||||
firstTD: 'vn-ticket-log vn-table vn-td:nth-child(1)',
|
||||
logButton: 'vn-left-menu a[ui-sref="ticket.card.log"]',
|
||||
user: 'vn-ticket-log vn-tbody vn-tr vn-td:nth-child(2)',
|
||||
action: 'vn-ticket-log vn-tbody vn-tr vn-td:nth-child(4)',
|
||||
changes: 'vn-ticket-log vn-data-viewer vn-tbody vn-tr table tr:nth-child(2) td.after',
|
||||
id: 'vn-ticket-log vn-tr:nth-child(1) table tr:nth-child(1) td.before'
|
||||
},
|
||||
ticketService: {
|
||||
addServiceButton: 'vn-ticket-service vn-icon-button[vn-tooltip="Add service"] > button',
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
vn-id="model"
|
||||
url="{{$ctrl.url}}"
|
||||
filter="$ctrl.filter"
|
||||
link="{originFk: $ctrl.originId}"
|
||||
where="{changedModel: $ctrl.changedModel, changedModelId: $ctrl.changedModelId}"
|
||||
data="$ctrl.logs"
|
||||
order="creationDate DESC, id DESC"
|
||||
limit="20">
|
||||
|
@ -17,90 +15,107 @@
|
|||
<vn-data-viewer
|
||||
model="model"
|
||||
class="vn-w-sm vn-px-sm vn-pb-xl">
|
||||
<div class="change vn-mb-sm" ng-repeat="log in $ctrl.logs">
|
||||
<div class="left">
|
||||
<vn-avatar class="vn-mt-xs"
|
||||
ng-class="::{system: !log.user}"
|
||||
val="{{::log.user ? log.user.nickname : $ctrl.$t('System')}}"
|
||||
ng-click="$ctrl.showWorkerDescriptor($event, log)">
|
||||
<img
|
||||
ng-if="::log.user.image"
|
||||
ng-src="/api/Images/user/160x160/{{::log.userFk}}/download?access_token={{::$ctrl.vnToken.token}}">
|
||||
</img>
|
||||
</vn-avatar>
|
||||
<div class="arrow bg-panel"></div>
|
||||
<div class="origin-log" ng-repeat="originLog in $ctrl.logTree">
|
||||
<div class="origin-info" ng-if="::$ctrl.logTree.length > 1">
|
||||
<div class="line"></div>
|
||||
<div class="origin-id">
|
||||
{{$ctrl.modelI18n}} #{{::originLog.originFk}}
|
||||
</div>
|
||||
</div>
|
||||
<vn-card class="detail">
|
||||
<div class="header vn-pa-sm">
|
||||
<div class="action-model">
|
||||
<span class="model-name"
|
||||
ng-if="::$ctrl.showModelName && log.changedModel"
|
||||
ng-style="::{backgroundColor: $ctrl.hashToColor(log.changedModel)}"
|
||||
title="{{::log.changedModel}}">
|
||||
{{::log.changedModelI18n}}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="action-date text-secondary text-caption vn-ml-sm"
|
||||
title="{{::log.creationDate | date:'dd/MM/yyyy HH:mm:ss'}}">
|
||||
{{::$ctrl.relativeDate(log.creationDate)}}
|
||||
<vn-icon
|
||||
class="action vn-ml-xs"
|
||||
ng-class="::$ctrl.actionsClass[log.action]"
|
||||
icon="{{::$ctrl.actionsIcon[log.action]}}"
|
||||
translate-attr="::{title: $ctrl.actionsText[log.action]}">
|
||||
</vn-icon>
|
||||
</div>
|
||||
<div class="user-log vn-mb-sm" ng-repeat="userLog in ::originLog.logs">
|
||||
<div class="timeline">
|
||||
<vn-avatar
|
||||
ng-class="::{system: !userLog.user}"
|
||||
val="{{::userLog.user ? userLog.user.nickname : $ctrl.$t('System')}}"
|
||||
ng-click="$ctrl.showWorkerDescriptor($event, userLog)">
|
||||
<img
|
||||
ng-if="::userLog.user.image"
|
||||
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="line"></div>
|
||||
</div>
|
||||
<div class="model vn-pb-sm vn-px-sm"
|
||||
ng-if="::$ctrl.showModelName">
|
||||
<span class="model-id" ng-if="::log.changedModelId">#{{::log.changedModelId}}</span>
|
||||
<vn-icon
|
||||
icon="filter_alt"
|
||||
translate-attr="{title: 'Show all record changes'}"
|
||||
ng-click="$ctrl.filterByEntity(log)">
|
||||
</vn-icon>
|
||||
<span class="model-value" title="{{::log.changedModelValue}}">{{::log.changedModelValue}}</span>
|
||||
</div>
|
||||
<div class="changes vn-pa-sm"
|
||||
ng-class="{expanded: log.expand}"
|
||||
ng-if="::log.props.length || log.description">
|
||||
<vn-icon
|
||||
icon="expand_more"
|
||||
translate-attr="{title: 'Details'}"
|
||||
ng-click="log.expand = !log.expand">
|
||||
</vn-icon>
|
||||
<span ng-if="::log.props.length"
|
||||
class="attributes">
|
||||
<span ng-if="!log.expand" ng-repeat="prop in ::log.props"
|
||||
class="basic-json">
|
||||
<span class="json-field" title="{{::prop.name}}">
|
||||
{{::prop.nameI18n}}:
|
||||
<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">
|
||||
<vn-icon
|
||||
icon="filter_alt"
|
||||
translate-attr="{title: 'Show all record changes'}"
|
||||
ng-click="$ctrl.filterByEntity(modelLog)">
|
||||
</vn-icon>
|
||||
<span class="model-name"
|
||||
ng-if="::$ctrl.showModelName && modelLog.model"
|
||||
ng-style="::{backgroundColor: $ctrl.hashToColor(modelLog.model)}"
|
||||
title="{{::modelLog.model}}">
|
||||
{{::modelLog.modelI18n}}
|
||||
</span>
|
||||
<vn-json-value value="::prop.val.val"></vn-json-value><span ng-if="::!$last">,</span>
|
||||
</span>
|
||||
<div ng-if="log.expand" class="expanded-json">
|
||||
<div ng-repeat="prop in ::log.props">
|
||||
<span class="json-field" title="{{::prop.name}}">
|
||||
{{::prop.nameI18n}}:
|
||||
</span>
|
||||
<vn-log-value val="::prop.val"></vn-log-value>
|
||||
<span ng-if="::log.action == 'update'">
|
||||
← <vn-log-value val="::prop.old"></vn-log-value>
|
||||
</span>
|
||||
</div>
|
||||
<span class="model-id" ng-if="::modelLog.id">#{{::modelLog.id}}</span>
|
||||
<span class="model-value" title="{{::modelLog.showValue}}">{{::modelLog.showValue}}</span>
|
||||
</div>
|
||||
</span>
|
||||
<span ng-if="::!log.props.length" class="description">
|
||||
{{::log.description}}
|
||||
</span>
|
||||
</vn-card>
|
||||
<vn-card class="changes-log vn-mb-xs" ng-repeat="log in ::modelLog.logs">
|
||||
<div class="change-info vn-pa-sm">
|
||||
<div
|
||||
class="date text-secondary text-caption vn-mr-sm"
|
||||
title="{{::log.creationDate | date:'dd/MM/yyyy HH:mm:ss'}}">
|
||||
{{::$ctrl.relativeDate(log.creationDate)}}
|
||||
</div>
|
||||
<div>
|
||||
<vn-icon
|
||||
class="pit vn-ml-xs"
|
||||
icon="visibility"
|
||||
translate-attr="::{title: 'View record at this point in time'}"
|
||||
ng-click="$ctrl.viewPitInstance($event, log.id, modelLog)">
|
||||
</vn-icon>
|
||||
<vn-icon
|
||||
class="action vn-ml-xs"
|
||||
ng-class="::$ctrl.actionsClass[log.action]"
|
||||
icon="{{::$ctrl.actionsIcon[log.action]}}"
|
||||
translate-attr="::{title: $ctrl.actionsText[log.action]}">
|
||||
</vn-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="change-detail vn-pa-sm"
|
||||
ng-class="{expanded: log.expand}"
|
||||
ng-if="::log.props.length || log.description">
|
||||
<vn-icon
|
||||
icon="expand_more"
|
||||
translate-attr="{title: 'Details'}"
|
||||
ng-click="log.expand = !log.expand">
|
||||
</vn-icon>
|
||||
<span ng-if="::log.props.length"
|
||||
class="attributes">
|
||||
<span ng-if="!log.expand" ng-repeat="prop in ::log.props"
|
||||
class="basic-json">
|
||||
<span class="json-field" title="{{::prop.name}}">
|
||||
{{::prop.nameI18n}}:
|
||||
</span>
|
||||
<vn-json-value value="::prop.val.val"></vn-json-value><span ng-if="::!$last">,</span>
|
||||
</span>
|
||||
<div ng-if="log.expand" class="expanded-json">
|
||||
<div ng-repeat="prop in ::log.props">
|
||||
<span class="json-field" title="{{::prop.name}}">
|
||||
{{::prop.nameI18n}}:
|
||||
</span>
|
||||
<vn-log-value val="::prop.val"></vn-log-value>
|
||||
<span ng-if="::log.action == 'update'">
|
||||
← <vn-log-value val="::prop.old"></vn-log-value>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
<span ng-if="::!log.props.length" class="description">
|
||||
{{::log.description}}
|
||||
</span>
|
||||
</vn-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</vn-data-viewer>
|
||||
<vn-float-button
|
||||
ng-if="model.userFilter"
|
||||
ng-if="$ctrl.hasFilter"
|
||||
icon="filter_alt_off"
|
||||
translate-attr="{title: 'Quit filter'}"
|
||||
ng-click="$ctrl.resetFilter()"
|
||||
|
@ -212,5 +227,33 @@
|
|||
</vn-date-picker>
|
||||
</form>
|
||||
</vn-side-menu>
|
||||
<vn-worker-descriptor-popover vn-id="workerDescriptor">
|
||||
<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
|
||||
ng-if="$ctrl.instance.canceler"
|
||||
class="loading vn-pa-sm"
|
||||
enable="true">
|
||||
</vn-spinner>
|
||||
<div
|
||||
ng-if="!$ctrl.instance.canceler" class="instance">
|
||||
<div class="header vn-pa-sm">
|
||||
{{$ctrl.instance.modelLog.modelI18n}} #{{$ctrl.instance.modelLog.id}}
|
||||
</div>
|
||||
<div class="change-detail vn-pa-sm">
|
||||
<div ng-if="$ctrl.instance.props"
|
||||
ng-repeat="prop in $ctrl.instance.props">
|
||||
<span class="json-field" title="{{::prop.name}}">
|
||||
{{::prop.nameI18n}}:
|
||||
</span>
|
||||
<vn-log-value val="::prop.val"></vn-log-value>
|
||||
</div>
|
||||
<div ng-if="!$ctrl.instance.props" translate>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</tpl-body>
|
||||
</vn-popover>
|
||||
|
|
|
@ -3,7 +3,10 @@ import Section from '../section';
|
|||
import {hashToColor} from 'core/lib/string';
|
||||
import './style.scss';
|
||||
|
||||
const validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/;
|
||||
const validDate = new RegExp(
|
||||
/^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])/.source
|
||||
+ /T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/.source
|
||||
);
|
||||
|
||||
export default class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
|
@ -28,6 +31,20 @@ export default class Controller extends Section {
|
|||
select: 'visibility'
|
||||
};
|
||||
this.filter = {
|
||||
fields: [
|
||||
'id',
|
||||
'originFk',
|
||||
'userFk',
|
||||
'action',
|
||||
'changedModel',
|
||||
'oldInstance',
|
||||
'newInstance',
|
||||
'creationDate',
|
||||
'changedModel',
|
||||
'changedModelId',
|
||||
'changedModelValue',
|
||||
'description'
|
||||
],
|
||||
include: [{
|
||||
relation: 'user',
|
||||
scope: {
|
||||
|
@ -48,6 +65,12 @@ export default class Controller extends Section {
|
|||
this.today.setHours(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
const match = this.url?.match(/(.*)Logs$/);
|
||||
this.model = match && match[1];
|
||||
this.modelI18n = this.translateModel(this.model);
|
||||
}
|
||||
|
||||
$postLink() {
|
||||
this.resetFilter();
|
||||
this.$.$watch(
|
||||
|
@ -63,47 +86,80 @@ export default class Controller extends Section {
|
|||
|
||||
set logs(value) {
|
||||
this._logs = value;
|
||||
this.logTree = [];
|
||||
if (!value) return;
|
||||
|
||||
const empty = {};
|
||||
const validations = window.validations;
|
||||
const castJsonValue = this.castJsonValue;
|
||||
|
||||
for (const log of value) {
|
||||
let originLog;
|
||||
let userLog;
|
||||
let modelLog;
|
||||
let nLogs;
|
||||
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const log = value[i];
|
||||
const prevLog = i > 0 ? value[i - 1] : null;
|
||||
const locale = validations[log.changedModel]?.locale || empty;
|
||||
|
||||
// Origin
|
||||
|
||||
const originChanged = !prevLog
|
||||
|| log.originFk != prevLog.originFk;
|
||||
if (originChanged) {
|
||||
this.logTree.push(originLog = {
|
||||
originFk: log.originFk,
|
||||
logs: []
|
||||
});
|
||||
}
|
||||
|
||||
// User
|
||||
|
||||
const day = 86400 * 1000;
|
||||
const time = new Date(log.creationDate).getTime();
|
||||
const prevTime = prevLog && new Date(prevLog.creationDate).getTime();
|
||||
const userChanged = !prevLog
|
||||
|| log.userFk != prevLog.userFk
|
||||
|| time < prevTime - day * 2
|
||||
|| nLogs >= 10;
|
||||
|
||||
if (userChanged) {
|
||||
originLog.logs.push(userLog = {
|
||||
user: log.user,
|
||||
userFk: log.userFk,
|
||||
logs: []
|
||||
});
|
||||
nLogs = 0;
|
||||
}
|
||||
nLogs++;
|
||||
|
||||
// Model
|
||||
|
||||
const modelChanged = userChanged
|
||||
|| log.changedModel != prevLog.changedModel
|
||||
|| log.changedModelId != prevLog.changedModelId;
|
||||
if (modelChanged) {
|
||||
userLog.logs.push(modelLog = {
|
||||
model: log.changedModel,
|
||||
modelI18n: firstUpper(locale.name) || log.changedModel,
|
||||
id: log.changedModelId,
|
||||
showValue: log.changedModelValue,
|
||||
logs: []
|
||||
});
|
||||
}
|
||||
|
||||
modelLog.logs.push(log);
|
||||
|
||||
// Changes
|
||||
|
||||
const notDelete = log.action != 'delete';
|
||||
const olds = (notDelete ? log.oldInstance : null) || empty;
|
||||
const vals = (notDelete ? log.newInstance : log.oldInstance) || empty;
|
||||
const locale = validations[log.changedModel]?.locale || empty;
|
||||
log.changedModelI18n = firstUpper(locale.name) || log.changedModel;
|
||||
|
||||
let props = Object.keys(olds).concat(Object.keys(vals));
|
||||
props = [...new Set(props)];
|
||||
let propNames = Object.keys(olds).concat(Object.keys(vals));
|
||||
propNames = [...new Set(propNames)];
|
||||
|
||||
log.props = [];
|
||||
for (const prop of props) {
|
||||
if (prop.endsWith('$')) continue;
|
||||
log.props.push({
|
||||
name: prop,
|
||||
nameI18n: firstUpper(locale.columns?.[prop]) || prop,
|
||||
old: getVal(olds, prop),
|
||||
val: getVal(vals, prop)
|
||||
});
|
||||
}
|
||||
log.props.sort(
|
||||
(a, b) => a.nameI18n.localeCompare(b.nameI18n));
|
||||
}
|
||||
|
||||
function getVal(vals, prop) {
|
||||
let val, id;
|
||||
const showProp = `${prop}$`;
|
||||
|
||||
if (vals[showProp] != null) {
|
||||
val = vals[showProp];
|
||||
id = vals[prop];
|
||||
} else
|
||||
val = vals[prop];
|
||||
|
||||
return {val: castJsonValue(val), id};
|
||||
log.props = this.parseProps(propNames, locale, vals, olds);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,17 +170,76 @@ export default class Controller extends Section {
|
|||
set models(value) {
|
||||
this._models = value;
|
||||
if (!value) return;
|
||||
for (const model of value) {
|
||||
const name = model.changedModel;
|
||||
model.changedModelI18n =
|
||||
firstUpper(window.validations[name]?.locale?.name) || name;
|
||||
}
|
||||
for (const model of value)
|
||||
model.changedModelI18n = this.translateModel(model.changedModel);
|
||||
}
|
||||
|
||||
get showModelName() {
|
||||
return !(this.changedModel && this.changedModelId);
|
||||
}
|
||||
|
||||
parseProps(propNames, locale, vals, olds) {
|
||||
const castJsonValue = this.castJsonValue;
|
||||
const props = [];
|
||||
|
||||
for (const prop of propNames) {
|
||||
if (prop.endsWith('$')) continue;
|
||||
props.push({
|
||||
name: prop,
|
||||
nameI18n: firstUpper(locale.columns?.[prop]) || prop,
|
||||
old: getVal(olds, prop),
|
||||
val: getVal(vals, prop)
|
||||
});
|
||||
}
|
||||
props.sort(
|
||||
(a, b) => a.nameI18n.localeCompare(b.nameI18n));
|
||||
|
||||
function getVal(vals, prop) {
|
||||
let val; let id;
|
||||
const showProp = `${prop}$`;
|
||||
|
||||
if (vals[showProp] != null) {
|
||||
val = vals[showProp];
|
||||
id = vals[prop];
|
||||
} else
|
||||
val = vals[prop];
|
||||
|
||||
return {val: castJsonValue(val), id};
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
viewPitInstance(event, id, modelLog) {
|
||||
if (this.instance?.canceler)
|
||||
this.instance.canceler.resolve();
|
||||
|
||||
const canceler = this.$q.defer();
|
||||
this.instance = {
|
||||
modelLog,
|
||||
canceler
|
||||
};
|
||||
const options = {timeout: canceler.promise};
|
||||
|
||||
this.$http.get(`${this.url}/${id}/pitInstance`, options)
|
||||
.then(res => {
|
||||
const instance = res.data;
|
||||
const propNames = Object.keys(instance);
|
||||
const locale = window.validations[modelLog.model]?.locale || {};
|
||||
this.instance.props = this.parseProps(propNames, locale, instance, {});
|
||||
})
|
||||
.finally(() => {
|
||||
this.instance.canceler = null;
|
||||
this.$.$applyAsync(() => this.$.instancePopover.relocate());
|
||||
});
|
||||
|
||||
this.$.instancePopover.show(event);
|
||||
}
|
||||
|
||||
translateModel(name) {
|
||||
return firstUpper(window.validations[name]?.locale?.name) || name;
|
||||
}
|
||||
|
||||
castJsonValue(value) {
|
||||
return typeof value === 'string' && validDate.test(value)
|
||||
? new Date(value)
|
||||
|
@ -160,12 +275,11 @@ export default class Controller extends Section {
|
|||
applyFilter() {
|
||||
const filter = this.$.filter;
|
||||
|
||||
function getParam(prop, value) {
|
||||
const getParam = (prop, value) => {
|
||||
if (value == null || value == '') return null;
|
||||
switch (prop) {
|
||||
case 'search':
|
||||
const or = [];
|
||||
if (/^\s*[0-9]+\s*$/.test(value))
|
||||
if (/^\s*[0-9]+\s*$/.test(value) || this.byEntity)
|
||||
return {changedModelId: value.trim()};
|
||||
else
|
||||
return {changedModelValue: {like: `%${value}%`}};
|
||||
|
@ -177,72 +291,86 @@ export default class Controller extends Section {
|
|||
]};
|
||||
case 'who':
|
||||
switch (value) {
|
||||
case 'all':
|
||||
return null;
|
||||
case 'user':
|
||||
return {userFk: {neq: null}};
|
||||
case 'system':
|
||||
return {userFk: null};
|
||||
case 'all':
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
case 'actions':
|
||||
case 'actions': {
|
||||
const inq = [];
|
||||
for (const action in value) {
|
||||
if (value[action])
|
||||
inq.push(action);
|
||||
}
|
||||
return inq.length ? {action: {inq}} : null;
|
||||
}
|
||||
case 'from':
|
||||
if (filter.to) {
|
||||
if (filter.to)
|
||||
return {creationDate: {gte: value}};
|
||||
} else {
|
||||
else {
|
||||
const to = new Date(value);
|
||||
to.setHours(23, 59, 59, 999);
|
||||
return {creationDate: {between: [value, to]}};
|
||||
}
|
||||
case 'to':
|
||||
case 'to': {
|
||||
const to = new Date(value);
|
||||
to.setHours(23, 59, 59, 999);
|
||||
return {creationDate: {lte: to}};
|
||||
}
|
||||
case 'userFk':
|
||||
return filter.who != 'system'
|
||||
? {[prop]: value} : null;
|
||||
default:
|
||||
return {[prop]: value};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.hasFilter = false;
|
||||
const and = [];
|
||||
|
||||
if (!filter.search || !filter.changedModel)
|
||||
this.byEntity = false;
|
||||
if (!this.byEntity)
|
||||
and.push({originFk: this.originId});
|
||||
|
||||
for (const prop in filter) {
|
||||
const param = getParam(prop, filter[prop]);
|
||||
if (param) and.push(param);
|
||||
if (param) {
|
||||
and.push(param);
|
||||
this.hasFilter = true;
|
||||
}
|
||||
}
|
||||
|
||||
const lbFilter = and.length ? {where: {and}} : null;
|
||||
return this.$.model.applyFilter(lbFilter);
|
||||
}
|
||||
|
||||
filterByEntity(log) {
|
||||
filterByEntity(modelLog) {
|
||||
this.byEntity = true;
|
||||
this.$.filter = {
|
||||
who: 'all',
|
||||
search: log.changedModelId,
|
||||
changedModel: log.changedModel
|
||||
search: modelLog.id,
|
||||
changedModel: modelLog.model
|
||||
};
|
||||
}
|
||||
|
||||
searchUser(search) {
|
||||
if (/^[0-9]+$/.test(search)) {
|
||||
if (/^[0-9]+$/.test(search))
|
||||
return {id: search};
|
||||
} else {
|
||||
else {
|
||||
return {or: [
|
||||
{name: search},
|
||||
{nickname: {like: `%${search}%`}}
|
||||
]}
|
||||
]};
|
||||
}
|
||||
}
|
||||
|
||||
showWorkerDescriptor(event, log) {
|
||||
if (log.user?.worker)
|
||||
this.$.workerDescriptor.show(event.target, log.userFk);
|
||||
showWorkerDescriptor(event, userLog) {
|
||||
if (userLog.user?.worker)
|
||||
this.$.workerDescriptor.show(event.target, userLog.userFk);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,4 +24,5 @@ Changes: Cambios
|
|||
today: hoy
|
||||
yesterday: ayer
|
||||
Show all record changes: Mostrar todos los cambios realizados en el registro
|
||||
View record at this point in time: Ver el registro en este punto
|
||||
Quit filter: Quitar filtro
|
||||
|
|
|
@ -1,13 +1,49 @@
|
|||
@import "util";
|
||||
|
||||
vn-log {
|
||||
.change {
|
||||
.origin-log {
|
||||
& > .origin-info {
|
||||
display: flex;
|
||||
text-align: right;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
column-gap: 4px;
|
||||
padding-left: 48px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
& > .line {
|
||||
flex-grow: 1;
|
||||
background-color: $color-font-secondary;
|
||||
height: 2px;
|
||||
}
|
||||
& > .origin-id {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
font-size: 1.1rem;
|
||||
color: $color-font-secondary;
|
||||
}
|
||||
}
|
||||
}
|
||||
.user-log {
|
||||
display: flex;
|
||||
|
||||
& > .left {
|
||||
& > .timeline {
|
||||
position: relative;
|
||||
padding-right: 10px;
|
||||
width: 38px;
|
||||
min-width: 38px;
|
||||
flex-grow: auto;
|
||||
|
||||
& > .arrow {
|
||||
height: 8px;
|
||||
width: 8px;
|
||||
position: absolute;
|
||||
transform: rotateY(0deg) rotate(45deg);
|
||||
top: 14px;
|
||||
right: -4px;
|
||||
z-index: 1;
|
||||
}
|
||||
& > vn-avatar {
|
||||
cursor: pointer;
|
||||
|
||||
|
@ -15,15 +51,6 @@ vn-log {
|
|||
background-color: $color-main !important;
|
||||
}
|
||||
}
|
||||
& > .arrow {
|
||||
height: 8px;
|
||||
width: 8px;
|
||||
position: absolute;
|
||||
transform: rotateY(0deg) rotate(45deg);
|
||||
top: 18px;
|
||||
right: -4px;
|
||||
z-index: 1;
|
||||
}
|
||||
& > .line {
|
||||
position: absolute;
|
||||
background-color: $color-main;
|
||||
|
@ -34,134 +61,173 @@ vn-log {
|
|||
bottom: -8px;
|
||||
}
|
||||
}
|
||||
&:last-child > .left > .line {
|
||||
&:last-child > .timeline > .line {
|
||||
display: none;
|
||||
}
|
||||
.detail {
|
||||
position: relative;
|
||||
& > .user-changes {
|
||||
flex-grow: 1;
|
||||
width: 100%;
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
.model-log {
|
||||
& > .model-info {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
margin-top: 6px;
|
||||
|
||||
& > .header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
& > .model-name {
|
||||
display: inline-block;
|
||||
padding: 2px 5px;
|
||||
color: $color-font-dark;
|
||||
border-radius: 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
& > .model-value {
|
||||
font-style: italic;
|
||||
}
|
||||
& > .model-id {
|
||||
color: $color-font-secondary;
|
||||
font-size: .9rem;
|
||||
}
|
||||
& > vn-icon[icon="filter_alt"] {
|
||||
@extend %clickable-light;
|
||||
vertical-align: middle;
|
||||
font-size: 18px;
|
||||
color: $color-font-secondary;
|
||||
float: right;
|
||||
display: none;
|
||||
|
||||
& > .action-model {
|
||||
display: inline-flex;
|
||||
overflow: hidden;
|
||||
|
||||
& > .model-name {
|
||||
display: inline-block;
|
||||
padding: 2px 5px;
|
||||
color: $color-font-dark;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
& > .action-date {
|
||||
white-space: nowrap;
|
||||
|
||||
& > .action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: $color-font-bg;
|
||||
vertical-align: middle;
|
||||
border-radius: 50%;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
font-size: 18px;
|
||||
|
||||
&.notice {
|
||||
background-color: $color-notice-medium
|
||||
}
|
||||
&.success {
|
||||
background-color: $color-success-medium;
|
||||
}
|
||||
&.warning {
|
||||
background-color: $color-main-medium;
|
||||
}
|
||||
&.alert {
|
||||
background-color: lighten($color-alert, 5%);
|
||||
}
|
||||
}
|
||||
@include mobile {
|
||||
display: initial;
|
||||
}
|
||||
}
|
||||
& > .model {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-height: 18px;
|
||||
}
|
||||
&:hover > .model-info > vn-icon[icon="filter_alt"] {
|
||||
display: initial;
|
||||
}
|
||||
}
|
||||
.changes-log {
|
||||
position: relative;
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
|
||||
& > vn-icon {
|
||||
& > .change-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
|
||||
& > .date {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
& > div {
|
||||
white-space: nowrap;
|
||||
|
||||
& > vn-icon.pit {
|
||||
@extend %clickable-light;
|
||||
vertical-align: middle;
|
||||
padding: 2px;
|
||||
margin: -2px;
|
||||
font-size: 18px;
|
||||
color: $color-font-secondary;
|
||||
float: right;
|
||||
display: none;
|
||||
|
||||
@include mobile {
|
||||
display: initial;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
& > .model-value {
|
||||
font-style: italic;
|
||||
}
|
||||
& > .model-id {
|
||||
color: $color-font-secondary;
|
||||
font-size: .9rem;
|
||||
}
|
||||
}
|
||||
&:hover > .model > vn-icon {
|
||||
display: initial;
|
||||
}
|
||||
}
|
||||
}
|
||||
.changes {
|
||||
overflow: hidden;
|
||||
background-color: rgba(255, 255, 255, .05);
|
||||
color: $color-font-light;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
min-height: 34px;
|
||||
box-sizing: border-box;
|
||||
& > .action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: $color-font-bg;
|
||||
vertical-align: middle;
|
||||
border-radius: 50%;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
font-size: 18px;
|
||||
|
||||
& > vn-icon {
|
||||
@extend %clickable;
|
||||
float: right;
|
||||
position: relative;
|
||||
transition-property: transform, background-color;
|
||||
transition-duration: 150ms;
|
||||
margin: -5px;
|
||||
margin-left: 4px;
|
||||
padding: 1px;
|
||||
border-radius: 50%;
|
||||
&.notice {
|
||||
background-color: $color-notice-medium
|
||||
}
|
||||
&.success {
|
||||
background-color: $color-success-medium;
|
||||
}
|
||||
&.warning {
|
||||
background-color: $color-main-medium;
|
||||
}
|
||||
&.alert {
|
||||
background-color: lighten($color-alert, 5%);
|
||||
}
|
||||
}
|
||||
}
|
||||
&:hover vn-icon.pit {
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
&.expanded {
|
||||
text-overflow: initial;
|
||||
white-space: initial;
|
||||
& > .change-detail {
|
||||
overflow: hidden;
|
||||
background-color: rgba(255, 255, 255, .05);
|
||||
color: $color-font-light;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
min-height: 34px;
|
||||
box-sizing: border-box;
|
||||
|
||||
& > vn-icon {
|
||||
transform: rotate(180deg);
|
||||
@extend %clickable;
|
||||
float: right;
|
||||
position: relative;
|
||||
transition-property: transform, background-color;
|
||||
transition-duration: 150ms;
|
||||
margin: -5px;
|
||||
margin-left: 4px;
|
||||
padding: 1px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
&.expanded {
|
||||
text-overflow: initial;
|
||||
white-space: initial;
|
||||
|
||||
& > vn-icon {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
& > .no-changes {
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
& > .no-changes {
|
||||
font-style: italic;
|
||||
}
|
||||
.id-value {
|
||||
font-size: .9rem;
|
||||
color: $color-font-secondary;
|
||||
}
|
||||
}
|
||||
.vn-log-instance {
|
||||
display: block;
|
||||
|
||||
& > .loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
& > .instance {
|
||||
min-width: 180px;
|
||||
max-width: 400px;
|
||||
|
||||
& > .header {
|
||||
background-color: $color-main;
|
||||
color: $color-font-dark;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
& > .change-detail {
|
||||
color: $color-font-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
vn-log-value > .id-value {
|
||||
font-size: .9rem;
|
||||
color: $color-font-secondary;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('pitInstance', {
|
||||
description: 'Gets the status of instance at specific point in time',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'integer',
|
||||
description: 'The log id',
|
||||
required: true
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: [Self],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/pitInstance`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.pitInstance = async function(id) {
|
||||
const log = await Self.findById(id, {
|
||||
fields: ['changedModel', 'changedModelId']
|
||||
});
|
||||
|
||||
const where = {
|
||||
changedModel: log.changedModel,
|
||||
changedModelId: log.changedModelId
|
||||
};
|
||||
|
||||
const createdWhere = {action: 'insert'};
|
||||
const createdLog = await Self.findOne({
|
||||
fields: ['id'],
|
||||
where: Object.assign(createdWhere, where)
|
||||
});
|
||||
|
||||
const logsWhere = {
|
||||
id: {between: [
|
||||
Math.min(id, createdLog.id),
|
||||
Math.max(id, createdLog.id)
|
||||
]}
|
||||
};
|
||||
const logs = await Self.find({
|
||||
fields: ['newInstance'],
|
||||
where: Object.assign(logsWhere, where),
|
||||
order: 'creationDate'
|
||||
});
|
||||
|
||||
const instance = {};
|
||||
for (const log of logs)
|
||||
Object.assign(instance, log.newInstance);
|
||||
|
||||
return instance;
|
||||
};
|
||||
};
|
|
@ -5,6 +5,7 @@ module.exports = function(Self) {
|
|||
Self.super_.setup.call(this);
|
||||
require('../methods/log/editors')(this);
|
||||
require('../methods/log/models')(this);
|
||||
require('../methods/log/pitInstance')(this);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const fs = require('fs-extra');
|
||||
|
||||
describe('InvoiceOut download()', () => {
|
||||
const userId = 9;
|
||||
const invoiceId = 1;
|
||||
const ctx = {
|
||||
req: {
|
||||
|
||||
accessToken: {userId: userId},
|
||||
headers: {origin: 'http://localhost:5000'},
|
||||
}
|
||||
};
|
||||
|
||||
it('should return the downloaded file name', async() => {
|
||||
spyOn(models.InvoiceContainer, 'container').and.returnValue({
|
||||
client: {root: '/path'}
|
||||
});
|
||||
spyOn(fs, 'createReadStream').and.returnValue(new Promise(resolve => resolve('streamObject')));
|
||||
spyOn(fs, 'access').and.returnValue(true);
|
||||
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(new Promise(resolve => resolve(true)));
|
||||
|
||||
const result = await models.InvoiceOut.download(ctx, invoiceId);
|
||||
|
||||
expect(result[1]).toEqual('application/pdf');
|
||||
expect(result[2]).toMatch(/filename="\d{4}T1111111.pdf"/);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue