Skip to content

Commit

Permalink
Adds items, fixes child creation, adds sorting to items.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Yurkowski committed Feb 27, 2012
1 parent 17d3c18 commit c560b3c
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class GalleriesController < ::Refinery::AdminController
:include => [:children],
:paging => false

def new
@gallery = ::Refinery::Portfolio::Gallery.new(params.except(:controller, :action, :switch_locale))
end

def children
@gallery = find_gallery
render :layout => false
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/refinery/portfolio/admin/items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Refinery
module Portfolio
module Admin
class ItemsController < ::Refinery::AdminController
crudify :'refinery/portfolio/item',
:order => 'lft ASC'

def index
if params[:orphaned]
@items = Item.orphaned
elsif params[:gallery_id]
@items = Item.child_of(params[:gallery_id])
else
@items = Item.all
end
end

def new
@item = ::Refinery::Portfolio::Item.new(params.except(:controller, :action, :switch_locale))
end

end
end
end
end
16 changes: 16 additions & 0 deletions app/helpers/refinery/portfolio/admin/items_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Refinery
module Portfolio
module Admin
module ItemsHelper

def gallery_path_for(item)
(gallery = item.gallery).present? ? refinery.portfolio_gallery_path(gallery) : refinery.portfolio_galleries_path
end

def gallery_url_for(item)
(gallery = item.gallery).present? ? refinery.portfolio_gallery_url(gallery) : refinery.portfolio_galleries_url
end
end
end
end
end
10 changes: 8 additions & 2 deletions app/models/refinery/portfolio/item.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
module Refinery
module Portfolio
class Item < ActiveRecord::Base
attr_accessible :title, :caption, :image_id, :gallery_id
attr_accessible :title, :caption, :image_id, :gallery_id, :position
validates :gallery_id, :numericality => {:allow_nil => true}
validates :image_id, :presence => true, :numericality => true

belongs_to :image, :class_name => 'Refinery::Image'
belongs_to :gallery, :class_name => 'Refinery::Portfolio::Gallery'

scope :root_items, lambda { where(:gallery_id => nil) }
class << self
def root_items
where(:gallery_id => nil)
end

alias_method :orphaned, :root_items
end

end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
} %>
</li>
<% end %>
<li>
<%= link_to t('.add_image'), refinery.new_portfolio_admin_item_path, :class => "add_icon" %>
</li>
<li>
<%= link_to t('.view_root_images'), refinery.portfolio_admin_items_path(:orphaned => true), :class => "go_icon" %>
</li>
<li>
<%= link_to t('.create_new'), refinery.new_portfolio_admin_gallery_path,
:class => "add_icon" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
</li>
<% end %>
</ul>

<div id='page_part_editors'>
<% [:body].each do |part| %>
<div class='page_part' id='<%= part %>'>
<%= f.text_area part, :rows => 20, :class => 'wymeditor widest' -%>
</div>
<% end %>
</div>
</div>
</div>

<div class='field'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<li class='clearfix record icons' id="<%= dom_id(gallery) -%>">
<div class='clearfix'>
<% if gallery.children.present? %>
<span class="icon toggle expanded" title="<%= t('.expand_collapse') %>"></span>
<span class="icon expanded" %>"></span>
<% else %>
<span class="icon"></span>
<% end %>
Expand All @@ -12,13 +12,16 @@
</span>

<span class='actions'>
<%= link_to refinery_icon_tag("image_add.png"), refinery.new_portfolio_admin_gallery_item_path(gallery),
:title => t('.add_image') %>

<%= link_to refinery_icon_tag("application_go.png"), refinery.portfolio_gallery_path(gallery),
:title => t('.view_live_html'),
:target => "_blank" %>

<%= link_to refinery_icon_tag('page_add.png'),
refinery.new_portfolio_admin_gallery_path(:parent_id => gallery.id),
:title => t('.new') %>
:title => t('.new_child') %>

<%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_portfolio_admin_gallery_path(gallery),
:title => t('.edit') %>
Expand Down
Empty file.
62 changes: 62 additions & 0 deletions app/views/refinery/portfolio/admin/items/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<%= form_for [refinery, :portfolio_admin, @gallery, @item] do |f| -%>
<%= render :partial => "/refinery/admin/error_messages", :locals => {
:object => @item,
:include_object_name => true } %>

<div class='field'>
<%= f.label :title -%>
<%= f.text_field :title, :class => 'larger widest' -%>
</div>

<div class='field'>
<div id='page-tabs' class='clearfix ui-tabs ui-widget ui-widget-content ui-corner-all'>
<ul id='page_parts'>
<% [:caption].each_with_index do |part, part_index| %>
<li class='ui-state-default<%= ' ui-state-active' if part_index == 0 %>'>
<%= link_to t("#{part}", :scope => "activerecord.attributes.refinery/portfolio/item", :default => part.to_s.titleize), "##{part}" %>
</li>
<% end %>
</ul>
<div id='page_part_editors'>
<% [:caption].each do |part| %>
<div class='page_part' id='<%= part %>'>
<%= f.text_area part, :rows => 20, :class => 'wymeditor widest' -%>
</div>
<% end %>
</div>
</div>
</div>

<%= render :partial => '/refinery/admin/image_picker',
:locals => {
:f => f,
:field => :image_id,
:image => @item.image,
:toggle_image_display => false
} %>

<div class='field'>
<span class='label_with_help'>
<%= f.label :gallery_id, t('.gallery') -%>
<%= refinery_help_tag t('.gallery_help') -%>
</span>
<%= f.select :gallery_id, nested_set_options(::Refinery::Portfolio::Gallery, @gallery) { |i| "#{'-' * i.level} #{i.title}" }, :include_blank => true %>
</div>

