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
8ecc2117
Commit
8ecc2117
authored
Nov 30, 2016
by
Clement Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor validTokenKeys
parent
3d670422
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
75 deletions
+81
-75
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
...avascripts/filtered_search/filtered_search_manager.js.es6
+7
-44
app/assets/javascripts/filtered_search/filtered_search_token_keys.js.es6
...scripts/filtered_search/filtered_search_token_keys.js.es6
+45
-0
app/assets/javascripts/filtered_search/filtered_search_tokenizer.es6
...javascripts/filtered_search/filtered_search_tokenizer.es6
+29
-31
No files found.
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
View file @
8ecc2117
/* eslint-disable no-param-reassign */
((global) => {
const validTokenKeys = [{
key: 'author',
type: 'string',
param: 'username',
symbol: '@',
}, {
key: 'assignee',
type: 'string',
param: 'username',
symbol: '@',
conditions: [{
keyword: 'none',
url: 'assignee_id=0',
}],
}, {
key: 'milestone',
type: 'string',
param: 'title',
symbol: '%',
conditions: [{
keyword: 'none',
url: 'milestone_title=No+Milestone',
}, {
keyword: 'upcoming',
url: 'milestone_title=%23upcoming',
}],
}, {
key: 'label',
type: 'array',
param: 'name[]',
symbol: '~',
conditions: [{
keyword: 'none',
url: 'label_name[]=No+Label',
}],
}];
function clearSearch(e) {
e.stopPropagation();
e.preventDefault();
...
...
@@ -66,9 +29,9 @@
const key = decodeURIComponent(split[0]);
const value = split[1];
// Check if it matches edge conditions listed in
validTokenKeys
// Check if it matches edge conditions listed in
gl.FilteredSearchTokenKeys.get()
let conditionIndex = 0;
const validCondition =
validTokenKeys
const validCondition =
gl.FilteredSearchTokenKeys.get()
.filter(v => v.conditions && v.conditions.filter((c, index) => {
if (c.url === p) {
conditionIndex = index;
...
...
@@ -82,7 +45,7 @@
// Sanitize value since URL converts spaces into +
// Replace before decode so that we know what was originally + versus the encoded +
const sanitizedValue = value ? decodeURIComponent(value.replace(/[+]/g, ' ')) : value;
const match =
validTokenKeys
.filter(t => key === `${t.key}_${t.param}`)[0];
const match =
gl.FilteredSearchTokenKeys.get()
.filter(t => key === `${t.key}_${t.param}`)[0];
if (match) {
const sanitizedKey = key.slice(0, key.indexOf('_'));
...
...
@@ -116,7 +79,7 @@
class FilteredSearchManager {
constructor() {
this.tokenizer =
new gl.FilteredSearchTokenizer(validTokenKeys)
;
this.tokenizer =
gl.FilteredSearchTokenizer
;
this.bindEvents();
loadSearchParamsFromURL();
}
...
...
@@ -131,6 +94,7 @@
document.querySelector('.clear-search').addEventListener('click', clearSearch);
}
// TODO: This is only used for testing, remove when going to PRO
processInput(e) {
const input = e.target.value;
this.tokenizer.processTokens(input);
...
...
@@ -155,8 +119,7 @@
const defaultState = 'opened';
let currentState = defaultState;
const tokens = this.tokenizer.getTokens();
const searchToken = this.tokenizer.getSearchToken();
const { tokens, searchToken } = this.tokenizer.processTokens(document.querySelector('.filtered-search').value);
if (stateIndex !== -1) {
const remaining = currentPath.slice(stateIndex + 6);
...
...
@@ -167,7 +130,7 @@
path += `&state=${currentState}`;
tokens.forEach((token) => {
const match =
validTokenKeys
.filter(t => t.key === token.key)[0];
const match =
gl.FilteredSearchTokenKeys.get()
.filter(t => t.key === token.key)[0];
let tokenPath = '';
if (token.wildcard && match.conditions) {
...
...
app/assets/javascripts/filtered_search/filtered_search_token_keys.js.es6
0 → 100644
View file @
8ecc2117
/* eslint-disable no-param-reassign */
((global) => {
class FilteredSearchTokenKeys {
static get() {
return [{
key: 'author',
type: 'string',
param: 'username',
symbol: '@',
}, {
key: 'assignee',
type: 'string',
param: 'username',
symbol: '@',
conditions: [{
keyword: 'none',
url: 'assignee_id=0',
}],
}, {
key: 'milestone',
type: 'string',
param: 'title',
symbol: '%',
conditions: [{
keyword: 'none',
url: 'milestone_title=No+Milestone',
}, {
keyword: 'upcoming',
url: 'milestone_title=%23upcoming',
}],
}, {
key: 'label',
type: 'array',
param: 'name[]',
symbol: '~',
conditions: [{
keyword: 'none',
url: 'label_name[]=No+Label',
}],
}];
}
}
global.FilteredSearchTokenKeys = FilteredSearchTokenKeys;
})(window.gl || (window.gl = {}));
app/assets/javascripts/filtered_search/filtered_search_tokenizer.es6
View file @
8ecc2117
/* eslint-disable no-param-reassign */
((global) => {
class FilteredSearchTokenizer {
constructor(validTokenKeys) {
this.validTokenKeys = validTokenKeys;
this.resetTokens();
}
getTokens() {
return this.tokens;
}
getSearchToken() {
return this.searchToken;
}
resetTokens() {
this.tokens = [];
this.searchToken = '';
}
printTokens() {
// TODO: Remove when going to pro
static printTokens(tokens, searchToken, lastToken) {
console.log('tokens:');
this.tokens.forEach(token => console.log(token));
console.log(`search: ${this.searchToken}`);
tokens.forEach(token => console.log(token));
console.log(`search: ${searchToken}`);
console.log('last token:');
console.log(lastToken);
}
processTokens(input) {
// Re-calculate tokens
this.resetTokens();
static processTokens(input) {
let tokens = [];
let searchToken = '';
let lastToken = '';
const validTokenKeys = gl.FilteredSearchTokenKeys.get();
const inputs = input.split(' ');
let searchTerms = '';
...
...
@@ -36,16 +23,17 @@
inputs.forEach((i) => {
if (incompleteToken) {
const prevToken = t
his.t
okens.last();
const prevToken = tokens.last();
prevToken.value += ` ${i}`;
// Remove last quotation
const lastQuotationRegex = new RegExp(lastQuotation, 'g');
prevToken.value = prevToken.value.replace(lastQuotationRegex, '');
t
his.tokens[this.
tokens.length - 1] = prevToken;
t
okens[
tokens.length - 1] = prevToken;
// Check to see if this quotation completes the token value
if (i.indexOf(lastQuotation)) {
lastToken = tokens.last();
incompleteToken = !incompleteToken;
}
...
...
@@ -59,8 +47,8 @@
const tokenValue = i.slice(colonIndex + 1);
const tokenSymbol = tokenValue[0];
console.log(tokenSymbol)
const keyMatch =
this.
validTokenKeys.filter(v => v.key === tokenKey)[0];
const symbolMatch =
this.
validTokenKeys.filter(v => v.symbol === tokenSymbol)[0];
const keyMatch = validTokenKeys.filter(v => v.key === tokenKey)[0];
const symbolMatch = validTokenKeys.filter(v => v.symbol === tokenSymbol)[0];
const doubleQuoteIndex = tokenValue.indexOf('"');
const singleQuoteIndex = tokenValue.indexOf('\'');
...
...
@@ -81,11 +69,12 @@
}
if (keyMatch && tokenValue.length > 0) {
t
his.t
okens.push({
tokens.push({
key: keyMatch.key,
value: tokenValue,
wildcard: symbolMatch ? false : true,
});
lastToken = tokens.last();
return;
}
...
...
@@ -93,10 +82,19 @@
// Add space for next term
searchTerms += `${i} `;
lastToken = i;
}, this);
this.searchToken = searchTerms.trim();
this.printTokens();
searchToken = searchTerms.trim();
// TODO: Remove when going to PRO
gl.FilteredSearchTokenizer.printTokens(tokens, searchToken, lastToken);
return {
tokens,
searchToken,
lastToken,
};
}
}
...
...
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