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
329b03b3
Commit
329b03b3
authored
Nov 14, 2016
by
Clement Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add token symbol matching
parent
01eb0571
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
26 deletions
+78
-26
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
...avascripts/filtered_search/filtered_search_manager.js.es6
+71
-23
app/assets/javascripts/filtered_search/filtered_search_tokenizer.es6
...javascripts/filtered_search/filtered_search_tokenizer.es6
+7
-3
No files found.
app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
View file @
329b03b3
...
@@ -4,18 +4,37 @@
...
@@ -4,18 +4,37 @@
key: 'author',
key: 'author',
type: 'string',
type: 'string',
param: 'username',
param: 'username',
symbol: '@',
}, {
}, {
key: 'assignee',
key: 'assignee',
type: 'string',
type: 'string',
param: 'username',
param: 'username',
symbol: '@',
conditions: [{
keyword: 'none',
url: 'assignee_id=0',
}]
}, {
}, {
key: 'milestone',
key: 'milestone',
type: 'string',
type: 'string',
param: 'title',
param: 'title',
symbol: '%',
conditions: [{
keyword: 'none',
url: 'milestone_title=No+Milestone',
}, {
keyword: 'upcoming',
url: 'milestone_title=%23upcoming',
}]
}, {
}, {
key: 'label',
key: 'label',
type: 'array',
type: 'array',
param: 'name[]',
param: 'name[]',
symbol: '~',
conditions: [{
keyword: 'none',
url: 'label_name[]=No+Label',
}]
}];
}];
function clearSearch(e) {
function clearSearch(e) {
...
@@ -47,28 +66,42 @@
...
@@ -47,28 +66,42 @@
const key = decodeURIComponent(split[0]);
const key = decodeURIComponent(split[0]);
const value = split[1];
const value = split[1];
// Sanitize value since URL converts spaces into +
// Check if it matches edge conditions listed in validTokenKeys
// Replace before decode so that we know what was originally + versus the encoded +
let conditionIndex = 0;
const sanitizedValue = value ? decodeURIComponent(value.replace(/[+]/g, ' ')) : value;
const validCondition = validTokenKeys.filter(v => v.conditions && v.conditions.filter((c, index) => {
const match = validTokenKeys.filter(t => key === `${t.key}_${t.param}`)[0];
if (c.url === p) {
conditionIndex = index;
if (match) {
}
const sanitizedKey = key.slice(0, key.indexOf('_'));
return c.url === p;
const valueHasSpace = sanitizedValue.indexOf(' ') !== -1;
})[0])[0];
const preferredQuotations = '"';
if (validCondition) {
let quotationsToUse = preferredQuotations;
inputValue += `${validCondition.key}:${validCondition.conditions[conditionIndex].keyword}`;
} else {
if (valueHasSpace) {
// Sanitize value since URL converts spaces into +
// Prefer ", but use ' if required
// Replace before decode so that we know what was originally + versus the encoded +
quotationsToUse = sanitizedValue.indexOf(preferredQuotations) === -1 ? preferredQuotations : '\'';
const sanitizedValue = value ? decodeURIComponent(value.replace(/[+]/g, ' ')) : value;
const match = validTokenKeys.filter(t => key === `${t.key}_${t.param}`)[0];
if (match) {
const sanitizedKey = key.slice(0, key.indexOf('_'));
const valueHasSpace = sanitizedValue.indexOf(' ') !== -1;
const symbol = match.symbol;
const preferredQuotations = '"';
let quotationsToUse = preferredQuotations;
if (valueHasSpace) {
// Prefer ", but use ' if required
quotationsToUse = sanitizedValue.indexOf(preferredQuotations) === -1 ? preferredQuotations : '\'';
}
inputValue += valueHasSpace ? `${sanitizedKey}:${symbol}${quotationsToUse}${sanitizedValue}${quotationsToUse}` : `${sanitizedKey}:${symbol}${sanitizedValue}`;
inputValue += ' ';
} else if (!match && key === 'search') {
inputValue += sanitizedValue;
inputValue += ' ';
}
}
inputValue += valueHasSpace ? `${sanitizedKey}:${quotationsToUse}${sanitizedValue}${quotationsToUse}` : `${sanitizedKey}:${sanitizedValue}`;
inputValue += ' ';
} else if (!match && key === 'search') {
inputValue += sanitizedValue;
inputValue += ' ';
}
}
});
});
...
@@ -133,8 +166,23 @@
...
@@ -133,8 +166,23 @@
path += `&state=${currentState}`;
path += `&state=${currentState}`;
tokens.forEach((token) => {
tokens.forEach((token) => {
const param = validTokenKeys.filter(t => t.key === token.key)[0].param;
const match = validTokenKeys.filter(t => t.key === token.key)[0];
path += `&${token.key}_${param}=${encodeURIComponent(token.value)}`;
let tokenPath = '';
if (token.wildcard && match.conditions) {
const condition = match.conditions.filter(c => c.keyword === token.value.toLowerCase())[0];
if (condition) {
tokenPath = `${condition.url}`;
}
} else if (!token.wildcard) {
// Remove the wildcard token
tokenPath = `${token.key}_${match.param}=${encodeURIComponent(token.value.slice(1))}`;
} else {
tokenPath = `${token.key}_${match.param}=${encodeURIComponent(token.value)}`;
}
path += `&${tokenPath}`;
});
});
if (searchToken) {
if (searchToken) {
...
...
app/assets/javascripts/filtered_search/filtered_search_tokenizer.es6
View file @
329b03b3
...
@@ -57,7 +57,10 @@
...
@@ -57,7 +57,10 @@
if (colonIndex !== -1) {
if (colonIndex !== -1) {
const tokenKey = i.slice(0, colonIndex).toLowerCase();
const tokenKey = i.slice(0, colonIndex).toLowerCase();
const tokenValue = i.slice(colonIndex + 1);
const tokenValue = i.slice(colonIndex + 1);
const match = this.validTokenKeys.filter(v => v.key === tokenKey)[0];
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];
if (tokenValue.indexOf('"') !== -1) {
if (tokenValue.indexOf('"') !== -1) {
lastQuotation = '"';
lastQuotation = '"';
...
@@ -67,10 +70,11 @@
...
@@ -67,10 +70,11 @@
incompleteToken = true;
incompleteToken = true;
}
}
if (
m
atch && tokenValue.length > 0) {
if (
keyM
atch && tokenValue.length > 0) {
this.tokens.push({
this.tokens.push({
key:
m
atch.key,
key:
keyM
atch.key,
value: tokenValue,
value: tokenValue,
wildcard: symbolMatch ? false : true,
});
});
return;
return;
...
...
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