<%= render :partial => "/refinery/admin/form_actions",
:locals => {
:f => f,
:continue_editing => false,
:delete_title => t('delete', :scope => 'refinery.portfolio.admin.items.item'),
:delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @item.title)
} %>

<% end -%>

<% content_for :javascripts do %>
<script>
$(document).ready(function(){
page_options.init(false, '', '');
});
</script>
<% end %>
18 changes: 18 additions & 0 deletions app/views/refinery/portfolio/admin/items/_item.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(item) -%>">
<span class='title'>
<%= item.title %>
<span class="preview">&nbsp;</span>
</span>
<span class='actions'>
<%= link_to refinery_icon_tag("application_go.png"), gallery_path_for(item),
:title => t('.view_live_html'),
:target => "_blank" %>
<%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_portfolio_admin_item_path(item),
:title => t('.edit') %>
<%= link_to refinery_icon_tag("delete.png"), refinery.portfolio_admin_item_path(item),
:class => "cancel confirm-delete",
:title => t('.delete'),
:confirm => t('message', :scope => 'refinery.admin.delete', :title => item.title),
:method => :delete %>
</span>
</li>
1 change: 1 addition & 0 deletions app/views/refinery/portfolio/admin/items/_items.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render :partial => "sortable_list" %>
16 changes: 16 additions & 0 deletions app/views/refinery/portfolio/admin/items/_records.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% if searching? %>
<h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
<% end %>
<% if @items.any? %>
<%= render :partial => 'items' %>
<% else %>
<p>
<% unless searching? %>
<strong>
<%= t('.no_items_yet') %>
</strong>
<% else %>
<%= t('no_results', :scope => 'refinery.admin.search') %>
<% end %>
</p>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul class='sortable_list'>
<%= render :partial => 'item',
:collection => @items,
:locals => {
:collection => @items
} %>
</ul>
<%= render :partial => "/refinery/admin/sortable_list", :locals => { :continue_reordering => !!local_assigns[:continue_reordering] } %>

9 changes: 9 additions & 0 deletions app/views/refinery/portfolio/admin/items/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<section id='records' class='tree'>
<%= render 'records' %>
</section>

<section id='actions'
<%= render :partial => 'actions' %>
</section>

<%= render '/refinery/admin/make_sortable', :tree => false if @items.many? %>
1 change: 1 addition & 0 deletions app/views/refinery/portfolio/admin/items/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render :partial => "form" %>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
resources :galleries, :except => :show do
get :children, :on => :member
post :update_positions, :on => :collection
resources :items do
post :update_positions, :on => :collection
end
end
resources :items do
post :update_positions, :on => :collection
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/3_add_position_to_portfolio_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPositionToPortfolioItems < ActiveRecord::Migration
def change
add_column :refinery_portfolio_items, :position, :integer
end
end
16 changes: 9 additions & 7 deletions spec/requests/refinery/portfolio/admin/galleries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
describe "Galleries" do
login_refinery_user

let (:gallery) { FactoryGirl.create(:gallery) }
let (:nested_gallery) { FactoryGirl.create(:gallery, :parent => gallery) }

describe "galleries list" do
before(:each) do
# Force load
gallery
nested_gallery
@gallery = FactoryGirl.create(:gallery)
@nested_gallery = FactoryGirl.create(:gallery, :parent => @gallery)
end

it "shows child items" do
visit refinery.portfolio_admin_galleries_path
page.should have_content(gallery.title)
page.should have_content(nested_gallery.title)
page.should have_content(@gallery.title)
page.should have_content(@nested_gallery.title)
end

it "allows item creation" do
visit refinery.portfolio_admin_galleries_path
page.should have_selector("a[href='/refinery/portfolio/items/new']")
end
end

Expand Down
87 changes: 87 additions & 0 deletions spec/requests/refinery/portfolio/admin/items_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
require "spec_helper"
include ActionController::RecordIdentifier

describe Refinery do
describe "Portfolio" do
describe "Admin" do
describe "Items" do
login_refinery_user

let(:image) { mock_model(Refinery::Image, :id => 23, :url => 'http://gifs.gifbin.com/1236681924_snail_transformers.gif') }
let(:item) { FactoryGirl.create(:item, :gallery_id => nil, :image_id => 23) }
let(:gallery) { FactoryGirl.create(:gallery) }

describe "items list" do
before(:each) do
item.stub(:image).and_return(image)
::Refinery::Portfolio::Item.stub(:root_items).and_return([item])
end

context "no parent gallery" do
it "shows items" do
visit refinery.portfolio_admin_galleries_path
within "#actions" do
click_link "View top-level images"
end

page.should have_content item.title
end
end

context "parent gallery" do
before(:each) do
gallery.stub(:items).and_return([item])
end

it "shows items" do
pending "Needs implementation"
visit refinery.portfolio_admin_galleries_path
within("##{dom_id(gallery)}") do
click_link 'Edit'
end

page.should have_content(item.title)
end
end
end

describe "create" do
context "valid data" do
it "succeeds" do
pending "Needs implementation"
visit refinery.portfolio_admin_galleries_path
within("#actions") do
click_link 'Add an image'
end

fill_in :title, :with => "My Image"
click_link "There is currently no image selected, please click here to add one."
save_and_open_page
end
end

context "invalid data" do
it "fails" do
end
end

context "duplicate" do
it "fails" do
end
end
end

describe "edit" do
it "succeeds" do
end
end

describe "destroy" do
it "succeeds" do
end
end

end
end
end
end
Loading

0 comments on commit c560b3c

Please sign in to comment.