From af290f57f5f781a8641150a992142368d7d22b77 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Thu, 20 Jan 2022 10:33:09 +1100 Subject: [PATCH 1/7] Inline temporary variables --- lib/tasks/application.rake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/tasks/application.rake b/lib/tasks/application.rake index 1400e013e..df2e705aa 100644 --- a/lib/tasks/application.rake +++ b/lib/tasks/application.rake @@ -151,13 +151,11 @@ namespace :application do end Division.find_each do |division| - parsed_data = Nokogiri::HTML.parse(division.formatted_motion_text) broken_urls = [] - tags = parsed_data.xpath("//a") + tags = Nokogiri::HTML.parse(division.formatted_motion_text).xpath("//a") tags.each do |tag| - url = tag[:href] - broken_urls << url if broken_url?(url) + broken_urls << tag[:href] if broken_url?(tag[:href]) end unless broken_urls.empty? # Horrible hack to get same host and protocol settings as used by the mailer From 114e802d12f43114e87f08adf41300afb26fd9b7 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Mon, 7 Feb 2022 18:33:04 +1100 Subject: [PATCH 2/7] Examples in search placeholder no rotate --- app/views/home/index.html.haml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index f8aa45781..94c9bd853 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -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++ + } \ No newline at end of file From 256c5b4c662423775e0bc20c4ffb641ee6fe8779 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Mon, 7 Feb 2022 18:34:13 +1100 Subject: [PATCH 3/7] Added helper to resolve query string for senator search --- app/helpers/home_helper.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 03620959c..98ffaf582 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -1,4 +1,35 @@ # frozen_string_literal: true module HomeHelper + def senator_search(query) + res = [] + if query.downcase.include?("senator") || query.downcase.include?("senate") + res << "senate" + else + return res + end + + 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 + + return res + end end From 73c6294e111d0b1ca4580bedcb96080fb113af9e Mon Sep 17 00:00:00 2001 From: Taz17 Date: Mon, 7 Feb 2022 18:34:52 +1100 Subject: [PATCH 4/7] Added handeling to support senator search in home controller --- app/controllers/home_controller.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 4ce7b5c2d..cb96dd825 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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? + member = Member.current.where(:house => res[0], :constituency => res[1]) + + member.each do |m| + @mps << m unless m.nil? + end + + else + @mps = Member.search_with_sql_fallback params[:query] + end + @divisions = Division.search_with_sql_fallback params[:query] @policies = Policy.search_with_sql_fallback params[:query] end From 4477224fa669674be842e4cf9527751c2b29bbcc Mon Sep 17 00:00:00 2001 From: Taz17 Date: Mon, 7 Feb 2022 18:57:48 +1100 Subject: [PATCH 5/7] To keep rubocop happy --- app/controllers/home_controller.rb | 10 +++--- app/helpers/home_helper.rb | 54 ++++++++++++++---------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index cb96dd825..2a44417bd 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -40,16 +40,16 @@ def search redirect_to view_context.member_path_simple(Member.with_name(params[:query]).first) elsif params[:query].present? res = helpers.senator_search(params[:query]) - - if !res.empty? - member = Member.current.where(:house => res[0], :constituency => res[1]) + + 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 - else - @mps = Member.search_with_sql_fallback params[:query] end @divisions = Division.search_with_sql_fallback params[:query] diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 98ffaf582..b8d6aaf1d 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -1,35 +1,33 @@ # frozen_string_literal: true module HomeHelper - def senator_search(query) - res = [] - if query.downcase.include?("senator") || query.downcase.include?("senate") - res << "senate" - else - return res - end + def senator_search(query) + res = [] + return res unless query.downcase.include?("senator") || query.downcase.include?("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 << "senate" - return res + 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 From 42ba8f1128bc2e5690e2ccfe6ab3f0e77a1d9993 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Mon, 7 Feb 2022 18:59:59 +1100 Subject: [PATCH 6/7] Updated regression tests --- spec/fixtures/static_pages/.html | 17 +++++++++++++++++ spec/fixtures/static_pages/divisions.html | 2 ++ spec/fixtures/static_pages/divisions/all.html | 2 ++ .../static_pages/divisions/all/2004.html | 2 ++ .../divisions/all/2004__sort=rebellions.html | 2 ++ .../divisions/all/2004__sort=subject.html | 2 ++ .../divisions/all/2004__sort=turnout.html | 2 ++ .../static_pages/divisions/all/2007.html | 2 ++ .../divisions/all/2007__sort=rebellions.html | 2 ++ .../divisions/all/2007__sort=subject.html | 2 ++ .../divisions/all/2007__sort=turnout.html | 2 ++ .../divisions/all__sort=rebellions.html | 5 +++-- .../divisions/all__sort=subject.html | 2 ++ .../divisions/all__sort=turnout.html | 5 +++-- .../static_pages/divisions/representatives.html | 2 ++ .../divisions/representatives/2004.html | 2 ++ .../representatives/2004__sort=rebellions.html | 2 ++ .../representatives/2004__sort=subject.html | 2 ++ .../representatives/2004__sort=turnout.html | 2 ++ .../divisions/representatives/2006-12-06/3.html | 2 ++ .../representatives/2006-12-06/3/policies.html | 6 ++++-- .../divisions/representatives/2007.html | 2 ++ .../representatives/2007__sort=rebellions.html | 2 ++ .../representatives/2007__sort=subject.html | 2 ++ .../representatives/2007__sort=turnout.html | 2 ++ .../divisions/representatives/2013-03-14/1.html | 2 ++ .../representatives/2013-03-14/1/edit.html | 3 +++ .../representatives/2013-03-14/1/policies.html | 6 ++++-- .../representatives__sort=rebellions.html | 5 +++-- .../representatives__sort=subject.html | 2 ++ .../representatives__sort=turnout.html | 5 +++-- .../fixtures/static_pages/divisions/senate.html | 2 ++ .../static_pages/divisions/senate/2004.html | 2 ++ .../divisions/senate/2004__sort=rebellions.html | 2 ++ .../divisions/senate/2004__sort=subject.html | 2 ++ .../divisions/senate/2004__sort=turnout.html | 2 ++ .../static_pages/divisions/senate/2007.html | 2 ++ .../divisions/senate/2007__sort=rebellions.html | 2 ++ .../divisions/senate/2007__sort=subject.html | 2 ++ .../divisions/senate/2007__sort=turnout.html | 2 ++ .../divisions/senate/2009-11-25/8.html | 2 ++ .../divisions/senate/2009-11-25/8/edit.html | 3 +++ .../divisions/senate/2009-11-25/8/policies.html | 6 ++++-- .../senate/2009-11-25/8/policies/1.html | 6 ++++-- .../senate/2009-11-25/8/policies/2.html | 6 ++++-- .../divisions/senate/2013-03-14/1.html | 2 ++ .../divisions/senate/2013-03-14/1/policies.html | 6 ++++-- .../divisions/senate__sort=rebellions.html | 5 +++-- .../divisions/senate__sort=subject.html | 2 ++ .../divisions/senate__sort=turnout.html | 5 +++-- .../divisions__sort=rebellions.html | 5 +++-- .../static_pages/divisions__sort=subject.html | 2 ++ .../static_pages/divisions__sort=turnout.html | 5 +++-- spec/fixtures/static_pages/help/faq.html | 2 ++ spec/fixtures/static_pages/help/research.html | 2 ++ .../static_pages/people/representatives.html | 2 ++ .../representatives/chifley/roger_price.html | 2 ++ .../representatives/griffith/kevin_rudd.html | 2 ++ .../griffith/kevin_rudd/divisions.html | 2 ++ .../griffith/kevin_rudd/friends.html | 2 ++ .../griffith/kevin_rudd/policies/1.html | 3 +++ .../new_england/barnaby_joyce.html | 2 ++ .../representatives/warringah/tony_abbott.html | 2 ++ .../warringah/tony_abbott/divisions.html | 2 ++ .../warringah/tony_abbott/friends.html | 2 ++ .../warringah/tony_abbott/policies/1.html | 3 +++ .../representatives__sort=attendance.html | 2 ++ .../representatives__sort=constituency.html | 2 ++ .../people/representatives__sort=party.html | 2 ++ .../representatives__sort=rebellions.html | 2 ++ spec/fixtures/static_pages/people/senate.html | 2 ++ .../people/senate/tasmania/christine_milne.html | 2 ++ .../tasmania/christine_milne/divisions.html | 2 ++ .../tasmania/christine_milne/friends.html | 2 ++ .../people/senate__sort=attendance.html | 2 ++ .../people/senate__sort=constituency.html | 2 ++ .../static_pages/people/senate__sort=party.html | 2 ++ .../people/senate__sort=rebellions.html | 2 ++ spec/fixtures/static_pages/policies.html | 2 ++ spec/fixtures/static_pages/policies/1.html | 2 ++ spec/fixtures/static_pages/policies/2.html | 2 ++ spec/fixtures/static_pages/search.html | 2 ++ .../static_pages/search__query=0000.html | 2 ++ .../static_pages/search__query=2042.html | 2 ++ .../static_pages/search__query=2088.html | 2 ++ 85 files changed, 209 insertions(+), 28 deletions(-) diff --git a/spec/fixtures/static_pages/.html b/spec/fixtures/static_pages/.html index 113062100..99a34c43e 100644 --- a/spec/fixtures/static_pages/.html +++ b/spec/fixtures/static_pages/.html @@ -4,6 +4,8 @@ + + They Vote For You — How does your MP vote? @@ -243,6 +245,21 @@

+