Commit 6700b76b authored by Clement Ho's avatar Clement Ho

Fix eslint

parent 27b22040
/* eslint-disable no-param-reassign */
/*= require filtered_search/filtered_search_dropdown */
((global) => {
(() => {
const dropdownData = [{
icon: 'fa-pencil',
hint: 'author:',
tag: '<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>',
......@@ -27,7 +25,7 @@
droplabFilter: {
template: 'hint',
filterFunction: this.filterMethod,
}
},
};
}
......@@ -41,7 +39,8 @@
const tag = selected.querySelector('.js-filter-tag').innerText.trim();
if (tag.length) {
gl.FilteredSearchDropdownManager.addWordToInput(this.getSelectedTextWithoutEscaping(token));
gl.FilteredSearchDropdownManager
.addWordToInput(this.getSelectedTextWithoutEscaping(token));
}
this.dismissDropdown();
this.dispatchInputEvent();
......@@ -61,15 +60,16 @@
}
filterMethod(item, query) {
const updatedItem = item;
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
if (value === '') {
item.droplab_hidden = false;
updatedItem.droplab_hidden = false;
} else {
item.droplab_hidden = item['hint'].indexOf(value) === -1;
updatedItem.droplab_hidden = updatedItem.hint.indexOf(value) === -1;
}
return item;
return updatedItem;
}
init() {
......@@ -77,5 +77,6 @@
}
}
global.DropdownHint = DropdownHint;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.DropdownHint = DropdownHint;
})();
/* eslint-disable no-param-reassign */
/*= require filtered_search/filtered_search_dropdown */
((global) => {
(() => {
class DropdownNonUser extends gl.FilteredSearchDropdown {
constructor(droplab, dropdown, input, endpoint, symbol) {
super(droplab, dropdown, input);
this.symbol = symbol;
this.config = {
droplabAjax: {
endpoint: endpoint,
endpoint,
method: 'setData',
loadingTemplate: this.loadingTemplate,
},
droplabFilter: {
filterFunction: this.filterWithSymbol.bind(this, this.symbol),
}
},
};
}
itemClicked(e) {
super.itemClicked(e, (selected) => {
const title = e.detail.selected.querySelector('.js-data-value').innerText.trim();
const title = selected.querySelector('.js-data-value').innerText.trim();
return `${this.symbol}${this.getEscapedText(title)}`;
});
}
......@@ -46,30 +44,35 @@
}
filterWithSymbol(filterSymbol, item, query) {
const updatedItem = item;
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
const valueWithoutColon = value.slice(1).toLowerCase();
const prefix = valueWithoutColon[0];
const valueWithoutPrefix = valueWithoutColon.slice(1);
const title = item.title.toLowerCase();
const title = updatedItem.title.toLowerCase();
// Eg. filterSymbol = ~ for labels
const matchWithoutPrefix = prefix === filterSymbol && title.indexOf(valueWithoutPrefix) !== -1;
const matchWithoutPrefix =
prefix === filterSymbol && title.indexOf(valueWithoutPrefix) !== -1;
const match = title.indexOf(valueWithoutColon) !== -1;
item.droplab_hidden = !match && !matchWithoutPrefix;
return item;
updatedItem.droplab_hidden = !match && !matchWithoutPrefix;
return updatedItem;
}
renderContent(forceShowList = false) {
this.droplab.changeHookList(this.hookId, this.dropdown, [droplabAjax, droplabFilter], this.config);
this.droplab
.changeHookList(this.hookId, this.dropdown, [droplabAjax, droplabFilter], this.config);
super.renderContent(forceShowList);
}
init() {
this.droplab.addHook(this.input, this.dropdown, [droplabAjax, droplabFilter], this.config).init();
this.droplab
.addHook(this.input, this.dropdown, [droplabAjax, droplabFilter], this.config).init();
}
}
global.DropdownNonUser = DropdownNonUser;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.DropdownNonUser = DropdownNonUser;
})();
/* eslint-disable no-param-reassign */
/*= require filtered_search/filtered_search_dropdown */
((global) => {
(() => {
class DropdownUser extends gl.FilteredSearchDropdown {
constructor(droplab, dropdown, input) {
super(droplab, dropdown, input);
......@@ -22,9 +20,8 @@
}
itemClicked(e) {
super.itemClicked(e, (selected) => {
return selected.querySelector('.dropdown-light-content').innerText.trim();
});
super.itemClicked(e,
selected => selected.querySelector('.dropdown-light-content').innerText.trim());
}
renderContent(forceShowList = false) {
......@@ -51,5 +48,6 @@
}
}
global.DropdownUser = DropdownUser;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.DropdownUser = DropdownUser;
})();
/* eslint-disable no-param-reassign */
((global) => {
(() => {
const DATA_DROPDOWN_TRIGGER = 'data-dropdown-trigger';
class FilteredSearchDropdown {
......@@ -72,7 +71,7 @@
if (firstTimeInitialized || forceRenderContent) {
this.renderContent(forceShowList);
} else if(currentHook.list.list.id !== this.dropdown.id) {
} else if (currentHook.list.list.id !== this.dropdown.id) {
this.renderContent(forceShowList);
}
}
......@@ -96,10 +95,15 @@
resetFilters() {
const hook = this.getCurrentHook();
const data = hook.list.data;
const results = data.map(o => o.droplab_hidden = false);
const results = data.map((o) => {
const updated = o;
updated.droplab_hidden = false;
return updated;
});
hook.list.render(results);
}
}
global.FilteredSearchDropdown = FilteredSearchDropdown;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.FilteredSearchDropdown = FilteredSearchDropdown;
})();
/* eslint-disable no-param-reassign */
((global) => {
(() => {
class FilteredSearchDropdownManager {
constructor() {
this.tokenizer = gl.FilteredSearchTokenizer;
......@@ -51,7 +50,7 @@
gl: 'DropdownHint',
element: document.querySelector('#js-dropdown-hint'),
},
}
};
}
static addWordToInput(word, addSpace = false) {
......@@ -60,7 +59,7 @@
const hasExistingValue = value.length !== 0;
const { lastToken } = gl.FilteredSearchTokenizer.processTokens(value);
if (lastToken.hasOwnProperty('key')) {
if ({}.hasOwnProperty.call(lastToken, 'key')) {
// Spaces inside the token means that the token value will be escaped by quotes
const hasQuotes = lastToken.value.indexOf(' ') !== -1;
......@@ -82,7 +81,8 @@
}
const filterIconPadding = 27;
const offset = gl.text.getTextWidth(this.filteredSearchInput.value, this.font) + filterIconPadding;
const offset = gl.text
.getTextWidth(this.filteredSearchInput.value, this.font) + filterIconPadding;
this.mapping[key].reference.setOffset(offset);
}
......@@ -99,7 +99,7 @@
const glArguments = defaultArguments.concat(mappingKey.extraArguments || []);
// Passing glArguments to `new gl[glClass](<arguments>)`
mappingKey.reference = new (Function.prototype.bind.apply(gl[glClass], glArguments));
mappingKey.reference = new (Function.prototype.bind.apply(gl[glClass], glArguments))();
}
if (firstLoad) {
......@@ -126,12 +126,13 @@
}
const match = gl.FilteredSearchTokenKeys.searchByKey(dropdownName.toLowerCase());
const shouldOpenFilterDropdown = match && this.currentDropdown !== match.key && this.mapping.hasOwnProperty(match.key);
const shouldOpenFilterDropdown = match && this.currentDropdown !== match.key
&& {}.hasOwnProperty.call(this.mapping, match.key);
const shouldOpenHintDropdown = !match && this.currentDropdown !== 'hint';
if (shouldOpenFilterDropdown || shouldOpenHintDropdown) {
// `hint` is not listed as a tokenKey (since it is not a real `filter`)
const key = match && match.hasOwnProperty('key') ? match.key : 'hint';
const key = match && {}.hasOwnProperty.call(match, 'key') ? match.key : 'hint';
this.load(key, firstLoad);
}
......@@ -146,7 +147,7 @@
// Eg. token = 'label:'
const { tokenKey } = this.tokenizer.parseToken(lastToken);
this.loadDropdown(tokenKey);
} else if (lastToken.hasOwnProperty('key')) {
} else if ({}.hasOwnProperty.call(lastToken, 'key')) {
// Token has been initialized into an object because it has a value
this.loadDropdown(lastToken.key);
} else {
......@@ -173,5 +174,6 @@
}
}
global.FilteredSearchDropdownManager = FilteredSearchDropdownManager;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.FilteredSearchDropdownManager = FilteredSearchDropdownManager;
})();
/* eslint-disable no-param-reassign */
((global) => {
(() => {
class FilteredSearchManager {
constructor() {
this.tokenizer = gl.FilteredSearchTokenizer;
......@@ -81,7 +80,7 @@
loadSearchParamsFromURL() {
const params = gl.utils.getUrlParamsArray();
let inputValues = [];
const inputValues = [];
params.forEach((p) => {
const split = p.split('=');
......@@ -125,13 +124,14 @@
}
search() {
let paths = [];
const paths = [];
const { tokens, searchToken } = this.tokenizer.processTokens(this.filteredSearchInput.value);
const currentState = gl.utils.getParameterByName('state') || 'opened';
paths.push(`state=${currentState}`);
tokens.forEach((token) => {
const condition = gl.FilteredSearchTokenKeys.searchByConditionKeyValue(token.key, token.value.toLowerCase());
const condition = gl.FilteredSearchTokenKeys
.searchByConditionKeyValue(token.key, token.value.toLowerCase());
const { param } = gl.FilteredSearchTokenKeys.searchByKey(token.key);
let tokenPath = '';
......@@ -156,5 +156,6 @@
}
}
global.FilteredSearchManager = FilteredSearchManager;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.FilteredSearchManager = FilteredSearchManager;
})();
/* eslint-disable no-param-reassign */
((global) => {
(() => {
const tokenKeys = [{
key: 'author',
type: 'string',
......@@ -62,9 +61,11 @@
}
static searchByConditionKeyValue(key, value) {
return conditions.find(condition => condition.tokenKey === key && condition.value === value) || null;
return conditions
.find(condition => condition.tokenKey === key && condition.value === value) || null;
}
}
global.FilteredSearchTokenKeys = FilteredSearchTokenKeys;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.FilteredSearchTokenKeys = FilteredSearchTokenKeys;
})();
/* eslint-disable no-param-reassign */
((global) => {
(() => {
class FilteredSearchTokenizer {
static parseToken(input) {
const colonIndex = input.indexOf(':');
......@@ -161,5 +160,6 @@
}
}
global.FilteredSearchTokenizer = FilteredSearchTokenizer;
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
gl.FilteredSearchTokenizer = FilteredSearchTokenizer;
})();
......@@ -128,7 +128,7 @@
// We can trust that each param has one & since values containing & will be encoded
// Remove the first character of search as it is always ?
return window.location.search.slice(1).split('&');
}
};
gl.utils.getParameterByName = function(name) {
var url = window.location.href;
......
......@@ -30,8 +30,7 @@
var canvas = gl.text.getTextWidth.canvas || (gl.text.getTextWidth.canvas = document.createElement('canvas'));
var context = canvas.getContext('2d');
context.font = font;
var metrics = context.measureText(text);
return metrics.width;
return context.measureText(text).width;
};
gl.text.selectedText = function(text, textarea) {
return text.substring(textarea.selectionStart, textarea.selectionEnd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment