Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to search for a senator #1368

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ def search
elsif params[:button] == "hero_search" && @current_members.include?(params[:query].downcase)
redirect_to view_context.member_path_simple(Member.with_name(params[:query]).first)
elsif params[:query].present?
@mps = Member.search_with_sql_fallback params[:query]
res = helpers.house_constituency_from_query(params[:query])
if res.empty?
@mps = Member.search_with_sql_fallback params[:query]
else
house, con = res
member = Member.current.where(house: house, constituency: con)

member.each do |m|
@mps << m unless m.nil?
end
end

@divisions = Division.search_with_sql_fallback params[:query]
@policies = Policy.search_with_sql_fallback params[:query]
end
Expand Down
35 changes: 35 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
# frozen_string_literal: true

module HomeHelper
def house_constituency_from_query(query)
res = []
states = {
nsw: "NSW",
victoria: "Victoria",
vic: "Victoria",
wa: "WA",
queensland: "Queensland",
qld: "Queensland",
nt: "NT",
sa: "SA",
tasmania: "Tasmania",
tas: "Tasmania",
canberra: "ACT",
act: "ACT",
"new south wales": "NSW",
"western australia": "WA",
"northern territory": "NT",
"south australia": "SA"
}

return res unless query.downcase.include?("senator") || query.downcase.include?("senate")

res << "senate"

states.each_key do |key|
Rails.logger.debug key
if query.downcase.include?(key.to_s)
res << states[key]
break
end
end

res
end
end
16 changes: 16 additions & 0 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,19 @@
.front-quote-block.banner-section
.container
= render "quote"

:javascript
input = document.querySelectorAll('.form-control#query')[1]
vals = ['e.g. Senate for Tasmania', 'e.g. Senate for NSW']
index = 0

current_placeholder = input.getAttribute('placeholder')
vals.push(current_placeholder)

setInterval(updatePlaceholder, 2500);

function updatePlaceholder() {
input.setAttribute('placeholder', vals[index % vals.length])
index++
}

16 changes: 16 additions & 0 deletions spec/fixtures/static_pages/.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<meta name="twitter:image" content="http://www.example.com/assets/theyvoteforyou_logo_200x200.jpg">
<meta name="twitter:title" content="How does your MP vote on the issues that matter to you?">
<meta name="twitter:description" content="Forget what politicians say. What truly matters is what they do. And what they do is vote, to write our laws which affect us all.">

</head>
<body class='home'>
<nav class='site-header navbar' role='navigation'>
Expand Down Expand Up @@ -243,6 +244,21 @@ <h2 class='h3' id='supporting_orgs'>

</div>
</div>
<script>
input = document.querySelectorAll('.form-control#query')[1]
vals = ['e.g. Senate for Tasmania', 'e.g. Senate for NSW']
index = 0

current_placeholder = input.getAttribute('placeholder')
vals.push(current_placeholder)

setInterval(updatePlaceholder, 2500);

function updatePlaceholder() {
input.setAttribute('placeholder', vals[index % vals.length])
index++
}
</script>

<footer class='site-footer'>
<div class='footer-main'>
Expand Down