From ed1b49d6c310dc4e7d8da0572e54f491594f539a Mon Sep 17 00:00:00 2001 From: Christian Sutter Date: Sun, 26 Nov 2023 15:04:12 +0000 Subject: [PATCH] Add parts to results that have them --- app/assets/stylesheets/search.scss | 9 +++++++++ app/models/result.rb | 6 +++++- app/models/search.rb | 1 + app/views/searches/_result.html.erb | 6 ++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/search.scss b/app/assets/stylesheets/search.scss index c40558e..bfa39e3 100644 --- a/app/assets/stylesheets/search.scss +++ b/app/assets/stylesheets/search.scss @@ -51,6 +51,15 @@ margin: govuk-spacing(2) 0 0 0; } +.search-results__parts { + margin: govuk-spacing(2) 0 0 0; + padding: govuk-spacing(1); + border-radius: govuk-spacing(1); + + background-color: govuk-colour("blue"); + color: govuk-colour("white"); +} + .search-results__metadata { margin: govuk-spacing(2) 0 0 0; } diff --git a/app/models/result.rb b/app/models/result.rb index d39f826..ff99594 100644 --- a/app/models/result.rb +++ b/app/models/result.rb @@ -1,5 +1,9 @@ class Result include ActiveModel::Model - attr_accessor :title, :description, :link, :content_id, :document_type, :public_timestamp + attr_accessor :title, :description, :link, :content_id, :document_type, :public_timestamp, :parts + + def parts? + parts.any? + end end diff --git a/app/models/search.rb b/app/models/search.rb index 3252c61..713ecf1 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -20,6 +20,7 @@ def results content_id: result["content_id"], document_type: result["content_store_document_type"], public_timestamp: timestamp, + parts: (result["parts"] || []).map { |part| part["title"] }, ) end end diff --git a/app/views/searches/_result.html.erb b/app/views/searches/_result.html.erb index 40ccb9c..a22b9a3 100644 --- a/app/views/searches/_result.html.erb +++ b/app/views/searches/_result.html.erb @@ -5,6 +5,12 @@

<%= result.link %>

<%= result.description %>

+ <% if result.parts? %> +

+ Parts: + <%= result.parts.join(", ") %> +

+ <% end %> <% if show_metadata? %>