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

learn_gitlab_helper.rb « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f8f6d77ff4b932d5e8ccf055b7746b95eadee64 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true

module LearnGitlabHelper
  def learn_gitlab_enabled?(project)
    return false unless current_user

    learn_gitlab_onboarding_available?(project)
  end

  def learn_gitlab_data(project)
    {
      actions: onboarding_actions_data(project).to_json,
      sections: onboarding_sections_data.to_json,
      project: onboarding_project_data(project).to_json
    }
  end

  def learn_gitlab_onboarding_available?(project)
    OnboardingProgress.onboarding?(project.namespace) &&
      LearnGitlab::Project.new(current_user).available?
  end

  private

  def onboarding_actions_data(project)
    attributes = onboarding_progress(project).attributes.symbolize_keys

    urls_to_use = nil

    experiment(:change_continuous_onboarding_link_urls) do |e|
      e.namespace = project.namespace
      e.use { urls_to_use = action_urls }
      e.try { urls_to_use = new_action_urls(project) }
    end

    urls_to_use.to_h do |action, url|
      [
        action,
        url: url,
        completed: attributes[OnboardingProgress.column_name(action)].present?,
        svg: image_path("learn_gitlab/#{action}.svg")
      ]
    end
  end

  def onboarding_sections_data
    {
      workspace: {
        svg: image_path("learn_gitlab/section_workspace.svg")
      },
      plan: {
        svg: image_path("learn_gitlab/section_plan.svg")
      },
      deploy: {
        svg: image_path("learn_gitlab/section_deploy.svg")
      }
    }
  end

  def onboarding_project_data(project)
    { name: project.name }
  end

  def action_urls
    LearnGitlab::Onboarding::ACTION_ISSUE_IDS.transform_values { |id| project_issue_url(learn_gitlab_project, id) }
      .merge(LearnGitlab::Onboarding::ACTION_DOC_URLS)
  end

  def new_action_urls(project)
    action_urls.merge(
      issue_created: project_issues_path(project),
      git_write: project_path(project),
      pipeline_created: project_pipelines_path(project),
      merge_request_created: project_merge_requests_path(project),
      user_added: project_members_url(project),
      security_scan_enabled: project_security_configuration_path(project)
    )
  end

  def learn_gitlab_project
    @learn_gitlab_project ||= LearnGitlab::Project.new(current_user).project
  end

  def onboarding_progress(project)
    OnboardingProgress.find_by(namespace: project.namespace) # rubocop: disable CodeReuse/ActiveRecord
  end
end

LearnGitlabHelper.prepend_mod_with('LearnGitlabHelper')