This commit is contained in:
parent
eb6953a2b6
commit
4c7c7f5c96
|
@ -51,40 +51,29 @@ module.exports = Self => {
|
|||
|
||||
Self.filter = async(ctx, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
|
||||
console.log('ENTRY');
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
? {'d.id': value}
|
||||
? {'id': value}
|
||||
: {or: [
|
||||
{'d.code': {like: `%${value}%`}},
|
||||
{'d.name': {like: `%${value}%`}}
|
||||
{'code': {like: `%${value}%`}},
|
||||
{'name': {like: `%${value}%`}}
|
||||
]};
|
||||
case 'id':
|
||||
return {'d.id': value};
|
||||
return {'id': value};
|
||||
case 'code':
|
||||
return {'d.code': value};
|
||||
return {'code': value};
|
||||
case 'name':
|
||||
return {'d.name': {like: `%${value}%`}};
|
||||
return {'name': {like: `%${value}%`}};
|
||||
}
|
||||
});
|
||||
|
||||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmt = new ParameterizedSQL(
|
||||
`SELECT id, code, name
|
||||
FROM department d`
|
||||
);
|
||||
|
||||
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];
|
||||
console.log(filter);
|
||||
const departments = await Self.app.models.Department.find(filter);
|
||||
console.log(departments);
|
||||
return departments;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -36,16 +36,20 @@
|
|||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Boss department"
|
||||
ng-model="$ctrl.department.workerFk">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Self-consumption customer"
|
||||
ng-model="$ctrl.department.clientFk">
|
||||
</vn-textfield>
|
||||
<vn-autocomplete
|
||||
ng-model="$ctrl.department.workerFk"
|
||||
url="Workers/activeWithInheritedRole"
|
||||
show-field="nickname"
|
||||
search-function="{firstName: $search}"
|
||||
label="Boss department">
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete
|
||||
ng-model="$ctrl.department.clientFk"
|
||||
url="Clients/"
|
||||
show-field="name"
|
||||
search-function="{firstName: $search}"
|
||||
label="Self-consumption customer">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-check
|
||||
|
|
|
@ -29,10 +29,14 @@
|
|||
value="{{$ctrl.department.worker.firstName}} {{$ctrl.department.worker.secondName}}">
|
||||
</vn-label-value>
|
||||
</div>
|
||||
<vn-icon-button vn-anchor="{state: 'worker.index', params: {q: {departmentFk: $ctrl.$params.id}}}"
|
||||
<div class="quicklinks">
|
||||
<div ng-transclude="btnOne">
|
||||
<vn-quick-link vn-anchor="{state: 'worker.index', params: {q: {departmentFk: $ctrl.$params.id} } }"
|
||||
vn-tooltip="Department workers"
|
||||
icon="icon-ticket">
|
||||
</vn-icon-button>
|
||||
</vn-quick-link>
|
||||
</div>
|
||||
</div>
|
||||
</slot-body>
|
||||
</vn-descriptor-content>
|
||||
<vn-popup vn-id="summary">
|
||||
|
@ -44,8 +48,3 @@
|
|||
on-accept="$ctrl.deleteDepartment()"
|
||||
question="You are going to delete this department">
|
||||
</vn-confirm>
|
||||
<!-- Upload photo dialog -->
|
||||
<!-- <vn-upload-photo
|
||||
vn-id="uploadPhoto"
|
||||
on-response="$ctrl.onUploadResponse()">
|
||||
</vn-upload-photo>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<vn-portal slot="topbar">
|
||||
<vn-searchbar
|
||||
vn-focus
|
||||
panel="vn-worker-search-panel"
|
||||
panel="vn-worker-department-search-panel"
|
||||
info="Search workers by id, firstName, lastName or user name"
|
||||
model="model"
|
||||
base-state="worker.department">
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Workers",
|
||||
"icon" : "icon-worker",
|
||||
"validations" : true,
|
||||
"dependencies": ["account", "worker"],
|
||||
"dependencies": ["account"],
|
||||
"menus": {
|
||||
"main": [
|
||||
{"state": "worker.index", "icon": "icon-worker"},
|
||||
|
@ -124,7 +124,8 @@
|
|||
"url": "/department?q",
|
||||
"state": "worker.department",
|
||||
"component": "vn-worker-department",
|
||||
"description":"Departments"
|
||||
"description":"Departments",
|
||||
"acl":["hr"]
|
||||
}, {
|
||||
"url": "/:id",
|
||||
"state": "worker.department.card",
|
||||
|
|
Loading…
Reference in New Issue