Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Editing interface for featured reporting page
Browse files Browse the repository at this point in the history
Convert the Featured Reporting page to source it's content from the database in markdown format.

To support this:
  * A Backbone editing interface is implemented at /admin/featured
  * Basic CSS to style markdown is included in pages/body.css   This may need to be tweaked to ensure desired styling.  A good test is to paste all the Markdown examples into a report and see how it appears.
  * Since the content is now pulled from the database, I've also added an RSS feed at /featured.rss
  • Loading branch information
nathanstitt committed Nov 11, 2012
1 parent 6587914 commit 1870a54
Show file tree
Hide file tree
Showing 17 changed files with 531 additions and 352 deletions.
42 changes: 42 additions & 0 deletions app/controllers/featured_controller.rb
@@ -0,0 +1,42 @@
class FeaturedController < ApplicationController

before_filter :admin_required, :except => [:index]

def index
@reports = FeaturedReport.sorted
respond_to do |format|
format.any(:js, :json) do
json @reports
end
format.html { render :layout=>'home' }
format.rss { render :layout=>false }
end
end

def create
json FeaturedReport.create plucked_attributes
end

def update
report = FeaturedReport.find(params[:id])
report.update_attributes( plucked_attributes )
json report
end

def destroy
FeaturedReport.find(params[:id]).destroy
render :nothing=>true
end

def present_order
params[:order].each_with_index do | id, order |
FeaturedReport.update_all( {:present_order=>order}, {:id=>id} )
end
render :nothing=>true
end

private
def plucked_attributes
pick( params, :title, :url, :organization, :article_date, :writeup )
end
end
31 changes: 31 additions & 0 deletions app/models/featured_report.rb
@@ -0,0 +1,31 @@

class FeaturedReport < ActiveRecord::Base

validates_presence_of :url, :title, :organization, :writeup
validate do | rec |
rec.errors.add(:article_date, 'is invalid') if rec.article_date.blank?
end

named_scope :sorted, :order=>'present_order asc, created_at desc'

before_save :fixup_url

def fixup_url
self.url = "http://#{url}" unless url=~/^http\:\/\//
end

def writeup=(markdown)
super(markdown)
@writeup_html = nil
end

def writeup_html
@writeup_html ||= RDiscount.new( writeup ).to_html
end


def to_json(opts={})
super( opts.merge(:methods=>[ :writeup_html ] ) )
end

end
18 changes: 18 additions & 0 deletions app/views/admin/featured.html.erb
@@ -0,0 +1,18 @@
<%
@title = "Admin Dashboard :: Featured Reports"
@stylesheets = [:admin]
@javascripts = [:admin]
@bodyclass = 'featured_reports'
%>

<script type="text/javascript">

$(function(){

$('#content').append( (new dc.ui.FeaturedReporting( {
collection: new dc.model.FeaturedReports( <%= FeaturedReport.sorted.to_json %> )
} ) ).render().el);
});

</script>

8 changes: 8 additions & 0 deletions app/views/admin/featured_report_display.jst
@@ -0,0 +1,8 @@
<div class="controls">
<div class="icon edit_glyph">&#65279;</div>
</div>
<h6>
<a href="<%= url %>"><u><%= title %></u></a>
<small><i><%= organization %></i>, <%= article_date %></small>
</h6>
<%= writeup_html %>
61 changes: 61 additions & 0 deletions app/views/admin/featured_report_edit.jst
@@ -0,0 +1,61 @@
<form class="edit">
<div class="errors"></div>
<div class="row">
<div class="title">
<label for="title" title="What is the name of the Article?">
Title
</label>
<div class="text_input light small">
<input name="title" id="title" class="attribute" type="text" value="<%= title %>" />
</div>
</div>

<div class="url">
<label for="url" title="Link to the article">
URL
</label>
<div class="text_input light small">
<input name="url" id="url" class="attribute" type="text" value="<%= url %>" />
</div>
</div>
<br class="clear"/>
</div>


<div class="row">
<div class="organization">
<label for="organization" title="Organization that created Article">
Organization
</label>
<div class="text_input light small">
<input name="organization" id="organization" class="attribute" type="text" value="<%= organization %>" />
</div>
</div>

<div class="article_date">
<label for="article_date" title="Date Article was created/posted">
Article Date <i>(YYYY-MM-DD)</i>
</label>
<div class="text_input light small">
<input name="article_date" id="article_date" class="attribute" type="text" value="<%= article_date %>" />
</div>
</div>
<br class="clear"/>
</div>

<div class="row writeup">
<label for="writeup" title="Description of Article">
Writeup <i>(in <a href="http://daringfireball.net/projects/markdown/basics" target="_blank">Markdown format</a>)</i>
</label>
<textarea name="writeup" id="writeup" class="text_area" type="text"><%= writeup %></textarea>
</div>

<div class="minibutton warn delete" href="#">Delete</div>
<div class="controls">
<div class="minibutton cancel" href="#">Cancel</div>
<div class="minibutton ok" href="#">Save</div>
</div>

<br class="clear"/>

</form>
12 changes: 12 additions & 0 deletions app/views/admin/featured_reporting.jst
@@ -0,0 +1,12 @@

<div class="controls actions">
<div class="toAdmin minibutton" href="#">Admin Dashboard</div>
<div class="reload minibutton" href="#">Reload</div>
<div class="add minibutton" href="#">Add</div>
</div>

<br class="clear"/>

<div class="listing">

</div>
21 changes: 21 additions & 0 deletions app/views/featured/index.html.erb
@@ -0,0 +1,21 @@
<%
@title = 'Featured Reporting'
@header = 'What can I do with DocumentCloud?'
%>
<%= auto_discovery_link_tag(:rss, :format=>:rss ) %>

<div id="content" class="featured">

<p>
<i>This is a sampling of some of the thousands of documents that newsrooms have published with DocumentCloud. Find many more by searching our <a href="http://www.documentcloud.org/public">public catalog</a> for <a href="http://www.documentcloud.org/public/search/filter%3A%20published">published documents</a>.</i>
</p>

<% @reports.each do | report | %>
<h6>
<a href="<%= report.url %>"><u><%= report.title %></u></a>
<small><i><%= report.organization %></i>, <%= report.article_date.strftime('%B %e, %Y') %></small>
</h6>
<%= report.writeup_html %>
<% end %>

</div>
18 changes: 18 additions & 0 deletions app/views/featured/index.rss.builder
@@ -0,0 +1,18 @@
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title "DocumentCloud Featured Reporting"
xml.description "Featured reports that have utilized DocumentCloud to assist with the creation or presentation of the article or series"
xml.link featured_index_url

@reports.each do | report |
xml.item do
xml.title "#{report.title} by the #{report.organization} on #{report.article_date.strftime('%B %e, %Y')}"
xml.description report.writeup_html
xml.pubDate report.created_at.to_s(:rfc822)
xml.link "#{featured_index_url}#{report.id}"
xml.guid "#{featured_index_url}#{report.id}"
end
end
end
end

0 comments on commit 1870a54

Please sign in to comment.