mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-28 12:58:48 +01:00
Cleaned up some more unnecessary ActiveRecord calls in the ProjectsController and ContextsController.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@529 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
472db2f586
commit
2ff03c573e
3 changed files with 31 additions and 25 deletions
|
|
@ -145,8 +145,8 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def init_data_for_sidebar
|
||||
@projects = @user.projects
|
||||
@contexts = @user.contexts
|
||||
@projects = @projects || @user.projects
|
||||
@contexts = @contexts || @user.contexts
|
||||
init_not_done_counts
|
||||
if @prefs.show_hidden_projects_in_sidebar
|
||||
init_project_hidden_todo_counts(['project'])
|
||||
|
|
@ -155,13 +155,13 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def init_not_done_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_not_done_counts = Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'active'], :group => :#{parent}_id)")
|
||||
eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'active'], :group => :#{parent}_id)")
|
||||
end
|
||||
end
|
||||
|
||||
def init_project_hidden_todo_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_project_hidden_todo_counts = Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'project_hidden'], :group => :#{parent}_id)")
|
||||
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'project_hidden'], :group => :#{parent}_id)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class ContextsController < ApplicationController
|
|||
|
||||
helper :todos
|
||||
|
||||
before_filter :init, :except => [:create, :destroy, :order]
|
||||
before_filter :init, :except => [:index, :create, :destroy, :order]
|
||||
before_filter :init_todos, :only => :show
|
||||
before_filter :set_context_from_params, :only => [:update, :destroy]
|
||||
skip_before_filter :login_required, :only => [:index]
|
||||
|
|
@ -10,6 +10,8 @@ class ContextsController < ApplicationController
|
|||
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
|
||||
|
||||
def index
|
||||
@contexts = @user.contexts
|
||||
init_not_done_counts(['context'])
|
||||
respond_to do |format|
|
||||
format.html &render_contexts_html
|
||||
format.xml { render :xml => @contexts.to_xml( :except => :user_id ) }
|
||||
|
|
@ -131,8 +133,6 @@ class ContextsController < ApplicationController
|
|||
# if the user sets the preference for them to be shown
|
||||
# @projects = @user.projects.reject { |x| x.completed? }
|
||||
init_data_for_sidebar
|
||||
@todos = @user.todos
|
||||
@done = @user.todos.find_in_state(:all, :completed, :order => "todos.completed_at DESC")
|
||||
end
|
||||
|
||||
def init_todos
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class ProjectsController < ApplicationController
|
||||
|
||||
helper :application, :todos, :notes
|
||||
before_filter :init, :except => [:create, :destroy, :order]
|
||||
before_filter :set_source_view
|
||||
before_filter :set_project_from_params, :only => [:update, :destroy, :show]
|
||||
before_filter :default_context_filter, :only => [:create,:update]
|
||||
skip_before_filter :login_required, :only => [:index]
|
||||
|
|
@ -9,6 +9,9 @@ class ProjectsController < ApplicationController
|
|||
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
|
||||
|
||||
def index
|
||||
@projects = @user.projects
|
||||
@contexts = @user.contexts
|
||||
init_not_done_counts(['project'])
|
||||
if params[:only_active_with_no_next_actions]
|
||||
@projects = @projects.select { |p| p.active? && count_undone_todos(p) == 0 }
|
||||
end
|
||||
|
|
@ -22,6 +25,9 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
init_data_for_sidebar
|
||||
@projects = @user.projects
|
||||
@contexts = @user.contexts
|
||||
@page_title = "TRACKS::Project: #{@project.name}"
|
||||
@not_done = @project.not_done_todos(:include_project_hidden_todos => true)
|
||||
@deferred = @project.deferred_todos
|
||||
|
|
@ -88,8 +94,10 @@ class ProjectsController < ApplicationController
|
|||
@project_project_hidden_todo_counts = Hash.new
|
||||
@project_project_hidden_todo_counts[@project.id] = @project.reload().not_done_todo_count(:include_project_hidden_todos => true)
|
||||
else
|
||||
@project_not_done_counts = Hash.new
|
||||
@project_not_done_counts[@project.id] = @project.reload().not_done_todo_count(:include_project_hidden_todos => true)
|
||||
end
|
||||
@contexts = @user.contexts
|
||||
@active_projects_count = @user.projects.count(:conditions => "state = 'active'")
|
||||
@hidden_projects_count = @user.projects.count(:conditions => "state = 'hidden'")
|
||||
@completed_projects_count = @user.projects.count(:conditions => "state = 'completed'")
|
||||
|
|
@ -130,13 +138,15 @@ class ProjectsController < ApplicationController
|
|||
def alphabetize
|
||||
@state = params['state']
|
||||
@projects = @user.projects.alphabetize(:state => @state) if @state
|
||||
@contexts = @user.contexts
|
||||
init_not_done_counts(['project'])
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def render_projects_html
|
||||
lambda do
|
||||
init_project_hidden_todo_counts
|
||||
init_project_hidden_todo_counts(['project'])
|
||||
@page_title = "TRACKS::List Projects"
|
||||
@active_projects = @projects.select{ |p| p.active? }
|
||||
@hidden_projects = @projects.select{ |p| p.hidden? }
|
||||
|
|
@ -174,27 +184,23 @@ class ProjectsController < ApplicationController
|
|||
def set_project_from_params
|
||||
@project = @user.projects.find_by_params(params)
|
||||
end
|
||||
|
||||
def init
|
||||
|
||||
def set_source_view
|
||||
@source_view = params['_source_view'] || 'project'
|
||||
@projects = @user.projects
|
||||
@contexts = @user.contexts
|
||||
@todos = @user.todos
|
||||
init_data_for_sidebar
|
||||
end
|
||||
|
||||
def default_context_filter
|
||||
p = params['project']
|
||||
p = params['request']['project'] if p.nil? && params['request']
|
||||
p = {} if p.nil?
|
||||
default_context_name = p['default_context_name']
|
||||
p.delete('default_context_name')
|
||||
def default_context_filter
|
||||
p = params['project']
|
||||
p = params['request']['project'] if p.nil? && params['request']
|
||||
p = {} if p.nil?
|
||||
default_context_name = p['default_context_name']
|
||||
p.delete('default_context_name')
|
||||
|
||||
unless default_context_name.blank?
|
||||
default_context = Context.find_or_create_by_name(default_context_name)
|
||||
p['default_context_id'] = default_context.id
|
||||
end
|
||||
unless default_context_name.blank?
|
||||
default_context = Context.find_or_create_by_name(default_context_name)
|
||||
p['default_context_id'] = default_context.id
|
||||
end
|
||||
end
|
||||
|
||||
def summary(project)
|
||||
project_description = ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue