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 @ 1535:e2c122809c5c

History | View | Annotate | Download (6.04 KB)

1 909:cbb26bc654de Chris
# Redmine - project management software
2 1494:e248c7af89ec Chris
# Copyright (C) 2006-2014  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 1115:433d4f72a19b Chris
  before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed]
24 0:513646585e45 Chris
  before_filter :authorize
25
26 929:5f33065ddc4b Chris
  accept_api_auth :index, :show, :create, :update, :destroy
27 909:cbb26bc654de Chris
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 1464:261b3d9a4903 Chris
        @trackers = @project.trackers.sorted.all
35 909:cbb26bc654de Chris
        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 1115:433d4f72a19b Chris
        unless params[:completed]
43
          @completed_versions = @versions.select {|version| version.closed? || version.completed? }
44
          @versions -= @completed_versions
45
        end
46 909:cbb26bc654de Chris
47
        @issues_by_version = {}
48 1115:433d4f72a19b Chris
        if @selected_tracker_ids.any? && @versions.any?
49 1464:261b3d9a4903 Chris
          issues = Issue.visible.
50
            includes(:project, :tracker).
51
            preload(:status, :priority, :fixed_version).
52
            where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)).
53
            order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
54 1115:433d4f72a19b Chris
          @issues_by_version = issues.group_by(&:fixed_version)
55 909:cbb26bc654de Chris
        end
56
        @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
57
      }
58
      format.api {
59
        @versions = @project.shared_versions.all
60
      }
61 22:40f7cfd4df19 chris
    end
62
  end
63 909:cbb26bc654de Chris
64 0:513646585e45 Chris
  def show
65 909:cbb26bc654de Chris
    respond_to do |format|
66
      format.html {
67 1464:261b3d9a4903 Chris
        @issues = @version.fixed_issues.visible.
68
          includes(:status, :tracker, :priority).
69
          reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
70
          all
71 909:cbb26bc654de Chris
      }
72
      format.api
73
    end
74 0:513646585e45 Chris
  end
75 909:cbb26bc654de Chris
76 0:513646585e45 Chris
  def new
77
    @version = @project.versions.build
78 1115:433d4f72a19b Chris
    @version.safe_attributes = params[:version]
79
80
    respond_to do |format|
81
      format.html
82
      format.js
83 0:513646585e45 Chris
    end
84 22:40f7cfd4df19 chris
  end
85
86
  def create
87
    @version = @project.versions.build
88
    if params[:version]
89
      attributes = params[:version].dup
90
      attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
91 929:5f33065ddc4b Chris
      @version.safe_attributes = attributes
92 22:40f7cfd4df19 chris
    end
93
94 0:513646585e45 Chris
    if request.post?
95
      if @version.save
96
        respond_to do |format|
97
          format.html do
98
            flash[:notice] = l(:notice_successful_create)
99 1464:261b3d9a4903 Chris
            redirect_back_or_default settings_project_path(@project, :tab => 'versions')
100 0:513646585e45 Chris
          end
101 1115:433d4f72a19b Chris
          format.js
102 909:cbb26bc654de Chris
          format.api do
103
            render :action => 'show', :status => :created, :location => version_url(@version)
104
          end
105 0:513646585e45 Chris
        end
106
      else
107
        respond_to do |format|
108 22:40f7cfd4df19 chris
          format.html { render :action => 'new' }
109 1115:433d4f72a19b Chris
          format.js   { render :action => 'new' }
110 909:cbb26bc654de Chris
          format.api  { render_validation_errors(@version) }
111 0:513646585e45 Chris
        end
112
      end
113
    end
114
  end
115 22:40f7cfd4df19 chris
116
  def edit
117
  end
118 909:cbb26bc654de Chris
119 22:40f7cfd4df19 chris
  def update
120
    if request.put? && params[:version]
121 0:513646585e45 Chris
      attributes = params[:version].dup
122
      attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
123 929:5f33065ddc4b Chris
      @version.safe_attributes = attributes
124
      if @version.save
125 909:cbb26bc654de Chris
        respond_to do |format|
126
          format.html {
127
            flash[:notice] = l(:notice_successful_update)
128 1464:261b3d9a4903 Chris
            redirect_back_or_default settings_project_path(@project, :tab => 'versions')
129 909:cbb26bc654de Chris
          }
130 1115:433d4f72a19b Chris
          format.api  { render_api_ok }
131 909:cbb26bc654de Chris
        end
132 37:94944d00e43c chris
      else
133
        respond_to do |format|
134
          format.html { render :action => 'edit' }
135 909:cbb26bc654de Chris
          format.api  { render_validation_errors(@version) }
136 37:94944d00e43c chris
        end
137 0:513646585e45 Chris
      end
138
    end
139
  end
140 909:cbb26bc654de Chris
141 0:513646585e45 Chris
  def close_completed
142 22:40f7cfd4df19 chris
    if request.put?
143 0:513646585e45 Chris
      @project.close_completed_versions
144
    end
145 1464:261b3d9a4903 Chris
    redirect_to settings_project_path(@project, :tab => 'versions')
146 0:513646585e45 Chris
  end
147
148
  def destroy
149
    if @version.fixed_issues.empty?
150
      @version.destroy
151 909:cbb26bc654de Chris
      respond_to do |format|
152 1464:261b3d9a4903 Chris
        format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') }
153 1115:433d4f72a19b Chris
        format.api  { render_api_ok }
154 909:cbb26bc654de Chris
      end
155 0:513646585e45 Chris
    else
156 909:cbb26bc654de Chris
      respond_to do |format|
157
        format.html {
158
          flash[:error] = l(:notice_unable_delete_version)
159 1464:261b3d9a4903 Chris
          redirect_to settings_project_path(@project, :tab => 'versions')
160 909:cbb26bc654de Chris
        }
161
        format.api  { head :unprocessable_entity }
162
      end
163 0:513646585e45 Chris
    end
164
  end
165 909:cbb26bc654de Chris
166 0:513646585e45 Chris
  def status_by
167
    respond_to do |format|
168
      format.html { render :action => 'show' }
169 1115:433d4f72a19b Chris
      format.js
170 0:513646585e45 Chris
    end
171
  end
172
173 1115:433d4f72a19b Chris
  private
174 22:40f7cfd4df19 chris
175
  def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
176
    if ids = params[:tracker_ids]
177
      @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
178
    else
179
      @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
180
    end
181
  end
182 0:513646585e45 Chris
end