Mercurial > hg > soundsoftware-site
diff app/controllers/projects_controller.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | 51364c0cd58f e248c7af89ec |
line wrap: on
line diff
--- a/app/controllers/projects_controller.rb Fri Jun 14 09:05:06 2013 +0100 +++ b/app/controllers/projects_controller.rb Tue Jan 14 14:37:42 2014 +0000 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2012 Jean-Philippe Lang +# Copyright (C) 2006-2013 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -43,6 +43,7 @@ helper :repositories include RepositoriesHelper include ProjectsHelper + helper :members # Lists visible projects def index @@ -57,32 +58,31 @@ format.api { @offset, @limit = api_offset_and_limit @project_count = Project.visible.count - @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') + @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all } format.atom { - projects = Project.visible.find(:all, :order => 'created_on DESC', - :limit => Setting.feeds_limit.to_i) + projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") } end end def new - @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") + @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all @project = Project.new @project.safe_attributes = params[:project] end def create - @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") + @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all @project = Project.new @project.safe_attributes = params[:project] if validate_parent_id && @project.save @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') - # Add current user as a project member if he is not admin + # Add current user as a project member if current user is not admin unless User.current.admin? r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) @@ -91,10 +91,12 @@ respond_to do |format| format.html { flash[:notice] = l(:notice_successful_create) - redirect_to(params[:continue] ? - {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} : - {:controller => 'projects', :action => 'settings', :id => @project} - ) + if params[:continue] + attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} + redirect_to new_project_path(attrs) + else + redirect_to settings_project_path(@project) + end } format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } end @@ -104,15 +106,11 @@ format.api { render_validation_errors(@project) } end end - end def copy - @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") + @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all - @root_projects = Project.find(:all, - :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", - :order => 'name') @source_project = Project.find(params[:id]) if request.get? @project = Project.copy_from(@source_project) @@ -124,13 +122,13 @@ if validate_parent_id && @project.copy(@source_project, :only => params[:only]) @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') flash[:notice] = l(:notice_successful_create) - redirect_to :controller => 'projects', :action => 'settings', :id => @project + redirect_to settings_project_path(@project) elsif !@project.new_record? # Project was created # But some objects were not copied due to validation failures # (eg. issues from disabled trackers) # TODO: inform about that - redirect_to :controller => 'projects', :action => 'settings', :id => @project + redirect_to settings_project_path(@project) end end end @@ -138,17 +136,17 @@ # source_project not found render_404 end - + # Show @project def show - if params[:jump] - # try to redirect to the requested menu item - redirect_to_project_menu_item(@project, params[:jump]) && return + # try to redirect to the requested menu item + if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) + return end @users_by_role = @project.users_by_role @subprojects = @project.children.visible.all - @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") + @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all @trackers = @project.rolled_up_trackers cond = @project.project_condition(Setting.display_subprojects_issues?) @@ -157,7 +155,7 @@ @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker) if User.current.allowed_to?(:view_time_entries, @project) - @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f + @total_hours = TimeEntry.visible.where(cond).sum(:hours).to_f end @key = User.current.rss_key @@ -169,7 +167,7 @@ end def settings - @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") + @issue_custom_fields = IssueCustomField.sorted.all @issue_category ||= IssueCategory.new @member ||= @project.members.new @trackers = Tracker.sorted.all @@ -186,7 +184,7 @@ respond_to do |format| format.html { flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'settings', :id => @project + redirect_to settings_project_path(@project) } format.api { render_api_ok } end @@ -204,7 +202,7 @@ def modules @project.enabled_module_names = params[:enabled_module_names] flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'settings', :id => @project, :tab => 'modules' + redirect_to settings_project_path(@project, :tab => 'modules') end def archive @@ -213,12 +211,12 @@ flash[:error] = l(:error_can_not_archive_project) end end - redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) + redirect_to admin_projects_path(:status => params[:status]) end def unarchive @project.unarchive if request.post? && !@project.active? - redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) + redirect_to admin_projects_path(:status => params[:status]) end def close @@ -237,7 +235,7 @@ if api_request? || params[:confirm] @project_to_destroy.destroy respond_to do |format| - format.html { redirect_to :controller => 'admin', :action => 'projects' } + format.html { redirect_to admin_projects_path } format.api { render_api_ok } end end