Skip to content

Commit

Permalink
Merge pull request #8265 from alphagov/1544-fix-consultation-response…
Browse files Browse the repository at this point in the history
…-form-bug

Fix ConsultationResponseForm & CallForEvidenceResponseForm bug
  • Loading branch information
davidgisbey authored Sep 19, 2023
2 parents 3ffcfee + bd1d783 commit 44cefdf
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 197 deletions.
7 changes: 7 additions & 0 deletions app/controllers/admin/calls_for_evidence_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ def cope_with_call_for_evidence_response_form_data_action_params
def document_can_be_previously_published
false
end

def build_edition_dependencies
super
participation = @edition.call_for_evidence_participation || @edition.build_call_for_evidence_participation
response_form = participation.call_for_evidence_response_form || participation.build_call_for_evidence_response_form
response_form.call_for_evidence_response_form_data || response_form.build_call_for_evidence_response_form_data
end
end
7 changes: 7 additions & 0 deletions app/controllers/admin/consultations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ def cope_with_consultation_response_form_data_action_params
def document_can_be_previously_published
false
end

def build_edition_dependencies
super
participation = @edition.consultation_participation || @edition.build_consultation_participation
response_form = participation.consultation_response_form || participation.build_consultation_response_form
response_form.consultation_response_form_data || response_form.build_consultation_response_form_data
end
end
2 changes: 1 addition & 1 deletion app/models/call_for_evidence_response_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CallForEvidenceResponseForm < ApplicationRecord

delegate :url, :file, to: :call_for_evidence_response_form_data

validates :title, presence: true
validates :title, :call_for_evidence_response_form_data, presence: true

accepts_nested_attributes_for :call_for_evidence_response_form_data

Expand Down
2 changes: 1 addition & 1 deletion app/models/consultation_response_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ConsultationResponseForm < ApplicationRecord

delegate :url, :file, to: :consultation_response_form_data

validates :title, presence: true
validates :title, :consultation_response_form_data, presence: true

accepts_nested_attributes_for :consultation_response_form_data

Expand Down
197 changes: 100 additions & 97 deletions app/views/admin/calls_for_evidence/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,113 +45,116 @@
heading_level: 3,
heading_size: "l"
} do %>
<% call_for_evidence_participation = edition.call_for_evidence_participation || edition.build_call_for_evidence_participation %>
<%= hidden_field_tag "edition[call_for_evidence_participation_attributes][id]", call_for_evidence_participation.id %>

<%= render "govuk_publishing_components/components/input", {
label: {
text: "Link URL",
},
name: "edition[call_for_evidence_participation_attributes][link_url]",
id: "edition_call_for_evidence_participation_link_url",
heading_size: "m",
value: call_for_evidence_participation.link_url,
error_items: errors_for(call_for_evidence_participation.errors, :link_url),
} %>

<%= render "govuk_publishing_components/components/input", {
label: {
text: "Email",
},
name: "edition[call_for_evidence_participation_attributes][email]",
id: "edition_call_for_evidence_participation_email",
heading_size: "m",
value: call_for_evidence_participation.email,
error_items: errors_for(call_for_evidence_participation.errors, :email),
} %>
<% call_for_evidence_participation = edition.call_for_evidence_participation %>

<%= render "govuk_publishing_components/components/textarea", {
label: {
text: "Postal address",
<%= form.fields_for :call_for_evidence_participation, call_for_evidence_participation do |call_for_evidence_participation_form| %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Link URL",
},
name: "edition[call_for_evidence_participation_attributes][link_url]",
id: "edition_call_for_evidence_participation_link_url",
heading_size: "m",
},
name: "edition[call_for_evidence_participation_attributes][postal_address]",
id: "edition_call_for_evidence_participation_postal_address",
value: call_for_evidence_participation.postal_address,
error_items: errors_for(call_for_evidence_participation.errors, :postal_address),
rows: 4,
} %>

<% call_for_evidence_response_form = call_for_evidence_participation.call_for_evidence_response_form || call_for_evidence_participation.build_call_for_evidence_response_form %>
<% call_for_evidence_response_form_data = call_for_evidence_response_form.call_for_evidence_response_form_data || call_for_evidence_response_form.build_call_for_evidence_response_form_data %>

<%= render "govuk_publishing_components/components/input", {
label: {
text: "Downloadable response form title",
},
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][title]",
id: "edition_call_for_evidence_participation_call_for_evidence_response_form_title",
heading_size: "m",
value: call_for_evidence_response_form.title,
error_items: errors_for(call_for_evidence_response_form.errors, :title),
} %>

<% if call_for_evidence_response_form.call_for_evidence_response_form_data.try(:persisted?) %>
<div class="attachment">
<p class="govuk-body">Current data: <%= link_to File.basename(call_for_evidence_response_form.call_for_evidence_response_form_data.file.path), call_for_evidence_response_form.call_for_evidence_response_form_data.file.url, class: "govuk-link" %></p>
value: call_for_evidence_participation.link_url,
error_items: errors_for(call_for_evidence_participation.errors, :link_url),
} %>

<%= hidden_field_tag "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][call_for_evidence_response_form_data_attributes][file_cache]", call_for_evidence_response_form_data.file_cache %>
<%= hidden_field_tag "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][call_for_evidence_response_form_data_attributes][id]", call_for_evidence_response_form_data.id %>
<%= hidden_field_tag "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][id]", call_for_evidence_response_form.id %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Email",
},
name: "edition[call_for_evidence_participation_attributes][email]",
id: "edition_call_for_evidence_participation_email",
heading_size: "m",
value: call_for_evidence_participation.email,
error_items: errors_for(call_for_evidence_participation.errors, :email),
} %>

