2016-11-30 21:25:10 +00:00
|
|
|
/* eslint-disable no-param-reassign */
|
2016-12-02 21:04:10 +00:00
|
|
|
/*= require filtered_search/filtered_search_dropdown */
|
|
|
|
|
2016-11-30 21:25:10 +00:00
|
|
|
((global) => {
|
|
|
|
const dropdownData = [{
|
|
|
|
icon: 'fa-pencil',
|
|
|
|
hint: 'author:',
|
|
|
|
tag: '<author>'
|
|
|
|
},{
|
|
|
|
icon: 'fa-user',
|
|
|
|
hint: 'assignee:',
|
|
|
|
tag: '<assignee>',
|
|
|
|
},{
|
|
|
|
icon: 'fa-clock-o',
|
|
|
|
hint: 'milestone:',
|
|
|
|
tag: '<milestone>',
|
|
|
|
},{
|
|
|
|
icon: 'fa-tag',
|
|
|
|
hint: 'label:',
|
|
|
|
tag: '<label>',
|
|
|
|
}];
|
|
|
|
|
2016-12-02 21:04:10 +00:00
|
|
|
class DropdownHint 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-hint';
|
2016-12-09 17:44:09 +00:00
|
|
|
this.config = {
|
|
|
|
droplabFilter: {
|
|
|
|
template: 'hint',
|
|
|
|
filterFunction: this.filterMethod,
|
|
|
|
}
|
|
|
|
};
|
2016-11-30 21:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
itemClicked(e) {
|
2016-12-09 17:44:09 +00:00
|
|
|
const selected = e.detail.selected;
|
|
|
|
if (!selected.hasAttribute('data-value')) {
|
|
|
|
const token = selected.querySelector('.js-filter-hint').innerText.trim();
|
|
|
|
const tag = selected.querySelector('.js-filter-tag').innerText.trim();
|
2016-11-30 21:25:10 +00:00
|
|
|
|
2016-12-09 17:44:09 +00:00
|
|
|
if (tag.length) {
|
|
|
|
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(token));
|
|
|
|
}
|
2016-11-30 21:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.dismissDropdown();
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:04:10 +00:00
|
|
|
renderContent() {
|
2016-12-09 17:44:09 +00:00
|
|
|
this.droplab.changeHookList(this.hookId, this.dropdown, [droplabFilter], this.config);
|
2016-12-08 21:36:54 +00:00
|
|
|
this.droplab.setData(this.hookId, dropdownData);
|
2016-11-30 21:25:10 +00:00
|
|
|
}
|
2016-12-06 22:23:04 +00:00
|
|
|
|
|
|
|
filterMethod(item, query) {
|
|
|
|
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
|
|
|
|
|
|
|
|
if (value === '') {
|
|
|
|
item.droplab_hidden = false;
|
|
|
|
} else {
|
|
|
|
item.droplab_hidden = item['hint'].indexOf(value) === -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2016-12-08 21:36:54 +00:00
|
|
|
|
|
|
|
configure() {
|
2016-12-09 17:44:09 +00:00
|
|
|
this.droplab.addHook(this.input, this.dropdown, [droplabFilter], this.config).init();
|
2016-12-08 21:36:54 +00:00
|
|
|
}
|
2016-11-30 21:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
global.DropdownHint = DropdownHint;
|
|
|
|
})(window.gl || (window.gl = {}));
|