2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-30 14:23:35 -05:00
|
|
|
module NavHelper
|
2017-12-11 09:21:06 -05:00
|
|
|
def header_links
|
|
|
|
@header_links ||= get_header_links
|
|
|
|
end
|
|
|
|
|
|
|
|
def header_link?(link)
|
|
|
|
header_links.include?(link)
|
|
|
|
end
|
|
|
|
|
2017-07-31 04:07:51 -04:00
|
|
|
def page_with_sidebar_class
|
|
|
|
class_name = page_gutter_class
|
2017-10-20 18:57:24 -04:00
|
|
|
class_name << 'page-with-contextual-sidebar' if defined?(@left_sidebar) && @left_sidebar
|
2017-09-06 06:58:24 -04:00
|
|
|
class_name << 'page-with-icon-sidebar' if collapsed_sidebar? && @left_sidebar
|
2018-05-29 03:28:49 -04:00
|
|
|
class_name -= ['right-sidebar-expanded'] if defined?(@right_sidebar) && !@right_sidebar
|
2017-07-31 04:07:51 -04:00
|
|
|
|
|
|
|
class_name
|
|
|
|
end
|
|
|
|
|
2016-01-27 17:38:19 -05:00
|
|
|
def page_gutter_class
|
2022-05-16 17:09:09 -04:00
|
|
|
moved_sidebar_enabled = current_controller?('merge_requests') && moved_mr_sidebar_enabled?
|
|
|
|
|
2022-06-07 08:08:05 -04:00
|
|
|
if page_has_markdown? && !current_controller?('conflicts')
|
2016-01-28 18:26:47 -05:00
|
|
|
if cookies[:collapsed_gutter] == 'true'
|
2022-05-16 17:09:09 -04:00
|
|
|
["page-gutter", "#{'right-sidebar-collapsed' unless moved_sidebar_enabled}"]
|
2016-01-28 18:26:47 -05:00
|
|
|
else
|
2022-05-16 17:09:09 -04:00
|
|
|
["page-gutter", "#{'right-sidebar-expanded' unless moved_sidebar_enabled}"]
|
2016-01-28 18:26:47 -05:00
|
|
|
end
|
2017-06-08 08:21:03 -04:00
|
|
|
elsif current_path?('jobs#show')
|
2017-07-31 04:07:51 -04:00
|
|
|
%w[page-gutter build-sidebar right-sidebar-expanded]
|
2020-07-02 11:09:08 -04:00
|
|
|
elsif current_controller?('wikis') && current_action?('show', 'create', 'edit', 'update', 'history', 'git_access', 'destroy', 'diff')
|
2017-07-31 04:07:51 -04:00
|
|
|
%w[page-gutter wiki-sidebar right-sidebar-expanded]
|
|
|
|
else
|
|
|
|
[]
|
2016-01-27 17:38:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-16 15:58:15 -04:00
|
|
|
def nav_control_class
|
|
|
|
"nav-control" if current_user
|
|
|
|
end
|
2017-08-10 16:13:38 -04:00
|
|
|
|
|
|
|
def user_dropdown_class
|
|
|
|
class_names = []
|
|
|
|
class_names << 'header-user-dropdown-toggle'
|
|
|
|
class_names << 'impersonated-user' if session[:impersonator_id]
|
|
|
|
|
|
|
|
class_names
|
|
|
|
end
|
2017-12-11 09:21:06 -05:00
|
|
|
|
2018-11-09 07:17:00 -05:00
|
|
|
def page_has_markdown?
|
2022-09-29 11:09:34 -04:00
|
|
|
current_path?('projects/merge_requests#show') ||
|
2018-11-09 07:17:00 -05:00
|
|
|
current_path?('projects/merge_requests/conflicts#show') ||
|
|
|
|
current_path?('issues#show') ||
|
2020-05-12 17:08:14 -04:00
|
|
|
current_path?('milestones#show') ||
|
2020-10-01 11:10:05 -04:00
|
|
|
current_path?('issues#designs') ||
|
|
|
|
current_path?('incidents#show')
|
2018-11-09 07:17:00 -05:00
|
|
|
end
|
|
|
|
|
2019-05-08 01:26:10 -04:00
|
|
|
def admin_monitoring_nav_links
|
2022-04-28 14:10:01 -04:00
|
|
|
%w(system_info background_migrations background_jobs health_check)
|
2019-05-08 01:26:10 -04:00
|
|
|
end
|
|
|
|
|
2020-08-21 14:10:24 -04:00
|
|
|
def admin_analytics_nav_links
|
2021-07-01 05:07:33 -04:00
|
|
|
%w(dev_ops_report usage_trends)
|
2020-08-21 14:10:24 -04:00
|
|
|
end
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_header_links
|
|
|
|
links = if current_user
|
|
|
|
[:user_dropdown]
|
|
|
|
else
|
|
|
|
[:sign_in]
|
|
|
|
end
|
|
|
|
|
|
|
|
if can?(current_user, :read_cross_project)
|
|
|
|
links += [:issues, :merge_requests, :todos] if current_user.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
if @project&.persisted? || can?(current_user, :read_cross_project)
|
|
|
|
links << :search
|
|
|
|
end
|
|
|
|
|
|
|
|
if session[:impersonator_id]
|
|
|
|
links << :admin_impersonation
|
|
|
|
end
|
|
|
|
|
2021-03-17 20:08:58 -04:00
|
|
|
if Gitlab::CurrentSettings.admin_mode && current_user_mode.admin_mode?
|
|
|
|
links << :admin_mode
|
2019-09-26 08:06:00 -04:00
|
|
|
end
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
links
|
|
|
|
end
|
2015-01-30 14:23:35 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
NavHelper.prepend_mod_with('NavHelper')
|