Skip to content

Commit

Permalink
Merge pull request #167 from ukparliament/development
Browse files Browse the repository at this point in the history
Development merge
  • Loading branch information
j-corry authored Sep 2, 2024
2 parents 684312d + 1890aff commit a08fa1f
Show file tree
Hide file tree
Showing 8 changed files with 2,925 additions and 2,816 deletions.
46 changes: 29 additions & 17 deletions app/assets/stylesheets/search_results.css
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,42 @@
}

.search-control-panel {
display: flex;
flex-direction: column;
gap: 12px;
/*display: flex;*/
/*flex-wrap: wrap;*/
/*flex-direction: row;*/
/*gap: 24px;*/

.control-panel-row {
.search-control-panel-row {
display: flex;
flex-direction: row;
gap: 12px;
flex-wrap: wrap;
column-gap: 24px;

.search-control-panel-label {
align-content: center;
}
.search-control-panel-item {

.search-control-panel-link {
align-content: center;
}
}
.search-control-panel-label {
align-content: center;
}

.flex-spacer {
flex-grow: 1;
}
span.search-control-panel-current {
align-content: center;
background: #2B57AB;
color: white;
padding: 0.2rem;
}

span.search-control-panel-link {
padding: 0.2rem;
&:hover {
text-decoration-thickness: 3px;
background: #e3e3e3
}
}
}

select {
padding: 5px;
.flex-spacer {
flex-grow: 1;
}
}
}

Expand Down
42 changes: 0 additions & 42 deletions app/assets/stylesheets/toggle_sliders.css

This file was deleted.

44 changes: 0 additions & 44 deletions app/javascript/controllers/detailed_results_controller.js

This file was deleted.

9 changes: 3 additions & 6 deletions app/javascript/controllers/expand_types_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export default class extends Controller {
const container_id = event.params.id
const container_id_string = container_id.toString();

// find all search links marked as modifiable, as these will be updated with hierarchy interaction data
const links = document.querySelectorAll('.modifiable-link');
const hidden_existing_id_fields = document.querySelectorAll('.hidden-existing-ids');

let existingIds = [];
const first_link = links.item(0).href;
const first_url = new URL(first_link);
Expand All @@ -37,11 +38,6 @@ export default class extends Controller {
existingIds.push(container_id_string);
}

// Update form hidden fields with existing IDs
hidden_existing_id_fields.forEach(field => {
field.value = existingIds;
})

links.forEach(link => {
const url = new URL(link.href);
url.searchParams.delete('expanded_types');
Expand All @@ -55,6 +51,7 @@ export default class extends Controller {
current_url.searchParams.append('expanded_types', existingIds)
history.pushState(null, '', current_url);

// find all "toggle-1234" elements within the hierarchy layers
const all_toggles = Array.from(document.getElementsByClassName('toggle-' + container_id));
const button = event.currentTarget;
all_toggles.forEach(element => {
Expand Down
132 changes: 58 additions & 74 deletions app/views/search/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<% end %>
<% if Rails.env.development? %>
<%= render 'search/fragments/data', data: @associated_object_data, title: 'Associated object data' %>
<%= render 'search/fragments/data', data: @search_data.search, title: 'Search response' %>
<%#= render 'search/fragments/data', data: @associated_object_data, title: 'Associated object data' %>
<%#= render 'search/fragments/data', data: @search_data.search, title: 'Search response' %>
<%#= render 'search/fragments/data', data: @ses_data, title: 'SES results' %>
<%= render 'search/fragments/data', data: @search_data.facets, title: 'Facets' %>
<%#= render 'search/fragments/data', data: @search_data.facets, title: 'Facets' %>
<%#= render 'search/fragments/data', data: @top_level, title: 'Hierarchy top level types' %>
<%#= render 'search/fragments/data', data: @toggled_facets, title: 'Toggled facets' %>
<%#= render 'search/fragments/data', data: request.params, title: 'All params' %>
Expand Down Expand Up @@ -134,81 +134,65 @@

<div class="results-container" data-controller="detailed-results">
<section class="search-control-panel">
<div class="control-panel-row">
<div class="search-control-panel-row">
<strong><%= number_to_delimited(@search_data.number_of_results, separator: ",") %><%= @search_data.number_of_results && @search_data.number_of_results > 1 ? " results" : " result" %></strong>
</div>
<div class="control-panel-row">
<label class="search-control-panel-label">
<span>Show detailed:</span>
</label>
<div class="search-control-panel-link">
<%= link_to_unless @search_data.show_detailed?, "On", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: true), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
|
<%= link_to_if @search_data.show_detailed?, "Off", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: false), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
</div>
<!-- <label class="toggle">-->
<!-- <input hidden id="show-detailed" type="checkbox" <%#= 'checked' if params[:show_detailed] == "true" %> data-action="change->detailed-results#toggle">-->
<!-- <span class="slider"></span>-->
<!-- </label>-->
<div class="flex-spacer"></div>
<label class="search-control-panel-label">
<span>Results:</span>
</label>
<div class="search-control-panel-link">
<%= link_to_unless @search_data.results_per_page == 10, "10", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: 10, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
|
<%= link_to_unless @search_data.results_per_page == 20, "20", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: 20, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
|
<%= link_to_unless @search_data.results_per_page == 50, "50", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: 50, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
|
<%= link_to_unless @search_data.results_per_page == 100, "100", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: 100, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
</div>
<label class="search-control-panel-label">
<span>Sort by:</span>
</label>
<div class="search-control-panel-link">
<%= link_to_unless @search_data.sort == "date_desc", "Newest first", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: 'date_desc', results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
|
<%= link_to_unless @search_data.sort == "date_asc", "Oldest first", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: 'date_asc', results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "#{'selected' if @search_data.show_detailed} modifiable-link" %>
</div>
<span class="search-control-panel-item">
<span class="search-control-panel-label">Show detailed:</span>
<% if @search_data.show_detailed? %>
<span class="search-control-panel-current">
On
</span>
<span class="search-control-panel-link">
<%= link_to "Off", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: false), class: "modifiable-link" %>
</span>
<% else %>
<span class="search-control-panel-link">
<%= link_to "On", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: true), class: "modifiable-link" %>
</span>
<span class="search-control-panel-current">
Off
</span>
<% end %>
</span>

<%#= form_with url: request.url, method: :get, remote: true, id: 'results-per-page' do |rf| %>
<%# unless request.params.dig(:filter).blank? %>
<%# request.params.dig(:filter).keys.each do |filter_key| %>
<%# request.params.dig(:filter, filter_key).each do |val| %>
<%#= rf.hidden_field "filter[#{filter_key}]", value: val, multiple: true %>
<%# end %>
<%# end %>
<%# end %>
<%# unless request.params.dig(:query).blank? %>
<%#= rf.hidden_field :query, value: request.params.dig(:query) %>
<%# end %>
<%# unless request.params.dig(:sort_by).blank? %>
<%#= rf.hidden_field :sort_by, value: request.params.dig(:sort_by) %>
<%# end %>
<%#= rf.hidden_field :expanded_types, value: @search_data.expanded_types_string, class: 'hidden-existing-ids' %>
<%#= rf.hidden_field :show_detailed, value: request.params.dig(:show_detailed), class: 'hidden-show-detailed' %>
<%#= rf.select "results_per_page", options_for_select([["Show 10 results", 10], ["Show 20 results", 20], ["Show 50 results", 50], ["Show 100 results", 100]], selected: @search_data.results_per_page), {}, { onchange: "this.form.submit()", class: 'form-select' } %>
<%# end %>
<span class="search-control-panel-item">
<label class="search-control-panel-label">
<span>Results:</span>
</label>
<% [10, 20, 50, 100].each do |per_page_option| %>
<% if @search_data.results_per_page == per_page_option %>
<span class="search-control-panel-current">
<%= per_page_option %>
</span>
<% else %>
<span class="search-control-panel-link">
<%= link_to per_page_option, search_url(query: @search_data.query, filter: @search_data.filter, sort_by: @search_data.sort, results_per_page: per_page_option, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "modifiable-link" %>
</span>
<% end %>
<% end %>
</span>

<%#= form_with url: request.url, method: :get, remote: true, id: 'sort-by' do |sf| %>
<%# unless request.params.dig(:filter).blank? %>
<%# request.params.dig(:filter).keys.each do |filter_key| %>
<%# request.params.dig(:filter, filter_key).each do |val| %>
<%#= sf.hidden_field "filter[#{filter_key}]", value: val, multiple: true %>
<%# end %>
<%# end %>
<%# end %>
<%# unless request.params.dig(:query).blank? %>
<%#= sf.hidden_field :query, value: request.params.dig(:query) %>
<%# end %>
<%# unless request.params.dig(:results_per_page).blank? %>
<%#= sf.hidden_field :results_per_page, value: request.params.dig(:results_per_page) %>
<%# end %>
<%#= sf.hidden_field :expanded_types, value: @search_data.expanded_types_string, class: 'hidden-existing-ids' %>
<%#= sf.hidden_field :show_detailed, value: request.params.dig(:show_detailed), class: 'hidden-show-detailed' %>
<%#= sf.select("sort_by", options_for_select([["Newest first", "date_desc"], ["Oldest first", "date_asc"]], selected: @search_data.sort), {}, { onchange: 'this.form.submit()', class: 'form-select' }) %>
<%# end %>
<span class="search-control-panel-item">
<label class="search-control-panel-label">
<span>Sort by:</span>
</label>
<% if @search_data.sort == "date_desc" %>
<span class="search-control-panel-current">
Newest first
</span>
<span class="search-control-panel-link">
<%= link_to "Oldest first", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: 'date_asc', results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "modifiable-link" %>
</span>
<% else %>
<span class="search-control-panel-link">
<%= link_to "Newest first", search_url(query: @search_data.query, filter: @search_data.filter, sort_by: 'date_desc', results_per_page: @search_data.results_per_page, page: @search_data.current_page, expanded_types: @search_data.expanded_types, show_detailed: @search_data.show_detailed), class: "modifiable-link" %>
</span>
<span class="search-control-panel-current">
Oldest first
</span>
<% end %>
</span>

</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"line": 39.31
"line": 82.93
}
}
Loading

0 comments on commit a08fa1f

Please sign in to comment.