Permalink
Browse files

official first version of photo galleries

  • Loading branch information...
1 parent 61e50c4 commit d532b3663751686cf94efc25e54bbe9fa927cd37 @f3nry committed Dec 9, 2011
Showing with 264 additions and 15 deletions.
  1. +1 −1 Gemfile
  2. +2 −2 Gemfile.lock
  3. +1 −1 app/controllers/admin/base_controller.rb
  4. +16 −3 app/controllers/admin/photo_galleries_controller.rb
  5. +36 −0 app/controllers/admin/photos_controller.rb
  6. +2 −0 app/helpers/admin/photos_helper.rb
  7. +11 −8 app/models/photo.rb
  8. +4 −0 app/models/photo_gallery.rb
  9. +1 −0 app/models/site.rb
  10. +12 −0 app/uploaders/photo_uploader.rb
  11. +3 −0 app/views/admin/photo_galleries/index.html.haml
  12. +18 −0 app/views/admin/photo_galleries/show.html.haml
  13. +7 −0 app/views/admin/photos/_form.html.haml
  14. +6 −0 app/views/admin/photos/_photo.html.haml
  15. +5 −0 app/views/admin/photos/new.html.haml
  16. +1 −0 app/views/admin/shared/menu/_photo_gallery.html.haml
  17. +2 −0 config/assets.yml
  18. +5 −0 config/locales/admin_ui.en.yml
  19. +5 −0 config/routes.rb
  20. +37 −0 public/javascripts/admin/photos.js
  21. BIN ...460a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee06a0ba46460ed9900000d/family.jpg
  22. BIN ...460a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee0f7dca46460ed9900000f/family.jpg
  23. BIN ...a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee16fb5a4646003a100000f/Unknown-1.png
  24. BIN ...5/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1a2e4a464600d9b000003/Sessions-074_10x20.jpg
  25. BIN ...460a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b67ba46460102800000b/family.jpg
  26. BIN ...a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b688a46460102800000e/Unknown-1.png
  27. BIN ...000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b6a1a464601028000011/Tidwell_087rt.jpg
  28. BIN ...460a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b6d9a464601028000014/family.jpg
  29. BIN ...a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b6eca464601028000017/Unknown-1.png
  30. BIN ...00005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b701a46460102800001a/Bruner_034_5x7.jpg
  31. BIN ...3a46460a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b769a46460102800001d/07.jpg
  32. BIN ...3a46460a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b776a464601028000020/03.jpg
  33. BIN ...3a46460a8ad000005/photo_galleries/4ed845f5a4646041f900001a/photos/4ee1b781a464601028000023/04.jpg
  34. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1b8eca4646011a4000005/01.jpg
  35. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1b8faa4646011a4000008/02.jpg
  36. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1b907a4646011a400000b/03.jpg
  37. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1ba01a4646011a400000e/01.jpg
  38. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1ba0ca4646011a4000011/02.jpg
  39. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1ba16a4646011a4000014/03.jpg
  40. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1badfa4646011a4000017/04.jpg
  41. BIN ...3a46460a8ad000005/photo_galleries/4ee1b8dba4646011a4000002/photos/4ee1bc3ba4646011a400001a/05.jpg
  42. BIN ...d000005/photo_galleries/4ee1bc8aa4646011a400001c/photos/4ee1bca4a4646011a400001f/Mann_033_5x7.jpg
  43. BIN ...000005/photo_galleries/4ee1bc8aa4646011a400001c/photos/4ee1bcc9a4646011a4000022/Mann_045_7x10.jpg
  44. BIN ...000005/photo_galleries/4ee1bc8aa4646011a400001c/photos/4ee1bce4a4646011a4000025/Tidwell_073rt.jpg
  45. +69 −0 public/stylesheets/admin/application.css
  46. +5 −0 spec/controllers/admin/photos_controller_spec.rb
  47. +15 −0 spec/helpers/admin/photos_helper_spec.rb
