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
Tatuya Kamada
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
Hide 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 @@
...
@@ -125,7 +125,7 @@
this.droplab = new DropLab();
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 shouldOpenFilterDropdown = match && this.currentDropdown !== match.key && this.mapping.hasOwnProperty(match.key);
const shouldOpenHintDropdown = !match && this.currentDropdown !== 'hint';
const shouldOpenHintDropdown = !match && this.currentDropdown !== 'hint';
...
...
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
View file @
bf16e91f
...
@@ -85,42 +85,32 @@
...
@@ -85,42 +85,32 @@
params.forEach((p) => {
params.forEach((p) => {
const split = p.split('=');
const split = p.split('=');
const key = decodeURIComponent(split[0]);
const key
Param
= decodeURIComponent(split[0]);
const value = split[1];
const value = split[1];
// Check if it matches edge conditions listed in gl.FilteredSearchTokenKeys.get()
// Check if it matches edge conditions listed in gl.FilteredSearchTokenKeys
let conditionIndex = 0;
const condition = gl.FilteredSearchTokenKeys.searchByConditionUrl(p);
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];
if (validCondition) {
if (condition) {
// Parse params based on rules provided in the conditions key of gl.FilteredSearchTokenKeys.get()
inputValues.push(`${condition.tokenKey}:${condition.value}`);
inputValues.push(`${validCondition.key}:${validCondition.conditions[conditionIndex].keyword}`);
} else {
} else {
// Sanitize value since URL converts spaces into +
// Sanitize value since URL converts spaces into +
// Replace before decode so that we know what was originally + versus the encoded +
// Replace before decode so that we know what was originally + versus the encoded +
const sanitizedValue = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : value;
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) {
if (match) {
const sanitizedKey = key.slice(0, key.indexOf('_'));
const sanitizedKey = keyParam.slice(0, keyParam.indexOf('_'));
const valueHasSpace = sanitizedValue.indexOf(' ') !== -1;
const symbol = match.symbol;
const symbol = match.symbol;
let quotationsToUse;
let quotationsToUse
= ''
;
if (
valueHasSpace
) {
if (
sanitizedValue.indexOf(' ') !== -1
) {
// Prefer ", but use ' if required
// Prefer ", but use ' if required
quotationsToUse = sanitizedValue.indexOf('"') === -1 ? '"' : '\'';
quotationsToUse = sanitizedValue.indexOf('"') === -1 ? '"' : '\'';
}
}
inputValues.push(
valueHasSpace ? `${sanitizedKey}:${symbol}${quotationsToUse}${sanitizedValue}${quotationsToUse}` : `${sanitizedKey}:${symbol}${sanitizedValu
e}`);
inputValues.push(
`${sanitizedKey}:${symbol}${quotationsToUse}${sanitizedValue}${quotationsToUs
e}`);
} else if (!match && key === 'search') {
} else if (!match && key
Param
=== 'search') {
inputValues.push(sanitizedValue);
inputValues.push(sanitizedValue);
}
}
}
}
...
@@ -141,21 +131,17 @@
...
@@ -141,21 +131,17 @@
paths.push(`state=${currentState}`);
paths.push(`state=${currentState}`);
tokens.forEach((token) => {
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 = '';
let tokenPath = '';
if (token.wildcard && match.conditions) {
if (token.wildcard && condition) {
const condition = match.conditions
tokenPath = condition.url;
.filter(c => c.keyword === token.value.toLowerCase())[0];
if (condition) {
tokenPath = `${condition.url}`;
}
} else if (!token.wildcard) {
} else if (!token.wildcard) {
// Remove the wildcard token
// Remove the wildcard token
tokenPath = `${token.key}_${
match.
param}=${encodeURIComponent(token.value.slice(1))}`;
tokenPath = `${token.key}_${param}=${encodeURIComponent(token.value.slice(1))}`;
} else {
} else {
tokenPath = `${token.key}_${
match.
param}=${encodeURIComponent(token.value)}`;
tokenPath = `${token.key}_${param}=${encodeURIComponent(token.value)}`;
}
}
paths.push(tokenPath);
paths.push(tokenPath);
...
...
app/assets/javascripts/filtered_search/filtered_search_token_keys.js.es6
View file @
bf16e91f
/* eslint-disable no-param-reassign */
/* eslint-disable no-param-reassign */
((global) => {
((global) => {
const tokenKeys = [{
key: 'author',
type: 'string',
param: 'username',
symbol: '@',
}, {
key: 'assignee',
type: 'string',
param: 'username',
symbol: '@',
}, {
key: 'milestone',
type: 'string',
param: 'title',
symbol: '%',
}, {
key: 'label',
type: 'array',
param: 'name[]',
symbol: '~',
}];
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 {
class FilteredSearchTokenKeys {
static get() {
static get() {
return [{
return tokenKeys;
key: 'author',
}
type: 'string',
param: 'username',
static searchByKey(key) {
symbol: '@',
return tokenKeys.find(tokenKey => tokenKey.key === key) || null;
}, {
}
key: 'assignee',
type: 'string',
static searchBySymbol(symbol) {
param: 'username',
return tokenKeys.find(tokenKey => tokenKey.symbol === symbol) || null;
symbol: '@',
}
conditions: [{
keyword: 'none',
static searchByKeyParam(keyParam) {
url: 'assignee_id=0',
return tokenKeys.find(tokenKey => keyParam === `${tokenKey.key}_${tokenKey.param}`) || null;
}],
}
}, {
key: 'milestone',
static searchByConditionUrl(url) {
type: 'string',
return conditions.find(condition => condition.url === url) || null;
param: 'title',
}
symbol: '%',
conditions: [{
static searchByConditionKeyValue(key, value) {
keyword: 'none',
return conditions.find(condition => condition.tokenKey === key && condition.value === value) || null;
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',
}],
}];
}
}
}
}
...
...
app/assets/javascripts/filtered_search/filtered_search_tokenizer.es6
View file @
bf16e91f
...
@@ -73,7 +73,6 @@
...
@@ -73,7 +73,6 @@
let tokens = [];
let tokens = [];
let searchToken = '';
let searchToken = '';
let lastToken = '';
let lastToken = '';
const validTokenKeys = gl.FilteredSearchTokenKeys.get();
const inputs = input.split(' ');
const inputs = input.split(' ');
let searchTerms = '';
let searchTerms = '';
...
@@ -107,8 +106,8 @@
...
@@ -107,8 +106,8 @@
if (colonIndex !== -1) {
if (colonIndex !== -1) {
const { tokenKey, tokenValue, tokenSymbol } = gl.FilteredSearchTokenizer.parseToken(i);
const { tokenKey, tokenValue, tokenSymbol } = gl.FilteredSearchTokenizer.parseToken(i);
const keyMatch =
validTokenKeys.filter(v => v.key === tokenKey)[0]
;
const keyMatch =
gl.FilteredSearchTokenKeys.searchByKey(tokenKey)
;
const symbolMatch =
validTokenKeys.filter(v => v.symbol === tokenSymbol)[0]
;
const symbolMatch =
gl.FilteredSearchTokenKeys.searchBySymbol(tokenSymbol)
;
const doubleQuoteOccurrences = tokenValue.split('"').length - 1;
const doubleQuoteOccurrences = tokenValue.split('"').length - 1;
const singleQuoteOccurrences = 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