refs #5517 Filter improved
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Juan Ferrer 2023-04-24 19:10:04 +02:00
parent a053764122
commit 49368a837b
22 changed files with 163 additions and 40 deletions

View File

@ -3,13 +3,18 @@
url="{{$ctrl.url}}"
filter="$ctrl.filter"
link="{originFk: $ctrl.originId}"
where="{changedModel: $ctrl.changedModel,
changedModelId: $ctrl.changedModelId}"
where="{changedModel: $ctrl.changedModel, changedModelId: $ctrl.changedModelId}"
data="$ctrl.logs"
order="creationDate DESC, id DESC"
limit="20"
auto-load="true">
</vn-crud-model>
<vn-crud-model
url="{{$ctrl.url}}/{{$ctrl.originId}}/models"
data="models"
order="changedModel"
auto-load="true">
</vn-crud-model>
<vn-data-viewer model="model" class="vn-w-md">
<vn-card>
<table class="vn-table" model="model">
@ -120,10 +125,13 @@
ng-submit="$ctrl.applyFilter(filter)"
ng-model-options="{updateOn: 'change blur'}"
class="vn-pa-md filter">
<vn-textfield
<vn-autocomplete
label="Model"
ng-model="filter.changedModel">
</vn-textfield>
ng-model="filter.changedModel"
value-field="changedModel"
show-field="changedModel"
data="models">
</vn-autocomplete>
<vn-textfield
label="Id"
ng-model="filter.changedModelId">
@ -135,7 +143,8 @@
show-field="nickname"
fields="['id', 'name', 'nickname']"
search-function="$ctrl.searchUser($search)"
url="VnUsers">
url="{{$ctrl.url}}/{{$ctrl.originId}}/editors"
order="nickname">
<tpl-item>
<div>{{nickname}}</div>
<div class="text-secondary text-caption">{{name}}</div>
@ -172,7 +181,7 @@
ng-model="filter.to">
</vn-date-picker>
<vn-button-bar vn-vertical class="vn-mt-sm">
<vn-submit label="Buscar"></vn-submit>
<vn-submit label="Filter"></vn-submit>
<vn-button
label="Reset"
class="flat"

View File

@ -21,9 +21,6 @@ export default class Controller extends Section {
};
$.filter = {};
$.$watch('filter.actions', () => this.applyFilter(), true);
$.$watch('filter.from', () => $.filter.to = $.filter.from);
this.filter = {
include: [{
relation: 'user',
@ -45,6 +42,23 @@ export default class Controller extends Section {
this.today.setHours(0, 0, 0, 0);
}
$onInit() {
const {$} = this;
$.$watch(
() => [
$.filter.actions,
$.filter.changedModel,
$.filter.userFk
],
() => this.applyFilter(),
true
);
$.$watch(
() => $.filter.from,
() => $.filter.to = $.filter.from
);
}
get logs() {
return this._logs;
}

View File

@ -0,0 +1,40 @@
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('editors', {
description: 'Get the list of entity editors',
accepts: [
{
arg: 'id',
type: 'integer',
description: 'The model id',
required: true
}, {
arg: 'filter',
type: 'Object',
description: 'The user filter object'
}
],
returns: {
type: [Self],
root: true
},
http: {
path: `/:id/editors`,
verb: 'GET'
}
});
Self.editors = async(id, filter) => {
const res = await Self.find({
fields: ['userFk'],
where: {originFk: id}
});
const userIds = new Set(res.map(x => x.userFk));
filter = mergeFilters(filter, {
where: {id: {inq: [...userIds]}}
});
return await Self.app.models.VnUser.find(filter);
};
};

View File

@ -0,0 +1,44 @@
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('models', {
description: 'Get the list of entity models',
accepts: [
{
arg: 'id',
type: 'integer',
description: 'The model id',
required: true
}, {
arg: 'filter',
type: 'Object',
description: 'The filter object'
}
],
returns: {
type: [Self],
root: true
},
http: {
path: `/:id/models`,
verb: 'GET'
}
});
Self.models = async(id, filter) => {
filter = mergeFilters(filter, {
fields: ['changedModel'],
where: {
originFk: id,
changedModel: {neq: null}
}
});
const res = await Self.find(filter);
const set = new Set();
return res.filter(x => set.has(x.changedModel)
? false
: set.add(x.changedModel)
);
};
};

View File

@ -0,0 +1,10 @@
module.exports = function(Self) {
Object.assign(Self, {
setup() {
Self.super_.setup.call(this);
require('../methods/log/editors')(this);
require('../methods/log/models')(this);
}
});
};

View File

@ -0,0 +1,4 @@
{
"name": "Log",
"base": "VnModel"
}

View File

@ -28,12 +28,14 @@ module.exports = function(Self) {
});
// Register field ACL validation
/* this.beforeRemote('prototype.patchAttributes', ctx => this.checkUpdateAcls(ctx));
/*
this.beforeRemote('prototype.patchAttributes', ctx => this.checkUpdateAcls(ctx));
this.beforeRemote('updateAll', ctx => this.checkUpdateAcls(ctx));
this.beforeRemote('patchOrCreate', ctx => this.checkInsertAcls(ctx));
this.beforeRemote('create', ctx => this.checkInsertAcls(ctx));
this.beforeRemote('replaceById', ctx => this.checkInsertAcls(ctx));
this.beforeRemote('replaceOrCreate', ctx => this.checkInsertAcls(ctx)); */
this.beforeRemote('replaceOrCreate', ctx => this.checkInsertAcls(ctx));
*/
this.remoteMethod('crud', {
description: `Create, update or/and delete instances from model with a single request`,

View File

@ -1,6 +1,6 @@
{
"name": "RoleLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "account.roleLog"

View File

@ -1,6 +1,6 @@
{
"name": "UserLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "account.userLog"

View File

@ -1,6 +1,6 @@
{
"name": "ClaimLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "claimLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "ClientLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "clientLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "EntryLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "entryLog"
@ -55,4 +55,4 @@
"scope": {
"order": ["creationDate DESC", "id DESC"]
}
}
}

View File

@ -1,6 +1,6 @@
{
"name": "InvoiceInLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "invoiceInLog"
@ -58,4 +58,4 @@
"id DESC"
]
}
}
}

View File

@ -1,6 +1,6 @@
{
"name": "ItemLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "itemLog"
@ -12,7 +12,7 @@
"type": "number",
"forceId": false
},
"originFk": {
"originFk": {
"type": "number",
"required": true
},
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "RouteLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "routeLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "ShelvingLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "shelvingLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "SupplierLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "supplierLog"
@ -55,4 +55,4 @@
"scope": {
"order": ["creationDate DESC", "id DESC"]
}
}
}

View File

@ -1,6 +1,6 @@
{
"name": "TicketLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "ticketLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "TravelLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "travelLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "DeviceProductionLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "deviceProductionLog"

View File

@ -1,6 +1,6 @@
{
"name": "WorkerLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "workerLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]

View File

@ -1,6 +1,6 @@
{
"name": "ZoneLog",
"base": "VnModel",
"base": "Log",
"options": {
"mysql": {
"table": "zoneLog"
@ -50,7 +50,7 @@
"type": "belongsTo",
"model": "VnUser",
"foreignKey": "userFk"
}
}
},
"scope": {
"order": ["creationDate DESC", "id DESC"]