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
Boxiang Sun
gitlab-ce
Commits
bf16e91f
Commit
bf16e91f
authored
Dec 12, 2016
by
Clement Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor FilteredSearchTokenKeys model
parent
49231cce
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
71 deletions
+81
-71
app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6
...s/filtered_search/filtered_search_dropdown_manager.js.es6
+1
-1
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
...avascripts/filtered_search/filtered_search_manager.js.es6
+17
-31
app/assets/javascripts/filtered_search/filtered_search_token_keys.js.es6
...scripts/filtered_search/filtered_search_token_keys.js.es6
+61
-36
app/assets/javascripts/filtered_search/filtered_search_tokenizer.es6
...javascripts/filtered_search/filtered_search_tokenizer.es6
+2
-3
No files found.
app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6
View file @
bf16e91f
...
...
@@ -125,7 +125,7 @@
this.droplab = new DropLab();
}
const match = gl.FilteredSearchTokenKeys.
get().filter(value => value.key === dropdownName.toLowerCase())[0]
;
const match = gl.FilteredSearchTokenKeys.
searchByKey(dropdownName.toLowerCase())
;
const shouldOpenFilterDropdown = match && this.currentDropdown !== match.key && this.mapping.hasOwnProperty(match.key);
const shouldOpenHintDropdown = !match && this.currentDropdown !== 'hint';
...
...
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
View file @
bf16e91f
...
...
@@ -85,42 +85,32 @@
params.forEach((p) => {
const split = p.split('=');
const key = decodeURIComponent(split[0]);
const key
Param
= decodeURIComponent(split[0]);
const value = split[1];
// Check if it matches edge conditions listed in gl.FilteredSearchTokenKeys.get()
let conditionIndex = 0;
const validCondition = gl.FilteredSearchTokenKeys.get()
.filter(v => v.conditions && v.conditions.filter((c, index) => {
// Return TokenKeys that have conditions that much the URL
if (c.url === p) {
conditionIndex = index;
}
return c.url === p;
})[0])[0];
// Check if it matches edge conditions listed in gl.FilteredSearchTokenKeys
const condition = gl.FilteredSearchTokenKeys.searchByConditionUrl(p);
if (validCondition) {
// Parse params based on rules provided in the conditions key of gl.FilteredSearchTokenKeys.get()
inputValues.push(`${validCondition.key}:${validCondition.conditions[conditionIndex].keyword}`);
if (condition) {
inputValues.push(`${condition.tokenKey}:${condition.value}`);
} else {
// 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 = gl.FilteredSearchTokenKeys.
get().filter(t => key === `${t.key}_${t.param}`)[0]
;
const match = gl.FilteredSearchTokenKeys.
searchByKeyParam(keyParam)
;
if (match) {
const sanitizedKey = key.slice(0, key.indexOf('_'));
const valueHasSpace = sanitizedValue.indexOf(' ') !== -1;
const sanitizedKey = keyParam.slice(0, keyParam.indexOf('_'));
const symbol = match.symbol;
let quotationsToUse;
let quotationsToUse
= ''
;
if (
valueHasSpace
) {
if (
sanitizedValue.indexOf(' ') !== -1
) {
// Prefer ", but use ' if required
quotationsToUse = sanitizedValue.indexOf('"') === -1 ? '"' : '\'';
}
inputValues.push(
valueHasSpace ? `${sanitizedKey}:${symbol}${quotationsToUse}${sanitizedValue}${quotationsToUse}` : `${sanitizedKey}:${symbol}${sanitizedValu
e}`);
} else if (!match && key === 'search') {
inputValues.push(
`${sanitizedKey}:${symbol}${quotationsToUse}${sanitizedValue}${quotationsToUs
e}`);
} else if (!match && key
Param
=== 'search') {
inputValues.push(sanitizedValue);
}
}
...
...
@@ -141,21 +131,17 @@
paths.push(`state=${currentState}`);
tokens.forEach((token) => {
const match = gl.FilteredSearchTokenKeys.get().filter(t => t.key === token.key)[0];
const condition = gl.FilteredSearchTokenKeys.searchByConditionKeyValue(token.key, token.value.toLowerCase());
const { param } = gl.FilteredSearchTokenKeys.searchByKey(token.key);
let tokenPath = '';
if (token.wildcard && match.conditions) {
const condition = match.conditions
.filter(c => c.keyword === token.value.toLowerCase())[0];
if (condition) {
tokenPath = `${condition.url}`;
}
if (token.wildcard && condition) {
tokenPath = condition.url;
} else if (!token.wildcard) {
// Remove the wildcard token
tokenPath = `${token.key}_${
match.
param}=${encodeURIComponent(token.value.slice(1))}`;
tokenPath = `${token.key}_${param}=${encodeURIComponent(token.value.slice(1))}`;
} else {
tokenPath = `${token.key}_${
match.
param}=${encodeURIComponent(token.value)}`;
tokenPath = `${token.key}_${param}=${encodeURIComponent(token.value)}`;
}
paths.push(tokenPath);
...
...
app/assets/javascripts/filtered_search/filtered_search_token_keys.js.es6
View file @
bf16e91f
/* eslint-disable no-param-reassign */
((global) => {
class FilteredSearchTokenKeys {
static get() {
return [{
const tokenKeys = [{
key: 'author',
type: 'string',
param: 'username',
...
...
@@ -12,32 +10,59 @@
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',
}];
const conditions = [{
url: 'assignee_id=0',
tokenKey: 'assignee',
value: 'none',
}, {
url: 'milestone_title=No+Milestone',
tokenKey: 'milestone',
value: 'none',
}, {
url: 'milestone_title=%23upcoming',
tokenKey: 'milestone',
value: 'upcoming',
}, {
url: 'label_name[]=No+Label',
}],
tokenKey: 'label',
value: 'none',
}];
class FilteredSearchTokenKeys {
static get() {
return tokenKeys;
}
static searchByKey(key) {
return tokenKeys.find(tokenKey => tokenKey.key === key) || null;
}
static searchBySymbol(symbol) {
return tokenKeys.find(tokenKey => tokenKey.symbol === symbol) || null;
}
static searchByKeyParam(keyParam) {
return tokenKeys.find(tokenKey => keyParam === `${tokenKey.key}_${tokenKey.param}`) || null;
}
static searchByConditionUrl(url) {
return conditions.find(condition => condition.url === url) || null;
}
static searchByConditionKeyValue(key, value) {
return conditions.find(condition => condition.tokenKey === key && condition.value === value) || null;
}
}
...
...
app/assets/javascripts/filtered_search/filtered_search_tokenizer.es6
View file @
bf16e91f
...
...
@@ -73,7 +73,6 @@
let tokens = [];
let searchToken = '';
let lastToken = '';
const validTokenKeys = gl.FilteredSearchTokenKeys.get();
const inputs = input.split(' ');
let searchTerms = '';
...
...
@@ -107,8 +106,8 @@
if (colonIndex !== -1) {
const { tokenKey, tokenValue, tokenSymbol } = gl.FilteredSearchTokenizer.parseToken(i);
const keyMatch =
validTokenKeys.filter(v => v.key === tokenKey)[0]
;
const symbolMatch =
validTokenKeys.filter(v => v.symbol === tokenSymbol)[0]
;
const keyMatch =
gl.FilteredSearchTokenKeys.searchByKey(tokenKey)
;
const symbolMatch =
gl.FilteredSearchTokenKeys.searchBySymbol(tokenSymbol)
;
const doubleQuoteOccurrences = tokenValue.split('"').length - 1;
const singleQuoteOccurrences = tokenValue.split('\'').length - 1;
...
...
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