-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.rb
140 lines (121 loc) · 5.72 KB
/
init.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require 'redmine'
require_dependency 'extended_fields_hook'
Rails.logger.info 'Starting Extended Fields plugin for Redmine'
unless defined?(Redmine::CustomFieldFormat)
require_dependency 'extended_field_format'
end
if defined?(Redmine::CustomFieldFormat)
Redmine::CustomFieldFormat.map do |fields|
if Redmine::VERSION::MAJOR < 2 || defined?(ChiliProject)
base_order = 2
else
base_order = 1
end
fields.register WikiCustomFieldFormat.new('wiki', :label => :label_wiki_text, :order => base_order + 0.1)
fields.register LinkCustomFieldFormat.new('link', :label => :label_link, :order => base_order + 0.2)
fields.register ProjectCustomFieldFormat.new('project', :label => :label_project, :order => base_order + 6)
end
end
issue_query = (IssueQuery rescue Query)
issue_query.add_available_column(ExtendedQueryColumn.new(:notes,
:value => lambda { |issue| issue.journals.select{ |journal| journal.notes.present? }.size }))
issue_query.add_available_column(ExtendedQueryColumn.new(:changes,
:caption => :label_change_plural,
:value => lambda { |issue| issue.journals.select{ |journal| journal.details.any? }.size }))
issue_query.add_available_column(ExtendedQueryColumn.new(:watchers,
:caption => :label_issue_watchers,
:value => lambda { |issue| issue.watchers.size }))
Rails.configuration.to_prepare do
unless String.method_defined?(:html_safe)
String.send(:include, ExtendedStringHTMLSafePatch)
end
unless ActionView::Base.included_modules.include?(ExtendedFieldsHelper)
ActionView::Base.send(:include, ExtendedFieldsHelper)
end
unless defined? ActiveSupport::SafeBuffer
unless ActionView::Base.included_modules.include?(ExtendedHTMLEscapePatch)
ActionView::Base.send(:include, ExtendedHTMLEscapePatch)
end
end
unless AdminController.included_modules.include?(ExtendedAdminControllerPatch)
AdminController.send(:include, ExtendedAdminControllerPatch)
end
unless UsersController.included_modules.include?(ExtendedUsersControllerPatch)
UsersController.send(:include, ExtendedUsersControllerPatch)
end
unless IssuesController.included_modules.include?(ExtendedIssuesControllerPatch)
IssuesController.send(:include, ExtendedIssuesControllerPatch)
end
if ActiveRecord::Base.connection.adapter_name =~ %r{mysql}i
unless CalendarsController.included_modules.include?(ExtendedCalendarsControllerPatch)
CalendarsController.send(:include, ExtendedCalendarsControllerPatch)
end
end
if Redmine::VERSION::MAJOR == 2 && Redmine::VERSION::MINOR < 5
unless ApplicationHelper.included_modules.include?(ExtendedApplicationHelperPatch)
ApplicationHelper.send(:include, ExtendedApplicationHelperPatch)
end
end
unless QueriesHelper.included_modules.include?(ExtendedQueriesHelperPatch)
QueriesHelper.send(:include, ExtendedQueriesHelperPatch)
end
unless CustomFieldsHelper.included_modules.include?(ExtendedFieldsHelperPatch)
CustomFieldsHelper.send(:include, ExtendedFieldsHelperPatch)
end
if defined?(Redmine::CustomFieldFormat)
unless CustomField.included_modules.include?(ExtendedCustomFieldPatch)
CustomField.send(:include, ExtendedCustomFieldPatch)
end
end
begin
unless CustomFieldValue.included_modules.include?(ExtendedCustomFieldValuePatch)
CustomFieldValue.send(:include, ExtendedCustomFieldValuePatch)
end
rescue NameError
end
unless CustomValue.included_modules.include?(ExtendedCustomValuePatch)
CustomValue.send(:include, ExtendedCustomValuePatch)
end
if defined?(Redmine::CustomFieldFormat)
unless Query.included_modules.include?(ExtendedCustomQueryPatch)
Query.send(:include, ExtendedCustomQueryPatch)
end
end
unless Project.included_modules.include?(ExtendedProjectPatch)
Project.send(:include, ExtendedProjectPatch)
end
unless User.included_modules.include?(ExtendedUserPatch)
User.send(:include, ExtendedUserPatch)
end
unless AdminController.included_modules.include?(CustomFieldsHelper)
AdminController.send(:helper, :custom_fields)
AdminController.send(:include, CustomFieldsHelper)
end
unless WikiController.included_modules.include?(CustomFieldsHelper)
WikiController.send(:helper, :custom_fields)
WikiController.send(:include, CustomFieldsHelper)
end
if defined? ActionView::OptimizedFileSystemResolver
unless ActionView::OptimizedFileSystemResolver.method_defined?(:[])
ActionView::OptimizedFileSystemResolver.send(:include, ExtendedFileSystemResolverPatch)
end
end
if CustomField.method_defined?(:format_in?)
unless CustomField.included_modules.include?(ExtendedFormatInPatch)
CustomField.send(:include, ExtendedFormatInPatch)
end
end
if defined? XlsExportController
unless XlsExportController.included_modules.include?(ExtendedFieldsHelper)
XlsExportController.send(:include, ExtendedFieldsHelper)
end
end
end
Redmine::Plugin.register :extended_fields do
name 'Extended fields'
author 'Andriy Lesyuk'
author_url 'http://www.andriylesyuk.com'
description 'Adds new custom field types, improves listings etc.'
url 'http://projects.andriylesyuk.com/projects/extended-fields'
version '0.2.3'
end