Mercurial > hg > soundsoftware-site
comparison app/controllers/.svn/text-base/versions_controller.rb.svn-base @ 22:40f7cfd4df19
* Update to SVN trunk rev 4173
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 24 Sep 2010 14:06:04 +0100 |
parents | cca12e1c1fd4 |
children | 94944d00e43c |
comparison
equal
deleted
inserted
replaced
14:1d32c0a0efbf | 22:40f7cfd4df19 |
---|---|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 class VersionsController < ApplicationController | 18 class VersionsController < ApplicationController |
19 menu_item :roadmap | 19 menu_item :roadmap |
20 model_object Version | 20 model_object Version |
21 before_filter :find_model_object, :except => [:new, :close_completed] | 21 before_filter :find_model_object, :except => [:index, :new, :create, :close_completed] |
22 before_filter :find_project_from_association, :except => [:new, :close_completed] | 22 before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed] |
23 before_filter :find_project, :only => [:new, :close_completed] | 23 before_filter :find_project, :only => [:index, :new, :create, :close_completed] |
24 before_filter :authorize | 24 before_filter :authorize |
25 | 25 |
26 helper :custom_fields | 26 helper :custom_fields |
27 helper :projects | 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 | |
28 | 52 |
29 def show | 53 def show |
30 @issues = @version.fixed_issues.visible.find(:all, | 54 @issues = @version.fixed_issues.visible.find(:all, |
31 :include => [:status, :tracker, :priority], | 55 :include => [:status, :tracker, :priority], |
32 :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id") | 56 :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id") |
37 if params[:version] | 61 if params[:version] |
38 attributes = params[:version].dup | 62 attributes = params[:version].dup |
39 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) | 63 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) |
40 @version.attributes = attributes | 64 @version.attributes = attributes |
41 end | 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 | |
42 if request.post? | 77 if request.post? |
43 if @version.save | 78 if @version.save |
44 respond_to do |format| | 79 respond_to do |format| |
45 format.html do | 80 format.html do |
46 flash[:notice] = l(:notice_successful_create) | 81 flash[:notice] = l(:notice_successful_create) |
53 } | 88 } |
54 end | 89 end |
55 end | 90 end |
56 else | 91 else |
57 respond_to do |format| | 92 respond_to do |format| |
58 format.html | 93 format.html { render :action => 'new' } |
59 format.js do | 94 format.js do |
60 render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) } | 95 render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) } |
61 end | 96 end |
62 end | 97 end |
63 end | 98 end |
64 end | 99 end |
65 end | 100 end |
101 | |
102 def edit | |
103 end | |
66 | 104 |
67 def edit | 105 def update |
68 if request.post? && params[:version] | 106 if request.put? && params[:version] |
69 attributes = params[:version].dup | 107 attributes = params[:version].dup |
70 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) | 108 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) |
71 if @version.update_attributes(attributes) | 109 if @version.update_attributes(attributes) |
72 flash[:notice] = l(:notice_successful_update) | 110 flash[:notice] = l(:notice_successful_update) |
73 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | 111 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
74 end | 112 end |
75 end | 113 end |
76 end | 114 end |
77 | 115 |
78 def close_completed | 116 def close_completed |
79 if request.post? | 117 if request.put? |
80 @project.close_completed_versions | 118 @project.close_completed_versions |
81 end | 119 end |
82 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | 120 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
83 end | 121 end |
84 | 122 |
103 def find_project | 141 def find_project |
104 @project = Project.find(params[:project_id]) | 142 @project = Project.find(params[:project_id]) |
105 rescue ActiveRecord::RecordNotFound | 143 rescue ActiveRecord::RecordNotFound |
106 render_404 | 144 render_404 |
107 end | 145 end |
146 | |
147 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil) | |
148 if ids = params[:tracker_ids] | |
149 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
150 else | |
151 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s } | |
152 end | |
153 end | |
154 | |
108 end | 155 end |