Skip to content

Commit

Permalink
Added the ability to use nested routes into the Dashboard Activity. R…
Browse files Browse the repository at this point in the history
…emoved the use of eval from dashboard_helper and cleaned up the init files so that they are not all scrunched up.
  • Loading branch information
parndt committed Feb 9, 2010
1 parent ed56a23 commit dbe1c81
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ public/stylesheets/cache
config/database.yml.example
.yardoc/
themes/*
refinerycms.gemspec
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.6.4
0.9.6.5
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Admin::DashboardHelper

def activity_message_for(record)
unless (activity = Refinery::Plugins.active.find_activity_by_model(record.class)).nil? or activity.title.blank?
if (activity = Refinery::Plugins.active.find_activity_by_model(record.class)).present? and activity.title.present?
title = record.send activity.title
link = link_to truncate(title, :length => 45),
eval("#{activity.url_prefix}admin_#{record.class.name.underscore.downcase}_url(record)"),
:title => "See '#{title}'"
link = link_to truncate(title, :length => 45),
eval("#{activity.url}(#{activity.nesting("record")}record)"),
:title => "See '#{title}'"

# next work out which action occured and how long ago it happened
action = record.updated_at.eql?(record.created_at) ? "created" : "updated"
Expand Down
9 changes: 8 additions & 1 deletion vendor/plugins/images/rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
plugin.description = "Manage images"
plugin.version = 1.0
plugin.menu_match = /admin\/((images)|(image_dialogs))$/
plugin.activity = {:class => Image, :title => 'title', :url_prefix => 'edit', :conditions => "parent_id IS NULL", :created_image => "image_add.png", :updated_image => "image_edit.png"}
plugin.activity = {
:class => Image,
:title => 'title',
:url_prefix => 'edit',
:conditions => "parent_id IS NULL",
:created_image => "image_add.png",
:updated_image => "image_edit.png"
}
end
6 changes: 5 additions & 1 deletion vendor/plugins/news/rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
plugin.description = "Provides a blog-like news section"
plugin.version = 1.0
plugin.menu_match = /admin\/((news)|(news_items))$/
plugin.activity = {:class => NewsItem, :title => 'title', :url_prefix => 'edit'}
plugin.activity = {
:class => NewsItem,
:title => 'title',
:url_prefix => 'edit'
}
end
8 changes: 7 additions & 1 deletion vendor/plugins/pages/rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
plugin.description = "Manage content pages"
plugin.version = 1.0
plugin.menu_match = /admin\/((pages)|(page_dialogs)|(page_parts))$/
plugin.activity = {:class => Page, :url_prefix => "edit_", :title => "title", :created_image => "page_add.png", :updated_image => "page_edit.png"}
plugin.activity = {
:class => Page,
:url_prefix => "edit",
:title => "title",
:created_image => "page_add.png",
:updated_image => "page_edit.png"
}
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
plugin.title = "<%= class_name.pluralize.underscore.titleize %>"
plugin.description = "Manage <%= class_name.pluralize.underscore.titleize %>"
plugin.version = 1.0
plugin.activity = {:class => <%= class_name %>, :url_prefix => "edit_", :title => '<%= attributes.first.name %>'}
plugin.activity = {
:class => <%= class_name %>,
:url_prefix => "edit",
:title => '<%= attributes.first.name %>'
}
end
33 changes: 27 additions & 6 deletions vendor/plugins/refinery/lib/refinery/activity.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
module Refinery
class Activity

attr_accessor :class, :title, :url_prefix, :order, :conditions, :limit, :created_image, :updated_image, :conditions
attr_accessor :class, :conditions, :created_image, :limit, :nested_with, :order, :title, :updated_image, :url, :url_prefix

def initialize(new_options)
options = {:class => nil, :title => nil, :url_prefix => "", :order => 'updated_at DESC', :conditions => nil, :limit => 10, :created_image => "add.png", :updated_image => "edit.png"}
options.merge!(new_options).each { |key,value| eval("self.#{key} = value") }
# for nested_with, pass in the reverse order of ancestry e.g. [parent.parent_of_parent, parent]
def initialize(options={})
{
:class => nil,
:conditions => nil,
:created_image => "add.png",
:limit => 10,
:nested_with => [],
:order => 'updated_at DESC',
:title => nil,
:updated_image => "edit.png",
:url => nil,
:url_prefix => ""
}.merge(options).each { |key,value| self.instance_variable_set(:"@#{key}", value) }
end

# to use in a URL like edit_admin_group_individuals_url(record.group, record)
# which will help you if you're using nested routed.
def nesting(record_string="record")
self.nested_with.inject("") { |nest_chain, nesting| nest_chain << "#{record_string}.#{nesting}," }
end

def url_prefix
@url_prefix.blank? ? "" : "#{@url_prefix}_".gsub("__", "_")
"#{"#{@url_prefix}_".gsub("__", "_") if @url_prefix.present?}"
end

def url
"#{self.url_prefix}#{@url ||= "admin_#{self.class.name.underscore.downcase}_url"}"
end

end
end
end
54 changes: 29 additions & 25 deletions vendor/plugins/refinery/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ The Refinery generator is a standard Rails generator that functions just like th
To see how to use the generator run

ruby script/generate refinery

Usage instructions should appear.

## Example of Using the Generator

Let's say you have a client who has a range of products they want to show on their website. You've considered using a few pages to manage the products but you've decided it would be much nicer if there was a separate place that had forms dedicated to managing products.

First decide what fields they need to manage. In our case, the client is going to want to edit the title and description of each product. They would also like a little "facts panel" to show on the right of the page.
First decide what fields they need to manage. In our case, the client is going to want to edit the title and description of each product. They would also like a little "facts panel" to show on the right of the page.

So go to the root of your project and run

ruby script/generate refinery

This will output the help on how to use the generator. To generate the new section we want to manage products we run:

ruby script/generate refinery product title:string description:text facts:text

The generator will output a list of files it generated. You'll notice there is a new plugin that has been added in ``vendor/plugins/products``. This is where both the backend and front end files are held for this new products area.

A new database migration has been added to add the products table in so run:
Expand Down Expand Up @@ -90,7 +90,7 @@ This bit is important. It's where all the controllers are held to manage pages i
:order => "position ASC", :paging => false

end

This single controller allows us to create, read, update and delete pages in the backend. With a little bit of Refinery magic we utilise the [crudify mixin](http://github.com/resolve/refinerycms/blob/master/vendor/plugins/refinery/crud.md) which gives us all of these regular features out of the box.

How crudify works is an entire topic of it's own. Checkout the [crudify documentation](http://github.com/resolve/refinerycms/blob/master/vendor/plugins/refinery/crud.md) to get an insight into how that works.
Expand All @@ -112,31 +112,35 @@ This file runs when your site is started up. All is does is registers this plugi
plugin.description = "Manage content pages"
plugin.version = 1.0
plugin.menu_match = /admin\/((pages)|(page_dialogs)|(page_parts))$/
plugin.activity = {:class => Page,
:url_prefix => "edit_",
:title => "title",
:created_image => "page_add.png",
:updated_image => "page_edit.png"}
plugin.activity = {
:class => Page,
:url_prefix => "edit_",
:title => "title",
:created_image => "page_add.png",
:updated_image => "page_edit.png"
}
end

## Getting your Plugin to Report Activity in the Dashboard

Recent activity reporting is built right in, so all you need to do is follow the convention below and your plugin will start showing up in the recent activity list of the Dashboard.

In our example above we showed the use of ``plugin.activity`` for the pages plugin.

Refinery::Plugin.register do |plugin|
plugin.title = "Pages"
plugin.description = "Manage content pages"
plugin.version = 1.0
plugin.menu_match = /admin\/((pages)|(page_dialogs)|(page_parts))$/
plugin.activity = {:class => Page,
:url_prefix => "edit_",
:title => "title",
:created_image => "page_add.png",
:updated_image => "page_edit.png"}
plugin.activity = {
:class => Page,
:url_prefix => "edit_",
:title => "title",
:created_image => "page_add.png",
:updated_image => "page_edit.png"
}
end

Here's what the different activity options mean:

### Required
Expand All @@ -147,7 +151,7 @@ Here's what the different activity options mean:
:url_prefix
# Just use "_edit" if you're not sure how this works.
#
# When it says "'About Us' page was updated about 4 hours ago", the page title "About Us"
# When it says "'About Us' page was updated about 4 hours ago", the page title "About Us"
# is linked to that page in a way we specify. So by setting "_edit" as a :url_prefix what
# we're doing is making it link to the page that allows us to edit this page.
# So the next result is edit_admin_page_url(page)
Expand All @@ -159,8 +163,8 @@ Here's what the different activity options mean:
### Optional

:created_image and :updated_image
# the activity monitor knows if something is created or updated and shows a different icon
# depending on how you want that to look. You can specify the filename to any image you
# the activity monitor knows if something is created or updated and shows a different icon
# depending on how you want that to look. You can specify the filename to any image you
# want in the public/images/refinery/icons/ directory.

## Search Engine Optimisation: Improving the default URLs
Expand All @@ -170,14 +174,14 @@ In our example above we extended Refinery to manage a products area. The problem
To achieve this all you need to do is open up the product model (found in ``/vendor/plugins/products/app/models/product.rb``) and add the following line inside your class:

has_friendly_id :title, :use_slug => true

Note you want to change ``:title`` to the field which you want to show up in the URL.

This will work just fine for new products added from this point, but you'll want to migrate any existing products you have to use this new URL format. All you have to do is save each product you have in the database to make it create a nice URL for you.

ruby script/console
>> Product.all.each {|p| p.save };nil

Now all the products in your database will have nice URLs.

## How to get a WYSIWYG editor to show on your form fields
Expand All @@ -197,5 +201,5 @@ Again going back to our product plugin example if you had this in your ``vendor/
Just change that to:

<%= f.text_area :description, :class => "wymeditor" %>

Refresh and you're done.
8 changes: 7 additions & 1 deletion vendor/plugins/refinery_settings/rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
plugin.version = 1.0
plugin.url = "/admin/settings"
plugin.menu_match = /admin\/((refinery_settings)|(settings))$/
plugin.activity = {:class => RefinerySetting, :title => 'title', :url_prefix => 'edit', :created_image => "cog_add.png", :updated_image => "cog_edit.png"}
plugin.activity = {
:class => RefinerySetting,
:title => 'title',
:url_prefix => 'edit',
:created_image => "cog_add.png",
:updated_image => "cog_edit.png"
}
end
10 changes: 8 additions & 2 deletions vendor/plugins/resources/rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
plugin.title = "Resources"
plugin.description = "Upload and link to files"
plugin.version = 1.0
plugin.activity = {:class => Resource, :title => 'title', :url_prefix => 'edit', :created_image => "page_white_put.png", :updated_image => "page_white_edit.png"}
end
plugin.activity = {
:class => Resource,
:title => 'title',
:url_prefix => 'edit',
:created_image => "page_white_put.png",
:updated_image => "page_white_edit.png"
}
end
11 changes: 7 additions & 4 deletions vendor/plugins/themes/rails/init.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Refinery::Plugin.register do |plugin|

plugin.title = "Themes"
plugin.description = "Upload and manage themes"
plugin.version = 1.0
plugin.activity = {:class => Theme, :title => 'title', :url_prefix => 'edit',
:created_image => "layout_add.png", :updated_image => "layout_edit.png"}

plugin.activity = {
:class => Theme,
:title => 'title',
:url_prefix => 'edit',
:created_image => "layout_add.png",
:updated_image => "layout_edit.png"
}
end

0 comments on commit dbe1c81

Please sign in to comment.