search.js: Construct descriptions while constructing suggestions.

(imported from commit 5de6d0799de6d132e6e7ac28658d0f25b71cc7ed)
This commit is contained in:
Steve Howell 2013-07-15 19:03:13 -04:00
parent d216069e29
commit b4e05d3430
1 changed files with 28 additions and 30 deletions

View File

@ -197,6 +197,13 @@ function get_stream_suggestions(query) {
return mapped[label];
});
$.each(objs, function (idx, obj) {
var prefix = 'Narrow to stream';
var stream = obj.query;
stream = typeahead_helper.highlight_query_in_phrase(query, stream);
obj.description = prefix + ' ' + stream;
});
// streams are already sorted
objs = typeahead_helper.sorter(query, objs, get_query);
@ -217,6 +224,24 @@ function get_person_suggestions(query, action) {
return mapped[label];
});
$.each(objs, function (idx, obj) {
var prefix;
var person;
var name;
if (action === 'private_message') {
prefix = 'Narrow to private messages with';
}
if (action === 'sender') {
prefix = 'Narrow to messages sent by';
}
person = obj.query;
name = highlight_person(query, person);
obj.description = prefix + ' ' + name;
});
objs.sort(function (x, y) {
return typeahead_helper.compare_by_pms(get_query(x), get_query(y));
@ -242,6 +267,8 @@ exports.initialize = function () {
var label = get_label(obj);
mapped[label] = obj;
obj.label = label;
var description = describe(operators);
obj.description = Handlebars.Utils.escapeExpression(description);
result = [label];
} else {
return [];
@ -262,37 +289,8 @@ exports.initialize = function () {
},
items: 20,
highlighter: function (item) {
var query = this.query;
var obj = mapped[item];
var prefix;
var person;
var name;
var stream;
if (obj.action === 'private_message') {
prefix = 'Narrow to private messages with';
person = obj.query;
name = highlight_person(query, person);
return prefix + ' ' + name;
}
if (obj.action === 'sender') {
prefix = 'Narrow to messages sent by';
person = obj.query;
name = highlight_person(query, person);
return prefix + ' ' + name;
}
if (obj.action === 'stream') {
prefix = 'Narrow to stream';
stream = obj.query;
stream = typeahead_helper.highlight_query_in_phrase(query, stream);
return prefix + ' ' + stream;
}
var description = describe(obj.operators);
description = Handlebars.Utils.escapeExpression(description);
return description;
return obj.description;
},
matcher: function (item) {
return true;