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
2019-01-01 12:11:19 +03:00
LIST_SEPARATOR = ' » ' . html_safe
2018-08-23 15:56:32 +03:00
2017-10-03 15:09:32 +03:00
class << self
2018-02-12 16:53:05 +03:00
def setup
incompatible_plugins ( %w[ redmine_tweaks
2018-02-17 13:34:26 +03:00
redmine_issue_control_panel
2018-02-12 16:53:05 +03:00
redmine_editauthor
redmine_changeauthor
2018-08-30 13:15:49 +03:00
redmine_auto_watch ] )
2018-02-12 16:53:05 +03:00
patch ( %w[ AccountController
Issue
2018-07-18 00:04:49 +03:00
IssuePriority
2018-02-12 16:53:05 +03:00
TimeEntry
2018-12-02 20:40:47 +03:00
Project
2018-02-12 16:53:05 +03:00
Wiki
WikiController
2018-12-03 12:15:50 +03:00
Principal
2018-12-02 20:40:47 +03:00
QueryFilter
Role
2018-09-12 21:42:36 +03:00
UserPreference ] )
2018-02-12 16:53:05 +03:00
Rails . configuration . assets . paths << Emoji . images_path
Redmine :: WikiFormatting . format_names . each do | format |
case format
when 'markdown'
2018-11-30 00:07:49 +03:00
Redmine :: WikiFormatting :: Markdown :: HTML . send ( :include , Patches :: FormatterMarkdownPatch )
Redmine :: WikiFormatting :: Markdown :: Helper . send ( :include , Patches :: FormattingHelperPatch )
2018-02-12 16:53:05 +03:00
when 'textile'
2018-11-30 00:07:49 +03:00
Redmine :: WikiFormatting :: Textile :: Formatter . send ( :include , Patches :: FormatterTextilePatch )
Redmine :: WikiFormatting :: Textile :: Helper . send ( :include , Patches :: FormattingHelperPatch )
2018-02-12 16:53:05 +03:00
end
end
# Static class patches
2018-07-31 17:09:40 +03:00
IssuesController . send ( :helper , AdditionalsIssuesHelper )
WikiController . send ( :helper , AdditionalsWikiPdfHelper )
2018-07-30 12:14:07 +03:00
Redmine :: AccessControl . send ( :include , Additionals :: Patches :: AccessControlPatch )
2018-02-12 16:53:05 +03:00
# Global helpers
2018-07-30 12:14:07 +03:00
ActionView :: Base . send :include , Additionals :: Helpers
2018-09-12 19:08:44 +03:00
ActionView :: Base . send :include , AdditionalsFontawesomeHelper
ActionView :: Base . send :include , AdditionalsMenuHelper
2018-02-12 16:53:05 +03:00
# Hooks
require_dependency 'additionals/hooks'
# Macros
2018-08-31 18:02:03 +03:00
load_macros ( %w[ calendar cryptocompare date fa gist gmap group_users iframe
issue redmine_issue redmine_wiki
2018-06-30 14:17:28 +03:00
last_updated_at last_updated_by meteoblue member new_issue project
recently_updated reddit slideshare tradingview twitter user vimeo youtube ] )
2018-02-12 16:53:05 +03:00
end
2017-10-03 15:09:32 +03:00
def settings
2018-12-29 23:33:57 +03:00
settings_compatible ( :plugin_additionals )
end
def settings_compatible ( plugin_name )
if Setting [ plugin_name ] . class == Hash
2018-12-29 20:12:09 +03:00
if Rails . version > = '5.2'
2018-12-29 23:33:57 +03:00
# convert Rails 4 data (this runs only once)
new_settings = ActiveSupport :: HashWithIndifferentAccess . new ( Setting [ plugin_name ] )
Setting . send ( " #{ plugin_name } = " , new_settings )
2018-12-29 20:12:09 +03:00
new_settings
else
2018-12-29 23:33:57 +03:00
ActionController :: Parameters . new ( Setting [ plugin_name ] )
2018-12-29 20:12:09 +03:00
end
2018-09-26 13:52:48 +03:00
else
2018-12-29 20:12:09 +03:00
# Rails 5 uses ActiveSupport::HashWithIndifferentAccess
2018-12-29 23:33:57 +03:00
Setting [ plugin_name ]
2018-09-26 13:52:48 +03:00
end
2017-10-03 15:09:32 +03:00
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?
2018-09-10 18:24:07 +03:00
2017-10-28 18:31:15 +03:00
false
2017-10-03 15:09:32 +03:00
end
2017-08-29 16:39:12 +03:00
2018-03-10 16:07:48 +03:00
def now_with_user_time_zone ( user = User . current )
if user . time_zone . nil?
Time . zone . now
else
user . time_zone . now
end
end
2017-10-03 15:09:32 +03:00
def incompatible_plugins ( plugins = [ ] , title = 'additionals' )
plugins . each do | plugin |
2017-12-13 09:07:18 +03:00
raise " \n \033 [31m #{ title } plugin cannot be used with #{ plugin } plugin'. \033 [0m " if Redmine :: Plugin . installed? ( plugin )
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-12-13 00:10:10 +03:00
target . send ( :include , patch ) unless target . included_modules . include? ( patch )
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
2017-07-26 12:01:51 +03:00
end
end