mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-28 21:08:48 +01:00
implement suggestions for search in #787
* the search form gets focus when loaded * searching on contexts and tags added
This commit is contained in:
parent
2101ed6cf8
commit
3ddabd20d1
4 changed files with 97 additions and 70 deletions
|
|
@ -1,27 +1,30 @@
|
|||
class SearchController < ApplicationController
|
||||
|
||||
helper :todos, :application, :notes, :projects
|
||||
|
||||
def results
|
||||
@source_view = params['_source_view'] || 'search'
|
||||
@page_title = "TRACKS::Search Results for #{params[:search]}"
|
||||
terms = '%' + params[:search] + '%'
|
||||
@found_todos = current_user.todos.find(:all, :conditions => ["todos.description LIKE ? OR todos.notes LIKE ?", terms, terms], :include => [:tags, :project, :context])
|
||||
@found_projects = current_user.projects.find(:all, :conditions => ["name LIKE ? or description LIKE ?", terms, terms])
|
||||
@found_notes = current_user.notes.find(:all, :conditions => ["body LIKE ?", terms])
|
||||
|
||||
@count = @found_todos.size + @found_projects.size + @found_notes.size
|
||||
|
||||
init_not_done_counts(['project'])
|
||||
init_project_hidden_todo_counts(['project'])
|
||||
end
|
||||
|
||||
def index
|
||||
@page_title = "TRACKS::Search"
|
||||
end
|
||||
|
||||
def init
|
||||
@source_view = params['_source_view'] || 'search'
|
||||
end
|
||||
|
||||
end
|
||||
class SearchController < ApplicationController
|
||||
|
||||
helper :todos, :application, :notes, :projects
|
||||
|
||||
def results
|
||||
@source_view = params['_source_view'] || 'search'
|
||||
@page_title = "TRACKS::Search Results for #{params[:search]}"
|
||||
terms = '%' + params[:search] + '%'
|
||||
@found_todos = current_user.todos.find(:all, :conditions => ["todos.description LIKE ? OR todos.notes LIKE ?", terms, terms], :include => [:tags, :project, :context])
|
||||
@found_projects = current_user.projects.find(:all, :conditions => ["name LIKE ? OR description LIKE ?", terms, terms])
|
||||
@found_notes = current_user.notes.find(:all, :conditions => ["body LIKE ?", terms])
|
||||
@found_contexts = current_user.contexts.find(:all, :conditions => ["name LIKE ?", terms])
|
||||
# TODO: limit search to tags on todos
|
||||
@found_tags = current_user.tags.find(:all, :conditions => ["name LIKE ?", terms])
|
||||
|
||||
@count = @found_todos.size + @found_projects.size + @found_notes.size + @found_contexts.size + @found_tags.size
|
||||
|
||||
init_not_done_counts
|
||||
init_project_hidden_todo_counts
|
||||
end
|
||||
|
||||
def index
|
||||
@page_title = "TRACKS::Search"
|
||||
end
|
||||
|
||||
def init
|
||||
@source_view = params['_source_view'] || 'search'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
<% context = context_listing %>
|
||||
<% context = context_listing
|
||||
suppress_drag_handle ||= false
|
||||
suppress_edit_button ||= false
|
||||
%>
|
||||
<div id="<%= dom_id(context, "container") %>" class="list">
|
||||
<div id="<%= dom_id(context) %>" class="context sortable_row" style="display:'';">
|
||||
<div class="position">
|
||||
<span class="handle">DRAG</span>
|
||||
</div>
|
||||
<% unless suppress_drag_handle -%>
|
||||
<div class="position">
|
||||
<span class="handle">DRAG</span>
|
||||
</div>
|
||||
<% end -%>
|
||||
<div class="data">
|
||||
<%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %>
|
||||
</div>
|
||||
|
|
@ -32,5 +37,5 @@
|
|||
-%>
|
||||
</div>
|
||||
</div>
|
||||
<%= render :partial => 'context_form', :object => context %>
|
||||
<%= render :partial => 'contexts/context_form', :object => context %>
|
||||
</div>
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
<div id="display_box_search">
|
||||
<% form_tag(:action => :results) do %>
|
||||
<%= text_field_tag(:search, params[:search]) %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div id="display_box_search">
|
||||
<% form_tag({:action => :results}, :id => 'search-form') do %>
|
||||
<%= text_field_tag(:search, params[:search]) %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
Form.focusFirstElement('search-form')
|
||||
</script>
|
||||
|
|
@ -1,32 +1,48 @@
|
|||
<div id="display_box_results">
|
||||
<% if @count == 0 -%>
|
||||
<div class="message"><p>Your search yielded no results.</p></div>
|
||||
<% else -%>
|
||||
<% source_view_is = :search %>
|
||||
<% parent_container_type = 'search' %>
|
||||
<% if not @found_todos.empty? -%>
|
||||
<div id="found-todos-container" class="container">
|
||||
<h2><span id="found-todos-count" class="badge"><%= @found_todos.size %></span>Todos matching query</h2>
|
||||
<%= render :partial => "todos/todo", :collection => @found_todos, :locals => { :parent_container_type => 'search', :suppress_context => false, :suppress_project => false, :suppress_edit_button => true } %>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<% if not @found_projects.empty? -%>
|
||||
<div id="found-projects-container" class="container">
|
||||
<h2><span id="found-projects-count" class="badge"><%= @found_projects.size %></span>Projects matching query</h2>
|
||||
<%= render :partial => "projects/project_listing", :collection => @found_projects, :locals => { :suppress_drag_handle => true, :suppress_edit_button => true } %>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<% if not @found_notes.empty? -%>
|
||||
<div id="found-notes-container" class="container">
|
||||
<h2><span id="found-notes-count" class="badge"><%= @found_notes.size %></span>Notes matching query</h2>
|
||||
<% for notes in @found_notes -%>
|
||||
<div class="container" id="note-<%= notes.id %>-wrapper">
|
||||
<%= render :partial => "notes/notes_summary", :object => notes %>
|
||||
</div>
|
||||
<% end -%>
|
||||
</div>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
</div>
|
||||
<div id="display_box_results">
|
||||
<% if @count == 0 -%>
|
||||
<div class="message"><p>Your search yielded no results.</p></div>
|
||||
<% else -%>
|
||||
<% unless @found_todos.empty? -%>
|
||||
<div id="found-todos-container" class="container">
|
||||
<h2><span id="found-todos-count" class="badge"><%= @found_todos.size %></span>Todos matching query</h2>
|
||||
<%= render :partial => "todos/todo", :collection => @found_todos, :locals => { :parent_container_type => 'search', :suppress_context => false, :suppress_project => false, :suppress_edit_button => true } %>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<% unless @found_projects.empty? -%>
|
||||
<div id="found-projects-container" class="container">
|
||||
<h2><span id="found-projects-count" class="badge"><%= @found_projects.size %></span>Projects matching query</h2>
|
||||
<%= render :partial => "projects/project_listing", :collection => @found_projects, :locals => { :suppress_drag_handle => true, :suppress_edit_button => true } %>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<% unless @found_notes.empty? -%>
|
||||
<div id="found-notes-container" class="container">
|
||||
<h2><span id="found-notes-count" class="badge"><%= @found_notes.size %></span>Notes matching query</h2>
|
||||
<% for notes in @found_notes -%>
|
||||
<div class="container" id="note-<%= notes.id %>-wrapper">
|
||||
<%= render :partial => "notes/notes_summary", :object => notes %>
|
||||
</div>
|
||||
<% end -%>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<% unless @found_contexts.empty? -%>
|
||||
<div id="found-contexts-container" class="container">
|
||||
<h2><span id="found-contexts-count" class="badge"><%= @found_contexts.size %></span>Contexts matching query</h2>
|
||||
<%= render :partial => "contexts/context_listing", :collection => @found_contexts, :locals => { :suppress_drag_handle => true, :suppress_edit_button => true } %>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
<% unless @found_tags.empty? -%>
|
||||
<div id="found-tags-container" class="container">
|
||||
<h2><span id="found-tags-count" class="badge"><%= @found_tags.size %></span>Tags matching query</h2>
|
||||
<span class="tags"><% @found_tags.each do |tag| -%>
|
||||
<span class="tag"><%= link_to tag.name, {:controller => "todos", :action => "tag", :id => tag.name} -%></span>
|
||||
<% end %>
|
||||
</span>
|
||||
<br/>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end -%>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue