Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
moved the ansuz setup stuff into ansuz/setup.rb (explained there), ad…
Browse files Browse the repository at this point in the history
…ded at_a_glance api and admin dashboard box
  • Loading branch information
Josh Adams committed Jan 27, 2009
1 parent 36e276d commit 4fe98fa
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/models/comment.rb
Expand Up @@ -10,6 +10,7 @@ class Comment < ActiveRecord::Base
belongs_to :user

named_scope :recent, :limit => 5, :order => "created_at DESC"
named_scope :for, lambda{ |klass| { :conditions => ["commentable_type = ?", klass] } }

# Helper class method to lookup all comments assigned
# to all commentable types for a given user.
Expand Down
8 changes: 8 additions & 0 deletions app/views/admin/default_dashboard_boxes/_at_a_glance.html.erb
@@ -0,0 +1,8 @@
<ul class='at-a-glance'>
<% Ansuz::PluginManagerInstance.at_a_glance_entries.each do |entry| %>
<li>
<em><%= entry[1].call %></em>
<%= entry[0] %>
</li>
<% end %>
</ul>
2 changes: 1 addition & 1 deletion config/environments/development.rb
Expand Up @@ -22,4 +22,4 @@
# FIXME: Once that bug is fixed this can all go away. -ja
# It has to be in every environment.
require 'isotope11/active_record_extensions'
require 'ansuz/setup_admin_menu_entries'
require 'ansuz/setup'
2 changes: 1 addition & 1 deletion config/environments/production.rb
Expand Up @@ -31,4 +31,4 @@
# FIXME: Once that bug is fixed this can all go away. -ja
# It has to be in every environment.
require 'isotope11/active_record_extensions'
require 'ansuz/setup_admin_menu_entries'
require 'ansuz/setup'
2 changes: 1 addition & 1 deletion config/environments/test.rb
Expand Up @@ -27,4 +27,4 @@
# FIXME: Once that bug is fixed this can all go away. -ja
# It has to be in every environment.
require 'isotope11/active_record_extensions'
require 'ansuz/setup_admin_menu_entries'
require 'ansuz/setup'
13 changes: 12 additions & 1 deletion lib/ansuz/plugin_manager.rb
Expand Up @@ -2,7 +2,7 @@
module Ansuz
class PluginManager
include Ansuz::PluginSettings
attr_accessor :plugins, :plugin_nav, :admin_plugin_nav, :admin_menu, :admin_menu_top_level_entries, :page_types, :admin_dashboard_boxes
attr_accessor :plugins, :plugin_nav, :admin_plugin_nav, :admin_menu, :admin_menu_top_level_entries, :page_types, :admin_dashboard_boxes, :at_a_glance_entries
ADMIN_MENU_TOP_LEVEL_ENTRIES = ["Create", "Manage", "Ansuz"]

def initialize
Expand All @@ -13,6 +13,7 @@ def initialize
@admin_menu_top_level_entries = ADMIN_MENU_TOP_LEVEL_ENTRIES.clone
@admin_dashboard_boxes = []
@page_types = []
@at_a_glance_entries = []
setup_admin_menu
end

Expand All @@ -36,6 +37,16 @@ def register_admin_dashboard_box title, partial_path
@admin_dashboard_boxes << [title, partial_path]
end

# At-a-Glance is a way to see what's going on in your website in one
# box on the admin dashboard. This method may be used to register a new
# statistic. You should call it with:
# register_at_a_glance_statistic "Posts" do
# Post.count
# end
def register_at_a_glance_statistic title, &block
@at_a_glance_entries << [title, block]
end

# Plugins may have external gem depdencies, such as ansuz_content_section (RedCloth/BlueCloth)
# The arguments are the same as the gem examples in config/environment.rb
def add_gem_dependency(name, options = {})
Expand Down
7 changes: 7 additions & 0 deletions lib/ansuz/setup.rb
@@ -0,0 +1,7 @@
# This is loaded in the context of each environment's config/environments/#{environment}.rb.
# It's kind of an integral part of an appropriate rails tie-in like ansuz is, as far as I can tell.
#
# - JA

require 'ansuz/setup_admin_menu_entries'
require 'ansuz/setup_default_admin_dashboard_boxes'
10 changes: 10 additions & 0 deletions lib/ansuz/setup_default_admin_dashboard_boxes.rb
@@ -0,0 +1,10 @@
# Add a box to the admin dashboard to see site stats at a glance
Ansuz::PluginManagerInstance.register_admin_dashboard_box("At a Glance", 'admin/default_dashboard_boxes/at_a_glance')

# Register an At-a-Glance entry for number of pages, page comments.
Ansuz::PluginManagerInstance.register_at_a_glance_statistic "Pages" do
Page.count
end
Ansuz::PluginManagerInstance.register_at_a_glance_statistic "Page Comments" do
Comment.for("Page").count
end
3 changes: 3 additions & 0 deletions public/stylesheets/admin.css
Expand Up @@ -477,6 +477,9 @@ table.tree tr.odd:hover td {
background-color:#ebebeb !important;
}

.dashboard_box{
margin-bottom: 10px;
}
.dashboard_box h3{
background-color: #222;
color: white;
Expand Down
8 changes: 8 additions & 0 deletions vendor/plugins/ansuz_blog/init.rb
Expand Up @@ -8,3 +8,11 @@

# Add a box to the admin dashboard to see most recent comments
Ansuz::PluginManagerInstance.register_admin_dashboard_box("Recent Comments", 'articles/recent_comments_admin_dashboard_box')

# Add a statistic to the admin "At a Glance" box for Comments, Posts
Ansuz::PluginManagerInstance.register_at_a_glance_statistic "Blog Posts" do
Ansuz::JAdams::BlogPost.count
end
Ansuz::PluginManagerInstance.register_at_a_glance_statistic "Blog Comments" do
Comment.for("Ansuz::JAdams::BlogPost").count
end

0 comments on commit 4fe98fa

Please sign in to comment.