This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editing interface for featured reporting page
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
1 parent
6587914
commit 1870a54
Showing
17 changed files
with
531 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="controls"> | ||
<div class="icon edit_glyph"></div> | ||
</div> | ||
<h6> | ||
<a href="<%= url %>"><u><%= title %></u></a> | ||
<small><i><%= organization %></i>, <%= article_date %></small> | ||
</h6> | ||
<%= writeup_html %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.