diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb new file mode 100644 index 0000000..bef3f5c --- /dev/null +++ b/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 diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb deleted file mode 100644 index d5c6d35..0000000 --- a/app/helpers/admin_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module AdminHelper -end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..3100ce8 --- /dev/null +++ b/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 diff --git a/app/views/admin/dashboards/show.html.erb b/app/views/admin/dashboards/show.html.erb new file mode 100644 index 0000000..e4e3f39 --- /dev/null +++ b/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 %> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 56464e9..5c3a193 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -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 -%> diff --git a/app/views/shared/_dashboard_box.html.erb b/app/views/shared/_dashboard_box.html.erb new file mode 100644 index 0000000..129afca --- /dev/null +++ b/app/views/shared/_dashboard_box.html.erb @@ -0,0 +1,6 @@ +
+

<%= title -%>

+
+ <%= yield -%> +
+
diff --git a/config/routes.rb b/config/routes.rb index 46c449f..bf9679c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/ansuz/plugin_manager.rb b/lib/ansuz/plugin_manager.rb index 2f29342..9047478 100644 --- a/lib/ansuz/plugin_manager.rb +++ b/lib/ansuz/plugin_manager.rb @@ -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 @@ -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 @@ -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 = {}) diff --git a/lib/ansuz/setup_admin_menu_entries.rb b/lib/ansuz/setup_admin_menu_entries.rb index 75590d1..ec3f859 100644 --- a/lib/ansuz/setup_admin_menu_entries.rb +++ b/lib/ansuz/setup_admin_menu_entries.rb @@ -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' diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index 75ae8ad..11fd0bc 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css @@ -475,4 +475,10 @@ table.tree tr.even:hover td { } table.tree tr.odd:hover td { background-color:#ebebeb !important; -} \ No newline at end of file +} + +.dashboard_box h3{ + background-color: #222; + color: white; + padding: 6px; +} diff --git a/vendor/plugins/ansuz_blog/app/views/articles/_recent_comments_admin_dashboard_box.html.erb b/vendor/plugins/ansuz_blog/app/views/articles/_recent_comments_admin_dashboard_box.html.erb new file mode 100644 index 0000000..f190a39 --- /dev/null +++ b/vendor/plugins/ansuz_blog/app/views/articles/_recent_comments_admin_dashboard_box.html.erb @@ -0,0 +1,5 @@ +
+ <% Comment.recent.each do |comment| %> + <%= show_comment comment %> + <% end %> +
diff --git a/vendor/plugins/ansuz_blog/init.rb b/vendor/plugins/ansuz_blog/init.rb index c67ab8a..8fc9980 100644 --- a/vendor/plugins/ansuz_blog/init.rb +++ b/vendor/plugins/ansuz_blog/init.rb @@ -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')