diff options
-rw-r--r-- | app/controllers/application_controller.rb | 30 | ||||
-rw-r--r-- | app/controllers/general_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/public_body_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 3 | ||||
-rwxr-xr-x | app/helpers/link_to_helper.rb | 8 | ||||
-rw-r--r-- | app/views/general/_locale_switcher.rhtml | 2 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 5 |
7 files changed, 24 insertions, 34 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ed1523f75..f3deeb64a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -456,11 +456,7 @@ class ApplicationController < ActionController::Base end end - def param_exists(item) - return params[item] && !params[item].empty? - end - - def get_request_variety_from_params + def get_request_variety_from_params(params) query = "" sortby = "newest" varieties = [] @@ -482,7 +478,7 @@ class ApplicationController < ActionController::Base return query end - def get_status_from_params + def get_status_from_params(params) query = "" if params[:latest_status] statuses = [] @@ -517,24 +513,24 @@ class ApplicationController < ActionController::Base return query end - def get_date_range_from_params + def get_date_range_from_params(params) query = "" - if param_exists(:request_date_after) && !param_exists(:request_date_before) + if params.has_key?(:request_date_after) && !params.has_key?(:request_date_before) params[:request_date_before] = Time.now.strftime("%d/%m/%Y") query += " #{params[:request_date_after]}..#{params[:request_date_before]}" - elsif !param_exists(:request_date_after) && param_exists(:request_date_before) + elsif !params.has_key?(:request_date_after) && params.has_key?(:request_date_before) params[:request_date_after] = "01/01/2001" end - if param_exists(:request_date_after) + if params.has_key?(:request_date_after) query = " #{params[:request_date_after]}..#{params[:request_date_before]}" end return query end - def get_tags_from_params + def get_tags_from_params(params) query = "" tags = [] - if param_exists(:tags) + if params.has_key?(:tags) params[:tags].split().each do |tag| tags << "tag:#{tag}" end @@ -545,12 +541,12 @@ class ApplicationController < ActionController::Base return query end - def make_query_from_params + def make_query_from_params(params) query = params[:query] || "" if query.nil? - query += get_date_range_from_params - query += get_request_variety_from_params - query += get_status_from_params - query += get_tags_from_params + query += get_date_range_from_params(params) + query += get_request_variety_from_params(params) + query += get_status_from_params(params) + query += get_tags_from_params(params) return query end diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 875e39494..a8bbc22ff 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -151,10 +151,10 @@ class GeneralController < ApplicationController params[:query] = @query end if @variety_postfix != "all" && @requests - @query, _ = make_query_from_params + @query, _ = make_query_from_params(params) end @inputted_sortby = @sortby - @common_query = get_tags_from_params + @common_query = get_tags_from_params(params) if @sortby.nil? # Parse query, so can work out if it has prefix terms only - if so then it is a # structured query which should show newest first, rather than a free text search diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 8a4a65820..1bcc0145c 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -25,7 +25,7 @@ class PublicBodyController < ApplicationController end # If found by historic name, or alternate locale name, redirect to new name if @public_body.url_name != params[:url_name] - redirect_to show_public_body_url(:url_name => @public_body.url_name) + redirect_to :url_name => @public_body.url_name return end @@ -38,9 +38,7 @@ class PublicBodyController < ApplicationController @searched_to_send_request = true end @view = params[:view] - params[:latest_status] = @view - - query = make_query_from_params + query = make_query_from_params(params.merge(:latest_status => @view)) query += " requested_from:#{@public_body.url_name}" # Use search query for this so can collapse and paginate easily # XXX really should just use SQL query here rather than Xapian. diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index dfa3a4834..6b8444f90 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -174,8 +174,7 @@ class RequestController < ApplicationController raise ActiveRecord::RecordNotFound.new("Sorry. No pages after #{MAX_RESULTS / PER_PAGE}.") end - params[:latest_status] = @view - query = make_query_from_params + query = make_query_from_params(params.merge(:latest_status => @view)) @title = _("View and search requests") sortby = "newest" xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 030fab20b..42c1e0549 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -269,13 +269,5 @@ module LinkToHelper def year_from_date(date) return date.strftime("%Y").strip end - - #I18n locale switcher - - def locale_switcher(locale, params) - params['locale'] = locale - return url_for(params) - end - end diff --git a/app/views/general/_locale_switcher.rhtml b/app/views/general/_locale_switcher.rhtml index 2521b5eb5..d0040bb0d 100644 --- a/app/views/general/_locale_switcher.rhtml +++ b/app/views/general/_locale_switcher.rhtml @@ -5,7 +5,7 @@ <% if possible_locale == I18n.locale.to_s %> <a href="#" class="btn disabled"><%= locale_name(possible_locale) %></a> <% else %> - <a href="<%= locale_switcher(possible_locale, params) %>" class="btn"><%= locale_name(possible_locale) %></a> + <a href="<%= url_for params.merge(:locale => possible_locale) %>" class="btn"><%= locale_name(possible_locale) %></a> <% end %> <% end %> </div> diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 29ece18cb..5f4012737 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -67,6 +67,11 @@ describe PublicBodyController, "when showing a body" do ActionController::Routing::Routes.filters = old_filters end + it "should remember the filter (view) setting on redirecting" do + get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful' + response.should redirect_to show_public_body_successful_url(:url_name => "etgq") + end + it "should redirect to newest name if you use historic name of public body in URL" do get :show, :url_name => "hdink", :view => 'all' response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") |