2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module IssuablesDescriptionTemplatesHelper
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
include GitlabRoutingHelper
|
|
|
|
|
|
|
|
def template_dropdown_tag(issuable, &block)
|
2021-04-17 20:07:23 +05:30
|
|
|
selected_template = selected_template(issuable)
|
|
|
|
title = selected_template || "Choose a template"
|
2021-03-11 19:13:27 +05:30
|
|
|
options = {
|
|
|
|
toggle_class: 'js-issuable-selector',
|
|
|
|
title: title,
|
|
|
|
filter: true,
|
|
|
|
placeholder: 'Filter',
|
|
|
|
footer_content: true,
|
|
|
|
data: {
|
|
|
|
data: issuable_templates(ref_project, issuable.to_ability_name),
|
|
|
|
field_name: 'issuable_template',
|
2021-04-17 20:07:23 +05:30
|
|
|
selected: selected_template,
|
2021-03-11 19:13:27 +05:30
|
|
|
project_id: ref_project.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dropdown_tag(title, options: options) do
|
|
|
|
capture(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def issuable_templates(project, issuable_type)
|
|
|
|
@template_types ||= {}
|
|
|
|
@template_types[project.id] ||= {}
|
2021-09-04 01:27:46 +05:30
|
|
|
@template_types[project.id][issuable_type] ||= TemplateFinder.all_template_names(project, issuable_type.pluralize)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
# Overriden on EE::IssuablesDescriptionTemplatesHelper to include inherited templates names
|
|
|
|
def issuable_templates_names(issuable, include_inherited_templates = false)
|
2021-04-17 20:07:23 +05:30
|
|
|
all_templates = issuable_templates(ref_project, issuable.to_ability_name)
|
2021-09-04 01:27:46 +05:30
|
|
|
all_templates.values.flatten.map { |tpl| tpl[:name] if tpl[:project_id] == ref_project.id }.compact.uniq
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def selected_template(issuable)
|
2021-10-27 15:23:28 +05:30
|
|
|
params[:issuable_template] if issuable_templates_names(issuable, true).any? { |tmpl_name| tmpl_name == params[:issuable_template] }
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def template_names_path(parent, issuable)
|
|
|
|
return '' unless parent.is_a?(Project)
|
|
|
|
|
|
|
|
project_template_names_path(parent, template_type: issuable.to_ability_name)
|
|
|
|
end
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
IssuablesDescriptionTemplatesHelper.prepend_mod
|