Skip to content

Commit

Permalink
Adding really simple feed selection tool for upload. Additonal named …
Browse files Browse the repository at this point in the history
…scopes for content -> feeds and the displays to go along with it.
  • Loading branch information
bamnet committed Feb 21, 2010
1 parent ab7a1c1 commit a1a5638
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/contents_controller.rb
Expand Up @@ -25,6 +25,8 @@ def show
# GET /contents/new.xml
def new
@content = Content.new
@feeds = Feed.all
@content.submissions.build

respond_to do |format|
format.html # new.html.erb
Expand All @@ -41,6 +43,13 @@ def edit
# POST /contents.xml
def create
@content = Content.new(params[:content])

# Copy over the duration to each submission instance
# This would be a good place to add code to auto-moderate content
# for feed owners or something like that
@content.submissions.each do |submission|
submission.duration = @content.duration
end

respond_to do |format|
if @content.save
Expand Down
9 changes: 8 additions & 1 deletion app/models/content.rb
@@ -1,8 +1,10 @@
class Content < ActiveRecord::Base
belongs_to :user
belongs_to :type
has_many :submissions
has_many :submissions, :dependent => :destroy
has_many :feeds, :through => :submissions

accepts_nested_attributes_for :submissions

#Validations
validates :name, :presence => true
Expand All @@ -16,6 +18,11 @@ class Content < ActiveRecord::Base
scope :expired, where("end_time < :now", {:now => Time.now})
scope :future, where("start_time > :now", {:now => Time.now})
scope :active, where("(start_time IS NULL OR start_time < :now) AND (end_time IS NULL OR end_time > :now)", {:now => Time.now})

#Scoped relations for feed approval states
has_many :approved_feeds, :through => :submissions, :source => :feed, :conditions => {"submissions.moderation_flag" => true}
has_many :pending_feeds, :through => :submissions, :source => :feed, :conditions => "submissions.moderation_flag IS NULL"
has_many :denied_feeds, :through => :submissions, :source => :feed, :conditions => {"submissions.moderation_flag" => false}

#Determine if content is active based on its start and end times.
def is_active?
Expand Down
3 changes: 3 additions & 0 deletions app/models/submission.rb
Expand Up @@ -2,4 +2,7 @@ class Submission < ActiveRecord::Base
belongs_to :content
belongs_to :feed
belongs_to :user

#Validations
validates_associated :feed, :content
end
10 changes: 10 additions & 0 deletions app/views/contents/_form.html.erb
Expand Up @@ -33,6 +33,16 @@
<%= f.label :type %><br />
<%#= f.text_field :type %>
</div>
<% if @content.new_record? %>
<div class="field">
<% @feeds.each do |feed| %>
<% f.fields_for :submissions do |submissions| %>
<%= submissions.check_box :feed_id, {}, feed.id %>
<%= feed.name %><br />
<% end %>
<% end %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
Expand Down
27 changes: 27 additions & 0 deletions app/views/contents/show.html.erb
Expand Up @@ -38,6 +38,33 @@
<%= @content.type unless @content.user.nil? %>
</p>

<p>
<b>Approved Feeds:</b>
<ul>
<% @content.approved_feeds.each do |feed| %>
<li><%= link_to feed.name, feed %></li>
<% end %>
</ul>
</p>

<p>
<b>Pending Feeds:</b>
<ul>
<% @content.pending_feeds.each do |feed| %>
<li><%= link_to feed.name, feed %></li>
<% end %>
</ul>
</p>

<p>
<b>Denied Feeds:</b>
<ul>
<% @content.denied_feeds.each do |feed| %>
<li><%= link_to feed.name, feed %></li>
<% end %>
</ul>
</p>


<%= link_to 'Edit', edit_content_path(@content) %> |
<%= link_to 'Back', contents_path %>
24 changes: 24 additions & 0 deletions app/views/feeds/show.html.erb
Expand Up @@ -18,6 +18,30 @@
<%= @feed.group %>
</p>

<p>
<b>Approved Content:</b>
<ul>
<% @feed.approved_contents.each do |content| %>
<li><%= link_to content.name, content %>
<% end %>
</ul>
</p>
<p>
<b>Denied Content:</b>
<ul>
<% @feed.denied_contents.each do |content| %>
<li><%= link_to content.name, content %>
<% end %>
</ul>
</p>
<p>
<b>Pending Content:</b>
<ul>
<% @feed.pending_contents.each do |content| %>
<li><%= link_to content.name, content %>
<% end %>
</ul>
</p>

<%= link_to 'Edit', edit_feed_path(@feed) %> |
<%= link_to 'Back', feeds_path %>

0 comments on commit a1a5638

Please sign in to comment.