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

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

138 lines
4 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 RepositoryMenu < ::Sidebars::Menu
override :configure_menu_items
def configure_menu_items
2023-03-04 22:38:38 +05:30
return false unless can?(context.current_user, :read_code, context.project)
2021-06-08 01:23:25 +05:30
return false if context.project.empty_repo?
add_item(files_menu_item)
add_item(commits_menu_item)
add_item(branches_menu_item)
add_item(tags_menu_item)
add_item(contributors_menu_item)
add_item(graphs_menu_item)
add_item(compare_menu_item)
true
end
override :extra_container_html_options
def extra_container_html_options
{
class: 'shortcuts-tree'
}
end
override :title
def title
_('Repository')
end
override :title_html_options
def title_html_options
{
id: 'js-onboarding-repo-link'
}
end
override :sprite_icon
def sprite_icon
'doc-text'
end
2023-05-27 22:25:52 +05:30
override :pick_into_super_sidebar?
def pick_into_super_sidebar?
true
end
2021-06-08 01:23:25 +05:30
private
def files_menu_item
::Sidebars::MenuItem.new(
title: _('Files'),
link: project_tree_path(context.project, context.current_ref),
active_routes: { controller: %w[tree blob blame edit_tree new_tree find_file] },
item_id: :files
)
end
def commits_menu_item
2023-04-23 21:23:45 +05:30
link = project_commits_path(context.project, context.current_ref, ref_type: ref_type_from_context(context))
2023-03-04 22:38:38 +05:30
2021-06-08 01:23:25 +05:30
::Sidebars::MenuItem.new(
title: _('Commits'),
2023-03-04 22:38:38 +05:30
link: link,
2021-06-08 01:23:25 +05:30
active_routes: { controller: %w(commit commits) },
item_id: :commits,
container_html_options: { id: 'js-onboarding-commits-link' }
)
end
def branches_menu_item
::Sidebars::MenuItem.new(
title: _('Branches'),
link: project_branches_path(context.project),
active_routes: { controller: :branches },
item_id: :branches,
container_html_options: { id: 'js-onboarding-branches-link' }
)
end
def tags_menu_item
::Sidebars::MenuItem.new(
title: _('Tags'),
link: project_tags_path(context.project),
item_id: :tags,
active_routes: { controller: :tags }
)
end
def contributors_menu_item
2022-11-25 23:54:43 +05:30
return false unless context.project.analytics_enabled?
2023-04-23 21:23:45 +05:30
link = project_graph_path(context.project, context.current_ref, ref_type: ref_type_from_context(context))
2023-03-04 22:38:38 +05:30
2021-06-08 01:23:25 +05:30
::Sidebars::MenuItem.new(
2023-05-27 22:25:52 +05:30
title: _('Contributor statistics'),
2023-03-04 22:38:38 +05:30
link: link,
2021-06-08 01:23:25 +05:30
active_routes: { path: 'graphs#show' },
item_id: :contributors
)
end
def graphs_menu_item
2023-04-23 21:23:45 +05:30
link = project_network_path(context.project, context.current_ref, ref_type: ref_type_from_context(context))
2023-03-04 22:38:38 +05:30
2021-06-08 01:23:25 +05:30
::Sidebars::MenuItem.new(
title: _('Graph'),
2023-03-04 22:38:38 +05:30
link: link,
2021-06-08 01:23:25 +05:30
active_routes: { controller: :network },
item_id: :graphs
)
end
def compare_menu_item
::Sidebars::MenuItem.new(
2023-05-27 22:25:52 +05:30
title: _('Compare revisions'),
2021-06-08 01:23:25 +05:30
link: project_compare_index_path(context.project, from: context.project.repository.root_ref, to: context.current_ref),
active_routes: { controller: :compare },
item_id: :compare
)
end
2023-03-04 22:38:38 +05:30
def ref_type_from_context(context)
ref_type = context.try(:ref_type)
ref_type ||= 'heads' if context.current_ref == context.project.repository.root_ref
ref_type
end
2021-06-08 01:23:25 +05:30
end
end
end
end
Sidebars::Projects::Menus::RepositoryMenu.prepend_mod_with('Sidebars::Projects::Menus::RepositoryMenu')