Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dashboard_helper.rb « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7a0e2135b94f0e9960fdbd092c2818e3a9d7f575 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module DashboardHelper
  def assigned_issues_dashboard_path
    issues_dashboard_path(assignee_id: current_user.id)
  end

  def assigned_mrs_dashboard_path
    merge_requests_dashboard_path(assignee_id: current_user.id)
  end

  def dashboard_nav_links
    @dashboard_nav_links ||= get_dashboard_nav_links
  end

  def dashboard_nav_link?(link)
    dashboard_nav_links.include?(link)
  end

  def any_dashboard_nav_link?(links)
    links.any? { |link| dashboard_nav_link?(link) }
  end

  def controller_action_to_child_dashboards(controller = controller_name, action = action_name)
    case "#{controller}##{action}"
    when 'projects#index', 'root#index', 'projects#starred', 'projects#trending'
      ['projects', 'stars']
    when 'dashboard#activity'
      ['starred_project_activity', 'project_activity']
    when 'groups#index'
      ['groups']
    when 'todos#index'
      ['todos']
    when 'dashboard#issues'
      ['issues']
    when 'dashboard#merge_requests'
      ['merge_requests']
    else
      []
    end
  end

  def is_default_dashboard?(user = current_user)
    controller_action_to_child_dashboards.any? {|dashboard| dashboard == user.dashboard }
  end

  private

  def get_dashboard_nav_links
    links = [:projects, :groups, :snippets]

    if can?(current_user, :read_cross_project)
      links += [:activity, :milestones]
    end

    links
  end
end