From 04e1567ef895d8353c2161c6c374d886915d0cf0 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 19 Jul 2013 16:32:05 -0400 Subject: [PATCH] Suggest special filters like "All" and "Private messages" in search. (They will show up for empty queries or queries that are prefixes of either the operator syntax or the label used in the sidebar.) (imported from commit 3765896e3bc1fc95caf987194e22d89d649ba5ae) --- zephyr/static/js/search.js | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index a1bbc8b927..8a4c9d0576 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -279,6 +279,50 @@ function get_topic_suggestions(query, query_operators) { }); } +function get_special_filter_suggestions(query, operators) { + if (operators.length >= 2) { + return []; + } + + var suggestions = [ + { + search_string: '', + description: 'Home' + }, + { + search_string: 'in:all', + description: 'All messages' + }, + { + search_string: 'is:private', + description: 'Private messages' + }, + { + search_string: 'is:starred', + description: 'Starred messages' + }, + { + search_string: 'is:mentioned', + description: '@-mentions' + } + ]; + + query = query.toLowerCase(); + + suggestions = $.grep(suggestions, function (s) { + if (s.search_string.toLowerCase() === query) { + return false; // redundant + } + if (query === '') { + return true; + } + return (s.search_string.toLowerCase().indexOf(query) === 0) || + (s.description.toLowerCase().indexOf(query) === 0); + }); + + return suggestions; +} + exports.initialize = function () { $( "#search_query" ).typeahead({ source: function (query, process) { @@ -291,6 +335,9 @@ exports.initialize = function () { suggestion = get_suggestion_based_on_query(query, operators); result = [suggestion]; + suggestions = get_special_filter_suggestions(query, operators); + result = result.concat(suggestions); + suggestions = get_stream_suggestions(query); result = result.concat(suggestions);