merge
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
commit
3afedbd89b
|
@ -0,0 +1,126 @@
|
||||||
|
|
||||||
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
|
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||||
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('filter', {
|
||||||
|
description: 'Find all instances of the model matched by filter from the data source.',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'Object',
|
||||||
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'tags',
|
||||||
|
type: ['Object'],
|
||||||
|
description: 'List of tags to filter with',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'search',
|
||||||
|
type: 'String',
|
||||||
|
description: `If it's and integer searchs by id, otherwise it searchs by name`,
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'id',
|
||||||
|
type: 'Integer',
|
||||||
|
description: 'The worker id',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'fi',
|
||||||
|
type: 'String',
|
||||||
|
description: 'The worker fi',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'departmentFk',
|
||||||
|
type: 'Integer',
|
||||||
|
description: 'The worker department id',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'extension',
|
||||||
|
type: 'Integer',
|
||||||
|
description: 'The worker extension id',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'firstName',
|
||||||
|
type: 'String',
|
||||||
|
description: 'The worker firstName',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'name',
|
||||||
|
type: 'String',
|
||||||
|
description: 'The worker name',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'nickname',
|
||||||
|
type: 'String',
|
||||||
|
description: 'The worker name',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['Object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/filter`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.filter = async(ctx, filter) => {
|
||||||
|
let conn = Self.dataSource.connector;
|
||||||
|
|
||||||
|
let where = buildFilter(ctx.args, (param, value) => {
|
||||||
|
switch (param) {
|
||||||
|
case 'search':
|
||||||
|
return /^\d+$/.test(value)
|
||||||
|
? {'w.id': value}
|
||||||
|
: {or: [
|
||||||
|
{'w.firstName': {like: `%${value}%`}},
|
||||||
|
{'w.name': {like: `%${value}%`}}
|
||||||
|
]};
|
||||||
|
case 'id':
|
||||||
|
return {'w.id': value};
|
||||||
|
case 'name':
|
||||||
|
return {'w.name': {like: `%${value}%`}};
|
||||||
|
case 'firstName':
|
||||||
|
return {'w.firstName': {like: `%${value}%`}};
|
||||||
|
case 'extension':
|
||||||
|
return {'p.extension': value};
|
||||||
|
case 'fi':
|
||||||
|
return {'c.fi': value};
|
||||||
|
case 'departmentFk':
|
||||||
|
return {'d.id': value};
|
||||||
|
case 'userName':
|
||||||
|
return {'u.name': {like: `%${value}%`}};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filter = mergeFilters(ctx.args.filter, {where});
|
||||||
|
|
||||||
|
let stmts = [];
|
||||||
|
let stmt;
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(
|
||||||
|
`SELECT w.id, u.email, p.extension, u.name as userName,
|
||||||
|
d.name AS department, w.name, u.nickname
|
||||||
|
FROM worker w
|
||||||
|
LEFT JOIN workerDepartment wd ON wd.workerFk = w.id
|
||||||
|
LEFT JOIN department d ON d.id = wd.departmentFk
|
||||||
|
LEFT JOIN client c ON c.id = w.userFk
|
||||||
|
LEFT JOIN account.user u ON u.id = w.userFk
|
||||||
|
LEFT JOIN pbx.sip p ON p.user_id = u.id`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
|
let itemsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
|
let sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
let result = await conn.executeStmt(sql);
|
||||||
|
return itemsIndex === 0 ? result : result[itemsIndex];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/worker/filter')(Self);
|
||||||
|
};
|
|
@ -1,8 +1,8 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="/agency/api/Workers"
|
url="/agency/api/Workers/filter"
|
||||||
include="::$ctrl.include"
|
|
||||||
limit="20"
|
limit="20"
|
||||||
|
order="id"
|
||||||
data="workers">
|
data="workers">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<div class="content-block">
|
<div class="content-block">
|
||||||
|
@ -10,8 +10,7 @@
|
||||||
<vn-card pad-medium-h>
|
<vn-card pad-medium-h>
|
||||||
<vn-searchbar
|
<vn-searchbar
|
||||||
panel="vn-worker-search-panel"
|
panel="vn-worker-search-panel"
|
||||||
model="model"
|
on-search="$ctrl.onSearch($params)"
|
||||||
expr-builder="$ctrl.exprBuilder(param, value)"
|
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
|
@ -23,21 +22,18 @@
|
||||||
class="vn-list-item searchResult">
|
class="vn-list-item searchResult">
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-one>
|
<vn-one>
|
||||||
<h6>{{::worker.user.nickname}}</h6>
|
<h6>{{::worker.nickname}}</h6>
|
||||||
<vn-label-value label="Id"
|
<vn-label-value label="Id"
|
||||||
value="{{::worker.id}}">
|
value="{{::worker.id}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="User"
|
<vn-label-value label="User"
|
||||||
value="{{::worker.user.nickname}}">
|
value="{{::worker.userName}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Email"
|
<vn-label-value label="Email"
|
||||||
value="{{::worker.user.email}}">
|
value="{{::worker.userName}}@verdnatura.es">
|
||||||
</vn-label-value>
|
|
||||||
<vn-label-value label="Fiscal identifier"
|
|
||||||
value="{{::worker.client.fi}}">
|
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Department"
|
<vn-label-value label="Department"
|
||||||
value="{{::worker.department.department}}">
|
value="{{::worker.department}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
</vn-one>
|
</vn-one>
|
||||||
<vn-horizontal class="buttons">
|
<vn-horizontal class="buttons">
|
||||||
|
|
|
@ -5,33 +5,14 @@ export default class Controller {
|
||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
$,
|
$,
|
||||||
selectedWorker: null,
|
selectedWorker: null,
|
||||||
include: [
|
|
||||||
{
|
|
||||||
relation: 'user',
|
|
||||||
scope: {fields: ['nickname', 'email']}
|
|
||||||
}, {
|
|
||||||
relation: 'client',
|
|
||||||
scope: {fields: ['fi']}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exprBuilder(param, value) {
|
onSearch(params) {
|
||||||
switch (param) {
|
if (params)
|
||||||
case 'search':
|
this.$.model.applyFilter(null, params);
|
||||||
return /^\d+$/.test(value)
|
else
|
||||||
? {id: value}
|
this.$.model.clear();
|
||||||
: {or: [
|
|
||||||
{firstName: {like: `%${value}%`}},
|
|
||||||
{name: {like: `%${value}%`}}
|
|
||||||
]};
|
|
||||||
case 'name':
|
|
||||||
case 'firstName':
|
|
||||||
return {[param]: {like: `%${value}%`}};
|
|
||||||
case 'id':
|
|
||||||
return {[param]: value};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
preview(event, worker) {
|
preview(event, worker) {
|
||||||
|
|
|
@ -9,3 +9,7 @@ Role: Rol
|
||||||
Extension: Extensión
|
Extension: Extensión
|
||||||
Go to client: Ir al cliente
|
Go to client: Ir al cliente
|
||||||
Private Branch Exchange: Centralita
|
Private Branch Exchange: Centralita
|
||||||
|
View worker: Ver trabajador
|
||||||
|
Worker id: Id trabajador
|
||||||
|
Fiscal Identifier: NIF
|
||||||
|
User name: Usuario
|
||||||
|
|
|
@ -11,22 +11,54 @@
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Id"
|
label="Worker id"
|
||||||
model="filter.id">
|
model="filter.id">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Name"
|
label="User id"
|
||||||
model="filter.firstName">
|
model="filter.id">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
<vn-textfield
|
||||||
|
vn-one
|
||||||
|
label="Name"
|
||||||
|
model="filter.firstName">
|
||||||
|
</vn-textfield>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
vn-one
|
vn-one
|
||||||
label="Last name"
|
label="Last name"
|
||||||
model="filter.name">
|
model="filter.name">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-textfield
|
||||||
|
vn-one
|
||||||
|
label="User name"
|
||||||
|
model="filter.userName">
|
||||||
|
</vn-textfield>
|
||||||
|
<vn-textfield
|
||||||
|
vn-one
|
||||||
|
label="Fiscal Identifier"
|
||||||
|
model="filter.fi">
|
||||||
|
</vn-textfield>
|
||||||
|
</vn-horizontal>
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-autocomplete
|
||||||
|
vn-one
|
||||||
|
field="filter.departmentFk"
|
||||||
|
url="/api/Departments"
|
||||||
|
show-field="name"
|
||||||
|
value-field="id"
|
||||||
|
label="Department">
|
||||||
|
</vn-autocomplete>
|
||||||
|
<vn-textfield
|
||||||
|
vn-one
|
||||||
|
label="Extension"
|
||||||
|
model="filter.extension">
|
||||||
|
</vn-textfield>
|
||||||
|
</vn-horizontal>
|
||||||
<vn-horizontal margin-large-top>
|
<vn-horizontal margin-large-top>
|
||||||
<vn-submit label="Search"></vn-submit>
|
<vn-submit label="Search"></vn-submit>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
|
Loading…
Reference in New Issue