2020-03-13 15:44:24 +05:30
|
|
|
import Filter from '~/droplab/plugins/filter';
|
|
|
|
import { __ } from '~/locale';
|
|
|
|
import FilteredSearchDropdown from './filtered_search_dropdown';
|
|
|
|
import DropdownUtils from './dropdown_utils';
|
|
|
|
import FilteredSearchDropdownManager from './filtered_search_dropdown_manager';
|
|
|
|
import FilteredSearchVisualTokens from './filtered_search_visual_tokens';
|
|
|
|
|
|
|
|
export default class DropdownOperator extends FilteredSearchDropdown {
|
|
|
|
constructor(options = {}) {
|
|
|
|
const { input, tokenKeys } = options;
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.config = {
|
|
|
|
Filter: {
|
|
|
|
filterFunction: DropdownUtils.filterWithSymbol.bind(null, '', input),
|
|
|
|
template: 'title',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
this.tokenKeys = tokenKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemClicked(e) {
|
|
|
|
const { selected } = e.detail;
|
|
|
|
|
|
|
|
if (selected.tagName === 'LI') {
|
|
|
|
if (selected.hasAttribute('data-value')) {
|
2020-04-22 19:07:51 +05:30
|
|
|
const name = FilteredSearchVisualTokens.getLastTokenPartial();
|
2020-03-13 15:44:24 +05:30
|
|
|
const operator = selected.dataset.value;
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchVisualTokens.removeLastTokenPartial();
|
|
|
|
FilteredSearchDropdownManager.addWordToInput({
|
2020-04-22 19:07:51 +05:30
|
|
|
tokenName: name,
|
2020-03-13 15:44:24 +05:30
|
|
|
tokenOperator: operator,
|
|
|
|
clicked: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.dismissDropdown();
|
|
|
|
this.dispatchInputEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderContent(forceShowList = false) {
|
|
|
|
const dropdownData = [
|
|
|
|
{
|
|
|
|
tag: 'equal',
|
|
|
|
type: 'string',
|
|
|
|
title: '=',
|
|
|
|
help: __('is'),
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
];
|
|
|
|
|
|
|
|
if (gon.features?.notIssuableQueries) {
|
|
|
|
dropdownData.push({
|
2020-03-13 15:44:24 +05:30
|
|
|
tag: 'not-equal',
|
|
|
|
type: 'string',
|
|
|
|
title: '!=',
|
|
|
|
help: __('is not'),
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
this.droplab.changeHookList(this.hookId, this.dropdown, [Filter], this.config);
|
|
|
|
this.droplab.setData(this.hookId, dropdownData);
|
|
|
|
super.renderContent(forceShowList);
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.droplab.addHook(this.input, this.dropdown, [Filter], this.config).init();
|
|
|
|
}
|
|
|
|
}
|