Class: Search::Navigation
Instance Method Summary
collapse
#can?, #can_all?, #can_any?
Constructor Details
#initialize(user:, project: nil, group: nil, options: {}) ⇒ Navigation
Returns a new instance of Navigation.
7
8
9
10
11
12
|
# File 'lib/search/navigation.rb', line 7
def initialize(user:, project: nil, group: nil, options: {})
@user = user
@project = project
@group = group
@options = options
end
|
Instance Method Details
#tab_enabled_for_project?(tab) ⇒ Boolean
14
15
16
17
18
19
|
# File 'lib/search/navigation.rb', line 14
def tab_enabled_for_project?(tab)
return false unless project.present?
abilities = Array(search_tab_ability_map[tab])
Array.wrap(project).any? { |p| abilities.any? { |ability| can?(user, ability, p) } }
end
|
#tabs ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/search/navigation.rb', line 21
def tabs
nav = {}
Search::Scopes.scope_definitions.each do |scope_key, definition|
label = definition[:label]
label = label.call if label.respond_to?(:call)
nav[scope_key] = {
sort: definition[:sort],
label: label,
condition: scope_visible?(scope_key)
}
if scope_key == :projects
nav[scope_key][:data] = { testid: 'projects-tab' }
elsif scope_key == :blobs
nav[scope_key][:data] = { testid: 'code-tab' }
end
nav[scope_key][:search] = { snippets: true, group_id: nil, project_id: nil } if scope_key == :snippet_titles
end
nav
end
|