Skip to content

Commit

Permalink
Merge pull request #19 from alphagov/parts
Browse files Browse the repository at this point in the history
Add parts to results that have them
  • Loading branch information
csutter authored Nov 26, 2023
2 parents 8fa4731 + ed1b49d commit bb93141
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/assets/stylesheets/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion app/models/result.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/views/searches/_result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
</h2>
<p class="search-results__url"><%= result.link %></p>
<p class="search-results__description"><%= result.description %></p>
<% if result.parts? %>
<p class="search-results__parts">
<strong>Parts:</strong>
<%= result.parts.join(", ") %>
</p>
<% end %>
<% if show_metadata? %>
<div class="search-results__metadata">
<span class="search-results__metadata-item search-results__metadata-item--content-type">
Expand Down

0 comments on commit bb93141

Please sign in to comment.