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 @ 831:7614169e14ed

History | View | Annotate | Download (6.09 KB)

1
# redMine - project management software
2
# Copyright (C) 2006  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
  helper :custom_fields
27
  helper :projects
28

    
29
  def index
30
    @trackers = @project.trackers.find(:all, :order => 'position')
31
    retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
32
    @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
33
    project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
34
    
35
    @versions = @project.shared_versions || []
36
    @versions += @project.rolled_up_versions.visible if @with_subprojects
37
    @versions = @versions.uniq.sort
38
    @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
39
    
40
    @issues_by_version = {}
41
    unless @selected_tracker_ids.empty?
42
      @versions.each do |version|
43
        issues = version.fixed_issues.visible.find(:all,
44
                                                   :include => [:project, :status, :tracker, :priority],
45
                                                   :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
46
                                                   :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
47
        @issues_by_version[version] = issues
48
      end
49
    end
50
    @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
51
  end
52
  
53
  def show
54
    @issues = @version.fixed_issues.visible.find(:all,
55
      :include => [:status, :tracker, :priority],
56
      :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id")
57
  end
58
  
59
  def new
60
    @version = @project.versions.build
61
    if params[:version]
62
      attributes = params[:version].dup
63
      attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
64
      @version.attributes = attributes
65
    end
66
  end
67

    
68
  def create
69
    # TODO: refactor with code above in #new
70
    @version = @project.versions.build
71
    if params[:version]
72
      attributes = params[:version].dup
73
      attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
74
      @version.attributes = attributes
75
    end
76

    
77
    if request.post?
78
      if @version.save
79
        respond_to do |format|
80
          format.html do
81
            flash[:notice] = l(:notice_successful_create)
82
            redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
83
          end
84
          format.js do
85
            # IE doesn't support the replace_html rjs method for select box options
86
            render(:update) {|page| page.replace "issue_fixed_version_id",
87
              content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
88
            }
89
          end
90
        end
91
      else
92
        respond_to do |format|
93
          format.html { render :action => 'new' }
94
          format.js do
95
            render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
96
          end
97
        end
98
      end
99
    end
100
  end
101

    
102
  def edit
103
  end
104
  
105
  def update
106
    if request.put? && params[:version]
107
      attributes = params[:version].dup
108
      attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
109
      if @version.update_attributes(attributes)
110
        flash[:notice] = l(:notice_successful_update)
111
        redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
112
      else
113
        respond_to do |format|
114
          format.html { render :action => 'edit' }
115
        end
116
      end
117
    end
118
  end
119
  
120
  def close_completed
121
    if request.put?
122
      @project.close_completed_versions
123
    end
124
    redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
125
  end
126

    
127
  def destroy
128
    if @version.fixed_issues.empty?
129
      @version.destroy
130
      redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
131
    else
132
      flash[:error] = l(:notice_unable_delete_version)
133
      redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
134
    end
135
  end
136
  
137
  def status_by
138
    respond_to do |format|
139
      format.html { render :action => 'show' }
140
      format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
141
    end
142
  end
143

    
144
private
145
  def find_project
146
    @project = Project.find(params[:project_id])
147
  rescue ActiveRecord::RecordNotFound
148
    render_404
149
  end
150

    
151
  def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
152
    if ids = params[:tracker_ids]
153
      @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
154
    else
155
      @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
156
    end
157
  end
158

    
159
end