Commit 0ce24455 authored by Clement Ho's avatar Clement Ho

Fix eslint

parent 4786a978
/* eslint-disable */
// Determine where to place this // Determine where to place this
if (typeof Object.assign != 'function') { if (typeof Object.assign != 'function') {
Object.assign = function (target, varArgs) { // .length of function is 2 Object.assign = function (target, varArgs) { // .length of function is 2
...@@ -24,7 +25,6 @@ if (typeof Object.assign != 'function') { ...@@ -24,7 +25,6 @@ if (typeof Object.assign != 'function') {
}; };
} }
/* eslint-disable */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.droplab = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.droplab = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var DATA_TRIGGER = 'data-dropdown-trigger'; var DATA_TRIGGER = 'data-dropdown-trigger';
var DATA_DROPDOWN = 'data-dropdown'; var DATA_DROPDOWN = 'data-dropdown';
......
/*= require filtered_search/filtered_search_dropdown */ /*= require filtered_search/filtered_search_dropdown */
/* global droplabFilter */
(() => { (() => {
const dropdownData = [{ const dropdownData = [{
icon: 'fa-pencil', icon: 'fa-pencil',
...@@ -24,7 +27,7 @@ ...@@ -24,7 +27,7 @@
this.config = { this.config = {
droplabFilter: { droplabFilter: {
template: 'hint', template: 'hint',
filterFunction: this.filterMethod, filterFunction: gl.DropdownUtils.filterMethod,
}, },
}; };
} }
...@@ -59,19 +62,6 @@ ...@@ -59,19 +62,6 @@
this.droplab.setData(this.hookId, dropdownData); this.droplab.setData(this.hookId, dropdownData);
} }
filterMethod(item, query) {
const updatedItem = item;
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
if (value === '') {
updatedItem.droplab_hidden = false;
} else {
updatedItem.droplab_hidden = updatedItem.hint.indexOf(value) === -1;
}
return updatedItem;
}
init() { init() {
this.droplab.addHook(this.input, this.dropdown, [droplabFilter], this.config).init(); this.droplab.addHook(this.input, this.dropdown, [droplabFilter], this.config).init();
} }
......
/*= require filtered_search/filtered_search_dropdown */ /*= require filtered_search/filtered_search_dropdown */
/* global droplabAjax */
/* global droplabFilter */
(() => { (() => {
class DropdownNonUser extends gl.FilteredSearchDropdown { class DropdownNonUser extends gl.FilteredSearchDropdown {
constructor(droplab, dropdown, input, endpoint, symbol) { constructor(droplab, dropdown, input, endpoint, symbol) {
...@@ -11,7 +15,7 @@ ...@@ -11,7 +15,7 @@
loadingTemplate: this.loadingTemplate, loadingTemplate: this.loadingTemplate,
}, },
droplabFilter: { droplabFilter: {
filterFunction: this.filterWithSymbol.bind(this, this.symbol), filterFunction: gl.DropdownUtils.filterWithSymbol.bind(null, this.symbol),
}, },
}; };
} }
...@@ -19,48 +23,10 @@ ...@@ -19,48 +23,10 @@
itemClicked(e) { itemClicked(e) {
super.itemClicked(e, (selected) => { super.itemClicked(e, (selected) => {
const title = selected.querySelector('.js-data-value').innerText.trim(); const title = selected.querySelector('.js-data-value').innerText.trim();
return `${this.symbol}${this.getEscapedText(title)}`; return `${this.symbol}${gl.DropdownUtils.getEscapedText(title)}`;
}); });
} }
getEscapedText(text) {
let escapedText = text;
const hasSpace = text.indexOf(' ') !== -1;
const hasDoubleQuote = text.indexOf('"') !== -1;
// Encapsulate value with quotes if it has spaces
// Known side effect: values's with both single and double quotes
// won't escape properly
if (hasSpace) {
if (hasDoubleQuote) {
escapedText = `'${text}'`;
} else {
// Encapsulate singleQuotes or if it hasSpace
escapedText = `"${text}"`;
}
}
return escapedText;
}
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 = updatedItem.title.toLowerCase();
// Eg. filterSymbol = ~ for labels
const matchWithoutPrefix =
prefix === filterSymbol && title.indexOf(valueWithoutPrefix) !== -1;
const match = title.indexOf(valueWithoutColon) !== -1;
updatedItem.droplab_hidden = !match && !matchWithoutPrefix;
return updatedItem;
}
renderContent(forceShowList = false) { renderContent(forceShowList = false) {
this.droplab this.droplab
.changeHookList(this.hookId, this.dropdown, [droplabAjax, droplabFilter], this.config); .changeHookList(this.hookId, this.dropdown, [droplabAjax, droplabFilter], this.config);
......
/*= require filtered_search/filtered_search_dropdown */ /*= require filtered_search/filtered_search_dropdown */
/* global droplabAjaxFilter */
(() => { (() => {
class DropdownUser extends gl.FilteredSearchDropdown { class DropdownUser extends gl.FilteredSearchDropdown {
constructor(droplab, dropdown, input) { constructor(droplab, dropdown, input) {
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
itemClicked(e, getValueFunction) { itemClicked(e, getValueFunction) {
const { selected } = e.detail; const { selected } = e.detail;
const dataValueSet = this.setDataValueIfSelected(selected); const dataValueSet = gl.DropdownUtils.setDataValueIfSelected(selected);
if (!dataValueSet) { if (!dataValueSet) {
const value = getValueFunction(selected); const value = getValueFunction(selected);
...@@ -46,17 +46,6 @@ ...@@ -46,17 +46,6 @@
this.dropdown.style.left = `${offset}px`; this.dropdown.style.left = `${offset}px`;
} }
setDataValueIfSelected(selected) {
const dataValue = selected.getAttribute('data-value');
if (dataValue) {
gl.FilteredSearchDropdownManager.addWordToInput(dataValue);
}
// Return boolean based on whether it was set
return dataValue !== null;
}
renderContent(forceShowList = false) { renderContent(forceShowList = false) {
if (forceShowList && this.getCurrentHook().list.hidden) { if (forceShowList && this.getCurrentHook().list.hidden) {
this.getCurrentHook().list.show(); this.getCurrentHook().list.show();
......
/* global DropLab */
(() => { (() => {
class FilteredSearchDropdownManager { class FilteredSearchDropdownManager {
constructor() { constructor() {
......
/* global Turbolinks */
(() => { (() => {
class FilteredSearchManager { class FilteredSearchManager {
constructor() { constructor() {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
tokenKey, tokenKey,
tokenValue, tokenValue,
tokenSymbol, tokenSymbol,
} };
} }
static getLastTokenObject(input) { static getLastTokenObject(input) {
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
return { return {
key, key,
value, value,
} };
} }
static getLastToken(input) { static getLastToken(input) {
...@@ -40,19 +40,19 @@ ...@@ -40,19 +40,19 @@
const doubleQuote = '"'; const doubleQuote = '"';
const singleQuote = '\''; const singleQuote = '\'';
while(!completeToken && i >= 0) { while (!completeToken && i >= 0) {
const isDoubleQuote = input[i] === doubleQuote; const isDoubleQuote = input[i] === doubleQuote;
const isSingleQuote = input[i] === singleQuote; const isSingleQuote = input[i] === singleQuote;
// If the second quotation is found // If the second quotation is found
if ((lastQuotation === doubleQuote && input[i] === doubleQuote) || if ((lastQuotation === doubleQuote && isDoubleQuote) ||
(lastQuotation === singleQuote && input[i] === singleQuote)) { (lastQuotation === singleQuote && isSingleQuote)) {
completeQuotation = true; completeQuotation = true;
} }
// Save the first quotation // Save the first quotation
if ((input[i] === doubleQuote && lastQuotation === '') || if ((isDoubleQuote && lastQuotation === '') ||
(input[i] === singleQuote && lastQuotation === '')) { (isSingleQuote && lastQuotation === '')) {
lastQuotation = input[i]; lastQuotation = input[i];
completeQuotation = false; completeQuotation = false;
} }
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
if (completeQuotation && input[i] === ' ') { if (completeQuotation && input[i] === ' ') {
completeToken = true; completeToken = true;
} else { } else {
i--; i -= 1;
} }
} }
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
} }
static processTokens(input) { static processTokens(input) {
let tokens = []; const tokens = [];
let searchToken = ''; let searchToken = '';
let lastToken = ''; let lastToken = '';
...@@ -118,16 +118,20 @@ ...@@ -118,16 +118,20 @@
const singleQuoteExist = singleQuoteIndex !== -1; const singleQuoteExist = singleQuoteIndex !== -1;
const doubleQuoteExistOnly = doubleQuoteExist && !singleQuoteExist; const doubleQuoteExistOnly = doubleQuoteExist && !singleQuoteExist;
const doubleQuoteIsBeforeSingleQuote = doubleQuoteExist && singleQuoteExist && doubleQuoteIndex < singleQuoteIndex; const doubleQuoteIsBeforeSingleQuote =
doubleQuoteExist && singleQuoteExist && doubleQuoteIndex < singleQuoteIndex;
const singleQuoteExistOnly = singleQuoteExist && !doubleQuoteExist; const singleQuoteExistOnly = singleQuoteExist && !doubleQuoteExist;
const singleQuoteIsBeforeDoubleQuote = doubleQuoteExist && singleQuoteExist && singleQuoteIndex < doubleQuoteIndex; const singleQuoteIsBeforeDoubleQuote =
doubleQuoteExist && singleQuoteExist && singleQuoteIndex < doubleQuoteIndex;
if ((doubleQuoteExistOnly || doubleQuoteIsBeforeSingleQuote) && doubleQuoteOccurrences % 2 !== 0) { if ((doubleQuoteExistOnly || doubleQuoteIsBeforeSingleQuote)
&& doubleQuoteOccurrences % 2 !== 0) {
// " is found and is in front of ' (if any) // " is found and is in front of ' (if any)
lastQuotation = '"'; lastQuotation = '"';
incompleteToken = true; incompleteToken = true;
} else if ((singleQuoteExistOnly || singleQuoteIsBeforeDoubleQuote) && singleQuoteOccurrences % 2 !== 0) { } else if ((singleQuoteExistOnly || singleQuoteIsBeforeDoubleQuote)
&& singleQuoteOccurrences % 2 !== 0) {
// ' is found and is in front of " (if any) // ' is found and is in front of " (if any)
lastQuotation = '\''; lastQuotation = '\'';
incompleteToken = true; incompleteToken = true;
...@@ -137,7 +141,7 @@ ...@@ -137,7 +141,7 @@
tokens.push({ tokens.push({
key: keyMatch.key, key: keyMatch.key,
value: tokenValue, value: tokenValue,
wildcard: symbolMatch ? false : true, wildcard: !symbolMatch,
}); });
lastToken = tokens.last(); lastToken = tokens.last();
......
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