Added CSS for index search fields and revised regex for author search

This commit is contained in:
MrYummy
2017-06-02 19:06:20 +02:00
parent 0c3f6b2223
commit 0d5d69ac6e
4 changed files with 104 additions and 39 deletions

View File

@@ -88,5 +88,45 @@ $(function() {
}], { }], {
debounce: 300 debounce: 300
}); });
$('.md_editor .field_container_user .editor_field').textcomplete([{
// match up to 2 words (everything except some special characters)
// each word can have up to 16 characters (up to 32 total)
// words must be separated by a single space
match: /(^|\s)(([^!"§$%&\/()=?.,;+*@\s]{1,16} ?){0,1}[^!"§$%&\/()=?.,;+*@\s]{1,16})$/,
search: function (text, callback, match) {
console.log("Searching " + text);
text = text.toLowerCase();
$.ajax("/users/suggestions", {
type: "post",
data: {name: text},
dataType: "json",
headers: {
"X-CSRF-Token": $('meta[name="csrf-token"]').attr("content")
},
success: function(data) {
callback(data);
},
error: function(xhr, status, err) {
console.error(err);
callback([]);
}
});
},
template: function(user) {
var name = user[0];
var ign = user[1];
if (name != ign) {
return name + " <small>(" + ign + ")</small>";
} else {
return ign;
}
},
cache: true,
replace: function (word) {
return "$1" + word[1] + " ";
}
}], {
debounce: 300
});
}); });

View File

@@ -489,6 +489,10 @@ blockquote p {
padding: 4em 1em 1em; padding: 4em 1em 1em;
} }
} }
.field_container_user {
.editor_field {
}
}
} }
ul.dropdown-menu { ul.dropdown-menu {
@@ -1043,3 +1047,20 @@ nav.pagination {
border-radius: 0.2em; border-radius: 0.2em;
text-shadow: none; text-shadow: none;
} }
.searchfield {
margin:0px;
height:40px;
display: inline-block;
.btn {
margin: 4px 1px 0 0;
padding: 6px;
cursor: default;
color: #fff;
border: none;
font-size: 12px;
line-height: normal;
background: #4096ee;
}
}

View File

@@ -1,49 +1,51 @@
<%= link_to "Forums", forums_path %> → <%= link_to "Forums", forums_path %> →
<% if params.to_hash.slice("label", "title", "content", "author", "reply").size > 0 %> <% params_list = params.to_hash %>
<% if params_list.any? %>
<%= link_to "All Threads", forumthreads_path %> → Search Results <%= link_to "All Threads", forumthreads_path %> → Search Results
<% else %> <% else %>
<%= "All Threads" %> <%= "All Threads" %>
<% end %> <% end %>
<% params_list = params.to_hash.slice("id", "query", "label", "title", "content", "author", "reply") %>
<h1> <h1>
<% if params[:id] %> <%
<% text = "forum '#{Forum.find(params[:id]).name}'" %> if params[:id]
<% else %> text = "forum '#{Forum.find(params[:id]).name}'"
<% text = "all threads" %> if params_list.any?
<% end %> text = "Search results in #{text} (#{@threads.length})"
<% if params_list.size > 0 %> else
<%= title "Search results in #{text} (#{@threads.length})" %> text = text.capitalize
<% else %> end
<% if params[:id] %> elsif params_list.any?
<%= title "All threads in #{text}" %> text = "Search results (#{@threads.length})"
<% else %> else
<%= title "All Threads" %> text = "All threads"
<% end %> end
<% end %> %>
<%= title text %>
<br> <br>
<%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %> <%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %>
<% if params_list.size > 0 && params[:id] %> <% if params_list.any? %>
<%= link_to "Show All Threads", forumthreads_path(params_list.except("id")), class: "btn right blue" %> <% if params[:id] %>
<% elsif params_list.size > 0 && !params[:id] %> <%= link_to "Show All Threads", forumthreads_path(params_list.except("id")), class: "btn right blue" %>
<%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %> <% else %>
<%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %>
<% end %>
<% end %> <% end %>
<% if params[:id] %> <% if params[:id] %>
<%= link_to "Go to Forum", forum_path(params[:id]), class: "btn right blue" %> <%= link_to "Go to Forum", forum_path(params[:id]), class: "btn right blue" %>
<% end %> <% end %>
</h1> </h1>
<br> <div class="searchfield">
<%= form_tag({controller: "forumthreads", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %> <%= form_tag({controller: "forumthreads", action: "index"}, method: :get, enforce_utf8: nil) do %>
<%= text_field_tag "query", nil, placeholder: "Search...", style: "margin:0px;height:40px;width:300px" %> <%= text_field_tag "query", params[:query], placeholder: "Search...", style: "width:300px" %>
<% params.each do |key, value| %> <% params_list.compact.except("query").each do |key, value| %>
<%= hidden_field_tag key, params[key] if params[key] && params[key] != params[:query] %> <%= hidden_field_tag key, params[key] %>
<% end %>
<%= submit_tag "Go", class: "searchfield btn", style: "width:40px", name: nil %>
<% end %> <% end %>
<%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %> </div>
<% end %>
</h1> </h1>
<div id="forum_groups"> <div id="forum_groups">
<% counter = 0 %>
<% @threads.each do |thread| %> <% @threads.each do |thread| %>
<% counter += 1 %>
<div class="item-group with-avatar" id="thread-<%= thread.id %>"> <div class="item-group with-avatar" id="thread-<%= thread.id %>">
<div class="header"> <div class="header">
<%= link_to(thread.author.avatar(64), thread.author, title: thread.author.ign) %> <%= link_to(thread.author.avatar(64), thread.author, title: thread.author.ign) %>
@@ -77,7 +79,8 @@
</div> </div>
</div> </div>
<% end %> <% end %>
<% if counter == 0 %> <% if @threads.empty? %>
<br>
<h3>No results found</h3> <h3>No results found</h3>
<% end %> <% end %>
<%= paginate @threads %> <%= paginate @threads %>

View File

@@ -1,9 +1,11 @@
<%= form_tag({controller: "users", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %> <div class="searchfield">
<%= text_field_tag "search", nil, placeholder: "Search for a user", style: "margin:0px;height:40px;width:300px" %> <%= form_tag({controller: "users", action: "index"}, method: :get, enforce_utf8: false) do %>
<%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %> <%= text_field_tag "search", params[:search], placeholder: "Search for a user", style: "width:300px" %>
<%= hidden_field_tag "role", params[:role] %> <%= submit_tag "Go", class: "searchfield btn", style: "width:40px", name: nil %>
<% end %> <%= hidden_field_tag "role", params[:role] if params[:role] %>
<%= hidden_field_tag "badge", params[:badge] if params[:badge]%>
<% end %>
</div>
<h1> <h1>
<% <%
if params[:role] && !params[:badge] if params[:role] && !params[:badge]
@@ -19,11 +21,10 @@
%> %>
<%= title text %> <%= title text %>
<% if params[:search] %> <% if params[:search] %>
(<%= @users.select {|u| u.name.downcase.include?(params[:search].downcase) || u.ign.downcase.include?(params[:search].downcase) }.size %>) (<%= @users.total_count %>)
<% else %> <% else %>
(<%= @count %>) (<%= @count %>)
<% end %> <% end %>
</h1> </h1>
<%= link_to "show all", users_path if params[:role] || params[:badge] %> <%= link_to "show all", users_path if params[:role] || params[:badge] %>