debian-mirror-gitlab/lib/gitlab/nav/top_nav_view_model_builder.rb

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

54 lines
1.3 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Gitlab
module Nav
class TopNavViewModelBuilder
def initialize
@menu_builder = ::Gitlab::Nav::TopNavMenuBuilder.new
@views = {}
2021-09-04 01:27:46 +05:30
@shortcuts = []
2021-06-08 01:23:25 +05:30
end
2021-09-04 01:27:46 +05:30
# Using delegate hides the stacktrace for some errors, so we choose to be explicit.
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62047#note_579031091
2023-04-23 21:23:45 +05:30
def add_primary_menu_item(...)
@menu_builder.add_primary_menu_item(...)
2021-09-04 01:27:46 +05:30
end
2023-04-23 21:23:45 +05:30
def add_secondary_menu_item(...)
@menu_builder.add_secondary_menu_item(...)
2021-09-04 01:27:46 +05:30
end
def add_shortcut(**args)
item = ::Gitlab::Nav::TopNavMenuItem.build(**args)
@shortcuts.push(item)
end
def add_primary_menu_item_with_shortcut(shortcut_class:, shortcut_href: nil, **args)
add_primary_menu_item(**args)
add_shortcut(
id: "#{args.fetch(:id)}-shortcut",
title: args.fetch(:title),
href: shortcut_href || args.fetch(:href),
css_class: shortcut_class
)
end
2021-06-08 01:23:25 +05:30
def add_view(name, props)
@views[name] = props
end
def build
menu = @menu_builder.build
menu.merge({
views: @views,
2021-09-04 01:27:46 +05:30
shortcuts: @shortcuts,
2023-01-13 00:05:48 +05:30
menuTooltip: _('Main menu')
2022-10-11 01:57:18 +05:30
}.compact)
2021-06-08 01:23:25 +05:30
end
end
end
end