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

Added support to search for a senator #1329

Closed
wants to merge 15 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
14 changes: 13 additions & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ 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.senator_search(params[:query])

if res.empty?
@mps = Member.search_with_sql_fallback params[:query]
else
member = Member.current.where(house: res[0], constituency: res[1])

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
29 changes: 29 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
# frozen_string_literal: true

module HomeHelper
def senator_search(query)
res = []
return res unless query.downcase.include?("senator") || query.downcase.include?("senate")

res << "senate"

query.downcase.split.each do |string|
case string
when "new south wales", "nsw"
res << "NSW"
when "victoria", "vic"
res << "Victoria"
when "western australia", "wa"
res << "WA"
when "queensland", "qld"
res << "Queensland"
when "northern territory", "nt"
res << "NT"
when "south australia", "sa"
res << "SA"
when "tasmania", "tas"
res << "Tasmania"
when "canberra", "act"
res << "ACT"
end
end

res
end
end
15 changes: 15 additions & 0 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@
.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++
}
17 changes: 17 additions & 0 deletions spec/fixtures/static_pages/.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Taz17 this looks very suspicious. I would guess this is the source of the problem. Why was this committed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were changes made automatically after bundle exec rake was run. I manually anything under spec/*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It those get changed, that means the regression tests failed!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes definitely, that was in commit 42ba8f1

I then re-ran the rake and it added more changes. Here 33cca66

But its passing everything now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is something to do with a meta tag to do with facebook getting updated in a PR to do with searching?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, all the changes that I made are regarding search.

What could be the cause of the meta tag getting updated?

As a side note. I just ran the rake tasks on the branch (policy_filter_search_js) to see why PR #1332 was failing the rake tasks and I got the same changes for the facebook meta tags... very odd

Copy link
Contributor Author

@MutazAshhab MutazAshhab Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also get the same meta tag changes if i run bundle exec rake on the master branch (note: i never code on the master branch)... Im considering deleting my fork and re-forking the project

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you need to do is understand where that meta tag is being generated and then figure out what you're doing to cause that to be different on your box vs someone else's box.

<meta content='4567' property='fb:admins'>
<title>
They Vote For You — How does your MP vote?
</title>
Expand Down Expand Up @@ -243,6 +245,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
2 changes: 2 additions & 0 deletions spec/fixtures/static_pages/divisions.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/static_pages/divisions/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/static_pages/divisions/all/2004.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/static_pages/divisions/all/2007.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down Expand Up @@ -78,8 +80,7 @@ <h1>
</nav>
<div class='list-sorter dropdown'>
<button class='btn btn-sm btn-default dropdown-toggle' data-toggle='dropdown' id='dropdownMenu1' type='button'>
Sorted by
Rebellions
Sorted by Rebellions
<span class='caret'></span>
</button>
<ul aria-labelledby='dropdownMenu1' class='dropdown-menu' role='menu'>
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/static_pages/divisions/all__sort=subject.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
5 changes: 3 additions & 2 deletions spec/fixtures/static_pages/divisions/all__sort=turnout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down Expand Up @@ -78,8 +80,7 @@ <h1>
</nav>
<div class='list-sorter dropdown'>
<button class='btn btn-sm btn-default dropdown-toggle' data-toggle='dropdown' id='dropdownMenu1' type='button'>
Sorted by
Attendance
Sorted by Attendance
<span class='caret'></span>
</button>
<ul aria-labelledby='dropdownMenu1' class='dropdown-menu' role='menu'>
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/static_pages/divisions/representatives.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Prohibition of Human Cloning for Reproduction and the Regulation of Human Embryo Research Amendment Bill 2006 - Consideration in Detail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Prohibition of Human Cloning for Reproduction and the Regulation of Human Embryo Research Amendment Bill 2006 - Consideration in Detail

Expand Down Expand Up @@ -62,6 +64,7 @@
<li><a title="Make your browser forget that you are logged into They Vote For You as Henare Degan" rel="nofollow" data-method="delete" href="/users/sign_out">Logout</a></li>
</ul>
</li>

</ul>
</div>
</nav>
Expand Down Expand Up @@ -94,9 +97,8 @@ <h2>Related Policies</h2>
</form><form class="button_to" method="post" action="/divisions/representatives/2006-12-06/3/policies/2/delete"><input type="hidden" name="_method" value="delete" /><input class="btn btn-sm btn-link" type="submit" value="remove" /></form>
</li>
</ul>

<h3>Make a new connection</h3>
<form class="simple_form form-inline policyvote" novalidate="novalidate" id="new_policy_division" action="/divisions/representatives/2006-12-06/3/policies/create" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" /><legend class='small'>
<form class="simple_form form-inline policyvote" id="new_policy_division" novalidate="novalidate" action="/divisions/representatives/2006-12-06/3/policies/create" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" /><legend class='small'>
<p>Connect this division with relevant policies.</p>
<p>Please read policy definitions and the division’s description before altering list.</p>
</legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Divisions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='1234' property='fb:admins'>
<meta content='4567' property='fb:admins'>
<title>
Edit division summary —
test
Expand Down Expand Up @@ -65,6 +67,7 @@
<li><a title="Make your browser forget that you are logged into They Vote For You as Henare Degan" rel="nofollow" data-method="delete" href="/users/sign_out">Logout</a></li>
</ul>
</li>

</ul>
</div>
</nav>
Expand Down
Loading