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