Compare commits
18 Commits
17ca477719
...
6a954a42a4
Author | SHA1 | Date |
---|---|---|
Manny Dinssa | 6a954a42a4 | 6 days ago |
Manny Dinssa | 603523d168 | 1 week ago |
Manny Dinssa | 543733c284 | 1 week ago |
Manny Dinssa | 0d0338e76a | 1 week ago |
Manny Dinssa | e4e9e33869 | 1 week ago |
Rachael Booth | 32ea130340 | 1 week ago |
Manny Dinssa | b0ce9e63dd | 1 week ago |
Manny Dinssa | 3bf30de51a | 1 week ago |
Manny Dinssa | 9977cce7d0 | 1 week ago |
Manny Dinssa | fc837b7cf7 | 1 week ago |
Manny Dinssa | 1cf324e6e8 | 1 week ago |
Manny Dinssa | 2ac3c4799f | 1 week ago |
Manny Dinssa | 9f422fb53a | 1 week ago |
Manny Dinssa | c20363ceae | 1 week ago |
Manny Dinssa | a3240e5d16 | 1 week ago |
Manny Dinssa | 59ecac5cf3 | 1 week ago |
Manny Dinssa | b74fd830f1 | 1 week ago |
Manny Dinssa | b64d73d942 | 1 week ago |
56 changed files with 287 additions and 288 deletions
@ -1,42 +1,42 @@
|
||||
module DetailsTableHelper |
||||
def details_html(attribute, resource = nil) |
||||
resource_class = resource.class.name |
||||
|
||||
if attribute[:format] == :bullet && attribute[:value].length > 1 |
||||
list = attribute[:value].map { |value| "<li>#{value}</li>" }.join |
||||
simple_format(list, { class: "govuk-list govuk-list--bullet" }, wrapper_tag: "ul") |
||||
else |
||||
return simple_format(attribute[:value].first.to_s, { class: "govuk-body" }, wrapper_tag: "p") if attribute[:value].is_a?(Array) && attribute[:value].any? |
||||
|
||||
value = determine_value(attribute, resource, resource_class) |
||||
value = determine_value(attribute, resource) |
||||
simple_format(value.to_s, { class: "govuk-body" }, wrapper_tag: "p") |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def determine_value(attribute, resource, resource_class) |
||||
attribute[:value].presence || case resource_class |
||||
when "Location" |
||||
location_value(attribute, resource) |
||||
when "Organisation" |
||||
organisation_value(attribute, resource) |
||||
when "Scheme" |
||||
scheme_value(attribute, resource) |
||||
else |
||||
def determine_value(attribute, resource) |
||||
return attribute[:value] if attribute[:value].present? |
||||
|
||||
method_name = "#{resource.class.name.downcase}_value" |
||||
return send(method_name, attribute, resource) if respond_to?(method_name, true) |
||||
|
||||
"<span class=\"app-!-colour-muted\">No answer provided</span>".html_safe |
||||
end |
||||
end |
||||
|
||||
def location_value(attribute, resource) |
||||
LocationPolicy.new(current_user, resource).update? ? govuk_link_to(location_details_link_message(attribute), location_edit_path(resource, attribute[:attribute]), class: "govuk-link govuk-link--no-visited-state") : "<span class=\"app-!-colour-muted\">No answer provided</span>".html_safe |
||||
return nil unless LocationPolicy.new(current_user, resource).update? |
||||
|
||||
govuk_link_to(location_details_link_message(attribute), location_edit_path(resource, attribute[:attribute]), class: "govuk-link govuk-link--no-visited-state") |
||||
end |
||||
|
||||
def organisation_value(attribute, resource) |
||||
can_edit_org?(current_user) && attribute[:editable] ? govuk_link_to(organisation_details_link_message(attribute), edit_organisation_path(resource), class: "govuk-link govuk-link--no-visited-state") : "<span class=\"app-!-colour-muted\">No answer provided</span>".html_safe |
||||
return nil unless can_edit_org?(current_user) && attribute[:editable] |
||||
|
||||
govuk_link_to(organisation_details_link_message(attribute), edit_organisation_path(resource), class: "govuk-link govuk-link--no-visited-state") |
||||
end |
||||
|
||||
def scheme_value(attribute, resource) |
||||
can_change_scheme_answer?(attribute[:name], resource) ? govuk_link_to(scheme_details_link_message(attribute), scheme_edit_path(resource, attribute), class: "govuk-link govuk-link--no-visited-state") : "<span class=\"app-!-colour-muted\">No answer provided</span>".html_safe |
||||
return nil unless can_change_scheme_answer?(attribute[:name], resource) |
||||
|
||||
govuk_link_to(scheme_details_link_message(attribute), scheme_edit_path(resource, attribute[:id]), class: "govuk-link govuk-link--no-visited-state") |
||||
end |
||||
end |
||||
|
Loading…
Reference in new issue