2021-04-18 14:34:55 +03:00
# frozen_string_literal: true
2018-09-12 17:04:39 +03:00
module AdditionalsMenuHelper
2018-09-12 21:42:36 +03:00
def additionals_top_menu_setup
2021-09-20 13:44:10 +03:00
return if AdditionalsPlugin . active_hrm?
2018-09-12 21:42:36 +03:00
2020-08-06 09:18:30 +03:00
if Additionals . setting? :remove_help
2018-09-12 21:42:36 +03:00
Redmine :: MenuManager . map ( :top_menu ) . delete ( :help ) if Redmine :: MenuManager . map ( :top_menu ) . exists? ( :help )
2018-09-14 13:37:05 +03:00
elsif User . current . logged?
2020-09-02 14:19:59 +03:00
handle_top_submenu_item :help , url : '#' , symbol : 'fas_question' , last : true
2018-09-12 21:42:36 +03:00
@additionals_help_items = additionals_help_menu_items
2018-09-14 13:37:05 +03:00
else
2020-09-02 14:19:59 +03:00
handle_top_menu_item :help , url : Redmine :: Info . help_url , symbol : 'fas_question' , last : true
2018-09-12 21:42:36 +03:00
end
end
2021-04-18 14:34:55 +03:00
def handle_top_submenu_item ( menu_name , ** item )
handle_top_menu_item menu_name , with_submenu : true , ** item
2020-09-02 14:18:05 +03:00
end
2021-08-04 07:47:41 +03:00
def handle_top_menu_item ( menu_name , url : , with_submenu : false , onlyif : nil ,
name : nil , parent : nil , title : nil , symbol : nil , before : nil , after : nil , last : false )
2018-09-12 17:04:39 +03:00
Redmine :: MenuManager . map ( :top_menu ) . delete ( menu_name . to_sym ) if Redmine :: MenuManager . map ( :top_menu ) . exists? ( menu_name . to_sym )
html_options = { }
2020-09-02 14:18:05 +03:00
css_classes = [ ]
css_classes << 'top-submenu' if with_submenu
2021-08-04 07:47:41 +03:00
css_classes << 'external' if url . include? '://'
2021-04-18 14:34:55 +03:00
html_options [ :class ] = css_classes . join ' ' if css_classes . present?
2020-09-02 14:18:05 +03:00
2021-08-04 07:47:41 +03:00
html_options [ :title ] = title if title . present?
2018-09-12 17:04:39 +03:00
2021-08-04 07:47:41 +03:00
menu_options = { parent : parent . present? ? parent . to_sym : nil ,
2018-09-12 17:04:39 +03:00
html : html_options }
2021-08-04 07:47:41 +03:00
menu_options [ :if ] = onlyif if onlyif . present?
2018-09-12 17:04:39 +03:00
2021-08-04 07:47:41 +03:00
menu_options [ :caption ] = if symbol . present? && name . present?
font_awesome_icon symbol , post_text : name
elsif symbol . present?
font_awesome_icon symbol
elsif name . present?
name . to_s
2018-09-12 17:04:39 +03:00
end
2021-08-04 07:47:41 +03:00
if last
2018-09-12 17:04:39 +03:00
menu_options [ :last ] = true
2021-08-04 07:47:41 +03:00
elsif before . present?
menu_options [ :before ] = before
elsif after . present?
menu_options [ :after ] = after
2018-09-12 17:04:39 +03:00
else
menu_options [ :before ] = :help
end
2021-08-04 07:47:41 +03:00
Redmine :: MenuManager . map ( :top_menu ) . push menu_name , url , ** menu_options
2018-09-12 17:04:39 +03:00
end
2018-09-14 17:25:07 +03:00
def addtionals_help_plugin_items
2022-05-01 16:25:37 +03:00
user_items = [ { title : 'Redmine Guide' ,
url : Redmine :: Info . help_url ,
id : :redmine_guide } ,
{ title : " Redmine #{ l :label_macro_plural } " ,
url : additionals_macros_path ,
id : :macros } ]
2018-09-14 17:25:07 +03:00
2022-04-28 16:02:32 +03:00
admin_items = [ { title : 'Redmine Changelog' ,
2022-05-01 16:25:37 +03:00
url : " https://www.redmine.org/projects/redmine/wiki/Changelog_ #{ Redmine :: VERSION :: MAJOR } _ #{ Redmine :: VERSION :: MINOR } " ,
id : :changelog } ,
2020-04-08 08:55:04 +03:00
{ title : 'Redmine Upgrade' ,
2022-05-01 16:25:37 +03:00
url : 'https://www.redmine.org/projects/redmine/wiki/RedmineUpgrade' ,
2022-10-24 20:01:07 +03:00
id : :redmine_upgrade } ,
2020-04-08 08:55:04 +03:00
{ title : 'Redmine Security Advisories' ,
2022-10-24 20:01:07 +03:00
url : 'https://www.redmine.org/projects/redmine/wiki/Security_Advisories' ,
id : :security_advisories } ]
2018-09-14 17:25:07 +03:00
Redmine :: Plugin . all . each do | plugin |
next if plugin . id == :additionals
2018-09-14 18:55:25 +03:00
plugin_item_base = nil
2018-09-14 17:25:07 +03:00
begin
2018-09-14 18:55:25 +03:00
plugin_item_base = plugin . id . to_s . camelize . constantize
2018-10-25 16:02:35 +03:00
rescue LoadError
2021-06-21 15:52:57 +03:00
Rails . logger . debug { " Ignore plugin #{ plugin . id } for help integration " }
2018-09-14 17:25:07 +03:00
rescue StandardError = > e
2023-04-12 15:15:53 +03:00
raise e unless e . instance_of? :: NameError
2018-09-14 17:25:07 +03:00
end
2021-04-18 14:34:55 +03:00
plugin_item = plugin_item_base . try :additionals_help_items unless plugin_item_base . nil?
plugin_item = additionals_help_items_fallbacks plugin . id if plugin_item . nil?
2018-09-14 17:25:07 +03:00
2018-09-14 18:55:25 +03:00
next if plugin_item . nil?
plugin_item . each do | temp_item |
2022-05-01 16:25:37 +03:00
title = Array temp_item [ :title ]
title << l ( " label_help_ #{ temp_item [ :type ] } " ) if temp_item . key? :type
u_items = { title : safe_join ( title , ' ' ) ,
url : temp_item [ :url ] ,
id : temp_item [ :id ] }
2018-09-14 18:55:25 +03:00
if ! temp_item [ :admin ] . nil? && temp_item [ :admin ]
admin_items << u_items
else
user_items << u_items
end
2018-09-14 17:25:07 +03:00
end
end
{ user : user_items , admin : admin_items }
end
2018-09-12 17:04:39 +03:00
def additionals_help_menu_items
2018-09-14 17:25:07 +03:00
plugin_items = addtionals_help_plugin_items
pages = plugin_items [ :user ] . sort_by { | k | k [ :title ] }
2018-09-12 17:04:39 +03:00
if User . current . admin?
2022-05-01 16:25:37 +03:00
pages << { title : '-' , id : :sep }
2018-09-14 17:25:07 +03:00
pages += plugin_items [ :admin ] . sort_by { | k | k [ :title ] }
2018-09-12 17:04:39 +03:00
end
s = [ ]
2022-05-01 16:25:37 +03:00
ids = [ ]
pages . each do | item |
next unless item . key? :id
id = item [ :id ]
next if ids . include? id
ids << id
2018-09-12 17:38:07 +03:00
s << if item [ :title ] == '-'
2020-08-09 11:11:52 +03:00
tag . li tag . hr
2018-09-12 17:38:07 +03:00
else
2022-05-01 16:25:37 +03:00
html_options = { class : + " help_item_ #{ id } " }
2018-09-12 17:38:07 +03:00
if item [ :url ] . include? '://'
html_options [ :class ] << ' external'
html_options [ :target ] = '_blank'
end
2021-04-18 14:34:55 +03:00
tag . li link_to ( item [ :title ] , item [ :url ] , html_options )
2018-09-12 17:38:07 +03:00
end
2018-09-12 17:04:39 +03:00
end
2020-08-09 11:11:52 +03:00
safe_join s
2018-09-12 17:04:39 +03:00
end
2018-09-14 17:25:07 +03:00
# Plugin help items definition for plugins,
# which do not have additionals_help_menu_items integration
def additionals_help_items_fallbacks ( plugin_id )
2021-04-18 14:34:55 +03:00
plugins = { redmine_drawio : [ { title : 'draw.io usage' ,
2022-05-01 16:25:37 +03:00
id : :drawio ,
2021-04-18 14:34:55 +03:00
url : 'https://github.com/mikitex70/redmine_drawio#usage' } ] ,
2018-09-14 17:25:07 +03:00
redmine_contacts : [ { title : 'Redmine CRM' ,
2022-05-01 16:25:37 +03:00
id : :crm ,
2018-09-14 18:55:25 +03:00
url : 'https://www.redmineup.com/pages/help/crm' ,
admin : true } ] ,
2018-09-14 17:25:07 +03:00
redmine_contacts_helpdesk : [ { title : 'Redmine Helpdesk' ,
2022-05-01 16:25:37 +03:00
id : :helpdesk ,
2018-09-14 18:55:25 +03:00
url : 'https://www.redmineup.com/pages/help/helpdesk' ,
2022-05-01 16:25:37 +03:00
admin : true } ] }
2018-09-14 17:25:07 +03:00
plugins [ plugin_id ]
end
2018-09-12 17:04:39 +03:00
end