Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 1 commit
  • 29 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 23, 2010
Jeff Reifman gallery checkins for jeffdev d3483a2
View
84 app/controllers/admin/galleries_controller.rb
@@ -0,0 +1,84 @@
+class Admin::GalleriesController < AdminController
+
+ def index
+ render :partial => 'shared/admin/index_page', :layout => 'new_admin', :locals => {
+ :items => Gallery.paginate(:page => params[:page], :per_page => 20, :order => "created_at desc"),
+ :model => Gallery,
+ :fields => [:name, :section, :created_at],
+ :paginate => true
+ }
+ end
+
+ def new
+ render_new
+ end
+
+ def edit
+ @gallery = Gallery.find(params[:id])
+
+ render_edit @gallery
+ end
+
+ def update
+ @gallery = Gallery.find(params[:id])
+ if @gallery.update_attributes(params[:gallery])
+ flash[:success] = "Successfully updated your Gallery."
+ redirect_to [:admin, @gallery]
+ else
+ flash[:error] = "Could not update your Gallery as requested. Please try again."
+ render_edit @gallery
+ end
+ end
+
+ def show
+ render :partial => 'shared/admin/show_page', :layout => 'new_admin', :locals => {
+ :item => Gallery.find(params[:id]),
+ :model => Gallery,
+ :fields => [:name, :url, :all_subdomains_valid, :created_at],
+ }
+ end
+
+ def create
+ @gallery = Gallery.new(params[:gallery])
+ @gallery.url = params[:gallery][:url].sub(/^\/+/,'').sub(/^http:\/\/(www.)*/,'').strip.sub(/\/+$/,'')
+ if @gallery.save
+ flash[:success] = "Successfully created your new Gallery!"
+ redirect_to [:admin, @gallery]
+ else
+ flash[:error] = "Could not create your Gallery, please try again"
+ render_new @gallery
+ end
+ end
+
+ def destroy
+ @gallery = Gallery.find(params[:id])
+ @gallery.destroy
+
+ redirect_to admin_galleries_path
+ end
+
+ private
+
+ def render_new gallery = nil
+ gallery ||= Gallery.new
+
+ render :partial => 'shared/admin/new_page', :layout => 'new_admin', :locals => {
+ :item => @gallery,
+ :model => Gallery,
+ :fields => [:name, :section, :created_at],
+ }
+ end
+
+ def render_edit gallery
+ render :partial => 'shared/admin/edit_page', :layout => 'new_admin', :locals => {
+ :item => gallery,
+ :model => Gallery,
+ :fields => [:name, :section, :created_at],
+ }
+ end
+
+ def set_current_tab
+ @current_tab = 'galleries';
+ end
+
+end
View
85 app/controllers/admin/gallery_items_controller.rb
@@ -0,0 +1,85 @@
+class Admin::GalleryItemsController < AdminController
+
+ def index
+ render :partial => 'shared/admin/index_page', :layout => 'new_admin', :locals => {
+ :items => GalleryItem.paginate(:page => params[:page], :per_page => 20, :order => "created_at desc"),
+ :model => GalleryItem,
+ :fields => [:title, :comments_count, :created_at],
+ :paginate => true
+ }
+ end
+
+ def new
+ render_new
+ end
+
+ def edit
+ @gallery_item = GalleryItem.find(params[:id])
+
+ render_edit @gallery_item
+ end
+
+ def update
+ @gallery_item = GalleryItem.find(params[:id])
+ if @gallery_item.update_attributes(params[:gallery_item])
+ flash[:success] = "Successfully updated your Gallery Item."
+ redirect_to [:admin, @gallery_item]
+ else
+ flash[:error] = "Could not update your GalleryItem as requested. Please try again."
+ render_edit @gallery_item
+ end
+ end
+
+ def show
+ render :partial => 'shared/admin/show_page', :layout => 'new_admin', :locals => {
+ :item => GalleryItem.find(params[:id]),
+ :model => GalleryItem,
+ :fields => [:title, :comments_count, :created_at],
+ }
+ end
+
+ def create
+ @gallery_item = GalleryItem.new(params[:gallery_item])
+ if @gallery_item.save
+ flash[:success] = "Successfully created your new GalleryItem!"
+ redirect_to [:admin, @gallery_item]
+ else
+ flash[:error] = "Could not create your GalleryItem, please try again"
+ render_new @gallery_item
+ end
+ end
+
+ def destroy
+ @gallery_item = GalleryItem.find(params[:id])
+ @gallery_item.destroy
+
+ redirect_to admin_gallery_items_path
+ end
+
+ private
+
+ def render_new gallery_item = nil
+ gallery_item ||= GalleryItem.new
+
+ render :partial => 'shared/admin/new_page', :layout => 'new_admin', :locals => {
+ :item => @gallery_item,
+ :model => GalleryItem,
+ :fields => [:title, :gallery_id],
+ :associations => { :belongs_to => { :user => :user_id , :gallery => :gallery_id } }
+ }
+ end
+
+ def render_edit gallery_item
+ render :partial => 'shared/admin/edit_page', :layout => 'new_admin', :locals => {
+ :item => gallery_item,
+ :model => GalleryItem,
+ :fields => [:title],
+ :associations => { :belongs_to => { :user => :user_id , :gallery => :gallery_id } }
+ }
+ end
+
+ def set_current_tab
+ @current_tab = 'gallery_items';
+ end
+
+end
View
2 app/controllers/galleries_controller.rb
@@ -0,0 +1,2 @@
+class GalleriesController < ApplicationController
+end
View
79 app/controllers/gallery_items_controller.rb
@@ -0,0 +1,79 @@
+class GalleryItemsController < ApplicationController
+ before_filter :logged_in_to_facebook_and_app_authorized, :only => [:new, :create, :update, :my_gallery_items], :if => :request_comes_from_facebook?
+
+# cache_sweeper :gallery_item_sweeper, :only => [:create, :update, :destroy]
+
+ before_filter :set_current_tab
+ before_filter :login_required, :only => [:new, :create, :update, :my_gallery_items]
+ before_filter :set_gallery
+# before_filter :load_top_gallery_items
+# before_filter :load_newest_gallery_items
+# before_filter :load_featured_gallery_items, :only => [:index]
+# before_filter :load_newest_gallerys
+
+ def index
+ @page = params[:page].present? ? (params[:page].to_i < 3 ? "page_#{params[:page]}_" : "") : "page_1_"
+ @current_sub_tab = 'Browse GalleryItems'
+ @gallery_items = GalleryItem.active.paginate :page => params[:page], :per_page => GalleryItem.per_page, :order => "created_at desc"
+ respond_to do |format|
+ format.html { @paginate = true }
+ format.json { @gallery_items = GalleryItem.refine(params) }
+ end
+ end
+
+ def new
+ @current_sub_tab = t('gallery.add')
+ @gallery_item = GalleryItem.new
+ @gallery_item.gallery = @gallery if @gallery.present?
+ @gallery_items = GalleryItem.active.newest
+ end
+
+ def create
+ @gallery_item = GalleryItem.new(params[:gallery_item])
+ @gallery_item.tag_list = params[:gallery_item][:tags_string]
+ @gallery_item.user = current_user
+ if params[:gallery_item][:gallery_id].present?
+ @gallery = Gallery.find_by_id(params[:gallery_item][:gallery_id])
+ @gallery_item.section_list = @gallery.section unless @gallery.nil?
+ end
+ if @gallery_item.valid? and current_user.gallery_items.push @gallery_item
+ if @gallery_item.post_wall?
+ session[:post_wall] = @gallery_item
+ end
+ flash[:success] = "Thank you for your gallery_item!"
+ redirect_to @gallery.present? ? [@gallery, @gallery_item] : @gallery_item
+ else
+ @gallery_items = GalleryItem.active.newest
+ render :new
+ end
+ end
+
+ def show
+ @gallery_item = GalleryItem.find(params[:id])
+ tag_cloud @gallery_item
+ end
+
+ def my_gallery_items
+ @paginate = true
+ @current_sub_tab = 'My Gallery Items'
+ @user = User.find(params[:id])
+ @gallery_items = @user.gallery_items.active.paginate :page => params[:page], :per_page => GalleryItem.per_page, :order => "created_at desc"
+ end
+
+ def set_slot_data
+ @ad_banner = Metadata.get_ad_slot('banner', 'gallery_items')
+ @ad_leaderboard = Metadata.get_ad_slot('leaderboard', 'gallery_items')
+ @ad_skyscraper = Metadata.get_ad_slot('skyscraper', 'gallery_items')
+ end
+
+ private
+
+ def set_gallery
+ @gallery = params[:gallery_id].present? ? Gallery.find(params[:gallery_id]) : nil
+ end
+
+ def set_current_tab
+ @current_tab = 'gallery'
+ end
+
+end
View
2 app/helpers/galleries_helper.rb
@@ -0,0 +1,2 @@
+module GalleriesHelper
+end
View
2 app/helpers/gallery_items_helper.rb
@@ -0,0 +1,2 @@
+module GalleryItemsHelper
+end
View
2 app/models/gallery.rb
@@ -0,0 +1,2 @@
+class Gallery < ActiveRecord::Base
+end
View
34 app/models/gallery_item.rb
@@ -0,0 +1,34 @@
+class GalleryItem < ActiveRecord::Base
+ acts_as_media_item
+ acts_as_voteable
+ acts_as_taggable_on :tags, :sections
+ acts_as_moderatable
+ acts_as_wall_postable
+
+ named_scope :newest, lambda { |*args| { :order => ["created_at desc"], :limit => (args.first || 10)} }
+ named_scope :featured, lambda { |*args| { :conditions => ["is_featured=1"],:order => ["created_at desc"], :limit => (args.first || 3)} }
+
+ belongs_to :user
+ belongs_to :gallery
+ has_many :comments, :as => :commentable
+ has_one :tweeted_item, :as => :item
+ attr_accessor :tags_string
+
+ has_friendly_id :title, :use_slug => true
+
+ validates_presence_of :title
+ validates_uniqueness_of :title
+ validates_presence_of :gallery
+ validates_format_of :tags_string, :with => /^([-a-zA-Z0-9_ ]+,?)+$/, :allow_blank => true, :message => "Invalid tags. Tags can be alphanumeric characters or -_ or a blank space."
+
+ def self.per_page; 10; end
+
+ def self.top
+ self.tally({
+ :at_least => 1,
+ :limit => 10,
+ :order => "votes.count desc"
+ })
+ end
+
+end
View
7 app/views/galleries/index.html.haml
@@ -0,0 +1,7 @@
+- content_for :sub_nav do
+ = render :partial => 'shared/subnav/galleries_subnav'
+
+#col_left
+ = render :partial => 'shared/galleries', :locals => { :galleries => @galleries }
+
+#col_right
View
4 app/views/galleries/show.html.haml
@@ -0,0 +1,4 @@
+- content_for :sub_nav do
+ = render :partial => 'shared/subnav/galleries_subnav'
+
+#col_left
View
0 app/views/gallery_items/index.html.haml
No changes.
View
24 app/views/gallery_items/new.html.haml
@@ -0,0 +1,24 @@
+- content_for :sub_nav do
+ - if @gallery.present?
+ = render :partial => 'shared/subnav/galleries_subnav'
+ - else
+ = render :partial => 'shared/subnav/gallery_items_subnav'
+
+#col_left
+ .panel_1
+ .panelBar
+ %h2
+ t('gallery.add')
+ .formBox
+ - semantic_form_for @gallery_item do |form|
+ - form.inputs do
+ = form.input :title, :label => t('.title'), :hint => t('.hint_gallery_item_title')
+ = form.input :caption, :input_html => { :rows => 5 }, :hint => t('.hint_gallery_item_details')
+ = form.input :tags_string, :label => t('tags'), :required => false, :hint => t('tags_hint')
+ = render :partial => 'shared/forms/media_items', :locals => { :form => form, :item => @gallery_item }
+ = render :partial => 'shared/forms/wall_postable', :locals => { :form => form, :item => @gallery_item }
+ - form.buttons do
+ = form.commit_button :button_html => { :class => 'btn_1' }
+
+#col_right
+ = render :partial => 'shared/ads_banner' ,:locals => { :slot_data => @ad_skyscraper }
View
0 app/views/gallery_items/show.html.haml
No changes.
View
5 app/views/layouts/new_admin.html.haml
@@ -104,6 +104,11 @@
%ul
%li= link_to 'Forums', admin_forums_path
%li= link_to 'Topics', admin_topics_path
+ %li
+ %a{:href => "#modules-galleries"} Galleries
+ %ul
+ %li= link_to 'Galleries', admin_galleries_path
+ %li= link_to 'Gallery Items', admin_gallery_items_path
%li
%a{:href => "#members"} Members
%ul
View
0 app/views/shared/subnav/_galleries_subnav.html.haml
No changes.
View
0 app/views/shared/subnav/_gallery_items_subnav.html.haml
No changes.
View
4 config/routes.rb
@@ -68,6 +68,8 @@
map.resources :newswires, :member => { :quick_post => [:get, :post] }
map.resources :ideas, :member => { :like => [:get, :post],:my_ideas => [:get, :post] },:collection => { :index => [:get, :post] }, :has_many => [:comments, :flags, :related_items ]
map.resources :idea_boards, :has_many => :ideas
+ map.resources :galleries, :has_many => :gallery_items
+ map.resources :gallery_items, :member => { :like => [:get, :post],:my_gallery_items => [:get, :post] },:collection => { :index => [:get, :post] }, :has_many => [:comments, :flags ]
map.resources :resources, :member => { :like => [:get, :post], :my_resources => [:get, :post] }, :collection => { :index => [:get, :post] }, :has_many => [:comments, :flags, :related_items]
map.resources :resource_sections, :has_many => :resources
map.resources :events, :member => { :like => [:get, :post],:my_events => [:get, :post] }, :collection => { :index => [:get, :post], :import_facebook => [:get, :post] },:has_many => [:comments, :flags, :related_items]
@@ -100,6 +102,8 @@
admin.resources :activity_scores
admin.resources :ideas
admin.resources :idea_boards
+ admin.resources :galleries
+ admin.resources :gallery_items
admin.resources :resources
admin.resources :resource_sections
admin.resources :events, :collection => { :import_zvents => [:get, :post]}
View
22 db/migrate/20100717230313_create_gallery_items.rb
@@ -0,0 +1,22 @@
+class CreateGalleryItems < ActiveRecord::Migration
+ def self.up
+ create_table :gallery_items do |t|
+ t.integer :user_id
+ t.string :title
+ t.text :caption, :limit => 1000
+ t.integer :votes_tally, :default => 0
+ t.integer :comments_count, :default => 0
+ t.boolean :is_featured, :default => false
+ t.datetime :featured_at
+ t.integer :flags_count, :default => 0
+ t.boolean :is_blocked, :default => false
+ t.integer :gallery_id
+ t.timestamps
+ end
+
+ end
+
+ def self.down
+ drop_table :gallery_items
+ end
+end
View
13 db/migrate/20100717232033_create_galleries.rb
@@ -0,0 +1,13 @@
+class CreateGalleries < ActiveRecord::Migration
+ def self.up
+ create_table :galleries do |t|
+ t.string :name
+ t.string :section
+ t.text :description, :limit => 1000
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :galleries
+ endend
View
25 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100715214727) do
+ActiveRecord::Schema.define(:version => 20100717231853) do
create_table "announcements", :force => true do |t|
t.string "prefix"
@@ -281,6 +281,29 @@
t.datetime "updated_at"
end
+ create_table "galleries", :force => true do |t|
+ t.string "name"
+ t.string "section"
+ t.text "description"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "gallery_items", :force => true do |t|
+ t.integer "user_id"
+ t.string "title"
+ t.text "caption"
+ t.integer "votes_tally", :default => 0
+ t.integer "comments_count", :default => 0
+ t.boolean "is_featured", :default => false
+ t.datetime "featured_at"
+ t.integer "flags_count", :default => 0
+ t.boolean "is_blocked", :default => false
+ t.integer "gallery_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "idea_boards", :force => true do |t|
t.string "name"
t.string "section"
View
1 db/seeds.rb
@@ -12,6 +12,7 @@
# Initial Topic Sections
IdeaBoard.create!({:name => 'General', :section =>'general',:description=>'General ideas.'}) unless IdeaBoard.find_by_name_and_section('General', 'general')
ResourceSection.create!({:name => 'General', :section =>'general',:description=>'General links.'}) unless ResourceSection.find_by_name_and_section('General', 'general')
+Gallery.create!({:name => 'General', :section =>'general',:description=>'General multimedia'}) unless Gallery.find_by_name_and_section('General', 'general')
# Populate Sources table with some commonly used sites
Source.create!({:name => 'New York Times', :url =>'nytimes.com'}) unless Source.find_by_url('nytimes.com')
View
7 test/fixtures/galleries.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
View
7 test/fixtures/gallery_items.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
View
8 test/functional/galleries_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class GalleriesControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
8 test/functional/gallery_items_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class GalleryItemsControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
8 test/unit/gallery_item_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class GalleryItemTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
8 test/unit/gallery_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class GalleryTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
4 test/unit/helpers/galleries_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class GalleriesHelperTest < ActionView::TestCase
+end
View
4 test/unit/helpers/gallery_items_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class GalleryItemsHelperTest < ActionView::TestCase
+end

No commit comments for this range

Something went wrong with that request. Please try again.