Skip to content

Commit

Permalink
changed naming of private galleries and added pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
rapind committed Mar 26, 2012
1 parent 4ce6339 commit 61beb7f
Show file tree
Hide file tree
Showing 81 changed files with 509 additions and 568 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Admin::PhotosController < Admin::HomeController
inherit_resources
actions :destroy
respond_to :json
belongs_to :gallery
belongs_to :private_gallery

def destroy
destroy! do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
class Admin::GalleriesController < Admin::HomeController
class Admin::PrivateGalleriesController < Admin::HomeController
inherit_resources
actions :all, :except => :show
respond_to :html

def index
params[:order] = 'name' unless params[:order]
@galleries = Gallery.order(params[:order])
@private_galleries = PrivateGallery.order(params[:order])

if defined?(params[:search][:q]) and params[:search][:q]
term = Regexp.escape(params[:search][:q])
@galleries = @galleries.where(["name ~* ?", term])
@private_galleries = @private_galleries.where(["name ~* ?", term])
end

respond_to do |format|
format.html { @galleries = @galleries.page(params[:page]) } # page html view
format.json { @galleries = @galleries.limit(25) } # limit json view
format.html { @private_galleries = @private_galleries.page(params[:page]) } # page html view
format.json { @private_galleries = @private_galleries.limit(25) } # limit json view
end
end

# Set a default expire date
def new
new! { @gallery.expires_on = 4.weeks.from_now }
new! { @private_gallery.expires_on = 4.weeks.from_now }
end

# Redirect to the edit path on create.
Expand All @@ -34,18 +34,18 @@ def update
end

def invite
@gallery = Gallery.find(params[:id])
@private_gallery = PrivateGallery.find(params[:id])
end

def send_invite
@gallery = Gallery.find(params[:id])
@private_gallery = PrivateGallery.find(params[:id])

# Send the email
begin
logger.debug("Send email invitation to: #{params[:email]}")
GalleryMailer.invite(photographer.email, params[:email], @gallery).deliver
PrivateGalleryMailer.invite(photographer.email, params[:email], @private_gallery).deliver

redirect_to collection_path, :notice => 'Gallery sent.'
redirect_to collection_path, :notice => 'Private gallery sent.'
rescue Exception => e
render :invite, :error => 'The was a problem sending an email to the address you provided.'
end
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
class ApplicationController < ActionController::Base
protect_from_forgery

helper_method :photographer
helper_method :photographer, :page_links

protected #----

def photographer
return @photographer if defined?(@photographer)
@photographer = Photographer.cached
end
end

def page_links
return @pages if defined?(@pages)
@pages = Page.cached
end

end
14 changes: 0 additions & 14 deletions app/controllers/galleries_controller.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class PagesController < ApplicationController
inherit_resources
respond_to :html
actions :show
end
14 changes: 14 additions & 0 deletions app/controllers/private_galleries_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class PrivateGalleriesController < ApplicationController
respond_to :html

def show
@photographer = Photographer.first
@private_gallery = PrivateGallery.find_by_token(params[:id])
if @private_gallery
render
else
redirect_to(root_path, :alert => "Unable to find that private gallery.")
end
end

end
9 changes: 0 additions & 9 deletions app/mailers/gallery_mailer.rb

This file was deleted.

9 changes: 9 additions & 0 deletions app/mailers/private_gallery_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PrivateGalleryMailer < ActionMailer::Base

def invite(from, to, private_gallery)
@private_gallery = private_gallery
@photographer = Photographer.cached
mail( :from => from, :to => to, :subject => 'Your private gallery is ready!')
end

end
4 changes: 2 additions & 2 deletions app/models/contact_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class ContactRequest < ActiveRecord::Base
# Validations
validates :email, :presence => true, :length => { :within => 5..100 }
validates :name, :length => { :within => 2..64, :allow_blank => true }
validates :subject, :presence => true, :length => { :within => 5..128 }
validates :message, :presence => true, :length => { :minimum => 10 }

# ****
# Mass-assignment protection
attr_accessible :email, :name, :subject, :body
attr_accessible :email, :name, :message

# ****
# Named scopes
Expand Down
43 changes: 43 additions & 0 deletions app/models/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Page < ActiveRecord::Base

# ****
# Validations
validates :name, :presence => true, :length => { :within => 2..32 }
validates :body, :presence => true

# ****
# Mass-assignment protection
attr_accessible :name, :body, :image, :image_cache, :remove_image

# Image attachment.
mount_uploader :image, ImageUploader

