Skip to content

Commit

Permalink
Use active_admin for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaiwarner committed Jul 10, 2012
1 parent 375282d commit fb7d919
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 1 deletion.
35 changes: 35 additions & 0 deletions Gemfile.lock
Expand Up @@ -14,6 +14,17 @@ GEM
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
activeadmin (0.4.4)
bourbon (>= 1.0.0)
devise (>= 1.1.2)
fastercsv
formtastic (~> 2.1.1)
inherited_resources (>= 1.3.1)
jquery-rails (>= 1.0.0)
kaminari (>= 0.13.0)
meta_search (>= 0.9.2)
rails (>= 3.0.0)
sass (>= 3.1.0)
activemodel (3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
Expand All @@ -33,6 +44,8 @@ GEM
sass
arel (3.0.2)
bcrypt-ruby (3.0.1)
bourbon (2.1.1)
sass (>= 3.1)
builder (3.0.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
Expand All @@ -49,21 +62,39 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
fastercsv (1.5.5)
formtastic (2.1.1)
actionpack (~> 3.0)
has_scope (0.5.1)
hike (1.2.1)
i18n (0.6.0)
inherited_resources (1.3.1)
has_scope (~> 0.5.0)
responders (~> 0.6)
journey (1.0.4)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.7.3)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
meta_search (1.1.3)
actionpack (~> 3.1)
activerecord (~> 3.1)
activesupport (~> 3.1)
polyamorous (~> 0.5.0)
mime-types (1.19)
multi_json (1.3.6)
orm_adapter (0.0.6)
pg (0.14.0)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand All @@ -90,6 +121,8 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
responders (0.9.1)
railties (~> 3.1)
sass (3.1.20)
sass-rails (3.2.5)
railties (~> 3.2.0)
Expand Down Expand Up @@ -119,10 +152,12 @@ PLATFORMS
ruby

DEPENDENCIES
activeadmin
anjlab-bootstrap-rails (>= 2.0)
coffee-rails (~> 3.2.1)
devise
jquery-rails
meta_search (>= 1.1.0.pre)
pg
rails (= 3.2.6)
sass-rails (~> 3.2.3)
Expand Down
44 changes: 44 additions & 0 deletions app/admin/dashboards.rb
@@ -0,0 +1,44 @@
ActiveAdmin::Dashboards.build do

# Define your dashboard sections here. Each block will be
# rendered on the dashboard in the context of the view. So just
# return the content which you would like to display.

# == Simple Dashboard Section
# Here is an example of a simple dashboard section
#
# section "Recent Posts" do
# ul do
# Post.recent(5).collect do |post|
# li link_to(post.title, admin_post_path(post))
# end
# end
# end

# == Render Partial Section
# The block is rendered within the context of the view, so you can
# easily render a partial rather than build content in ruby.
#
# section "Recent Posts" do
# div do
# render 'recent_posts' # => this will render /app/views/admin/dashboard/_recent_posts.html.erb
# end
# end

# == Section Ordering
# The dashboard sections are ordered by a given priority from top left to
# bottom right. The default priority is 10. By giving a section numerically lower
# priority it will be sorted higher. For example:
#
# section "Recent Posts", :priority => 10
# section "Recent User", :priority => 1
#
# Will render the "Recent Users" then the "Recent Posts" sections on the dashboard.

# == Conditionally Display
# Provide a method name or Proc object to conditionally render a section at run time.
#
# section "Membership Summary", :if => :memberships_enabled?
# section "Membership Summary", :if => Proc.new { current_admin_user.account.memberships.any? }

end
3 changes: 3 additions & 0 deletions app/admin/items.rb
@@ -0,0 +1,3 @@
ActiveAdmin.register Item do

end
3 changes: 3 additions & 0 deletions app/admin/member_types.rb
@@ -0,0 +1,3 @@
ActiveAdmin.register MemberType do

end
3 changes: 3 additions & 0 deletions app/admin/users.rb
@@ -0,0 +1,3 @@
ActiveAdmin.register User do

end
1 change: 1 addition & 0 deletions app/assets/javascripts/active_admin.js
@@ -0,0 +1 @@
//= require active_admin/base
6 changes: 6 additions & 0 deletions app/assets/stylesheets/active_admin.css.scss
@@ -0,0 +1,6 @@
// Active Admin CSS Styles
@import "active_admin/mixins";
@import "active_admin/base";

// To customize the Active Admin interfaces, add your
// styles here:
10 changes: 10 additions & 0 deletions app/models/admin_user.rb
@@ -0,0 +1,10 @@
class AdminUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
end
129 changes: 129 additions & 0 deletions config/initializers/active_admin.rb
@@ -0,0 +1,129 @@
ActiveAdmin.setup do |config|

# == Site Title
#
# Set the title that is displayed on the main layout
# for each of the active admin pages.
#
config.site_title = "Collector"

# Set the link url for the title. For example, to take
# users to your main site. Defaults to no link.
#
# config.site_title_link = "/"

# Set an optional image to be displayed for the header
# instead of a string (overrides :site_title)
#
# Note: Recommended image height is 21px to properly fit in the header
#
# config.site_title_image = "/images/logo.png"

# == Default Namespace
#
# Set the default namespace each administration resource
# will be added to.
#
# eg:
# config.default_namespace = :hello_world
#
# This will create resources in the HelloWorld module and
# will namespace routes to /hello_world/*
#
# To set no namespace by default, use:
# config.default_namespace = false
#
# Default:
# config.default_namespace = :admin
#
# You can customize the settings for each namespace by using
# a namespace block. For example, to change the site title
# within a namespace:
#
# config.namespace :admin do |admin|
# admin.site_title = "Custom Admin Title"
# end
#
# This will ONLY change the title for the admin section. Other
# namespaces will continue to use the main "site_title" configuration.

# == User Authentication
#
# Active Admin will automatically call an authentication
# method in a before filter of all controller actions to
# ensure that there is a currently logged in admin user.
#
# This setting changes the method which Active Admin calls
# within the controller.
config.authentication_method = :authenticate_admin_user!


# == Current User
#
# Active Admin will associate actions with the current
# user performing them.
#
# This setting changes the method which Active Admin calls
# to return the currently logged in user.
config.current_user_method = :current_admin_user


# == Logging Out
#
# Active Admin displays a logout link on each screen. These
# settings configure the location and method used for the link.
#
# This setting changes the path where the link points to. If it's
# a string, the strings is used as the path. If it's a Symbol, we
# will call the method to return the path.
#
# Default:
config.logout_link_path = :destroy_admin_user_session_path

# This setting changes the http method used when rendering the
# link. For example :get, :delete, :put, etc..
#
# Default:
# config.logout_link_method = :get


# == Admin Comments
#
# Admin comments allow you to add comments to any model for admin use.
# Admin comments are enabled by default.
#
# Default:
# config.allow_comments = true
#
# You can turn them on and off for any given namespace by using a
# namespace config block.
#
# Eg:
# config.namespace :without_comments do |without_comments|
# without_comments.allow_comments = false
# end


# == Controller Filters
#
# You can add before, after and around filters to all of your
# Active Admin resources from here.
#
# config.before_filter :do_something_awesome


# == Register Stylesheets & Javascripts
#
# We recommend using the built in Active Admin layout and loading
# up your own stylesheets / javascripts to customize the look
# and feel.
#
# To load a stylesheet:
# config.register_stylesheet 'my_stylesheet.css'
#
# You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
# config.register_stylesheet 'my_print_stylesheet.css', :media => :print
#
# To load a javascript file:
# config.register_javascript 'my_javascript.js'
end
4 changes: 4 additions & 0 deletions config/routes.rb
@@ -1,4 +1,8 @@
Collector::Application.routes.draw do
ActiveAdmin.routes(self)

devise_for :admin_users, ActiveAdmin::Devise.config

resources :items do
member do
put :check_in
Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20120709230406_create_admin_notes.rb
@@ -0,0 +1,17 @@
class CreateAdminNotes < ActiveRecord::Migration
def self.up
create_table :admin_notes do |t|
t.string :resource_id, :null => false
t.string :resource_type, :null => false
t.references :admin_user, :polymorphic => true
t.text :body
t.timestamps
end
add_index :admin_notes, [:resource_type, :resource_id]
add_index :admin_notes, [:admin_user_type, :admin_user_id]
end

def self.down
drop_table :admin_notes
end
end
25 changes: 25 additions & 0 deletions db/migrate/20120709230407_move_admin_notes_to_comments.rb
@@ -0,0 +1,25 @@
class MoveAdminNotesToComments < ActiveRecord::Migration
def self.up
remove_index :admin_notes, [:admin_user_type, :admin_user_id]
rename_table :admin_notes, :active_admin_comments
rename_column :active_admin_comments, :admin_user_type, :author_type
rename_column :active_admin_comments, :admin_user_id, :author_id
add_column :active_admin_comments, :namespace, :string
add_index :active_admin_comments, [:namespace]
add_index :active_admin_comments, [:author_type, :author_id]

# Update all the existing comments to the default namespace
say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
end

def self.down
remove_index :active_admin_comments, :column => [:author_type, :author_id]
remove_index :active_admin_comments, :column => [:namespace]
remove_column :active_admin_comments, :namespace
rename_column :active_admin_comments, :author_id, :admin_user_id
rename_column :active_admin_comments, :author_type, :admin_user_type
rename_table :active_admin_comments, :admin_notes
add_index :admin_notes, [:admin_user_type, :admin_user_id]
end
end

0 comments on commit fb7d919

Please sign in to comment.