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