Browse files

Add basic support for display static Guides or How-Tos

  • Loading branch information...
1 parent 44431b9 commit 092affed7a440811634403bb82ac498dd51d3df8 @mhl mhl committed Apr 17, 2012
View
15 app/controllers/static_controller.rb
@@ -34,5 +34,16 @@ def facebook
# NB max width for canvas should be 760px
# process incoming request_ids here (if any): test code for this has been deleted
end
-
-end
+
+ def guide_index
+ @guides = Guide.find(:all, :order => :title)
+ end
+
+ def show_guide
+ @guide = Guide.find(params[:guide])
+ @title = @guide.title
+ @all_guides = Guide.find(:all, :order => :title)
+ @example_issues = @guide.problems + @guide.campaigns
+ end
+
+end
View
9 app/models/campaign.rb
@@ -18,6 +18,7 @@ class Campaign < ActiveRecord::Base
has_many :subscriptions, :as => :target
has_many :subscribers, :through => :subscriptions, :source => :user, :conditions => ['subscriptions.confirmed_at is not null']
has_many :questionnaires, :as => :subject
+ has_and_belongs_to_many :guides
validates_length_of :title, :maximum => 80, :on => :update, :allow_nil => true
validates_presence_of :title, :description, :on => :update
validates_format_of :title, :with => /^.*(?=.*[a-zA-Z]).*$/,
@@ -61,6 +62,14 @@ def confirm
self.confirmed_at = Time.now
end
+ def fixed?
+ self.status == :fixed
+ end
+
+ def confirmed_and_visible?
@crowbot
mySociety member
crowbot added a note Apr 17, 2012

