Commit a798684

mo khan <mo@mokhan.ca>
2013-06-23 02:24:29
add active admin
1 parent 93a4c2a
app/admin/admin_user.rb
@@ -0,0 +1,20 @@
+ActiveAdmin.register AdminUser do     
+  index do                            
+    column :email                     
+    column :current_sign_in_at        
+    column :last_sign_in_at           
+    column :sign_in_count             
+    default_actions                   
+  end                                 
+
+  filter :email                       
+
+  form do |f|                         
+    f.inputs "Admin Details" do       
+      f.input :email                  
+      f.input :password               
+      f.input :password_confirmation  
+    end                               
+    f.actions                         
+  end                                 
+end                                   
app/admin/dashboard.rb
@@ -0,0 +1,33 @@
+ActiveAdmin.register_page "Dashboard" do
+
+  menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
+
+  content :title => proc{ I18n.t("active_admin.dashboard") } do
+    div :class => "blank_slate_container", :id => "dashboard_default_message" do
+      span :class => "blank_slate" do
+        span I18n.t("active_admin.dashboard_welcome.welcome")
+        small I18n.t("active_admin.dashboard_welcome.call_to_action")
+      end
+    end
+
+    # Here is an example of a simple dashboard with columns and panels.
+    #
+    # columns do
+    #   column do
+    #     panel "Recent Posts" do
+    #       ul do
+    #         Post.recent(5).map do |post|
+    #           li link_to(post.title, admin_post_path(post))
+    #         end
+    #       end
+    #     end
+    #   end
+
+    #   column do
+    #     panel "Info" do
+    #       para "Welcome to ActiveAdmin."
+    #     end
+    #   end
+    # end
+  end # content
+end
app/admin/neighbourhoods.rb
@@ -0,0 +1,3 @@
+ActiveAdmin.register Neighbourhood do
+  
+end
app/assets/javascripts/active_admin.js
@@ -0,0 +1,1 @@
+//= require active_admin/base
app/assets/javascripts/application.js
@@ -11,7 +11,7 @@
 // GO AFTER THE REQUIRES BELOW.
 //
 //= require jquery
-//= require jquery.ui.all
+//= require jquery-ui
 //= require jquery_ujs
 //= require tag-it
 //= require bootstrap
