aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/body_controller.rb26
-rw-r--r--app/models/public_body.rb10
-rw-r--r--app/views/body/list.rhtml13
-rw-r--r--config/routes.rb3
4 files changed, 44 insertions, 8 deletions
diff --git a/app/controllers/body_controller.rb b/app/controllers/body_controller.rb
index 103b500b8..940df1609 100644
--- a/app/controllers/body_controller.rb
+++ b/app/controllers/body_controller.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: body_controller.rb,v 1.7 2008-02-27 13:59:51 francis Exp $
+# $Id: body_controller.rb,v 1.8 2008-03-03 00:43:51 francis Exp $
class BodyController < ApplicationController
# XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL
@@ -35,7 +35,27 @@ class BodyController < ApplicationController
end
def list
- @public_bodies = PublicBody.paginate :order => "name", :page => params[:page], :per_page => 25
+ @tag = params[:tag]
+ if @tag.nil?
+ conditions = []
+ elsif @tag == 'other'
+ categories = PublicBody.categories_by_tag.keys
+ category_list = categories.map{|c| "'"+c+"'"}.join(",")
+ conditions = ['(select count(*) from public_body_tags where public_body_tags.public_body_id = public_bodies.id
+ and public_body_tags.name in (' + category_list + ')) = 0']
+ else
+ conditions = ['(select count(*) from public_body_tags where public_body_tags.public_body_id = public_bodies.id
+ and public_body_tags.name = ?) > 0', @tag]
+ end
+ @public_bodies = PublicBody.paginate(
+ :order => "public_bodies.name", :page => params[:page], :per_page => 25,
+ :conditions => conditions
+ )
+ @description = "All"
+ if not @tag.nil?
+ @description = PublicBody.categories_by_tag[@tag]
+ end
end
+end
+
- end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index c92972df1..cb1b8bfd0 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -22,7 +22,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: public_body.rb,v 1.29 2008-03-02 23:46:51 francis Exp $
+# $Id: public_body.rb,v 1.30 2008-03-03 00:43:51 francis Exp $
require 'csv'
require 'set'
@@ -36,6 +36,14 @@ class PublicBody < ActiveRecord::Base
has_many :public_body_tags
#acts_as_solr :fields => [:name, :short_name]
+
+ def self.categories_by_tag
+ {
+ "local_council" => "Local Councils",
+ "department" => "Departments",
+ "other" => "Other"
+ }
+ end
def validate
unless MySociety::Validate.is_valid_email(self.request_email)
diff --git a/app/views/body/list.rhtml b/app/views/body/list.rhtml
index bef1d8611..ddc3e0fd4 100644
--- a/app/views/body/list.rhtml
+++ b/app/views/body/list.rhtml
@@ -1,11 +1,18 @@
-<% @title = "All UK public bodies" %>
-
-<h1><%=@title%></h1>
+<p>
+Show only:
+<% for category, description in PublicBody.categories_by_tag %>
+<%= link_to_unless (@tag == category), description, list_public_bodies_url(:tag => category) %>
+<% end %>
+</p>
<p>
<a href="/help/about#missing_body">Are we missing a public body?</a>
</p>
+<% @title = "Public bodies - " + @description %>
+
+<h1><%=@title%></h1>
+
<%= render :partial => 'body_listing', :locals => { :public_bodies => @public_bodies } %>
<%= will_paginate(@public_bodies) %>
diff --git a/config/routes.rb b/config/routes.rb
index 17124bed2..81cb9c0ab 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: routes.rb,v 1.40 2008-02-27 13:59:52 francis Exp $
+# $Id: routes.rb,v 1.41 2008-03-03 00:43:52 francis Exp $
ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
@@ -38,6 +38,7 @@ ActionController::Routing::Routes.draw do |map|
map.with_options :controller => 'body' do |body|
body.list_public_bodies "/body", :action => 'list'
+ body.list_public_bodies "/body/list/:tag", :action => 'list'
body.show_public_body "/body/:url_name", :action => 'show'
end