gitlab-org--gitlab-foss/app/assets/javascripts/filtered_search/dropdown_assignee.js.es6

50 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-12-02 21:04:10 +00:00
/* eslint-disable no-param-reassign */
/*= require filtered_search/filtered_search_dropdown */
((global) => {
class DropdownAssignee extends gl.FilteredSearchDropdown {
2016-12-08 21:36:54 +00:00
constructor(droplab, dropdown, input) {
super(droplab, dropdown, input);
2016-12-02 21:04:10 +00:00
this.listId = 'js-dropdown-assignee';
}
itemClicked(e) {
const dataValueSet = this.setDataValueIfSelected(e.detail.selected);
if (!dataValueSet) {
const username = e.detail.selected.querySelector('.dropdown-light-content').innerText.trim();
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(username));
}
this.dismissDropdown();
2016-12-02 21:04:10 +00:00
}
renderContent() {
2016-12-08 21:36:54 +00:00
// TODO: Pass elements instead of querySelectors
this.droplab.changeHookList(this.hookId, '#js-dropdown-assignee', [droplabAjax], {
droplabAjax: {
endpoint: '/autocomplete/users.json?search=&per_page=20&active=true&project_id=2&group_id=&skip_ldap=&todo_filter=&todo_state_filter=&current_user=true&push_code_to_protected_branches=&author_id=&skip_users=',
method: 'setData',
}
});
2016-12-02 21:04:10 +00:00
}
filterMethod(item, query) {
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
const valueWithoutColon = value.slice(1).toLowerCase();
const valueWithoutPrefix = valueWithoutColon.slice(1);
const username = item.username.toLowerCase();
const name = item.name.toLowerCase();
const noUsernameMatch = username.indexOf(valueWithoutPrefix) === -1 && username.indexOf(valueWithoutColon) === -1;
const noNameMatch = name.indexOf(valueWithoutColon) === -1;
item.droplab_hidden = noUsernameMatch && noNameMatch;
return item;
}
2016-12-02 21:04:10 +00:00
}
global.DropdownAssignee = DropdownAssignee;
})(window.gl || (window.gl = {}));