diff options
Diffstat (limited to 'app')
25 files changed, 719 insertions, 313 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 021122734..bd85f6eed 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -82,16 +82,12 @@ class AdminPublicBodyController < AdminController end def new - @locale = self.locale_from_params() - PublicBody.with_locale(@locale) do - @public_body = PublicBody.new - render - end + @public_body = PublicBody.new + render end - + def create - @locale = self.locale_from_params() - PublicBody.with_locale(@locale) do + PublicBody.with_locale(I18n.default_locale) do params[:public_body][:last_edit_editor] = admin_http_auth_user() @public_body = PublicBody.new(params[:public_body]) if @public_body.save @@ -104,17 +100,13 @@ class AdminPublicBodyController < AdminController end def edit - @locale = self.locale_from_params() - PublicBody.with_locale(@locale) do - @public_body = PublicBody.find(params[:id]) - @public_body.last_edit_comment = "" - render - end + @public_body = PublicBody.find(params[:id]) + @public_body.last_edit_comment = "" + render end def update - @locale = self.locale_from_params() - PublicBody.with_locale(@locale) do + PublicBody.with_locale(I18n.default_locale) do params[:public_body][:last_edit_editor] = admin_http_auth_user() @public_body = PublicBody.find(params[:id]) if @public_body.update_attributes(params[:public_body]) @@ -157,7 +149,7 @@ class AdminPublicBodyController < AdminController # Try with dry run first csv_contents = params[:csv_file].read - en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user(), I18n.available_locales) + en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user(), available_locales) errors = en[0] notes = en[1] @@ -166,7 +158,7 @@ class AdminPublicBodyController < AdminController notes.push("Dry run was successful, real run would do as above.") else # And if OK, with real run - en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user(), available_locales) + en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user(), I18n.available_locales) errors = en[0] notes = en[1] if errors.size != 0 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0df3e22da..caf613f8d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -349,6 +349,104 @@ class ApplicationController < ActionController::Base session[:last_body_id] = public_body.id end + def param_exists(item) + return params[item] && !params[item].empty? + end + + def get_request_variety_from_params + query = "" + sortby = "newest" + varieties = [] + if params[:request_variety] && !(query =~ /variety:/) + if params[:request_variety].include? "sent" + varieties -= ['variety:sent', 'variety:followup_sent', 'variety:response', 'variety:comment'] + varieties << ['variety:sent', 'variety:followup_sent'] + end + if params[:request_variety].include? "response" + varieties << ['variety:response'] + end + if params[:request_variety].include? "comment" + varieties << ['variety:comment'] + end + end + if !varieties.empty? + query = " (#{varieties.join(' OR ')})" + end + return query + end + + def get_status_from_params + query = "" + if params[:latest_status] + statuses = [] + if params[:latest_status].class == String + params[:latest_status] = [params[:latest_status]] + end + if params[:latest_status].include?("recent") || params[:latest_status].include?("all") + query += " (variety:sent)" + end + if params[:latest_status].include? "successful" + statuses << ['latest_status:successful', 'latest_status:partially_successful'] + end + if params[:latest_status].include? "unsuccessful" + statuses << ['latest_status:rejected', 'latest_status:not_held'] + end + if params[:latest_status].include? "awaiting" + statuses << ['latest_status:waiting_response', 'latest_status:waiting_clarification', 'waiting_classification:true'] + end + if params[:latest_status].include? "internal_review" + statuses << ['status:internal_review'] + end + if params[:latest_status].include? "other" + statuses << ['latest_status:gone_postal', 'latest_status:error_message', 'latest_status:requires_admin', 'latest_status:user_withdrawn'] + end + if params[:latest_status].include? "gone_postal" + statuses << ['latest_status:gone_postal'] + end + if !statuses.empty? + query = " (#{statuses.join(' OR ')})" + end + end + return query + end + + def get_date_range_from_params + query = "" + if param_exists(:request_date_after) && !param_exists(:request_date_before) + params[:request_date_before] = Date.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) + params[:request_date_after] = "01/01/2008" + end + if param_exists(:request_date_after) + query = " #{params[:request_date_after]}..#{params[:request_date_before]}" + end + return query + end + + def get_tags_from_params + query = "" + tags = [] + if param_exists(:tags) + params[:tags].split().each do |tag| + tags << "tag:#{tag}" + end + end + if !tags.empty? + query = " (#{tags.join(' OR ')})" + end + return query + end + + def make_query_from_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 + return query + end + # URL generating functions are needed by all controllers (for redirects), # views (for links) and mailers (for use in emails), so include them into # all of all. diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 4fa603aab..2d0527d3a 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -82,20 +82,34 @@ class GeneralController < ApplicationController # Just does a redirect from ?query= search to /query def search_redirect - @query = params[:query] + if params[:advanced].nil? + @query, _ = make_query_from_params + else + @query, _ = params[:query] + end @sortby = params[:sortby] - @bodies = params[:bodies] + path = request.path.split("/") + if path.size > 0 && (['newest', 'described', 'relevant'].include?(path[-1])) + @sort_postfix = path.pop + end + if path.size > 0 && (['bodies', 'requests', 'users', 'all'].include?(path[-1])) + @variety_postfix = path.pop + end + @variety_postfix = params[:bodies] if @variety_postfix.nil? && !params[:bodies].nil? + @variety_postfix = "all" if @variety_postfix.nil? + if @variety_postfix != "users" + @common_query = get_tags_from_params + end + [:latest_status, :request_variety, :request_date_after, :request_date_before, :query, :tags].each do |x| + session[x] = params[x] + end if @query.nil? || @query.empty? @query = nil @page = 1 + @advanced = !params[:advanced].nil? render :action => "search" else - if (@bodies == '1') && (@sortby.nil? || @sortby.empty?) - @postfix = 'bodies' - else - @postfix = @sortby - end - redirect_to search_url(@query, @postfix) + redirect_to search_url(@query, @variety_postfix, @sort_postfix, params[:advanced]) end end @@ -103,23 +117,49 @@ class GeneralController < ApplicationController def search # XXX Why is this so complicated with arrays and stuff? Look at the route # in config/routes.rb for comments. + if !params[:commit].nil? + search_redirect + return + end + [:latest_status, :request_variety, :request_date_after, :request_date_before, :query, :tags].each do |x| + params[x] = session[x] + end combined = params[:combined] @sortby = nil - @bodies = false # searching from front page, largely for a public authority + @bodies = @requests = @users = true + if combined.size > 0 && (['advanced'].include?(combined[-1])) + combined.pop + @advanced = true + else + @advanced = false + end # XXX currently /described isn't linked to anywhere, just used in RSS and for /list/successful # This is because it's confusingly different from /newest - but still useful for power users. - if combined.size > 1 && (['newest', 'described', 'bodies', 'relevant'].include?(combined[-1])) - @postfix = combined[-1] - combined = combined[0..-2] - if @postfix == 'bodies' + if combined.size > 0 && (['newest', 'described', 'relevant'].include?(combined[-1])) + @sort_postfix = combined.pop + @sortby = @sort_postfix + end + + if combined.size > 0 && (['bodies', 'requests', 'users', 'all'].include?(combined[-1])) + @variety_postfix = combined.pop + case @variety_postfix + when 'bodies' @bodies = true - else - @sortby = @postfix + @requests = false + @users = false + when 'requests' + @bodies = false + @requests = true + @users = false + when 'users' + @bodies = false + @requests = false + @users = true end end @query = combined.join("/") - @inputted_sortby = @sortby + @common_query = get_tags_from_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 @@ -145,21 +185,41 @@ class GeneralController < ApplicationController if params[:requests_per_page] requests_per_page = params[:requests_per_page].to_i end - @xapian_requests = perform_search([InfoRequestEvent], @query, @sortby, 'request_collapse', requests_per_page) - @requests_per_page = @per_page - @xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5) - @bodies_per_page = @per_page - @xapian_users = perform_search([User], @query, @sortby, nil, 5) - @users_per_page = @per_page - - @this_page_hits = @xapian_requests.results.size + @xapian_bodies.results.size + @xapian_users.results.size - @total_hits = @xapian_requests.matches_estimated + @xapian_bodies.matches_estimated + @xapian_users.matches_estimated + @this_page_hits = @total_hits = @xapian_requests_hits = @xapian_bodies_hits = @xapian_users_hits = 0 + if @requests + @xapian_requests = perform_search([InfoRequestEvent], @query, @sortby, 'request_collapse', requests_per_page) + @requests_per_page = @per_page + @this_page_hits += @xapian_requests.results.size + @xapian_requests_hits = @xapian_requests.results.size + @xapian_requests_total_hits = @xapian_requests.matches_estimated + @total_hits += @xapian_requests.matches_estimated + end + if @bodies + @xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5) + @bodies_per_page = @per_page + @this_page_hits += @xapian_bodies.results.size + @xapian_bodies_hits = @xapian_bodies.results.size + @xapian_bodies_total_hits = @xapian_bodies.matches_estimated + @total_hits += @xapian_bodies.matches_estimated + end + if @users + @xapian_users = perform_search([User], @query, @sortby, nil, 5) + @users_per_page = @per_page + @this_page_hits += @xapian_users.results.size + @xapian_users_hits = @xapian_users.results.size + @xapian_users_total_hits = @xapian_users.matches_estimated + @total_hits += @xapian_users.matches_estimated + end # Spelling and highight words are same for all three queries - @spelling_correction = @xapian_requests.spelling_correction - @highlight_words = @xapian_requests.words_to_highlight + if !@xapian_requests.nil? + @highlight_words = @xapian_requests.words_to_highlight + if !(@xapian_requests.spelling_correction =~ /[a-z]+:/) + @spelling_correction = @xapian_requests.spelling_correction + end + end - @track_thing = TrackThing.create_track_for_search_query(@query) + @track_thing = TrackThing.create_track_for_search_query(@query, @variety_postfix) @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] end diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 05acf4868..d7d8c2c56 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -16,7 +16,6 @@ class PublicBodyController < ApplicationController redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently return end - @locale = self.locale_from_params() PublicBody.with_locale(@locale) do @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) @@ -39,11 +38,16 @@ class PublicBodyController < ApplicationController if !referrer.nil? && referrer.match(%r{^#{top_url}search/.*/bodies$}) @searched_to_send_request = true end + @view = params[:view] + params[:latest_status] = @view + query = make_query_from_params + 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. + sortby = "described" begin - @xapian_requests = perform_search([InfoRequestEvent], 'requested_from:' + @public_body.url_name, 'newest', 'request_collapse') + @xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') if (@page > 1) @page_desc = " (page " + @page.to_s + ")" else @@ -83,29 +87,30 @@ class PublicBodyController < ApplicationController def list long_cache # XXX move some of these tag SQL queries into has_tag_string.rb + @query = "%#{params[:public_body_query].nil? ? "" : params[:public_body_query]}%" @tag = params[:tag] @locale = self.locale_from_params() - locale_condition = 'public_body_translations.locale = ?' - if @tag.nil? + locale_condition = "upper(public_body_translations.name) LIKE upper(?) AND public_body_translations.locale = ?" + if @tag.nil? or @tag == "all" @tag = "all" - conditions = [locale_condition, @locale] + conditions = [locale_condition, @query, @locale] elsif @tag == 'other' category_list = PublicBodyCategories::CATEGORIES.map{|c| "'"+c+"'"}.join(",") conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name in (' + category_list + ')) = 0', @locale] + and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @locale] elsif @tag.size == 1 @tag.upcase! - conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @locale, @tag] + conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @locale, @tag] elsif @tag.include?(":") name, value = HasTagString::HasTagStringTag.split_tag_into_name_value(@tag) conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @locale, name, value] + and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @locale, name, value] else conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ?) > 0', @locale, @tag] + and has_tag_string_tags.name = ?) > 0', @query, @locale, @tag] end if @tag.size == 1 @description = _("beginning with") + " '" + @tag + "'" diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index c1a13273a..3c283baae 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -129,26 +129,10 @@ class RequestController < ApplicationController def list medium_cache @view = params[:view] - - if @view.nil? - redirect_to request_list_url(:view => 'successful') - return - end - - if @view == 'recent' - @title = _("Recently sent Freedom of Information requests") - query = "variety:sent"; - sortby = "newest" - @track_thing = TrackThing.create_track_for_all_new_requests - elsif @view == 'successful' - @title = _("Recently successful responses") - query = 'variety:response (status:successful OR status:partially_successful)' - sortby = "described" - @track_thing = TrackThing.create_track_for_all_successful_requests - else - raise "unknown request list view " + @view.to_s - end - + params[:latest_status] = @view + query = make_query_from_params + @title = "View and search requests" + sortby = "newest" @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect behavior_cache :tag => [@view, @page] do xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') @@ -158,7 +142,8 @@ class RequestController < ApplicationController @title = @title + " (page " + @page.to_s + ")" if (@page > 1) - @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] + # XXX need to reinstate the following; @track_thing had previously been set to "TrackThing.create_track_for_all_new_requests" and "TrackThing.create_track_for_all_successful_requests" + # @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] # Don't let robots go more than 20 pages in if @page > 20 diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 445a96920..54b8d69d0 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -61,7 +61,7 @@ module LinkToHelper # Public bodies def public_body_url(public_body) - return show_public_body_url(:url_name => public_body.url_name, :only_path => true) + public_body.url_name.nil? ? '' : show_public_body_url(:url_name => public_body.url_name, :only_path => true) end def public_body_link_short(public_body) link_to h(public_body.short_or_long_name), public_body_url(public_body) @@ -79,7 +79,7 @@ module LinkToHelper link_to(h(public_body.name), main_url(public_body_url(public_body))) + " (" + link_to("admin", public_body_admin_url(public_body)) + ")" end def list_public_bodies_default - list_public_bodies_url(:tag => 'a') + list_public_bodies_url(:tag => 'all') end # Users @@ -135,11 +135,10 @@ module LinkToHelper end end - # General pages. postfix is either the sort order, or 'bodies' to show you - # came from the front page and are looking for public bodies - def search_url(query, postfix = nil) + # General pages. + def search_url(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) + query = query - ["", nil] if query.kind_of?(Array) url = search_general_url(:combined => query) - # Here we can't escape the slashes, as RFC 2396 doesn't allow slashes # within a path component. Rails is assuming when generating URLs that # either there aren't slashes, or we are in a query part where you can @@ -151,13 +150,19 @@ module LinkToHelper # http://rails.lighthouseapp.com/projects/8994/tickets/144-patch-bug-in-rails-route-globbing url = url.gsub("%2F", "/") - if !postfix.nil? && !postfix.empty? - url = url + "/" + postfix + if !variety_postfix.nil? && !variety_postfix.empty? + url = url + "/" + variety_postfix + end + if !sort_postfix.nil? && !sort_postfix.empty? + url = url + "/" + sort_postfix + end + if !advanced.nil? && (advanced) + url = url + "/advanced" end return url end - def search_link(query, postfix = nil) - link_to h(query), search_url(query, postfix) + def search_link(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) + link_to h(query), search_url(query, variety_postfix, sort_postfix, advanced) end # Admin pages diff --git a/app/models/info_request.rb b/app/models/info_request.rb index c667e1499..9b0f1047b 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -451,7 +451,7 @@ public self.log_event("response", params) self.save! end - + self.info_request_events.each { |event| event.xapian_mark_needs_index } # for the "waiting_classification" index RequestMailer.deliver_new_response(self, incoming_message) end @@ -564,6 +564,7 @@ public def calculate_event_states curr_state = nil for event in self.info_request_events.reverse + event.xapian_mark_needs_index # we need to reindex all events in order to update their latest_* terms if curr_state.nil? if !event.described_state.nil? curr_state = event.described_state diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index d79647c98..4003217b0 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -57,22 +57,7 @@ class InfoRequestEvent < ActiveRecord::Base ] # user described state (also update in info_request) - validates_inclusion_of :described_state, :in => [ - nil, - 'waiting_response', - 'waiting_clarification', - 'gone_postal', - 'deadline_extended', - 'wrong_response', - 'not_held', - 'rejected', - 'successful', - 'partially_successful', - 'internal_review', - 'error_message', - 'requires_admin', - 'user_withdrawn' - ] + validate :must_be_valid_state # whether event is publicly visible validates_inclusion_of :prominence, :in => [ @@ -81,6 +66,12 @@ class InfoRequestEvent < ActiveRecord::Base 'requester_only' ] + def must_be_valid_state + if !described_state.nil? and !InfoRequest.enumerate_states.include?(described_state) + errors.add(described_state, "is not a valid state") + end + end + def user_can_view?(user) if !self.info_request.user_can_view?(user) raise "internal error, called user_can_view? on event when there is not permission to view entire request" @@ -103,7 +94,7 @@ class InfoRequestEvent < ActiveRecord::Base [ :created_at_numeric, 1, "created_at", :number ], # for sorting [ :described_at_numeric, 2, "described_at", :number ], # XXX using :number for lack of :datetime support in Xapian values [ :request, 3, "request_collapse", :string ], - [ :request_title_collapse, 4, "request_title_collapse", :string ] + [ :request_title_collapse, 4, "request_title_collapse", :string ], ], :terms => [ [ :calculated_state, 'S', "status" ], [ :requested_by, 'B', "requested_by" ], @@ -111,6 +102,9 @@ class InfoRequestEvent < ActiveRecord::Base [ :commented_by, 'C', "commented_by" ], [ :request, 'R', "request" ], [ :variety, 'V', "variety" ], + [ :latest_variety, 'K', "latest_variety" ], + [ :latest_status, 'L', "latest_status" ], + [ :waiting_classification, 'W', "waiting_classification" ], [ :filetype, 'T', "filetype" ], [ :tags, 'U', "tag" ] ], @@ -138,6 +132,27 @@ class InfoRequestEvent < ActiveRecord::Base def request self.info_request.url_title end + + def latest_variety + for event in self.info_request.info_request_events.reverse + if !event.variety.nil? and !event.variety.empty? + return event.variety + end + end + end + + def latest_status + for event in self.info_request.info_request_events.reverse + if !event.calculated_state.nil? and !event.calculated_state.empty? + return event.calculated_state + end + end + end + + def waiting_classification + self.info_request.awaiting_description == true ? "yes" : "no" + end + def request_title_collapse url_title = self.info_request.url_title # remove numeric section from the end, use this to group lots diff --git a/app/models/public_body.rb b/app/models/public_body.rb index b75da4331..81149e3c2 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -38,7 +38,7 @@ class PublicBody < ActiveRecord::Base validates_uniqueness_of :short_name, :message => N_("Short name is already taken"), :if => Proc.new { |pb| pb.short_name != "" } validates_uniqueness_of :name, :message => N_("Name is already taken") - + has_many :info_requests, :order => 'created_at desc' has_many :track_things, :order => 'created_at desc' @@ -46,6 +46,40 @@ class PublicBody < ActiveRecord::Base translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme + # Convenience methods for creating/editing translations via forms + def translation(locale) + self.translations.find_by_locale(locale) + end + + # XXX - Don't like repeating this! + def calculate_cached_fields(t) + t.first_letter = t.name.scan(/^./mu)[0].upcase unless t.name.nil? or t.name.empty? + short_long_name = t.name + short_long_name = t.short_name if t.short_name and !t.short_name.empty? + t.url_name = MySociety::Format.simplify_url_part(short_long_name, 'body') + end + + def translated_versions + translations + end + + def translated_versions=(translation_attrs) + if translation_attrs.respond_to? :each_value # Hash => updating + translation_attrs.each_value do |attrs| + t = translation(attrs[:locale]) || PublicBody::Translation.new + t.attributes = attrs + calculate_cached_fields(t) + t.save! + end + else # Array => creating + translation_attrs.each do |attrs| + new_translation = PublicBody::Translation.new(attrs) + calculate_cached_fields(new_translation) + translations << new_translation + end + end + end + # Make sure publication_scheme gets the correct default value. # (This would work automatically, were publication_scheme not a translated attribute) def after_initialize @@ -172,7 +206,7 @@ class PublicBody < ActiveRecord::Base return self.created_at.strftime("%Y%m%d%H%M%S") end def variety - "authority" + return "authority" end # if the URL name has changed, then all requested_from: queries @@ -191,7 +225,6 @@ class PublicBody < ActiveRecord::Base # When name or short name is changed, also change the url name def short_name=(short_name) - globalize.write(self.class.locale || I18n.locale, :short_name, short_name) self[:short_name] = short_name self.update_url_name @@ -204,15 +237,15 @@ class PublicBody < ActiveRecord::Base end def update_url_name - url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body') - self.url_name = url_name + self.url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body') end + # Return the short name if present, or else long name def short_or_long_name - if self.short_name.nil? # can happen during construction + if self.short_name.nil? || self.short_name.empty? # 'nil' can happen during construction self.name else - self.short_name.empty? ? self.name : self.short_name + self.short_name end end @@ -311,9 +344,10 @@ class PublicBody < ActiveRecord::Base # Import from CSV. Just tests things and returns messages if dry_run is true. # Returns an array of [array of errors, array of notes]. If there are errors, # always rolls back (as with dry_run). - def self.import_csv(csv, tag, dry_run, editor, additional_locales = []) + def self.import_csv(csv, tag, dry_run, editor, available_locales = []) errors = [] notes = [] + available_locales = [I18n.default_locale] if available_locales.empty? begin ActiveRecord::Base.transaction do @@ -330,7 +364,7 @@ class PublicBody < ActiveRecord::Base end set_of_importing = Set.new() - field_names = { 'name'=>1, 'email'=>2 } # Default values in case no field list is given + field_names = { 'name'=>1, 'request_email'=>2 } # Default values in case no field list is given line = 0 CSV::Reader.parse(csv) do |row| line = line + 1 @@ -341,57 +375,65 @@ class PublicBody < ActiveRecord::Base row.each_with_index {|field, i| field_names[field] = i} next end + + fields = {} + field_names.each{|name, i| fields[name] = row[i]} name = row[field_names['name']] - email = row[field_names['email']] + email = row[field_names['request_email']] next if name.nil? - if email.nil? - email = '' # unknown/bad contact is empty string - end name.strip! email.strip! - if email != "" && !MySociety::Validate.is_valid_email(email) - errors.push "error: line " + line.to_s + ": invalid email " + email + " for authority '" + name + "'" + if !email.nil? && !email.empty? && !MySociety::Validate.is_valid_email(email) + errors.push "error: line #{line.to_s}: invalid email '#{email}' for authority '#{name}'" next end + + field_list = ['name', 'short_name', 'request_email', 'notes', 'publication_scheme', 'home_page'] + + if public_body = bodies_by_name[name] + available_locales.each do |locale| + PublicBody.with_locale(locale) do + changed = {} + field_list.each do |field_name| + localized_field_name = (locale === I18n.default_locale) ? field_name : "#{field_name}.#{locale}" + localized_value = field_names[localized_field_name] && row[field_names[localized_field_name]] + if !localized_value.nil? and public_body.send(field_name) != localized_value + changed[field_name] = "#{public_body.send(field_name)}: #{localized_value}" + public_body.send("#{field_name}=", localized_value) + end + end - if bodies_by_name[name] - # Already have the public body, just update email - public_body = bodies_by_name[name] - if public_body.request_email != email - notes.push "line " + line.to_s + ": updating email for '" + name + "' from " + public_body.request_email + " to " + email - public_body.request_email = email - public_body.last_edit_editor = editor - public_body.last_edit_comment = 'Updated from spreadsheet' - public_body.save! - end - - additional_locales.each do |locale| - localized_name = field_names["name.#{locale}"] && row[field_names["name.#{locale}"]] - PublicBody.with_locale(locale) do - if !localized_name.nil? and public_body.name != localized_name - notes.push "line " + line.to_s + ": updating name for '#{name}' from '#{public_body.name}' to '#{localized_name}' (locale: #{locale})." - public_body.name = localized_name + unless changed.empty? + notes.push "line #{line.to_s}: updating authority '#{name}' (locale: #{locale}):\n\t#{changed.to_json}" + public_body.last_edit_editor = editor + public_body.last_edit_comment = 'Updated from spreadsheet' public_body.save! end end end - else - # New public body - notes.push "line " + line.to_s + ": new authority '" + name + "' with email " + email - public_body = PublicBody.new(:name => name, :request_email => email, :short_name => "", :home_page => "", :publication_scheme => "", :notes => "", :last_edit_editor => editor, :last_edit_comment => 'Created from spreadsheet') - public_body.tag_string = tag - public_body.save! - - additional_locales.each do |locale| - localized_name = field_names["name.#{locale}"] && row[field_names["name.#{locale}"]] - if !localized_name.nil? - PublicBody.with_locale(locale) do - notes.push "line " + line.to_s + ": (aka '#{localized_name}' in locale #{locale})" - public_body.name = localized_name - public_body.publication_scheme = "" + else # New public body + public_body = PublicBody.new(:name=>name, :short_name=>"", :request_email=>"") + available_locales.each do |locale| + PublicBody.with_locale(locale) do + changed = {} + field_list.each do |field_name| + localized_field_name = (locale === I18n.default_locale) ? field_name : "#{field_name}.#{locale}" + localized_value = field_names[localized_field_name] && row[field_names[localized_field_name]] + if !localized_value.nil? and public_body.send(field_name) != localized_value + changed[field_name] = localized_value + public_body.send("#{field_name}=", localized_value) + end + end + + unless changed.empty? + notes.push "line #{line.to_s}: creating new authority '#{name}' (locale: #{locale}):\n\t#{changed.to_json}" + public_body.publication_scheme = public_body.publication_scheme || "" + public_body.tag_string = tag + public_body.last_edit_editor = editor + public_body.last_edit_comment = 'Created from spreadsheet' public_body.save! end end diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index fc317d20d..e244aaac9 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -266,12 +266,12 @@ class RequestMailer < ApplicationMailer end end - # Send email alerts for new responses which haven't been classified. Goes - # out 3 days after last update of event, then after 7, then after 24. + # Send email alerts for new responses which haven't been classified. By default, + # it goes out 3 days after last update of event, then after 10, then after 24. def self.alert_new_response_reminders - self.alert_new_response_reminders_internal(3, 'new_response_reminder_1') - self.alert_new_response_reminders_internal(10, 'new_response_reminder_2') - self.alert_new_response_reminders_internal(24, 'new_response_reminder_3') + MySociety::Config.get("NEW_RESPONSE_REMINDER_AFTER_DAYS", [3, 10, 24]).each_with_index do |days, i| + self.alert_new_response_reminders_internal(days, "new_response_reminder_#{i+1}") + end end def self.alert_new_response_reminders_internal(days_since, type_code) info_requests = InfoRequest.find_old_unclassified(:order => 'info_requests.id', diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 16a0dab87..1cd957549 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -105,9 +105,19 @@ class TrackThing < ActiveRecord::Base return track_thing end - def TrackThing.create_track_for_search_query(query) + def TrackThing.create_track_for_search_query(query, variety_postfix = nil) track_thing = TrackThing.new track_thing.track_type = 'search_query' + if !(query =~ /variety:/) + case variety_postfix + when "requests" + query += " variety:sent" + when "users" + query += " variety:user" + when "authorities" + query += " variety:authority" + end + end track_thing.track_query = query return track_thing end @@ -203,15 +213,15 @@ class TrackThing < ActiveRecord::Base @params = { # Website :list_description => "'<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest\">" + CGI.escapeHTML(self.track_query) + "</a>' in new requests/responses", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how - :verb_on_page => _("Track things matching '{{query}}' by email", :query=>CGI.escapeHTML(self.track_query)), - :verb_on_page_already => _("You are already tracking things matching '{{query}}' by email", :query=>CGI.escapeHTML(self.track_query)), + :verb_on_page => _("Track things matching this search by email"), + :verb_on_page_already => _("You are already tracking things matching this search by email"), # Email - :title_in_email => _("Requests or responses matching '{{query}}'", :query=>self.track_query), - :title_in_rss => _("Requests or responses matching '{{query}}'", :query=>self.track_query), + :title_in_email => _("Requests or responses matching your saved search"), + :title_in_rss => _("Requests or responses matching your saved search"), # Authentication - :web => _("To follow requests and responses matching '{{query}}'", :query=>CGI.escapeHTML(self.track_query)), - :email => _("Then you will be emailed whenever a new request or response matches '{{query}}'.", :query=>CGI.escapeHTML(self.track_query)), - :email_subject => _("Confirm you want to be emailed about new requests or responses matching '{{query}}'", :query=>self.track_query), + :web => _("To follow requests and responses matching your search"), + :email => _("Then you will be emailed whenever a new request or response matches your search."), + :email_subject => _("Confirm you want to be emailed about new requests or responses matching your search"), # RSS sorting - XXX hmmm, we don't really know which to use # here for sorting. Might be a query term (e.g. 'cctv'), in # which case newest is good, or might be something like diff --git a/app/views/admin_public_body/_form.rhtml b/app/views/admin_public_body/_form.rhtml index b1516be2e..191b29e89 100644 --- a/app/views/admin_public_body/_form.rhtml +++ b/app/views/admin_public_body/_form.rhtml @@ -2,48 +2,60 @@ <!--[form:public_body]--> -<div id="tag_help"> - <h2>List of tags</h2> - <% first_row = true %> - <% for row in PublicBodyCategories::CATEGORIES_WITH_HEADINGS %> - <% if row.instance_of?(Array) %> - <% if row[0] != 'other' %> - <strong><%= row[0] %></strong>=<%= row[1] %> - <br/> - <% end %> - <% elsif row != 'Miscellaneous' %> - <% if not first_row %> - <% else %> - <% first_row = false %> - <% end %> - <h3><%=h row%></h3> - <% end %> +<div id="div-locales"> + <ul> + <% for locale in I18n.available_locales do %> + <li><a href="#div-locale-<%=locale.to_s%>"><%=locale_name(locale.to_s)%></a></li> <% end %> + </ul> + +<% + for locale in I18n.available_locales do + if locale==I18n.default_locale # The default locale is submitted as part of the bigger object... + prefix = 'public_body' + object = @public_body + else # ...but additional locales go "on the side" + prefix = "public_body[translated_versions][]" + object = @public_body.new_record? ? + PublicBody::Translation.new : + @public_body.translation(locale.to_s) || PublicBody::Translation.new + end + + fields_for prefix, object do |t| +%> + <div id="div-locale-<%=locale.to_s%>"> + <%= t.hidden_field :locale, :value => locale.to_s %> + + <p><label for="public_body_name">Name</label><br/> + <%= t.text_field :name, :size => 60 %></p> + + <p><label for="public_body_short_name">Short name <small>(only put in abbreviations which are really used, otherwise leave blank. Short or long name is used in the URL - don't worry about breaking URLs through renaming, as the history is used to redirect)</small></label><br/> + <%= t.text_field :short_name, :size => 60 %></p> + + <p><label for="public_body_request_email">Request email <small>(set to <strong>blank</strong> (empty string) if can't find an address; these emails are <strong>public</strong> as anyone can view with a CAPTCHA)</small></label><br/> + <%= t.text_field :request_email, :size => 40 %></p> + + <p><label for="public_body_publication_scheme">Publication scheme URL</label><br/> + <%= t.text_field :publication_scheme, :size => 60 %></p> + + <p><label for="public_body_notes">Public notes</label> <small>(HTML, for users to consider when making FOI requests to the authority)</small><br/> + <%= t.text_area :notes, :rows => 3, :cols => 60 %></p> + </div> +<% + end + end +%> </div> -<p><label for="public_body_name">Name</label><br/> -<%= text_field 'public_body', 'name', :size => 60 %></p> - -<p><label for="public_body_short_name">Short name <small>(only put in abbreviations which are really used, otherwise leave blank. Short or long name is used in the URL - don't worry about breaking URLs through renaming, as the history is used to redirect)</small></label><br/> -<%= text_field 'public_body', 'short_name', :size => 60 %></p> - -<p><label for="public_body_request_email">Request email <small>(set to <strong>blank</strong> (empty string) if can't find an address; these emails are <strong>public</strong> as anyone can view with a CAPTCHA)</small></label><br/> -<%= text_field 'public_body', 'request_email', :size => 40 %></p> +<h3>Common Fields</h3> <p><label for="public_body_tag_string">Tags <small>(space separated; see list of tags on the right; also <strong>not_apply</strong> if FOI and EIR no longer apply to authority, <strong>eir_only</strong> if EIR but not FOI applies to authority, <strong>defunct</strong> if the authority no longer exists; charity:NUMBER if a registered charity)</small></label><br/> -<%= text_field 'public_body', 'tag_string', :size => 60 %></p> +<%= f.text_field :tag_string, :size => 60 %></p> <p><label for="public_body_home_page">Home page <small>(of whole authority, not just their FOI page; set to <strong>blank</strong> (empty string) to guess it from the email)</small></label><br/> -<%= text_field 'public_body', 'home_page', :size => 60 %></p> - -<p><label for="public_body_publication_scheme">Publication scheme URL</label><br/> -<%= text_field 'public_body', 'publication_scheme', :size => 60 %></p> - -<p><label for="public_body_notes">Public notes</label> <small>(HTML, for users to consider when making FOI requests to the authority)</small><br/> -<%= text_area 'public_body', 'notes', :rows => 3, :cols => 60 %></p> +<%= f.text_field :home_page, :size => 60 %></p> <p><label for="public_body_last_edit_comment"><strong>Comment</strong> for this edit</label> <small>(put URL or other source of new info)</small><br/> -<%= text_area 'public_body', 'last_edit_comment', :rows => 3, :cols => 60 %></p> -<!--[eoform:public_body]--> - +<%= f.text_area :last_edit_comment, :rows => 3, :cols => 60 %></p> +<!--[eoform:public_body]--> diff --git a/app/views/admin_public_body/_tag_help.rhtml b/app/views/admin_public_body/_tag_help.rhtml new file mode 100644 index 000000000..7954ff992 --- /dev/null +++ b/app/views/admin_public_body/_tag_help.rhtml @@ -0,0 +1,18 @@ +<div id="tag_help"> + <h2>List of tags</h2> + <% first_row = true %> + <% for row in PublicBodyCategories::CATEGORIES_WITH_HEADINGS %> + <% if row.instance_of?(Array) %> + <% if row[0] != 'other' %> + <strong><%= row[0] %></strong>=<%= row[1] %> + <br/> + <% end %> + <% elsif row != 'Miscellaneous' %> + <% if not first_row %> + <% else %> + <% first_row = false %> + <% end %> + <h3><%=h row%></h3> + <% end %> + <% end %> +</div>
\ No newline at end of file diff --git a/app/views/admin_public_body/edit.rhtml b/app/views/admin_public_body/edit.rhtml index 005ec93ce..1883eb083 100644 --- a/app/views/admin_public_body/edit.rhtml +++ b/app/views/admin_public_body/edit.rhtml @@ -1,23 +1,30 @@ - - <h1><%=@title%></h1> -<% form_tag '../update/' + @public_body.id.to_s do %> - <%= render :partial => 'form' %> - <p><%= submit_tag 'Save', :accesskey => 's' %></p> -<% end %> +<script> + $(function() { + $("#div-locales").tabs(); + }); +</script> -<p> -<%= link_to 'Show', '../show/' + @public_body.id.to_s %> | -<%= link_to 'List all', '../list' %> -</p> +<%= render :partial => 'tag_help' %> -<% if @public_body.info_requests.size == 0 %> - <% form_tag('../destroy/' + @public_body.id.to_s) do %> - <p> - <%= hidden_field_tag(:public_body_id, { :value => @public_body.id } ) %> - <%= submit_tag "Destroy " + @public_body.name %> (this is permanent!) - </p> +<div id="public_body_form"> + <% form_for @public_body, :url => {:action => 'update'} do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> + <p><%= f.submit 'Save', :accesskey => 's' %></p> <% end %> -<% end %> + <p> + <%= link_to 'Show', '../show/' + @public_body.id.to_s %> | + <%= link_to 'List all', '../list' %> + </p> + + <% if @public_body.info_requests.size == 0 %> + <% form_tag('../destroy/' + @public_body.id.to_s) do %> + <p> + <%= hidden_field_tag(:public_body_id, { :value => @public_body.id } ) %> + <%= submit_tag "Destroy " + @public_body.name %> (this is permanent!) + </p> + <% end %> + <% end %> +</div> diff --git a/app/views/admin_public_body/import_csv.rhtml b/app/views/admin_public_body/import_csv.rhtml index 50a4b951a..3bcc4bf41 100644 --- a/app/views/admin_public_body/import_csv.rhtml +++ b/app/views/admin_public_body/import_csv.rhtml @@ -23,16 +23,19 @@ <p><strong>CSV file format:</strong> A first row with the list of fields, starting with '#', is optional but highly recommended. The fields 'name' - and 'email' are required; additionaly, translated values are supported by + and 'request_email' are required; additionaly, translated values are supported by adding the locale name to the field name, e.g. 'name.es', 'name.de'... Example: </p> <blockquote> - #id,name,email,name.es<br/> + #id,name,request_email,name.es<br/> 1,An Authority,a@example.com,Un organismo<br/> 2,Another One,another@example.com,Otro organismo<br/> </blockquote> + <p>Supported files: name (i18n), short_name (i18n), request_email (i18n), notes (i18n), + publication_scheme (i18n), home_page.</p> + <p><strong>Note:</strong> Choose <strong>dry run</strong> to test, without actually altering the database. Choose <strong>upload</strong> to actually make the changes. In either case, you will be shown any errors, or details diff --git a/app/views/admin_public_body/new.rhtml b/app/views/admin_public_body/new.rhtml index 95208b5b3..11186ee47 100644 --- a/app/views/admin_public_body/new.rhtml +++ b/app/views/admin_public_body/new.rhtml @@ -2,11 +2,21 @@ <h1><%=@title%></h1> -<% form_tag 'create' do %> - <%= render :partial => 'form' %> - <p><%= submit_tag "Create" %></p> -<% end %> - -<p> -<%= link_to 'List all', 'list' %> -</p> +<script> + $(function() { + $("#div-locales").tabs(); + }); +</script> + +<%= render :partial => 'tag_help' %> + +<div id="public_body_form"> + <% form_for :public_body, @public_body, :url => {:action => "create"} do |f| %> + <%= render :partial => 'form', :locals => {:f => f} %> + <p><%= f.submit "Create" %></p> + <% end %> + + <p> + <%= link_to 'List all', 'list' %> + </p> +</div> diff --git a/app/views/admin_public_body/show.rhtml b/app/views/admin_public_body/show.rhtml index c1292c63a..643ccf5e8 100644 --- a/app/views/admin_public_body/show.rhtml +++ b/app/views/admin_public_body/show.rhtml @@ -12,7 +12,7 @@ <% if column.name == 'home_page' and !column.name.empty? %> <%= link_to(h(@public_body.send(column.name)), @public_body.send(column.name)) %> <% elsif column.name == 'request_email' and !column.name.empty? %> - <%= link_to(h(@public_body.send(column.name)), "mailto:" + @public_body.send(column.name)) %> + <%= link_to(h(@public_body.send(column.name)), "mailto:#{@public_body.send(column.name)}") %> <% if !@public_body.is_requestable? %> (not requestable due to: <%=h @public_body.not_requestable_reason %><% if @public_body.is_followupable? %>; but followupable<% end %>) <% end %> @@ -32,7 +32,14 @@ </p> <p> - <%= link_to 'Public page', main_url(public_body_url(@public_body)) %> + <%= + # url_name can be missing if the name hasn't been set for this locale + if !@public_body.url_name.nil? + link_to 'Public page', main_url(public_body_url(@public_body)) + else + 'Public page not available' + end + %> | <%= link_to 'Edit', '../edit/' + @public_body.id.to_s %> </p> diff --git a/app/views/general/advanced_search.rhtml b/app/views/general/advanced_search.rhtml new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/app/views/general/advanced_search.rhtml diff --git a/app/views/general/search.rhtml b/app/views/general/search.rhtml index 1d934f65a..853765a8a 100644 --- a/app/views/general/search.rhtml +++ b/app/views/general/search.rhtml @@ -2,73 +2,143 @@ <% if @query.nil? %> <% @title = _("Search Freedom of Information requests, public authorities and users") %> - <h1><%=@title%></h1> <% elsif @total_hits == 0 %> - <%= _("Nothing found for ‘{{search_terms}}’", :search_terms => h(@query)) %> + <% @title = _('There were no requests matching your query.') %> <% else %> <% @title = _("Results page {{page_number}}", :page_number => @page.to_s) %> <% end%> - <% @include_request_link_in_authority_listing = true %> -<% if @bodies && (@page == 1 || @xapian_bodies.results.size > 0) %> - <div id="stepwise_instructions"> - <p><strong><%=_("Next, select the public authority you'd like to make the request from.") %></strong></p> - <p><% _('Can\'t find it? <a href="%s">Browse all</a> or <a href="%s">ask us to add it</a>.') % [list_public_bodies_default, "#{help_requesting_path}#missing_body"] %></p> - <p> - </div> -<% end %> +<h1><%=@title%></h1> +<script> + $(function() { + $(".use-datepicker").datepicker({dateFormat: 'yy-mm-dd'}); + }); +</script> -<% form_tag({:action => "search_redirect"}, {:id => "search_form"}) do %> - <p> - <%= text_field_tag 'query', @query, { :size => 40 } %> - <%= hidden_field_tag 'sortby', @inputted_sortby %> - <% if @bodies %> - <%= hidden_field_tag 'bodies', 1 %> - <% end %> - <%= submit_tag _("Search") %> - <% if not @show_tips %> - <%= link_to _('Advanced search tips'), search_redirect_path %> + +<% if @advanced %> + <p><%= _('To use the advanced search, combine phrases and labels as described in the search tips below.') %></p> + <% form_tag(advanced_search_url, :method => "get") do %> + <%= label_tag(:query, _("Search for:")) %> + <%= text_field_tag(:query, params[:query], { :size => 40 }) %> + <%= submit_tag("Search") %> + <% end %> + <p><%= link_to(_("Simple search"), search_redirect_url) %></p> + +<% else %> + +<div id="list-filter"> + <div id="simple-search-box"> + <% form_tag(request.url, :method => "get") do %> + <%= label_tag(:query, _("Search for:")) %> + <%= text_field_tag(:query, params[:query], { :size => 40 }) %> + <%= submit_tag("Search") %> + </div> + + <fieldset> + <legend> + <%= _("Filters:") %> + </legend> +<div id="common-subfilters"> + <div id="variety-filter"> + <ul> + <% for variety, label in [ + ["all", _("everything")], + ["requests", _("requests")], + ["users", _("users")], + ["bodies", _("authorities")]]%> + <li> + <% if @variety_postfix != variety %> + <% if variety != "users" %> + <%= link_to label, search_url([params[:query], @common_query], variety, @sort_postfix), :method => :get %> + <% else %> + <%= link_to label, search_url(params[:query], variety, @sort_postfix), :method => :get %> + <% end %> + <% else %> + <%= label %> <% end %> - </p> + </li> + <% end %> + </ul> + </div> + +<% if false %> +<%-# Commented out for now as tags are of limited use when users can't see them. This will change in the future! -%> +<% if @variety_postfix != "users" %> + <div> + <%= label_tag(:query, _("Tags (separated by a space):")) %><%= text_field_tag(:tags, params[:tags], { :size => 20 }) %> + <% for tag in InfoRequest.get_tags %> + <%= tag.name_and_value %> + <% end %> + </div> +<% end %> +<% end %> +</div> + +<% if @variety_postfix == "requests" %> +<div id="requests-subfilters"> + <div> + <%= _("Only show:") %> <br /> + <% [["successful", _("successful requests")], + ["unsuccessful", _("unsuccessful requests")], + ["awaiting", _("unresolved requests")], + ["internal_review", _("internal reviews")]].each_with_index do |item, index| + + status, title = item %> + <%= check_box_tag "latest_status[]", status, params[:latest_status].nil? ? false : params[:latest_status].include?(status), :id => "latest_status_#{index}" %> + <%= label_tag("latest_status_#{index}", title) %> <br/> + <% end %> + </div> + <div> + <%= _("Search for words in:") %> <br/> + <% [["sent", _("messages from users")], + ["response", _("messages from authorities")], + ["comment", _("comments")]].each_with_index do |item, index| + variety, title = item %> + + <%= check_box_tag "request_variety[]", variety, params[:request_variety].nil? ? true : params[:request_variety].include?(variety), :id => "request_variety_#{index}" %> + <%= label_tag("request_variety_#{index}", title) %> <br/> + <% end %> + </div> + <div> + Search between dates: + <%= text_field_tag(:request_date_after, params[:request_date_after], {:class => "use-datepicker", :size => 10}) %> - + <%= text_field_tag(:request_date_before, params[:request_date_before], {:class => "use-datepicker", :size => 10}) %> + </div> +</div> <% end %> + <%= submit_tag("Filter") %> +<% end %> + </fieldset> +</div> + +<p><%= link_to(_("Advanced search"), advanced_search_url) %></p> +<% end %> <% if !@query.nil? %> <p> - <%=link_to_unless @sortby == 'relevant', _("Show most relevant results first"), search_url(@query, 'relevant') %> + <%=link_to_unless @sortby == 'relevant', _("Show most relevant results first"), search_url(@query, @variety_postfix, 'relevant', @advanced) %> | - <%=link_to_unless @sortby == 'newest', _("Newest results first"), search_url(@query, 'newest') %> + <%=link_to_unless @sortby == 'newest', _("Newest results first"), search_url(@query, @variety_postfix, 'newest', @advanced) %> <% if @sortby == 'described' %> | <%= _('Recently described results first') %> <% end %> </p> <% end %> -<% if @bodies && !@query.nil? && @xapian_bodies.results.size == 0 && @page == 1 %> - <h1><%= _('No public authorities found') %></h1> - <% if @spelling_correction %> - <p id="did_you_mean"><%= _('Did you mean: {{correction}}', - :correction => search_link(@spelling_correction, @postfix)) %></p> - <% end %> - <p><%= _('<a href="%s">Browse all</a> or <a href="%s">ask us to add one</a>.') % [list_public_bodies_default, help_requesting_path + '#missing_body'] %></p> -<% end %> - -<% if @total_hits == 0 %> - <h1><%=@title %></h1> -<% end %> - <% if not @query.nil? %> <% if @spelling_correction %> - <p id="did_you_mean"><%= _('Did you mean: {{correction}}', :correction => search_link(@spelling_correction, @postfix)) %></p> + <p id="did_you_mean"><%= _('Did you mean: {{correction}}', :correction => search_link(@spelling_correction, @variety_postfix, @sort_postfix, @advanced)) %></p> <% end %> - <% if (!@bodies || @xapian_requests.results.size == 0) && @track_thing && (@xapian_bodies.results.size > 0 || @xapian_users.results.size > 0 || @total_hits == 0)%> + <% if (!@bodies || @xapian_requests_hits == 0) && @track_thing && (@xapian_bodies_hits > 0 || @xapian_users_hits > 0 || @total_hits == 0)%> <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => false, :location => 'main' } %> <% end %> - <% if @xapian_bodies.results.size > 0 %> - <% if @xapian_bodies.results.size == 1 && @page == 1 %> - <h1><%= _('One public authority matching ‘{{user_search_query}}’', :user_search_query => h(@query)) %></h1> + <% if @xapian_bodies_hits > 0 %> + <% if @xapian_bodies_hits == 1 && @page == 1 %> + <h1><%= _('One public authority matching your search', :user_search_query => h(@query)) %></h1> <% else %> <h1><%= _('Public authorities {{start_count}} to {{end_count}} of {{total_count}} for {{user_search_query}}', :start_count => ((@page-1)*@bodies_per_page+1).to_s, :end_count => [@page*@bodies_per_page, @xapian_bodies.matches_estimated].min.to_s, :total_count => @xapian_bodies.matches_estimated.to_s, :user_search_query => h(@query)) %></h1> <% end %> @@ -80,8 +150,8 @@ <%= will_paginate WillPaginate::Collection.new(@page, @bodies_per_page, @xapian_bodies.matches_estimated) %> <% end %> - <% if @xapian_users.results.size > 0 %> - <% if @xapian_users.results.size == 1 && @page == 1 %> + <% if @xapian_users_hits > 0 %> + <% if @xapian_users_hits == 1 && @page == 1 %> <h1><%= _("One person matching ‘{{user_search_query}}’", :user_search_query => h(@query)) %></h1> <% else %> <h1><%= _("People {{start_count}} to {{end_count}} of {{total_count}} for ‘{{user_search_query}}’", :start_count => ((@page-1)*@users_per_page+1).to_s, :end_count => [@page*@users_per_page, @xapian_users.matches_estimated].min.to_s, :total_count => @xapian_users.matches_estimated.to_s, :user_search_query => h(@query)) %></h1> @@ -94,11 +164,11 @@ <%= will_paginate WillPaginate::Collection.new(@page, @users_per_page, @xapian_users.matches_estimated) %> <% end %> - <% if @xapian_requests.results.size > 0 %> - <% if @xapian_requests.results.size == 1 && @page == 1 %> - <h1><%= _("One FOI request matching ‘{{user_search_query}}’", :user_search_query => h(@query)) %></h1> + <% if @xapian_requests_hits > 0 %> + <% if @xapian_requests_hits == 1 && @page == 1 %> + <h1><%= _("One FOI request matching your search", :user_search_query => h(@query)) %></h1> <% else %> - <h1><%= _("FOI requests {{start_count}} to {{end_count}} of {{total_count}} for ‘{{user_search_query}}’", :start_count => ((@page-1)*@requests_per_page+1).to_s, :end_count => [@page*@requests_per_page, @xapian_requests.matches_estimated].min.to_s, :total_count => @xapian_requests.matches_estimated.to_s, :user_search_query => h(@query)) %></h1> + <h1><%= _("FOI requests {{start_count}} to {{end_count}} of {{total_count}}", :start_count => ((@page-1)*@requests_per_page+1).to_s, :end_count => [@page*@requests_per_page, @xapian_requests.matches_estimated].min.to_s, :total_count => @xapian_requests.matches_estimated.to_s, :user_search_query => h(@query)) %></h1> <% end %> <% if @track_thing %> @@ -117,7 +187,10 @@ <% end %> <% end %> -<% if @show_tips %> +<% if @advanced %> + +<div id="advanced-search-tips"> + <a name="show-tips"></a> <h2><%= _("Advanced search tips")%></h2> <ul> <li><%= _("Enter words that you want to find separated by spaces, e.g. <strong>climbing lane</strong>") %></li> @@ -139,28 +212,30 @@ <h2 id="statuses"><%= _('Table of statuses') %></h2> <table class="status_table"> - <tr><td><strong><%=search_link('status:waiting_response')%></strong></td><td><%= _('Waiting for the public authority to reply') %></td></tr> - <tr><td><strong><%=search_link('status:not_held')%></strong></td><td><%= _('The public authority does not have the information requested') %></td></tr> - <tr><td><strong><%=search_link('status:rejected')%></strong></td><td><%= _('The request was refused by the public authority') %></td></tr> - <tr><td><strong><%=search_link('status:partially_successful')%></strong></td><td><%= _('Some of the information requested has been received') %></td></tr> - <tr><td><strong><%=search_link('status:successful')%></strong></td><td><%= _('All of the information requested has been received') %></td></tr> - <tr><td><strong><%=search_link('status:waiting_clarification')%></strong></td><td><%= _('The public authority would like part of the request explained') %></td></tr> - <tr><td><strong><%=search_link('status:gone_postal')%></strong></td><td><%= _('The public authority would like to / has responded by post') %></td></tr> - <tr><td><strong><%=search_link('status:internal_review')%></strong></td><td><%= _('Waiting for the public authority to complete an internal review of their handling of the request') %></td></tr> - <tr><td><strong><%=search_link('status:error_message')%></strong></td><td><%= _('Received an error message, such as delivery failure.') %></td></tr> - <tr><td><strong><%=search_link('status:requires_admin')%></strong></td><td><%= _('A strange reponse, required attention by the {{site_name}} team', :site_name=>site_name) %></td></tr> - <tr><td><strong><%=search_link('status:user_withdrawn')%></strong></td><td><%= _('The requester has abandoned this request for some reason') %></td></tr> + <tr><td><strong><%=search_link('status:waiting_response', nil, nil, true)%></strong></td><td><%= _('Waiting for the public authority to reply') %></td></tr> + <tr><td><strong><%=search_link('status:not_held', nil, nil, true)%></strong></td><td><%= _('The public authority does not have the information requested') %></td></tr> + <tr><td><strong><%=search_link('status:rejected', nil, nil, true)%></strong></td><td><%= _('The request was refused by the public authority') %></td></tr> + <tr><td><strong><%=search_link('status:partially_successful', nil, nil, true)%></strong></td><td><%= _('Some of the information requested has been received') %></td></tr> + <tr><td><strong><%=search_link('status:successful', nil, nil, true)%></strong></td><td><%= _('All of the information requested has been received') %></td></tr> + <tr><td><strong><%=search_link('status:waiting_clarification', nil, nil, true)%></strong></td><td><%= _('The public authority would like part of the request explained') %></td></tr> + <tr><td><strong><%=search_link('status:gone_postal', nil, nil, true)%></strong></td><td><%= _('The public authority would like to / has responded by post') %></td></tr> + <tr><td><strong><%=search_link('status:internal_review', nil, nil, true)%></strong></td><td><%= _('Waiting for the public authority to complete an internal review of their handling of the request') %></td></tr> + <tr><td><strong><%=search_link('status:error_message', nil, nil, true)%></strong></td><td><%= _('Received an error message, such as delivery failure.') %></td></tr> + <tr><td><strong><%=search_link('status:requires_admin', nil, nil, true)%></strong></td><td><%= _('A strange reponse, required attention by the {{site_name}} team', :site_name=>site_name) %></td></tr> + <tr><td><strong><%=search_link('status:user_withdrawn', nil, nil, true)%></strong></td><td><%= _('The requester has abandoned this request for some reason') %></td></tr> </table> <h2 id="varieties"><%= _('Table of varieties') %></h2> <table class="status_table"> - <tr><td><strong><%=search_link('variety:sent')%></strong></td><td><%= _('Original request sent') %></td></tr> - <tr><td><strong><%=search_link('variety:followup_sent')%></strong></td><td><%= _('Follow up message sent by requester') %></td></tr> - <tr><td><strong><%=search_link('variety:response')%></strong></td><td><%= _('Response from a public authority') %></td></tr> - <tr><td><strong><%=search_link('variety:comment')%></strong></td><td><%= _('Annotation added to request') %></td></tr> - <tr><td><strong><%=search_link('variety:authority')%></strong></td><td><%= _('A public authority') %></td></tr> - <tr><td><strong><%=search_link('variety:user')%></strong></td><td><%= _('A {{site_name}} user', :site_name=>site_name) %></td></tr> + <tr><td><strong><%=search_link('variety:sent', nil, nil, true)%></strong></td><td><%= _('Original request sent') %></td></tr> + <tr><td><strong><%=search_link('variety:followup_sent', nil, nil, true)%></strong></td><td><%= _('Follow up message sent by requester') %></td></tr> + <tr><td><strong><%=search_link('variety:response', nil, nil, true)%></strong></td><td><%= _('Response from a public authority') %></td></tr> + <tr><td><strong><%=search_link('variety:comment', nil, nil, true)%></strong></td><td><%= _('Annotation added to request') %></td></tr> + <tr><td><strong><%=search_link('variety:authority', nil, nil, true)%></strong></td><td><%= _('A public authority') %></td></tr> + <tr><td><strong><%=search_link('variety:user', nil, nil, true)%></strong></td><td><%= _('A {{site_name}} user', :site_name=>site_name) %></td></tr> </table> +</div> + <% end %> diff --git a/app/views/layouts/admin.rhtml b/app/views/layouts/admin.rhtml index f0e9a7019..42ca5dbbb 100644 --- a/app/views/layouts/admin.rhtml +++ b/app/views/layouts/admin.rhtml @@ -3,6 +3,10 @@ <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" > <title><%= site_name %> admin<%= @title ? ":" : "" %> <%=@title%></title> + + <%= javascript_include_tag 'jquery.js', 'jquery-ui.min' %> + + <%= stylesheet_link_tag 'admin-theme/jquery-ui-1.8.15.custom.css', :rel => 'stylesheet'%> <%= stylesheet_link_tag 'admin', :title => "Main", :rel => "stylesheet" %> </head> <body> @@ -30,6 +34,6 @@ <% end %> <%= yield %> - + </body> </html> diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index 94ec5a956..e1e7a1e19 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -15,9 +15,10 @@ <%= site_name %> - <%= _('Make and browse Freedom of Information (FOI) requests') %> <% end %> </title> - + <link rel="shortcut icon" href="/favicon.ico"> - + <%= javascript_include_tag 'jquery.js', 'jquery-ui.min' %> + <%= stylesheet_link_tag 'admin-theme/jquery-ui-1.8.15.custom.css', :rel => 'stylesheet'%> <%= stylesheet_link_tag 'main', :title => "Main", :rel => "stylesheet" %> <!--[if LT IE 7]> <style type="text/css">@import url("/stylesheets/ie6.css");</style> diff --git a/app/views/public_body/list.rhtml b/app/views/public_body/list.rhtml index 5d88b1501..b3e945907 100644 --- a/app/views/public_body/list.rhtml +++ b/app/views/public_body/list.rhtml @@ -38,14 +38,17 @@ <h1><%=@title%></h1> +<% form_tag(request.url, :method => "get") do %> + <%= label_tag(:public_body_query, _("Search:")) %> + <%= text_field_tag(:public_body_query, params[:public_body_query]) %> + <%= submit_tag(_("Search")) %> +<% end %> + <p class="subtitle"> <%= @public_bodies.size %> <%= _('in total') %> (<%= _('<a href="%s">can\'t find the one you want?</a>') % [help_requesting_path + '#missing_body'] %>) </p> -<% if @tag.size == 1 %> - <p><%= render :partial => 'alphabet' %></p> -<% end %> <%= render :partial => 'body_listing', :locals => { :public_bodies => @public_bodies } %> <% if @tag.size == 1 && @public_bodies.size > 0 %> <p><%= render :partial => 'alphabet' %></p> diff --git a/app/views/public_body/show.rhtml b/app/views/public_body/show.rhtml index 36bba8851..1151b9966 100644 --- a/app/views/public_body/show.rhtml +++ b/app/views/public_body/show.rhtml @@ -64,7 +64,7 @@ </div> <% if !@xapian_requests.nil? %> - <% if @xapian_requests.results.empty? %> + <% if @public_body.info_requests.size == 0 %> <% if @public_body.eir_only? %> <h2><%= _('Environmental Information Regulations requests made using this site') %></h2> <p>Nobody has made any Environmental Information Regulations requests to <%=h(@public_body.name)%> using this site yet.</p> @@ -82,13 +82,19 @@ <%= @page_desc %> </h2> + <%= render :partial => 'request/request_filter_form' %> + <% for result in @xapian_requests.results %> <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %> <% end %> <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @public_body.info_requests.size) %> - <p> <%= _('Only requests made using {{site_name}} are shown.', :site_name => site_name) %></p> + <% if @xapian_requests.results.empty? %> + <p><% _('There were no requests matching your query.') %></p> + <% else %> + <p> <%= _('Only requests made using {{site_name}} are shown.', :site_name => site_name) %></p> + <% end %> <% end %> <% else %> diff --git a/app/views/request/_request_filter_form.rhtml b/app/views/request/_request_filter_form.rhtml new file mode 100644 index 000000000..fd1fc5910 --- /dev/null +++ b/app/views/request/_request_filter_form.rhtml @@ -0,0 +1,57 @@ +<script> + $(function() { + $(".use-datepicker").datepicker(); + }); +</script> + +<div id="list-filter"> + <div class="list-filter-item"> + Showing: + <ul class="request-selector"> + <% for status, label in [["all", _("all requests")], + ["successful", _("successful requests")], + ["unsuccessful", _("unsuccessful requests")], + ["awaiting", _("unresolved requests")]] %> + <li> + <% if params[:view] != status %> + <% if params[:controller] == "public_body" %> + <%= link_to label, url_for(:controller => "public_body", :action => "show", :view => status, :url_name => @public_body.url_name) + "?#{request.query_string}" %> + <% else %> + <%= link_to label, url_for(:controller => "request", :action => "list", :view => status) + "?#{request.query_string}" %> + <% end %> + <% else %> + <%= label %> + <% end %> + </li> + <% end %> + </ul> + </div> + <div class="list-filter-item"> + <% form_tag({}, :method => "get") do %> + <%= label_tag(:query, _("Search for:")) %> + <%= text_field_tag(:query, params[:query]) %> + </div> +<% if false # don't think we want this, but leaving as an example %> + <div class="list-filter-item"> + <%= _("Search for words in:") %> <br/> + <% [["sent", _("messages from users")], + ["response", _("messages from authorities")], + ["comment", _("comments")]].each_with_index do |item, index| + variety, title = item %> + + <%= check_box_tag "request_variety[]", variety, params[:request_variety].nil? ? true : params[:request_variety].include?(variety), :id => "request_variety_#{index}" %> + <%= label_tag("request_variety_#{index}", title) %> <br/> + <% end %> + </div> +<% end %> + <div class="list-filter-item"> + Search between dates: + <%= text_field_tag(:request_date_after, params[:request_date_after], {:class => "use-datepicker", :size => 10}) %> - + <%= text_field_tag(:request_date_before, params[:request_date_before], {:class => "use-datepicker", :size => 10}) %> + </div> + + <div class="list-filter-item"> + <%= submit_tag("Search") %> + </div> +<% end %> +</div> diff --git a/app/views/request/list.rhtml b/app/views/request/list.rhtml index 04dc0d010..a434566ac 100644 --- a/app/views/request/list.rhtml +++ b/app/views/request/list.rhtml @@ -1,19 +1,9 @@ -<div id="list_sidebar"> -<h1><%= _('Show only...')%></h1> -<ul> -<% for view, description, target in [ - ['successful', _('Successful responses'), request_list_successful_url(:view => 'successful')], - ['recent', _('Recently sent requests'), request_list_recent_url(:view => 'recent')] -] %> -<li> - <%= link_to_unless (@view == view), description, target %> -</li> -<% end %> -</ul> -</div> + <h1><%=@title%></h1> +<%= render :partial => 'request/request_filter_form' %> + <% if @track_thing %> <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => false, :location => 'main' } %> <% end %> |