Move describe() from narrow.js to search.js.

(This function is only used in the search code.)

(imported from commit 44d53fbd73be56d9d416ebcafdc517c686e7adf8)
This commit is contained in:
Steve Howell 2013-07-15 13:25:47 -04:00
parent 84a97f5c41
commit b4dd0efc74
2 changed files with 40 additions and 38 deletions

View File

@ -248,43 +248,6 @@ function unparse(operators) {
return parts.join(' ');
}
// Convert a list of operators to a human-readable description.
exports.describe = function (operators) {
return $.map(operators, function (elem) {
var operand = elem[1];
switch (elem[0]) {
case 'is':
if (operand === 'private') {
return 'Narrow to all private messages';
} else if (operand === 'starred') {
return 'Narrow to starred messages';
} else if (operand === 'mentioned') {
return 'Narrow to mentioned messages';
}
break;
case 'stream':
return 'Narrow to stream ' + operand;
case 'subject':
return 'Narrow to subject ' + operand;
case 'sender':
return 'Narrow to sender ' + operand;
case 'pm-with':
return 'Narrow to private messages with ' + operand;
case 'search':
return 'Search for ' + operand;
case 'in':
return 'Narrow to messages in ' + operand;
}
return 'Narrow to (unknown operator)';
}).join(', ');
};
// Collect operators which appear only once into an object,
// and discard those which appear more than once.
function collect_single(operators) {

View File

@ -42,6 +42,44 @@ function stream_matches_query(stream_name, q) {
return phrase_match(stream_name, q);
}
// Convert a list of operators to a human-readable description.
function describe(operators) {
return $.map(operators, function (elem) {
var operand = elem[1];
switch (elem[0]) {
case 'is':
if (operand === 'private') {
return 'Narrow to all private messages';
} else if (operand === 'starred') {
return 'Narrow to starred messages';
} else if (operand === 'mentioned') {
return 'Narrow to mentioned messages';
}
break;
case 'stream':
return 'Narrow to stream ' + operand;
case 'subject':
return 'Narrow to subject ' + operand;
case 'sender':
return 'Narrow to sender ' + operand;
case 'pm-with':
return 'Narrow to private messages with ' + operand;
case 'search':
return 'Search for ' + operand;
case 'in':
return 'Narrow to messages in ' + operand;
}
return 'Narrow to (unknown operator)';
}).join(', ');
}
function render_object_in_parts(obj) {
// N.B. action is *not* escaped by the caller
switch (obj.action) {
@ -50,6 +88,7 @@ function render_object_in_parts(obj) {
case 'private_message':
return {prefix: 'Narrow to private messages with',
query: get_person(obj),
suffix: ''};
@ -64,7 +103,7 @@ function render_object_in_parts(obj) {
// after 'Narrow to' ensures this, and is invisible with standard HTML
// whitespace handling.
return {prefix: '',
query: narrow.describe(obj.operators),
query: describe(obj.operators),
suffix: ''};
}
return {prefix: 'Error', query: 'Error', suffix: 'Error'};