-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathquery_patch.rb
53 lines (40 loc) · 1.58 KB
/
query_patch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require_dependency 'query'
# Patches Redmine's Queries dynamically, adding the Deliverable
# to the available query columns
module QueryPatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
# Same as typing in the class
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
base.add_available_column(QueryColumn.new(:deliverable_subject, :sortable => "#{Deliverable.table_name}.subject"))
alias_method :redmine_available_filters, :available_filters
alias_method :available_filters, :budget_available_filters
end
end
module ClassMethods
# Setter for +available_columns+ that isn't provided by the core.
def available_columns=(v)
self.available_columns = (v)
end
# Method to add a column to the +available_columns+ that isn't provided by the core.
def add_available_column(column)
self.available_columns << (column)
end
end
module InstanceMethods
# Wrapper around the +available_filters+ to add a new Deliverable filter
def budget_available_filters
@available_filters = redmine_available_filters
if project
budget_filters = { "deliverable_id" => { :type => :list_optional, :order => 14,
:values => Deliverable.find(:all, :conditions => ["project_id IN (?)", project], :order => 'subject ASC').collect { |d| [d.subject, d.id.to_s]}
}}
else
budget_filters = { }
end
return @available_filters.merge(budget_filters)
end
end
end