Commit 8149412f authored by Martin Markech's avatar Martin Markech
Browse files

refactor & do ajaxified pagination

parent 1dfa54dc
......@@ -20,8 +20,6 @@ module Refinery
"#{id}-#{title.parameterize}"
end
private
def set_title
......
......@@ -15,7 +15,7 @@ module Refinery
# only file store supports regexp
begin
# This is slow, but I was unable to get the actual cache folder path.
expire_fragment( %r{refinery/photo_gallery/albums/#{photo.album_id}/page_\d*})
expire_fragment( %r{refinery/photo_gallery/albums/#{photo.album_id}/page/\d*})
rescue NotImplementedError
Rails.cache.clear
warn "**** [REFINERY PHOTO GALLERY] The cache store you are using is not compatible with this engine. Only file_store is supported. Clearing entire cache instead ***"
......
......@@ -9,7 +9,7 @@ module Refinery
begin
# TODO This is slow, but I was unable to get the actual cache folder path.
# This should be replaced with FileUtils.rm to get better speed
expire_fragment( %r{refinery/photo_gallery/albums/#{photo.album_id}/page_\d*})
expire_fragment( %r{refinery/photo_gallery/albums/#{photo.album_id}/page/\d*})
rescue NotImplementedError
Rails.cache.clear
warn "**** [REFINERY PHOTO GALLERY] The cache store you are using is not compatible with this engine. Only file_store is supported. Clearing entire cache instead ***"
......
<%# cache "refinery/photo_gallery/albums/#{params[:id]}/page_#{params[:page]}" do %>
<%= will_paginate @page.photos.page(params[:page]) %>
<% cache "refinery/photo_gallery/albums/#{@page.album.id}/page/#{params[:page]}" do %>
<% photos_for_page = @page.photos_for_page(params[:page]) %>
<%= will_paginate photos_for_page %>
<ul id="gallery" class="clearfix">
<% @page.photos.each_with_index do |photo, index| %>
<li>
<%= link_to (image_tag photo.file.album.url, :width => Refinery::PhotoGallery.album_dimensions[0], :height => Refinery::PhotoGallery.album_dimensions[1] ), photo.file.single.url, {
:target=> "_blank",
:class=>"fancybox",
:data =>{:title=> t('.image') + ' ' + (index + 1 ).to_s + '/' + @page.photos.length.to_s + ' ' + photo.title + '<br/><br/>' + photo.description},
:rel=>"group",
:title=> photo.title } %>
</li>
<ul id="gallery" class="clearfix">
<% photos_for_page.each_with_index do |photo, index| %>
<li>
<%= link_to (image_tag photo.file.url(:album), :width => Refinery::PhotoGallery.album_dimensions[0], :height => Refinery::PhotoGallery.album_dimensions[1] ), photo.file.single.url, {
:target=> "_blank",
:class=>"fancybox",
:data =>{:title=> t('.image') + ' ' + (index + 1 ).to_s + '/' + photos_for_page.total_pages.to_s + ' ' + photo.title + '<br/><br/>' + photo.description},
:rel=>"group",
:title=> photo.title } %>
</li>
<% end %>
</ul>
<% end %>
</ul>
<%= will_paginate @page.photos.page(params[:page]) %>
<%# end %>
<%= will_paginate photos_for_page %>
<% end %>
<% if @page.album.present? %>
<% cache "refinery/photo_gallery/albums/#{params[:id]}" do %>
<% cache "refinery/photo_gallery/albums/#{@page.album.id}" do %>
<h2 >
<%= @page.album.title %>
</h2>
......@@ -10,8 +10,9 @@
</div>
<% end %>
<%= render :partial => "/refinery/photo_gallery/albums/photos" %>
<div id="photo_gallery">
<%= render :partial => "/refinery/photo_gallery/albums/photos" %>
</div>
<% end %>
Refinery::Core::Engine.routes.draw do
namespace "photo_gallery", :path => 'photo-gallery' do
root :to => "collections#index"
match "/collections/:collection_id/albums/:id/page-:page" => "albums#show"
resources :collections, :only => [:index,:show] do
resources :albums, :only => [:show] do
end
end
end
match ":path/page/:page" => "pages#show", :as => :page
match ":path" => "pages#show", :as => :page , :page => 1
namespace "photo_gallery", :path => '' do
namespace :admin, :path => 'refinery' do
......@@ -36,21 +28,4 @@ Refinery::Core::Engine.routes.draw do
end
end
end
# Frontend routes
namespace :photo_gallery do
resources :photo_pages, :only => [:index, :show]
end
# Admin routes
namespace :photo_gallery, :path => '' do
namespace :admin, :path => 'refinery/photo_gallery' do
resources :photo_pages, :except => :show do
collection do
post :update_positions
end
end
end
end
end
......@@ -24,6 +24,7 @@ module Refinery
config.to_prepare do
require 'refinerycms-pages'
Refinery::Page.send :has_one_page_album
Refinery::PagesController.send :include, Refinery::PhotoGallery::Extensions::PagesController
end
config.before_initialize do
......
......@@ -2,18 +2,25 @@ module Refinery
module PhotoGallery
module Extensions
module PagesController
def load_helpers
=begin
Refinery::PagesController.class_eval do
include Refinery::PhotoGallery::PhotoGalleryHelper
helper :'refinery/photo_gallery/photo_gallery'
def self.included(base)
base.class_eval do
around_filter :wrap_show_action, :only => :show
def wrap_show_action
if request.xhr?
respond_to do |format|
format.js { render :partial=> "/refinery/photo_gallery/albums/photos"}
end
else
show
end
end
=end
end
end
end
end
end
end
......@@ -5,12 +5,20 @@ module Refinery
def has_one_page_album
has_one :album_page, :as => :page
has_one :album, :through => :album_page
has_many :photos, :class_name => Refinery::PhotoGallery::Photo, :through => :album
has_many :photos, :class_name => Refinery::PhotoGallery::Photo, :through => :album , :order=> "created_at ASC"
accepts_nested_attributes_for :album_page
module_eval do
def photos_for_page(params_page)
Refinery::PhotoGallery::Photo.where("album_id = ?", self.album.id ).
includes(:album).
paginate(:page => params_page).
order("created_at ASC")
end
def album_page=(album_page_params)
# new
if self.album_page.nil?
......@@ -19,9 +27,9 @@ module Refinery
# destroy
if album_page_params[:album_id].blank?
self.album_page.destroy
self.album_page.destroy
# create or update if changed
# create or update if changed
elsif self.album_page.album_id.to_s != album_page_params[:album_id]
self.album_page.update_attributes( album_page_params)
self.album_page.save
......
module Refinery
module PhotoGallery
module Extensions
module PagesHelper
def self.included(base)
base.class_eval do
# TODO put here code from view.
# Before, fix this helper to work
end
end
end
end
end
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment