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-id="model"
|
||||
url="/agency/api/Workers"
|
||||
include="::$ctrl.include"
|
||||
url="/agency/api/Workers/filter"
|
||||
limit="20"
|
||||
order="id"
|
||||
data="workers">
|
||||
</vn-crud-model>
|
||||
<div class="content-block">
|
||||
|
@ -10,8 +10,7 @@
|
|||
<vn-card pad-medium-h>
|
||||
<vn-searchbar
|
||||
panel="vn-worker-search-panel"
|
||||
model="model"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)"
|
||||
on-search="$ctrl.onSearch($params)"
|
||||
vn-focus>
|
||||
</vn-searchbar>
|
||||
</vn-card>
|
||||
|
@ -23,21 +22,18 @@
|
|||
class="vn-list-item searchResult">
|
||||
<vn-horizontal>
|
||||
<vn-one>
|
||||
<h6>{{::worker.user.nickname}}</h6>
|
||||
<h6>{{::worker.nickname}}</h6>
|
||||
<vn-label-value label="Id"
|
||||
value="{{::worker.id}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="User"
|
||||
value="{{::worker.user.nickname}}">
|
||||
value="{{::worker.userName}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Email"
|
||||
value="{{::worker.user.email}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Fiscal identifier"
|
||||
value="{{::worker.client.fi}}">
|
||||
value="{{::worker.userName}}@verdnatura.es">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Department"
|
||||
value="{{::worker.department.department}}">
|
||||
value="{{::worker.department}}">
|
||||
</vn-label-value>
|
||||
</vn-one>
|
||||
<vn-horizontal class="buttons">
|
||||
|
|
|
@ -5,33 +5,14 @@ export default class Controller {
|
|||
Object.assign(this, {
|
||||
$,
|
||||
selectedWorker: null,
|
||||
include: [
|
||||
{
|
||||
relation: 'user',
|
||||
scope: {fields: ['nickname', 'email']}
|
||||
}, {
|
||||
relation: 'client',
|
||||
scope: {fields: ['fi']}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
? {id: value}
|
||||
: {or: [
|
||||
{firstName: {like: `%${value}%`}},
|
||||
{name: {like: `%${value}%`}}
|
||||
]};
|
||||
case 'name':
|
||||
case 'firstName':
|
||||
return {[param]: {like: `%${value}%`}};
|
||||
case 'id':
|
||||
return {[param]: value};
|
||||
}
|
||||
onSearch(params) {
|
||||
if (params)
|
||||
this.$.model.applyFilter(null, params);
|
||||
else
|
||||
this.$.model.clear();
|
||||
}
|
||||
|
||||
preview(event, worker) {
|
||||
|
|
|
@ -9,3 +9,7 @@ Role: Rol
|
|||
Extension: Extensión
|
||||
Go to client: Ir al cliente
|
||||
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-textfield
|
||||
vn-one
|
||||
label="Id"
|
||||
label="Worker id"
|
||||
model="filter.id">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Name"
|
||||
model="filter.firstName">
|
||||
label="User id"
|
||||
model="filter.id">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Name"
|
||||
model="filter.firstName">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Last name"
|
||||
model="filter.name">
|
||||
</vn-textfield>
|
||||
</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-submit label="Search"></vn-submit>
|
||||
</vn-horizontal>
|
||||
|
|
Loading…
Reference in New Issue