diff --git a/app/helpers/manuals_helper.rb b/app/helpers/manuals_helper.rb new file mode 100644 index 000000000..b26f52c68 --- /dev/null +++ b/app/helpers/manuals_helper.rb @@ -0,0 +1,7 @@ +module ManualsHelper + def sanitize_manual_update_title(title) + return "" if title.nil? + + strip_tags(title).gsub(I18n.t("manuals.updates_amendments"), "").gsub(/\s+/, " ").strip + end +end diff --git a/app/presenters/content_item/manual_updates.rb b/app/presenters/content_item/manual_updates.rb index c52ecb26a..2015c7535 100644 --- a/app/presenters/content_item/manual_updates.rb +++ b/app/presenters/content_item/manual_updates.rb @@ -42,7 +42,7 @@ def marked_up_date(date) formatted_date = I18n.l(date, format: "%-d %B %Y") if date updates_span = view_context.content_tag("span", I18n.t("manuals.updates_amendments"), - class: "visuallyhidden") + class: "govuk-visually-hidden") formatted_date = "#{formatted_date} #{updates_span}" view_context.sanitize(formatted_date) diff --git a/app/views/content_items/manual_section.html.erb b/app/views/content_items/manual_section.html.erb index fb0a6a1aa..052c2bfc5 100644 --- a/app/views/content_items/manual_section.html.erb +++ b/app/views/content_items/manual_section.html.erb @@ -49,20 +49,45 @@ <% end %> <% else %> - <%= render "govuk_publishing_components/components/accordion", { - anchor_navigation: true, - items: @content_item.main.map do |item| + <% + items = @content_item.main.each.with_index(1).map do |item, index| rendered_content = render "govuk_publishing_components/components/govspeak", {} do raw(item[:content]) end { + data_attributes: { + module: "gtm-track-click", + ga4: { + event_name: "select_content", + type: "accordion", + text: item[:heading], + index: index, + index_total: @content_item.main.length, + } + }, heading: item[:heading], content: { html: rendered_content, }, } end + %> + + <% + ga4_attributes = { + event_name: "select_content", + type: "accordion", + index: 0, + index_total: @content_item.main.length, + } + %> + <%= render "govuk_publishing_components/components/accordion", { + data_attributes_show_all: { + "ga4": ga4_attributes.to_json + }, + anchor_navigation: true, + items: items, } %> <% end %> <% end %> diff --git a/app/views/content_items/manuals/_updates.html.erb b/app/views/content_items/manuals/_updates.html.erb index e94c558ad..edef46a7d 100644 --- a/app/views/content_items/manuals/_updates.html.erb +++ b/app/views/content_items/manuals/_updates.html.erb @@ -18,23 +18,45 @@ font_size: "l" } %> + <% + show_all_attributes = { + event_name: "select_content", + type: "accordion", + index: 0, + index_total: updates_by_year.length, + } + %> <%= render "govuk_publishing_components/components/accordion", { heading_level: 3, - items: updates_by_year.map do |day, updated_documents| + data_attributes_show_all: { + "ga4": show_all_attributes.to_json + }, + items: updates_by_year.each.with_index(1).map do |updated_documents, index| accordion_content = capture do %> + <% change_notes = updated_documents.last %>
<%= link_to change_note["title"], change_note["base_path"], class: "govuk-link" %>
- <%= simple_format(change_note["change_note"], class: "govuk-body") %> - <% end %> + <% change_notes.each do |change_note_entry| %> + <% change_note = change_note_entry.flatten.last %> ++ <%= link_to change_note["title"], change_note["base_path"], class: "govuk-link" %> +
+ <%= simple_format(change_note["change_note"], class: "govuk-body") %> <% end %>