Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
3c075580
Commit
3c075580
authored
Nov 30, 2016
by
Clement Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dropdown hint
parent
64d46a3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
+106
-0
app/assets/javascripts/filtered_search/dropdown_hint.js.es6
app/assets/javascripts/filtered_search/dropdown_hint.js.es6
+106
-0
No files found.
app/assets/javascripts/filtered_search/dropdown_hint.js.es6
0 → 100644
View file @
3c075580
/* eslint-disable no-param-reassign */
((global) => {
const dropdownData = [{
icon: 'fa-search',
hint: 'Keep typing and press Enter',
tag: '',
},{
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>',
}];
class DropdownHint {
constructor(dropdown, input) {
this.input = input;
this.dropdown = dropdown;
this.bindEvents();
}
bindEvents() {
this.dropdown.addEventListener('click.dl', this.itemClicked.bind(this));
}
unbindEvents() {
this.dropdown.removeEventListener('click.dl', this.itemClicked.bind(this));
}
// cleanup() {
// this.unbindEvents();
// droplab.setConfig({'filtered-search': {}});
// droplab.setData('filtered-search', []);
// this.dropdown.style.display = 'hidden';
// }
getSelectedText(selectedToken) {
// TODO: Get last word from FilteredSearchTokenizer
const lastWord = this.input.value.split(' ').last();
const lastWordIndex = selectedToken.indexOf(lastWord);
return lastWordIndex === -1 ? selectedToken : selectedToken.slice(lastWord.length);
}
itemClicked(e) {
const token = e.detail.selected.querySelector('.js-filter-hint').innerText.trim();
const tag = e.detail.selected.querySelector('.js-filter-tag').innerText.trim();
if (tag.length) {
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(token));
}
this.input.focus();
this.dismissDropdown();
// Propogate input change to FilteredSearchManager
// so that it can determine which dropdowns to open
this.input.dispatchEvent(new Event('input'));
}
dismissDropdown() {
this.input.removeAttribute('data-dropdown-trigger');
droplab.setConfig({'filtered-search': {}});
droplab.setData('filtered-search', []);
this.unbindEvents();
}
setAsDropdown() {
this.input.setAttribute('data-dropdown-trigger', '#js-dropdown-hint');
// const hookId = 'filtered-search';
// const listId = 'js-dropdown-hint';
// const hook = droplab.hooks.filter((h) => {
// return h.id === hookId;
// })[0];
// if (hook.list.list.id !== listId) {
// droplab.changeHookList(hookId, `#${listId}`);
// }
}
render() {
console.log('render dropdown hint');
this.setAsDropdown();
droplab.setConfig({
'filtered-search': {
text: 'hint'
}
});
droplab.setData('filtered-search', dropdownData);
}
}
global.DropdownHint = DropdownHint;
})(window.gl || (window.gl = {}));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment