BigW Consortium Gitlab

preferences_helper.rb 1.96 KB
Newer Older
1 2
# Helper methods for per-User preferences
module PreferencesHelper
3 4
  def layout_choices
    [
5 6
        ['Fixed', :fixed],
        ['Fluid', :fluid]
7 8 9
    ]
  end

10 11 12
  # Maps `dashboard` values to more user-friendly option text
  DASHBOARD_CHOICES = {
    projects: 'Your Projects (default)',
13 14
    stars:    'Starred Projects',
    project_activity: "Your Projects' Activity",
15 16 17
    starred_project_activity: "Starred Projects' Activity",
    groups: "Your Groups",
    todos: "Your Todos"
18
  }.with_indifferent_access.freeze
19

20 21 22
  # Returns an Array usable by a select field for more user-friendly option text
  def dashboard_choices
    defined = User.dashboards
23

24 25 26 27
    if defined.size != DASHBOARD_CHOICES.size
      # Ensure that anyone adding new options updates this method too
      raise RuntimeError, "`User` defines #{defined.size} dashboard choices," +
        " but `DASHBOARD_CHOICES` defined #{DASHBOARD_CHOICES.size}."
28
    else
29 30 31 32
      defined.map do |key, _|
        # Use `fetch` so `KeyError` gets raised when a key is missing
        [DASHBOARD_CHOICES.fetch(key), key]
      end
33 34 35
    end
  end

36 37 38
  def project_view_choices
    [
      ['Readme (default)', :readme],
39 40
      ['Activity view', :activity],
      ['Files view', :files]
41 42 43
    ]
  end

44
  def user_application_theme
45 46 47 48 49
    Gitlab::Themes.for_user(current_user).css_class
  end

  def user_color_scheme
    Gitlab::ColorSchemes.for_user(current_user).css_class
50 51
  end

52
  def default_project_view
53
    return anonymous_project_view unless current_user
54 55 56 57 58 59 60 61 62 63 64 65 66 67

    user_view = current_user.project_view

    if @project.feature_available?(:repository, current_user)
      user_view
    elsif user_view == "activity"
      "activity"
    elsif @project.wiki_enabled?
      "wiki"
    elsif @project.feature_available?(:issues, current_user)
      "projects/issues/issues"
    else
      "customize_workflow"
    end
68
  end
69

70 71
  def anonymous_project_view
    @project.empty_repo? || !can?(current_user, :download_code, @project) ? 'activity' : 'readme'
72
  end
73
end