Skip to content

Commit

Permalink
Add a select list to select the parent portfolio entry for a given po…
Browse files Browse the repository at this point in the history
…rtfolio entry. Caveats being it can't be the entry itself and it can't be a descendant of the entry.
  • Loading branch information
parndt committed Feb 27, 2010
1 parent 8864f5f commit 3ae48d7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
15 changes: 15 additions & 0 deletions app/controllers/admin/portfolio_entries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Admin::PortfolioEntriesController < Admin::BaseController

crudify :portfolio_entry, :order => 'position ASC', :conditions => "parent_id IS NULL"
before_filter :find_portfolio_entries_for_parents_list, :only => [:new, :create, :edit, :update]

def emancipate
if (entry = PortfolioEntry.find(params[:id])).present?
Expand All @@ -10,4 +11,18 @@ def emancipate
redirect_to :action => "index"
end

protected

# This finds all of the entries that could possibly be assigned as the current entry's parent.
def find_portfolio_entries_for_parents_list
@portfolio_entries_for_parents_list = PortfolioEntry.find(:all, :order => "parent_id, position ASC")

# We need to remove all references to the current entry or any of its decendants or we get a nightmare.
unless @portfolio_entry.nil? or @portfolio_entry.new_record?
@portfolio_entries_for_parents_list.reject! do |entry|
entry.id == @portfolio_entry.id or @portfolio_entry.descendants.include?(entry)
end
end
end

end
18 changes: 11 additions & 7 deletions app/models/portfolio_entry.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
class PortfolioEntry < ActiveRecord::Base

validates_presence_of :title

# call to gems included in refinery.
has_friendly_id :title, :use_slug => true, :strip_diacritics => true
acts_as_tree :order => "position"

has_and_belongs_to_many :images

def content
self.body
end

def content=(value)
self.body = value
end

def image_ids=(ids)
self.images.clear

ids.reject{|id| id.blank? }.each do |image_id|
image = Image.find(image_id.to_i) rescue nil
self.images << image unless image.nil?
end
end


def indented_title
"#{"--" * self.ancestors.size} #{self.title}".chomp
end

end
6 changes: 6 additions & 0 deletions app/views/admin/portfolio_entries/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<%= f.label :body, 'Content' %>
<%= f.text_area :body, :class => "wymeditor", :rows => 7 %>
</div>
<% if @portfolio_entries_for_parents_list.any? %>
<div class='field'>
<%= f.label :parent_id %>
<%= f.collection_select :parent_id, @portfolio_entries_for_parents_list, :id, :indented_title, :include_blank => true %>
</div>
<% end %>
<div class='form-actions'>
<%= f.submit 'Save', :class => "wymupdate" %>
or
Expand Down
2 changes: 1 addition & 1 deletion rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
plugin.title = "Portfolio"
plugin.description = "Manage a portfolio"
plugin.url = "/admin/#{plugin.title.downcase}"
plugin.version = '0.9.3.6'
plugin.version = '0.9.3.7'
plugin.menu_match = /admin\/portfolio(_entries)?/
plugin.activity = {
:class => PortfolioEntry,
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Then run:
refinerycms-portfolio-install /path/to/your/refinery/application

Then place in your config/environment.rb (or config/application.rb for refinery 0.9.6.x) file before all other Refinery gem calls:
config.gem "refinerycms-portfolio", :version => ">= 0.9.3.6", :lib => "portfolio", :source => "http://gemcutter.org"
config.gem "refinerycms-portfolio", :version => ">= 0.9.3.7", :lib => "portfolio", :source => "http://gemcutter.org"

..and follow the instructions!

### Method Two
Place in your config/environment.rb (or config/application.rb for refinery 0.9.6.x) file before all other Refinery gem calls:
config.gem "refinerycms-portfolio", :version => ">= 0.9.3.6", :lib => "portfolio", :source => "http://gemcutter.org"
config.gem "refinerycms-portfolio", :version => ">= 0.9.3.7", :lib => "portfolio", :source => "http://gemcutter.org"

Then run in your application's directory:
rake gems:install
Expand Down
4 changes: 2 additions & 2 deletions refinerycms-portfolio.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Gem::Specification.new do |s|

s.name = %q{refinerycms-portfolio}
s.version = "0.9.3.6"
s.version = "0.9.3.7"

s.authors = ["Resolve Digital", "Philip Arndt"]
s.date = %q{2010-02-18}
s.date = %q{2010-02-27}

s.description = %q{A really straightforward open source Ruby on Rails portfolio plugin designed for integration with RefineryCMS.}
s.summary = %q{Ruby on Rails portfolio plugin for RefineryCMS.}
Expand Down

0 comments on commit 3ae48d7

Please sign in to comment.