##// END OF EJS Templates
Fixed: queries with multiple custom fields return no result....
Jean-Philippe Lang -
r662:8da5bad29516
parent child
Show More
@@ -0,0 +1,22
1 ---
2 queries_001:
3 name: Multiple custom fields query
4 project_id: 1
5 filters: |
6 ---
7 cf_1:
8 :values:
9 - MySQL
10 :operator: "="
11 status_id:
12 :values:
13 - "1"
14 :operator: o
15 cf_2:
16 :values:
17 - "125"
18 :operator: "="
19
20 id: 1
21 is_public: true
22 user_id: 1
@@ -0,0 +1,31
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19
20 class QueryTest < Test::Unit::TestCase
21 fixtures :projects, :users, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
22
23 def test_query_with_multiple_custom_fields
24 query = Query.find(1)
25 assert query.valid?
26 assert query.statement.include?("custom_values.value IN ('MySQL')")
27 issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
28 assert_equal 1, issues.length
29 assert_equal Issue.find(3), issues.first
30 end
31 end
@@ -1,98 +1,98
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class FeedsController < ApplicationController
19 19 before_filter :find_scope
20 20 session :off
21 21
22 22 helper :issues
23 23 include IssuesHelper
24 24 helper :custom_fields
25 25 include CustomFieldsHelper
26 26
27 27 # news feeds
28 28 def news
29 29 News.with_scope(:find => @find_options) do
30 30 @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ]
31 31 end
32 32 headers["Content-Type"] = "application/rss+xml"
33 33 render :action => 'news_atom' if 'atom' == params[:format]
34 34 end
35 35
36 36 # issue feeds
37 37 def issues
38 38 if @project && params[:query_id]
39 39 query = Query.find(params[:query_id])
40 40 query.executed_by = @user
41 41 # ignore query if it's not valid
42 42 query = nil unless query.valid?
43 43 # override with query conditions
44 44 @find_options[:conditions] = query.statement if query.valid? and @project == query.project
45 45 end
46 46
47 47 Issue.with_scope(:find => @find_options) do
48 @issues = Issue.find :all, :include => [:project, :author, :tracker, :status, :custom_values],
48 @issues = Issue.find :all, :include => [:project, :author, :tracker, :status],
49 49 :order => "#{Issue.table_name}.created_on DESC"
50 50 end
51 51 @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues))
52 52 headers["Content-Type"] = "application/rss+xml"
53 53 render :action => 'issues_atom' if 'atom' == params[:format]
54 54 end
55 55
56 56 # issue changes feeds
57 57 def history
58 58 if @project && params[:query_id]
59 59 query = Query.find(params[:query_id])
60 60 query.executed_by = @user
61 61 # ignore query if it's not valid
62 62 query = nil unless query.valid?
63 63 # override with query conditions
64 64 @find_options[:conditions] = query.statement if query.valid? and @project == query.project
65 65 end
66 66
67 67 Journal.with_scope(:find => @find_options) do
68 @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status, :custom_values]} ],
68 @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
69 69 :order => "#{Journal.table_name}.created_on DESC"
70 70 end
71 71
72 72 @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_changes_details))
73 73 headers["Content-Type"] = "application/rss+xml"
74 74 render :action => 'history_atom' if 'atom' == params[:format]
75 75 end
76 76
77 77 private
78 78 # override for feeds specific authentication
79 79 def check_if_login_required
80 80 @user = User.find_by_rss_key(params[:key])
81 81 render(:nothing => true, :status => 403) and return false if !@user && Setting.login_required?
82 82 end
83 83
84 84 def find_scope
85 85 if params[:project_id]
86 86 # project feed
87 87 # check if project is public or if the user is a member
88 88 @project = Project.find(params[:project_id])
89 89 render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project))
90 90 scope = ["#{Project.table_name}.id=?", params[:project_id].to_i]
91 91 else
92 92 # global feed
93 93 scope = ["#{Project.table_name}.is_public=?", true]
94 94 end
95 95 @find_options = {:conditions => scope, :limit => Setting.feeds_limit.to_i}
96 96 return true
97 97 end
98 98 end
@@ -1,681 +1,681
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'csv'
19 19
20 20 class ProjectsController < ApplicationController
21 21 layout 'base'
22 22 before_filter :find_project, :except => [ :index, :list, :add ]
23 23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
24 24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
25 25
26 26 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
27 27 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
28 28 cache_sweeper :version_sweeper, :only => [ :add_version ]
29 29
30 30 helper :sort
31 31 include SortHelper
32 32 helper :custom_fields
33 33 include CustomFieldsHelper
34 34 helper :ifpdf
35 35 include IfpdfHelper
36 36 helper IssuesHelper
37 37 helper :queries
38 38 include QueriesHelper
39 39 helper :repositories
40 40 include RepositoriesHelper
41 41 include ProjectsHelper
42 42
43 43 def index
44 44 list
45 45 render :action => 'list' unless request.xhr?
46 46 end
47 47
48 48 # Lists public projects
49 49 def list
50 50 sort_init "#{Project.table_name}.name", "asc"
51 51 sort_update
52 52 @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user))
53 53 @project_pages = Paginator.new self, @project_count,
54 54 15,
55 55 params['page']
56 56 @projects = Project.find :all, :order => sort_clause,
57 57 :conditions => Project.visible_by(logged_in_user),
58 58 :include => :parent,
59 59 :limit => @project_pages.items_per_page,
60 60 :offset => @project_pages.current.offset
61 61
62 62 render :action => "list", :layout => false if request.xhr?
63 63 end
64 64
65 65 # Add a new project
66 66 def add
67 67 @custom_fields = IssueCustomField.find(:all)
68 68 @root_projects = Project.find(:all, :conditions => "parent_id is null")
69 69 @project = Project.new(params[:project])
70 70 if request.get?
71 71 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
72 72 else
73 73 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
74 74 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
75 75 @project.custom_values = @custom_values
76 76 if params[:repository_enabled] && params[:repository_enabled] == "1"
77 77 @project.repository = Repository.factory(params[:repository_scm])
78 78 @project.repository.attributes = params[:repository]
79 79 end
80 80 if "1" == params[:wiki_enabled]
81 81 @project.wiki = Wiki.new
82 82 @project.wiki.attributes = params[:wiki]
83 83 end
84 84 if @project.save
85 85 flash[:notice] = l(:notice_successful_create)
86 86 redirect_to :controller => 'admin', :action => 'projects'
87 87 end
88 88 end
89 89 end
90 90
91 91 # Show @project
92 92 def show
93 93 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
94 94 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
95 95 @subprojects = @project.active_children
96 96 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
97 97 @trackers = Tracker.find(:all, :order => 'position')
98 98 @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])
99 99 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
100 100
101 101 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
102 102 end
103 103
104 104 def settings
105 105 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
106 106 @custom_fields = IssueCustomField.find(:all)
107 107 @issue_category ||= IssueCategory.new
108 108 @member ||= @project.members.new
109 109 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
110 110 end
111 111
112 112 # Edit @project
113 113 def edit
114 114 if request.post?
115 115 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
116 116 if params[:custom_fields]
117 117 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
118 118 @project.custom_values = @custom_values
119 119 end
120 120 if params[:repository_enabled]
121 121 case params[:repository_enabled]
122 122 when "0"
123 123 @project.repository = nil
124 124 when "1"
125 125 @project.repository ||= Repository.factory(params[:repository_scm])
126 126 @project.repository.update_attributes params[:repository] if @project.repository
127 127 end
128 128 end
129 129 if params[:wiki_enabled]
130 130 case params[:wiki_enabled]
131 131 when "0"
132 132 @project.wiki.destroy if @project.wiki
133 133 when "1"
134 134 @project.wiki ||= Wiki.new
135 135 @project.wiki.update_attributes params[:wiki]
136 136 end
137 137 end
138 138 @project.attributes = params[:project]
139 139 if @project.save
140 140 flash[:notice] = l(:notice_successful_update)
141 141 redirect_to :action => 'settings', :id => @project
142 142 else
143 143 settings
144 144 render :action => 'settings'
145 145 end
146 146 end
147 147 end
148 148
149 149 def archive
150 150 @project.archive if request.post? && @project.active?
151 151 redirect_to :controller => 'admin', :action => 'projects'
152 152 end
153 153
154 154 def unarchive
155 155 @project.unarchive if request.post? && !@project.active?
156 156 redirect_to :controller => 'admin', :action => 'projects'
157 157 end
158 158
159 159 # Delete @project
160 160 def destroy
161 161 @project_to_destroy = @project
162 162 if request.post? and params[:confirm]
163 163 @project_to_destroy.destroy
164 164 redirect_to :controller => 'admin', :action => 'projects'
165 165 end
166 166 # hide project in layout
167 167 @project = nil
168 168 end
169 169
170 170 # Add a new issue category to @project
171 171 def add_issue_category
172 172 @category = @project.issue_categories.build(params[:category])
173 173 if request.post? and @category.save
174 174 respond_to do |format|
175 175 format.html do
176 176 flash[:notice] = l(:notice_successful_create)
177 177 redirect_to :action => 'settings', :tab => 'categories', :id => @project
178 178 end
179 179 format.js do
180 180 # IE doesn't support the replace_html rjs method for select box options
181 181 render(:update) {|page| page.replace "issue_category_id",
182 182 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]')
183 183 }
184 184 end
185 185 end
186 186 end
187 187 end
188 188
189 189 # Add a new version to @project
190 190 def add_version
191 191 @version = @project.versions.build(params[:version])
192 192 if request.post? and @version.save
193 193 flash[:notice] = l(:notice_successful_create)
194 194 redirect_to :action => 'settings', :tab => 'versions', :id => @project
195 195 end
196 196 end
197 197
198 198 # Add a new member to @project
199 199 def add_member
200 200 @member = @project.members.build(params[:member])
201 201 if request.post? && @member.save
202 202 respond_to do |format|
203 203 format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
204 204 format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} }
205 205 end
206 206 else
207 207 settings
208 208 render :action => 'settings'
209 209 end
210 210 end
211 211
212 212 # Show members list of @project
213 213 def list_members
214 214 @members = @project.members.find(:all)
215 215 end
216 216
217 217 # Add a new document to @project
218 218 def add_document
219 219 @categories = Enumeration::get_values('DCAT')
220 220 @document = @project.documents.build(params[:document])
221 221 if request.post? and @document.save
222 222 # Save the attachments
223 223 params[:attachments].each { |a|
224 224 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
225 225 } if params[:attachments] and params[:attachments].is_a? Array
226 226 flash[:notice] = l(:notice_successful_create)
227 227 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
228 228 redirect_to :action => 'list_documents', :id => @project
229 229 end
230 230 end
231 231
232 232 # Show documents list of @project
233 233 def list_documents
234 234 @documents = @project.documents.find :all, :include => :category
235 235 end
236 236
237 237 # Add a new issue to @project
238 238 def add_issue
239 239 @tracker = Tracker.find(params[:tracker_id])
240 240 @priorities = Enumeration::get_values('IPRI')
241 241
242 242 default_status = IssueStatus.default
243 243 unless default_status
244 244 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
245 245 render :nothing => true, :layout => true
246 246 return
247 247 end
248 248 @issue = Issue.new(:project => @project, :tracker => @tracker)
249 249 @issue.status = default_status
250 250 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
251 251 if request.get?
252 252 @issue.start_date = Date.today
253 253 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
254 254 else
255 255 @issue.attributes = params[:issue]
256 256
257 257 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
258 258 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
259 259
260 260 @issue.author_id = self.logged_in_user.id if self.logged_in_user
261 261 # Multiple file upload
262 262 @attachments = []
263 263 params[:attachments].each { |a|
264 264 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
265 265 } if params[:attachments] and params[:attachments].is_a? Array
266 266 @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]) }
267 267 @issue.custom_values = @custom_values
268 268 if @issue.save
269 269 @attachments.each(&:save)
270 270 flash[:notice] = l(:notice_successful_create)
271 271 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
272 272 redirect_to :action => 'list_issues', :id => @project
273 273 end
274 274 end
275 275 end
276 276
277 277 # Show filtered/sorted issues list of @project
278 278 def list_issues
279 279 sort_init "#{Issue.table_name}.id", "desc"
280 280 sort_update
281 281
282 282 retrieve_query
283 283
284 284 @results_per_page_options = [ 15, 25, 50, 100 ]
285 285 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
286 286 @results_per_page = params[:per_page].to_i
287 287 session[:results_per_page] = @results_per_page
288 288 else
289 289 @results_per_page = session[:results_per_page] || 25
290 290 end
291 291
292 292 if @query.valid?
293 @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement)
293 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
294 294 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
295 295 @issues = Issue.find :all, :order => sort_clause,
296 :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ],
296 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
297 297 :conditions => @query.statement,
298 298 :limit => @issue_pages.items_per_page,
299 299 :offset => @issue_pages.current.offset
300 300 end
301 301 render :layout => false if request.xhr?
302 302 end
303 303
304 304 # Export filtered/sorted issues list to CSV
305 305 def export_issues_csv
306 306 sort_init "#{Issue.table_name}.id", "desc"
307 307 sort_update
308 308
309 309 retrieve_query
310 310 render :action => 'list_issues' and return unless @query.valid?
311 311
312 312 @issues = Issue.find :all, :order => sort_clause,
313 313 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
314 314 :conditions => @query.statement,
315 315 :limit => Setting.issues_export_limit.to_i
316 316
317 317 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
318 318 export = StringIO.new
319 319 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
320 320 # csv header fields
321 321 headers = [ "#", l(:field_status),
322 322 l(:field_project),
323 323 l(:field_tracker),
324 324 l(:field_priority),
325 325 l(:field_subject),
326 326 l(:field_assigned_to),
327 327 l(:field_author),
328 328 l(:field_start_date),
329 329 l(:field_due_date),
330 330 l(:field_done_ratio),
331 331 l(:field_created_on),
332 332 l(:field_updated_on)
333 333 ]
334 334 for custom_field in @project.all_custom_fields
335 335 headers << custom_field.name
336 336 end
337 337 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
338 338 # csv lines
339 339 @issues.each do |issue|
340 340 fields = [issue.id, issue.status.name,
341 341 issue.project.name,
342 342 issue.tracker.name,
343 343 issue.priority.name,
344 344 issue.subject,
345 345 (issue.assigned_to ? issue.assigned_to.name : ""),
346 346 issue.author.name,
347 347 issue.start_date ? l_date(issue.start_date) : nil,
348 348 issue.due_date ? l_date(issue.due_date) : nil,
349 349 issue.done_ratio,
350 350 l_datetime(issue.created_on),
351 351 l_datetime(issue.updated_on)
352 352 ]
353 353 for custom_field in @project.all_custom_fields
354 354 fields << (show_value issue.custom_value_for(custom_field))
355 355 end
356 356 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
357 357 end
358 358 end
359 359 export.rewind
360 360 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
361 361 end
362 362
363 363 # Export filtered/sorted issues to PDF
364 364 def export_issues_pdf
365 365 sort_init "#{Issue.table_name}.id", "desc"
366 366 sort_update
367 367
368 368 retrieve_query
369 369 render :action => 'list_issues' and return unless @query.valid?
370 370
371 371 @issues = Issue.find :all, :order => sort_clause,
372 :include => [ :author, :status, :tracker, :priority, :project, :custom_values ],
372 :include => [ :author, :status, :tracker, :priority, :project ],
373 373 :conditions => @query.statement,
374 374 :limit => Setting.issues_export_limit.to_i
375 375
376 376 @options_for_rfpdf ||= {}
377 377 @options_for_rfpdf[:file_name] = "export.pdf"
378 378 render :layout => false
379 379 end
380 380
381 381 def move_issues
382 382 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
383 383 redirect_to :action => 'list_issues', :id => @project and return unless @issues
384 384 @projects = []
385 385 # find projects to which the user is allowed to move the issue
386 386 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)}
387 387 # issue can be moved to any tracker
388 388 @trackers = Tracker.find(:all)
389 389 if request.post? and params[:new_project_id] and params[:new_tracker_id]
390 390 new_project = Project.find(params[:new_project_id])
391 391 new_tracker = Tracker.find(params[:new_tracker_id])
392 392 @issues.each { |i|
393 393 # project dependent properties
394 394 unless i.project_id == new_project.id
395 395 i.category = nil
396 396 i.fixed_version = nil
397 397 # delete issue relations
398 398 i.relations_from.clear
399 399 i.relations_to.clear
400 400 end
401 401 # move the issue
402 402 i.project = new_project
403 403 i.tracker = new_tracker
404 404 i.save
405 405 }
406 406 flash[:notice] = l(:notice_successful_update)
407 407 redirect_to :action => 'list_issues', :id => @project
408 408 end
409 409 end
410 410
411 411 # Add a news to @project
412 412 def add_news
413 413 @news = News.new(:project => @project)
414 414 if request.post?
415 415 @news.attributes = params[:news]
416 416 @news.author_id = self.logged_in_user.id if self.logged_in_user
417 417 if @news.save
418 418 flash[:notice] = l(:notice_successful_create)
419 419 redirect_to :action => 'list_news', :id => @project
420 420 end
421 421 end
422 422 end
423 423
424 424 # Show news list of @project
425 425 def list_news
426 426 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
427 427 render :action => "list_news", :layout => false if request.xhr?
428 428 end
429 429
430 430 def add_file
431 431 if request.post?
432 432 @version = @project.versions.find_by_id(params[:version_id])
433 433 # Save the attachments
434 434 @attachments = []
435 435 params[:attachments].each { |file|
436 436 next unless file.size > 0
437 437 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
438 438 @attachments << a unless a.new_record?
439 439 } if params[:attachments] and params[:attachments].is_a? Array
440 440 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
441 441 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
442 442 end
443 443 @versions = @project.versions.sort
444 444 end
445 445
446 446 def list_files
447 447 @versions = @project.versions.sort
448 448 end
449 449
450 450 # Show changelog for @project
451 451 def changelog
452 452 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
453 453 retrieve_selected_tracker_ids(@trackers)
454 454 @versions = @project.versions.sort
455 455 end
456 456
457 457 def roadmap
458 458 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
459 459 retrieve_selected_tracker_ids(@trackers)
460 460 @versions = @project.versions.sort
461 461 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
462 462 end
463 463
464 464 def activity
465 465 if params[:year] and params[:year].to_i > 1900
466 466 @year = params[:year].to_i
467 467 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
468 468 @month = params[:month].to_i
469 469 end
470 470 end
471 471 @year ||= Date.today.year
472 472 @month ||= Date.today.month
473 473
474 474 @date_from = Date.civil(@year, @month, 1)
475 475 @date_to = @date_from >> 1
476 476
477 477 @events_by_day = Hash.new { |h,k| h[k] = [] }
478 478
479 479 unless params[:show_issues] == "0"
480 480 @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i|
481 481 @events_by_day[i.created_on.to_date] << i
482 482 }
483 483 @project.issue_changes.find(:all, :include => :details, :conditions => ["(#{Journal.table_name}.created_on BETWEEN ? AND ?) AND (#{JournalDetail.table_name}.prop_key = 'status_id')", @date_from, @date_to] ).each { |i|
484 484 @events_by_day[i.created_on.to_date] << i
485 485 }
486 486 @show_issues = 1
487 487 end
488 488
489 489 unless params[:show_news] == "0"
490 490 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to], :include => :author ).each { |i|
491 491 @events_by_day[i.created_on.to_date] << i
492 492 }
493 493 @show_news = 1
494 494 end
495 495
496 496 unless params[:show_files] == "0"
497 497 Attachment.find(:all, :select => "#{Attachment.table_name}.*",
498 498 :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id",
499 499 :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to],
500 500 :include => :author ).each { |i|
501 501 @events_by_day[i.created_on.to_date] << i
502 502 }
503 503 @show_files = 1
504 504 end
505 505
506 506 unless params[:show_documents] == "0"
507 507 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i|
508 508 @events_by_day[i.created_on.to_date] << i
509 509 }
510 510 Attachment.find(:all, :select => "attachments.*",
511 511 :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id",
512 512 :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to],
513 513 :include => :author ).each { |i|
514 514 @events_by_day[i.created_on.to_date] << i
515 515 }
516 516 @show_documents = 1
517 517 end
518 518
519 519 unless @project.wiki.nil? || params[:show_wiki_edits] == "0"
520 520 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
521 521 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
522 522 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
523 523 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
524 524 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
525 525 @project.id, @date_from, @date_to]
526 526
527 527 WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
528 528 # We provide this alias so all events can be treated in the same manner
529 529 def i.created_on
530 530 self.updated_on
531 531 end
532 532 @events_by_day[i.created_on.to_date] << i
533 533 }
534 534 @show_wiki_edits = 1
535 535 end
536 536
537 537 unless @project.repository.nil? || params[:show_changesets] == "0"
538 538 @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
539 539 def i.created_on
540 540 self.committed_on
541 541 end
542 542 @events_by_day[i.created_on.to_date] << i
543 543 }
544 544 @show_changesets = 1
545 545 end
546 546
547 547 render :layout => false if request.xhr?
548 548 end
549 549
550 550 def calendar
551 551 @trackers = Tracker.find(:all, :order => 'position')
552 552 retrieve_selected_tracker_ids(@trackers)
553 553
554 554 if params[:year] and params[:year].to_i > 1900
555 555 @year = params[:year].to_i
556 556 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
557 557 @month = params[:month].to_i
558 558 end
559 559 end
560 560 @year ||= Date.today.year
561 561 @month ||= Date.today.month
562 562
563 563 @date_from = Date.civil(@year, @month, 1)
564 564 @date_to = (@date_from >> 1)-1
565 565 # start on monday
566 566 @date_from = @date_from - (@date_from.cwday-1)
567 567 # finish on sunday
568 568 @date_to = @date_to + (7-@date_to.cwday)
569 569
570 570 @events = []
571 571 @project.issues_with_subprojects(params[:with_subprojects]) do
572 572 @events += Issue.find(:all,
573 573 :include => [:tracker, :status, :assigned_to, :priority, :project],
574 574 :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]
575 575 ) unless @selected_tracker_ids.empty?
576 576 end
577 577 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
578 578
579 579 @ending_events_by_days = @events.group_by {|event| event.due_date}
580 580 @starting_events_by_days = @events.group_by {|event| event.start_date}
581 581
582 582 render :layout => false if request.xhr?
583 583 end
584 584
585 585 def gantt
586 586 @trackers = Tracker.find(:all, :order => 'position')
587 587 retrieve_selected_tracker_ids(@trackers)
588 588
589 589 if params[:year] and params[:year].to_i >0
590 590 @year_from = params[:year].to_i
591 591 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
592 592 @month_from = params[:month].to_i
593 593 else
594 594 @month_from = 1
595 595 end
596 596 else
597 597 @month_from ||= (Date.today << 1).month
598 598 @year_from ||= (Date.today << 1).year
599 599 end
600 600
601 601 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
602 602 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
603 603
604 604 @date_from = Date.civil(@year_from, @month_from, 1)
605 605 @date_to = (@date_from >> @months) - 1
606 606
607 607 @events = []
608 608 @project.issues_with_subprojects(params[:with_subprojects]) do
609 609 @events += Issue.find(:all,
610 610 :order => "start_date, due_date",
611 611 :include => [:tracker, :status, :assigned_to, :priority, :project],
612 612 :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]
613 613 ) unless @selected_tracker_ids.empty?
614 614 end
615 615 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
616 616 @events.sort! {|x,y| x.start_date <=> y.start_date }
617 617
618 618 if params[:format]=='pdf'
619 619 @options_for_rfpdf ||= {}
620 620 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
621 621 render :template => "projects/gantt.rfpdf", :layout => false
622 622 elsif params[:format]=='png' && respond_to?('gantt_image')
623 623 image = gantt_image(@events, @date_from, @months, @zoom)
624 624 image.format = 'PNG'
625 625 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
626 626 else
627 627 render :template => "projects/gantt.rhtml"
628 628 end
629 629 end
630 630
631 631 def feeds
632 632 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
633 633 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
634 634 end
635 635
636 636 private
637 637 # Find project of id params[:id]
638 638 # if not found, redirect to project list
639 639 # Used as a before_filter
640 640 def find_project
641 641 @project = Project.find(params[:id])
642 642 @html_title = @project.name
643 643 rescue ActiveRecord::RecordNotFound
644 644 render_404
645 645 end
646 646
647 647 def retrieve_selected_tracker_ids(selectable_trackers)
648 648 if ids = params[:tracker_ids]
649 649 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
650 650 else
651 651 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
652 652 end
653 653 end
654 654
655 655 # Retrieve query from session or build a new query
656 656 def retrieve_query
657 657 if params[:query_id]
658 658 @query = @project.queries.find(params[:query_id])
659 659 @query.executed_by = logged_in_user
660 660 session[:query] = @query
661 661 else
662 662 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
663 663 # Give it a name, required to be valid
664 664 @query = Query.new(:name => "_", :executed_by => logged_in_user)
665 665 @query.project = @project
666 666 if params[:fields] and params[:fields].is_a? Array
667 667 params[:fields].each do |field|
668 668 @query.add_filter(field, params[:operators][field], params[:values][field])
669 669 end
670 670 else
671 671 @query.available_filters.keys.each do |field|
672 672 @query.add_short_filter(field, params[field]) if params[field]
673 673 end
674 674 end
675 675 session[:query] = @query
676 676 else
677 677 @query = session[:query]
678 678 end
679 679 end
680 680 end
681 681 end
@@ -1,240 +1,245
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Query < ActiveRecord::Base
19 19 belongs_to :project
20 20 belongs_to :user
21 21 serialize :filters
22 22
23 23 attr_protected :project, :user
24 24 attr_accessor :executed_by
25 25
26 26 validates_presence_of :name, :on => :save
27 27 validates_length_of :name, :maximum => 255
28 28
29 29 @@operators = { "=" => :label_equals,
30 30 "!" => :label_not_equals,
31 31 "o" => :label_open_issues,
32 32 "c" => :label_closed_issues,
33 33 "!*" => :label_none,
34 34 "*" => :label_all,
35 35 "<t+" => :label_in_less_than,
36 36 ">t+" => :label_in_more_than,
37 37 "t+" => :label_in,
38 38 "t" => :label_today,
39 39 ">t-" => :label_less_than_ago,
40 40 "<t-" => :label_more_than_ago,
41 41 "t-" => :label_ago,
42 42 "~" => :label_contains,
43 43 "!~" => :label_not_contains }
44 44
45 45 cattr_reader :operators
46 46
47 47 @@operators_by_filter_type = { :list => [ "=", "!" ],
48 48 :list_status => [ "o", "=", "!", "c", "*" ],
49 49 :list_optional => [ "=", "!", "!*", "*" ],
50 50 :list_one_or_more => [ "*", "=" ],
51 51 :date => [ "<t+", ">t+", "t+", "t", ">t-", "<t-", "t-" ],
52 52 :date_past => [ ">t-", "<t-", "t-", "t" ],
53 53 :string => [ "=", "~", "!", "!~" ],
54 54 :text => [ "~", "!~" ] }
55 55
56 56 cattr_reader :operators_by_filter_type
57 57
58 58 def initialize(attributes = nil)
59 59 super attributes
60 60 self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
61 61 end
62 62
63 63 def executed_by=(user)
64 64 @executed_by = user
65 65 set_language_if_valid(user.language) if user
66 66 end
67 67
68 68 def validate
69 69 filters.each_key do |field|
70 70 errors.add label_for(field), :activerecord_error_blank unless
71 71 # filter requires one or more values
72 72 (values_for(field) and !values_for(field).first.empty?) or
73 73 # filter doesn't require any value
74 74 ["o", "c", "!*", "*", "t"].include? operator_for(field)
75 75 end if filters
76 76 end
77 77
78 78 def editable_by?(user)
79 79 return false unless user
80 80 return true if !is_public && self.user_id == user.id
81 81 is_public && user.authorized_to(project, "projects/add_query")
82 82 end
83 83
84 84 def available_filters
85 85 return @available_filters if @available_filters
86 86 @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
87 87 "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
88 88 "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } },
89 89 "subject" => { :type => :text, :order => 8 },
90 90 "created_on" => { :type => :date_past, :order => 9 },
91 91 "updated_on" => { :type => :date_past, :order => 10 },
92 92 "start_date" => { :type => :date, :order => 11 },
93 93 "due_date" => { :type => :date, :order => 12 } }
94 94 unless project.nil?
95 95 # project specific filters
96 96 user_values = []
97 97 user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by
98 98 user_values += @project.users.collect{|s| [s.name, s.id.to_s] }
99 99
100 100 @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values }
101 101 @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values }
102 102 @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
103 103 @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
104 104 unless @project.active_children.empty?
105 105 @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
106 106 end
107 107 @project.all_custom_fields.select(&:is_filter?).each do |field|
108 108 case field.field_format
109 109 when "string", "int"
110 110 options = { :type => :string, :order => 20 }
111 111 when "text"
112 112 options = { :type => :text, :order => 20 }
113 113 when "list"
114 114 options = { :type => :list_optional, :values => field.possible_values, :order => 20}
115 115 when "date"
116 116 options = { :type => :date, :order => 20 }
117 117 when "bool"
118 118 options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
119 119 end
120 120 @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
121 121 end
122 122 # remove category filter if no category defined
123 123 @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
124 124 end
125 125 @available_filters
126 126 end
127 127
128 128 def add_filter(field, operator, values)
129 129 # values must be an array
130 130 return unless values and values.is_a? Array # and !values.first.empty?
131 131 # check if field is defined as an available filter
132 132 if available_filters.has_key? field
133 133 filter_options = available_filters[field]
134 134 # check if operator is allowed for that filter
135 135 #if @@operators_by_filter_type[filter_options[:type]].include? operator
136 136 # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
137 137 # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
138 138 #end
139 139 filters[field] = {:operator => operator, :values => values }
140 140 end
141 141 end
142 142
143 143 def add_short_filter(field, expression)
144 144 return unless expression
145 145 parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first
146 146 add_filter field, (parms[0] || "="), [parms[1] || ""]
147 147 end
148 148
149 149 def has_filter?(field)
150 150 filters and filters[field]
151 151 end
152 152
153 153 def operator_for(field)
154 154 has_filter?(field) ? filters[field][:operator] : nil
155 155 end
156 156
157 157 def values_for(field)
158 158 has_filter?(field) ? filters[field][:values] : nil
159 159 end
160 160
161 161 def label_for(field)
162 162 label = @available_filters[field][:name] if @available_filters.has_key?(field)
163 163 label ||= field.gsub(/\_id$/, "")
164 164 end
165 165
166 166 def statement
167 sql = "1=1"
167 # project/subprojects clause
168 clause = ''
168 169 if has_filter?("subproject_id")
169 170 subproject_ids = []
170 171 if operator_for("subproject_id") == "="
171 172 subproject_ids = values_for("subproject_id").each(&:to_i)
172 173 else
173 174 subproject_ids = project.active_children.collect{|p| p.id}
174 175 end
175 sql << " AND #{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
176 clause << "#{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
176 177 else
177 sql << " AND #{Issue.table_name}.project_id=%d" % project.id if project
178 clause << "#{Issue.table_name}.project_id=%d" % project.id if project
178 179 end
180
181 # filters clauses
182 filters_clauses = []
179 183 filters.each_key do |field|
180 184 next if field == "subproject_id"
181 185 v = values_for(field).clone
182 186 next unless v and !v.empty?
183
184 sql = sql + " AND " unless sql.empty?
185 sql << "("
186
187
188 sql = ''
187 189 if field =~ /^cf_(\d+)$/
188 190 # custom field
189 191 db_table = CustomValue.table_name
190 db_field = "value"
191 sql << "#{db_table}.custom_field_id = #{$1} AND "
192 db_field = 'value'
193 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 "
192 194 else
193 195 # regular field
194 196 db_table = Issue.table_name
195 197 db_field = field
198 sql << '('
196 199 end
197 200
198 201 # "me" value subsitution
199 202 if %w(assigned_to_id author_id).include?(field)
200 203 v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me")
201 204 end
202 205
203 206 case operator_for field
204 207 when "="
205 208 sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
206 209 when "!"
207 210 sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
208 211 when "!*"
209 212 sql = sql + "#{db_table}.#{db_field} IS NULL"
210 213 when "*"
211 214 sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
212 215 when "o"
213 216 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
214 217 when "c"
215 218 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
216 219 when ">t-"
217 220 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)]
218 221 when "<t-"
219 222 sql = sql + "#{db_table}.#{db_field} <= '%s'" % connection.quoted_date((Date.today - v.first.to_i).to_time)
220 223 when "t-"
221 224 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)]
222 225 when ">t+"
223 226 sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date((Date.today + v.first.to_i).to_time)
224 227 when "<t+"
225 228 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)]
226 229 when "t+"
227 230 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)]
228 231 when "t"
229 232 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)]
230 233 when "~"
231 234 sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
232 235 when "!~"
233 236 sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
234 237 end
235 sql << ")"
236
238 sql << ')'
239 filters_clauses << sql
237 240 end if filters and valid?
238 sql
241
242 clause << (' AND ' + filters_clauses.join(' AND ')) unless filters_clauses.empty?
243 clause
239 244 end
240 245 end
@@ -1,43 +1,49
1 1 ---
2 2 custom_values_006:
3 3 customized_type: Issue
4 4 custom_field_id: 2
5 5 customized_id: 3
6 6 id: 9
7 7 value: "125"
8 8 custom_values_007:
9 9 customized_type: Project
10 10 custom_field_id: 3
11 11 customized_id: 1
12 12 id: 10
13 13 value: Stable
14 14 custom_values_001:
15 15 customized_type: User
16 16 custom_field_id: 4
17 17 customized_id: 3
18 18 id: 2
19 19 value: ""
20 20 custom_values_002:
21 21 customized_type: User
22 22 custom_field_id: 4
23 23 customized_id: 4
24 24 id: 3
25 25 value: 01 23 45 67 89
26 26 custom_values_003:
27 27 customized_type: User
28 28 custom_field_id: 4
29 29 customized_id: 2
30 30 id: 4
31 31 value: ""
32 32 custom_values_004:
33 33 customized_type: Issue
34 34 custom_field_id: 2
35 35 customized_id: 1
36 36 id: 7
37 value: "101"
37 value: "125"
38 38 custom_values_005:
39 39 customized_type: Issue
40 40 custom_field_id: 2
41 41 customized_id: 2
42 42 id: 8
43 43 value: ""
44 custom_values_008:
45 customized_type: Issue
46 custom_field_id: 1
47 customized_id: 3
48 id: 11
49 value: "MySQL" No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now