diff app/controllers/projects_controller.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 1aee31f54e13 622f24f53b42
children
line wrap: on
line diff
--- a/app/controllers/projects_controller.rb	Fri Jun 14 09:07:32 2013 +0100
+++ b/app/controllers/projects_controller.rb	Fri Jun 14 09:28:30 2013 +0100
@@ -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
   include ActivitiesHelper
   helper :activities
 
@@ -70,11 +71,10 @@
       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
@@ -91,14 +91,14 @@
   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]
@@ -114,10 +114,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
@@ -127,15 +129,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)
@@ -147,13 +145,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
@@ -164,14 +162,14 @@
 
   # 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?)
@@ -192,7 +190,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
@@ -209,7 +207,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
@@ -235,7 +233,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
@@ -244,12 +242,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
@@ -268,7 +266,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