I wonder if calling this method confirmed? would be clearer? Although I suppose what we really want is "visible_but_not_fixed?" in order to insulate ourselves from having other visible but not fixed states in the future (at the moment, confirmed is the only one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ self.status == :confirmed
+ end
+
def visible?
[:confirmed, :fixed].include?(self.status)
end
View
6 app/models/guide.rb
@@ -0,0 +1,6 @@
+class Guide < ActiveRecord::Base
+ has_friendly_id :title, :use_slug => :true
+ validates_presence_of :title, :partial_name
+ has_and_belongs_to_many :problems
+ has_and_belongs_to_many :campaigns
+end
View
9 app/models/problem.rb
@@ -14,6 +14,7 @@ class Problem < ActiveRecord::Base
has_many :sent_emails
has_many :responsibilities
has_many :questionnaires, :as => :subject
+ has_and_belongs_to_many :guides
validates_presence_of :description, :subject, :category, :if => :location
validates_associated :reporter
@@ -243,6 +244,14 @@ def transport_mode_text
location.transport_modes.map{ |transport_mode| transport_mode.name }.join(", ")
end
+ def fixed?
+ self.status == :fixed
+ end
+
+ def confirmed_and_visible?
+ self.status == :confirmed
+ end
+
def visible?
[:confirmed, :fixed].include?(self.status)
end
View
48 app/views/shared/_guides_example_issues.erb
@@ -0,0 +1,48 @@
+<% if @example_issues.empty? %>
+
+ <!-- No example issues to disply -->
+
+<% else %>
+
+ <%- if solved_issues %>
+
+<section class="guide-solved_problems" id="solved">
+
+ <h2 id="solved">It worked for them&hellip;</h2>
+
+ <div class="guide-desc">
+ <p>FixMyTransport gets things changed - have a look at examples of <%= @description %> that we’ve already helped to solve.</p>
+ </div>
+
+ <ul class="issues-list">
+ <%= render :partial => "shared/issue",
+ :collection => @example_issues.select { |i| i.fixed? },
+ :as => :issue,
+ :locals => { :context => :browse_issues } %>
+ </ul>
+
+</section>
+
+ <% else %>
+
+ <section class="guide-solved_problems">
+
+ <h2 id="unsolved">Can you help with these?</h2>
+
+ <div class="guide-desc">
+ <p>The following <%= @description %> are still unsolved -
+ can you help with these?</p>
+ </div>
+
+ <ul class="issues-list">
+ <%= render :partial => "shared/issue",
+ :collection => @example_issues.select { |i| i.confirmed_and_visible? },
+ :as => :issue,
+ :locals => { :context => :browse_issues } %>
+ </ul>
+
+ </section>
+
+ <% end %>
+
+<% end %>
View
19 app/views/static/guide_index.erb
@@ -0,0 +1,19 @@
+<article class="guide">
+ <header>
+ <h1>Fixing Public Transport Problems</h1>
+ </header>
+
+ <section>
+ <p>These are a series of "how-to" style guides to help you
+ to get common public transport problems fixed.</p>
+ </section>
+
+ <section class="guide-index">
+ <ul class="guide-index-list">
+ <%- @guides.each do |g| -%>
+ <li class="deselected-guide"><%= link_to g.title, :controller => "static", :action => "show_guide", :guide => g.friendly_id %></li>
+ <%- end -%>
+ </ul>
+ </section>
+
+</article>
View
29 app/views/static/show_guide.erb
@@ -0,0 +1,29 @@
+<article id="guide-accessibility" class="guide">
+
+ <header>
+ <p>The FixMyTransport Guide to</p>
+ <h1><%= @guide.title %></h1>
+
+ <nav class="toc">
+
+ </nav>
+ </header>
+
+ <%= render "shared/guides/#{@guide.partial_name}" %>
+
+ <footer>
+ <div class="guide-other-guides">
+ <h2>Not quite what you were look for? Read one of our other guides:</h2>
+ <ul>
+ <% @all_guides.each do |g| %>
+ <% if g.id == @guide.id %>
+ <li class="selected-guide"><%= g.title %></li>
+ <% else %>
+ <li class="deselected-guide"><%= link_to g.title, :controller => "static", :action => "show_guide", :guide => g.friendly_id %></li>
+ <% end %>
+ <% end %>
+ </ul>
+ </div>
+ </footer>
+
+</article>
View
1 config/locales/views/problems/en.yml
@@ -140,6 +140,7 @@ en:
stop_or_station: "STOP or STATION"
journey_or_route: "JOURNEY or ROUTE"
journey_or_route_break: "JOURNEY or<br> ROUTE"
+ report_a_problem: "REPORT A PROBLEM"
stop_examples: "Examples: poor facilities or accessibility, missing timetables, dirt or litter."
route_examples: "Examples: overcrowding, late buses or trains, fare and ticket problems."
issues_near_you: "issues near you"
View
3 config/routes.rb
@@ -202,6 +202,9 @@
map.facebook '/facebook', :controller => 'static', :action => 'facebook'
map.howto '/howto', :controller => 'static', :action => 'howto'
+ map.guide_index '/guides', :controller => 'static', :action => 'guide_index'
+ map.guides '/guides/:guide', :controller => 'static', :action => 'show_guide'
+
# admin
map.namespace :admin do |admin|
admin.root :controller => 'home'
View
14 db/migrate/20120411131114_create_guides.rb
@@ -0,0 +1,14 @@
+class CreateGuides < ActiveRecord::Migration
+ def self.up
+ create_table :guides do |t|
+ t.string :title, :null => false
+ t.string :partial_name, :null => false
+ end
+ add_column :guides, :cached_slug, :string
+ add_index :guides, :cached_slug, :unique => true
+ end
+
+ def self.down
+ drop_table :guides
+ end
+end
View
19 db/migrate/20120413074449_create_guide_examples.rb
@@ -0,0 +1,19 @@
+class CreateGuideExamples < ActiveRecord::Migration
+
+ def self.up
+ create_table :campaigns_guides, :id => false do |t|
+ t.integer :campaign_id
+ t.integer :guide_id
+ end
+ create_table :guides_problems, :id => false do |t|
+ t.integer :problem_id
+ t.integer :guide_id
+ end
+ end
+
+ def self.down
+ drop_table :campaigns_guides
+ drop_table :guides_problems
+ end
+
+end
View
22 lib/tasks/guides.rake
@@ -0,0 +1,22 @@
+namespace :guides do
+
+ desc 'Add the static guides to common problems'
+ task :add_static_guides => :environment do
+ { "accessibility" => "Making your public transport accessible",
+ "bus_stop_fixed" => "Getting your bus stop fixed",
+ "rude_staff" => "Reporting rude transport staff",
+ "discontinued_bus" => "Getting bus routes reinstated",
+ "delayed_bus" => "Getting your bus to run on time",
+ "overcrowding" => "Overcrowded trains, and what to do about them"
+ }.each do |partial_name, title|
+ g = Guide.find_by_partial_name partial_name
+ if g
+ g.title = title
+ g.save!
+ else
+ Guide.create! :partial_name => partial_name, :title => title
+ end
+ end
+ end
+
+end

0 comments on commit 092affe

Please sign in to comment.