Permalink
Browse files

Channels admin and on search page

  • Loading branch information...
1 parent 5965a72 commit ff69d4e47a9c0d9922f9e2d4f2b3252e36b355dd @spherop spherop committed Dec 24, 2009
View
47 app/controllers/admin/channels_controller.rb
@@ -0,0 +1,47 @@
+class Admin::ChannelsController < ApplicationController
+ resources_controller_for :channels
+ before_filter :admin_required
+ layout 'bare'
+
+ response_for :create do |format|
+ format.html do
+ if resource_saved?
+ flash[:success] = "Success!"
+ redirect_to admin_channels_path
+ else
+ render :action => 'new'
+ end
+ end
+ end
+
+ response_for :update do |format|
+ format.html do
+ if resource_saved?
+ flash[:success] = "Success!"
+ redirect_to admin_channels_path
+ else
+ render :action => 'edit'
+ end
+ end
+ end
+
+ def show
+ @channel = Channel.find(params[:id])
+ @selectable_pitches = Pitch.browsable - @channel.pitches
+ end
+
+ def add_pitch
+ @pitch = Pitch.find(params[:pitch_id])
+ @channel = Channel.find(params[:id])
+ @channel.pitches << @pitch
+ redirect_to admin_channel_path(@channel)
+ end
+
+ def remove_pitch
+ @pitch = Pitch.find(params[:pitch_id])
+ @channel = Channel.find(params[:id])
+ @channel.pitches.delete(@pitch)
+ redirect_to admin_channel_path(@channel)
+ end
+
+end
View
28 app/controllers/channels_controller.rb
@@ -0,0 +1,28 @@
+class ChannelsController < ApplicationController
+ before_filter :select_tab
+ before_filter :load_networks, :only => [:show]
+
+ def show
+ @channel = Channel.find(params[:id])
+ @news_items = @channel.pitches.approved.paginate(:page => params[:page])
+ @channels = Channel.by_network(current_network)
+ respond_to do |format|
+ format.rss do
+ render :template => "/news_items/index.rss", :layout => false
+ end
+ format.html do
+ render :template => "/news_items/index"
+ end
+ end
+ end
+
+ protected
+
+ def load_networks
+ @networks = Network.all
+ end
+
+ def select_tab
+ @selected_tab = "pitches"
+ end
+end
View
2 app/controllers/news_items_controller.rb
@@ -5,7 +5,7 @@ class NewsItemsController < ApplicationController
before_filter :select_tab, :only => [:index, :search]
def index
-
+ @channels = Channel.by_network(current_network)
respond_to do |format|
format.rss do
@news_items = NewsItem.newest.first(10)
View
36 app/models/channel.rb
@@ -0,0 +1,36 @@
+class Channel < ActiveRecord::Base
+ validates_presence_of :title, :channel_image_file_name, :description
+ validates_uniqueness_of :title
+ has_attached_file :channel_image,
+ :styles => { :thumb => '50x50#', :medium => "200x150#" },
+ :storage => :s3,
+ :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
+ :bucket => S3_BUCKET,
+ :default_url => "/images/default_avatar.png",
+ :path => "channels/:attachment/:id_partition/:basename_:style.:extension",
+ :url => "channels/:attachment/:id_partition/:basename_:style.:extension"
+
+ named_scope :hilited, :conditions => "channels.status = 'hilited'"
+ named_scope :by_network, lambda {|network|
+ return {:conditions => "channels.status = 'hilited'"} unless network
+ { :conditions =>
+ ["id in (select channel_id from channel_pitches where pitch_id in (select id from news_items where network_id = ? ))",
+ network.id] }
+ }
+
+ has_many :pitches, :through => :channel_pitches, :order => "created_at desc"
+ has_many :channel_pitches
+
+ def hilite_channel
+ self.status = "hilited"
+ end
+
+ def to_s
+ title
+ end
+
+ def to_param
+ "#{id}-#{to_s.parameterize}"
+ end
+
+end
View
7 app/models/channel_pitch.rb
@@ -0,0 +1,7 @@
+class ChannelPitch < ActiveRecord::Base
+ belongs_to :channel
+ belongs_to :pitch
+
+ validates_presence_of :channel, :pitch
+ validates_uniqueness_of :pitch_id, :scope => :channel_id
+end
View
2 app/models/pitch.rb
@@ -138,7 +138,7 @@ def unapproved
named_scope :sorted, lambda {|direction| { :order => "news_items.created_at #{direction}" } }
named_scope :without_a_story, :conditions => 'news_items.id NOT IN (SELECT news_item_id FROM news_items WHERE news_items.type = "Story" AND news_items.status = "published")'
named_scope :browsable, :include => :user, :conditions => "news_items.status != 'unapproved'"
-
+
MAX_PER_USER_DONATION_PERCENTAGE = 0.20
def self.featured_by_network(network=nil)
View
1 app/views/admin/_admin_header.html.haml
@@ -1,6 +1,7 @@
#admin_header
= link_to "city suggestions", admin_city_suggestions_path, :id => "city_suggestions_tab", :class => "tab"
= link_to "comments", admin_comments_path, :id => "comments_tab", :class => "tab"
+ = link_to "channels", admin_channels_path, :id => "channels_tab", :class => "tab"
= link_to "credits", admin_credits_path, :id => "credits_tab", :class => "tab"
= link_to "groups", admin_groups_path, :id => "groups_tab", :class => "tab"
= link_to "networks", admin_networks_path, :id => "networks_tab", :class => "tab"
View
21 app/views/admin/channels/_form.html.haml
@@ -0,0 +1,21 @@
+.field
+ = f.label :title
+.field
+ = f.text_field :title
+.field
+ = f.label :Hilited?
+.field
+ = check_box("channel", "status", {}, "hilited", "")
+
+%br/
+.field
+ = f.label :description
+.field
+ = f.text_field :description
+.field
+ = f.label :channel_image
+.field
+ = image_tag @channel.channel_image.url(:thumb) if params[:action] = "edit"
+ = f.file_field :channel_image
+%br/
+= f.submit
View
14 app/views/admin/channels/edit.html.haml
@@ -0,0 +1,14 @@
+= content_for :head do
+ :javascript
+ $(function(){
+ $(".tab").removeClass("hilited");
+ $("#channels_tab").addClass("hilited");
+ });
+
+= render :partial => "/admin/admin_header"
+
+%h1 Edit Channel
+.flash.error
+ = error_messages_for :channel
+- form_for [:admin, @channel], :html => { :multipart => true } do |f|
+ = render :partial => 'form', :locals => {:f => f}
View
33 app/views/admin/channels/index.html.haml
@@ -0,0 +1,33 @@
+= content_for :head do
+ :javascript
+ $(function(){
+ $(".tab").removeClass("hilited");
+ $("#channels_tab").addClass("hilited");
+ });
+
+= render :partial => "/admin/admin_header"
+
+%h1 channels
+
+.box
+ %table
+ %tr
+ %th Icon
+ %th Title
+ %th Description
+ %th Status
+ %th Pitches
+ %th Action
+ - @channels.each do |channel|
+ %tr
+ %td=image_tag channel.channel_image.url(:thumb)
+ %td=h channel.title
+ %td=truncate_words(channel.description, 30)
+ %td=channel.status
+ %td=link_to "Manage Pitches", admin_channel_path(channel)
+ %td
+ =link_to 'Edit', edit_admin_channel_path(channel)
+ |
+ =link_to 'Destroy', admin_channel_path(channel), :confirm => 'Are you sure?', :method => :delete
+
+= link_to "New", new_admin_channel_path
View
14 app/views/admin/channels/new.html.haml
@@ -0,0 +1,14 @@
+= content_for :head do
+ :javascript
+ $(function(){
+ $(".tab").removeClass("hilited");
+ $("#channels_tab").addClass("hilited");
+ });
+
+= render :partial => "/admin/admin_header"
+
+%h1 New Channel
+.flash.error
+ = error_messages_for :channel
+- form_for [:admin, @channel], :html => { :multipart => true } do |f|
+ = render :partial => 'form', :locals => {:f => f}
View
35 app/views/admin/channels/show.html.haml
@@ -0,0 +1,35 @@
+= content_for :head do
+ :javascript
+ $(function(){
+ $(".tab").removeClass("hilited");
+ $("#channels_tab").addClass("hilited");
+ });
+
+= render :partial => "/admin/admin_header"
+
+%h1.inline
+ %em= @channel.title
+= image_tag(@channel.channel_image(:thumb))
+
+%hr
+%h3 Channel Pitches
+%hr
+- if !@channel.pitches.any?
+ there are no pitches in this channel yet
+%table{:style=>"width:500px"}
+ - @channel.pitches.each do |pitch|
+ %tr
+ %td= pitch.headline
+ %td= pitch.network.name
+ %td{:style=>"text-align:right"}= link_to "Remove", "/admin/channels/" + @channel.id.to_s + "/remove_pitch/" + pitch.id.to_s
+%br
+%hr
+%h3 Add Pitch To Channel
+%hr
+%table{:style=>"width:500px"}
+ - @selectable_pitches.each do |pitch|
+ %tr
+ %td= pitch.headline
+ %td= pitch.network.name
+ %td{:style=>"text-align:right"}= link_to "Add", "/admin/channels/" + @channel.id.to_s + "/add_pitch/" + pitch.id.to_s
+
View
1 app/views/admin/groups/edit.html.haml
@@ -12,3 +12,4 @@
= error_messages_for :group
- form_for [:admin, @group], :html => { :multipart => true } do |f|
= render :partial => 'form', :locals => {:f => f}
+
View
10 app/views/admin/groups/new.html.haml
@@ -1,3 +1,13 @@
+= content_for :head do
+ :javascript
+ $(function(){
+ $(".tab").removeClass("hilited");
+ $("#groups_tab").addClass("hilited");
+ });
+
+= render :partial => "/admin/admin_header"
+
+ %h1 New Group
.flash.error
= error_messages_for :group
- form_for [:admin, @group], :html => { :multipart => true } do |f|
View
12 app/views/news_items/index.html.haml
@@ -29,7 +29,17 @@
= image_submit_tag image_path('search_button.png')
%hr.space
.double_content_border.clear
-
+ - if @channels.any?
+ #channels.clearfix
+ - @channels.each do |channel|
+ - if channel == @channel
+ .channel.selected
+ =link_to image_tag(channel.channel_image(:thumb)), channel_path(channel)
+ =channel.description
+ - else
+ .channel
+ =link_to image_tag(channel.channel_image(:thumb)), channel_path(channel)
+ =channel.description
- if @news_items.blank?
.box_white
%p
View
4 config/routes.rb
@@ -8,6 +8,7 @@
map.resources :stories, :member => {:accept => :put, :reject => :put, :fact_check => :put, :publish => :put}, :has_many => :comments
map.resources :tips, :has_many => [:affiliations, :comments]
map.resources :subscribers
+ map.resources :channels
map.resources :city_suggestions
map.resources :pitches, :member => {:feature => :put, :unfeature => :put, :half_fund => :put, :fully_fund => :put, :show_support => :put, :apply_to_contribute => :get, :assign_fact_checker => :put, :blog_posts => :get}, :has_many => :comments do |pitch|
@@ -23,6 +24,8 @@
map.connect "subscription/cancel/:id", :controller => "subscribers", :action => "cancel"
map.connect "/assignment/:assignment_id/application/accept/:id", :controller => "assignments", :action => "accept_application"
map.connect "/assignment/:assignment_id/application/reject/:id", :controller => "assignments", :action => "reject_application"
+ map.connect "/admin/channels/:id/add_pitch/:pitch_id", :controller => "admin/channels", :action => "add_pitch"
+ map.connect "/admin/channels/:id/remove_pitch/:pitch_id", :controller => "admin/channels", :action => "remove_pitch"
# TODO: remove when done
map.resources :ui
@@ -53,6 +56,7 @@
admin.resources :site_options
admin.resources :networks
admin.resources :groups
+ admin.resources :channels
end
map.namespace :myspot do |myspot|
View
16 db/migrate/20091223183147_create_channels.rb
@@ -0,0 +1,16 @@
+class CreateChannels < ActiveRecord::Migration
+ def self.up
+ create_table :channels do |t|
+ t.string :title
+ t.string :channel_image_file_name
+ t.string :status
+ t.string :description
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :channels
+ end
+end
+
View
13 db/migrate/20091223183643_create_channel_pitches.rb
@@ -0,0 +1,13 @@
+class CreateChannelPitches < ActiveRecord::Migration
+ def self.up
+ create_table :channel_pitches do |t|
+ t.integer :channel_id
+ t.integer :pitch_id
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :channel_pitches
+ end
+end
View
1 public/stylesheets/admin.css
@@ -46,5 +46,6 @@ table.admin_pitches tr td form input.delete_button {
.tab{padding:4px 8px 2px;background:#f3f3f3;}
a.tab{text-decoration:none;color:darkred;}
.hilited{background:#ddd;}
+.inline{display:inline;}
label{display:block;margin-bottom:20px;}
input[type="text"]{margin:3px 0 15px;}
View
5 public/stylesheets/screen_spotus.css
@@ -1219,6 +1219,11 @@ a.prev{
color:#990000;
font-weight: bold;
}
+#channels .channel{width:100px;height:80px;float:left;font-size:10px;padding:5px;border:solid 1px #999;-moz-border-radius:5px;-webkit-border-radius:5px;
+ text-align:center;margin-right:10px;}
+#channels .channel img{display:block;margin: 0 auto;}
+#channels .channel.selected{background:#eee;}
+
.progress_bar_container{width:120px;margin-right:10px;float:left}
#action_buttons_container{
padding:5px;
View
4 server
@@ -0,0 +1,4 @@
+Script started on Wed Dec 23 10:25:01 2009
+script: --debugger: No such file or directory
+
+Script done on Wed Dec 23 10:25:01 2009

0 comments on commit ff69d4e

Please sign in to comment.