-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.rb
180 lines (140 loc) · 5.15 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# encoding: UTF-8
require 'redmine'
###################
# 1/ Initialisation
Rails.logger.info 'o=>'
Rails.logger.info 'o=>Starting Redmine Queries for Time Report plugin for Redmine'
Rails.logger.info "o=>Application user : #{ENV['USER']}"
plugin_name = :redmine_queries_for_time_report
plugin_root = File.dirname(__FILE__)
# lib/not_reloaded
require plugin_root + '/lib/smile_tools'
Redmine::Plugin.register plugin_name do
########################
# 2/ Plugin informations
name 'Redmine - Time Report Queries'
author 'Jérôme BATAILLE'
author_url "mailto:Jerome BATAILLE <[email protected]>?subject=#{plugin_name}"
description 'Adds Queries to Time Report like Time Entry Queries'
url "https://github.com/Smile-SA/#{plugin_name}"
version '1.0.8'
requires_redmine :version_or_higher => '3.4.6'
#######################
# 2.1/ Plugin home page
settings :default => HashWithIndifferentAccess.new(
),
:partial => "settings/#{plugin_name}"
project_module :issue_tracking do
end
end # Redmine::Plugin.register ...
#################################
# 3/ Plugin internal informations
# To keep after plugin register
this_plugin = Redmine::Plugin::find(plugin_name.to_s)
plugin_version = '?.?'
# Root relative to application root
plugin_rel_root = '.'
plugin_id = 0
if this_plugin
plugin_version = this_plugin.version
plugin_id = this_plugin.__id__
plugin_rel_root = 'plugins/' + this_plugin.id.to_s
end
###############
# 4/ Dispatcher
#Executed each time the classes are reloaded
if !defined?(rails_dispatcher)
rails_dispatcher = Rails.configuration
end
def prepend_in(dest, mixin_module)
return if dest.include? mixin_module
# Rails.logger.info "o=>#{dest}.prepend #{mixin_module}"
dest.send(:prepend, mixin_module)
end
###############
# 5/ to_prepare
# Executed after Rails initialization
rails_dispatcher.after_initialize do
Rails.logger.info "o=>"
Rails.logger.info "o=>\\__ #{plugin_name} V#{plugin_version}"
SmileTools.reset_override_count(plugin_name)
SmileTools.trace_override " plugin #{plugin_name} V#{plugin_version}",
false,
plugin_name
#########################################
# 5.1/ List of files required dynamically
# Manage dependencies
# To put here if we want recent source files reloaded
# Outside of to_prepare, file changed => reloaded,
# but with primary loaded source code
required = [
# lib/
'/lib/mypage/smile_redmine_my_page',
'/lib/helpers/smile_redmine_helpers_time_report',
'/lib/redmine/field_format/string_format',
# lib/controllers
'/lib/controllers/smile_controllers_timelog',
# lib/helpers
'/lib/helpers/smile_helpers_timelog',
'/lib/helpers/smile_helpers_my',
'/lib/helpers/smile_helpers_queries',
# lib/models
'/lib/models/smile_models_query',
]
if Rails.env == "development"
###########################
# 5.2/ Dynamic requirements
Rails.logger.debug "o=>require_dependency"
required.each{ |d|
# Reloaded each time modified
Rails.logger.debug "o=> #{plugin_rel_root + d}"
require_dependency plugin_root + d
}
required = nil
# Folders whose contents should be reloaded, NOT including sub-folders
# ActiveSupport::Dependencies.autoload_once_paths.reject!{|x| x =~ /^#{Regexp.escape(plugin_root)}/}
autoload_plugin_paths = ['/lib/controllers', '/lib/helpers', '/lib/models']
Rails.logger.debug 'o=>'
Rails.logger.debug "o=>autoload_paths / watchable_dirs +="
autoload_plugin_paths.each{|p|
new_path = plugin_root + p
Rails.logger.debug "o=> #{plugin_rel_root + p}"
ActiveSupport::Dependencies.autoload_paths << new_path
rails_dispatcher.watchable_dirs[new_path] = [:rb]
}
else
##########################
# 5.3/ Static requirements
Rails.logger.debug "o=>require"
required.each{ |p|
# Never reloaded
Rails.logger.debug "o=> #{plugin_rel_root + p}"
require plugin_root + p
}
end
# END -- Manage dependencies
##############
# 6/ Overrides
require_dependency plugin_root + '/../../lib/redmine/my_page'
prepend_in(Redmine::MyPage, Mypage::SmileRedmineMyPage::Query4TimeReport)
prepend_in(Redmine::Helpers::TimeReport,
Helpers::SmileRedmineHelpersTimeReport::HelpersOverride::TimeReportOverride::NewCriteria
)
#***************************
# **** 6.1/ Controllers ****
#Rails.logger.info "o=>----- CONTROLLERS"
prepend_in(TimelogController, Controllers::SmileControllersTimelog::TimelogOverride::Query4TimeReport)
#***********************
# **** 6.2/ Helpers ****
Rails.logger.info "o=>----- HELPERS"
prepend_in(TimelogHelper, Helpers::SmileHelpersTimelog::TimelogOverride::Query4TimeReport)
prepend_in(MyHelper, Helpers::SmileHelpersMy::MyOverride::Query4TimeReport)
prepend_in(QueriesHelper, Helpers::SmileHelpersQueries::QueriesOverride::Query4TimeReport)
#**********************
# **** 6.3/ Models ****
Rails.logger.info "o=>----- MODELS"
prepend_in(Query, Models::SmileModelsQuery::QueryOverride::Query4TimeReport)
# keep traces if classes / modules are reloaded
SmileTools.enable_traces(false, plugin_name)
Rails.logger.info 'o=>/--'
end