diff options
Diffstat (limited to 'app/helpers/issuables_description_templates_helper.rb')
-rw-r--r-- | app/helpers/issuables_description_templates_helper.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/app/helpers/issuables_description_templates_helper.rb b/app/helpers/issuables_description_templates_helper.rb index 110b3954900..5f69098de56 100644 --- a/app/helpers/issuables_description_templates_helper.rb +++ b/app/helpers/issuables_description_templates_helper.rb @@ -5,7 +5,8 @@ module IssuablesDescriptionTemplatesHelper include GitlabRoutingHelper def template_dropdown_tag(issuable, &block) - title = selected_template(issuable) || "Choose a template" + selected_template = selected_template(issuable) + title = selected_template || "Choose a template" options = { toggle_class: 'js-issuable-selector', title: title, @@ -15,7 +16,7 @@ module IssuablesDescriptionTemplatesHelper data: { data: issuable_templates(ref_project, issuable.to_ability_name), field_name: 'issuable_template', - selected: selected_template(issuable), + selected: selected_template, project_id: ref_project.id } } @@ -28,15 +29,21 @@ module IssuablesDescriptionTemplatesHelper def issuable_templates(project, issuable_type) @template_types ||= {} @template_types[project.id] ||= {} - @template_types[project.id][issuable_type] ||= TemplateFinder.all_template_names_array(project, issuable_type.pluralize) + @template_types[project.id][issuable_type] ||= TemplateFinder.all_template_names_hash_or_array(project, issuable_type) end def issuable_templates_names(issuable) - issuable_templates(ref_project, issuable.to_ability_name).map { |template| template[:name] } + all_templates = issuable_templates(ref_project, issuable.to_ability_name) + + if ref_project.inherited_issuable_templates_enabled? + all_templates.values.flatten.map { |tpl| tpl[:name] if tpl[:project_id] == ref_project.id }.compact.uniq + else + all_templates.map { |template| template[:name] } + end end def selected_template(issuable) - params[:issuable_template] if issuable_templates(ref_project, issuable.to_ability_name).any? { |template| template[:name] == params[:issuable_template] } + params[:issuable_template] if issuable_templates_names(issuable).any? { |tmpl_name| tmpl_name == params[:issuable_template] } end def template_names_path(parent, issuable) |