diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index a08cbd3af..392ead92b 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? + @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 diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 03620959c..b8d6aaf1d 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -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 diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 2da42c983..3806f64dd 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 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 @@ + +