2017-07-26 12:01:51 +03:00
module Additionals
MAX_CUSTOM_MENU_ITEMS = 5
2017-11-17 09:10:50 +03:00
SELECT2_INIT_ENTRIES = 20
2017-07-26 12:01:51 +03:00
2017-10-03 15:09:32 +03:00
class << self
def settings
ActionController :: Parameters . new ( Setting [ :plugin_additionals ] )
end
2017-07-26 12:01:51 +03:00
2017-10-03 15:09:32 +03:00
def setting? ( value )
2017-10-28 18:31:15 +03:00
true ? ( settings [ value ] )
end
def true? ( value )
return true if value . to_i == 1 || value . to_s . casecmp ( 'true' ) . zero?
false
2017-10-03 15:09:32 +03:00
end
2017-08-29 16:39:12 +03:00
2017-10-03 15:09:32 +03:00
def incompatible_plugins ( plugins = [ ] , title = 'additionals' )
plugins . each do | plugin |
if Redmine :: Plugin . installed? ( plugin )
raise " \n \033 [31m #{ title } plugin cannot be used with #{ plugin } plugin'. \033 [0m "
end
2017-07-13 13:05:17 +03:00
end
end
2017-07-26 12:01:51 +03:00
2017-10-03 15:09:32 +03:00
def patch ( patches = [ ] , plugin_id = 'additionals' )
patches . each do | name |
patch_dir = Rails . root . join ( 'plugins' , plugin_id , 'lib' , plugin_id , 'patches' )
require " #{ patch_dir } / #{ name . underscore } _patch "
2017-07-26 12:01:51 +03:00
2017-10-03 15:09:32 +03:00
target = name . constantize
patch = " #{ plugin_id . camelize } ::Patches:: #{ name } Patch " . constantize
2017-07-13 13:05:17 +03:00
2017-10-03 15:09:32 +03:00
unless target . included_modules . include? ( patch )
target . send ( :include , patch )
end
2017-07-26 12:01:51 +03:00
end
2017-06-07 20:23:20 +03:00
end
2017-10-03 15:09:32 +03:00
def load_macros ( macros = [ ] , plugin_id = 'additionals' )
macro_dir = Rails . root . join ( 'plugins' , plugin_id , 'lib' , plugin_id , 'wiki_macros' )
macros . each do | macro |
require_dependency " #{ macro_dir } / #{ macro . underscore } _macro "
end
2017-06-07 20:23:20 +03:00
end
2017-10-03 15:09:32 +03:00
def load_settings ( plugin_id = 'additionals' )
data = YAML . safe_load ( ERB . new ( IO . read ( Rails . root . join ( 'plugins' ,
plugin_id ,
'config' ,
'settings.yml' ) ) ) . result ) || { }
data . symbolize_keys
end
def load_fontawesome_icons
data = YAML . safe_load ( ERB . new ( IO . read ( Rails . root . join ( 'plugins' ,
'additionals' ,
'config' ,
'fontawesome_icons.yml' ) ) ) . result ) || { }
data [ 'icons' ]
end
2017-07-26 12:01:51 +03:00
end
end
if ActiveRecord :: Base . connection . table_exists? ( :settings )
Rails . configuration . to_prepare do
2017-07-26 15:17:41 +03:00
Additionals . incompatible_plugins ( %w[ redmine_tweaks common_libraries redmine_editauthor redmine_changeauthor redmine_auto_watch ] )
2017-09-27 20:42:59 +03:00
Additionals . patch ( %w[ AccountController
Issue
2017-09-15 17:51:00 +03:00
IssuesController
TimeEntry
Wiki
WikiController
2017-09-30 20:30:44 +03:00
UserPreference
2017-09-15 17:51:00 +03:00
ApplicationController ] )
2017-06-07 20:23:20 +03:00
2017-09-15 18:06:26 +03:00
Additionals . patch ( %w[ QueryFilter ] ) if Redmine :: VERSION . to_s > = '3.4'
2017-06-07 20:23:20 +03:00
Rails . configuration . assets . paths << Emoji . images_path
# Send Emoji Patches to all wiki formatters available to be able to switch formatter without app restart
Redmine :: WikiFormatting . format_names . each do | format |
case format
when 'markdown'
require_dependency 'additionals/patches/formatter_markdown_patch'
when 'textile'
require_dependency 'additionals/patches/formatter_textile_patch'
end
end
2017-07-26 12:01:51 +03:00
# Static class patches
require_dependency 'additionals/patches/wiki_pdf_helper_patch'
require_dependency 'additionals/patches/access_control_patch'
2017-06-07 20:23:20 +03:00
# Global helpers
require_dependency 'additionals/helpers'
# Hooks
require_dependency 'additionals/hooks'
2017-07-26 12:01:51 +03:00
# Macros
2017-10-28 18:31:15 +03:00
Additionals . load_macros ( %w[ calendar cryptocompare date gist gmap group_users issue last_updated_at
last_updated_by meteoblue member project recently_updated reddit slideshare
2017-09-07 14:10:28 +03:00
tradingview twitter user vimeo youtube ] )
2017-06-07 20:23:20 +03:00
end
# include deface overwrites
Rails . application . paths [ 'app/overrides' ] || = [ ]
additionals_overwrite_dir = " #{ Redmine :: Plugin . directory } /additionals/app/overrides " . freeze
unless Rails . application . paths [ 'app/overrides' ] . include? ( additionals_overwrite_dir )
Rails . application . paths [ 'app/overrides' ] << additionals_overwrite_dir
end
end