annotate .svn/pristine/57/57a3ca6236cc4e5539fa3337ae1a20668f37ff47.svn-base @ 1477:f2ad2199b49a bibplugin_integration

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