Added Searching Features
* Added Thread Search Feature * Added User Search Feature * Re-organized searching, added @mention support to author search
This commit is contained in:
8
app/views/application/_md_editor_user.html.erb
Normal file
8
app/views/application/_md_editor_user.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="md_editor">
|
||||
<div class="field_container_user">
|
||||
<% options = (defined?(options) && options || {}) %>
|
||||
<% options[:class] = "#{options[:class]} editor_field" %>
|
||||
<% options[:placeholder] ||= "Enter user's name. Prefix with \"@\" to get suggestions." %>
|
||||
<%= text_field_tag name, content, options %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,5 +1,7 @@
|
||||
<% title "Forums" %>
|
||||
|
||||
<%= link_to "All threads", forumthreads_path(params.except("controller", "action")), class: "btn blue right" %>
|
||||
|
||||
<div id="forum_groups">
|
||||
<% @groups.each do |group| %>
|
||||
<div class="item-group" id="group-<%= group.id %>">
|
||||
@@ -56,4 +58,4 @@
|
||||
<%= link_to "New group", new_forumgroup_path, class: "btn blue" %>
|
||||
<% elsif mod? %>
|
||||
<%= link_to "New group", "#", class: "btn blue", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
<%= link_to @forum.group, forumgroup_path(@forum.group) %> → <%= @forum %>
|
||||
|
||||
<h1><%= title @forum %></h1>
|
||||
<h1>
|
||||
<%= title @forum %>
|
||||
<% params[:id] = params[:id].split("-")[0] %>
|
||||
<%= link_to "Search Threads", forumthreads_path(params.except("action", "controller")), class: "btn blue right" %>
|
||||
</h1>
|
||||
<% if @forum.can_write?(current_user) %>
|
||||
<p><%= link_to "New thread", new_forumthread_path(forum: @forum), class: "btn blue" %></p>
|
||||
<p>
|
||||
<%= link_to "New thread", new_forumthread_path(forum: @forum), class: "btn blue" %>
|
||||
<% params[:id] = params[:id].split("-")[0] %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<% if @forum.role_read && @forum.role_write && @forum.role_write < @forum.role_read %>
|
||||
@@ -51,4 +58,4 @@
|
||||
</div>
|
||||
<% end %>
|
||||
<%= paginate @threads %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
84
app/views/forumthreads/index.html.erb
Normal file
84
app/views/forumthreads/index.html.erb
Normal file
@@ -0,0 +1,84 @@
|
||||
<%= link_to "Forums", forums_path %> →
|
||||
<% if params.to_hash.slice("label", "title", "content", "author", "reply").size > 0 %>
|
||||
<%= link_to "All Threads", forumthreads_path %> → Search Results
|
||||
<% else %>
|
||||
<%= "All Threads" %>
|
||||
<% end %>
|
||||
<% params_list = params.to_hash.slice("id", "query", "label", "title", "content", "author", "reply") %>
|
||||
<h1>
|
||||
<% if params[:id] %>
|
||||
<% text = "forum '#{Forum.find(params[:id]).name}'" %>
|
||||
<% else %>
|
||||
<% text = "all threads" %>
|
||||
<% end %>
|
||||
<% if params_list.size > 0 %>
|
||||
<%= title "Search results in #{text} (#{@threads.length})" %>
|
||||
<% else %>
|
||||
<% if params[:id] %>
|
||||
<%= title "All threads in #{text}" %>
|
||||
<% else %>
|
||||
<%= title "All Threads" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<br>
|
||||
<%= link_to "Advanced Search", search_forumthreads_path(params_list), class: "btn right blue" %>
|
||||
<% if params_list.size > 0 && params[:id] %>
|
||||
<%= link_to "Show All Threads", forumthreads_path(params_list.except("id")), class: "btn right blue" %>
|
||||
<% elsif params_list.size > 0 && !params[:id] %>
|
||||
<%= link_to "Show All Threads", forumthreads_path, class: "btn right blue" %>
|
||||
<% end %>
|
||||
<% if params[:id] %>
|
||||
<%= link_to "Go to Forum", forum_path(params[:id]), class: "btn right blue" %>
|
||||
<% end %>
|
||||
</h1>
|
||||
<br>
|
||||
<%= form_tag({controller: "forumthreads", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %>
|
||||
<%= text_field_tag "query", nil, placeholder: "Search...", style: "margin:0px;height:40px;width:300px" %>
|
||||
<% params.each do |key, value| %>
|
||||
<%= hidden_field_tag key, params[key] if params[key] && params[key] != params[:query] %>
|
||||
<% end %>
|
||||
<%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %>
|
||||
<% end %>
|
||||
</h1>
|
||||
<div id="forum_groups">
|
||||
<% counter = 0 %>
|
||||
<% @threads.each do |thread| %>
|
||||
<% counter += 1 %>
|
||||
<div class="item-group with-avatar" id="thread-<%= thread.id %>">
|
||||
<div class="header">
|
||||
<%= link_to(thread.author.avatar(64), thread.author, title: thread.author.ign) %>
|
||||
<%= render partial: "users/username", locals: { user: thread.author } %>
|
||||
<%= link_to thread do %>
|
||||
<%= ago thread.created_at %>
|
||||
<% end %>
|
||||
<span class="comment-counter">
|
||||
<%= link_to pluralize(thread.replies.count, "Reply"), thread %>
|
||||
</span>
|
||||
<div class="clear-right"></div>
|
||||
</div>
|
||||
<div class="items bold">
|
||||
<div class="item <%= "#{"locked" if thread.locked}#{"sticky" if thread.sticky}" %>">
|
||||
<%= render partial: "labels/label", locals: {label: thread.label} %><%= link_to truncate(thread.title, length: 60, omission: " …"), forumthread_path(thread), title: thread.title %>
|
||||
<div class="item-info">
|
||||
<% if rpl = thread.replies.last %>
|
||||
<%= rpl.author.name %>
|
||||
<%
|
||||
position = thread.replies.count - 1
|
||||
page = position / Kaminari.config.default_per_page + 1
|
||||
%>
|
||||
<%= link_to "replied", forumthread_path(thread, page: page) + "#reply-#{rpl.id}" %>
|
||||
<%= ago rpl.created_at %>.
|
||||
<% else %>
|
||||
No replies yet.
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if counter == 0 %>
|
||||
<h3>No results found</h3>
|
||||
<% end %>
|
||||
<%= paginate @threads %>
|
||||
</div>
|
||||
56
app/views/forumthreads/search.html.erb
Normal file
56
app/views/forumthreads/search.html.erb
Normal file
@@ -0,0 +1,56 @@
|
||||
<% title "Thread Search" %>
|
||||
<h1>Thread Search</h1>
|
||||
<h3>Leave a field blank to ignore that search aspect.</h3>
|
||||
<% label = Label.where(name: params[:label]).first %>
|
||||
<table>
|
||||
<tbody>
|
||||
<%= form_tag({controller: "forumthreads", action: "search_redirect"}, method: :post) do %>
|
||||
<%
|
||||
forums = []
|
||||
Forum.all.sort_by{ |f| f.forumgroup && f.forumgroup.position || 0 }.each do |f|
|
||||
if current_user != nil && current_user.role_id > f.role_read_id.to_i || current_user == nil && f.role_read_id == nil
|
||||
forums << ["#{f.forumgroup.name} → #{f.name}", f.id] if f.forumgroup
|
||||
end
|
||||
end
|
||||
%>
|
||||
<% label_list = Label.pluck(:name).insert(0, "Label").insert(1, "No Label") %>
|
||||
<tr>
|
||||
<td>Forum</td>
|
||||
<td><%= select_tag "id", options_for_select(["Search All Threads"] + forums, params[:id]) %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Label</td>
|
||||
<td>
|
||||
<%= select_tag "label", options_for_select(label_list, params[:label]), class: "auto-width" %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Title</td>
|
||||
<td>
|
||||
<%= text_field_tag "title", params[:title], placeholder: "Search Titles" %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Content</td>
|
||||
<td>
|
||||
<%= text_field_tag "content", params[:content], placeholder: "Search Contents" %>
|
||||
</td>
|
||||
<tr>
|
||||
<td>Author</td>
|
||||
<td>
|
||||
<%= render partial: "md_editor_user", locals: {name: "author", content: params[:author]} %>
|
||||
</td>
|
||||
</tr>
|
||||
<td>Replies</td>
|
||||
<td>
|
||||
<%= text_field_tag "reply", params[:reply], placeholder: "Search Replies" %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<%= submit_tag "Go", class: "btn blue", style: "width:50px" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -1,14 +1,29 @@
|
||||
<%= form_tag({controller: "users", action: "search_redirect"}, method: :post, style: "margin:0px;height:40px") do %>
|
||||
<%= text_field_tag "search", nil, placeholder: "Search for a user", style: "margin:0px;height:40px;width:300px" %>
|
||||
<%= submit_tag "Go", class: "btn blue", style: "margin:0px;height:40px;width:40px" %>
|
||||
<%= hidden_field_tag "role", params[:role] %>
|
||||
<% end %>
|
||||
|
||||
<h1>
|
||||
<% if params[:role] && !params[:badge]%>
|
||||
<%= title "All '#{params[:role]}' users" %>
|
||||
<% elsif params[:badge] && !params[:role] %>
|
||||
<%= title "All '#{params[:badge]}' users" %>
|
||||
<% elsif params[:role] && params[:badge] %>
|
||||
<%= title "All '#{params[:role]}' and '#{params[:badge]}' users" %>
|
||||
<%
|
||||
if params[:role] && !params[:badge]
|
||||
text = "All '#{params[:role]}' users"
|
||||
elsif params[:badge] && !params[:role]
|
||||
text = "All '#{params[:badge]}' users"
|
||||
elsif params[:role] && params[:badge]
|
||||
text = "All '#{params[:role]}' and '#{params[:badge]}' users"
|
||||
else
|
||||
text = "All users"
|
||||
end
|
||||
text += " that contain '#{params[:search]}'" if params[:search]
|
||||
%>
|
||||
<%= title text %>
|
||||
<% if params[:search] %>
|
||||
(<%= @users.select {|u| u.name.downcase.include?(params[:search].downcase) || u.ign.downcase.include?(params[:search].downcase) }.size %>)
|
||||
<% else %>
|
||||
<%= title "All Users" %>
|
||||
(<%= @count %>)
|
||||
<% end %>
|
||||
(<%= @count %>)
|
||||
|
||||
</h1>
|
||||
<%= link_to "show all", users_path if params[:role] || params[:badge] %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user