2019-09-10 03:28:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ReleasesHelper
|
|
|
|
IMAGE_PATH = 'illustrations/releases.svg'
|
|
|
|
DOCUMENTATION_PATH = 'user/project/releases/index'
|
|
|
|
|
2021-06-23 11:07:50 -04:00
|
|
|
# This needs to be kept in sync with the constant in
|
|
|
|
# app/assets/javascripts/releases/constants.js
|
|
|
|
DEFAULT_SORT = 'RELEASED_AT_DESC'
|
|
|
|
|
2019-09-10 03:28:43 -04:00
|
|
|
def illustration
|
|
|
|
image_path(IMAGE_PATH)
|
|
|
|
end
|
|
|
|
|
2020-04-01 08:08:00 -04:00
|
|
|
def help_page(anchor: nil)
|
|
|
|
help_page_path(DOCUMENTATION_PATH, anchor: anchor)
|
2019-09-10 03:28:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data_for_releases_page
|
|
|
|
{
|
|
|
|
project_id: @project.id,
|
2020-09-15 11:10:08 -04:00
|
|
|
project_path: @project.full_path,
|
2019-09-10 03:28:43 -04:00
|
|
|
illustration_path: illustration,
|
2019-10-14 17:06:30 -04:00
|
|
|
documentation_path: help_page
|
2020-03-13 08:09:22 -04:00
|
|
|
}.tap do |data|
|
2020-07-09 11:08:59 -04:00
|
|
|
if can?(current_user, :create_release, @project)
|
2021-06-20 20:10:50 -04:00
|
|
|
data[:new_release_path] = new_project_release_path(@project)
|
2020-07-09 11:08:59 -04:00
|
|
|
end
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
2019-09-10 03:28:43 -04:00
|
|
|
end
|
2019-10-16 14:08:01 -04:00
|
|
|
|
2021-06-23 11:07:50 -04:00
|
|
|
# For simplicity, only optimize non-paginated requests
|
|
|
|
def use_startup_query_for_index_page?
|
|
|
|
params[:before].nil? && params[:after].nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_page_startup_query_variables
|
|
|
|
{
|
|
|
|
fullPath: @project.full_path,
|
|
|
|
sort: DEFAULT_SORT,
|
|
|
|
first: 1
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-10-16 05:09:06 -04:00
|
|
|
def data_for_show_page
|
|
|
|
{
|
|
|
|
project_id: @project.id,
|
|
|
|
project_path: @project.full_path,
|
|
|
|
tag_name: @release.tag
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-10-16 14:08:01 -04:00
|
|
|
def data_for_edit_release_page
|
2020-07-09 11:08:59 -04:00
|
|
|
new_edit_pages_shared_data.merge(
|
|
|
|
tag_name: @release.tag,
|
|
|
|
releases_page_path: project_releases_path(@project, anchor: @release.tag)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def data_for_new_release_page
|
|
|
|
new_edit_pages_shared_data.merge(
|
2020-08-11 17:10:09 -04:00
|
|
|
default_branch: @project.default_branch,
|
|
|
|
releases_page_path: project_releases_path(@project)
|
2020-07-09 11:08:59 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-11-10 16:08:51 -05:00
|
|
|
def group_milestone_project_releases_available?(project)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2020-07-09 11:08:59 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def new_edit_pages_shared_data
|
2019-10-16 14:08:01 -04:00
|
|
|
{
|
|
|
|
project_id: @project.id,
|
2020-11-10 16:08:51 -05:00
|
|
|
group_id: @project.group&.id,
|
|
|
|
group_milestones_available: group_milestone_project_releases_available?(@project),
|
2020-10-16 05:09:06 -04:00
|
|
|
project_path: @project.full_path,
|
2019-10-16 14:08:01 -04:00
|
|
|
markdown_preview_path: preview_markdown_path(@project),
|
|
|
|
markdown_docs_path: help_page_path('user/markdown'),
|
2020-05-07 17:09:26 -04:00
|
|
|
release_assets_docs_path: help_page(anchor: 'release-assets'),
|
|
|
|
manage_milestones_path: project_milestones_path(@project),
|
2020-07-09 11:08:59 -04:00
|
|
|
new_milestone_path: new_project_milestone_path(@project)
|
2019-10-16 14:08:01 -04:00
|
|
|
}
|
|
|
|
end
|
2019-09-10 03:28:43 -04:00
|
|
|
end
|
2020-11-10 16:08:51 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
ReleasesHelper.prepend_mod_with('ReleasesHelper')
|