Bug 586131 - Add OR functionality using | (Pipe character) to Quickfilter bar. r=mkmelin, r=squib, ui-r=bwinton
This commit is contained in:
Родитель
30edd29460
Коммит
dcc4760b7c
|
@ -968,9 +968,13 @@ let MessageTextFilter = {
|
|||
terms.push(aTerm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for spaces around | (OR operator) and remove them.
|
||||
*/
|
||||
aSearchString = aSearchString.replace(/\s*\|\s*/g, "|");
|
||||
while (aSearchString) {
|
||||
if (aSearchString.startsWith('"')) {
|
||||
let endIndex = aSearchString.indexOf(aSearchString[0], 1);
|
||||
let endIndex = aSearchString.indexOf('"', 1);
|
||||
// treat a quote without a friend as making a phrase containing the
|
||||
// rest of the string...
|
||||
if (endIndex == -1) {
|
||||
|
@ -982,14 +986,9 @@ let MessageTextFilter = {
|
|||
continue;
|
||||
}
|
||||
|
||||
let spaceIndex = aSearchString.indexOf(" ");
|
||||
if (spaceIndex == -1) {
|
||||
addTerm(aSearchString);
|
||||
break;
|
||||
}
|
||||
|
||||
addTerm(aSearchString.substring(0, spaceIndex));
|
||||
aSearchString = aSearchString.substring(spaceIndex+1);
|
||||
let searchTerms = aSearchString.split(" ");
|
||||
searchTerms.forEach(searchTerm => addTerm(searchTerm));
|
||||
break;
|
||||
}
|
||||
|
||||
return terms;
|
||||
|
@ -1006,26 +1005,29 @@ let MessageTextFilter = {
|
|||
|
||||
if (aFilterValue.text) {
|
||||
let phrases = this._parseSearchString(aFilterValue.text);
|
||||
for each (let [, phrase] in Iterator(phrases)) {
|
||||
for (let groupedPhrases of phrases) {
|
||||
let firstClause = true;
|
||||
term = null;
|
||||
for each (let [tfName, tfValue] in Iterator(aFilterValue.states)) {
|
||||
if (!tfValue)
|
||||
continue;
|
||||
let tfDef = this.textFilterDefs[tfName];
|
||||
let splitPhrases = groupedPhrases.split("|");
|
||||
for (let phrase of splitPhrases) {
|
||||
for (let [tfName, tfValue] in Iterator(aFilterValue.states)) {
|
||||
if (!tfValue)
|
||||
continue;
|
||||
let tfDef = this.textFilterDefs[tfName];
|
||||
|
||||
term = aTermCreator.createTerm();
|
||||
term.attrib = tfDef.attrib;
|
||||
value = term.value;
|
||||
value.attrib = tfDef.attrib;
|
||||
value.str = phrase;
|
||||
term.value = value;
|
||||
term.op = nsMsgSearchOp.Contains;
|
||||
// AND for the group, but OR inside the group
|
||||
term.booleanAnd = firstClause;
|
||||
term.beginsGrouping = firstClause;
|
||||
aTerms.push(term);
|
||||
firstClause = false;
|
||||
term = aTermCreator.createTerm();
|
||||
term.attrib = tfDef.attrib;
|
||||
value = term.value;
|
||||
value.attrib = tfDef.attrib;
|
||||
value.str = phrase;
|
||||
term.value = value;
|
||||
term.op = nsMsgSearchOp.Contains;
|
||||
// AND for the group, but OR inside the group
|
||||
term.booleanAnd = firstClause;
|
||||
term.beginsGrouping = firstClause;
|
||||
aTerms.push(term);
|
||||
firstClause = false;
|
||||
}
|
||||
}
|
||||
if (term)
|
||||
term.endsGrouping = true;
|
||||
|
|
|
@ -239,6 +239,50 @@ function test_filter_text_multi_word() {
|
|||
assert_messages_in_view([setPeepMatch, setSubjReverse]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the quickfilter bar has OR functionality using
|
||||
* | (Pipe character) - Bug 586131
|
||||
*/
|
||||
function test_filter_or_operator() {
|
||||
let folder = create_folder("QuickFilterBarOrOperator");
|
||||
|
||||
let whoFoo = ["foo", "zabba@madeup.invalid"];
|
||||
let whoBar = ["zabba", "bar@madeup.invalid"];
|
||||
let whoTest = ["test", "test@madeup.invalid"];
|
||||
let [setInert, setSenderFoo, setToBar,
|
||||
setSubject1, setSubject2, setSubject3,
|
||||
setMail1, setMail2] =
|
||||
make_new_sets_in_folder(folder, [
|
||||
{count: 1},
|
||||
{count: 1, from: whoFoo},
|
||||
{count: 1, to: [whoBar]},
|
||||
{count: 1, subject: "foo bar"},
|
||||
{count: 1, subject: "bar test"},
|
||||
{count: 1, subject: "test"},
|
||||
{count: 1, to: [whoTest], subject: "logic"},
|
||||
{count: 1, from: whoFoo, to: [whoBar], subject: "test"}]);
|
||||
be_in_folder(folder);
|
||||
|
||||
assert_text_constraints_checked("sender", "recipients", "subject");
|
||||
set_filter_text("foo | bar");
|
||||
assert_messages_not_in_view([setInert, setSubject3, setMail1]);
|
||||
|
||||
set_filter_text("test | bar");
|
||||
assert_messages_not_in_view([setInert, setSenderFoo]);
|
||||
|
||||
set_filter_text("foo | test");
|
||||
assert_messages_not_in_view([setInert, setToBar]);
|
||||
|
||||
// consists of leading and trailing spaces and tab character.
|
||||
set_filter_text("test | foo bar");
|
||||
assert_messages_not_in_view([setInert, setSenderFoo, setToBar,
|
||||
setSubject3, setMail1]);
|
||||
|
||||
set_filter_text("test | foo bar |logic");
|
||||
assert_messages_not_in_view([setInert, setSenderFoo, setToBar,
|
||||
setSubject3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that when dropping all constraints on toggle off or changing
|
||||
* folders that we persist/propagate the state of the
|
||||
|
|
Загрузка…
Ссылка в новой задаче