Skip to content

Commit

Permalink
Prevent defailt template loaded when new.js is called.
Browse files Browse the repository at this point in the history
  • Loading branch information
akiko-pusu committed Jun 30, 2020
1 parent 0333527 commit 2f46a68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions app/controllers/issue_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def set_pulldown
add_templates_to_group(@inherit_templates, class: 'inherited')
add_templates_to_group(@global_templates, class: 'global')

is_triggered_by = request.parameters[:is_triggered_by]
is_update_issue = request.parameters[:is_update_issue]
@group[@default_template].selected = 'selected' if @default_template.present? && (is_update_issue.blank? || is_update_issue != 'true')
if loadable_trigger?
@group[@default_template].selected = 'selected'
end

render action: '_template_pulldown', layout: false,
locals: { is_triggered_by: is_triggered_by, grouped_options: @group,
locals: { is_triggered_by: request.parameters[:is_triggered_by], grouped_options: @group,
should_replaced: setting.should_replaced, default_template: @default_template }
end

Expand Down Expand Up @@ -233,4 +233,12 @@ def render_form_params
locals: { issue_template: template, project: @project, child_project_used_count: child_project_used_count,
checklist_enabled: checklist_enabled?, custom_fields: custom_fields.to_s, builtin_fields_enable: builtin_fields_enabled? } }
end

def loadable_trigger?
is_triggered_by = request.parameters[:is_triggered_by]
is_update_issue = request.parameters[:is_update_issue]

return false if is_triggered_by.present? && is_triggered_by != 'is_update_issue'
return @default_template.present? && (is_update_issue.blank? || is_update_issue != 'true')
end
end
3 changes: 2 additions & 1 deletion app/views/issue_templates/_issue_select_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
confirmMessage: '<%=h l(:label_template_applied, default: "Issue template is applied. You can revert with click 'Revert' link.") %>'
}

var templateNS = templateNS || new ISSUE_TEMPLATE(templateConfig);
var templateNS = templateNS || new ISSUE_TEMPLATE(templateConfig)
templateNS.isTriggeredBy = '<%= is_triggered_by %>'
templateNS.setPulldown('<%= @issue.tracker.id %>')

document.getElementById('issue_template').addEventListener('change', (event) => {
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/issue_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ ISSUE_TEMPLATE.prototype = {
},
setPulldown: function (tracker) {
let ns = this
let params = { issue_tracker_id: tracker }
let params = { issue_tracker_id: tracker, is_triggered_by: ns.isTriggeredBy }
let pullDownProject = document.getElementById('issue_project_id')
if (pullDownProject) {
params.issue_project_id = pullDownProject.value
Expand Down

0 comments on commit 2f46a68

Please sign in to comment.