diff options
Diffstat (limited to 'lib/sidebars')
-rw-r--r-- | lib/sidebars/concerns/has_partial.rb | 21 | ||||
-rw-r--r-- | lib/sidebars/concerns/has_pill.rb | 13 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/ci_cd_menu.rb | 51 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/group_information_menu.rb | 79 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/issues_menu.rb | 101 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/kubernetes_menu.rb | 41 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/merge_requests_menu.rb | 58 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/packages_registries_menu.rb | 74 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/settings_menu.rb | 117 | ||||
-rw-r--r-- | lib/sidebars/groups/panel.rb | 10 | ||||
-rw-r--r-- | lib/sidebars/menu.rb | 3 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/packages_registries_menu.rb | 8 |
12 files changed, 573 insertions, 3 deletions
diff --git a/lib/sidebars/concerns/has_partial.rb b/lib/sidebars/concerns/has_partial.rb new file mode 100644 index 00000000000..e89bc66bc40 --- /dev/null +++ b/lib/sidebars/concerns/has_partial.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# This module has the necessary methods to render +# menus using a custom partial +module Sidebars + module Concerns + module HasPartial + def menu_partial + nil + end + + def menu_partial_options + {} + end + + def menu_with_partial? + menu_partial.present? + end + end + end +end diff --git a/lib/sidebars/concerns/has_pill.rb b/lib/sidebars/concerns/has_pill.rb index 5082ed477e6..4bbf69bf16b 100644 --- a/lib/sidebars/concerns/has_pill.rb +++ b/lib/sidebars/concerns/has_pill.rb @@ -5,6 +5,8 @@ module Sidebars module Concerns module HasPill + include ActionView::Helpers::NumberHelper + def has_pill? false end @@ -18,6 +20,17 @@ module Sidebars def pill_html_options {} end + + def format_cached_count(count_service, count) + if count > count_service::CACHED_COUNT_THRESHOLD + number_to_human( + count, + units: { thousand: 'k', million: 'm' }, precision: 1, significant: false, format: '%n%u' + ) + else + number_with_delimiter(count) + end + end end end end diff --git a/lib/sidebars/groups/menus/ci_cd_menu.rb b/lib/sidebars/groups/menus/ci_cd_menu.rb new file mode 100644 index 00000000000..e870bbf5ebc --- /dev/null +++ b/lib/sidebars/groups/menus/ci_cd_menu.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class CiCdMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + add_item(runners_menu_item) + + true + end + + override :link + def link + renderable_items.first.link + end + + override :title + def title + _('CI/CD') + end + + override :sprite_icon + def sprite_icon + 'rocket' + end + + private + + def runners_menu_item + return ::Sidebars::NilMenuItem.new(item_id: :runners) unless show_runners? + + ::Sidebars::MenuItem.new( + title: _('Runners'), + link: group_runners_path(context.group), + active_routes: { path: 'groups/runners#index' }, + item_id: :runners + ) + end + + # TODO Proper policies, such as `read_group_runners`, should be implemented per + # See https://gitlab.com/gitlab-org/gitlab/-/issues/334802 + def show_runners? + can?(context.current_user, :admin_group, context.group) && + Feature.enabled?(:runner_list_group_view_vue_ui, context.group, default_enabled: :yaml) + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/group_information_menu.rb b/lib/sidebars/groups/menus/group_information_menu.rb new file mode 100644 index 00000000000..b28cb927ad2 --- /dev/null +++ b/lib/sidebars/groups/menus/group_information_menu.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class GroupInformationMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + add_item(activity_menu_item) + add_item(labels_menu_item) + add_item(members_menu_item) + + true + end + + override :link + def link + renderable_items.first.link + end + + override :title + def title + context.group.subgroup? ? _('Subgroup information') : _('Group information') + end + + override :sprite_icon + def sprite_icon + 'group' + end + + override :active_routes + def active_routes + { path: 'groups#subgroups' } + end + + private + + def activity_menu_item + unless can?(context.current_user, :read_group_activity, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :activity) + end + + ::Sidebars::MenuItem.new( + title: _('Activity'), + link: activity_group_path(context.group), + active_routes: { path: 'groups#activity' }, + item_id: :activity + ) + end + + def labels_menu_item + unless can?(context.current_user, :read_group_labels, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :labels) + end + + ::Sidebars::MenuItem.new( + title: _('Labels'), + link: group_labels_path(context.group), + active_routes: { controller: :labels }, + item_id: :labels + ) + end + + def members_menu_item + unless can?(context.current_user, :read_group_member, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :members) + end + + ::Sidebars::MenuItem.new( + title: _('Members'), + link: group_group_members_path(context.group), + active_routes: { path: 'group_members#index' }, + item_id: :members + ) + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/issues_menu.rb b/lib/sidebars/groups/menus/issues_menu.rb new file mode 100644 index 00000000000..95641c09076 --- /dev/null +++ b/lib/sidebars/groups/menus/issues_menu.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class IssuesMenu < ::Sidebars::Menu + include Gitlab::Utils::StrongMemoize + + override :configure_menu_items + def configure_menu_items + return unless can?(context.current_user, :read_group_issues, context.group) + + add_item(list_menu_item) + add_item(boards_menu_item) + add_item(milestones_menu_item) + + true + end + + override :link + def link + issues_group_path(context.group) + end + + override :title + def title + _('Issues') + end + + override :sprite_icon + def sprite_icon + 'issues' + end + + override :has_pill? + def has_pill? + true + end + + override :pill_count + def pill_count + strong_memoize(:pill_count) do + count_service = ::Groups::OpenIssuesCountService + count = count_service.new(context.group, context.current_user).count + + format_cached_count(count_service, count) + end + end + + override :pill_html_options + def pill_html_options + { + class: 'issue_counter' + } + end + + private + + def list_menu_item + ::Sidebars::MenuItem.new( + title: _('List'), + link: issues_group_path(context.group), + active_routes: { path: 'groups#issues' }, + container_html_options: { aria: { label: _('Issues') } }, + item_id: :issue_list + ) + end + + def boards_menu_item + unless can?(context.current_user, :read_group_boards, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :boards) + end + + title = context.group.multiple_issue_boards_available? ? s_('IssueBoards|Boards') : s_('IssueBoards|Board') + + ::Sidebars::MenuItem.new( + title: title, + link: group_boards_path(context.group), + active_routes: { path: %w[boards#index boards#show] }, + item_id: :boards + ) + end + + def milestones_menu_item + unless can?(context.current_user, :read_group_milestones, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :milestones) + end + + ::Sidebars::MenuItem.new( + title: _('Milestones'), + link: group_milestones_path(context.group), + active_routes: { path: 'milestones#index' }, + item_id: :milestones + ) + end + end + end + end +end + +Sidebars::Groups::Menus::IssuesMenu.prepend_mod_with('Sidebars::Groups::Menus::IssuesMenu') diff --git a/lib/sidebars/groups/menus/kubernetes_menu.rb b/lib/sidebars/groups/menus/kubernetes_menu.rb new file mode 100644 index 00000000000..4ea294a4837 --- /dev/null +++ b/lib/sidebars/groups/menus/kubernetes_menu.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class KubernetesMenu < ::Sidebars::Menu + override :link + def link + group_clusters_path(context.group) + end + + override :title + def title + _('Kubernetes') + end + + override :sprite_icon + def sprite_icon + 'cloud-gear' + end + + override :render? + def render? + can?(context.current_user, :read_cluster, context.group) + end + + override :extra_container_html_options + def extra_container_html_options + { + class: 'shortcuts-kubernetes' + } + end + + override :active_routes + def active_routes + { controller: :clusters } + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/merge_requests_menu.rb b/lib/sidebars/groups/menus/merge_requests_menu.rb new file mode 100644 index 00000000000..7faf50305c6 --- /dev/null +++ b/lib/sidebars/groups/menus/merge_requests_menu.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class MergeRequestsMenu < ::Sidebars::Menu + include Gitlab::Utils::StrongMemoize + + override :link + def link + merge_requests_group_path(context.group) + end + + override :title + def title + _('Merge requests') + end + + override :sprite_icon + def sprite_icon + 'git-merge' + end + + override :render? + def render? + can?(context.current_user, :read_group_merge_requests, context.group) + end + + override :has_pill? + def has_pill? + true + end + + override :pill_count + def pill_count + strong_memoize(:pill_count) do + count_service = ::Groups::MergeRequestsCountService + count = count_service.new(context.group, context.current_user).count + + format_cached_count(count_service, count) + end + end + + override :pill_html_options + def pill_html_options + { + class: 'merge_counter js-merge-counter' + } + end + + override :active_routes + def active_routes + { path: 'groups#merge_requests' } + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/packages_registries_menu.rb b/lib/sidebars/groups/menus/packages_registries_menu.rb new file mode 100644 index 00000000000..e46e2820c04 --- /dev/null +++ b/lib/sidebars/groups/menus/packages_registries_menu.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class PackagesRegistriesMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + add_item(packages_registry_menu_item) + add_item(container_registry_menu_item) + add_item(dependency_proxy_menu_item) + + true + end + + override :link + def link + renderable_items.first.link + end + + override :title + def title + _('Packages & Registries') + end + + override :sprite_icon + def sprite_icon + 'package' + end + + private + + def packages_registry_menu_item + unless context.group.packages_feature_enabled? + return ::Sidebars::NilMenuItem.new(item_id: :packages_registry) + end + + ::Sidebars::MenuItem.new( + title: _('Package Registry'), + link: group_packages_path(context.group), + active_routes: { controller: 'groups/packages' }, + item_id: :packages_registry + ) + end + + def container_registry_menu_item + if !::Gitlab.config.registry.enabled || !can?(context.current_user, :read_container_image, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :container_registry) + end + + ::Sidebars::MenuItem.new( + title: _('Container Registry'), + link: group_container_registries_path(context.group), + active_routes: { controller: 'groups/registry/repositories' }, + item_id: :container_registry + ) + end + + def dependency_proxy_menu_item + unless context.group.dependency_proxy_feature_available? + return ::Sidebars::NilMenuItem.new(item_id: :dependency_proxy) + end + + ::Sidebars::MenuItem.new( + title: _('Dependency Proxy'), + link: group_dependency_proxy_path(context.group), + active_routes: { controller: 'groups/dependency_proxies' }, + item_id: :dependency_proxy + ) + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/settings_menu.rb b/lib/sidebars/groups/menus/settings_menu.rb new file mode 100644 index 00000000000..8bc6077d302 --- /dev/null +++ b/lib/sidebars/groups/menus/settings_menu.rb @@ -0,0 +1,117 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class SettingsMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + return false unless can?(context.current_user, :admin_group, context.group) + + add_item(general_menu_item) + add_item(integrations_menu_item) + add_item(group_projects_menu_item) + add_item(repository_menu_item) + add_item(ci_cd_menu_item) + add_item(applications_menu_item) + add_item(packages_and_registries_menu_item) + + true + end + + override :link + def link + edit_group_path(context.group) + end + + override :title + def title + _('Settings') + end + + override :sprite_icon + def sprite_icon + 'settings' + end + + override :extra_nav_link_html_options + def extra_nav_link_html_options + { + class: 'shortcuts-settings' + } + end + + private + + def general_menu_item + ::Sidebars::MenuItem.new( + title: _('General'), + link: edit_group_path(context.group), + active_routes: { path: 'groups#edit' }, + item_id: :general + ) + end + + def integrations_menu_item + ::Sidebars::MenuItem.new( + title: _('Integrations'), + link: group_settings_integrations_path(context.group), + active_routes: { controller: :integrations }, + item_id: :integrations + ) + end + + def group_projects_menu_item + ::Sidebars::MenuItem.new( + title: _('Projects'), + link: projects_group_path(context.group), + active_routes: { path: 'groups#projects' }, + item_id: :group_projects + ) + end + + def repository_menu_item + ::Sidebars::MenuItem.new( + title: _('Repository'), + link: group_settings_repository_path(context.group), + active_routes: { controller: :repository }, + item_id: :repository + ) + end + + def ci_cd_menu_item + ::Sidebars::MenuItem.new( + title: _('CI/CD'), + link: group_settings_ci_cd_path(context.group), + active_routes: { path: %w[ci_cd#show groups/runners#show groups/runners#edit] }, + item_id: :ci_cd + ) + end + + def applications_menu_item + ::Sidebars::MenuItem.new( + title: _('Applications'), + link: group_settings_applications_path(context.group), + active_routes: { controller: :applications }, + item_id: :applications + ) + end + + def packages_and_registries_menu_item + unless context.group.packages_feature_enabled? + return ::Sidebars::NilMenuItem.new(item_id: :packages_and_registries) + end + + ::Sidebars::MenuItem.new( + title: _('Packages & Registries'), + link: group_settings_packages_and_registries_path(context.group), + active_routes: { controller: :packages_and_registries }, + item_id: :packages_and_registries + ) + end + end + end + end +end + +Sidebars::Groups::Menus::SettingsMenu.prepend_mod_with('Sidebars::Groups::Menus::SettingsMenu') diff --git a/lib/sidebars/groups/panel.rb b/lib/sidebars/groups/panel.rb index fe669bf0b29..73b943c5655 100644 --- a/lib/sidebars/groups/panel.rb +++ b/lib/sidebars/groups/panel.rb @@ -6,6 +6,14 @@ module Sidebars override :configure_menus def configure_menus set_scope_menu(Sidebars::Groups::Menus::ScopeMenu.new(context)) + + add_menu(Sidebars::Groups::Menus::GroupInformationMenu.new(context)) + add_menu(Sidebars::Groups::Menus::IssuesMenu.new(context)) + add_menu(Sidebars::Groups::Menus::MergeRequestsMenu.new(context)) + add_menu(Sidebars::Groups::Menus::CiCdMenu.new(context)) + add_menu(Sidebars::Groups::Menus::KubernetesMenu.new(context)) + add_menu(Sidebars::Groups::Menus::PackagesRegistriesMenu.new(context)) + add_menu(Sidebars::Groups::Menus::SettingsMenu.new(context)) end override :render_raw_menus_partial @@ -20,3 +28,5 @@ module Sidebars end end end + +Sidebars::Groups::Panel.prepend_mod_with('Sidebars::Groups::Panel') diff --git a/lib/sidebars/menu.rb b/lib/sidebars/menu.rb index dcdc130b0d7..3b8872fd572 100644 --- a/lib/sidebars/menu.rb +++ b/lib/sidebars/menu.rb @@ -12,6 +12,7 @@ module Sidebars include ::Sidebars::Concerns::Renderable include ::Sidebars::Concerns::ContainerWithHtmlOptions include ::Sidebars::Concerns::HasActiveRoutes + include ::Sidebars::Concerns::HasPartial attr_reader :context delegate :current_user, :container, to: :@context @@ -29,7 +30,7 @@ module Sidebars override :render? def render? - has_renderable_items? + has_renderable_items? || menu_with_partial? end # Menus might have or not a link diff --git a/lib/sidebars/projects/menus/packages_registries_menu.rb b/lib/sidebars/projects/menus/packages_registries_menu.rb index 27e318d73c5..d49bb680853 100644 --- a/lib/sidebars/projects/menus/packages_registries_menu.rb +++ b/lib/sidebars/projects/menus/packages_registries_menu.rb @@ -31,7 +31,7 @@ module Sidebars private def packages_registry_menu_item - if !::Gitlab.config.packages.enabled || !can?(context.current_user, :read_package, context.project) + if packages_registry_disabled? return ::Sidebars::NilMenuItem.new(item_id: :packages_registry) end @@ -58,7 +58,7 @@ module Sidebars end def infrastructure_registry_menu_item - if Feature.disabled?(:infrastructure_registry_page, context.current_user, default_enabled: :yaml) + if packages_registry_disabled? return ::Sidebars::NilMenuItem.new(item_id: :infrastructure_registry) end @@ -69,6 +69,10 @@ module Sidebars item_id: :infrastructure_registry ) end + + def packages_registry_disabled? + !::Gitlab.config.packages.enabled || !can?(context.current_user, :read_package, context.project) + end end end end |