app/assets/stylesheets/active_admin.css.scss
@@ -0,0 +1,29 @@
+// SASS variable overrides must be declared before loading up Active Admin's styles.
+//
+// To view the variables that Active Admin provides, take a look at
+// `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
+// Active Admin source.
+//
+// For example, to change the sidebar width:
+// $sidebar-width: 242px;
+
+// Active Admin's got SASS!
+@import "active_admin/mixins";
+@import "active_admin/base";
+
+// Overriding any non-variable SASS must be done after the fact.
+// For example, to change the default status-tag color:
+//
+//   body.active_admin {
+//      .status_tag { background: #6090DB; }
+//   }
+//
+// Notice that Active Admin CSS rules are nested within a
+// 'body.active_admin' selector to prevent conflicts with
+// other pages in the app. It is best to wrap your changes in a 
+// namespace so they are properly recognized. You have options
+// if you e.g. want different styles for different namespaces:
+//
+// .active_admin       applies to any Active Admin namespace
+// .admin_namespace    applies to the admin namespace (eg: /admin)
+// .other_namespace    applies to a custom namespace named other (eg: /other)
app/models/admin_user.rb
@@ -0,0 +1,11 @@
+class AdminUser < ActiveRecord::Base
+  # Include default devise modules. Others available are:
+  # :token_authenticatable, :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
config/initializers/active_admin.rb
@@ -0,0 +1,210 @@
+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 = "Yycrebuild"
+
+  # 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
+
+  # == Root
+  #
+  # Set the action to call for the root path. You can set different
+  # roots for each namespace.
+  #
+  # Default:
+  # config.root_to = 'dashboard#index'
+
+  # == 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
+
+
+  # == Batch Actions
+  #
+  # Enable and disable Batch Actions
+  #
+  config.batch_actions = true
+
+
+  # == Controller Filters
+  #
+  # You can add before, after and around filters to all of your
+  # Active Admin resources and pages 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'
+
+
+  # == CSV options
+  #
+  # Set the CSV builder separator (default is ",")
+  # config.csv_column_separator = ','
+  #
+  # Set the CSV builder options (default is {})
+  # config.csv_options = {}
+
+
+  # == Menu System
+  #
+  # You can add a navigation menu to be used in your application, or configure a provided menu
+  # 
+  # To change the default utility navigation to show a link to your website & a logout btn
+  # 
+  #   config.namespace :admin do |admin|
+  #     admin.build_menu :utility_navigation do |menu|
+  #       menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
+  #       admin.add_logout_button_to_menu menu
+  #     end
+  #   end
+  #
+  # If you wanted to add a static menu item to the default menu provided:
+  #
+  #   config.namespace :admin do |admin|
+  #     admin.build_menu :default do |menu|
+  #       menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
+  #     end
+  #   end
+
+  # == Download Links
+  #
+  # You can disable download links on resource listing pages,
+  # or customize the formats shown per namespace/globally
+  #
+  # To disable/customize for the :admin namespace:
+  #
+  #   config.namespace :admin do |admin|
+  #
+  #     # Disable the links entirely
+  #     admin.download_links = false
+  #
+  #     # Only show XML & PDF options
+  #     admin.download_links = [:xml, :pdf]
+  #
+  #   end
+
+
+  # == Pagination
+  #
+  # Pagination is enabled by default for all resources.
+  # You can control the default per page count for all resources here.
+  #
+  # config.default_per_page = 30
+
+
+  # == Filters
+  #
+  # By default the index screen includes a “Filters” sidebar on the right 
+  # hand side with a filter for each attribute of the registered model.
+  # You can enable or disable them for all resources here.
+  #
+  # config.filters = true
+
+
+end
config/routes.rb
@@ -1,7 +1,11 @@
 Yycrebuild::Application.routes.draw do
+  root :to => 'needs#index'
+  devise_for :admin_users, ActiveAdmin::Devise.config
+  ActiveAdmin.routes(self)
+
   devise_for :users
+  ActiveAdmin.routes(self)
 
   resources :needs
   resources :neighbourhoods
-  root :to => 'needs#index'
 end
db/migrate/20130623021544_devise_create_admin_users.rb
@@ -0,0 +1,52 @@
+class DeviseCreateAdminUsers < ActiveRecord::Migration
+  def migrate(direction)
+    super
+    # Create a default user
+    AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') if direction == :up
+  end
+
+  def change
+    create_table(:admin_users) do |t|
+      ## Database authenticatable
+      t.string :email,              :null => false, :default => ""
+      t.string :encrypted_password, :null => false, :default => ""
+
+      ## Recoverable
+      t.string   :reset_password_token
+      t.datetime :reset_password_sent_at
+
+      ## Rememberable
+      t.datetime :remember_created_at
+
+      ## Trackable
+      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
+
+      ## Confirmable
+      # t.string   :confirmation_token
+      # t.datetime :confirmed_at
+      # t.datetime :confirmation_sent_at
+      # t.string   :unconfirmed_email # Only if using reconfirmable
+
+      ## Lockable
+      # t.integer  :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
+      # t.string   :unlock_token # Only if unlock strategy is :email or :both
+      # t.datetime :locked_at
+
+      ## Token authenticatable
+      # t.string :authentication_token
+
+
+      t.timestamps
+    end
+
+    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
db/migrate/20130623021547_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
db/migrate/20130623021548_move_admin_notes_to_comments.rb
@@ -0,0 +1,26 @@
+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."
+    comments_table_name = ActiveRecord::Migrator.proper_table_name("active_admin_comments")
+    execute "UPDATE #{comments_table_name} 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
db/schema.rb
@@ -11,7 +11,40 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130623015151) do
+ActiveRecord::Schema.define(:version => 20130623021548) do
+
+  create_table "active_admin_comments", :force => true do |t|
+    t.string   "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",    :null => false
+    t.datetime "updated_at",    :null => false
+    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",     :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",                             :null => false
+    t.datetime "updated_at",                             :null => false
+  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 "needs", :force => true do |t|
     t.text     "description"
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
Gemfile
@@ -1,11 +1,11 @@
 source 'https://rubygems.org'
 gem 'rails', '3.2.13'
