##// END OF EJS Templates
Custom query columns: checkboxes replaced by two selects that let the user specify columns order....
Jean-Philippe Lang -
r773:514cdacc87e6
parent child
Show More
@@ -0,0 +1,55
1 var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
2
3 function addOption(theSel, theText, theValue)
4 {
5 var newOpt = new Option(theText, theValue);
6 var selLength = theSel.length;
7 theSel.options[selLength] = newOpt;
8 }
9
10 function deleteOption(theSel, theIndex)
11 {
12 var selLength = theSel.length;
13 if(selLength>0)
14 {
15 theSel.options[theIndex] = null;
16 }
17 }
18
19 function moveOptions(theSelFrom, theSelTo)
20 {
21
22 var selLength = theSelFrom.length;
23 var selectedText = new Array();
24 var selectedValues = new Array();
25 var selectedCount = 0;
26
27 var i;
28
29 for(i=selLength-1; i>=0; i--)
30 {
31 if(theSelFrom.options[i].selected)
32 {
33 selectedText[selectedCount] = theSelFrom.options[i].text;
34 selectedValues[selectedCount] = theSelFrom.options[i].value;
35 deleteOption(theSelFrom, i);
36 selectedCount++;
37 }
38 }
39
40 for(i=selectedCount-1; i>=0; i--)
41 {
42 addOption(theSelTo, selectedText[i], selectedValues[i]);
43 }
44
45 if(NS4) history.go(0);
46 }
47
48 function selectAllOptions(id)
49 {
50 var select = $(id);
51 for (var i=0; i<select.options.length; i++) {
52 select.options[i].selected = true;
53 }
54 }
55
@@ -1,195 +1,195
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 IssuesController < ApplicationController
18 class IssuesController < ApplicationController
19 layout 'base', :except => :export_pdf
19 layout 'base', :except => :export_pdf
20 before_filter :find_project, :authorize, :except => :index
20 before_filter :find_project, :authorize, :except => :index
21 accept_key_auth :index
21 accept_key_auth :index
22
22
23 cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ]
23 cache_sweeper :issue_sweeper, :only => [ :edit, :change_status, :destroy ]
24
24
25 helper :projects
25 helper :projects
26 include ProjectsHelper
26 include ProjectsHelper
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 :issue_relations
31 helper :issue_relations
32 include IssueRelationsHelper
32 include IssueRelationsHelper
33 helper :watchers
33 helper :watchers
34 include WatchersHelper
34 include WatchersHelper
35 helper :attachments
35 helper :attachments
36 include AttachmentsHelper
36 include AttachmentsHelper
37 helper :queries
37 helper :queries
38 helper :sort
38 helper :sort
39 include SortHelper
39 include SortHelper
40
40
41 def index
41 def index
42 sort_init "#{Issue.table_name}.id", "desc"
42 sort_init "#{Issue.table_name}.id", "desc"
43 sort_update
43 sort_update
44 retrieve_query
44 retrieve_query
45 if @query.valid?
45 if @query.valid?
46 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
46 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
47 @issue_pages = Paginator.new self, @issue_count, 25, params['page']
47 @issue_pages = Paginator.new self, @issue_count, 25, params['page']
48 @issues = Issue.find :all, :order => sort_clause,
48 @issues = Issue.find :all, :order => sort_clause,
49 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
49 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
50 :conditions => @query.statement,
50 :conditions => @query.statement,
51 :limit => @issue_pages.items_per_page,
51 :limit => @issue_pages.items_per_page,
52 :offset => @issue_pages.current.offset
52 :offset => @issue_pages.current.offset
53 end
53 end
54 respond_to do |format|
54 respond_to do |format|
55 format.html { render :layout => false if request.xhr? }
55 format.html { render :layout => false if request.xhr? }
56 format.atom { render_feed(@issues, :title => l(:label_issue_plural)) }
56 format.atom { render_feed(@issues, :title => l(:label_issue_plural)) }
57 end
57 end
58 end
58 end
59
59
60 def show
60 def show
61 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
61 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
62 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
62 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
63 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
63 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
64 end
64 end
65
65
66 def export_pdf
66 def export_pdf
67 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
67 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
68 @options_for_rfpdf ||= {}
68 @options_for_rfpdf ||= {}
69 @options_for_rfpdf[:file_name] = "#{@project.name}_#{@issue.id}.pdf"
69 @options_for_rfpdf[:file_name] = "#{@project.name}_#{@issue.id}.pdf"
70 end
70 end
71
71
72 def edit
72 def edit
73 @priorities = Enumeration::get_values('IPRI')
73 @priorities = Enumeration::get_values('IPRI')
74 if request.get?
74 if request.get?
75 @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) }
75 @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) }
76 else
76 else
77 begin
77 begin
78 @issue.init_journal(self.logged_in_user)
78 @issue.init_journal(self.logged_in_user)
79 # Retrieve custom fields and values
79 # Retrieve custom fields and values
80 @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]) }
80 @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]) }
81 @issue.custom_values = @custom_values
81 @issue.custom_values = @custom_values
82 @issue.attributes = params[:issue]
82 @issue.attributes = params[:issue]
83 if @issue.save
83 if @issue.save
84 flash[:notice] = l(:notice_successful_update)
84 flash[:notice] = l(:notice_successful_update)
85 redirect_to :action => 'show', :id => @issue
85 redirect_to :action => 'show', :id => @issue
86 end
86 end
87 rescue ActiveRecord::StaleObjectError
87 rescue ActiveRecord::StaleObjectError
88 # Optimistic locking exception
88 # Optimistic locking exception
89 flash[:error] = l(:notice_locking_conflict)
89 flash[:error] = l(:notice_locking_conflict)
90 end
90 end
91 end
91 end
92 end
92 end
93
93
94 def add_note
94 def add_note
95 unless params[:notes].empty?
95 unless params[:notes].empty?
96 journal = @issue.init_journal(self.logged_in_user, params[:notes])
96 journal = @issue.init_journal(self.logged_in_user, params[:notes])
97 if @issue.save
97 if @issue.save
98 params[:attachments].each { |file|
98 params[:attachments].each { |file|
99 next unless file.size > 0
99 next unless file.size > 0
100 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
100 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
101 journal.details << JournalDetail.new(:property => 'attachment',
101 journal.details << JournalDetail.new(:property => 'attachment',
102 :prop_key => a.id,
102 :prop_key => a.id,
103 :value => a.filename) unless a.new_record?
103 :value => a.filename) unless a.new_record?
104 } if params[:attachments] and params[:attachments].is_a? Array
104 } if params[:attachments] and params[:attachments].is_a? Array
105 flash[:notice] = l(:notice_successful_update)
105 flash[:notice] = l(:notice_successful_update)
106 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
106 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
107 redirect_to :action => 'show', :id => @issue
107 redirect_to :action => 'show', :id => @issue
108 return
108 return
109 end
109 end
110 end
110 end
111 show
111 show
112 render :action => 'show'
112 render :action => 'show'
113 end
113 end
114
114
115 def change_status
115 def change_status
116 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
116 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
117 @new_status = IssueStatus.find(params[:new_status_id])
117 @new_status = IssueStatus.find(params[:new_status_id])
118 if params[:confirm]
118 if params[:confirm]
119 begin
119 begin
120 journal = @issue.init_journal(self.logged_in_user, params[:notes])
120 journal = @issue.init_journal(self.logged_in_user, params[:notes])
121 @issue.status = @new_status
121 @issue.status = @new_status
122 if @issue.update_attributes(params[:issue])
122 if @issue.update_attributes(params[:issue])
123 # Save attachments
123 # Save attachments
124 params[:attachments].each { |file|
124 params[:attachments].each { |file|
125 next unless file.size > 0
125 next unless file.size > 0
126 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
126 a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
127 journal.details << JournalDetail.new(:property => 'attachment',
127 journal.details << JournalDetail.new(:property => 'attachment',
128 :prop_key => a.id,
128 :prop_key => a.id,
129 :value => a.filename) unless a.new_record?
129 :value => a.filename) unless a.new_record?
130 } if params[:attachments] and params[:attachments].is_a? Array
130 } if params[:attachments] and params[:attachments].is_a? Array
131
131
132 # Log time
132 # Log time
133 if current_role.allowed_to?(:log_time)
133 if current_role.allowed_to?(:log_time)
134 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => logged_in_user, :spent_on => Date.today)
134 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => logged_in_user, :spent_on => Date.today)
135 @time_entry.attributes = params[:time_entry]
135 @time_entry.attributes = params[:time_entry]
136 @time_entry.save
136 @time_entry.save
137 end
137 end
138
138
139 flash[:notice] = l(:notice_successful_update)
139 flash[:notice] = l(:notice_successful_update)
140 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
140 Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
141 redirect_to :action => 'show', :id => @issue
141 redirect_to :action => 'show', :id => @issue
142 end
142 end
143 rescue ActiveRecord::StaleObjectError
143 rescue ActiveRecord::StaleObjectError
144 # Optimistic locking exception
144 # Optimistic locking exception
145 flash[:error] = l(:notice_locking_conflict)
145 flash[:error] = l(:notice_locking_conflict)
146 end
146 end
147 end
147 end
148 @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
148 @assignable_to = @project.members.find(:all, :include => :user).collect{ |m| m.user }
149 @activities = Enumeration::get_values('ACTI')
149 @activities = Enumeration::get_values('ACTI')
150 end
150 end
151
151
152 def destroy
152 def destroy
153 @issue.destroy
153 @issue.destroy
154 redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
154 redirect_to :controller => 'projects', :action => 'list_issues', :id => @project
155 end
155 end
156
156
157 def destroy_attachment
157 def destroy_attachment
158 a = @issue.attachments.find(params[:attachment_id])
158 a = @issue.attachments.find(params[:attachment_id])
159 a.destroy
159 a.destroy
160 journal = @issue.init_journal(self.logged_in_user)
160 journal = @issue.init_journal(self.logged_in_user)
161 journal.details << JournalDetail.new(:property => 'attachment',
161 journal.details << JournalDetail.new(:property => 'attachment',
162 :prop_key => a.id,
162 :prop_key => a.id,
163 :old_value => a.filename)
163 :old_value => a.filename)
164 journal.save
164 journal.save
165 redirect_to :action => 'show', :id => @issue
165 redirect_to :action => 'show', :id => @issue
166 end
166 end
167
167
168 private
168 private
169 def find_project
169 def find_project
170 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
170 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
171 @project = @issue.project
171 @project = @issue.project
172 rescue ActiveRecord::RecordNotFound
172 rescue ActiveRecord::RecordNotFound
173 render_404
173 render_404
174 end
174 end
175
175
176 # Retrieve query from session or build a new query
176 # Retrieve query from session or build a new query
177 def retrieve_query
177 def retrieve_query
178 if params[:set_filter] or !session[:query] or session[:query].project_id
178 if params[:set_filter] or !session[:query] or session[:query].project_id
179 # Give it a name, required to be valid
179 # Give it a name, required to be valid
180 @query = Query.new(:name => "_", :executed_by => logged_in_user)
180 @query = Query.new(:name => "_", :executed_by => logged_in_user)
181 if params[:fields] and params[:fields].is_a? Array
181 if params[:fields] and params[:fields].is_a? Array
182 params[:fields].each do |field|
182 params[:fields].each do |field|
183 @query.add_filter(field, params[:operators][field], params[:values][field])
183 @query.add_filter(field, params[:operators][field], params[:values][field])
184 end
184 end
185 else
185 else
186 @query.available_filters.keys.each do |field|
186 @query.available_filters.keys.each do |field|
187 @query.add_short_filter(field, params[field]) if params[field]
187 @query.add_short_filter(field, params[field]) if params[field]
188 end
188 end
189 end
189 end
190 session[:query] = @query
190 session[:query] = @query
191 else
191 else
192 @query = session[:query]
192 @query = session[:query]
193 end
193 end
194 end
194 end
195 end
195 end
@@ -1,633 +1,633
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, :except => [ :index, :list, :add ]
22 before_filter :find_project, :except => [ :index, :list, :add ]
23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
25 accept_key_auth :activity, :calendar
25 accept_key_auth :activity, :calendar
26
26
27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
29 cache_sweeper :version_sweeper, :only => [ :add_version ]
29 cache_sweeper :version_sweeper, :only => [ :add_version ]
30
30
31 helper :sort
31 helper :sort
32 include SortHelper
32 include SortHelper
33 helper :custom_fields
33 helper :custom_fields
34 include CustomFieldsHelper
34 include CustomFieldsHelper
35 helper :ifpdf
35 helper :ifpdf
36 include IfpdfHelper
36 include IfpdfHelper
37 helper IssuesHelper
37 helper IssuesHelper
38 helper :queries
38 helper :queries
39 include QueriesHelper
39 include QueriesHelper
40 helper :repositories
40 helper :repositories
41 include RepositoriesHelper
41 include RepositoriesHelper
42 include ProjectsHelper
42 include ProjectsHelper
43
43
44 def index
44 def index
45 list
45 list
46 render :action => 'list' unless request.xhr?
46 render :action => 'list' unless request.xhr?
47 end
47 end
48
48
49 # Lists visible projects
49 # Lists visible projects
50 def list
50 def list
51 projects = Project.find :all,
51 projects = Project.find :all,
52 :conditions => Project.visible_by(logged_in_user),
52 :conditions => Project.visible_by(logged_in_user),
53 :include => :parent
53 :include => :parent
54 @project_tree = projects.group_by {|p| p.parent || p}
54 @project_tree = projects.group_by {|p| p.parent || p}
55 @project_tree.each_key {|p| @project_tree[p] -= [p]}
55 @project_tree.each_key {|p| @project_tree[p] -= [p]}
56 end
56 end
57
57
58 # Add a new project
58 # Add a new project
59 def add
59 def add
60 @custom_fields = IssueCustomField.find(:all)
60 @custom_fields = IssueCustomField.find(:all)
61 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
61 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
62 @project = Project.new(params[:project])
62 @project = Project.new(params[:project])
63 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
63 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
64 if request.get?
64 if request.get?
65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
66 else
66 else
67 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
67 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
68 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
68 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
69 @project.custom_values = @custom_values
69 @project.custom_values = @custom_values
70 if @project.save
70 if @project.save
71 @project.enabled_module_names = params[:enabled_modules]
71 @project.enabled_module_names = params[:enabled_modules]
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_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
81 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
82 @subprojects = @project.active_children
82 @subprojects = @project.active_children
83 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
83 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
84 @trackers = Tracker.find(:all, :order => 'position')
84 @trackers = Tracker.find(:all, :order => 'position')
85 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
85 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.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 @total_hours = @project.time_entries.sum(:hours)
87 @total_hours = @project.time_entries.sum(:hours)
88 @key = User.current.rss_key
88 @key = User.current.rss_key
89 end
89 end
90
90
91 def settings
91 def settings
92 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
92 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
93 @custom_fields = IssueCustomField.find(:all)
93 @custom_fields = IssueCustomField.find(:all)
94 @issue_category ||= IssueCategory.new
94 @issue_category ||= IssueCategory.new
95 @member ||= @project.members.new
95 @member ||= @project.members.new
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 @repository ||= @project.repository
97 @repository ||= @project.repository
98 @wiki ||= @project.wiki
98 @wiki ||= @project.wiki
99 end
99 end
100
100
101 # Edit @project
101 # Edit @project
102 def edit
102 def edit
103 if request.post?
103 if request.post?
104 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
104 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
105 if params[:custom_fields]
105 if params[:custom_fields]
106 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
106 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
107 @project.custom_values = @custom_values
107 @project.custom_values = @custom_values
108 end
108 end
109 @project.attributes = params[:project]
109 @project.attributes = params[:project]
110 if @project.save
110 if @project.save
111 flash[:notice] = l(:notice_successful_update)
111 flash[:notice] = l(:notice_successful_update)
112 redirect_to :action => 'settings', :id => @project
112 redirect_to :action => 'settings', :id => @project
113 else
113 else
114 settings
114 settings
115 render :action => 'settings'
115 render :action => 'settings'
116 end
116 end
117 end
117 end
118 end
118 end
119
119
120 def modules
120 def modules
121 @project.enabled_module_names = params[:enabled_modules]
121 @project.enabled_module_names = params[:enabled_modules]
122 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
122 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
123 end
123 end
124
124
125 def archive
125 def archive
126 @project.archive if request.post? && @project.active?
126 @project.archive if request.post? && @project.active?
127 redirect_to :controller => 'admin', :action => 'projects'
127 redirect_to :controller => 'admin', :action => 'projects'
128 end
128 end
129
129
130 def unarchive
130 def unarchive
131 @project.unarchive if request.post? && !@project.active?
131 @project.unarchive if request.post? && !@project.active?
132 redirect_to :controller => 'admin', :action => 'projects'
132 redirect_to :controller => 'admin', :action => 'projects'
133 end
133 end
134
134
135 # Delete @project
135 # Delete @project
136 def destroy
136 def destroy
137 @project_to_destroy = @project
137 @project_to_destroy = @project
138 if request.post? and params[:confirm]
138 if request.post? and params[:confirm]
139 @project_to_destroy.destroy
139 @project_to_destroy.destroy
140 redirect_to :controller => 'admin', :action => 'projects'
140 redirect_to :controller => 'admin', :action => 'projects'
141 end
141 end
142 # hide project in layout
142 # hide project in layout
143 @project = nil
143 @project = nil
144 end
144 end
145
145
146 # Add a new issue category to @project
146 # Add a new issue category to @project
147 def add_issue_category
147 def add_issue_category
148 @category = @project.issue_categories.build(params[:category])
148 @category = @project.issue_categories.build(params[:category])
149 if request.post? and @category.save
149 if request.post? and @category.save
150 respond_to do |format|
150 respond_to do |format|
151 format.html do
151 format.html do
152 flash[:notice] = l(:notice_successful_create)
152 flash[:notice] = l(:notice_successful_create)
153 redirect_to :action => 'settings', :tab => 'categories', :id => @project
153 redirect_to :action => 'settings', :tab => 'categories', :id => @project
154 end
154 end
155 format.js do
155 format.js do
156 # IE doesn't support the replace_html rjs method for select box options
156 # IE doesn't support the replace_html rjs method for select box options
157 render(:update) {|page| page.replace "issue_category_id",
157 render(:update) {|page| page.replace "issue_category_id",
158 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
158 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
159 }
159 }
160 end
160 end
161 end
161 end
162 end
162 end
163 end
163 end
164
164
165 # Add a new version to @project
165 # Add a new version to @project
166 def add_version
166 def add_version
167 @version = @project.versions.build(params[:version])
167 @version = @project.versions.build(params[:version])
168 if request.post? and @version.save
168 if request.post? and @version.save
169 flash[:notice] = l(:notice_successful_create)
169 flash[:notice] = l(:notice_successful_create)
170 redirect_to :action => 'settings', :tab => 'versions', :id => @project
170 redirect_to :action => 'settings', :tab => 'versions', :id => @project
171 end
171 end
172 end
172 end
173
173
174 # Add a new document to @project
174 # Add a new document to @project
175 def add_document
175 def add_document
176 @categories = Enumeration::get_values('DCAT')
176 @categories = Enumeration::get_values('DCAT')
177 @document = @project.documents.build(params[:document])
177 @document = @project.documents.build(params[:document])
178 if request.post? and @document.save
178 if request.post? and @document.save
179 # Save the attachments
179 # Save the attachments
180 params[:attachments].each { |a|
180 params[:attachments].each { |a|
181 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
181 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
182 } if params[:attachments] and params[:attachments].is_a? Array
182 } if params[:attachments] and params[:attachments].is_a? Array
183 flash[:notice] = l(:notice_successful_create)
183 flash[:notice] = l(:notice_successful_create)
184 Mailer.deliver_document_add(@document) if Setting.notified_events.include?('document_added')
184 Mailer.deliver_document_add(@document) if Setting.notified_events.include?('document_added')
185 redirect_to :action => 'list_documents', :id => @project
185 redirect_to :action => 'list_documents', :id => @project
186 end
186 end
187 end
187 end
188
188
189 # Show documents list of @project
189 # Show documents list of @project
190 def list_documents
190 def list_documents
191 @documents = @project.documents.find :all, :include => :category
191 @documents = @project.documents.find :all, :include => :category
192 end
192 end
193
193
194 # Add a new issue to @project
194 # Add a new issue to @project
195 def add_issue
195 def add_issue
196 @tracker = Tracker.find(params[:tracker_id])
196 @tracker = Tracker.find(params[:tracker_id])
197 @priorities = Enumeration::get_values('IPRI')
197 @priorities = Enumeration::get_values('IPRI')
198
198
199 default_status = IssueStatus.default
199 default_status = IssueStatus.default
200 unless default_status
200 unless default_status
201 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
201 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
202 render :nothing => true, :layout => true
202 render :nothing => true, :layout => true
203 return
203 return
204 end
204 end
205 @issue = Issue.new(:project => @project, :tracker => @tracker)
205 @issue = Issue.new(:project => @project, :tracker => @tracker)
206 @issue.status = default_status
206 @issue.status = default_status
207 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
207 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
208 if request.get?
208 if request.get?
209 @issue.start_date = Date.today
209 @issue.start_date = Date.today
210 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
210 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
211 else
211 else
212 @issue.attributes = params[:issue]
212 @issue.attributes = params[:issue]
213
213
214 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
214 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
215 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
215 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
216
216
217 @issue.author_id = self.logged_in_user.id if self.logged_in_user
217 @issue.author_id = self.logged_in_user.id if self.logged_in_user
218 # Multiple file upload
218 # Multiple file upload
219 @attachments = []
219 @attachments = []
220 params[:attachments].each { |a|
220 params[:attachments].each { |a|
221 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
221 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
222 } if params[:attachments] and params[:attachments].is_a? Array
222 } if params[:attachments] and params[:attachments].is_a? Array
223 @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]) }
223 @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]) }
224 @issue.custom_values = @custom_values
224 @issue.custom_values = @custom_values
225 if @issue.save
225 if @issue.save
226 @attachments.each(&:save)
226 @attachments.each(&:save)
227 flash[:notice] = l(:notice_successful_create)
227 flash[:notice] = l(:notice_successful_create)
228 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
228 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
229 redirect_to :action => 'list_issues', :id => @project
229 redirect_to :action => 'list_issues', :id => @project
230 end
230 end
231 end
231 end
232 end
232 end
233
233
234 # Show filtered/sorted issues list of @project
234 # Show filtered/sorted issues list of @project
235 def list_issues
235 def list_issues
236 sort_init "#{Issue.table_name}.id", "desc"
236 sort_init "#{Issue.table_name}.id", "desc"
237 sort_update
237 sort_update
238
238
239 retrieve_query
239 retrieve_query
240
240
241 @results_per_page_options = [ 15, 25, 50, 100 ]
241 @results_per_page_options = [ 15, 25, 50, 100 ]
242 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
242 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
243 @results_per_page = params[:per_page].to_i
243 @results_per_page = params[:per_page].to_i
244 session[:results_per_page] = @results_per_page
244 session[:results_per_page] = @results_per_page
245 else
245 else
246 @results_per_page = session[:results_per_page] || 25
246 @results_per_page = session[:results_per_page] || 25
247 end
247 end
248
248
249 if @query.valid?
249 if @query.valid?
250 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
250 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
251 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
251 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
252 @issues = Issue.find :all, :order => sort_clause,
252 @issues = Issue.find :all, :order => sort_clause,
253 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
253 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
254 :conditions => @query.statement,
254 :conditions => @query.statement,
255 :limit => @issue_pages.items_per_page,
255 :limit => @issue_pages.items_per_page,
256 :offset => @issue_pages.current.offset
256 :offset => @issue_pages.current.offset
257 end
257 end
258
258
259 render :layout => false if request.xhr?
259 render :layout => false if request.xhr?
260 end
260 end
261
261
262 # Export filtered/sorted issues list to CSV
262 # Export filtered/sorted issues list to CSV
263 def export_issues_csv
263 def export_issues_csv
264 sort_init "#{Issue.table_name}.id", "desc"
264 sort_init "#{Issue.table_name}.id", "desc"
265 sort_update
265 sort_update
266
266
267 retrieve_query
267 retrieve_query
268 render :action => 'list_issues' and return unless @query.valid?
268 render :action => 'list_issues' and return unless @query.valid?
269
269
270 @issues = Issue.find :all, :order => sort_clause,
270 @issues = Issue.find :all, :order => sort_clause,
271 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
271 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
272 :conditions => @query.statement,
272 :conditions => @query.statement,
273 :limit => Setting.issues_export_limit.to_i
273 :limit => Setting.issues_export_limit.to_i
274
274
275 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
275 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
276 export = StringIO.new
276 export = StringIO.new
277 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
277 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
278 # csv header fields
278 # csv header fields
279 headers = [ "#", l(:field_status),
279 headers = [ "#", l(:field_status),
280 l(:field_project),
280 l(:field_project),
281 l(:field_tracker),
281 l(:field_tracker),
282 l(:field_priority),
282 l(:field_priority),
283 l(:field_subject),
283 l(:field_subject),
284 l(:field_assigned_to),
284 l(:field_assigned_to),
285 l(:field_author),
285 l(:field_author),
286 l(:field_start_date),
286 l(:field_start_date),
287 l(:field_due_date),
287 l(:field_due_date),
288 l(:field_done_ratio),
288 l(:field_done_ratio),
289 l(:field_created_on),
289 l(:field_created_on),
290 l(:field_updated_on)
290 l(:field_updated_on)
291 ]
291 ]
292 for custom_field in @project.all_custom_fields
292 for custom_field in @project.all_custom_fields
293 headers << custom_field.name
293 headers << custom_field.name
294 end
294 end
295 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
295 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
296 # csv lines
296 # csv lines
297 @issues.each do |issue|
297 @issues.each do |issue|
298 fields = [issue.id, issue.status.name,
298 fields = [issue.id, issue.status.name,
299 issue.project.name,
299 issue.project.name,
300 issue.tracker.name,
300 issue.tracker.name,
301 issue.priority.name,
301 issue.priority.name,
302 issue.subject,
302 issue.subject,
303 (issue.assigned_to ? issue.assigned_to.name : ""),
303 (issue.assigned_to ? issue.assigned_to.name : ""),
304 issue.author.name,
304 issue.author.name,
305 issue.start_date ? l_date(issue.start_date) : nil,
305 issue.start_date ? l_date(issue.start_date) : nil,
306 issue.due_date ? l_date(issue.due_date) : nil,
306 issue.due_date ? l_date(issue.due_date) : nil,
307 issue.done_ratio,
307 issue.done_ratio,
308 l_datetime(issue.created_on),
308 l_datetime(issue.created_on),
309 l_datetime(issue.updated_on)
309 l_datetime(issue.updated_on)
310 ]
310 ]
311 for custom_field in @project.all_custom_fields
311 for custom_field in @project.all_custom_fields
312 fields << (show_value issue.custom_value_for(custom_field))
312 fields << (show_value issue.custom_value_for(custom_field))
313 end
313 end
314 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
314 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
315 end
315 end
316 end
316 end
317 export.rewind
317 export.rewind
318 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
318 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
319 end
319 end
320
320
321 # Export filtered/sorted issues to PDF
321 # Export filtered/sorted issues to PDF
322 def export_issues_pdf
322 def export_issues_pdf
323 sort_init "#{Issue.table_name}.id", "desc"
323 sort_init "#{Issue.table_name}.id", "desc"
324 sort_update
324 sort_update
325
325
326 retrieve_query
326 retrieve_query
327 render :action => 'list_issues' and return unless @query.valid?
327 render :action => 'list_issues' and return unless @query.valid?
328
328
329 @issues = Issue.find :all, :order => sort_clause,
329 @issues = Issue.find :all, :order => sort_clause,
330 :include => [ :author, :status, :tracker, :priority, :project ],
330 :include => [ :author, :status, :tracker, :priority, :project ],
331 :conditions => @query.statement,
331 :conditions => @query.statement,
332 :limit => Setting.issues_export_limit.to_i
332 :limit => Setting.issues_export_limit.to_i
333
333
334 @options_for_rfpdf ||= {}
334 @options_for_rfpdf ||= {}
335 @options_for_rfpdf[:file_name] = "export.pdf"
335 @options_for_rfpdf[:file_name] = "export.pdf"
336 render :layout => false
336 render :layout => false
337 end
337 end
338
338
339 def move_issues
339 def move_issues
340 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
340 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
341 redirect_to :action => 'list_issues', :id => @project and return unless @issues
341 redirect_to :action => 'list_issues', :id => @project and return unless @issues
342 @projects = []
342 @projects = []
343 # find projects to which the user is allowed to move the issue
343 # find projects to which the user is allowed to move the issue
344 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
344 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
345 # issue can be moved to any tracker
345 # issue can be moved to any tracker
346 @trackers = Tracker.find(:all)
346 @trackers = Tracker.find(:all)
347 if request.post? and params[:new_project_id] and params[:new_tracker_id]
347 if request.post? and params[:new_project_id] and params[:new_tracker_id]
348 new_project = Project.find_by_id(params[:new_project_id])
348 new_project = Project.find_by_id(params[:new_project_id])
349 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
349 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
350 @issues.each do |i|
350 @issues.each do |i|
351 if new_project && i.project_id != new_project.id
351 if new_project && i.project_id != new_project.id
352 # issue is moved to another project
352 # issue is moved to another project
353 i.category = nil
353 i.category = nil
354 i.fixed_version = nil
354 i.fixed_version = nil
355 # delete issue relations
355 # delete issue relations
356 i.relations_from.clear
356 i.relations_from.clear
357 i.relations_to.clear
357 i.relations_to.clear
358 i.project = new_project
358 i.project = new_project
359 end
359 end
360 if new_tracker
360 if new_tracker
361 i.tracker = new_tracker
361 i.tracker = new_tracker
362 end
362 end
363 i.save
363 i.save
364 end
364 end
365 flash[:notice] = l(:notice_successful_update)
365 flash[:notice] = l(:notice_successful_update)
366 redirect_to :action => 'list_issues', :id => @project
366 redirect_to :action => 'list_issues', :id => @project
367 end
367 end
368 end
368 end
369
369
370 # Add a news to @project
370 # Add a news to @project
371 def add_news
371 def add_news
372 @news = News.new(:project => @project)
372 @news = News.new(:project => @project)
373 if request.post?
373 if request.post?
374 @news.attributes = params[:news]
374 @news.attributes = params[:news]
375 @news.author_id = self.logged_in_user.id if self.logged_in_user
375 @news.author_id = self.logged_in_user.id if self.logged_in_user
376 if @news.save
376 if @news.save
377 flash[:notice] = l(:notice_successful_create)
377 flash[:notice] = l(:notice_successful_create)
378 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
378 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
379 redirect_to :action => 'list_news', :id => @project
379 redirect_to :action => 'list_news', :id => @project
380 end
380 end
381 end
381 end
382 end
382 end
383
383
384 # Show news list of @project
384 # Show news list of @project
385 def list_news
385 def list_news
386 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
386 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
387
387
388 respond_to do |format|
388 respond_to do |format|
389 format.html { render :layout => false if request.xhr? }
389 format.html { render :layout => false if request.xhr? }
390 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
390 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
391 end
391 end
392 end
392 end
393
393
394 def add_file
394 def add_file
395 if request.post?
395 if request.post?
396 @version = @project.versions.find_by_id(params[:version_id])
396 @version = @project.versions.find_by_id(params[:version_id])
397 # Save the attachments
397 # Save the attachments
398 @attachments = []
398 @attachments = []
399 params[:attachments].each { |file|
399 params[:attachments].each { |file|
400 next unless file.size > 0
400 next unless file.size > 0
401 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
401 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
402 @attachments << a unless a.new_record?
402 @attachments << a unless a.new_record?
403 } if params[:attachments] and params[:attachments].is_a? Array
403 } if params[:attachments] and params[:attachments].is_a? Array
404 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
404 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
405 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
405 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
406 end
406 end
407 @versions = @project.versions.sort
407 @versions = @project.versions.sort
408 end
408 end
409
409
410 def list_files
410 def list_files
411 @versions = @project.versions.sort
411 @versions = @project.versions.sort
412 end
412 end
413
413
414 # Show changelog for @project
414 # Show changelog for @project
415 def changelog
415 def changelog
416 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
416 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
417 retrieve_selected_tracker_ids(@trackers)
417 retrieve_selected_tracker_ids(@trackers)
418 @versions = @project.versions.sort
418 @versions = @project.versions.sort
419 end
419 end
420
420
421 def roadmap
421 def roadmap
422 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
422 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
423 retrieve_selected_tracker_ids(@trackers)
423 retrieve_selected_tracker_ids(@trackers)
424 @versions = @project.versions.sort
424 @versions = @project.versions.sort
425 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
425 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
426 end
426 end
427
427
428 def activity
428 def activity
429 if params[:year] and params[:year].to_i > 1900
429 if params[:year] and params[:year].to_i > 1900
430 @year = params[:year].to_i
430 @year = params[:year].to_i
431 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
431 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
432 @month = params[:month].to_i
432 @month = params[:month].to_i
433 end
433 end
434 end
434 end
435 @year ||= Date.today.year
435 @year ||= Date.today.year
436 @month ||= Date.today.month
436 @month ||= Date.today.month
437
437
438 case params[:format]
438 case params[:format]
439 when 'rss'
439 when 'rss'
440 # 30 last days
440 # 30 last days
441 @date_from = Date.today - 30
441 @date_from = Date.today - 30
442 @date_to = Date.today + 1
442 @date_to = Date.today + 1
443 else
443 else
444 # current month
444 # current month
445 @date_from = Date.civil(@year, @month, 1)
445 @date_from = Date.civil(@year, @month, 1)
446 @date_to = @date_from >> 1
446 @date_to = @date_from >> 1
447 end
447 end
448
448
449 @event_types = %w(issues news files documents wiki_pages changesets)
449 @event_types = %w(issues news files documents wiki_pages changesets)
450 @event_types.delete('wiki_pages') unless @project.wiki
450 @event_types.delete('wiki_pages') unless @project.wiki
451 @event_types.delete('changesets') unless @project.repository
451 @event_types.delete('changesets') unless @project.repository
452 # only show what the user is allowed to view
452 # only show what the user is allowed to view
453 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
453 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
454
454
455 @scope = @event_types.select {|t| params["show_#{t}"]}
455 @scope = @event_types.select {|t| params["show_#{t}"]}
456 # default events if none is specified in parameters
456 # default events if none is specified in parameters
457 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
457 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
458
458
459 @events = []
459 @events = []
460
460
461 if @scope.include?('issues')
461 if @scope.include?('issues')
462 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
462 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
463 end
463 end
464
464
465 if @scope.include?('news')
465 if @scope.include?('news')
466 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
466 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
467 end
467 end
468
468
469 if @scope.include?('files')
469 if @scope.include?('files')
470 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
470 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
471 end
471 end
472
472
473 if @scope.include?('documents')
473 if @scope.include?('documents')
474 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
474 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
475 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
475 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
476 end
476 end
477
477
478 if @scope.include?('wiki_pages')
478 if @scope.include?('wiki_pages')
479 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
479 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
480 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
480 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
481 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
481 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
482 "#{WikiContent.versioned_table_name}.id"
482 "#{WikiContent.versioned_table_name}.id"
483 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
483 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
484 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
484 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
485 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
485 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
486 @project.id, @date_from, @date_to]
486 @project.id, @date_from, @date_to]
487
487
488 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
488 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
489 end
489 end
490
490
491 if @scope.include?('changesets')
491 if @scope.include?('changesets')
492 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
492 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
493 end
493 end
494
494
495 @events_by_day = @events.group_by(&:event_date)
495 @events_by_day = @events.group_by(&:event_date)
496
496
497 respond_to do |format|
497 respond_to do |format|
498 format.html { render :layout => false if request.xhr? }
498 format.html { render :layout => false if request.xhr? }
499 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
499 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
500 end
500 end
501 end
501 end
502
502
503 def calendar
503 def calendar
504 @trackers = Tracker.find(:all, :order => 'position')
504 @trackers = Tracker.find(:all, :order => 'position')
505 retrieve_selected_tracker_ids(@trackers)
505 retrieve_selected_tracker_ids(@trackers)
506
506
507 if params[:year] and params[:year].to_i > 1900
507 if params[:year] and params[:year].to_i > 1900
508 @year = params[:year].to_i
508 @year = params[:year].to_i
509 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
509 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
510 @month = params[:month].to_i
510 @month = params[:month].to_i
511 end
511 end
512 end
512 end
513 @year ||= Date.today.year
513 @year ||= Date.today.year
514 @month ||= Date.today.month
514 @month ||= Date.today.month
515
515
516 @date_from = Date.civil(@year, @month, 1)
516 @date_from = Date.civil(@year, @month, 1)
517 @date_to = (@date_from >> 1)-1
517 @date_to = (@date_from >> 1)-1
518 # start on monday
518 # start on monday
519 @date_from = @date_from - (@date_from.cwday-1)
519 @date_from = @date_from - (@date_from.cwday-1)
520 # finish on sunday
520 # finish on sunday
521 @date_to = @date_to + (7-@date_to.cwday)
521 @date_to = @date_to + (7-@date_to.cwday)
522
522
523 @events = []
523 @events = []
524 @project.issues_with_subprojects(params[:with_subprojects]) do
524 @project.issues_with_subprojects(params[:with_subprojects]) do
525 @events += Issue.find(:all,
525 @events += Issue.find(:all,
526 :include => [:tracker, :status, :assigned_to, :priority, :project],
526 :include => [:tracker, :status, :assigned_to, :priority, :project],
527 :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to]
527 :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to]
528 ) unless @selected_tracker_ids.empty?
528 ) unless @selected_tracker_ids.empty?
529 end
529 end
530 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
530 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
531
531
532 @ending_events_by_days = @events.group_by {|event| event.due_date}
532 @ending_events_by_days = @events.group_by {|event| event.due_date}
533 @starting_events_by_days = @events.group_by {|event| event.start_date}
533 @starting_events_by_days = @events.group_by {|event| event.start_date}
534
534
535 render :layout => false if request.xhr?
535 render :layout => false if request.xhr?
536 end
536 end
537
537
538 def gantt
538 def gantt
539 @trackers = Tracker.find(:all, :order => 'position')
539 @trackers = Tracker.find(:all, :order => 'position')
540 retrieve_selected_tracker_ids(@trackers)
540 retrieve_selected_tracker_ids(@trackers)
541
541
542 if params[:year] and params[:year].to_i >0
542 if params[:year] and params[:year].to_i >0
543 @year_from = params[:year].to_i
543 @year_from = params[:year].to_i
544 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
544 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
545 @month_from = params[:month].to_i
545 @month_from = params[:month].to_i
546 else
546 else
547 @month_from = 1
547 @month_from = 1
548 end
548 end
549 else
549 else
550 @month_from ||= (Date.today << 1).month
550 @month_from ||= (Date.today << 1).month
551 @year_from ||= (Date.today << 1).year
551 @year_from ||= (Date.today << 1).year
552 end
552 end
553
553
554 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
554 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
555 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
555 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
556
556
557 @date_from = Date.civil(@year_from, @month_from, 1)
557 @date_from = Date.civil(@year_from, @month_from, 1)
558 @date_to = (@date_from >> @months) - 1
558 @date_to = (@date_from >> @months) - 1
559
559
560 @events = []
560 @events = []
561 @project.issues_with_subprojects(params[:with_subprojects]) do
561 @project.issues_with_subprojects(params[:with_subprojects]) do
562 @events += Issue.find(:all,
562 @events += Issue.find(:all,
563 :order => "start_date, due_date",
563 :order => "start_date, due_date",
564 :include => [:tracker, :status, :assigned_to, :priority, :project],
564 :include => [:tracker, :status, :assigned_to, :priority, :project],
565 :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 and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
565 :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 and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
566 ) unless @selected_tracker_ids.empty?
566 ) unless @selected_tracker_ids.empty?
567 end
567 end
568 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
568 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
569 @events.sort! {|x,y| x.start_date <=> y.start_date }
569 @events.sort! {|x,y| x.start_date <=> y.start_date }
570
570
571 if params[:format]=='pdf'
571 if params[:format]=='pdf'
572 @options_for_rfpdf ||= {}
572 @options_for_rfpdf ||= {}
573 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
573 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
574 render :template => "projects/gantt.rfpdf", :layout => false
574 render :template => "projects/gantt.rfpdf", :layout => false
575 elsif params[:format]=='png' && respond_to?('gantt_image')
575 elsif params[:format]=='png' && respond_to?('gantt_image')
576 image = gantt_image(@events, @date_from, @months, @zoom)
576 image = gantt_image(@events, @date_from, @months, @zoom)
577 image.format = 'PNG'
577 image.format = 'PNG'
578 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
578 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
579 else
579 else
580 render :template => "projects/gantt.rhtml"
580 render :template => "projects/gantt.rhtml"
581 end
581 end
582 end
582 end
583
583
584 def feeds
584 def feeds
585 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
585 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
586 @key = User.current.rss_key
586 @key = User.current.rss_key
587 end
587 end
588
588
589 private
589 private
590 # Find project of id params[:id]
590 # Find project of id params[:id]
591 # if not found, redirect to project list
591 # if not found, redirect to project list
592 # Used as a before_filter
592 # Used as a before_filter
593 def find_project
593 def find_project
594 @project = Project.find(params[:id])
594 @project = Project.find(params[:id])
595 rescue ActiveRecord::RecordNotFound
595 rescue ActiveRecord::RecordNotFound
596 render_404
596 render_404
597 end
597 end
598
598
599 def retrieve_selected_tracker_ids(selectable_trackers)
599 def retrieve_selected_tracker_ids(selectable_trackers)
600 if ids = params[:tracker_ids]
600 if ids = params[:tracker_ids]
601 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
601 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
602 else
602 else
603 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
603 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
604 end
604 end
605 end
605 end
606
606
607 # Retrieve query from session or build a new query
607 # Retrieve query from session or build a new query
608 def retrieve_query
608 def retrieve_query
609 if params[:query_id]
609 if params[:query_id]
610 @query = @project.queries.find(params[:query_id])
610 @query = @project.queries.find(params[:query_id])
611 @query.executed_by = logged_in_user
611 @query.executed_by = logged_in_user
612 session[:query] = @query
612 session[:query] = @query
613 else
613 else
614 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
614 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
615 # Give it a name, required to be valid
615 # Give it a name, required to be valid
616 @query = Query.new(:name => "_", :executed_by => logged_in_user)
616 @query = Query.new(:name => "_", :executed_by => logged_in_user)
617 @query.project = @project
617 @query.project = @project
618 if params[:fields] and params[:fields].is_a? Array
618 if params[:fields] and params[:fields].is_a? Array
619 params[:fields].each do |field|
619 params[:fields].each do |field|
620 @query.add_filter(field, params[:operators][field], params[:values][field])
620 @query.add_filter(field, params[:operators][field], params[:values][field])
621 end
621 end
622 else
622 else
623 @query.available_filters.keys.each do |field|
623 @query.available_filters.keys.each do |field|
624 @query.add_short_filter(field, params[field]) if params[field]
624 @query.add_short_filter(field, params[field]) if params[field]
625 end
625 end
626 end
626 end
627 session[:query] = @query
627 session[:query] = @query
628 else
628 else
629 @query = session[:query]
629 @query = session[:query]
630 end
630 end
631 end
631 end
632 end
632 end
633 end
633 end
@@ -1,320 +1,321
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 QueryColumn
18 class QueryColumn
19 attr_accessor :name, :sortable, :default
19 attr_accessor :name, :sortable, :default
20
20
21 def initialize(name, options={})
21 def initialize(name, options={})
22 self.name = name
22 self.name = name
23 self.sortable = options[:sortable]
23 self.sortable = options[:sortable]
24 self.default = options[:default]
24 self.default = options[:default]
25 end
25 end
26
26
27 def default?; default end
27 def default?; default end
28 end
28 end
29
29
30 class Query < ActiveRecord::Base
30 class Query < ActiveRecord::Base
31 belongs_to :project
31 belongs_to :project
32 belongs_to :user
32 belongs_to :user
33 serialize :filters
33 serialize :filters
34 serialize :column_names
34 serialize :column_names
35
35
36 attr_protected :project, :user
36 attr_protected :project, :user
37 attr_accessor :executed_by
37 attr_accessor :executed_by
38
38
39 validates_presence_of :name, :on => :save
39 validates_presence_of :name, :on => :save
40 validates_length_of :name, :maximum => 255
40 validates_length_of :name, :maximum => 255
41
41
42 @@operators = { "=" => :label_equals,
42 @@operators = { "=" => :label_equals,
43 "!" => :label_not_equals,
43 "!" => :label_not_equals,
44 "o" => :label_open_issues,
44 "o" => :label_open_issues,
45 "c" => :label_closed_issues,
45 "c" => :label_closed_issues,
46 "!*" => :label_none,
46 "!*" => :label_none,
47 "*" => :label_all,
47 "*" => :label_all,
48 ">=" => '>=',
48 ">=" => '>=',
49 "<=" => '<=',
49 "<=" => '<=',
50 "<t+" => :label_in_less_than,
50 "<t+" => :label_in_less_than,
51 ">t+" => :label_in_more_than,
51 ">t+" => :label_in_more_than,
52 "t+" => :label_in,
52 "t+" => :label_in,
53 "t" => :label_today,
53 "t" => :label_today,
54 "w" => :label_this_week,
54 "w" => :label_this_week,
55 ">t-" => :label_less_than_ago,
55 ">t-" => :label_less_than_ago,
56 "<t-" => :label_more_than_ago,
56 "<t-" => :label_more_than_ago,
57 "t-" => :label_ago,
57 "t-" => :label_ago,
58 "~" => :label_contains,
58 "~" => :label_contains,
59 "!~" => :label_not_contains }
59 "!~" => :label_not_contains }
60
60
61 cattr_reader :operators
61 cattr_reader :operators
62
62
63 @@operators_by_filter_type = { :list => [ "=", "!" ],
63 @@operators_by_filter_type = { :list => [ "=", "!" ],
64 :list_status => [ "o", "=", "!", "c", "*" ],
64 :list_status => [ "o", "=", "!", "c", "*" ],
65 :list_optional => [ "=", "!", "!*", "*" ],
65 :list_optional => [ "=", "!", "!*", "*" ],
66 :list_one_or_more => [ "*", "=" ],
66 :list_one_or_more => [ "*", "=" ],
67 :date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
67 :date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
68 :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
68 :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
69 :string => [ "=", "~", "!", "!~" ],
69 :string => [ "=", "~", "!", "!~" ],
70 :text => [ "~", "!~" ],
70 :text => [ "~", "!~" ],
71 :integer => [ "=", ">=", "<=" ] }
71 :integer => [ "=", ">=", "<=" ] }
72
72
73 cattr_reader :operators_by_filter_type
73 cattr_reader :operators_by_filter_type
74
74
75 @@available_columns = [
75 @@available_columns = [
76 QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :default => true),
76 QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :default => true),
77 QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :default => true),
77 QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :default => true),
78 QueryColumn.new(:priority, :sortable => "#{Issue.table_name}.priority_id", :default => true),
78 QueryColumn.new(:priority, :sortable => "#{Issue.table_name}.priority_id", :default => true),
79 QueryColumn.new(:subject, :default => true),
79 QueryColumn.new(:subject, :default => true),
80 QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname", :default => true),
80 QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname", :default => true),
81 QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default => true),
81 QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default => true),
82 QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
82 QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
83 QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
83 QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
84 QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
84 QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
85 QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
85 QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
86 QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
86 QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
87 QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on"),
87 QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on"),
88 ]
88 ]
89 cattr_reader :available_columns
89 cattr_reader :available_columns
90
90
91 def initialize(attributes = nil)
91 def initialize(attributes = nil)
92 super attributes
92 super attributes
93 self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
93 self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
94 end
94 end
95
95
96 def executed_by=(user)
96 def executed_by=(user)
97 @executed_by = user
97 @executed_by = user
98 set_language_if_valid(user.language) if user
98 set_language_if_valid(user.language) if user
99 end
99 end
100
100
101 def validate
101 def validate
102 filters.each_key do |field|
102 filters.each_key do |field|
103 errors.add label_for(field), :activerecord_error_blank unless
103 errors.add label_for(field), :activerecord_error_blank unless
104 # filter requires one or more values
104 # filter requires one or more values
105 (values_for(field) and !values_for(field).first.empty?) or
105 (values_for(field) and !values_for(field).first.empty?) or
106 # filter doesn't require any value
106 # filter doesn't require any value
107 ["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
107 ["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
108 end if filters
108 end if filters
109 end
109 end
110
110
111 def editable_by?(user)
111 def editable_by?(user)
112 return false unless user
112 return false unless user
113 return true if !is_public && self.user_id == user.id
113 return true if !is_public && self.user_id == user.id
114 is_public && user.allowed_to?(:manage_public_queries, project)
114 is_public && user.allowed_to?(:manage_public_queries, project)
115 end
115 end
116
116
117 def available_filters
117 def available_filters
118 return @available_filters if @available_filters
118 return @available_filters if @available_filters
119 @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
119 @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
120 "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
120 "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
121 "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } },
121 "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } },
122 "subject" => { :type => :text, :order => 8 },
122 "subject" => { :type => :text, :order => 8 },
123 "created_on" => { :type => :date_past, :order => 9 },
123 "created_on" => { :type => :date_past, :order => 9 },
124 "updated_on" => { :type => :date_past, :order => 10 },
124 "updated_on" => { :type => :date_past, :order => 10 },
125 "start_date" => { :type => :date, :order => 11 },
125 "start_date" => { :type => :date, :order => 11 },
126 "due_date" => { :type => :date, :order => 12 },
126 "due_date" => { :type => :date, :order => 12 },
127 "done_ratio" => { :type => :integer, :order => 13 }}
127 "done_ratio" => { :type => :integer, :order => 13 }}
128
128
129 user_values = []
129 user_values = []
130 if project
130 if project
131 user_values += project.users.collect{|s| [s.name, s.id.to_s] }
131 user_values += project.users.collect{|s| [s.name, s.id.to_s] }
132 elsif executed_by
132 elsif executed_by
133 user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by
133 user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by
134 # members of the user's projects
134 # members of the user's projects
135 user_values += executed_by.projects.collect(&:users).flatten.uniq.sort.collect{|s| [s.name, s.id.to_s] }
135 user_values += executed_by.projects.collect(&:users).flatten.uniq.sort.collect{|s| [s.name, s.id.to_s] }
136 end
136 end
137 @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
137 @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
138 @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
138 @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
139
139
140 if project
140 if project
141 # project specific filters
141 # project specific filters
142 @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
142 @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
143 @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
143 @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
144 unless @project.active_children.empty?
144 unless @project.active_children.empty?
145 @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
145 @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
146 end
146 end
147 @project.all_custom_fields.select(&:is_filter?).each do |field|
147 @project.all_custom_fields.select(&:is_filter?).each do |field|
148 case field.field_format
148 case field.field_format
149 when "string", "int"
149 when "string", "int"
150 options = { :type => :string, :order => 20 }
150 options = { :type => :string, :order => 20 }
151 when "text"
151 when "text"
152 options = { :type => :text, :order => 20 }
152 options = { :type => :text, :order => 20 }
153 when "list"
153 when "list"
154 options = { :type => :list_optional, :values => field.possible_values, :order => 20}
154 options = { :type => :list_optional, :values => field.possible_values, :order => 20}
155 when "date"
155 when "date"
156 options = { :type => :date, :order => 20 }
156 options = { :type => :date, :order => 20 }
157 when "bool"
157 when "bool"
158 options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
158 options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
159 end
159 end
160 @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
160 @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
161 end
161 end
162 # remove category filter if no category defined
162 # remove category filter if no category defined
163 @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
163 @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
164 end
164 end
165 @available_filters
165 @available_filters
166 end
166 end
167
167
168 def add_filter(field, operator, values)
168 def add_filter(field, operator, values)
169 # values must be an array
169 # values must be an array
170 return unless values and values.is_a? Array # and !values.first.empty?
170 return unless values and values.is_a? Array # and !values.first.empty?
171 # check if field is defined as an available filter
171 # check if field is defined as an available filter
172 if available_filters.has_key? field
172 if available_filters.has_key? field
173 filter_options = available_filters[field]
173 filter_options = available_filters[field]
174 # check if operator is allowed for that filter
174 # check if operator is allowed for that filter
175 #if @@operators_by_filter_type[filter_options[:type]].include? operator
175 #if @@operators_by_filter_type[filter_options[:type]].include? operator
176 # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
176 # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
177 # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
177 # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
178 #end
178 #end
179 filters[field] = {:operator => operator, :values => values }
179 filters[field] = {:operator => operator, :values => values }
180 end
180 end
181 end
181 end
182
182
183 def add_short_filter(field, expression)
183 def add_short_filter(field, expression)
184 return unless expression
184 return unless expression
185 parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first
185 parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first
186 add_filter field, (parms[0] || "="), [parms[1] || ""]
186 add_filter field, (parms[0] || "="), [parms[1] || ""]
187 end
187 end
188
188
189 def has_filter?(field)
189 def has_filter?(field)
190 filters and filters[field]
190 filters and filters[field]
191 end
191 end
192
192
193 def operator_for(field)
193 def operator_for(field)
194 has_filter?(field) ? filters[field][:operator] : nil
194 has_filter?(field) ? filters[field][:operator] : nil
195 end
195 end
196
196
197 def values_for(field)
197 def values_for(field)
198 has_filter?(field) ? filters[field][:values] : nil
198 has_filter?(field) ? filters[field][:values] : nil
199 end
199 end
200
200
201 def label_for(field)
201 def label_for(field)
202 label = @available_filters[field][:name] if @available_filters.has_key?(field)
202 label = @available_filters[field][:name] if @available_filters.has_key?(field)
203 label ||= field.gsub(/\_id$/, "")
203 label ||= field.gsub(/\_id$/, "")
204 end
204 end
205
205
206 def available_columns
206 def available_columns
207 cols = Query.available_columns
207 cols = Query.available_columns
208 end
208 end
209
209
210 def columns
210 def columns
211 if has_default_columns?
211 if has_default_columns?
212 available_columns.select {|c| c.default? }
212 available_columns.select {|c| c.default? }
213 else
213 else
214 available_columns.select {|c| column_names.include?(c.name) }
214 # preserve the column_names order
215 column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
215 end
216 end
216 end
217 end
217
218
218 def column_names=(names)
219 def column_names=(names)
219 names = names.select {|n| n.is_a?(Symbol) || !n.blank? } if names
220 names = names.select {|n| n.is_a?(Symbol) || !n.blank? } if names
220 names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } if names
221 names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } if names
221 write_attribute(:column_names, names)
222 write_attribute(:column_names, names)
222 end
223 end
223
224
224 def has_column?(column)
225 def has_column?(column)
225 column_names && column_names.include?(column.name)
226 column_names && column_names.include?(column.name)
226 end
227 end
227
228
228 def has_default_columns?
229 def has_default_columns?
229 column_names.nil? || column_names.empty?
230 column_names.nil? || column_names.empty?
230 end
231 end
231
232
232 def statement
233 def statement
233 # project/subprojects clause
234 # project/subprojects clause
234 clause = ''
235 clause = ''
235 if project && has_filter?("subproject_id")
236 if project && has_filter?("subproject_id")
236 subproject_ids = []
237 subproject_ids = []
237 if operator_for("subproject_id") == "="
238 if operator_for("subproject_id") == "="
238 subproject_ids = values_for("subproject_id").each(&:to_i)
239 subproject_ids = values_for("subproject_id").each(&:to_i)
239 else
240 else
240 subproject_ids = project.active_children.collect{|p| p.id}
241 subproject_ids = project.active_children.collect{|p| p.id}
241 end
242 end
242 clause << "#{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
243 clause << "#{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
243 elsif project
244 elsif project
244 clause << "#{Issue.table_name}.project_id=%d" % project.id
245 clause << "#{Issue.table_name}.project_id=%d" % project.id
245 else
246 else
246 clause << Project.visible_by(executed_by)
247 clause << Project.visible_by(executed_by)
247 end
248 end
248
249
249 # filters clauses
250 # filters clauses
250 filters_clauses = []
251 filters_clauses = []
251 filters.each_key do |field|
252 filters.each_key do |field|
252 next if field == "subproject_id"
253 next if field == "subproject_id"
253 v = values_for(field).clone
254 v = values_for(field).clone
254 next unless v and !v.empty?
255 next unless v and !v.empty?
255
256
256 sql = ''
257 sql = ''
257 if field =~ /^cf_(\d+)$/
258 if field =~ /^cf_(\d+)$/
258 # custom field
259 # custom field
259 db_table = CustomValue.table_name
260 db_table = CustomValue.table_name
260 db_field = 'value'
261 db_field = 'value'
261 sql << "#{Issue.table_name}.id IN (SELECT #{db_table}.customized_id FROM #{db_table} where #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} AND "
262 sql << "#{Issue.table_name}.id IN (SELECT #{db_table}.customized_id FROM #{db_table} where #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} AND "
262 else
263 else
263 # regular field
264 # regular field
264 db_table = Issue.table_name
265 db_table = Issue.table_name
265 db_field = field
266 db_field = field
266 sql << '('
267 sql << '('
267 end
268 end
268
269
269 # "me" value subsitution
270 # "me" value subsitution
270 if %w(assigned_to_id author_id).include?(field)
271 if %w(assigned_to_id author_id).include?(field)
271 v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me")
272 v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me")
272 end
273 end
273
274
274 case operator_for field
275 case operator_for field
275 when "="
276 when "="
276 sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
277 sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
277 when "!"
278 when "!"
278 sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
279 sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
279 when "!*"
280 when "!*"
280 sql = sql + "#{db_table}.#{db_field} IS NULL"
281 sql = sql + "#{db_table}.#{db_field} IS NULL"
281 when "*"
282 when "*"
282 sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
283 sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
283 when ">="
284 when ">="
284 sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}"
285 sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}"
285 when "<="
286 when "<="
286 sql = sql + "#{db_table}.#{db_field} <= #{v.first.to_i}"
287 sql = sql + "#{db_table}.#{db_field} <= #{v.first.to_i}"
287 when "o"
288 when "o"
288 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
289 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
289 when "c"
290 when "c"
290 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
291 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
291 when ">t-"
292 when ">t-"
292 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today + 1).to_time)]
293 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today + 1).to_time)]
293 when "<t-"
294 when "<t-"
294 sql = sql + "#{db_table}.#{db_field} <= '%s'" % connection.quoted_date((Date.today - v.first.to_i).to_time)
295 sql = sql + "#{db_table}.#{db_field} <= '%s'" % connection.quoted_date((Date.today - v.first.to_i).to_time)
295 when "t-"
296 when "t-"
296 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today - v.first.to_i + 1).to_time)]
297 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today - v.first.to_i).to_time), connection.quoted_date((Date.today - v.first.to_i + 1).to_time)]
297 when ">t+"
298 when ">t+"
298 sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date((Date.today + v.first.to_i).to_time)
299 sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date((Date.today + v.first.to_i).to_time)
299 when "<t+"
300 when "<t+"
300 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
301 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
301 when "t+"
302 when "t+"
302 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today + v.first.to_i).to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
303 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date((Date.today + v.first.to_i).to_time), connection.quoted_date((Date.today + v.first.to_i + 1).to_time)]
303 when "t"
304 when "t"
304 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)]
305 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Date.today.to_time), connection.quoted_date((Date.today+1).to_time)]
305 when "w"
306 when "w"
306 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Time.now.at_beginning_of_week), connection.quoted_date(Time.now.next_week.yesterday)]
307 sql = sql + "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(Time.now.at_beginning_of_week), connection.quoted_date(Time.now.next_week.yesterday)]
307 when "~"
308 when "~"
308 sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
309 sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
309 when "!~"
310 when "!~"
310 sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
311 sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
311 end
312 end
312 sql << ')'
313 sql << ')'
313 filters_clauses << sql
314 filters_clauses << sql
314 end if filters and valid?
315 end if filters and valid?
315
316
316 clause << ' AND ' unless clause.empty?
317 clause << ' AND ' unless clause.empty?
317 clause << filters_clauses.join(' AND ') unless filters_clauses.empty?
318 clause << filters_clauses.join(' AND ') unless filters_clauses.empty?
318 clause
319 clause
319 end
320 end
320 end
321 end
@@ -1,7 +1,27
1 <% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %>
1 <% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %>
2 <legend><%= l(:field_column_names) %></legend>
2 <legend><%= l(:field_column_names) %></legend>
3 <% query.available_columns.each do |column| %>
3
4 <label><%= check_box_tag 'query[column_names][]', column.name, query.has_column?(column) %> <%= l("field_#{column.name}") %></label><br />
5 <% end %>
6 <%= hidden_field_tag 'query[column_names][]', '' %>
4 <%= hidden_field_tag 'query[column_names][]', '' %>
5 <table margin=0>
6 <tr>
7 <td><%= select_tag 'available_columns',
8 options_for_select((query.available_columns - query.columns).collect {|column| [l("field_#{column.name}"), column.name]}),
9 :multiple => true, :size => 10, :style => "width:150px" %>
10 </td>
11 <td align="center" valign="middle">
12 <input type="button" value="--&gt;"
13 onclick="moveOptions(this.form.available_columns, this.form.selected_columns);" /><br />
14 <input type="button" value="&lt;--"
15 onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
16 </td>
17 <td><%= select_tag 'query[column_names][]',
18 options_for_select(@query.columns.collect {|column| [l("field_#{column.name}"), column.name]}),
19 :id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
20 </td>
21 </tr>
22 </table>
23 <% end %>
24
25 <% content_for :header_tags do %>
26 <%= javascript_include_tag 'select_list_move' %>
7 <% end %>
27 <% end %>
@@ -1,20 +1,20
1 <%= error_messages_for 'query' %>
1 <%= error_messages_for 'query' %>
2
2
3 <div class="box">
3 <div class="box">
4 <div class="tabular">
4 <div class="tabular">
5 <p><label for="query_name"><%=l(:field_name)%></label>
5 <p><label for="query_name"><%=l(:field_name)%></label>
6 <%= text_field 'query', 'name', :size => 80 %></p>
6 <%= text_field 'query', 'name', :size => 80 %></p>
7
7
8 <% if current_role.allowed_to?(:manage_public_queries) %>
8 <% if current_role.allowed_to?(:manage_public_queries) %>
9 <p><label for="query_is_public"><%=l(:field_is_public)%></label>
9 <p><label for="query_is_public"><%=l(:field_is_public)%></label>
10 <%= check_box 'query', 'is_public' %></p>
10 <%= check_box 'query', 'is_public' %></p>
11 <% end %>
11 <% end %>
12
12
13 <p><label for="query_default_columns"><%=l(:label_default_columns)%></label>
13 <p><label for="query_default_columns"><%=l(:label_default_columns)%></label>
14 <%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns',
14 <%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns',
15 :onchange => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p>
15 :onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p>
16 </div>
16 </div>
17
17
18 <%= render :partial => 'queries/columns', :locals => {:query => query}%>
19 <%= render :partial => 'queries/filters', :locals => {:query => query}%>
18 <%= render :partial => 'queries/filters', :locals => {:query => query}%>
19 <%= render :partial => 'queries/columns', :locals => {:query => query}%>
20 </div>
20 </div>
@@ -1,6 +1,6
1 <h2><%= l(:label_query) %></h2>
1 <h2><%= l(:label_query) %></h2>
2
2
3 <% form_tag({:action => 'edit', :id => @query}) do %>
3 <% form_tag({:action => 'edit', :id => @query}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
4 <%= render :partial => 'form', :locals => {:query => @query} %>
4 <%= render :partial => 'form', :locals => {:query => @query} %>
5 <%= submit_tag l(:button_save) %>
5 <%= submit_tag l(:button_save) %>
6 <% end %>
6 <% end %>
@@ -1,6 +1,6
1 <h2><%= l(:label_query_new) %></h2>
1 <h2><%= l(:label_query_new) %></h2>
2
2
3 <% form_tag({:action => 'new', :project_id => @query.project}) do %>
3 <% form_tag({:action => 'new', :project_id => @query.project}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
4 <%= render :partial => 'form', :locals => {:query => @query} %>
4 <%= render :partial => 'form', :locals => {:query => @query} %>
5 <%= submit_tag l(:button_save) %>
5 <%= submit_tag l(:button_save) %>
6 <% end %>
6 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now