aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2009-08-26 00:45:38 +0000
committerfrancis <francis>2009-08-26 00:45:38 +0000
commit3e1a49796ce3a9b322b90fcedeeffed3191f9dd3 (patch)
tree3847336a59f699b0442bd7f187927e827c78dc61
parentf5ac4360d615ca08d343cfaccd406d41336b94be (diff)
Put tags (with links) in column on list of bodies admin interface tables.
Interface to mass add tags to all bodies in admin search result.
-rw-r--r--app/controllers/admin_public_body_controller.rb31
-rw-r--r--app/models/public_body.rb5
-rw-r--r--app/views/admin_public_body/_one_list.rhtml41
-rw-r--r--app/views/admin_public_body/_tags.rhtml6
-rw-r--r--app/views/admin_public_body/list.rhtml45
-rw-r--r--app/views/admin_public_body/show.rhtml5
-rw-r--r--public/stylesheets/admin.css3
7 files changed, 98 insertions, 38 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index 4185acf4f..8f51a4cfb 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_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: admin_public_body_controller.rb,v 1.21 2009-03-24 09:01:28 tony Exp $
+# $Id: admin_public_body_controller.rb,v 1.22 2009-08-26 00:45:38 francis Exp $
class AdminPublicBodyController < AdminController
def index
@@ -12,8 +12,11 @@ class AdminPublicBodyController < AdminController
render :action => 'list'
end
- def list
+ def _lookup_query_internal
@query = params[:query]
+ if @query == ""
+ @query = nil
+ end
@public_bodies = PublicBody.paginate :order => "name", :page => params[:page], :per_page => 100,
:conditions => @query.nil? ? nil : ["lower(name) like lower('%'||?||'%') or
lower(short_name) like lower('%'||?||'%') or
@@ -21,6 +24,30 @@ class AdminPublicBodyController < AdminController
@public_bodies_by_tag = PublicBody.find_by_tag(@query)
end
+ def list
+ self._lookup_query_internal
+ end
+
+ def mass_tag_add
+ self._lookup_query_internal
+
+ if params[:new_tag] and params[:new_tag] != ""
+ if params[:table_name] == 'exact':
+ bodies = @public_bodies_by_tag
+ elsif params[:table_name] == 'substring':
+ bodies = @public_bodies
+ else
+ raise "Unknown table_name " + params[:table_name]
+ end
+ for body in bodies
+ body.add_tag_if_not_already_present(params[:new_tag])
+ end
+ flash[:notice] = "Added tag to table of bodies."
+ end
+
+ redirect_to admin_url('body/list') + "?query=" + @query # XXX construct this URL properly
+ end
+
def missing_scheme
# There might be a way to do this in ActiveRecord, but I can't find it
@public_bodies = PublicBody.find_by_sql("
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 83eb1e501..9362ecf20 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -26,7 +26,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.148 2009-07-14 11:29:12 francis Exp $
+# $Id: public_body.rb,v 1.149 2009-08-26 00:45:38 francis Exp $
require 'csv'
require 'set'
@@ -276,6 +276,9 @@ class PublicBody < ActiveRecord::Base
end
return false
end
+ def add_tag_if_not_already_present(tag)
+ self.tag_string = self.tag_string + " " + tag
+ end
# Find all public bodies with a particular tag
def self.find_by_tag(tag)
diff --git a/app/views/admin_public_body/_one_list.rhtml b/app/views/admin_public_body/_one_list.rhtml
new file mode 100644
index 000000000..3fb7ce284
--- /dev/null
+++ b/app/views/admin_public_body/_one_list.rhtml
@@ -0,0 +1,41 @@
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Tags</th>
+ <% for column in PublicBody.content_columns.map { |c| c.human_name } - [ "Name", "Last edit comment" ] %>
+ <th><%= column %></th>
+ <% end %>
+ </tr>
+<% for public_body in bodies %>
+ <tr class="<%= cycle('odd', 'even') %>">
+ <td><%= public_body_both_links(public_body) %></td>
+ <td><%= render :partial => 'tags', :locals => { :body => public_body} %></td>
+ <% for column in PublicBody.content_columns.map { |c| c.name } - [ "name", "last_edit_comment" ] %>
+ <td><%=h public_body.send(column) %></td>
+ <% end %>
+ </tr>
+<% end %>
+</table>
+
+<% form_tag(admin_url("body/mass_tag_add"), :method => "post", :class => "forms_on_one_line" ) do %>
+ <p>
+ <%= text_field_tag 'new_tag', params[:new_tag], { :size => 15, :id => "mass_add_tag_new_tag_" + table_name } %>
+ <%= hidden_field_tag(:query, params[:query], { :id => "mass_add_tag_query_" + table_name } ) %>
+ <%= hidden_field_tag(:table_name, table_name, { :id => "mass_add_tag_table_name_" + table_name } ) %>
+ <%= submit_tag "Add tag to all" %> (in table just above)
+ </p>
+<% end %>
+
+<!-- Not sure we need this remove tag option, so not coding it yet. Also worried it might be a
+bit dangerous / annoying to clear it (as search will fail so you won't even be able to see what
+you remove the tag from.
+<% if table_name == 'exact' %>
+ <% form_tag(admin_url("body/mass_tag_remove"), :method => "post", :class => "forms_on_one_line" ) do %>
+ <%= hidden_field_tag(:remove_tag, params[:query] ) %>
+ <%= hidden_field_tag(:query, params[:query] ) %>
+ <%= hidden_field_tag(:table_name, table_name ) %>
+ <%= submit_tag "Remove tag '" + h(params[:query]) + "' from all" %> (that have it, i.e. in table just above)
+ <% end %>
+<% end %> -->
+
+
diff --git a/app/views/admin_public_body/_tags.rhtml b/app/views/admin_public_body/_tags.rhtml
new file mode 100644
index 000000000..b7ecc1143
--- /dev/null
+++ b/app/views/admin_public_body/_tags.rhtml
@@ -0,0 +1,6 @@
+<%= body.public_body_tags.map { |t|
+ link_to(h(t.name), list_public_bodies_url(:tag => t.name)) +
+ ' (<a href="' + admin_url('body/list') + "?query=" + h(t.name) + '">admin</a>)'
+ }.join(' ') %>
+
+
diff --git a/app/views/admin_public_body/list.rhtml b/app/views/admin_public_body/list.rhtml
index 95ee80def..d8c2a1ef0 100644
--- a/app/views/admin_public_body/list.rhtml
+++ b/app/views/admin_public_body/list.rhtml
@@ -1,8 +1,15 @@
-<% @title = 'Listing public authorities' %>
+<% if @query.nil? %>
+ <% @title = 'Listing public authorities' %>
+<% else %>
+ <% @title = "Listing public authorities matching '" + @query + "'" %>
+<% end %>
<h1><%=@title%></h1>
<p>
+ <% if !@query.nil? %>
+ <%= link_to 'Show all', 'list' %> |
+ <% end %>
<%= link_to 'New public authority', 'new' %>
| <%= link_to 'Import from CSV file', 'import_csv' %>
</p>
@@ -17,40 +24,16 @@
<% if @public_bodies_by_tag.size > 0 %>
<h2>Exact tag matches</h2>
- <table>
- <tr>
- <% for column in PublicBody.content_columns.map { |c| c.human_name } - [ "Last edit comment" ] %>
- <th><%= column %></th>
- <% end %>
- </tr>
- <% for public_body in @public_bodies_by_tag %>
- <tr class="<%= cycle('odd', 'even') %>">
- <td><%= public_body_both_links(public_body) %></td>
- <% for column in PublicBody.content_columns.map { |c| c.name } - [ "name", "last_edit_comment" ] %>
- <td><%=h public_body.send(column) %></td>
- <% end %>
- </tr>
- <% end %>
- </table>
+ <%= render :partial => 'one_list', :locals => { :bodies => @public_bodies_by_tag, :table_name => 'exact' } %>
<% end %>
<% if @public_bodies.size > 0 %>
- <h2>Substring search matches</h2>
- <table>
- <tr>
- <% for column in PublicBody.content_columns.map { |c| c.human_name } - [ "Last edit comment" ] %>
- <th><%= column %></th>
- <% end %>
- </tr>
- <% for public_body in @public_bodies %>
- <tr class="<%= cycle('odd', 'even') %>">
- <td><%= public_body_both_links(public_body) %></td>
- <% for column in PublicBody.content_columns.map { |c| c.name } - [ "name", "last_edit_comment" ] %>
- <td><%=h public_body.send(column) %></td>
- <% end %>
- </tr>
+ <% if @query.nil? %>
+ <h2>All authorities</h2>
+ <% else %>
+ <h2>Substring search matches</h2>
<% end %>
- </table>
+ <%= render :partial => 'one_list', :locals => { :bodies => @public_bodies, :table_name => 'substring' } %>
<% end %>
<%= will_paginate(@public_bodies) %>
diff --git a/app/views/admin_public_body/show.rhtml b/app/views/admin_public_body/show.rhtml
index cf12026fd..91d527ab2 100644
--- a/app/views/admin_public_body/show.rhtml
+++ b/app/views/admin_public_body/show.rhtml
@@ -24,10 +24,7 @@
<% else %>
*unknown*
<% end %>
-<br/><b>Tags:</b> <%= @public_body.public_body_tags.map { |t|
- link_to(h(t.name), list_public_bodies_url(:tag => t.name)) +
- ' (<a href="' + admin_url('body/list') + "?query=" + h(t.name) + '">admin</a>)' }.join(' ') %>
-
+<br/><b>Tags:</b> <%= render :partial => 'tags', :locals => { :body => @public_body} %>
<br/>
</p>
diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css
index 114643fdb..e13f5ccf6 100644
--- a/public/stylesheets/admin.css
+++ b/public/stylesheets/admin.css
@@ -51,4 +51,7 @@ form {
margin-top: 0;
}
+.forms_on_one_line {
+ display: inline;
+}