From 5997252270b5f92bfcccb11c6db0b8b917dbee0a Mon Sep 17 00:00:00 2001 From: Taz17 Date: Tue, 8 Mar 2022 13:36:36 +1100 Subject: [PATCH 1/4] Method to extract house and constituency from a URl query --- app/helpers/home_helper.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 03620959c..66d88bbd4 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -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 From 10ea4a72971d37df95cefbc17087039d895140d8 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Tue, 8 Mar 2022 13:37:35 +1100 Subject: [PATCH 2/4] look for house and constituency when URL query is present --- app/controllers/home_controller.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index a08cbd3af..a7d5a6bde 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 From 5617a691406ad10f8c8d7e07255aa74ba37a528f Mon Sep 17 00:00:00 2001 From: Taz17 Date: Tue, 8 Mar 2022 13:38:24 +1100 Subject: [PATCH 3/4] rotate placeholders to show support for senator search --- app/views/home/index.html.haml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 2da42c983..9c5167ef1 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -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++ + } + \ No newline at end of file From 7522fddbdb9c0b18fadb9fa15b2a898d59658927 Mon Sep 17 00:00:00 2001 From: Taz17 Date: Tue, 8 Mar 2022 13:45:51 +1100 Subject: [PATCH 4/4] Updated regression tests --- spec/fixtures/static_pages/.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/fixtures/static_pages/.html b/spec/fixtures/static_pages/.html index 113062100..0ea892084 100644 --- a/spec/fixtures/static_pages/.html +++ b/spec/fixtures/static_pages/.html @@ -26,6 +26,7 @@ +