debian-mirror-gitlab/lib/sidebars/projects/menus/analytics_menu.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
3.5 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class AnalyticsMenu < ::Sidebars::Menu
include Gitlab::Utils::StrongMemoize
override :configure_menu_items
def configure_menu_items
return false unless can?(context.current_user, :read_analytics, context.project)
2022-01-26 12:08:38 +05:30
add_item(cycle_analytics_menu_item)
2021-06-08 01:23:25 +05:30
add_item(ci_cd_analytics_menu_item)
add_item(repository_analytics_menu_item)
true
end
override :link
def link
return cycle_analytics_menu_item.link if cycle_analytics_menu_item.render?
2021-11-11 11:23:49 +05:30
super
2021-06-08 01:23:25 +05:30
end
override :extra_container_html_options
def extra_container_html_options
{
class: 'shortcuts-analytics'
}
end
override :title
def title
_('Analytics')
end
override :sprite_icon
def sprite_icon
'chart'
end
2023-06-20 00:43:36 +05:30
override :serialize_as_menu_item_args
def serialize_as_menu_item_args
nil
2023-05-27 22:25:52 +05:30
end
2021-06-08 01:23:25 +05:30
private
def ci_cd_analytics_menu_item
if !context.project.feature_available?(:builds, context.current_user) ||
2023-03-04 22:38:38 +05:30
!can?(context.current_user, :read_build, context.project) ||
!can?(context.current_user, :read_ci_cd_analytics, context.project) ||
context.project.empty_repo?
2021-06-08 01:23:25 +05:30
return ::Sidebars::NilMenuItem.new(item_id: :ci_cd_analytics)
end
::Sidebars::MenuItem.new(
2023-06-20 00:43:36 +05:30
title: context.is_super_sidebar ? _('CI/CD analytics') : _('CI/CD'),
2021-06-08 01:23:25 +05:30
link: charts_project_pipelines_path(context.project),
2023-06-20 00:43:36 +05:30
super_sidebar_parent: ::Sidebars::Projects::SuperSidebarMenus::AnalyzeMenu,
2021-06-08 01:23:25 +05:30
active_routes: { path: 'pipelines#charts' },
item_id: :ci_cd_analytics
)
end
def repository_analytics_menu_item
2021-12-07 22:27:20 +05:30
if context.project.empty_repo? || !can?(context.current_user, :read_repository_graphs, context.project)
2021-06-08 01:23:25 +05:30
return ::Sidebars::NilMenuItem.new(item_id: :repository_analytics)
end
::Sidebars::MenuItem.new(
2023-06-20 00:43:36 +05:30
title: context.is_super_sidebar ? _('Repository analytics') : _('Repository'),
2021-06-08 01:23:25 +05:30
link: charts_project_graph_path(context.project, context.current_ref),
2023-06-20 00:43:36 +05:30
super_sidebar_parent: ::Sidebars::Projects::SuperSidebarMenus::AnalyzeMenu,
2021-06-08 01:23:25 +05:30
container_html_options: { class: 'shortcuts-repository-charts' },
active_routes: { path: 'graphs#charts' },
item_id: :repository_analytics
)
end
def cycle_analytics_menu_item
strong_memoize(:cycle_analytics_menu_item) do
unless can?(context.current_user, :read_cycle_analytics, context.project)
next ::Sidebars::NilMenuItem.new(item_id: :cycle_analytics)
end
::Sidebars::MenuItem.new(
2023-06-20 00:43:36 +05:30
title: context.is_super_sidebar ? _('Value stream analytics') : _('Value stream'),
2021-06-08 01:23:25 +05:30
link: project_cycle_analytics_path(context.project),
2023-06-20 00:43:36 +05:30
super_sidebar_parent: ::Sidebars::Projects::SuperSidebarMenus::AnalyzeMenu,
2021-06-08 01:23:25 +05:30
container_html_options: { class: 'shortcuts-project-cycle-analytics' },
active_routes: { path: 'cycle_analytics#show' },
item_id: :cycle_analytics
)
end
end
end
end
end
end
Sidebars::Projects::Menus::AnalyticsMenu.prepend_mod_with('Sidebars::Projects::Menus::AnalyticsMenu')