-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2929 from alphagov/create-edit-finder-form-filter…
…s-and-options Create 'edit finder' form: "Filters and options"
- Loading branch information
Showing
20 changed files
with
827 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//= require govuk_publishing_components/dependencies | ||
//= require govuk_publishing_components/lib | ||
//= require govuk_publishing_components/components/add-another | ||
//= require govuk_publishing_components/components/copy-to-clipboard | ||
|
||
//= require components/autocomplete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.js-add-another__fieldset { | ||
background-color: govuk-colour("light-grey"); | ||
padding: 1em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// stylelint-disable max-nesting-depth | ||
|
||
// Diff of two editions | ||
|
||
$added-color: #ddffdd; | ||
$strong-added-color: #77f177; | ||
$removed-color: #ffdddd; | ||
$strong-removed-color: #ffaaaa; | ||
$gray-lighter: govuk-colour("light-grey"); | ||
$state-danger-text: govuk-colour("red"); | ||
$state-success-text: govuk-colour("green"); | ||
|
||
.diff { | ||
border: 1px solid $gray-lighter; | ||
border-left: 40px solid $gray-lighter; | ||
border-radius: 3px; | ||
padding: 15px; | ||
|
||
ul { | ||
padding-left: 0; | ||
|
||
li { | ||
min-height: 24px; | ||
margin: 0 -15px; | ||
padding: 0 15px; | ||
word-wrap: break-word; | ||
list-style: none; | ||
position: relative; | ||
|
||
del, | ||
ins { | ||
text-decoration: none; | ||
} | ||
} | ||
|
||
.del, | ||
.ins { | ||
padding-top: 2px; | ||
} | ||
|
||
.del { | ||
background-color: $removed-color; | ||
|
||
strong { | ||
font-weight: normal; | ||
background-color: $strong-removed-color; | ||
} | ||
} | ||
|
||
.ins { | ||
background-color: $added-color; | ||
|
||
strong { | ||
font-weight: normal; | ||
background-color: $strong-added-color; | ||
} | ||
} | ||
|
||
.del::before, | ||
.ins::before { | ||
position: absolute; | ||
font-weight: bold; | ||
margin-left: -55px; | ||
width: 40px; | ||
text-align: center; | ||
min-height: 24px; | ||
top: 0; | ||
bottom: 0; | ||
} | ||
|
||
.del::before { | ||
color: $state-danger-text; | ||
background-color: $removed-color; | ||
content: "-"; | ||
} | ||
|
||
.ins::before { | ||
color: $state-success-text; | ||
background-color: $added-color; | ||
content: "+"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class Facet | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
attribute :key | ||
attribute :name | ||
attribute :short_name | ||
attribute :type | ||
attribute :preposition | ||
attribute :display_as_result_metadata, :boolean | ||
attribute :filterable, :boolean | ||
attribute :allowed_values | ||
attribute :specialist_publisher_properties | ||
|
||
def to_finder_schema_attributes | ||
{ | ||
key:, | ||
name:, | ||
short_name:, | ||
type:, | ||
preposition:, | ||
display_as_result_metadata:, | ||
filterable:, | ||
allowed_values:, | ||
specialist_publisher_properties:, | ||
}.compact | ||
end | ||
|
||
class << self | ||
def from_finder_admin_form_params(params) | ||
facet = new | ||
facet.key = facet_key(params["key"], params["name"]) | ||
facet.name = params["name"] | ||
facet.short_name = nil_if_blank(params["short_name"]) | ||
facet.type = facet_type(params["type"]) | ||
facet.preposition = nil_if_blank(params["preposition"]) | ||
facet.display_as_result_metadata = params["display_as_result_metadata"] | ||
facet.filterable = params["filterable"] | ||
facet.allowed_values = facet_allowed_values(params["allowed_values"], params["type"]) | ||
facet.specialist_publisher_properties = facet_specialist_publisher_properties(params["type"]) | ||
facet | ||
end | ||
|
||
private | ||
|
||
def facet_key(key, name) | ||
key.presence || name&.gsub(" ", "")&.underscore | ||
end | ||
|
||
def nil_if_blank(str) | ||
str.presence | ||
end | ||
|
||
def facet_type(type) | ||
facet_types_that_allow_enum_values.include?(type) ? "text" : type | ||
end | ||
|
||
def facet_allowed_values(values, type) | ||
return nil if values.nil? || facet_types_that_allow_enum_values.exclude?(type) | ||
|
||
values.split("\n").map do |str| | ||
label = str.match(/^(.+){/) | ||
label = label.nil? ? str.strip : label[1].strip | ||
value = str.match(/{(.+)}/) | ||
value = value.nil? ? str.strip.downcase.gsub(/[^\w\d\s]/, "").gsub(/\s/u, "-") : value[1].strip | ||
{ label:, value: } | ||
end | ||
end | ||
|
||
def facet_specialist_publisher_properties(type) | ||
case type | ||
when "enum_text_multiple" | ||
{ select: "multiple" } | ||
when "enum_text_single" | ||
{ select: "one" } | ||
end | ||
end | ||
|
||
def facet_types_that_allow_enum_values | ||
%w[enum_text_multiple enum_text_single] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<% facet ||= {} %> | ||
<input type="hidden" name="facets[<%= index %>][key]" value="<%=facet["key"]%>"> | ||
|
||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Filter", | ||
heading_size: "s", | ||
}, | ||
name: "facets[#{index}][name]", | ||
value: facet["name"], | ||
hint: "Example: Disease control zone type" | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Filter short name (optional)", | ||
heading_size: "s", | ||
}, | ||
name: "facets[#{index}][short_name]", | ||
value: facet["short_name"], | ||
hint: "Example: Control zone type" | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/select", { | ||
id: "facets-#{index}-type", | ||
name: "facets[#{index}][type]", | ||
label: "Type", | ||
options: [ | ||
{ | ||
text: "Multiple select", | ||
value: "enum_text_multiple", # Temporary value for the form only. It ends up as "text" in the schema, and "allowed_values" is retained | ||
selected: facet.dig("specialist_publisher_properties", "select") == "multiple", | ||
}, | ||
{ | ||
text: "One option", | ||
value: "enum_text_single", # Temporary value for the form only. It ends up as "text" in the schema, and "allowed_values" is retained | ||
selected: facet.dig("specialist_publisher_properties", "select") == "one", | ||
}, | ||
{ | ||
text: "Free text", | ||
value: "text", # Ends up as "text" in the schema, and deletes any submitted "allowed_values" value | ||
selected: facet["type"] == "text" && facet["allowed_values"].nil?, | ||
}, | ||
{ | ||
text: "Date", | ||
value: "date", | ||
selected: facet["type"] == "date", | ||
} | ||
] | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/textarea", { | ||
label: { | ||
text: "Filter options ('Multiple select' or 'One option' only)", | ||
heading_size: "s", | ||
}, | ||
hint: sanitize("Put each option on a new line. The underlying name for existing (live) options will appear in curly braces: please don't edit these, and don't add them for new options (they'll be created automatically later on in the process). Example:<br><strong>Pre-existing value {pre-existing-value}</strong><br><strong>New value</strong>"), | ||
name: "facets[#{index}][allowed_values]", | ||
rows: 5, | ||
value: facet["allowed_values"]&.map { |opt| "#{opt["label"]} {#{opt["value"]}}" }&.join("\n"), | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/radio", { | ||
heading: "Can users use this filter when searching for content items?", | ||
heading_size: "s", | ||
name: "facets[#{index}][filterable]", | ||
inline: true, | ||
items: [ | ||
{ | ||
value: "true", | ||
text: "Yes", | ||
checked: facet["filterable"] | ||
}, | ||
{ | ||
value: "false", | ||
text: "No", | ||
checked: !facet["filterable"] | ||
} | ||
] | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/radio", { | ||
heading: "Show as information under content item?", | ||
heading_size: "s", | ||
hint: "Example: Air Accidents Investigation Branch reports displays ‘Aircraft category: Commercial - fixed wing’ under relevant content items", | ||
name: "facets[#{index}][display_as_result_metadata]", | ||
inline: true, | ||
items: [ | ||
{ | ||
value: "true", | ||
text: "Yes", | ||
checked: facet["display_as_result_metadata"] | ||
}, | ||
{ | ||
value: "false", | ||
text: "No", | ||
checked: !facet["display_as_result_metadata"] | ||
} | ||
] | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Preposition (to be displayed when filter option is selected)", | ||
heading_size: "s", | ||
}, | ||
name: "facets[#{index}][preposition]", | ||
value: facet["preposition"], | ||
hint: "Example: In Find funding for land or farms, selecting an option in the filter ‘Area of interest’ displays the preposition ‘With’ before the selected option" | ||
} %> |
Oops, something went wrong.