Commit 562d7cee

mo khan <mo@mokhan.ca>
2014-10-20 04:29:23
add charts to the admin section to analyze usage.
1 parent e25af8f
Changed files (8)
app/controllers/admin/charts_controller.rb
@@ -0,0 +1,6 @@
+module Admin
+  class ChartsController < AdminController
+    def index
+    end
+  end
+end
app/models/user.rb
@@ -41,7 +41,7 @@ class User < ActiveRecord::Base
   end
 
   def to_param
-    "#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
+    "#{id}-#{name.parameterize}"
   end
 
   def send_welcome_email
app/views/admin/charts/index.html.erb
@@ -0,0 +1,24 @@
+<div class="row-fluid">
+  <div class="span2">
+    <%= render partial: "my/shared/my_nav" %>
+  </div>
+  <div class="span10">
+    <h1>User Sessions <small>(<%= UserSession.count %>)</small></h1>
+    <%= line_chart UserSession.group_by_month(:created_at).count %>
+
+    <h1>Registrations <small>(<%= User.count %>)</small></h1>
+    <%= line_chart User.group_by_month(:created_at).count %>
+
+    <h1>Comments <small>(<%= Comment.count %>)</small></h1>
+    <%= line_chart Comment.group_by_month(:created_at).count %>
+
+    <h1>Favorites <small>(<%= Favorite.count %>)</small></h1>
+    <%= line_chart Favorite.group_by_month(:created_at).count %>
+
+    <h1>Photos <small>(<%= Photo.count %>)</small></h1>
+    <%= line_chart Photo.group_by_month(:created_at).count %>
+
+    <h1>Locations <small>(<%= Location.count %>)</small></h1>
+    <%= geo_chart Location.group(:country).count %>
+  </div>
+</div>
app/views/layouts/application.html.erb
@@ -22,6 +22,7 @@
 <%= favicon_link_tag 'apple-touch-icon-114x114.png', rel: 'apple-touch-icon', type: 'image/png', sizes: "114x114" %>
 <%= yield :head %>
 <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
+<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
 <!--[if lt IE 9]>
   <script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
 <![endif]-->
app/views/my/shared/_my_nav.html.erb
@@ -35,6 +35,7 @@
       <li><%= link_to "Blobs", admin_blobs_path %></li>
       <li><%= link_to "Sessions", admin_sessions_path %></li>
       <li><%= link_to "Products", admin_products_path %></li>
+      <li><%= link_to "Charts", admin_charts_path %></li>
     <% end %>
     <li class="nav-header">Other</li>
     <li><%= link_to t('.logout'), logout_path, method: :delete %></li>
config/routes.rb
@@ -80,6 +80,7 @@ Cake::Application.routes.draw do
     resources :errors, only: [:index, :create]
     resources :sessions, only: [:index, :destroy]
     resources :products, only: [:index, :show]
+    resources :charts, only: [:index]
   end
 
   namespace :my do
Gemfile
@@ -42,6 +42,8 @@ gem 'browser_sniffer'
 gem 'asin'
 gem 'curb'
 gem 'github-markdown'
+gem 'chartkick'
+gem 'groupdate'
 
 group :development do
   gem 'capistrano', '~> 3.0', require: false
Gemfile.lock
@@ -81,6 +81,7 @@ GEM
       rack (>= 1.0.0)
       rack-test (>= 0.5.4)
       xpath (~> 2.0)
+    chartkick (1.3.2)
     childprocess (0.5.3)
       ffi (~> 1.0, >= 1.0.11)
     cliver (0.3.2)
@@ -163,6 +164,8 @@ GEM
       httparty
       multi_json (>= 1.3.4)
     github-markdown (0.6.7)
+    groupdate (2.3.0)
+      activesupport (>= 3)
     hashie (2.0.5)
     hike (1.2.3)
     http (0.6.2)
@@ -365,6 +368,7 @@ DEPENDENCIES
   capistrano-rails (~> 1.1)
   capistrano-rbenv (~> 2.0)
   capybara
+  chartkick
   coffee-rails (~> 4.0)
   curb
   daemons (~> 1.1.9)
@@ -383,6 +387,7 @@ DEPENDENCIES
   geoip
   gibbon (~> 1.1.2)
   github-markdown
+  groupdate
   jbuilder (~> 2.0)
   jquery-rails
   jquery-ui-rails (~> 4.0.0)