-gem 'jquery-rails'
-gem 'jquery-ui-rails'
+gem "jquery-rails", "2.3.0"
 gem 'devise'
 gem 'bootstrap-sass'
 gem 'acts-as-taggable-on'
 gem 'rest-client'
+gem 'activeadmin'
 
 group :development, :test do
   gem 'sqlite3'
Gemfile.lock
@@ -14,6 +14,18 @@ GEM
       rack-cache (~> 1.2)
       rack-test (~> 0.6.1)
       sprockets (~> 2.2.1)
+    activeadmin (0.6.0)
+      arbre (>= 1.0.1)
+      bourbon (>= 1.0.0)
+      devise (>= 1.1.2)
+      fastercsv
+      formtastic (>= 2.0.0)
+      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.13)
       activesupport (= 3.2.13)
       builder (~> 3.0.0)
@@ -30,6 +42,8 @@ GEM
       multi_json (~> 1.0)
     acts-as-taggable-on (2.4.1)
       rails (>= 3, < 5)
+    arbre (1.0.1)
+      activesupport (>= 3.0.0)
     arel (3.0.2)
     asset_sync (0.5.4)
       activemodel
@@ -37,6 +51,9 @@ GEM
     bcrypt-ruby (3.0.1)
     bootstrap-sass (2.3.2.0)
       sass (~> 3.2)
+    bourbon (3.1.8)
+      sass (>= 3.2.0)
+      thor
     builder (3.0.4)
     coffee-rails (3.2.2)
       coffee-script (>= 2.2.0)
@@ -58,6 +75,7 @@ GEM
     excon (0.23.0)
     execjs (1.4.0)
       multi_json (~> 1.0)
+    fastercsv (1.5.5)
     fog (1.12.1)
       builder
       excon (~> 0.23.0)
@@ -69,20 +87,31 @@ GEM
       nokogiri (~> 1.5.0)
       ruby-hmac
     formatador (0.2.4)
+    formtastic (2.2.1)
+      actionpack (>= 3.0)
+    has_scope (0.5.1)
     hike (1.2.3)
     i18n (0.6.1)
+    inherited_resources (1.4.0)
+      has_scope (~> 0.5.0)
+      responders (~> 0.9)
     journey (1.0.4)
-    jquery-rails (3.0.1)
+    jquery-rails (2.3.0)
       railties (>= 3.0, < 5.0)
       thor (>= 0.14, < 2.0)
-    jquery-ui-rails (4.0.3)
-      jquery-rails
-      railties (>= 3.1.0)
     json (1.8.0)
+    kaminari (0.14.1)
+      actionpack (>= 3.0.0)
+      activesupport (>= 3.0.0)
     kgio (2.8.0)
     mail (2.5.4)
       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.23)
     multi_json (1.7.7)
     net-scp (1.1.1)
@@ -91,6 +120,8 @@ GEM
     nokogiri (1.5.10)
     orm_adapter (0.4.0)
     pg (0.15.1)
+    polyamorous (0.5.0)
+      activerecord (~> 3.0)
     polyglot (0.3.3)
     rack (1.4.5)
     rack-cache (1.2)
@@ -118,6 +149,8 @@ GEM
     rake (10.1.0)
     rdoc (3.12.2)
       json (~> 1.4)
+    responders (0.9.3)
+      railties (~> 3.1)
     rest-client (1.6.7)
       mime-types (>= 1.16)
     rspec-core (2.13.1)
@@ -163,14 +196,14 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
+  activeadmin
   acts-as-taggable-on
   asset_sync
   bootstrap-sass
   coffee-rails (~> 3.2.1)
   devise
   dotenv-rails
-  jquery-rails
-  jquery-ui-rails
+  jquery-rails (= 2.3.0)
   pg
   rails (= 3.2.13)
   rest-client