Mercurial > hg > soundsoftware-site
comparison app/controllers/projects_controller.rb @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
| author | Chris Cannam |
|---|---|
| date | Fri, 14 Jun 2013 09:02:21 +0100 |
| parents | 433d4f72a19b |
| children | 4f746d8966dd |
comparison
equal
deleted
inserted
replaced
| 1294:3e4c3460b6ca | 1295:622f24f53b42 |
|---|---|
| 1 # Redmine - project management software | 1 # Redmine - project management software |
| 2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
| 3 # | 3 # |
| 4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
| 5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
| 6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
| 7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
| 41 helper :queries | 41 helper :queries |
| 42 include QueriesHelper | 42 include QueriesHelper |
| 43 helper :repositories | 43 helper :repositories |
| 44 include RepositoriesHelper | 44 include RepositoriesHelper |
| 45 include ProjectsHelper | 45 include ProjectsHelper |
| 46 helper :members | |
| 46 | 47 |
| 47 # Lists visible projects | 48 # Lists visible projects |
| 48 def index | 49 def index |
| 49 respond_to do |format| | 50 respond_to do |format| |
| 50 format.html { | 51 format.html { |
| 55 @projects = scope.visible.order('lft').all | 56 @projects = scope.visible.order('lft').all |
| 56 } | 57 } |
| 57 format.api { | 58 format.api { |
| 58 @offset, @limit = api_offset_and_limit | 59 @offset, @limit = api_offset_and_limit |
| 59 @project_count = Project.visible.count | 60 @project_count = Project.visible.count |
| 60 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') | 61 @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all |
| 61 } | 62 } |
| 62 format.atom { | 63 format.atom { |
| 63 projects = Project.visible.find(:all, :order => 'created_on DESC', | 64 projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all |
| 64 :limit => Setting.feeds_limit.to_i) | |
| 65 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") | 65 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") |
| 66 } | 66 } |
| 67 end | 67 end |
| 68 end | 68 end |
| 69 | 69 |
| 70 def new | 70 def new |
| 71 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 71 @issue_custom_fields = IssueCustomField.sorted.all |
| 72 @trackers = Tracker.sorted.all | 72 @trackers = Tracker.sorted.all |
| 73 @project = Project.new | 73 @project = Project.new |
| 74 @project.safe_attributes = params[:project] | 74 @project.safe_attributes = params[:project] |
| 75 end | 75 end |
| 76 | 76 |
| 77 def create | 77 def create |
| 78 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 78 @issue_custom_fields = IssueCustomField.sorted.all |
| 79 @trackers = Tracker.sorted.all | 79 @trackers = Tracker.sorted.all |
| 80 @project = Project.new | 80 @project = Project.new |
| 81 @project.safe_attributes = params[:project] | 81 @project.safe_attributes = params[:project] |
| 82 | 82 |
| 83 if validate_parent_id && @project.save | 83 if validate_parent_id && @project.save |
| 89 @project.members << m | 89 @project.members << m |
| 90 end | 90 end |
| 91 respond_to do |format| | 91 respond_to do |format| |
| 92 format.html { | 92 format.html { |
| 93 flash[:notice] = l(:notice_successful_create) | 93 flash[:notice] = l(:notice_successful_create) |
| 94 redirect_to(params[:continue] ? | 94 if params[:continue] |
| 95 {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} : | 95 attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?} |
| 96 {:controller => 'projects', :action => 'settings', :id => @project} | 96 redirect_to new_project_path(attrs) |
| 97 ) | 97 else |
| 98 redirect_to settings_project_path(@project) | |
| 99 end | |
| 98 } | 100 } |
| 99 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | 101 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } |
| 100 end | 102 end |
| 101 else | 103 else |
| 102 respond_to do |format| | 104 respond_to do |format| |
| 103 format.html { render :action => 'new' } | 105 format.html { render :action => 'new' } |
| 104 format.api { render_validation_errors(@project) } | 106 format.api { render_validation_errors(@project) } |
| 105 end | 107 end |
| 106 end | 108 end |
| 107 | |
| 108 end | 109 end |
| 109 | 110 |
| 110 def copy | 111 def copy |
| 111 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 112 @issue_custom_fields = IssueCustomField.sorted.all |
| 112 @trackers = Tracker.sorted.all | 113 @trackers = Tracker.sorted.all |
| 113 @root_projects = Project.find(:all, | |
| 114 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | |
| 115 :order => 'name') | |
| 116 @source_project = Project.find(params[:id]) | 114 @source_project = Project.find(params[:id]) |
| 117 if request.get? | 115 if request.get? |
| 118 @project = Project.copy_from(@source_project) | 116 @project = Project.copy_from(@source_project) |
| 119 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | 117 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
| 120 else | 118 else |
| 122 @project = Project.new | 120 @project = Project.new |
| 123 @project.safe_attributes = params[:project] | 121 @project.safe_attributes = params[:project] |
| 124 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) | 122 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) |
| 125 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 123 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
| 126 flash[:notice] = l(:notice_successful_create) | 124 flash[:notice] = l(:notice_successful_create) |
| 127 redirect_to :controller => 'projects', :action => 'settings', :id => @project | 125 redirect_to settings_project_path(@project) |
| 128 elsif !@project.new_record? | 126 elsif !@project.new_record? |
| 129 # Project was created | 127 # Project was created |
| 130 # But some objects were not copied due to validation failures | 128 # But some objects were not copied due to validation failures |
| 131 # (eg. issues from disabled trackers) | 129 # (eg. issues from disabled trackers) |
| 132 # TODO: inform about that | 130 # TODO: inform about that |
| 133 redirect_to :controller => 'projects', :action => 'settings', :id => @project | 131 redirect_to settings_project_path(@project) |
| 134 end | 132 end |
| 135 end | 133 end |
| 136 end | 134 end |
| 137 rescue ActiveRecord::RecordNotFound | 135 rescue ActiveRecord::RecordNotFound |
| 138 # source_project not found | 136 # source_project not found |
| 139 render_404 | 137 render_404 |
| 140 end | 138 end |
| 141 | 139 |
| 142 # Show @project | 140 # Show @project |
| 143 def show | 141 def show |
| 144 if params[:jump] | 142 # try to redirect to the requested menu item |
| 145 # try to redirect to the requested menu item | 143 if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) |
| 146 redirect_to_project_menu_item(@project, params[:jump]) && return | 144 return |
| 147 end | 145 end |
| 148 | 146 |
| 149 @users_by_role = @project.users_by_role | 147 @users_by_role = @project.users_by_role |
| 150 @subprojects = @project.children.visible.all | 148 @subprojects = @project.children.visible.all |
| 151 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | 149 @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all |
| 152 @trackers = @project.rolled_up_trackers | 150 @trackers = @project.rolled_up_trackers |
| 153 | 151 |
| 154 cond = @project.project_condition(Setting.display_subprojects_issues?) | 152 cond = @project.project_condition(Setting.display_subprojects_issues?) |
| 155 | 153 |
| 156 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) | 154 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) |
| 167 format.api | 165 format.api |
| 168 end | 166 end |
| 169 end | 167 end |
| 170 | 168 |
| 171 def settings | 169 def settings |
| 172 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 170 @issue_custom_fields = IssueCustomField.sorted.all |
| 173 @issue_category ||= IssueCategory.new | 171 @issue_category ||= IssueCategory.new |
| 174 @member ||= @project.members.new | 172 @member ||= @project.members.new |
| 175 @trackers = Tracker.sorted.all | 173 @trackers = Tracker.sorted.all |
| 176 @wiki ||= @project.wiki | 174 @wiki ||= @project.wiki |
| 177 end | 175 end |
| 184 if validate_parent_id && @project.save | 182 if validate_parent_id && @project.save |
| 185 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 183 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
| 186 respond_to do |format| | 184 respond_to do |format| |
| 187 format.html { | 185 format.html { |
| 188 flash[:notice] = l(:notice_successful_update) | 186 flash[:notice] = l(:notice_successful_update) |
| 189 redirect_to :action => 'settings', :id => @project | 187 redirect_to settings_project_path(@project) |
| 190 } | 188 } |
| 191 format.api { render_api_ok } | 189 format.api { render_api_ok } |
| 192 end | 190 end |
| 193 else | 191 else |
| 194 respond_to do |format| | 192 respond_to do |format| |
| 202 end | 200 end |
| 203 | 201 |
| 204 def modules | 202 def modules |
| 205 @project.enabled_module_names = params[:enabled_module_names] | 203 @project.enabled_module_names = params[:enabled_module_names] |
| 206 flash[:notice] = l(:notice_successful_update) | 204 flash[:notice] = l(:notice_successful_update) |
| 207 redirect_to :action => 'settings', :id => @project, :tab => 'modules' | 205 redirect_to settings_project_path(@project, :tab => 'modules') |
| 208 end | 206 end |
| 209 | 207 |
| 210 def archive | 208 def archive |
| 211 if request.post? | 209 if request.post? |
| 212 unless @project.archive | 210 unless @project.archive |
| 213 flash[:error] = l(:error_can_not_archive_project) | 211 flash[:error] = l(:error_can_not_archive_project) |
| 214 end | 212 end |
| 215 end | 213 end |
| 216 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | 214 redirect_to admin_projects_path(:status => params[:status]) |
| 217 end | 215 end |
| 218 | 216 |
| 219 def unarchive | 217 def unarchive |
| 220 @project.unarchive if request.post? && !@project.active? | 218 @project.unarchive if request.post? && !@project.active? |
| 221 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | 219 redirect_to admin_projects_path(:status => params[:status]) |
| 222 end | 220 end |
| 223 | 221 |
| 224 def close | 222 def close |
| 225 @project.close | 223 @project.close |
| 226 redirect_to project_path(@project) | 224 redirect_to project_path(@project) |
| 235 def destroy | 233 def destroy |
| 236 @project_to_destroy = @project | 234 @project_to_destroy = @project |
| 237 if api_request? || params[:confirm] | 235 if api_request? || params[:confirm] |
| 238 @project_to_destroy.destroy | 236 @project_to_destroy.destroy |
| 239 respond_to do |format| | 237 respond_to do |format| |
| 240 format.html { redirect_to :controller => 'admin', :action => 'projects' } | 238 format.html { redirect_to admin_projects_path } |
| 241 format.api { render_api_ok } | 239 format.api { render_api_ok } |
| 242 end | 240 end |
| 243 end | 241 end |
| 244 # hide project in layout | 242 # hide project in layout |
| 245 @project = nil | 243 @project = nil |