<%= render "govuk_publishing_components/components/radio", {
heading: "Actions:",
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][attachment_action]",
id: "edition_call_for_evidence_participation_call_for_evidence_response_form_attachment_action",
heading_size: "m",
error_items: errors_for(call_for_evidence_response_form.errors, :attachment_action),
items: [
{
value: "keep",
text: "Keep",
checked: ["keep", nil].include?(params.dig("edition", "call_for_evidence_participation_attributes", "call_for_evidence_response_form_attributes", "attachment_action")),
},
{
value: "remove",
text: "Remove",
checked: params.dig("edition", "call_for_evidence_participation_attributes", "call_for_evidence_response_form_attributes", "attachment_action") == "remove",
},
{
value: "replace",
text: "Replace",
checked: params.dig("edition", "call_for_evidence_participation_attributes", "call_for_evidence_response_form_attributes", "attachment_action") == "replace",
conditional: render("govuk_publishing_components/components/file_upload", {
label: {
text: "Replacement"
},
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][call_for_evidence_response_form_data_attributes][file]",
id: "edition_call_for_evidence_participation_attributes_call_for_evidence_response_form_call_for_evidence_response_form_data_file",
error_items: errors_for(call_for_evidence_response_form_data.errors, :file),
}
)
}
]
} %>
</div>
<% else %>
<%= render "govuk_publishing_components/components/file_upload", {
<%= render "govuk_publishing_components/components/textarea", {
label: {
text: "File",
text: "Postal address",
heading_size: "m",
},
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][call_for_evidence_response_form_data_attributes][file]",
id: "edition_call_for_evidence_participation_call_for_evidence_response_form_call_for_evidence_response_form_data_file",
error_items: errors_for(call_for_evidence_response_form_data.errors, :file),
name: "edition[call_for_evidence_participation_attributes][postal_address]",
id: "edition_call_for_evidence_participation_postal_address",
value: call_for_evidence_participation.postal_address,
error_items: errors_for(call_for_evidence_participation.errors, :postal_address),
rows: 4,
} %>
<% if call_for_evidence_response_form_data.file_cache.present? %>
<%= hidden_field_tag "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][call_for_evidence_response_form_data_attributes][file_cache]", call_for_evidence_response_form_data.file_cache %>

<p class="govuk-body already-uploaded"><%= "#{File.basename(call_for_evidence_response_form_data.file_cache)} already uploaded" %></p>
<% call_for_evidence_response_form = call_for_evidence_participation.call_for_evidence_response_form %>

<%= call_for_evidence_participation_form.fields_for :call_for_evidence_response_form, call_for_evidence_response_form do |response_form| %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Downloadable response form title",
},
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][title]",
id: "edition_call_for_evidence_participation_call_for_evidence_response_form_title",
heading_size: "m",
value: call_for_evidence_response_form.title,
error_items: errors_for(call_for_evidence_response_form.errors, :title),
} %>

<% call_for_evidence_response_form_data = call_for_evidence_response_form.call_for_evidence_response_form_data %>

<%= response_form.fields_for :call_for_evidence_response_form_data, call_for_evidence_response_form_data do |call_for_evidence_response_form_data_form| %>
<%= call_for_evidence_response_form_data_form.hidden_field :file_cache, value: call_for_evidence_response_form_data.file_cache %>

<% if call_for_evidence_response_form.call_for_evidence_response_form_data.try(:persisted?) %>
<div class="attachment">
<p class="govuk-body">Current data: <%= link_to File.basename(call_for_evidence_response_form_data.file.path), call_for_evidence_response_form_data.file.url, class: "govuk-link" %></p>

<%= render "govuk_publishing_components/components/radio", {
heading: "Actions:",
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][attachment_action]",
id: "edition_call_for_evidence_participation_call_for_evidence_response_form_attachment_action",
heading_size: "m",
error_items: errors_for(call_for_evidence_response_form.errors, :attachment_action),
items: [
{
value: "keep",
text: "Keep",
checked: ["keep", nil].include?(params.dig("edition", "call_for_evidence_participation_attributes", "call_for_evidence_response_form_attributes", "attachment_action")),
},
{
value: "remove",
text: "Remove",
checked: params.dig("edition", "call_for_evidence_participation_attributes", "call_for_evidence_response_form_attributes", "attachment_action") == "remove",
},
{
value: "replace",
text: "Replace",
checked: params.dig("edition", "call_for_evidence_participation_attributes", "call_for_evidence_response_form_attributes", "attachment_action") == "replace",
conditional: render("govuk_publishing_components/components/file_upload", {
label: {
text: "Replacement"
},
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][call_for_evidence_response_form_data_attributes][file]",
id: "edition_call_for_evidence_participation_attributes_call_for_evidence_response_form_call_for_evidence_response_form_data_file",
error_items: errors_for(call_for_evidence_response_form_data.errors, :file) || errors_for(call_for_evidence_response_form.errors, :call_for_evidence_response_form_data),
}
)
}
]
} %>
</div>
<% else %>
<%= render "govuk_publishing_components/components/file_upload", {
label: {
text: "File",
heading_size: "m",
},
name: "edition[call_for_evidence_participation_attributes][call_for_evidence_response_form_attributes][call_for_evidence_response_form_data_attributes][file]",
id: "edition_call_for_evidence_participation_call_for_evidence_response_form_call_for_evidence_response_form_data_file",
error_items: errors_for(call_for_evidence_response_form_data.errors, :file) || errors_for(call_for_evidence_response_form.errors, :call_for_evidence_response_form_data),
} %>
<% if call_for_evidence_response_form_data.file_cache.present? %>
<p class="govuk-body already-uploaded"><%= "#{File.basename(call_for_evidence_response_form_data.file_cache)} already uploaded" %></p>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
Expand Down
Loading

0 comments on commit 44cefdf

Please sign in to comment.