mirror of https://github.com/zulip/zulip.git
search.js: Decouple object labeling from object rendering.
(imported from commit f761401d3e287aa2771ce4203f1b2b8f57c7ca86)
This commit is contained in:
parent
0a7b5e5b6b
commit
eca2ca675b
|
@ -109,9 +109,20 @@ function get_object_parts(obj) {
|
||||||
return {prefix: 'Error', query: 'Error', suffix: 'Error'};
|
return {prefix: 'Error', query: 'Error', suffix: 'Error'};
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_object(obj) {
|
function get_label(obj) {
|
||||||
var parts = get_object_parts(obj);
|
switch (obj.action) {
|
||||||
return parts.prefix + " " + parts.query + " " + parts.suffix;
|
case 'stream':
|
||||||
|
return 'stream:' + obj.query;
|
||||||
|
|
||||||
|
case 'private_message':
|
||||||
|
return 'pm-with:' + obj.query.email;
|
||||||
|
|
||||||
|
case 'sender':
|
||||||
|
return 'sender:' + obj.query.email;
|
||||||
|
|
||||||
|
case 'operators':
|
||||||
|
return obj.query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.update_typeahead = function () {
|
exports.update_typeahead = function () {
|
||||||
|
@ -139,8 +150,9 @@ exports.update_typeahead = function () {
|
||||||
mapped = {};
|
mapped = {};
|
||||||
labels = [];
|
labels = [];
|
||||||
$.each(options, function (i, obj) {
|
$.each(options, function (i, obj) {
|
||||||
var label = render_object(obj);
|
var label = get_label(obj);
|
||||||
mapped[label] = obj;
|
mapped[label] = obj;
|
||||||
|
obj.label = label;
|
||||||
labels.push(label);
|
labels.push(label);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -204,8 +216,10 @@ function searchbox_sorter(items) {
|
||||||
// streams are already sorted
|
// streams are already sorted
|
||||||
objs = typeahead_helper.sorter(query, objs, get_query);
|
objs = typeahead_helper.sorter(query, objs, get_query);
|
||||||
}
|
}
|
||||||
|
objs = objs.slice(0, 4);
|
||||||
|
var labels = $.map(objs, function (obj) { return obj.label;});
|
||||||
|
|
||||||
result = result.concat($.map(objs.slice(0, 4), render_object));
|
result = result.concat(labels);
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -244,8 +258,9 @@ exports.initialize = function () {
|
||||||
var operators = narrow.parse(query);
|
var operators = narrow.parse(query);
|
||||||
if (operators.length !== 0) {
|
if (operators.length !== 0) {
|
||||||
var obj = {action: 'operators', query: query, operators: operators};
|
var obj = {action: 'operators', query: query, operators: operators};
|
||||||
var label = render_object(obj);
|
var label = get_label(obj);
|
||||||
mapped[label] = obj;
|
mapped[label] = obj;
|
||||||
|
obj.label = label;
|
||||||
labels.unshift(label);
|
labels.unshift(label);
|
||||||
|
|
||||||
return labels;
|
return labels;
|
||||||
|
|
Loading…
Reference in New Issue