diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 16cb0518..0d54b75f 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -228,8 +228,13 @@ class ApplicationController < ActionController::Base end def init_data_for_sidebar - @projects = @projects || current_user.projects.find(:all, :include => [:default_context ]) - @contexts = @contexts || current_user.contexts + @completed_projects = current_user.projects.completed + @hidden_projects = current_user.projects.hidden + @active_projects = current_user.projects.active + + @active_contexts = current_user.contexts.active + @hidden_contexts = current_user.contexts.hidden + init_not_done_counts if prefs.show_hidden_projects_in_sidebar init_project_hidden_todo_counts(['project']) @@ -238,13 +243,13 @@ class ApplicationController < ActionController::Base def init_not_done_counts(parents = ['project','context']) parents.each do |parent| - eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || Todo.count(:conditions => ['user_id = ? and state = ?', current_user.id, 'active'], :group => :#{parent}_id)") + eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || current_user.todos.active.count(:group => :#{parent}_id)") end end def init_project_hidden_todo_counts(parents = ['project','context']) parents.each do |parent| - eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || Todo.count(:conditions => ['user_id = ? and (state = ? or state = ?)', current_user.id, 'project_hidden', 'active'], :group => :#{parent}_id)") + eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || current_user.todos.count(:conditions => ['state = ? or state = ?', 'project_hidden', 'active'], :group => :#{parent}_id)") end end diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index d09883a4..348151aa 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -201,6 +201,9 @@ class ContextsController < ApplicationController :conditions => ['todos.state = ? AND (todos.project_id IS ? OR projects.state = ?)', 'active', nil, 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [:project, :tags]) + + @projects = current_user.projects + @count = @not_done_todos.size @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index baaa25dd..93bdb23e 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -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 diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 99824886..8ccf710a 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -399,8 +399,9 @@ class TodosController < ApplicationController :limit => max_completed, :conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'completed'], :order => 'todos.completed_at DESC') - - @contexts = current_user.contexts.find(:all) + + @projects = current_user.projects + @contexts = current_user.contexts @contexts_to_show = @contexts.reject {|x| x.hide? } # Set count badge to number of items with this tag diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 79e058e9..0b38d202 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -242,13 +242,13 @@ module TodosHelper end def project_names_for_autocomplete - array_or_string_for_javascript( ['None'] + @projects.select{ |p| p.active? }.collect{|p| escape_javascript(p.name) } ) + array_or_string_for_javascript( ['None'] + current_user.projects.active.collect{|p| escape_javascript(p.name) } ) end def context_names_for_autocomplete # #return array_or_string_for_javascript(['Create a new context']) if # @contexts.empty? - array_or_string_for_javascript( @contexts.collect{|c| escape_javascript(c.name) } ) + array_or_string_for_javascript( current_user.contexts.collect{|c| escape_javascript(c.name) } ) end def format_ical_notes(notes) diff --git a/app/models/user.rb b/app/models/user.rb index fd649b10..33a9e4bc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -124,7 +124,7 @@ class User < ActiveRecord::Base #for will_paginate plugin cattr_accessor :per_page - @@per_page = 1 + @@per_page = 5 def validate unless Tracks::Config.auth_schemes.include?(auth_type) diff --git a/app/views/contexts/_context_listing.rhtml b/app/views/contexts/_context_listing.rhtml index 03ad73f3..32335457 100644 --- a/app/views/contexts/_context_listing.rhtml +++ b/app/views/contexts/_context_listing.rhtml @@ -1,9 +1,14 @@ -<% context = context_listing %> +<% context = context_listing + suppress_drag_handle ||= false + suppress_edit_button ||= false +%>
" class="list">
-
- DRAG -
+ <% unless suppress_drag_handle -%> +
+ DRAG +
+ <% end -%>
<%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %>
@@ -32,5 +37,5 @@ -%>
- <%= render :partial => 'context_form', :object => context %> + <%= render :partial => 'contexts/context_form', :object => context %> \ No newline at end of file diff --git a/app/views/projects/_default_context_autocomplete.rhtml b/app/views/projects/_default_context_autocomplete.rhtml index 178336b5..cd92380e 100644 --- a/app/views/projects/_default_context_autocomplete.rhtml +++ b/app/views/projects/_default_context_autocomplete.rhtml @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index 7065746b..8cfcbd76 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -1,6 +1,9 @@ - + + \ No newline at end of file diff --git a/app/views/search/results.rhtml b/app/views/search/results.rhtml index 679360c5..e18516ee 100644 --- a/app/views/search/results.rhtml +++ b/app/views/search/results.rhtml @@ -1,32 +1,48 @@ -
- <% if @count == 0 -%> -

Your search yielded no results.

- <% else -%> - <% source_view_is = :search %> - <% parent_container_type = 'search' %> - <% if not @found_todos.empty? -%> -
-

<%= @found_todos.size %>Todos matching query

- <%= render :partial => "todos/todo", :collection => @found_todos, :locals => { :parent_container_type => 'search', :suppress_context => false, :suppress_project => false, :suppress_edit_button => true } %> -
- <% end -%> - - <% if not @found_projects.empty? -%> -
-

<%= @found_projects.size %>Projects matching query

- <%= render :partial => "projects/project_listing", :collection => @found_projects, :locals => { :suppress_drag_handle => true, :suppress_edit_button => true } %> -
- <% end -%> - - <% if not @found_notes.empty? -%> -
-

<%= @found_notes.size %>Notes matching query

- <% for notes in @found_notes -%> -
- <%= render :partial => "notes/notes_summary", :object => notes %> -
- <% end -%> -
- <% end -%> - <% end -%> -
+
+<% if @count == 0 -%> +

Your search yielded no results.

+<% else -%> + <% unless @found_todos.empty? -%> +
+

<%= @found_todos.size %>Todos matching query

+ <%= render :partial => "todos/todo", :collection => @found_todos, :locals => { :parent_container_type => 'search', :suppress_context => false, :suppress_project => false, :suppress_edit_button => true } %> +
+ <% end -%> + + <% unless @found_projects.empty? -%> +
+

<%= @found_projects.size %>Projects matching query

+ <%= render :partial => "projects/project_listing", :collection => @found_projects, :locals => { :suppress_drag_handle => true, :suppress_edit_button => true } %> +
+ <% end -%> + + <% unless @found_notes.empty? -%> +
+

<%= @found_notes.size %>Notes matching query

+ <% for notes in @found_notes -%> +
+ <%= render :partial => "notes/notes_summary", :object => notes %> +
+ <% end -%> +
+ <% end -%> + + <% unless @found_contexts.empty? -%> +
+

<%= @found_contexts.size %>Contexts matching query

+ <%= render :partial => "contexts/context_listing", :collection => @found_contexts, :locals => { :suppress_drag_handle => true, :suppress_edit_button => true } %> +
+ <% end -%> + + <% unless @found_tags.empty? -%> +
+

<%= @found_tags.size %>Tags matching query

+ <% @found_tags.each do |tag| -%> + <%= link_to tag.name, {:controller => "todos", :action => "tag", :id => tag.name} -%> + <% end %> + +
+
+ <% end %> +<% end -%> +
diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index 65316245..c84e0580 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -2,7 +2,7 @@ @todo = nil @initial_context_name = @context.name unless @context.nil? @initial_context_name ||= @project.default_context.name unless @project.nil? || @project.default_context.nil? - @initial_context_name ||= @contexts[0].name unless @contexts[0].nil? + @initial_context_name ||= current_user.contexts.first.name unless current_user.contexts.first.nil? @initial_project_name = @project.name unless @project.nil? %>
diff --git a/app/views/sidebar/sidebar.html.erb b/app/views/sidebar/sidebar.html.erb index bb5d8847..3de85ff3 100644 --- a/app/views/sidebar/sidebar.html.erb +++ b/app/views/sidebar/sidebar.html.erb @@ -1,30 +1,30 @@