To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / versions_controller.rb @ 912:5e80956cc792

History | View | Annotate | Download (7.16 KB)

1 909:cbb26bc654de Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
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 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# 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 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# 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 22:40f7cfd4df19 chris
  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 0:513646585e45 Chris
  before_filter :authorize
25
26 909:cbb26bc654de Chris
  accept_api_auth :index, :create, :update, :destroy
27
28 0:513646585e45 Chris
  helper :custom_fields
29
  helper :projects
30 22:40f7cfd4df19 chris
31
  def index
32 909:cbb26bc654de Chris
    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 22:40f7cfd4df19 chris
    end
60
  end
61 909:cbb26bc654de Chris
62 0:513646585e45 Chris
  def show
63 909:cbb26bc654de Chris
    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 0:513646585e45 Chris
  end
72 909:cbb26bc654de Chris
73 0:513646585e45 Chris
  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.attributes = attributes
79
    end
80 22:40f7cfd4df19 chris
  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.attributes = attributes
89
    end
90
91 0:513646585e45 Chris
    if request.post?
92
      if @version.save
93
        respond_to do |format|
94
          format.html do
95
            flash[:notice] = l(:notice_successful_create)
96 909:cbb26bc654de Chris
            redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
97 0:513646585e45 Chris
          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 909:cbb26bc654de Chris
          format.api do
105
            render :action => 'show', :status => :created, :location => version_url(@version)
106
          end
107 0:513646585e45 Chris
        end
108
      else
109
        respond_to do |format|
110 22:40f7cfd4df19 chris
          format.html { render :action => 'new' }
111 0:513646585e45 Chris
          format.js do
112
            render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
113
          end
114 909:cbb26bc654de Chris
          format.api  { render_validation_errors(@version) }
115 0:513646585e45 Chris
        end
116
      end
117
    end
118
  end
119 22:40f7cfd4df19 chris
120
  def edit
121
  end
122 909:cbb26bc654de Chris
123 22:40f7cfd4df19 chris
  def update
124
    if request.put? && params[:version]
125 0:513646585e45 Chris
      attributes = params[:version].dup
126
      attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
127
      if @version.update_attributes(attributes)
128 909:cbb26bc654de Chris
        respond_to do |format|
129
          format.html {
130
            flash[:notice] = l(:notice_successful_update)
131
            redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
132
          }
133
          format.api  { head :ok }
134
        end
135 37:94944d00e43c chris
      else
136
        respond_to do |format|
137
          format.html { render :action => 'edit' }
138 909:cbb26bc654de Chris
          format.api  { render_validation_errors(@version) }
139 37:94944d00e43c chris
        end
140 0:513646585e45 Chris
      end
141
    end
142
  end
143 909:cbb26bc654de Chris
144 0:513646585e45 Chris
  def close_completed
145 22:40f7cfd4df19 chris
    if request.put?
146 0:513646585e45 Chris
      @project.close_completed_versions
147
    end
148
    redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
149
  end
150
151 909:cbb26bc654de Chris
  verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
152 0:513646585e45 Chris
  def destroy
153
    if @version.fixed_issues.empty?
154
      @version.destroy
155 909:cbb26bc654de Chris
      respond_to do |format|
156
        format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project }
157
        format.api  { head :ok }
158
      end
159 0:513646585e45 Chris
    else
160 909:cbb26bc654de Chris
      respond_to do |format|
161
        format.html {
162
          flash[:error] = l(:notice_unable_delete_version)
163
          redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
164
        }
165
        format.api  { head :unprocessable_entity }
166
      end
167 0:513646585e45 Chris
    end
168
  end
169 909:cbb26bc654de Chris
170 0:513646585e45 Chris
  def status_by
171
    respond_to do |format|
172
      format.html { render :action => 'show' }
173
      format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
174
    end
175
  end
176
177
private
178
  def find_project
179
    @project = Project.find(params[:project_id])
180
  rescue ActiveRecord::RecordNotFound
181
    render_404
182
  end
183 22:40f7cfd4df19 chris
184
  def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
185
    if ids = params[:tracker_ids]
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 }
187
    else
188
      @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
189
    end
190
  end
191
192 0:513646585e45 Chris
end