autocomplete: add saved search label autocomplete in more places.

This commit is contained in:
evazion
2019-11-12 20:24:24 -06:00
parent cc98f3b7cc
commit f9881e5414
6 changed files with 25 additions and 38 deletions

View File

@@ -1,5 +1,4 @@
import CurrentUser from './current_user'
import SavedSearch from './saved_searches'
let Autocomplete = {};
@@ -35,6 +34,7 @@ Autocomplete.initialize_all = function() {
this.initialize_pool_autocomplete($('[data-autocomplete="pool"]'));
this.initialize_user_autocomplete($('[data-autocomplete="user"]'));
this.initialize_wiki_autocomplete($('[data-autocomplete="wiki-page"]'));
this.initialize_saved_search_autocomplete($('[data-autocomplete="saved-search-label"]'));
}
}
@@ -132,7 +132,7 @@ Autocomplete.initialize_tag_autocomplete = function() {
Autocomplete.favorite_group_source(term, resp, metatag);
break;
case "search":
Autocomplete.saved_search_source(term, resp);
Autocomplete.saved_search_source(term, resp, "search:");
break;
case "tag":
Autocomplete.normal_source(term, resp);
@@ -238,6 +238,17 @@ Autocomplete.initialize_wiki_autocomplete = function($fields) {
});
};
Autocomplete.initialize_saved_search_autocomplete = function($fields) {
$fields.autocomplete({
search: function() {
$(this).data("ui-autocomplete").menu.bindings = $();
},
source: function(req, resp) {
Autocomplete.saved_search_source(req.term, resp);
},
});
};
Autocomplete.normal_source = function(term, resp) {
if (term === "") {
resp([]);
@@ -474,15 +485,15 @@ Autocomplete.favorite_group_source = function(term, resp, metatag) {
});
}
Autocomplete.saved_search_source = function(term, resp) {
return SavedSearch.labels(term).then(function(labels) {
resp(labels.map(function(label) {
return {
label: label.replace(/_/g, " "),
value: "search:" + label,
};
}));
});
Autocomplete.saved_search_source = async function(term, resp, prefix = "") {
let labels = await $.getJSON("/saved_searches/labels", { "search[label]": term + "*", "limit": 10 });
resp(labels.map(function(label) {
return {
label: label.replace(/_/g, " "),
value: prefix + label,
};
}));
}
$(document).ready(function() {

View File

@@ -3,7 +3,6 @@ import Utility from './utility'
import Hammer from 'hammerjs'
import Cookie from './cookie'
import Note from './notes'
import SavedSearch from './saved_searches'
let Post = {};
@@ -549,22 +548,6 @@ Post.approve = function(post_id) {
}
Post.initialize_saved_searches = function() {
$("#new_saved_search #saved_search_label_string").autocomplete({
search: function() {
$(this).data("ui-autocomplete").menu.bindings = $();
},
source: function(req, resp) {
SavedSearch.labels(req.term).then(function(labels) {
resp(labels.map(function(label) {
return {
label: label.replace(/_/g, " "),
value: label
};
}));
});
}
});
$("#save-search-dialog").dialog({
width: 700,
modal: true,

View File

@@ -6,13 +6,6 @@ SavedSearch.initialize_all = function() {
}
}
SavedSearch.labels = function(term) {
return $.getJSON("/saved_searches/labels", {
"search[label]": term + "*",
"limit": 10
});
}
$(SavedSearch.initialize_all);
export default SavedSearch

View File

@@ -2,7 +2,7 @@
<%= simple_form_for(SavedSearch.new, remote: true) do |f| %>
<%= f.input :query, as: :string, input_html: { value: params[:tags], data: { autocomplete: "tag-query" } } %>
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited." %>
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited.", input_html: { "data-autocomplete": "saved-search-label" } %>
<%= f.input :disable_labels, label: "Don't show this dialog again", as: :boolean %>
<% end %>
</div>

View File

@@ -6,7 +6,7 @@
<%= simple_form_for(@saved_search) do |f| %>
<%= f.input :query, :as => :string %>
<%= f.input :label_string, :label => "Labels", :hint => "A list of tags to help categorize this search. Space delimited." %>
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited.", input_html: { "data-autocomplete": "saved-search-label" } %>
<%= f.button :submit, :value => "Submit" %>
<% end %>
</div>

View File

@@ -9,7 +9,7 @@
<%= search_form_for(saved_searches_path) do |f| %>
<%= f.input :query_ilike, label: "Query", hint: "Use * for wildcard", input_html: { value: params[:search][:query_ilike] } %>
<%= f.input :label, label: "Label", input_html: { value: params[:search][:label] } %>
<%= f.input :label, label: "Label", input_html: { value: params[:search][:label] }, input_html: { "data-autocomplete": "saved-search-label" } %>
<%= f.input :order, collection: [%w[Newest id], %w[Query query], %w[Label label]], include_blank: false, selected: params[:search][:order] %>
<%= f.submit "Search" %>
<% end %>