Browse Source

Format bullet lists

pull/484/head
baarkerlounger 3 years ago
parent
commit
5b4dc5a16c
  1. 10
      app/helpers/details_table_helper.rb
  2. 6
      app/models/organisation.rb
  3. 4
      app/views/organisations/show.html.erb
  4. 32
      spec/helpers/table_details_helper_spec.rb

10
app/helpers/details_table_helper.rb

@ -0,0 +1,10 @@
module DetailsTableHelper
def details_html(attribute)
if attribute[:format] == :bullet
list = attribute[:value].map { |la| "<li>#{la}</li>"}.join("\n")
simple_format(list, { class: "govuk-list govuk-list--bullet" }, wrapper_tag: "ul")
else
simple_format(attribute[:value].to_s, {}, wrapper_tag: "div")
end
end
end

6
app/models/organisation.rb

@ -36,13 +36,17 @@ class Organisation < ApplicationRecord
!!data_protection_confirmations.order(created_at: :desc).first&.confirmed !!data_protection_confirmations.order(created_at: :desc).first&.confirmed
end end
def local_authorities
organisation_las.pluck(:ons_code)
end
def display_attributes def display_attributes
[ [
{ name: "name", value: name, editable: true }, { name: "name", value: name, editable: true },
{ name: "address", value: address_string, editable: true }, { name: "address", value: address_string, editable: true },
{ name: "telephone_number", value: phone, editable: true }, { name: "telephone_number", value: phone, editable: true },
{ name: "type", value: "Org type", editable: false }, { name: "type", value: "Org type", editable: false },
{ name: "local_authorities_operated_in", value: local_authorities, editable: false }, { name: "local_authorities_operated_in", value: local_authorities, editable: false, format: :bullet },
{ name: "holds_own_stock", value: holds_own_stock.to_s.humanize, editable: false }, { name: "holds_own_stock", value: holds_own_stock.to_s.humanize, editable: false },
{ name: "other_stock_owners", value: other_stock_owners, editable: false }, { name: "other_stock_owners", value: other_stock_owners, editable: false },
{ name: "managing_agents", value: managing_agents, editable: false }, { name: "managing_agents", value: managing_agents, editable: false },

4
app/views/organisations/show.html.erb

@ -12,7 +12,7 @@
<% if can_edit_org?(current_user) && attr[:editable] %> <% if can_edit_org?(current_user) && attr[:editable] %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s.humanize } %> <% row.key { attr[:name].to_s.humanize } %>
<% row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } %> <% row.value { details_html(attr) } %>
<% row.action( <% row.action(
visually_hidden_text: "name", visually_hidden_text: "name",
href: edit_organisation_path, href: edit_organisation_path,
@ -22,7 +22,7 @@
<% else %> <% else %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s.humanize } %> <% row.key { attr[:name].to_s.humanize } %>
<% row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } %> <% row.value { details_html(attr) } %>
<% row.action %> <% row.action %>
<% end %> <% end %>
<% end %> <% end %>

32
spec/helpers/table_details_helper_spec.rb

@ -0,0 +1,32 @@
require "rails_helper"
RSpec.describe DetailsTableHelper do
describe "details html" do
subject { details_html(attribute) }
context "when given a simple attribute" do
let(:attribute) { { name: "name", value: "Dummy org", editable: true } }
it "displays the string wrapped in a div" do
expect(subject).to eq("<div>Dummy org</div>")
end
end
context "when given a bullet point list of attibutes" do
let(:list) { ["Camden", "Westminster", "Bristol"] }
let(:attribute) do
{
name: "local_authorities_operated_in",
value: list,
editable: false,
format: :bullet,
}
end
it "displays the string wrapped in an unordered list with the correct classes" do
expect(subject).to eq("<ul class=\"govuk-list govuk-list--bullet\"><li>Camden</li>\n<br /><li>Westminster</li>\n<br /><li>Bristol</li></ul>")
end
end
end
end
Loading…
Cancel
Save