dev #1731

Merged
jgallego merged 105 commits from dev into test 2023-08-31 09:13:29 +00:00
5 changed files with 69 additions and 57 deletions
Showing only changes of commit a539abf3d8 - Show all commits

View File

@ -1,13 +1,16 @@
<vn-autocomplete
vn-one
url="Workers/activeWithInheritedRole"
url="Workers/search"
ng-model="$ctrl.workerFk"
search-function="{firstName: $search}"
value-field="id"
search-function="{or: [
{name: $search},
{nickname: {like: '%'+ $search +'%'}},
{code: {like: $search +'%'}}
]}"
label="Worker">
<tpl-item>
<div>
{{firstName}} {{lastName}}
{{name}}
</div>
<div class="text-caption text-secondary">
{{nickname}}, {{code}}

View File

@ -1,8 +1,5 @@
import ngModule from '../../module';
import Autocomplete from '../autocomplete';
import assignProps from '../../lib/assign-props';
import {mergeWhere} from 'vn-loopback/util/filter';
import './style.scss';
/**
* Input with option selector.
@ -20,26 +17,6 @@ export default class WorkerAutocomplete extends Autocomplete {
constructor($element, $, $compile, $transclude) {
super($element, $, $compile, $transclude);
}
// $postLink() {
// super.$postLink();
// this.assignDropdownProps();
// this.showField = this.$.dropDown.showField;
// this.valueField = this.$.dropDown.valueField;
// this.refreshSelection();
// }
// /**
// * @type {any} The autocomplete value.
// */
// get field() {
// return super.field;
// }
// set field(value) {
// super.field = value;
// this.refreshSelection();
// }
}
WorkerAutocomplete.$inject = ['$element', '$scope', '$compile', '$transclude'];

View File

@ -1,30 +0,0 @@
@import "effects";
.vn-worker-autocomplete {
overflow: hidden;
& > .container {
cursor: pointer;
& > .infix > .control {
overflow: hidden;
& > input {
cursor: pointer;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-align: left;
padding-left: 0;
padding-right: 0;
}
}
& > .icons.pre {
min-width: 22px
}
}
&.readonly > .container > .icons.post {
display: none;
}
}

View File

@ -0,0 +1,61 @@
module.exports = Self => {
Self.remoteMethod('search', {
description: 'Returns an array of search from an specified worker',
accepts: [{
arg: 'filter',
type: 'Object',
description: 'Filter defining where and paginated data',
required: true
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/search`,
verb: 'GET'
}
});
Self.search = async filter => {
const models = Self.app.models;
delete filter.order;
delete filter.fields;
const users = await models.VnUser.find(filter);
if (filter.where) {
const indexToDelete = 2;
const filterByCode = filter.where.or.splice(indexToDelete, 1)[0];
const ids = users.map(user => parseInt(user.id));
filter.where.or = [
{id: {inq: ids}},
filterByCode
];
}
filter.include = {
relation: 'user',
scope: {
fields: ['name', 'nickname']
}
};
const workers = await models.Worker.find(filter);
const result = workers.map(worker => {
return {
id: worker.id,
code: worker.code,
name: worker.user().name,
nickname: worker.user().nickname
};
});
result.sort((a, b) => {
return a.name.localeCompare(b.name);
});
return result;
};
};

View File

@ -16,6 +16,7 @@ module.exports = Self => {
require('../methods/worker/new')(Self);
require('../methods/worker/deallocatePDA')(Self);
require('../methods/worker/allocatePDA')(Self);
require('../methods/worker/search')(Self);
Self.validatesUniquenessOf('locker', {
message: 'This locker has already been assigned'