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

Commit

Permalink
Browse files Browse the repository at this point in the history
added admin dashboard, api for adding boxes to the admin dashboard. A…
…dded recent comments dashboard box to the blog plugin, as a proof of concept.
  • Loading branch information
Josh Adams committed Jan 27, 2009
1 parent 5aa3349 commit 36e276d
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/controllers/admin/dashboards_controller.rb
@@ -0,0 +1,6 @@
class Admin::DashboardsController < Admin::BaseController
# NOTE: Can grab a user-specific settings collection here, or we could make it site-specific. Should be decided.

def show
end
end
2 changes: 0 additions & 2 deletions app/helpers/admin_helper.rb

This file was deleted.

37 changes: 37 additions & 0 deletions app/models/comment.rb
@@ -0,0 +1,37 @@
# This was copied from the acts_as_commentable plugin, and I'm changing it a bit - JA
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true

# NOTE: install the acts_as_votable plugin if you
# want user to vote on the quality of comments.
#acts_as_voteable

# NOTE: Comments belong to a user
belongs_to :user

named_scope :recent, :limit => 5, :order => "created_at DESC"

# Helper class method to lookup all comments assigned
# to all commentable types for a given user.
def self.find_comments_by_user(user)
find(:all,
:conditions => ["user_id = ?", user.id],
:order => "created_at DESC"
)
end

# Helper class method to look up all comments for
# commentable class name and commentable id.
def self.find_comments_for_commentable(commentable_str, commentable_id)
find(:all,
:conditions => ["commentable_type = ? and commentable_id = ?", commentable_str, commentable_id],
:order => "created_at DESC"
)
end

# Helper class method to look up a commentable object
# given the commentable class name and id
def self.find_commentable(commentable_str, commentable_id)
commentable_str.constantize.find(commentable_id)
end
end
7 changes: 7 additions & 0 deletions app/views/admin/dashboards/show.html.erb
@@ -0,0 +1,7 @@
<%= title "Dashboard" %>
<% Ansuz::PluginManagerInstance.admin_dashboard_boxes.each do |dashboard_box| %>
<% render :layout => 'shared/dashboard_box', :locals => { :title => dashboard_box[0] } do %>
<%= render :partial => dashboard_box[1] %>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions app/views/layouts/admin.html.erb
Expand Up @@ -19,6 +19,7 @@
<%= stylesheet_link_tag 'form-tables' %>
<%= stylesheet_link_tag 'acts_as_taggable_stylesheet' %>
<%= stylesheet_link_tag 'ui.tabs.css' %>
<%= stylesheet_link_tag 'comments' %>
<%= javascript_include_tag 'jquery' -%>
<%= javascript_tag "jQuery.noConflict();" -%>
<%= javascript_include_tag :defaults -%>
Expand Down
6 changes: 6 additions & 0 deletions app/views/shared/_dashboard_box.html.erb
@@ -0,0 +1,6 @@
<div class='dashboard_box'>
<h3><%= title -%></h3>
<div class='subdued contents'>
<%= yield -%>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -30,6 +30,7 @@
admin.resources :tags
admin.resources :roles
admin.resource :account
admin.resource :dashboard
admin.resource :site_settings, :collection => [:choose_theme]
admin.connect 'account/:action/:id', :controller => 'account'
end
Expand Down
10 changes: 9 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
attr_accessor :plugins, :plugin_nav, :admin_plugin_nav, :admin_menu, :admin_menu_top_level_entries, :page_types, :admin_dashboard_boxes
ADMIN_MENU_TOP_LEVEL_ENTRIES = ["Create", "Manage", "Ansuz"]

def initialize
Expand All @@ -11,6 +11,7 @@ def initialize
@admin_plugin_nav = []
@admin_menu = {}
@admin_menu_top_level_entries = ADMIN_MENU_TOP_LEVEL_ENTRIES.clone
@admin_dashboard_boxes = []
@page_types = []
setup_admin_menu
end
Expand All @@ -28,6 +29,13 @@ def register_plugin_nav title, link
self.plugin_nav << [title, link]
end

# A plugin can register a box to be shown in the admin dashboard
# The partial is expected to contain everything necessary to
# render the box.
def register_admin_dashboard_box title, partial_path
@admin_dashboard_boxes << [title, partial_path]
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
1 change: 1 addition & 0 deletions lib/ansuz/setup_admin_menu_entries.rb
Expand Up @@ -2,6 +2,7 @@

Ansuz::PluginManagerInstance.register_admin_menu_entry "Manage", 'Pages', '/admin/pages', :span_options => { :note => "This is where your site's primary content lives." }

Ansuz::PluginManagerInstance.register_admin_menu_entry "Ansuz", 'Dashboard', '/admin/dashboard', :span_options => { :note => "See what's happening on your site at a glance." }
Ansuz::PluginManagerInstance.register_admin_menu_entry "Ansuz", 'Site Settings', '/admin/site_settings', :span_options => { :note => "Change your site title, etc." }
Ansuz::PluginManagerInstance.register_admin_menu_entry "Ansuz", 'Choose a Theme', '/admin/site_settings/choose_theme', :span_options => { :note => "Easily change the look and feel of your site." }
Ansuz::PluginManagerInstance.register_admin_menu_entry "Ansuz", 'List Plugins', '/admin/plugins'
Expand Down
8 changes: 7 additions & 1 deletion public/stylesheets/admin.css
Expand Up @@ -475,4 +475,10 @@ table.tree tr.even:hover td {
}
table.tree tr.odd:hover td {
background-color:#ebebeb !important;
}
}

.dashboard_box h3{
background-color: #222;
color: white;
padding: 6px;
}
@@ -0,0 +1,5 @@
<div class='comments'>
<% Comment.recent.each do |comment| %>
<%= show_comment comment %>
<% end %>
</div>
3 changes: 3 additions & 0 deletions vendor/plugins/ansuz_blog/init.rb
Expand Up @@ -5,3 +5,6 @@

# Add a PagePlugin that will let you list recent posts
Ansuz::PluginManagerInstance.register_plugin(Ansuz::JAdams::Blog::RecentPostsWidget)

# 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')

0 comments on commit 36e276d

Please sign in to comment.