diff options
| author | mo k <mo@mokhan.ca> | 2012-02-29 20:50:23 -0700 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-02-29 20:50:23 -0700 |
| commit | 29fc85fbec3ca220d6dfaa38ea7e71c2c195ec7e (patch) | |
| tree | b7d73ed17100d7908cde9c662e1e8a7369de877c | |
| parent | d07feb75ec40f68a8b011d3a61195798c2d78cae (diff) | |
add active admin. go to http://??/admin/ username:admin@example.com password:password
| -rw-r--r-- | Gemfile | 3 | ||||
| -rw-r--r-- | Gemfile.lock | 28 | ||||
| -rw-r--r-- | app/admin/dashboards.rb | 38 | ||||
| -rw-r--r-- | app/assets/javascripts/active_admin.js | 1 | ||||
| -rw-r--r-- | app/assets/stylesheets/active_admin.css.scss | 6 | ||||
| -rw-r--r-- | app/models/admin_user.rb | 9 | ||||
| -rw-r--r-- | config/initializers/active_admin.rb | 103 | ||||
| -rw-r--r-- | config/routes.rb | 4 | ||||
| -rw-r--r-- | db/migrate/20120229204755_create_admin_notes.rb | 16 | ||||
| -rw-r--r-- | db/migrate/20120229204756_move_admin_notes_to_comments.rb | 25 | ||||
| -rw-r--r-- | db/migrate/20120301034745_devise_create_admin_users.rb | 28 | ||||
| -rw-r--r-- | db/schema.rb | 35 | ||||
| -rw-r--r-- | spec/models/admin_user_spec.rb | 5 |
13 files changed, 300 insertions, 1 deletions
@@ -15,6 +15,9 @@ gem 'kaminari' gem 'capistrano' gem 'capistrano-ext' gem 'exception_notification' +gem 'activeadmin' +gem 'sass-rails' +gem 'meta_search', '>= 1.1.0.pre' group :development, :test do gem 'webrat' diff --git a/Gemfile.lock b/Gemfile.lock index 05a1b866..0905a4e7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,6 +16,15 @@ GEM rack-mount (~> 0.8.2) rack-test (~> 0.6.1) sprockets (~> 2.1.0) + activeadmin (0.3.4) + devise (>= 1.1.2) + fastercsv + formtastic (< 2.0.0) + inherited_resources (< 1.3.0) + kaminari (>= 0.12.4) + meta_search (>= 0.9.2) + rails (>= 3.0.0) + sass (>= 3.1.0) activemodel (3.1.2) activesupport (= 3.1.2) builder (~> 3.0.0) @@ -81,6 +90,7 @@ GEM factory_girl_rails (1.3.0) factory_girl (~> 2.2.0) railties (>= 3.0.0) + fastercsv (1.5.4) ffi (1.0.11) fog (1.1.1) builder @@ -93,6 +103,10 @@ GEM nokogiri (~> 1.5.0) ruby-hmac formatador (0.2.1) + formtastic (1.2.4) + actionpack (>= 2.3.7) + activesupport (>= 2.3.7) + i18n (~> 0.4) growl (1.0.3) growl_notify (0.0.3) rb-appscript @@ -104,9 +118,13 @@ GEM multi_json (~> 1.0.3) guard-rspec (0.5.4) guard (>= 0.8.4) + has_scope (0.5.1) highline (1.6.8) hike (1.2.1) i18n (0.6.0) + inherited_resources (1.2.2) + has_scope (~> 0.5.0) + responders (~> 0.6.0) jasmine (1.1.2) jasmine-core (>= 1.1.0) rack (>= 1.1) @@ -124,6 +142,11 @@ GEM 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.17.2) multi_json (1.0.3) net-scp (1.0.4) @@ -136,6 +159,8 @@ GEM nokogiri (1.5.0) orm_adapter (0.0.5) pg (0.11.0) + polyamorous (0.5.0) + activerecord (~> 3.0) polyglot (0.3.3) rack (1.3.5) rack-cache (1.1) @@ -166,6 +191,7 @@ GEM rb-fsevent (0.4.3.1) rdoc (3.11) json (~> 1.4) + responders (0.6.5) riddle (1.5.0) rmagick (2.13.1) rspec (2.7.0) @@ -230,6 +256,7 @@ PLATFORMS DEPENDENCIES RedCloth + activeadmin bcrypt-ruby capistrano capistrano-ext @@ -248,6 +275,7 @@ DEPENDENCIES jquery-rails json kaminari + meta_search (>= 1.1.0.pre) pg rails rake diff --git a/app/admin/dashboards.rb b/app/admin/dashboards.rb new file mode 100644 index 00000000..cdf4c9c6 --- /dev/null +++ b/app/admin/dashboards.rb @@ -0,0 +1,38 @@ +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. + +end diff --git a/app/assets/javascripts/active_admin.js b/app/assets/javascripts/active_admin.js new file mode 100644 index 00000000..d2b66c59 --- /dev/null +++ b/app/assets/javascripts/active_admin.js @@ -0,0 +1 @@ +//= require active_admin/base diff --git a/app/assets/stylesheets/active_admin.css.scss b/app/assets/stylesheets/active_admin.css.scss new file mode 100644 index 00000000..9b2dc9d7 --- /dev/null +++ b/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: diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb new file mode 100644 index 00000000..039464fa --- /dev/null +++ b/app/models/admin_user.rb @@ -0,0 +1,9 @@ +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 +end diff --git a/config/initializers/active_admin.rb b/config/initializers/active_admin.rb new file mode 100644 index 00000000..c67771ad --- /dev/null +++ b/config/initializers/active_admin.rb @@ -0,0 +1,103 @@ +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 = "Cake" + + # Set the link url for the title. For example, to take + # users to your main site. Defaults to no link. + # + # config.site_title_link = "/" + + # == 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 + + # == 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 in the default + # namespace only. You can turn them on in a namesapce + # by adding them to the comments array. + # + # Default: + # config.allow_comments_in = [:admin] + + + # == 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' + # + # To load a javascript file: + # config.register_javascript 'my_javascript.js' +end diff --git a/config/routes.rb b/config/routes.rb index db86f8a5..b268a002 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,9 @@ Cake::Application.routes.draw do + ActiveAdmin.routes(self) + + devise_for :admin_users, ActiveAdmin::Devise.config + root :to => "creations#index" # /home diff --git a/db/migrate/20120229204755_create_admin_notes.rb b/db/migrate/20120229204755_create_admin_notes.rb new file mode 100644 index 00000000..a2d3247e --- /dev/null +++ b/db/migrate/20120229204755_create_admin_notes.rb @@ -0,0 +1,16 @@ +class CreateAdminNotes < ActiveRecord::Migration + def self.up + create_table :admin_notes do |t| + t.references :resource, :polymorphic => true, :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 diff --git a/db/migrate/20120229204756_move_admin_notes_to_comments.rb b/db/migrate/20120229204756_move_admin_notes_to_comments.rb new file mode 100644 index 00000000..296aa43f --- /dev/null +++ b/db/migrate/20120229204756_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 diff --git a/db/migrate/20120301034745_devise_create_admin_users.rb b/db/migrate/20120301034745_devise_create_admin_users.rb new file mode 100644 index 00000000..6730a47b --- /dev/null +++ b/db/migrate/20120301034745_devise_create_admin_users.rb @@ -0,0 +1,28 @@ +class DeviseCreateAdminUsers < ActiveRecord::Migration + def change + create_table(:admin_users) do |t| + t.database_authenticatable :null => false + t.recoverable + t.rememberable + t.trackable + + # t.encryptable + # t.confirmable + # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both + # t.token_authenticatable + + + t.timestamps + end + + # Create a default user + AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') + + add_index :admin_users, :email, :unique => true + add_index :admin_users, :reset_password_token, :unique => true + # add_index :admin_users, :confirmation_token, :unique => true + # add_index :admin_users, :unlock_token, :unique => true + # add_index :admin_users, :authentication_token, :unique => true + end + +end diff --git a/db/schema.rb b/db/schema.rb index 4212b150..49af2c03 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,40 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120130032306) do +ActiveRecord::Schema.define(:version => 20120301034745) do + + create_table "active_admin_comments", :force => true do |t| + t.integer "resource_id", :null => false + t.string "resource_type", :null => false + t.integer "author_id" + t.string "author_type" + t.text "body" + t.datetime "created_at" + t.datetime "updated_at" + t.string "namespace" + end + + add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id" + add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace" + add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id" + + create_table "admin_users", :force => true do |t| + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", :default => 0 + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true + add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true create_table "categories", :force => true do |t| t.string "name" diff --git a/spec/models/admin_user_spec.rb b/spec/models/admin_user_spec.rb new file mode 100644 index 00000000..3d153022 --- /dev/null +++ b/spec/models/admin_user_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe AdminUser do + pending "add some examples to (or delete) #{__FILE__}" +end |
