diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin_request_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/public_body_controller.rb | 18 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 2 | ||||
-rw-r--r-- | app/models/info_request.rb | 2 | ||||
-rw-r--r-- | app/models/public_body.rb | 64 | ||||
-rw-r--r-- | app/models/public_body_tag.rb | 48 | ||||
-rw-r--r-- | app/views/admin_public_body/_tags.rhtml | 2 | ||||
-rw-r--r-- | app/views/admin_request/_tags.rhtml | 8 | ||||
-rw-r--r-- | app/views/admin_request/edit.rhtml | 3 | ||||
-rw-r--r-- | app/views/admin_request/show.rhtml | 1 | ||||
-rw-r--r-- | app/views/request/_sidebar.rhtml | 13 | ||||
-rw-r--r-- | app/views/request/new.rhtml | 17 | ||||
-rw-r--r-- | app/views/request/preview.rhtml | 5 |
13 files changed, 62 insertions, 126 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 7e6c365c1..d5bd4c4d6 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -46,6 +46,7 @@ class AdminRequestController < AdminController old_awaiting_description = @info_request.awaiting_description old_allow_new_responses_from = @info_request.allow_new_responses_from old_handle_rejected_responses = @info_request.handle_rejected_responses + old_tag_string = @info_request.tag_string @info_request.title = params[:info_request][:title] @info_request.prominence = params[:info_request][:prominence] @@ -55,6 +56,7 @@ class AdminRequestController < AdminController @info_request.awaiting_description = params[:info_request][:awaiting_description] == "true" ? true : false @info_request.allow_new_responses_from = params[:info_request][:allow_new_responses_from] @info_request.handle_rejected_responses = params[:info_request][:handle_rejected_responses] + @info_request.tag_string = params[:info_request][:tag_string] if @info_request.valid? @info_request.save! @@ -65,7 +67,8 @@ class AdminRequestController < AdminController :old_described_state => old_described_state, :described_state => @info_request.described_state, :old_awaiting_description => old_awaiting_description, :awaiting_description => @info_request.awaiting_description, :old_allow_new_responses_from => old_allow_new_responses_from, :allow_new_responses_from => @info_request.allow_new_responses_from, - :old_handle_rejected_responses => old_handle_rejected_responses, :handle_rejected_responses => @info_request.handle_rejected_responses + :old_handle_rejected_responses => old_handle_rejected_responses, :handle_rejected_responses => @info_request.handle_rejected_responses, + :old_tag_string => old_tag_string, :tag_string => @info_request.tag_string }) flash[:notice] = 'Request successfully updated.' redirect_to request_admin_url(@info_request) diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 5f51948ee..560206900 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -65,24 +65,28 @@ class PublicBodyController < ApplicationController end def list + # XXX move some of these tag SQL queries into has_tag_string.rb @tag = params[:tag] if @tag.nil? @tag = "all" conditions = [] elsif @tag == 'other' category_list = PublicBodyCategories::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'] + conditions = ['(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'] elsif @tag.size == 1 @tag.upcase! conditions = ['first_letter = ?', @tag] elsif @tag.include?(":") - name, value = PublicBodyTag.split_tag_into_name_value(@tag) - conditions = ['(select count(*) from public_body_tags where public_body_tags.public_body_id = public_bodies.id - and public_body_tags.name = ? and public_body_tags.value = ?) > 0', name, value] + name, value = HasTagString::HasTagStringTag.split_tag_into_name_value(@tag) + conditions = ['(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', name, value] 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] + conditions = ['(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', @tag] end @public_bodies = PublicBody.paginate( :order => "public_bodies.name", :page => params[:page], :per_page => 1000, # fit all councils on one page diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index e9475e1b2..734c649dd 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -180,7 +180,7 @@ class RequestController < ApplicationController # First time we get to the page, just display it if params[:submitted_new_request].nil? || params[:reedit] # Read parameters in - public body must be passed in - params[:info_request] = { :public_body_id => params[:public_body_id] } if !params[:info_request] + params[:info_request] = { :public_body_id => params[:public_body_id], :tag_string => params[:tags] } if !params[:info_request] if !params[:info_request][:public_body_id] redirect_to frontpage_url return diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 4f997baa6..3f5224907 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -50,6 +50,8 @@ class InfoRequest < ActiveRecord::Base has_many :censor_rules, :order => 'created_at desc' has_many :exim_logs, :order => 'exim_log_done_id' + has_tag_string + # user described state (also update in info_request_event, admin_request/edit.rhtml) validates_inclusion_of :described_state, :in => [ 'waiting_response', diff --git a/app/models/public_body.rb b/app/models/public_body.rb index d54c761e6..1bd9dcc94 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -40,9 +40,10 @@ class PublicBody < ActiveRecord::Base validates_uniqueness_of :name has_many :info_requests, :order => 'created_at desc' - has_many :public_body_tags has_many :track_things, :order => 'created_at desc' + has_tag_string + # like find_by_url_name but also search historic url_name if none found def self.find_by_url_name_with_historic(name) found = PublicBody.find_all_by_url_name(name) @@ -183,71 +184,12 @@ class PublicBody < ActiveRecord::Base end end - # Given an input string of tags, sets all tags to that string. - # XXX This immediately saves the new tags. - def tag_string=(tag_string) - tag_string = tag_string.strip - # split tags apart - tags = tag_string.split(/\s+/).uniq - - ActiveRecord::Base.transaction do - for public_body_tag in self.public_body_tags - public_body_tag.destroy - end - self.public_body_tags = [] - for tag in tags - # see if is a machine tags (i.e. a tag which has a value) - name, value = PublicBodyTag.split_tag_into_name_value(tag) - - public_body_tag = PublicBodyTag.new(:name => name, :value => value) - self.public_body_tags << public_body_tag - public_body_tag.public_body = self - end - end - end - def tag_string - return self.public_body_tags.map { |t| t.name_and_value }.join(' ') - end - def has_tag?(tag) - for public_body_tag in self.public_body_tags - if public_body_tag.name == tag - return true - end - end - return false - end - class TagNotFound < StandardError - end - def get_tag_values(tag) - found = false - results = [] - for public_body_tag in self.public_body_tags - if public_body_tag.name == tag - found = true - if !public_body_tag.value.nil? - results << public_body_tag.value - end - end - end - if !found - raise TagNotFound - end - return results - 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) - return PublicBodyTag.find(:all, :conditions => ['name = ?', tag] ).map { |t| t.public_body }.sort { |a,b| a.name <=> b.name } - end # Use tags to describe what type of thing this is def type_of_authority(html = false) types = [] first = true - for tag in self.public_body_tags + for tag in self.tags if PublicBodyCategories::CATEGORIES_BY_TAG.include?(tag.name) desc = PublicBodyCategories::CATEGORY_SINGULAR_BY_TAG[tag.name] if first diff --git a/app/models/public_body_tag.rb b/app/models/public_body_tag.rb deleted file mode 100644 index e24ace7d7..000000000 --- a/app/models/public_body_tag.rb +++ /dev/null @@ -1,48 +0,0 @@ -# == Schema Information -# Schema version: 92 -# -# Table name: public_body_tags -# -# id :integer not null, primary key -# public_body_id :integer not null -# name :text not null -# created_at :datetime not null -# value :text -# - -# models/public_body_tag.rb: -# Categories for public bodies. -# -# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: public_body_tag.rb,v 1.29 2009-09-17 21:10:05 francis Exp $ - -class PublicBodyTag < ActiveRecord::Base - strip_attributes! - - validates_presence_of :public_body - validates_presence_of :name - - belongs_to :public_body - - def name_and_value - ret = self.name - if !self.value.nil? - ret += ":" + self.value - end - return ret - end - - def PublicBodyTag.split_tag_into_name_value(tag) - sections = tag.split(/:/) - name = sections[0] - if sections[1] - value = sections[1,sections.size].join(":") - else - value = nil - end - return name, value - end -end - diff --git a/app/views/admin_public_body/_tags.rhtml b/app/views/admin_public_body/_tags.rhtml index 362424013..85dc942fd 100644 --- a/app/views/admin_public_body/_tags.rhtml +++ b/app/views/admin_public_body/_tags.rhtml @@ -1,4 +1,4 @@ -<% for t in body.public_body_tags %> +<% for t in body.tags %> <% if t.value %> <%= link_to(h(t.name), main_url(list_public_bodies_url(:tag => t.name, :only_path => true))) %>:<%= link_to(h(t.value), main_url(list_public_bodies_url(:tag => t.name_and_value, :only_path => true))) %> <% else %> diff --git a/app/views/admin_request/_tags.rhtml b/app/views/admin_request/_tags.rhtml new file mode 100644 index 000000000..22fbf13c8 --- /dev/null +++ b/app/views/admin_request/_tags.rhtml @@ -0,0 +1,8 @@ +<% for t in info_request.tags %> + <% if t.value %> + <%=h t.name %>:<%=h t.value %> + <% else %> + <%=h t.name %> + <% end %> +<% end %> + diff --git a/app/views/admin_request/edit.rhtml b/app/views/admin_request/edit.rhtml index 1bfe4cb90..b659c676d 100644 --- a/app/views/admin_request/edit.rhtml +++ b/app/views/admin_request/edit.rhtml @@ -41,6 +41,9 @@ <br/>(don't forget to change 'awaiting description' when you set described state)<br/> </p> + <p><label for="info_request_tag_string"><strong>Tags</strong> <small>(space separated, can use key:value)</small></label><br/> + <%= text_field 'info_request', 'tag_string', :size => 60 %></p> + <p><%= submit_tag 'Save changes', :accesskey => 's' %> </p> diff --git a/app/views/admin_request/show.rhtml b/app/views/admin_request/show.rhtml index 279d09295..aac68ad2e 100644 --- a/app/views/admin_request/show.rhtml +++ b/app/views/admin_request/show.rhtml @@ -43,6 +43,7 @@ </span> <br> <strong>Incoming email address:</strong> <%= link_to h(@info_request.incoming_email), "mailto:" + @info_request.incoming_email %> <br> +<b>Tags:</b> <%= render :partial => 'tags', :locals => { :info_request => @info_request} %> <br> </p> <% end %> diff --git a/app/views/request/_sidebar.rhtml b/app/views/request/_sidebar.rhtml index 4a503d574..5557f0a6b 100644 --- a/app/views/request/_sidebar.rhtml +++ b/app/views/request/_sidebar.rhtml @@ -4,6 +4,10 @@ <h2>Act on what you've learnt</h2> <div class="act_link"> + <%= link_to '<img src="/images/helpmeinvestigate.png" alt="" class="rss">', "http://helpmeinvestigate.com/"%> + <%= link_to 'Get help investigating', "http://helpmeinvestigate.com/"%> + </div> + <div class="act_link"> <%= link_to '<img src="/images/writetothem.png" alt="" class="rss">', "http://www.writetothem.com"%> <%= link_to 'Write to your politician', "http://www.writetothem.com"%> </div> @@ -11,15 +15,16 @@ <%= link_to '<img src="/images/pledgebank.png" alt="" class="rss">', "http://www.pledgebank.com"%> <%= link_to 'Pledge with others', "http://www.pledgebank.com"%> </div> - <div class="act_link"> + <!-- <div class="act_link"> <%= link_to '<img src="/images/petitions.png" alt="" class="rss">', "http://petitions.number10.gov.uk"%> <%= link_to 'Petition the PM', "http://petitions.number10.gov.uk"%> - </div> + </div> --> <div class="act_link"> <%= link_to '<img src="/images/wordpress.png" alt="" class="rss">', "http://wordpress.com/"%> <%= link_to 'Start your own blog', "http://wordpress.com/"%> </div> + <% view_cache :ttl => 1.day, :tag => ['similar', @info_request.id] do %> <% if !@xapian_similar.nil? && @xapian_similar.results.size > 0 %> <h2>Similar requests</h2> @@ -34,6 +39,6 @@ <% end %> <p><%= link_to "Event history details", request_details_url(@info_request) %></p> - <p><a href="/help/about#commercial">Are you the owner of - any commercial copyright on this page?</a></p> + <p><small><a href="/help/about#commercial">Are you the owner of + any commercial copyright on this page?</a></small></p> </div> diff --git a/app/views/request/new.rhtml b/app/views/request/new.rhtml index b48966e2f..1b061fd46 100644 --- a/app/views/request/new.rhtml +++ b/app/views/request/new.rhtml @@ -115,8 +115,8 @@ <%= o.text_area :body, :rows => 20, :cols => 60 %> </p> <% end %> - - <div class="form_button"> + + <div class="form_button"> <script type="text/javascript">document.write('<input name="doSpell" type="button" value="Check spelling" onClick="openSpellChecker(document.getElementById(\'write_form\').body);"/> (optional)')</script> </div> @@ -147,7 +147,18 @@ <%= hidden_field_tag(:preview, 1 ) %> <%= submit_tag "Preview your public request" %> </div> - </div> + + <% if !@info_request.tag_string.empty? %> + <p class="form_note"> + <!-- <label class="form_label" for="info_request_tag_string">Tags:</label> + <%= f.text_field :tag_string, :size => 50 %> --> + + <%= f.hidden_field(:tag_string) %> + <strong>Tags:</strong> <%=h @info_request.tag_string %> + </p> + <% end %> + + </div> <% end %> diff --git a/app/views/request/preview.rhtml b/app/views/request/preview.rhtml index 427d036d9..97b92ffae 100644 --- a/app/views/request/preview.rhtml +++ b/app/views/request/preview.rhtml @@ -34,12 +34,17 @@ <p> <%= f.hidden_field(:title) %> <%= f.hidden_field(:public_body_id, { :value => @info_request.public_body_id } ) %> + <%= f.hidden_field(:tag_string) %> <%= hidden_field_tag(:submitted_new_request, 1) %> <%= hidden_field_tag(:preview, 0 ) %> <%= submit_tag "Re-edit this request", :name => 'reedit' %> <%= submit_tag "Send public " + h(@info_request.law_used_full) + " request", :name => 'submit' %> </p> + <% if !@info_request.tag_string.empty? %> + <p><strong>Tags:</strong> <%=h @info_request.tag_string %></p> + <% end %> + <% end %> |