5244-component_workerAutocomplete #1679
|
@ -1,12 +1,3 @@
|
|||
<vn-autocomplete
|
||||
vn-one
|
||||
url="Workers/search"
|
||||
search-function="{or: [
|
||||
{name: $search},
|
||||
{nickname: {like: '%'+ $search +'%'}},
|
||||
{code: {like: $search +'%'}}
|
||||
]}"
|
||||
label="Worker">
|
||||
<tpl-item>
|
||||
<div>
|
||||
{{name}}
|
||||
|
@ -14,10 +5,4 @@
|
|||
<div class="text-caption text-secondary">
|
||||
{{nickname}}, {{code}}
|
||||
</div>
|
||||
</vn-autocomplete>
|
||||
<vn-drop-down
|
||||
vn-id="drop-down"
|
||||
on-select="$ctrl.onDropDownSelect(item)"
|
||||
on-data-ready="$ctrl.onDataReady()"
|
||||
on-close-start="$ctrl.onDropDownClose()">
|
||||
</vn-drop-down>
|
||||
</tpl-item>
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
import ngModule from '../../module';
|
||||
import Autocomplete from '../autocomplete';
|
||||
|
||||
/**
|
||||
* Input with option selector.
|
||||
*
|
||||
* @property {String} showFiled The data field name that should be shown
|
||||
* @property {String} valueField The data field name that should be used as value
|
||||
* @property {Array} data Static data for the autocomplete
|
||||
* @property {Object} intialData An initial data to avoid the server request used to get the selection
|
||||
* @property {Boolean} multiple Whether to allow multiple selection
|
||||
* @property {Object} selection Current object selected
|
||||
*
|
||||
* @event change Thrown when value is changed
|
||||
*/
|
||||
export default class WorkerAutocomplete extends Autocomplete {
|
||||
constructor($element, $, $compile, $transclude) {
|
||||
super($element, $, $compile, $transclude);
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
Object.assign(this, {
|
||||
label: 'Worker',
|
||||
url: 'Workers/search',
|
||||
fields: ['id', 'name', 'nickname'],
|
||||
searchFunction: function($search) {
|
||||
return {and: [
|
||||
{active: {neq: false}},
|
||||
{or: [
|
||||
{name: $search},
|
||||
{nickname: {like: '%' + $search + '%'}},
|
||||
{code: {like: $search + '%'}}
|
||||
]}
|
||||
]};
|
||||
vicent marked this conversation as resolved
Outdated
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
WorkerAutocomplete.$inject = ['$element', '$scope', '$compile', '$transclude'];
|
||||
|
||||
ngModule.vnComponent('vnWorkerAutocomplete', {
|
||||
template: require('./index.html'),
|
||||
slotTemplate: require('./index.html'),
|
||||
controller: WorkerAutocomplete
|
||||
});
|
||||
|
|
|
@ -18,44 +18,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
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;
|
||||
const $ = Self.app.models;
|
||||
return await $.VnUser.find(filter);
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
url,