# ****
# Pagination
paginates_per 16

def to_param
"#{id}-#{name}".parameterize
end

# Caching
# -------
CACHED = 'pages'

after_save :clear_cache

def self.cached
Rails.cache.fetch(CACHED, :expires_in => 1.day) do
Page.order(:name).all
end
end

def clear_cache
Page.clear_cache
end

def self.clear_cache
Rails.cache.delete(CACHED)
end

end
8 changes: 4 additions & 4 deletions app/models/photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ class Photo < ActiveRecord::Base

# ****
# Associations
belongs_to :gallery, :counter_cache => true
belongs_to :private_gallery, :counter_cache => true

# ****
# Validations
validates :name, :presence => true, :length => { :maximum => 100 }

# ****
# Mass-assignment protection
attr_accessible :gallery_id, :name, :image, :image_cache
attr_accessible :private_gallery_id, :name, :image, :image_cache

# Photo attachment.
mount_uploader :image, ImageUploader
mount_uploader :photo, PhotoUploader

before_validation :set_name

private #----

# If no name has been set, use the image's file name but spruce it up a little.
def set_name
self.name = self.image.filename[0, self.image.filename.rindex('.')].humanize.titleize if self.name.blank? and !self.image.filename.blank?
self.name = self.photo.filename[0, self.photo.filename.rindex('.')].humanize.titleize if self.name.blank? and !self.photo.filename.blank?
end

end
14 changes: 7 additions & 7 deletions app/models/gallery.rb → app/models/private_gallery.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Gallery < ActiveRecord::Base
class PrivateGallery < ActiveRecord::Base

# ****
# Associations
has_many :photos, :dependent => :destroy
has_many :gallery_events, :dependent => :destroy
has_many :private_gallery_events, :dependent => :destroy

# ****
# Virtual attribute for sending email invitations.
Expand Down Expand Up @@ -32,13 +32,13 @@ def photos_attrs=(attrs)
attrs.each { |attr| self.photos.build(:image => attr) }
end

# Determine if the gallery has expired.
# Determine if the private gallery has expired.
def expired?
(self.expires_on and self.expires_on < Date.today) || false
end

def status
gallery_events.order('created_at desc').limit(1).first.description rescue nil
private_gallery_events.order('created_at desc').limit(1).first.description rescue nil
end

before_create :build_token
Expand All @@ -47,17 +47,17 @@ def status

private #----

# Secures galleries by using an unguessable token.
# Secures private galleries by using an unguessable token.
def build_token
self.token = Devise.friendly_token
end

def log_create_event
gallery_events.create(:description => 'Created')
private_gallery_events.create(:description => 'Created')
end

def log_update_event
gallery_events.create(:description => 'Updated')
private_gallery_events.create(:description => 'Updated')
end

end
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class GalleryEvent < ActiveRecord::Base
class PrivateGalleryEvent < ActiveRecord::Base

# ****
# Associations
belongs_to :gallery
belongs_to :private_gallery

# ****
# Validations
validates :gallery, :presence => true
validates :private_gallery, :presence => true
validates :description, :presence => true, :length => { :within => 5..128 }

# ****
Expand Down
30 changes: 30 additions & 0 deletions app/uploaders/photo_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# encoding: utf-8

class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

# Provide a default URL as a default if there hasn't been a file uploaded.
def default_url
"/images/misc/missing.png"
end

# Resize the original
process :resize_to_limit => [580, 640]

# Create a thumbnail
version :thumb do
process :resize_to_fill => [150, 100]
end

# Add a white list of extensions which are allowed to be uploaded.
def extension_white_list
%w(jpg jpeg gif png)
end

end
14 changes: 0 additions & 14 deletions app/views/admin/galleries/_form.html.haml

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/admin/galleries/_photo.html.haml

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/admin/galleries/edit.html.haml

This file was deleted.

11 changes: 0 additions & 11 deletions app/views/admin/galleries/invite.html.haml

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/admin/galleries/new.html.haml

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/admin/photographers/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%p Click the "Update Settings" button when you're done.

= simple_form_for(@photographer, :url => admin_photographer_path, :method => :put, :html => { :class => 'form-horizontal' }) do |form|
= render "admin/shared/error_messages", :target => @photographer
= render "shared/error_messages", :target => @photographer

= form.input :email, :required => true, :hint => 'Your business email address.'
= form.input :name, :hint => 'Your business name.'
Expand Down
Loading

0 comments on commit 61beb7f

Please sign in to comment.