##// END OF EJS Templates
Feature 9867 Allow file upload in comment and add to issue history...
Jean-Philippe Lang -
r422:3f87f3c47a26
parent child
Show More
@@ -1,139 +1,159
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssuesController < ApplicationController
19 19 layout 'base', :except => :export_pdf
20 20 before_filter :find_project, :authorize
21 21
22 22 helper :custom_fields
23 23 include CustomFieldsHelper
24 24 helper :ifpdf
25 25 include IfpdfHelper
26 26
27 27 def show
28 28 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
29 29 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
30 30 @journals_count = @issue.journals.count
31 31 @journals = @issue.journals.find(:all, :include => [:user, :details], :limit => 15, :order => "#{Journal.table_name}.created_on desc")
32 32 end
33 33
34 34 def history
35 35 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on desc")
36 36 @journals_count = @journals.length
37 37 end
38 38
39 39 def export_pdf
40 40 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
41 41 @options_for_rfpdf ||= {}
42 42 @options_for_rfpdf[:file_name] = "#{@project.name}_#{@issue.long_id}.pdf"
43 43 end
44 44
45 45 def edit
46 46 @priorities = Enumeration::get_values('IPRI')
47 47 if request.get?
48 48 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| @issue.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x, :customized => @issue) }
49 49 else
50 50 begin
51 51 @issue.init_journal(self.logged_in_user)
52 52 # Retrieve custom fields and values
53 53 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
54 54 @issue.custom_values = @custom_values
55 55 @issue.attributes = params[:issue]
56 56 if @issue.save
57 57 flash[:notice] = l(:notice_successful_update)
58 58 redirect_to :action => 'show', :id => @issue
59 59 end
60 60 rescue ActiveRecord::StaleObjectError
61 61 # Optimistic locking exception
62 62 flash[:notice] = l(:notice_locking_conflict)
63 63 end
64 64 end
65 65 end
66 66
67 67 def add_note
68 68 unless params[:notes].empty?
69 69 journal = @issue.init_journal(self.logged_in_user, params[:notes])
70 70 if @issue.save
71 71 flash[:notice] = l(:notice_successful_update)
72 72 Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
73 73 redirect_to :action => 'show', :id => @issue
74 74 return
75 75 end
76 76 end
77 77 show
78 78 render :action => 'show'
79 79 end
80 80
81 81 def change_status
82 82 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
83 83 @new_status = IssueStatus.find(params[:new_status_id])
84 84 if params[:confirm]
85 85 begin
86 86 journal = @issue.init_journal(self.logged_in_user, params[:notes])
87 87 @issue.status = @new_status
88 88 if @issue.update_attributes(params[:issue])
89 # Save attachments
90 params[:attachments].each { |file|
91 next unless file.size > 0
92 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
93 journal.details << JournalDetail.new(:property => 'attachment',
94 :prop_key => a.id,
95 :value => a.filename) unless a.new_record?
96 } if params[:attachments] and params[:attachments].is_a? Array
97
89 98 flash[:notice] = l(:notice_successful_update)
90 99 Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
91 100 redirect_to :action => 'show', :id => @issue
92 101 end
93 102 rescue ActiveRecord::StaleObjectError
94 103 # Optimistic locking exception
95 104 flash[:notice] = l(:notice_locking_conflict)
96 105 end
97 106 end
98 107 @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
99 108 end
100 109
101 110 def destroy
102 111 @issue.destroy
103 112 redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
104 113 end
105 114
106 115 def add_attachment
107 116 # Save the attachments
108 117 @attachments = []
118 journal = @issue.init_journal(self.logged_in_user)
109 119 params[:attachments].each { |file|
110 120 next unless file.size > 0
111 121 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
112 122 @attachments << a unless a.new_record?
123 journal.details << JournalDetail.new(:property => 'attachment',
124 :prop_key => a.id,
125 :value => a.filename) unless a.new_record?
113 126 } if params[:attachments] and params[:attachments].is_a? Array
127 journal.save if journal.details.any?
114 128 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
115 129 redirect_to :action => 'show', :id => @issue
116 130 end
117 131
118 132 def destroy_attachment
119 @issue.attachments.find(params[:attachment_id]).destroy
133 a = @issue.attachments.find(params[:attachment_id])
134 a.destroy
135 journal = @issue.init_journal(self.logged_in_user)
136 journal.details << JournalDetail.new(:property => 'attachment',
137 :prop_key => a.id,
138 :old_value => a.filename)
139 journal.save
120 140 redirect_to :action => 'show', :id => @issue
121 141 end
122 142
123 143 # Send the file in stream mode
124 144 def download
125 145 @attachment = @issue.attachments.find(params[:attachment_id])
126 146 send_file @attachment.diskfile, :filename => @attachment.filename
127 147 rescue
128 148 render_404
129 149 end
130 150
131 151 private
132 152 def find_project
133 153 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
134 154 @project = @issue.project
135 155 @html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}"
136 156 rescue ActiveRecord::RecordNotFound
137 157 render_404
138 158 end
139 159 end
@@ -1,74 +1,86
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module IssuesHelper
19 19
20 20 def show_detail(detail, no_html=false)
21 21 case detail.property
22 22 when 'attr'
23 23 label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym)
24 24 case detail.prop_key
25 25 when 'due_date', 'start_date'
26 26 value = format_date(detail.value.to_date) if detail.value
27 27 old_value = format_date(detail.old_value.to_date) if detail.old_value
28 28 when 'status_id'
29 29 s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value
30 30 s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value
31 31 when 'assigned_to_id'
32 32 u = User.find_by_id(detail.value) and value = u.name if detail.value
33 33 u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
34 34 when 'priority_id'
35 35 e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value
36 36 e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
37 37 when 'category_id'
38 38 c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
39 39 c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
40 40 when 'fixed_version_id'
41 41 v = Version.find_by_id(detail.value) and value = v.name if detail.value
42 42 v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value
43 43 end
44 44 when 'cf'
45 45 custom_field = CustomField.find_by_id(detail.prop_key)
46 46 if custom_field
47 47 label = custom_field.name
48 48 value = format_value(detail.value, custom_field.field_format) if detail.value
49 49 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
50 50 end
51 when 'attachment'
52 label = l(:label_attachment)
51 53 end
52 54
53 55 label ||= detail.prop_key
54 56 value ||= detail.value
55 57 old_value ||= detail.old_value
56 58
57 59 unless no_html
58 60 label = content_tag('strong', label)
59 61 old_value = content_tag("i", h(old_value)) if detail.old_value
60 62 old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
61 63 value = content_tag("i", h(value)) if value
62 64 end
63 65
64 66 if detail.value and !detail.value.to_s.empty?
65 if old_value
66 label + " " + l(:text_journal_changed, old_value, value)
67 else
68 label + " " + l(:text_journal_set_to, value)
67 case detail.property
68 when 'attr', 'cf'
69 if old_value
70 label + " " + l(:text_journal_changed, old_value, value)
71 else
72 label + " " + l(:text_journal_set_to, value)
73 end
74 when 'attachment'
75 "#{label} #{value} #{l(:label_added)}"
69 76 end
70 77 else
71 label + " " + l(:text_journal_deleted) + " (#{old_value})"
78 case detail.property
79 when 'attr', 'cf'
80 label + " " + l(:text_journal_deleted) + " (#{old_value})"
81 when 'attachment'
82 "#{label} #{old_value} #{l(:label_deleted)}"
83 end
72 84 end
73 85 end
74 86 end
@@ -1,37 +1,43
1 1 <h2><%=l(:label_issue)%> #<%= @issue.id %>: <%=h @issue.subject %></h2>
2 2
3 3 <%= error_messages_for 'issue' %>
4 <% form_tag({:action => 'change_status', :id => @issue}, :class => "tabular") do %>
4 <% form_tag({:action => 'change_status', :id => @issue}, :multipart => true, :class => "tabular") do %>
5 5
6 6 <%= hidden_field_tag 'confirm', 1 %>
7 7 <%= hidden_field_tag 'new_status_id', @new_status.id %>
8 8
9 9 <div class="box">
10 10 <p><label><%=l(:label_issue_status_new)%></label> <%= @new_status.name %></p>
11 11
12 12 <p><label for="issue_assigned_to_id"><%=l(:field_assigned_to)%></label>
13 13 <select name="issue[assigned_to_id]">
14 14 <option value=""></option>
15 15 <%= options_from_collection_for_select @assignable_to, "id", "display_name", @issue.assigned_to_id %></p>
16 16 </select></p>
17 17
18 18
19 19 <p><label for="issue_done_ratio"><%=l(:field_done_ratio)%></label>
20 20 <%= select("issue", "done_ratio", ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) ) %>
21 21 </select></p>
22 22
23 23
24 24 <p><label for="issue_fixed_version"><%=l(:field_fixed_version)%></label>
25 25 <select name="issue[fixed_version_id]">
26 26 <option value="">--none--</option>
27 27 <%= options_from_collection_for_select @issue.project.versions, "id", "name", @issue.fixed_version_id %>
28 28 </select></p>
29 29
30 30 <p><label for="notes"><%= l(:field_notes) %></label>
31 31 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %></p>
32 32
33 <% if authorize_for('issues', 'add_attachment') %>
34 <p id="attachments_p"><label><%=l(:label_attachment_new)%>
35 <%= image_to_function "add.png", "addFileField();return false" %></label>
36 <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p>
37 <% end %>
38
33 39 </div>
34 40
35 41 <%= hidden_field 'issue', 'lock_version' %>
36 42 <%= submit_tag l(:button_save) %>
37 43 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now