2021-02-16 09:09:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module LearnGitlabHelper
|
2021-09-13 15:10:34 +00:00
|
|
|
def learn_gitlab_enabled?(project)
|
2021-02-16 09:09:36 +00:00
|
|
|
return false unless current_user
|
|
|
|
|
|
|
|
learn_gitlab_onboarding_available?(project)
|
|
|
|
end
|
|
|
|
|
2021-11-17 18:14:12 +00:00
|
|
|
def learn_gitlab_data(project)
|
|
|
|
{
|
|
|
|
actions: onboarding_actions_data(project).to_json,
|
2021-11-18 15:10:19 +00:00
|
|
|
sections: onboarding_sections_data.to_json,
|
|
|
|
project: onboarding_project_data(project).to_json
|
2021-11-17 18:14:12 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def learn_gitlab_onboarding_available?(project)
|
|
|
|
OnboardingProgress.onboarding?(project.namespace) &&
|
|
|
|
LearnGitlab::Project.new(current_user).available?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-02-16 09:09:36 +00:00
|
|
|
def onboarding_actions_data(project)
|
|
|
|
attributes = onboarding_progress(project).attributes.symbolize_keys
|
|
|
|
|
2021-10-28 18:14:18 +00:00
|
|
|
urls_to_use = nil
|
|
|
|
|
2021-12-23 12:15:16 +00:00
|
|
|
experiment(
|
|
|
|
:change_continuous_onboarding_link_urls,
|
|
|
|
namespace: project.namespace,
|
|
|
|
actor: current_user,
|
|
|
|
sticky_to: project.namespace
|
|
|
|
) do |e|
|
2022-02-04 21:16:06 +00:00
|
|
|
e.control { urls_to_use = action_urls }
|
|
|
|
e.candidate { urls_to_use = new_action_urls(project) }
|
2021-10-28 18:14:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
urls_to_use.to_h do |action, url|
|
2021-02-16 09:09:36 +00:00
|
|
|
[
|
|
|
|
action,
|
|
|
|
url: url,
|
2021-02-23 18:10:40 +00:00
|
|
|
completed: attributes[OnboardingProgress.column_name(action)].present?,
|
|
|
|
svg: image_path("learn_gitlab/#{action}.svg")
|
2021-02-16 09:09:36 +00:00
|
|
|
]
|
2021-03-28 15:09:30 +00:00
|
|
|
end
|
2021-02-16 09:09:36 +00:00
|
|
|
end
|
|
|
|
|
2021-05-06 18:10:06 +00:00
|
|
|
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
|
|
|
|
|
2021-11-18 15:10:19 +00:00
|
|
|
def onboarding_project_data(project)
|
|
|
|
{ name: project.name }
|
|
|
|
end
|
|
|
|
|
2021-02-16 09:09:36 +00:00
|
|
|
def action_urls
|
2021-04-30 12:12:30 +00:00
|
|
|
LearnGitlab::Onboarding::ACTION_ISSUE_IDS.transform_values { |id| project_issue_url(learn_gitlab_project, id) }
|
|
|
|
.merge(LearnGitlab::Onboarding::ACTION_DOC_URLS)
|
2021-02-16 09:09:36 +00:00
|
|
|
end
|
|
|
|
|
2021-10-28 18:14:18 +00:00
|
|
|
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
|
|
|
|
|
2021-02-16 09:09:36 +00:00
|
|
|
def learn_gitlab_project
|
2021-04-30 12:12:30 +00:00
|
|
|
@learn_gitlab_project ||= LearnGitlab::Project.new(current_user).project
|
2021-02-16 09:09:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def onboarding_progress(project)
|
|
|
|
OnboardingProgress.find_by(namespace: project.namespace) # rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|
2021-10-28 18:14:18 +00:00
|
|
|
|
|
|
|
LearnGitlabHelper.prepend_mod_with('LearnGitlabHelper')
|