mirror of https://github.com/zulip/zulip.git
Describe negated search terms correctly.
This changes Filter.describe and Filter.operator_to_prefix to handle negated terms correctly. (imported from commit 673c0d3a5a77784e95772c14e12534ad2daecda2)
This commit is contained in:
parent
8611cc3977
commit
8ce5404777
|
@ -357,14 +357,14 @@ Filter.prototype = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Filter.operator_to_prefix = function (operator) {
|
Filter.operator_to_prefix = function (operator, negated) {
|
||||||
var verb;
|
var verb;
|
||||||
|
|
||||||
if (operator === 'search') {
|
if (operator === 'search') {
|
||||||
return 'Search for';
|
return negated ? 'Exclude' : 'Search for';
|
||||||
}
|
}
|
||||||
|
|
||||||
verb = 'Narrow to ';
|
verb = negated ? 'Exclude ' : 'Narrow to ';
|
||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case 'stream':
|
case 'stream':
|
||||||
|
@ -400,7 +400,11 @@ Filter.describe = function (operators) {
|
||||||
var parts = [];
|
var parts = [];
|
||||||
|
|
||||||
if (operators.length >= 2) {
|
if (operators.length >= 2) {
|
||||||
if (operators[0].operator === 'stream' && operators[1].operator === 'topic') {
|
var is = function (term, expected) {
|
||||||
|
return (term.operator === expected) && !term.negated;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (is(operators[0], 'stream') && is(operators[1], 'topic')) {
|
||||||
var stream = operators[0].operand;
|
var stream = operators[0].operand;
|
||||||
var topic = operators[1].operand;
|
var topic = operators[1].operand;
|
||||||
var part = 'Narrow to ' + stream + ' > ' + topic;
|
var part = 'Narrow to ' + stream + ' > ' + topic;
|
||||||
|
@ -413,7 +417,7 @@ Filter.describe = function (operators) {
|
||||||
var operand = elem.operand;
|
var operand = elem.operand;
|
||||||
var canonicalized_operator = Filter.canonicalize_operator(elem.operator);
|
var canonicalized_operator = Filter.canonicalize_operator(elem.operator);
|
||||||
if (canonicalized_operator ==='is') {
|
if (canonicalized_operator ==='is') {
|
||||||
var verb = 'Narrow to ';
|
var verb = elem.negated ? 'Exclude ' : 'Narrow to ';
|
||||||
if (operand === 'private') {
|
if (operand === 'private') {
|
||||||
return verb + 'all private messages';
|
return verb + 'all private messages';
|
||||||
} else if (operand === 'starred') {
|
} else if (operand === 'starred') {
|
||||||
|
@ -424,7 +428,7 @@ Filter.describe = function (operators) {
|
||||||
return verb + 'alerted messages';
|
return verb + 'alerted messages';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var prefix_for_operator = Filter.operator_to_prefix(canonicalized_operator);
|
var prefix_for_operator = Filter.operator_to_prefix(canonicalized_operator, elem.negated);
|
||||||
if (prefix_for_operator !== '') {
|
if (prefix_for_operator !== '') {
|
||||||
return prefix_for_operator + ' ' + operand;
|
return prefix_for_operator + ' ' + operand;
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,5 +373,26 @@ function get_predicate(operators) {
|
||||||
string = 'Narrow to all private messages, Search for lunch';
|
string = 'Narrow to all private messages, Search for lunch';
|
||||||
assert.equal(Filter.describe(narrow), string);
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|
||||||
|
narrow = [
|
||||||
|
{operator: 'stream', operand: 'devel'},
|
||||||
|
{operator: 'topic', operand: 'JS', negated: true}
|
||||||
|
];
|
||||||
|
string = 'Narrow to stream devel, Exclude topic JS';
|
||||||
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|
||||||
|
narrow = [
|
||||||
|
{operator: 'is', operand: 'private'},
|
||||||
|
{operator: 'search', operand: 'lunch', negated: true}
|
||||||
|
];
|
||||||
|
string = 'Narrow to all private messages, Exclude lunch';
|
||||||
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|
||||||
|
narrow = [
|
||||||
|
{operator: 'stream', operand: 'devel'},
|
||||||
|
{operator: 'is', operand: 'starred', negated: true}
|
||||||
|
];
|
||||||
|
string = 'Narrow to stream devel, Exclude starred messages';
|
||||||
|
assert.equal(Filter.describe(narrow), string);
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue