##// END OF EJS Templates
mail notifications added when:...
Jean-Philippe Lang -
r193:2d47a6d71c09
parent child
Show More
@@ -0,0 +1,6
1 <%= @added_to %>
2 <%= @attachments.size %> files(s) added.
3 <% @attachments.each do |attachment | %>
4 - <%= attachment.filename %><% end %>
5
6 <%= @url %> No newline at end of file
@@ -0,0 +1,6
1 <%= @added_to %>
2 <%= @attachments.size %> files(s) added.
3 <% @attachments.each do |attachment | %>
4 - <%= attachment.filename %><% end %>
5
6 <%= @url %> No newline at end of file
@@ -0,0 +1,6
1 <%= @added_to %>
2 <%= @attachments.size %> files(s) added.
3 <% @attachments.each do |attachment | %>
4 - <%= attachment.filename %><% end %>
5
6 <%= @url %> No newline at end of file
@@ -0,0 +1,6
1 <%= @added_to %>
2 <%= @attachments.size %> fichier(s) ajoutΓ©(s).
3 <% @attachments.each do |attachment | %>
4 - <%= attachment.filename %><% end %>
5
6 <%= @url %> No newline at end of file
@@ -0,0 +1,4
1 A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):
2 <%= l(:field_title) %>: <%= @document.title %>
3
4 http://<%= Setting.host_name %>/documents/show/<%= @document.id %> No newline at end of file
@@ -0,0 +1,4
1 A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):
2 <%= l(:field_title) %>: <%= @document.title %>
3
4 http://<%= Setting.host_name %>/documents/show/<%= @document.id %> No newline at end of file
@@ -0,0 +1,4
1 A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):
2 <%= l(:field_title) %>: <%= @document.title %>
3
4 http://<%= Setting.host_name %>/documents/show/<%= @document.id %> No newline at end of file
@@ -0,0 +1,4
1 Un document a Γ©tΓ© ajoutΓ© Γ  <%= @document.project.name %> (<%= @document.category.name %>):
2 <%= l(:field_title) %>: <%= @document.title %>
3
4 http://<%= Setting.host_name %>/documents/show/<%= @document.id %> No newline at end of file
@@ -0,0 +1,15
1 class SetDocAndFilesNotifications < ActiveRecord::Migration
2 def self.up
3 Permission.find_by_controller_and_action("projects", "add_file").update_attribute(:mail_option, true)
4 Permission.find_by_controller_and_action("projects", "add_document").update_attribute(:mail_option, true)
5 Permission.find_by_controller_and_action("documents", "add_attachment").update_attribute(:mail_option, true)
6 Permission.find_by_controller_and_action("issues", "add_attachment").update_attribute(:mail_option, true)
7 end
8
9 def self.down
10 Permission.find_by_controller_and_action("projects", "add_file").update_attribute(:mail_option, false)
11 Permission.find_by_controller_and_action("projects", "add_document").update_attribute(:mail_option, false)
12 Permission.find_by_controller_and_action("documents", "add_attachment").update_attribute(:mail_option, false)
13 Permission.find_by_controller_and_action("issues", "add_attachment").update_attribute(:mail_option, false)
14 end
15 end
@@ -1,67 +1,71
1 1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
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 DocumentsController < ApplicationController
19 19 layout 'base'
20 20 before_filter :find_project, :authorize
21 21
22 22 def show
23 23 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
24 24 end
25 25
26 26 def edit
27 27 @categories = Enumeration::get_values('DCAT')
28 28 if request.post? and @document.update_attributes(params[:document])
29 29 flash[:notice] = l(:notice_successful_update)
30 30 redirect_to :action => 'show', :id => @document
31 31 end
32 32 end
33 33
34 34 def destroy
35 35 @document.destroy
36 36 redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
37 37 end
38 38
39 39 def download
40 40 @attachment = @document.attachments.find(params[:attachment_id])
41 41 @attachment.increment_download
42 42 send_file @attachment.diskfile, :filename => @attachment.filename
43 43 rescue
44 44 render_404
45 45 end
46 46
47 47 def add_attachment
48 48 # Save the attachments
49 params[:attachments].each { |a|
50 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
49 @attachments = []
50 params[:attachments].each { |file|
51 next unless file.size > 0
52 a = Attachment.create(:container => @document, :file => file, :author => logged_in_user)
53 @attachments << a unless a.new_record?
51 54 } if params[:attachments] and params[:attachments].is_a? Array
55 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
52 56 redirect_to :action => 'show', :id => @document
53 57 end
54 58
55 59 def destroy_attachment
56 60 @document.attachments.find(params[:attachment_id]).destroy
57 61 redirect_to :action => 'show', :id => @document
58 62 end
59 63
60 64 private
61 65 def find_project
62 66 @document = Document.find(params[:id])
63 67 @project = @document.project
64 68 rescue ActiveRecord::RecordNotFound
65 69 render_404
66 70 end
67 71 end
@@ -1,146 +1,149
1 1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
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.workflows.find(:all, :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.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 => "journals.created_on desc")
32 32 end
33 33
34 34 def history
35 35 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "journals.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 #@history = @issue.histories.build(params[:history])
71 71 #@history.author_id = self.logged_in_user.id if self.logged_in_user
72 72 #@history.status = @issue.status
73 73 if @issue.save
74 74 flash[:notice] = l(:notice_successful_update)
75 75 Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
76 76 redirect_to :action => 'show', :id => @issue
77 77 return
78 78 end
79 79 end
80 80 show
81 81 render :action => 'show'
82 82 end
83 83
84 84 def change_status
85 85 #@history = @issue.histories.build(params[:history])
86 86 @status_options = @issue.status.workflows.find(:all, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } if self.logged_in_user
87 87 @new_status = IssueStatus.find(params[:new_status_id])
88 88 if params[:confirm]
89 89 begin
90 90 #@history.author_id = self.logged_in_user.id if self.logged_in_user
91 91 #@issue.status = @history.status
92 92 #@issue.fixed_version_id = (params[:issue][:fixed_version_id])
93 93 #@issue.assigned_to_id = (params[:issue][:assigned_to_id])
94 94 #@issue.done_ratio = (params[:issue][:done_ratio])
95 95 #@issue.lock_version = (params[:issue][:lock_version])
96 96 journal = @issue.init_journal(self.logged_in_user, params[:notes])
97 97 @issue.status = @new_status
98 98 if @issue.update_attributes(params[:issue])
99 99 flash[:notice] = l(:notice_successful_update)
100 100 Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
101 101 redirect_to :action => 'show', :id => @issue
102 102 end
103 103 rescue ActiveRecord::StaleObjectError
104 104 # Optimistic locking exception
105 105 flash[:notice] = l(:notice_locking_conflict)
106 106 end
107 107 end
108 108 @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
109 109 end
110 110
111 111 def destroy
112 112 @issue.destroy
113 113 redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
114 114 end
115 115
116 116 def add_attachment
117 117 # Save the attachments
118 params[:attachments].each { |a|
119 @attachment = @issue.attachments.build(:file => a, :author => self.logged_in_user) unless a.size == 0
120 @attachment.save
118 @attachments = []
119 params[:attachments].each { |file|
120 next unless file.size > 0
121 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
122 @attachments << a unless a.new_record?
121 123 } if params[:attachments] and params[:attachments].is_a? Array
124 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
122 125 redirect_to :action => 'show', :id => @issue
123 126 end
124 127
125 128 def destroy_attachment
126 129 @issue.attachments.find(params[:attachment_id]).destroy
127 130 redirect_to :action => 'show', :id => @issue
128 131 end
129 132
130 133 # Send the file in stream mode
131 134 def download
132 135 @attachment = @issue.attachments.find(params[:attachment_id])
133 136 send_file @attachment.diskfile, :filename => @attachment.filename
134 137 rescue
135 138 render_404
136 139 end
137 140
138 141 private
139 142 def find_project
140 143 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
141 144 @project = @issue.project
142 145 @html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}"
143 146 rescue ActiveRecord::RecordNotFound
144 147 render_404
145 148 end
146 149 end
@@ -1,557 +1,562
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 require 'csv'
19 19
20 20 class ProjectsController < ApplicationController
21 21 layout 'base'
22 22 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
23 23 before_filter :require_admin, :only => [ :add, :destroy ]
24 24
25 25 helper :sort
26 26 include SortHelper
27 27 helper :custom_fields
28 28 include CustomFieldsHelper
29 29 helper :ifpdf
30 30 include IfpdfHelper
31 31 helper IssuesHelper
32 32 helper :queries
33 33 include QueriesHelper
34 34
35 35 def index
36 36 list
37 37 render :action => 'list' unless request.xhr?
38 38 end
39 39
40 40 # Lists public projects
41 41 def list
42 42 sort_init 'name', 'asc'
43 43 sort_update
44 44 @project_count = Project.count(:all, :conditions => ["is_public=?", true])
45 45 @project_pages = Paginator.new self, @project_count,
46 46 15,
47 47 params['page']
48 48 @projects = Project.find :all, :order => sort_clause,
49 49 :conditions => ["is_public=?", true],
50 50 :limit => @project_pages.items_per_page,
51 51 :offset => @project_pages.current.offset
52 52
53 53 render :action => "list", :layout => false if request.xhr?
54 54 end
55 55
56 56 # Add a new project
57 57 def add
58 58 @custom_fields = IssueCustomField.find(:all)
59 59 @root_projects = Project.find(:all, :conditions => "parent_id is null")
60 60 @project = Project.new(params[:project])
61 61 if request.get?
62 62 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
63 63 else
64 64 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
65 65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
66 66 @project.custom_values = @custom_values
67 67 if params[:repository_enabled] && params[:repository_enabled] == "1"
68 68 @project.repository = Repository.new
69 69 @project.repository.attributes = params[:repository]
70 70 end
71 71 if @project.save
72 72 flash[:notice] = l(:notice_successful_create)
73 73 redirect_to :controller => 'admin', :action => 'projects'
74 74 end
75 75 end
76 76 end
77 77
78 78 # Show @project
79 79 def show
80 80 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
81 81 @members = @project.members.find(:all, :include => [:user, :role])
82 82 @subprojects = @project.children if @project.children.size > 0
83 83 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC")
84 84 @trackers = Tracker.find(:all)
85 85 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id", :conditions => ["project_id=? and issue_statuses.is_closed=?", @project.id, false])
86 86 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
87 87 end
88 88
89 89 def settings
90 90 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
91 91 @custom_fields = IssueCustomField.find(:all)
92 92 @issue_category ||= IssueCategory.new
93 93 @member ||= @project.members.new
94 94 @roles = Role.find(:all)
95 95 @users = User.find_active(:all) - @project.users
96 96 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
97 97 end
98 98
99 99 # Edit @project
100 100 def edit
101 101 if request.post?
102 102 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
103 103 if params[:custom_fields]
104 104 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
105 105 @project.custom_values = @custom_values
106 106 end
107 107 if params[:repository_enabled]
108 108 case params[:repository_enabled]
109 109 when "0"
110 110 @project.repository = nil
111 111 when "1"
112 112 @project.repository ||= Repository.new
113 113 @project.repository.attributes = params[:repository]
114 114 end
115 115 end
116 116 @project.attributes = params[:project]
117 117 if @project.save
118 118 flash[:notice] = l(:notice_successful_update)
119 119 redirect_to :action => 'settings', :id => @project
120 120 else
121 121 settings
122 122 render :action => 'settings'
123 123 end
124 124 end
125 125 end
126 126
127 127 # Delete @project
128 128 def destroy
129 129 if request.post? and params[:confirm]
130 130 @project.destroy
131 131 redirect_to :controller => 'admin', :action => 'projects'
132 132 end
133 133 end
134 134
135 135 # Add a new issue category to @project
136 136 def add_issue_category
137 137 if request.post?
138 138 @issue_category = @project.issue_categories.build(params[:issue_category])
139 139 if @issue_category.save
140 140 flash[:notice] = l(:notice_successful_create)
141 141 redirect_to :action => 'settings', :tab => 'categories', :id => @project
142 142 else
143 143 settings
144 144 render :action => 'settings'
145 145 end
146 146 end
147 147 end
148 148
149 149 # Add a new version to @project
150 150 def add_version
151 151 @version = @project.versions.build(params[:version])
152 152 if request.post? and @version.save
153 153 flash[:notice] = l(:notice_successful_create)
154 154 redirect_to :action => 'settings', :tab => 'versions', :id => @project
155 155 end
156 156 end
157 157
158 158 # Add a new member to @project
159 159 def add_member
160 160 @member = @project.members.build(params[:member])
161 161 if request.post?
162 162 if @member.save
163 163 flash[:notice] = l(:notice_successful_create)
164 164 redirect_to :action => 'settings', :tab => 'members', :id => @project
165 165 else
166 166 settings
167 167 render :action => 'settings'
168 168 end
169 169 end
170 170 end
171 171
172 172 # Show members list of @project
173 173 def list_members
174 174 @members = @project.members
175 175 end
176 176
177 177 # Add a new document to @project
178 178 def add_document
179 179 @categories = Enumeration::get_values('DCAT')
180 180 @document = @project.documents.build(params[:document])
181 181 if request.post? and @document.save
182 182 # Save the attachments
183 183 params[:attachments].each { |a|
184 184 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
185 185 } if params[:attachments] and params[:attachments].is_a? Array
186 186 flash[:notice] = l(:notice_successful_create)
187 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
187 188 redirect_to :action => 'list_documents', :id => @project
188 189 end
189 190 end
190 191
191 192 # Show documents list of @project
192 193 def list_documents
193 194 @documents = @project.documents.find :all, :include => :category
194 195 end
195 196
196 197 # Add a new issue to @project
197 198 def add_issue
198 199 @tracker = Tracker.find(params[:tracker_id])
199 200 @priorities = Enumeration::get_values('IPRI')
200 201 @issue = Issue.new(:project => @project, :tracker => @tracker)
201 202 if request.get?
202 203 @issue.start_date = Date.today
203 204 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
204 205 else
205 206 @issue.attributes = params[:issue]
206 207 @issue.author_id = self.logged_in_user.id if self.logged_in_user
207 208 # Multiple file upload
208 209 @attachments = []
209 210 params[:attachments].each { |a|
210 211 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
211 212 } if params[:attachments] and params[:attachments].is_a? Array
212 213 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
213 214 @issue.custom_values = @custom_values
214 215 if @issue.save
215 216 @attachments.each(&:save)
216 217 flash[:notice] = l(:notice_successful_create)
217 218 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
218 219 redirect_to :action => 'list_issues', :id => @project
219 220 end
220 221 end
221 222 end
222 223
223 224 # Show filtered/sorted issues list of @project
224 225 def list_issues
225 226 sort_init 'issues.id', 'desc'
226 227 sort_update
227 228
228 229 retrieve_query
229 230
230 231 @results_per_page_options = [ 15, 25, 50, 100 ]
231 232 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
232 233 @results_per_page = params[:per_page].to_i
233 234 session[:results_per_page] = @results_per_page
234 235 else
235 236 @results_per_page = session[:results_per_page] || 25
236 237 end
237 238
238 239 if @query.valid?
239 240 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
240 241 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
241 242 @issues = Issue.find :all, :order => sort_clause,
242 243 :include => [ :author, :status, :tracker, :project ],
243 244 :conditions => @query.statement,
244 245 :limit => @issue_pages.items_per_page,
245 246 :offset => @issue_pages.current.offset
246 247 end
247 248 @trackers = Tracker.find :all
248 249 render :layout => false if request.xhr?
249 250 end
250 251
251 252 # Export filtered/sorted issues list to CSV
252 253 def export_issues_csv
253 254 sort_init 'issues.id', 'desc'
254 255 sort_update
255 256
256 257 retrieve_query
257 258 render :action => 'list_issues' and return unless @query.valid?
258 259
259 260 @issues = Issue.find :all, :order => sort_clause,
260 261 :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
261 262 :conditions => @query.statement
262 263
263 264 ic = Iconv.new('ISO-8859-1', 'UTF-8')
264 265 export = StringIO.new
265 266 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
266 267 # csv header fields
267 268 headers = [ "#", l(:field_status),
268 269 l(:field_tracker),
269 270 l(:field_priority),
270 271 l(:field_subject),
271 272 l(:field_author),
272 273 l(:field_start_date),
273 274 l(:field_due_date),
274 275 l(:field_done_ratio),
275 276 l(:field_created_on),
276 277 l(:field_updated_on)
277 278 ]
278 279 for custom_field in @project.all_custom_fields
279 280 headers << custom_field.name
280 281 end
281 282 csv << headers.collect {|c| ic.iconv(c) }
282 283 # csv lines
283 284 @issues.each do |issue|
284 285 fields = [issue.id, issue.status.name,
285 286 issue.tracker.name,
286 287 issue.priority.name,
287 288 issue.subject,
288 289 issue.author.display_name,
289 290 issue.start_date ? l_date(issue.start_date) : nil,
290 291 issue.due_date ? l_date(issue.due_date) : nil,
291 292 issue.done_ratio,
292 293 l_datetime(issue.created_on),
293 294 l_datetime(issue.updated_on)
294 295 ]
295 296 for custom_field in @project.all_custom_fields
296 297 fields << (show_value issue.custom_value_for(custom_field))
297 298 end
298 299 csv << fields.collect {|c| ic.iconv(c.to_s) }
299 300 end
300 301 end
301 302 export.rewind
302 303 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
303 304 end
304 305
305 306 # Export filtered/sorted issues to PDF
306 307 def export_issues_pdf
307 308 sort_init 'issues.id', 'desc'
308 309 sort_update
309 310
310 311 retrieve_query
311 312 render :action => 'list_issues' and return unless @query.valid?
312 313
313 314 @issues = Issue.find :all, :order => sort_clause,
314 315 :include => [ :author, :status, :tracker, :project, :custom_values ],
315 316 :conditions => @query.statement
316 317
317 318 @options_for_rfpdf ||= {}
318 319 @options_for_rfpdf[:file_name] = "export.pdf"
319 320 render :layout => false
320 321 end
321 322
322 323 def move_issues
323 324 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
324 325 redirect_to :action => 'list_issues', :id => @project and return unless @issues
325 326 @projects = []
326 327 # find projects to which the user is allowed to move the issue
327 328 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
328 329 # issue can be moved to any tracker
329 330 @trackers = Tracker.find(:all)
330 331 if request.post? and params[:new_project_id] and params[:new_tracker_id]
331 332 new_project = Project.find(params[:new_project_id])
332 333 new_tracker = Tracker.find(params[:new_tracker_id])
333 334 @issues.each { |i|
334 335 # project dependent properties
335 336 unless i.project_id == new_project.id
336 337 i.category = nil
337 338 i.fixed_version = nil
338 339 end
339 340 # move the issue
340 341 i.project = new_project
341 342 i.tracker = new_tracker
342 343 i.save
343 344 }
344 345 flash[:notice] = l(:notice_successful_update)
345 346 redirect_to :action => 'list_issues', :id => @project
346 347 end
347 348 end
348 349
349 350 def add_query
350 351 @query = Query.new(params[:query])
351 352 @query.project = @project
352 353 @query.user = logged_in_user
353 354
354 355 params[:fields].each do |field|
355 356 @query.add_filter(field, params[:operators][field], params[:values][field])
356 357 end if params[:fields]
357 358
358 359 if request.post? and @query.save
359 360 flash[:notice] = l(:notice_successful_create)
360 361 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
361 362 end
362 363 render :layout => false if request.xhr?
363 364 end
364 365
365 366 # Add a news to @project
366 367 def add_news
367 368 @news = News.new(:project => @project)
368 369 if request.post?
369 370 @news.attributes = params[:news]
370 371 @news.author_id = self.logged_in_user.id if self.logged_in_user
371 372 if @news.save
372 373 flash[:notice] = l(:notice_successful_create)
373 374 redirect_to :action => 'list_news', :id => @project
374 375 end
375 376 end
376 377 end
377 378
378 379 # Show news list of @project
379 380 def list_news
380 381 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "news.created_on DESC"
381 382 render :action => "list_news", :layout => false if request.xhr?
382 383 end
383 384
384 385 def add_file
385 386 if request.post?
386 387 @version = @project.versions.find_by_id(params[:version_id])
387 388 # Save the attachments
388 params[:attachments].each { |a|
389 Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0
389 @attachments = []
390 params[:attachments].each { |file|
391 next unless file.size > 0
392 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
393 @attachments << a unless a.new_record?
390 394 } if params[:attachments] and params[:attachments].is_a? Array
395 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
391 396 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
392 397 end
393 398 @versions = @project.versions
394 399 end
395 400
396 401 def list_files
397 402 @versions = @project.versions
398 403 end
399 404
400 405 # Show changelog for @project
401 406 def changelog
402 407 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true])
403 408 if request.get?
404 409 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
405 410 else
406 411 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
407 412 end
408 413 @selected_tracker_ids ||= []
409 414 @fixed_issues = @project.issues.find(:all,
410 415 :include => [ :fixed_version, :status, :tracker ],
411 416 :conditions => [ "issue_statuses.is_closed=? and issues.tracker_id in (#{@selected_tracker_ids.join(',')}) and issues.fixed_version_id is not null", true],
412 417 :order => "versions.effective_date DESC, issues.id DESC"
413 418 ) unless @selected_tracker_ids.empty?
414 419 @fixed_issues ||= []
415 420 end
416 421
417 422 def activity
418 423 if params[:year] and params[:year].to_i > 1900
419 424 @year = params[:year].to_i
420 425 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
421 426 @month = params[:month].to_i
422 427 end
423 428 end
424 429 @year ||= Date.today.year
425 430 @month ||= Date.today.month
426 431
427 432 @date_from = Date.civil(@year, @month, 1)
428 433 @date_to = (@date_from >> 1)-1
429 434
430 435 @events_by_day = {}
431 436
432 437 unless params[:show_issues] == "0"
433 438 @project.issues.find(:all, :include => [:author, :status], :conditions => ["issues.created_on>=? and issues.created_on<=?", @date_from, @date_to] ).each { |i|
434 439 @events_by_day[i.created_on.to_date] ||= []
435 440 @events_by_day[i.created_on.to_date] << i
436 441 }
437 442 @show_issues = 1
438 443 end
439 444
440 445 unless params[:show_news] == "0"
441 446 @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
442 447 @events_by_day[i.created_on.to_date] ||= []
443 448 @events_by_day[i.created_on.to_date] << i
444 449 }
445 450 @show_news = 1
446 451 end
447 452
448 453 unless params[:show_files] == "0"
449 454 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
450 455 @events_by_day[i.created_on.to_date] ||= []
451 456 @events_by_day[i.created_on.to_date] << i
452 457 }
453 458 @show_files = 1
454 459 end
455 460
456 461 unless params[:show_documents] == "0"
457 462 @project.documents.find(:all, :conditions => ["documents.created_on>=? and documents.created_on<=?", @date_from, @date_to] ).each { |i|
458 463 @events_by_day[i.created_on.to_date] ||= []
459 464 @events_by_day[i.created_on.to_date] << i
460 465 }
461 466 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
462 467 @events_by_day[i.created_on.to_date] ||= []
463 468 @events_by_day[i.created_on.to_date] << i
464 469 }
465 470 @show_documents = 1
466 471 end
467 472
468 473 render :layout => false if request.xhr?
469 474 end
470 475
471 476 def calendar
472 477 if params[:year] and params[:year].to_i > 1900
473 478 @year = params[:year].to_i
474 479 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
475 480 @month = params[:month].to_i
476 481 end
477 482 end
478 483 @year ||= Date.today.year
479 484 @month ||= Date.today.month
480 485
481 486 @date_from = Date.civil(@year, @month, 1)
482 487 @date_to = (@date_from >> 1)-1
483 488 # start on monday
484 489 @date_from = @date_from - (@date_from.cwday-1)
485 490 # finish on sunday
486 491 @date_to = @date_to + (7-@date_to.cwday)
487 492
488 493 @issues = @project.issues.find(:all, :include => [:tracker, :status, :assigned_to, :priority], :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to])
489 494 render :layout => false if request.xhr?
490 495 end
491 496
492 497 def gantt
493 498 if params[:year] and params[:year].to_i >0
494 499 @year_from = params[:year].to_i
495 500 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
496 501 @month_from = params[:month].to_i
497 502 else
498 503 @month_from = 1
499 504 end
500 505 else
501 506 @month_from ||= (Date.today << 1).month
502 507 @year_from ||= (Date.today << 1).year
503 508 end
504 509
505 510 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
506 511 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
507 512
508 513 @date_from = Date.civil(@year_from, @month_from, 1)
509 514 @date_to = (@date_from >> @months) - 1
510 515 @issues = @project.issues.find(:all, :order => "start_date, due_date", :include => [:tracker, :status, :assigned_to, :priority], :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to])
511 516
512 517 if params[:output]=='pdf'
513 518 @options_for_rfpdf ||= {}
514 519 @options_for_rfpdf[:file_name] = "gantt.pdf"
515 520 render :template => "projects/gantt.rfpdf", :layout => false
516 521 else
517 522 render :template => "projects/gantt.rhtml"
518 523 end
519 524 end
520 525
521 526 private
522 527 # Find project of id params[:id]
523 528 # if not found, redirect to project list
524 529 # Used as a before_filter
525 530 def find_project
526 531 @project = Project.find(params[:id])
527 532 @html_title = @project.name
528 533 rescue ActiveRecord::RecordNotFound
529 534 render_404
530 535 end
531 536
532 537 # Retrieve query from session or build a new query
533 538 def retrieve_query
534 539 if params[:query_id]
535 540 @query = @project.queries.find(params[:query_id])
536 541 session[:query] = @query
537 542 else
538 543 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
539 544 # Give it a name, required to be valid
540 545 @query = Query.new(:name => "_")
541 546 @query.project = @project
542 547 if params[:fields] and params[:fields].is_a? Array
543 548 params[:fields].each do |field|
544 549 @query.add_filter(field, params[:operators][field], params[:values][field])
545 550 end
546 551 else
547 552 @query.available_filters.keys.each do |field|
548 553 @query.add_short_filter(field, params[field]) if params[field]
549 554 end
550 555 end
551 556 session[:query] = @query
552 557 else
553 558 @query = session[:query]
554 559 end
555 560 end
556 561 end
557 562 end
@@ -1,52 +1,82
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 Mailer < ActionMailer::Base
19 19 helper IssuesHelper
20 20
21 21 def issue_add(issue)
22 22 # Sends to all project members
23 23 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
24 24 @from = Setting.mail_from
25 25 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
26 26 @body['issue'] = issue
27 27 end
28 28
29 29 def issue_edit(journal)
30 30 # Sends to all project members
31 31 issue = journal.journalized
32 32 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
33 33 @from = Setting.mail_from
34 34 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
35 35 @body['issue'] = issue
36 36 @body['journal']= journal
37 37 end
38 38
39 def document_add(document)
40 @recipients = document.project.users.collect { |u| u.mail if u.mail_notification }.compact
41 @from = Setting.mail_from
42 @subject = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
43 @body['document'] = document
44 end
45
46 def attachments_add(attachments)
47 container = attachments.first.container
48 url = "http://#{Setting.host_name}/"
49 added_to = ""
50 case container.class.to_s
51 when 'Version'
52 url << "projects/list_files/#{container.project_id}"
53 added_to = "#{l(:label_version)}: #{container.name}"
54 when 'Document'
55 url << "documents/show/#{container.id}"
56 added_to = "#{l(:label_document)}: #{container.title}"
57 when 'Issue'
58 url << "issues/show/#{container.id}"
59 added_to = "#{container.tracker.name} ##{container.id}: #{container.subject}"
60 end
61 @recipients = container.project.users.collect { |u| u.mail if u.mail_notification }.compact
62 @from = Setting.mail_from
63 @subject = "[#{container.project.name}] #{l(:label_attachment_new)}"
64 @body['attachments'] = attachments
65 @body['url'] = url
66 @body['added_to'] = added_to
67 end
68
39 69 def lost_password(token)
40 70 @recipients = token.user.mail
41 71 @from = Setting.mail_from
42 72 @subject = l(:mail_subject_lost_password)
43 73 @body['token'] = token
44 74 end
45 75
46 76 def register(token)
47 77 @recipients = token.user.mail
48 78 @from = Setting.mail_from
49 79 @subject = l(:mail_subject_register)
50 80 @body['token'] = token
51 81 end
52 82 end
General Comments 0
You need to be logged in to leave comments. Login now