Skip to content

Commit

Permalink
Merge pull request #24 from ukparliament/development
Browse files Browse the repository at this point in the history
Development merge
  • Loading branch information
j-corry authored Nov 16, 2023
2 parents 133c871 + 4b63d10 commit eb135b3
Show file tree
Hide file tree
Showing 49 changed files with 48,483 additions and 1,686 deletions.
24 changes: 24 additions & 0 deletions app/assets/stylesheets/primary.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ main {
}
}

div.callout {
background-color: #E7DFF4;
border-left: 6px solid #2B57AB;
padding: 16px;
}

/* Object view custom lists (e.g. amendments) */
.content-list {
flex-direction: column;
Expand All @@ -132,6 +138,11 @@ main {
padding: 16px;
}

&.white {
background: none;
padding: 16px 0;
}

flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
Expand All @@ -140,6 +151,10 @@ main {
box-sizing: border-box;

.about-item {
.raw-html & p {
margin: 0;
}

color: #181818;
}

Expand All @@ -151,6 +166,15 @@ main {
padding: 8px 0;
}

.flex-list {
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
gap: 24px;
display: flex;
box-sizing: border-box;
}

.pill-section {
display: flex;
flex-direction: row;
Expand Down
1 change: 0 additions & 1 deletion app/controllers/content_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ def show
render template: @object.template, :locals => { :object => @object }
end
end

end
38 changes: 12 additions & 26 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
# # The one and only search controller.
class SearchController < ApplicationController

# A method to render the search form.
def form
@page_title = 'Search'

def index
@page_title = "Search results"
results = SolrSearch.new(search_params)

@items = results.object_data
@metadata = results.send(:evaluated_response)['response']
end

# ## A method to render a results page.
def results
@page_title = 'Search results'

# We get the document type from the URL parameter.
document_type = params[:document_type]

# We construct the URL string to grab the XML from.
url = "#{BASE_API_URI}results/#{document_type}.rb"

# We turn the URL string into a RUBY URI.
uri = URI( url )

# We get the body of the response from deferencing the URI.
response_body = Net::HTTP.get( uri )

# We evaluate the body and construct a Ruby hash.
evaluated = eval( response_body )

# We render the search results template, passing the evaluated response body as results.
render :template => 'search/results/results', :locals => { :results => evaluated }

private

def search_params
params.permit(:query, :page, :type_ses)
end
end
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module ApplicationHelper
def boolean_yes_no(boolean)
# outputs 'Yes' or 'No' strings from a boolean (an instance of Ruby TrueClass or FalseClass)
# for presenting output of methods such as WrittenQuestion transferred?
# Note that in most cases the partial will not be rendered except where the answer is 'Yes', but exceptions exist
return 'Yes' if boolean == true

'No'
Expand Down
21 changes: 15 additions & 6 deletions app/models/content_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ def legislature
content_object_data['legislature_ses'].first
end

def registered_interest_declared
def registered_interest_declared?
return if content_object_data['registeredInterest_b'].blank?

content_object_data['registeredInterest_b'].first == 'true' ? 'Yes' : 'No'
return false unless content_object_data['registeredInterest_b'].first == 'true'

true
end

def external_location_uri
Expand Down Expand Up @@ -206,11 +208,14 @@ def related_items

return unless relation_uris.map(&:class).uniq.compact == [String]

related_objects = SolrMultiQuery.new(object_uris: relation_uris).object_data
ret = {}

ret = []
related_objects.each do |object|
ret << ContentObject.generate(object)
query = SolrMultiQuery.new(object_uris: relation_uris)
ret[:ses_lookup] = SesLookup.new(query.all_ses_ids).data unless query.all_ses_ids.blank?

ret[:items] = []
query.object_data.each do |object|
ret[:items] << ContentObject.generate(object)
end

ret
Expand Down Expand Up @@ -259,6 +264,10 @@ def corporate_author
end

def contains_statistics?
# TODO: this will be any of three attributes being true
# see comments on trello card
# Blanket rule proposed for all object views: “Given an object with one or more of the attributes, hasTable OR containsStatistics OR statisticsIndicated, show Yes if at least one of those is true. If all statistical attributes associated with the object are false, do not display.”

return if content_object_data['containsStatistics_b'].blank?

return false unless content_object_data['containsStatistics_b'].first == 'true'
Expand Down
6 changes: 5 additions & 1 deletion app/models/solr_multi_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def initialize(params)
def object_data
return evaluated_response if evaluated_response['statusCode'] == 500

evaluated_response['response']['docs']
response = evaluated_response['response']['docs']
end

def all_ses_ids
object_data.flat_map{|o| o["all_ses"]}
end

def ruby_uri
Expand Down
9 changes: 1 addition & 8 deletions app/models/solr_query.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
class SolrQuery < ApiCall
require 'open-uri'
require 'net/http'

attr_reader :object_uri

BASE_API_URI = "https://api.parliament.uk/new-solr/"

def initialize(params)
@object_uri = params[:object_uri]
super
end

def object_data
Expand Down
42 changes: 42 additions & 0 deletions app/models/solr_search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class SolrSearch < ApiCall

attr_reader :query, :page, :type

def initialize(params)
super
@query = params[:query]
@page = params[:page]
@type = params[:type_ses]
end

def object_data
return evaluated_response if evaluated_response['statusCode'] == 500

res = evaluated_response['response']['docs']
puts "response: #{res}"
res
end

def result_uris
object_data.map { |doc| doc["uri"] }
end

def start
# offset number of rows
return 0 if page.blank?

page.to_i * rows
end

def rows
# number of results per page; default is 10 in SOLR
20
end

def ruby_uri
build_uri("#{BASE_API_URI}select?q=%22#{query}%22&rows=#{rows}&start=#{start}")
end

# TODO: we can search for a specific term / filter by adding to the query string
# select?q=type_ses:#{type}
end
2 changes: 1 addition & 1 deletion app/models/statutory_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def referred_to
content_object_data['referral_t'].first
end

def reported_by_joint_committee
def reported_by_joint_committee?
return if content_object_data['jointCommitteeOnStatutoryInstruments_b'].blank?

return false unless content_object_data['jointCommitteeOnStatutoryInstruments_b'].first == 'true'
Expand Down
10 changes: 10 additions & 0 deletions app/models/written_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def holding_answer?
false
end

def prorogation_answer?
#to show conditionally on answered states only (as determined by method)

return if content_object_data['prorogationAnswer_b'].blank?

return true if content_object_data['prorogationAnswer_b'] == 'true'

false
end

def date_of_holding_answer
return if content_object_data['dateOfHoldingAnswer_dt'].blank?

Expand Down
10 changes: 9 additions & 1 deletion app/views/content_objects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
<div id="top"></div>
<% end %>

<section class="content-section">
<section id="search" class="content-section white">
<h2 class="content-heading">Search</h2>
<%= form_with url: search_url do |f| %>
<%= f.text_field :query %>
<%= f.submit 'Search' %>
<% end %>
</section>

<section id="examples" class="content-section white">
<h2 class="content-heading">Example Objects</h2>
<ul>
<%= content_tag('li', link_to('An EDM', object_show_url(object: 'http://data.parliament.uk/edms/22468'))) %>
Expand Down
10 changes: 4 additions & 6 deletions app/views/search/fragments/_answer.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<section id="text" class="content-section">
<div class="about-item">
<h3 class="content-heading" id="answer">Answer</h3>
<%= raw(object.answer_text) %>
</div>
</section>
<div class="about-item">
<h3 class="content-heading" id="answer">Answer</h3>
<%= raw sanitize object.answer_text, tags: %w(strong em a br) %>
</div>
16 changes: 7 additions & 9 deletions app/views/search/fragments/_corrected_answer.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<section id="text" class="content-section">
<div class="about-item">
<h3 class="content-heading" id="corrected-answer">Corrected answer</h3>
<%= raw(object.corrected_answer) %>
</div>
<div class="about-item">
<%= link_to object.corrected_item_link %>
</div>
</section>
<div class="about-item">
<h3 class="content-heading" id="corrected-answer">Corrected answer</h3>
<%= raw(object.corrected_answer) %>
</div>
<div class="about-item">
<%= link_to object.corrected_item_link %>
</div>
7 changes: 7 additions & 0 deletions app/views/search/fragments/_prorogation_information.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="about-item">
<div class="callout">
When a parliamentary session comes to an end Parliament is prorogued until the next session begins. Prorogation
is the formal end to the parliamentary year. A 'prorogation answer' to a written question may be issued by a
Minister if it has not been possible to provide a substantive answer in the time available before Prorogation.
</div>
</div>
10 changes: 4 additions & 6 deletions app/views/search/fragments/_question.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<section id="text" class="content-section">
<div class="about-item">
<h3 class="content-heading" id="question">Question</h3>
<%= raw(object.question_text) %>
</div>
</section>
<div class="about-item">
<h3 class="content-heading" id="question">Question</h3>
<%= raw sanitize object.question_text, tags: %w(strong em a br) %>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="about-item">
<h3 class="content-heading" id="registered-interest-declared">Registered interest declared</h3>
<%= registered_interest_declared %>
<%= boolean_yes_no(registered_interest) %>
</div>
36 changes: 21 additions & 15 deletions app/views/search/fragments/_related_items.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<!--like content section, this needs to be properly vertically spaced-->

<div class="about-item">
<h3 class="content-heading" id="related-items">Related items</h3>
<% related_items.each do |related_item| %>
<div>
<%= link_to related_item.page_title, related_item.content_object_data['uri'] %><br/>
<% if related_item.date %>
<%= related_item.date&.strftime(ApplicationHelper::DATE_DISPLAY_FORMAT) %>
<% end %>
<% if related_item.type %>
<%= ses_name(related_item.type) %><br/>
<% end %>
<% if related_item.legislature %>
<%= ses_name(related_item.legislature) %><br/>
<% end %>
</div>
<br/>
<% end %>
<div class="flex-list">
<% related_items[:items].each do |related_item| %>
<div>
<% unless related_item.content_object_data['uri'].blank? %>
<%= link_to(related_item.page_title, object_show_url(:object => related_item.content_object_data['uri'])) %>
<br/>
<% end %>
<% if related_item.date %>
<%= related_item.date&.strftime(ApplicationHelper::DATE_DISPLAY_FORMAT) %><br/>
<% end %>
<% if related_item.type %>
<%= related_items[:ses_lookup][related_item.type] %><br/>
<% end %>
<% unless related_item.legislature.blank? %>
<%= related_items[:ses_lookup][related_item.legislature] %><br/>
<% end %>
</div>
<% end %>
</div>
</div>
23 changes: 23 additions & 0 deletions app/views/search/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% content_for(:before_title) do %>
<%= link_to('UK Parliament', root_path) %> / <%= link_to('Open data', root_path) %><br/>
<div id="top"></div>
<% end %>

<section>
<h3>Search results</h3>

<h6>Found <%= @metadata['numFound'] %> results</h6>

<ul>
<% @items.each do |item| %>
<li>
<%= link_to(item["title_t"], object_show_url(:object => item["uri"])) %>
</li>
<% end %>
</ul>

</section>

<%= button_to "1", search_url(query: params[:query], page: 1), { method: :post } %>
<%= button_to "2", search_url(query: params[:query], page: 2), { method: :post } %>
<%= button_to "3", search_url(query: params[:query], page: 3), { method: :post } %>
Loading

0 comments on commit eb135b3

Please sign in to comment.