annotate app/controllers/versions_controller.rb @ 1478:5ca1f4a47171 bibplugin_db_migrations

Close obsolete branch bibplugin_db_migrations
author Chris Cannam
date Fri, 30 Nov 2012 14:40:50 +0000
parents 5f33065ddc4b
children 433d4f72a19b
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class VersionsController < ApplicationController
Chris@0 19 menu_item :roadmap
Chris@0 20 model_object Version
chris@22 21 before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
chris@22 22 before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
chris@22 23 before_filter :find_project, :only => [:index, :new, :create, :close_completed]
Chris@0 24 before_filter :authorize
Chris@0 25
Chris@929 26 accept_api_auth :index, :show, :create, :update, :destroy
Chris@909 27
Chris@0 28 helper :custom_fields
Chris@0 29 helper :projects
chris@22 30
chris@22 31 def index
Chris@909 32 respond_to do |format|
Chris@909 33 format.html {
Chris@909 34 @trackers = @project.trackers.find(:all, :order => 'position')
Chris@909 35 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
Chris@909 36 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
Chris@909 37 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
Chris@909 38
Chris@909 39 @versions = @project.shared_versions || []
Chris@909 40 @versions += @project.rolled_up_versions.visible if @with_subprojects
Chris@909 41 @versions = @versions.uniq.sort
Chris@909 42 @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
Chris@909 43
Chris@909 44 @issues_by_version = {}
Chris@909 45 unless @selected_tracker_ids.empty?
Chris@909 46 @versions.each do |version|
Chris@909 47 issues = version.fixed_issues.visible.find(:all,
Chris@909 48 :include => [:project, :status, :tracker, :priority],
Chris@909 49 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
Chris@909 50 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
Chris@909 51 @issues_by_version[version] = issues
Chris@909 52 end
Chris@909 53 end
Chris@909 54 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
Chris@909 55 }
Chris@909 56 format.api {
Chris@909 57 @versions = @project.shared_versions.all
Chris@909 58 }
chris@22 59 end
chris@22 60 end
Chris@909 61
Chris@0 62 def show
Chris@909 63 respond_to do |format|
Chris@909 64 format.html {
Chris@909 65 @issues = @version.fixed_issues.visible.find(:all,
Chris@909 66 :include => [:status, :tracker, :priority],
Chris@909 67 :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id")
Chris@909 68 }
Chris@909 69 format.api
Chris@909 70 end
Chris@0 71 end
Chris@909 72
Chris@0 73 def new
Chris@0 74 @version = @project.versions.build
Chris@0 75 if params[:version]
Chris@0 76 attributes = params[:version].dup
Chris@0 77 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
Chris@929 78 @version.safe_attributes = attributes
Chris@0 79 end
chris@22 80 end
chris@22 81
chris@22 82 def create
chris@22 83 # TODO: refactor with code above in #new
chris@22 84 @version = @project.versions.build
chris@22 85 if params[:version]
chris@22 86 attributes = params[:version].dup
chris@22 87 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
Chris@929 88 @version.safe_attributes = attributes
chris@22 89 end
chris@22 90
Chris@0 91 if request.post?
Chris@0 92 if @version.save
Chris@0 93 respond_to do |format|
Chris@0 94 format.html do
Chris@0 95 flash[:notice] = l(:notice_successful_create)
Chris@909 96 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
Chris@0 97 end
Chris@0 98 format.js do
Chris@0 99 # IE doesn't support the replace_html rjs method for select box options
Chris@0 100 render(:update) {|page| page.replace "issue_fixed_version_id",
Chris@0 101 content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
Chris@0 102 }
Chris@0 103 end
Chris@909 104 format.api do
Chris@909 105 render :action => 'show', :status => :created, :location => version_url(@version)
Chris@909 106 end
Chris@0 107 end
Chris@0 108 else
Chris@0 109 respond_to do |format|
chris@22 110 format.html { render :action => 'new' }
Chris@0 111 format.js do
Chris@0 112 render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
Chris@0 113 end
Chris@909 114 format.api { render_validation_errors(@version) }
Chris@0 115 end
Chris@0 116 end
Chris@0 117 end
Chris@0 118 end
chris@22 119
chris@22 120 def edit
chris@22 121 end
Chris@909 122
chris@22 123 def update
chris@22 124 if request.put? && params[:version]
Chris@0 125 attributes = params[:version].dup
Chris@0 126 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
Chris@929 127 @version.safe_attributes = attributes
Chris@929 128 if @version.save
Chris@909 129 respond_to do |format|
Chris@909 130 format.html {
Chris@909 131 flash[:notice] = l(:notice_successful_update)
Chris@909 132 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
Chris@909 133 }
Chris@909 134 format.api { head :ok }
Chris@909 135 end
chris@37 136 else
chris@37 137 respond_to do |format|
chris@37 138 format.html { render :action => 'edit' }
Chris@909 139 format.api { render_validation_errors(@version) }
chris@37 140 end
Chris@0 141 end
Chris@0 142 end
Chris@0 143 end
Chris@909 144
Chris@0 145 def close_completed
chris@22 146 if request.put?
Chris@0 147 @project.close_completed_versions
Chris@0 148 end
Chris@0 149 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
Chris@0 150 end
Chris@0 151
Chris@909 152 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
Chris@0 153 def destroy
Chris@0 154 if @version.fixed_issues.empty?
Chris@0 155 @version.destroy
Chris@909 156 respond_to do |format|
Chris@909 157 format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project }
Chris@909 158 format.api { head :ok }
Chris@909 159 end
Chris@0 160 else
Chris@909 161 respond_to do |format|
Chris@909 162 format.html {
Chris@909 163 flash[:error] = l(:notice_unable_delete_version)
Chris@909 164 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
Chris@909 165 }
Chris@909 166 format.api { head :unprocessable_entity }
Chris@909 167 end
Chris@0 168 end
Chris@0 169 end
Chris@909 170
Chris@0 171 def status_by
Chris@0 172 respond_to do |format|
Chris@0 173 format.html { render :action => 'show' }
Chris@0 174 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
Chris@0 175 end
Chris@0 176 end
Chris@0 177
Chris@0 178 private
Chris@0 179 def find_project
Chris@0 180 @project = Project.find(params[:project_id])
Chris@0 181 rescue ActiveRecord::RecordNotFound
Chris@0 182 render_404
Chris@0 183 end
chris@22 184
chris@22 185 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
chris@22 186 if ids = params[:tracker_ids]
chris@22 187 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
chris@22 188 else
chris@22 189 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
chris@22 190 end
chris@22 191 end
chris@22 192
Chris@0 193 end