2021-02-16 04:09:36 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module LearnGitlabHelper
|
2022-03-15 14:08:10 -04:00
|
|
|
IMAGE_PATH_PLAN = "learn_gitlab/section_plan.svg"
|
|
|
|
IMAGE_PATH_DEPLOY = "learn_gitlab/section_deploy.svg"
|
|
|
|
IMAGE_PATH_WORKSPACE = "learn_gitlab/section_workspace.svg"
|
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
def learn_gitlab_enabled?(project)
|
2021-02-16 04:09:36 -05:00
|
|
|
return false unless current_user
|
|
|
|
|
|
|
|
learn_gitlab_onboarding_available?(project)
|
|
|
|
end
|
|
|
|
|
2021-11-17 13:14:12 -05:00
|
|
|
def learn_gitlab_data(project)
|
|
|
|
{
|
|
|
|
actions: onboarding_actions_data(project).to_json,
|
2021-11-18 10:10:19 -05:00
|
|
|
sections: onboarding_sections_data.to_json,
|
|
|
|
project: onboarding_project_data(project).to_json
|
2021-11-17 13:14:12 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def learn_gitlab_onboarding_available?(project)
|
|
|
|
OnboardingProgress.onboarding?(project.namespace) &&
|
|
|
|
LearnGitlab::Project.new(current_user).available?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-02-16 04:09:36 -05:00
|
|
|
def onboarding_actions_data(project)
|
|
|
|
attributes = onboarding_progress(project).attributes.symbolize_keys
|
|
|
|
|
2022-03-15 14:08:10 -04:00
|
|
|
action_urls(project).to_h do |action, url|
|
2021-02-16 04:09:36 -05:00
|
|
|
[
|
|
|
|
action,
|
|
|
|
url: url,
|
2021-02-23 13:10:40 -05:00
|
|
|
completed: attributes[OnboardingProgress.column_name(action)].present?,
|
2022-04-20 20:10:20 -04:00
|
|
|
svg: image_path("learn_gitlab/#{action}.svg"),
|
|
|
|
enabled: true
|
2021-02-16 04:09:36 -05:00
|
|
|
]
|
2021-03-28 11:09:30 -04:00
|
|
|
end
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
|
2021-05-06 14:10:06 -04:00
|
|
|
def onboarding_sections_data
|
|
|
|
{
|
|
|
|
workspace: {
|
2022-03-15 14:08:10 -04:00
|
|
|
svg: image_path(IMAGE_PATH_WORKSPACE)
|
2021-05-06 14:10:06 -04:00
|
|
|
},
|
|
|
|
plan: {
|
2022-03-15 14:08:10 -04:00
|
|
|
svg: image_path(IMAGE_PATH_PLAN)
|
2021-05-06 14:10:06 -04:00
|
|
|
},
|
|
|
|
deploy: {
|
2022-03-15 14:08:10 -04:00
|
|
|
svg: image_path(IMAGE_PATH_DEPLOY)
|
2021-05-06 14:10:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-11-18 10:10:19 -05:00
|
|
|
def onboarding_project_data(project)
|
|
|
|
{ name: project.name }
|
|
|
|
end
|
|
|
|
|
2022-03-15 14:08:10 -04:00
|
|
|
def action_urls(project)
|
|
|
|
action_issue_urls.merge(
|
2021-10-28 14:14:18 -04:00
|
|
|
issue_created: project_issues_path(project),
|
|
|
|
git_write: project_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
|
|
|
|
|
2022-03-15 14:08:10 -04:00
|
|
|
def action_issue_urls
|
|
|
|
LearnGitlab::Onboarding::ACTION_ISSUE_IDS.transform_values { |id| project_issue_url(learn_gitlab_project, id) }
|
|
|
|
end
|
|
|
|
|
2021-02-16 04:09:36 -05:00
|
|
|
def learn_gitlab_project
|
2021-04-30 08:12:30 -04:00
|
|
|
@learn_gitlab_project ||= LearnGitlab::Project.new(current_user).project
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def onboarding_progress(project)
|
|
|
|
OnboardingProgress.find_by(namespace: project.namespace) # rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|
2021-10-28 14:14:18 -04:00
|
|
|
|
|
|
|
LearnGitlabHelper.prepend_mod_with('LearnGitlabHelper')
|