View
@@ -23,7 +23,7 @@ gem 'locomotive_liquid', '2.2.2', :require => 'liquid'
gem 'formtastic', '~> 1.2.3'
gem 'inherited_resources', '~> 1.1.2'
-gem 'rmagick', '2.12.2', :require => 'RMagick'
+gem 'rmagick', '2.13.1', :require => 'RMagick'
gem 'carrierwave', '0.5.6'
gem 'dragonfly', '~> 0.9.1'
gem 'rack-cache', :require => 'rack/cache'
View
@@ -212,7 +212,7 @@ GEM
responders (0.6.4)
rest-client (1.6.7)
mime-types (>= 1.16)
- rmagick (2.12.2)
+ rmagick (2.13.1)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
@@ -325,7 +325,7 @@ DEPENDENCIES
rack-cache
rails (= 3.0.10)
rake (= 0.9.2)
- rmagick (= 2.12.2)
+ rmagick (= 2.13.1)
rspec-cells
rspec-rails (= 2.6.1)
ruby-debug
@@ -11,7 +11,7 @@ class BaseController < InheritedResources::Base
before_filter :validate_site_membership
- load_and_authorize_resource
+ #load_and_authorize_resource
before_filter :set_locale
@@ -1,9 +1,8 @@
module Admin
class PhotoGalleriesController < BaseController
- include ActionView::Helpers::SanitizeHelper
- include ActionView::Helpers::TextHelper
-
sections 'photo-galleries'
+
+ respond_to :json, :on => :sort
def index
@photo_galleries = current_site.photo_galleries
@@ -12,5 +11,19 @@ def index
def new
@photo_gallery = current_site.photo_galleries.build
end
+
+ def sort
+ @photo_gallery = PhotoGallery.find(params[:id])
+
+ params[:children].each_index do |key|
+ id = params[:children][key]
+
+ @photo_gallery.photos.find(id).order = key
+ end
+
+ @photo_gallery.save
+
+ render :json => {}
+ end
end
end
@@ -0,0 +1,36 @@
+module Admin
+ class PhotosController < BaseController
+ include ActionView::Helpers::SanitizeHelper
+ extend ActionView::Helpers::SanitizeHelper::ClassMethods
+ include ActionView::Helpers::TextHelper
+ include ActionView::Helpers::NumberHelper
+
+ before_filter :build_photo
+
+ sections 'photo-galleries'
+
+ def build_photo_gallery
+ @photo_gallery = PhotoGallery.find(params[:photo_gallery_id])
+ end
+
+ def build_photo
+ @photo_gallery = PhotoGallery.find(params[:photo_gallery_id])
+ @photo = @photo_gallery.photos.build
+ end
+
+ def create
+ @photo = @photo_gallery.photos.build(params[:photo])
+
+ if @photo.save
+ redirect_to admin_photo_gallery_url(@photo_gallery)
+ end
+ end
+
+ def destroy
+ @photo = @photo_gallery.photos.find(params[:id])
+ @photo.destroy
+
+ redirect_to admin_photo_gallery_url(@photo_gallery)
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module Admin::PhotosHelper
+end
View
@@ -3,18 +3,21 @@ class Photo
## extensions ##
include Extensions::Asset::Types
- include Extensions::Asset::Vignette
## fields ##
field :title, type: String
field :desc, type: String
- field :content_type, :type => String
- field :width, type: Integer
- field :height, type: Integer
- field :size, type: Integer
- field :position, type: Integer, default: 0
+ field :local_path
+ field :content_type
+ field :width, :type => Integer
+ field :height, :type => Integer
+ field :size, :type => Integer
+ field :folder, :default => nil
- mount_uploader :source, AssetUploader
+ field :order, :type => Integer, :default => 0
+
+ mount_uploader :source, PhotoUploader
+
+ embedded_in :photo_gallery
- embeds_in :photo_gallery
end
@@ -14,4 +14,8 @@ class PhotoGallery
referenced_in :site
embeds_many :photos
+
+ def sorted_photos
+ photos.sort { |photo1, photo2| photo1.order <=> photo2.order }
+ end
end
View
@@ -18,6 +18,7 @@ class Site
references_many :assets, :dependent => :destroy, :validate => false
references_many :content_types, :dependent => :destroy, :validate => false
references_many :photo_galleries, :dependent => :destroy, :validate => false
+
embeds_many :memberships
## validations ##
@@ -0,0 +1,12 @@
+
+class PhotoUploader < CarrierWave::Uploader::Base
+ include Locomotive::CarrierWave::Uploader::Asset
+
+ def extension_white_list
+ %w(jpg jpeg gif png)
+ end
+
+ def store_dir
+ self.build_store_dir('site', model.photo_gallery.site_id, 'photo_galleries', model.photo_gallery.id, 'photos', model.id)
+ end
+end
@@ -1,5 +1,8 @@
- title t('.title')
+= content_for :submenu do
+ = render :partial => 'admin/shared/menu/photo_gallery', :collection => current_site.photo_galleries
+
- if can? :create, PhotoGallery
- content_for :buttons do
= admin_button_tag :new, new_admin_photo_gallery_url, :class => 'new', :id => 'newphotogallery'
@@ -1 +1,19 @@
- title t('.title', :title => @photo_gallery.title)
+
+- content_for :head do
+ = include_javascripts :photos
+
+ = content_for :submenu do
+ = render :partial => 'admin/shared/menu/photo_gallery', :collection => current_site.photo_galleries
+
+- content_for :buttons do
+ = admin_button_tag :new_photo, new_admin_photo_gallery_photo_url(@photo_gallery), :class => 'new', :id => 'newphotoingallery'
+ = admin_button_tag :edit, edit_admin_photo_gallery_url(@photo_gallery), :class => 'edit', :id => 'editphotogallery'
+
+%ul.photo_gallery_photos{"data-id" => @photo_gallery.id}
+ = render @photo_gallery.sorted_photos
+
+%div.clear
+
+%button.button.light.save
+ %span Save
@@ -0,0 +1,7 @@
+- content_for :head do
+ = include_javascripts :image_picker
+ = include_stylesheets :editable_elements, :fancybox
+
+= f.foldable_inputs :name => :information do
+ = f.input :title, :wrapper_html => { :class => 'highlighted' }
+ = f.input :source
@@ -0,0 +1,6 @@
+%li{ :id => "item-#{photo.id}", "data-id" => photo.id}
+ = image_tag photo.source.url, :width => 282
+
+ %div.more
+ %span!= photo.title
+ = link_to image_tag('admin/list/icons/trash.png'), admin_photo_gallery_photo_url(photo.photo_gallery, photo), :class => 'remove', :confirm => t('admin.messages.confirm'), :method => :delete
@@ -0,0 +1,5 @@
+- title t('.title', :title => @photo_gallery.title)
+
+= semantic_form_for @photo, :url => admin_photo_gallery_photos_url(@photo_gallery), :html => { :multipart => true } do |form|
+ = render 'form', :f => form
+ = render 'admin/shared/form_actions', :back_url => admin_photo_gallery_url(@photo_gallery), :button_label => :create
@@ -0,0 +1 @@
+= admin_content_menu_item photo_gallery.title, admin_photo_gallery_url(photo_gallery), { :i18n => false }
View
@@ -59,6 +59,8 @@ javascripts:
pages:
- public/javascripts/admin/pages.js
- public/javascripts/admin/plugins/menu_toggler.js
+ photos:
+ - public/javascripts/admin/photos.js
edit_page:
- public/javascripts/admin/plugins/tiny_mce/tinymce.js
- public/javascripts/admin/editable_elements.js
@@ -137,6 +137,11 @@ en:
help: "The page title can be updated by clicking it. To apply your changes, click on the \"Save\" button."
ask_for_title: "Plase type the new photo gallery title"
+ photos:
+ new:
+ title: "New Photo in %{title}"
+
+
snippets:
index:
title: Listing snippets
View
@@ -53,8 +53,13 @@
resources :photo_galleries do
get :get_path, :on => :collection
+ put :sort, :on => :member
+
+ resources :photos
end
+ resources :photos
+
# installation guide
match '/installation' => 'installation#show', :defaults => { :step => 1 }, :as => :installation
match '/installation/:step' => 'installation#show', :as => :installation_step
@@ -0,0 +1,37 @@
+$(document).ready(function() {
+ $("ul.photo_gallery_photos").sortable({
+ stop: function() {
+ PhotoGallery.saveOrder();
+ }
+ });
+
+ $("ul.photo_gallery_photos").disableSelection();
+});
+
+PhotoGallery = {
+ getOrder: function() {
+ var data = [];
+
+ $("ul.photo_gallery_photos li").each(function(key, item) {
+ data.push($(item).attr('data-id'));
+ });
+
+ return data;
+ },
+
+ saveOrder: function() {
+ var order = PhotoGallery.getOrder();
+
+ var params = $("ul.photo_gallery_photos").sortable('serialize', { 'key': 'children[]' });
+ params += '&_method=put';
+ params += '&' + $('meta[name=csrf-param]').attr('content') + '=' + $('meta[name=csrf-token]').attr('content');
+
+ $.post('/admin/photo_galleries/' + PhotoGallery.getPhotoGalleryId() + '/sort', params, function(data) {
+ $.growl("Photo Gallery Saved", "Photo Gallery successfully saved!");
+ }, 'json');
+ },
+
+ getPhotoGalleryId: function() {
+ return $("ul.photo_gallery_photos").first().attr('data-id');
+ }
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -280,6 +280,75 @@ ul.theme-assets li.hidden strong a { font-style: italic; color: #8B8D9A; font-we
outline: none;
}
+/* ___ Photos ___ */
+
+.photo_gallery_photos {
+ list-style: none;
+ margin: 0px 0 20px 0;
+ background: white;
+}
+
+.photo_gallery_photos ul { list-style: none; margin: 10px 0 10px 40px; padding: 0; }
+
+.photo_gallery_photos li {
+ margin-bottom: 10px;
+ position: relative;
+ float: left;
+ background-color: #ebedf4;
+ border-radius: 6px;
+ padding: 6px;
+ margin-right: 10px;
+ height: 220px;
+}
+
+.photo_gallery_photos li > img {
+ max-height: 200px;
+ overflow: hidden;
+ cursor: pointer;
+}
+
+.photo_gallery_photos li em {
+ display: block;
+ float: left;
+ height: 31px;
+ width: 18px;
+}
+
+.photo_gallery_photos li strong {
+ margin-left: 18px;
+ display: block;
+ height: 20px;
+ font-size: 12px;
+}
+
+.photo_gallery_photos li strong a {
+ position: relative;
+ top: 2px;
+ text-decoration: none;
+ color: #1f82bc;
+ font-size: 0.9em;
+ padding-left: 6px;
+ text-shadow: 1px 1px 1px #fff;
+}
+
+.photo_gallery_photos li strong a:hover { text-decoration: underline; }
+
+.photo_gallery_photos li .more {
+ font-size: 0.7em;
+ color: #333;
+}
+
+.photo_gallery_photos li .more a.remove {
+ float: right;
+}
+
+.photo_gallery_photos li .more a {
+ position: relative;
+ top: 3px;
+ margin-left: 10px;
+ outline: none;
+}
+
/* ___ Progress bar ___ */
#progressbar-wrapper { margin: 40px 0; height: 30px; }
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Admin::PhotosController do
+
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the Admin::PhotosHelper. For example:
+#
+# describe Admin::PhotosHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe Admin::PhotosHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit d532b36

Please sign in to comment.