Commit a8715f59

mo khan <mo@mokhan.ca>
2014-09-08 04:17:42
tidy up the admin section.
1 parent 6c28cc6
Changed files (6)
app/controllers/admin/users_controller.rb
@@ -5,7 +5,7 @@ module Admin
     end
 
     def show
-      @user = User.find(params[:id])
+      @user = User.includes(creations: :photos).find(params[:id])
     end
   end
 end
app/models/user.rb
@@ -11,6 +11,7 @@ class User < ActiveRecord::Base
   has_many :tutorials, :dependent => :destroy
   has_many :activities, dependent: :destroy
   has_many :comments, dependent: :destroy
+  has_many :user_sessions, dependent: :destroy
   has_and_belongs_to_many :interests, :join_table => 'users_interests', :autosave => true
   has_one :avatar
   acts_as_tagger
app/views/admin/photos/index.html.erb
@@ -10,10 +10,8 @@
           <th>id</th>
           <th>processing</th>
           <th>filename</th>
-          <th>original</th>
           <th>content type</th>
           <th>geolocation</th>
-          <th>sha256</th>
           <th>created</th>
           <th>updated</th>
         </tr>
@@ -24,10 +22,8 @@
             <td><%= link_to photo.id, admin_photo_path(photo.id) %></td>
             <td><%= photo.image_processing %></td>
             <td><%= photo.image %></td>
-            <td><%= photo.original_filename %></td>
             <td><%= photo.content_type %></td>
             <td><%= photo.latitude %> <%= photo.longitude %></td>
-            <td><%= photo.sha256 %></td>
             <td><%= time_ago_in_words(photo.created_at) %> ago</td>
             <td><%= time_ago_in_words(photo.updated_at) %> ago</td>
           </tr>
app/views/admin/users/_index.html.erb
@@ -1,7 +1,6 @@
 <table class="table table-striped table-condensed">
   <thead>
     <tr>
-      <td>signins</td>
       <td>cakes</td>
       <td>name</td>
       <td>email</td>
@@ -14,7 +13,6 @@
   <tbody>
     <%- @users.each do |user| %>
       <tr>
-        <td><%= user.sign_in_count %></td>
         <td><%= user.creations_count %></td>
         <td><%= link_to user.name, admin_user_path(user) %></td>
         <td><%= mail_to user.email %></td>
app/views/admin/users/show.html.erb
@@ -17,15 +17,85 @@
     <%= render partial: "my/shared/my_nav" %>
   </div>
   <div class="span10">
-      <h1><%= @user.name %></h1>
-      <%= debug @user %>
-  </div>
-</div>
-<!--
-<div class="row-fluid">
-  <div style="overflow:hidden;height:500px;width:600px;">
-    <div id="map-canvas" style="height:500px;width:600px;"></div>
-    <style> img{max-width:none!important;background:none!important} </style>
+    <h1> <%= avatar_for(@user, size: 24) %> <%= @user.name %></h1>
+    <table class="table table-striped table-condensed">
+      <thead>
+        <tr>
+          <th>name</th>
+          <th>email</th>
+          <th>city</th>
+          <th>website</th>
+          <th>twitter</th>
+          <th>facebook</th>
+        </tr>
+      </thead>
+      <tbody>
+        <tr>
+          <td><%= link_to @user.name, admin_user_path(@user) %></td>
+          <td><%= mail_to @user.email %></td>
+          <td><%= @user.city %></td>
+          <td><%= link_to @user.website %></td>
+          <td><%= @user.twitter %></td>
+          <td><%= link_to @user.facebook %></td>
+        </tr>
+      </tbody>
+    </table>
+
+    <h2>sessions</h2>
+    <table class="table table-striped table-condensed">
+      <thead>
+        <tr>
+          <th>ip</th>
+          <th>user agent</th>
+          <th>accessed at</th>
+          <th>revoked at</th>
+          <th></th>
+        </tr>
+      </thead>
+      <tbody>
+        <%- @user.user_sessions.each do |user_session| %>
+          <tr>
+            <td><%= link_to user_session.user.name, admin_user_path(user_session.user) %></td>
+            <td><%= user_session.ip %></td>
+            <td><%= user_session.user_agent %></td>
+            <td><%= time_ago_in_words(user_session.accessed_at) %></td>
+            <td><%= time_ago_in_words(user_session.revoked_at) if user_session.revoked_at %></td>
+            <td><%= link_to "Revoke", admin_session_path(user_session), method: :delete, class: 'btn btn-danger' %></td>
+          </tr>
+        <% end %>
+      </tbody>
+    </table>
+
+    <h2>cakes</h2>
+    <table class="table table-striped">
+      <thead>
+        <th></th>
+        <th>Name</th>
+        <th>Description</th>
+      </thead>
+      <tbody>
+      <% @user.creations.each_with_index do |creation, index| %>
+        <% cache creation do %>
+        <tr>
+          <td>
+            <%= link_to creation_path(creation) do %>
+              <%= image_tag creation.primary_image.url_for(:thumb), class: 'thumbnail', style: "width:65px;" %>
+            <% end %>
+          </td>
+          <td><%= creation.name %></td>
+          <td>
+            <%= creation.story %>
+            <%= creation.tags.map(&:name) if creation.tags.any? %>
+          </td>
+        </tr>
+        <% end %>
+      <% end %>
+      </tbody>
+    </table>
+
+    <div style="overflow:hidden;height:500px;width:600px;">
+      <div id="map-canvas" style="height:500px;width:600px;"></div>
+      <style> img{max-width:none!important;background:none!important} </style>
+    </div>
   </div>
 </div>
--->
app/views/my/shared/_my_nav.html.erb
@@ -9,7 +9,7 @@
     <li id="cakes-tab" class="<%= "active" if controller?("cakes") %>"><%= link_to "Creations", my_root_path(anchor: 'cakes') %></li>
     <li id="tutorial-tab"><%= link_to "Tutorials", my_root_path(anchor: 'tutorials') %></li>
     -->
-    <li class="<%= "active" if controller?("favorites") %>"><%= link_to "<i class='fa fa-heart'></i> Favorites".html_safe, my_favorites_path %></li>
+    <li class="<%= "active" if controller?("favorites") %>"><%= link_to "<i class='fa fa-star'></i> Favorites".html_safe, my_favorites_path %></li>
     <li class="<%= 'active' if controller?('settings') %>"><%= link_to "<i class='fa fa-cog'></i> Settings".html_safe, my_settings_path %></li>
     <li class="<%= 'active' if controller?('passwords') %>"><%= link_to "<i class='fa fa-eye'></i> Password".html_safe, my_passwords_path %></li>
     <li class="<%= 'active' if controller?('avatars') %>"><%= link_to "<i class='fa fa-picture-o'></i> Picture".html_safe, edit_my_avatar_path(current_user) %></li>
@@ -26,11 +26,11 @@
     </li>
     <% if current_user.admin? %>
       <li class="nav-header">Admin</li>
-      <li><%= link_to "Users", admin_users_path %></li>
-      <li><%= link_to "Jobs", admin_jobs_path %></li>
-      <li><%= link_to "Activity", admin_activities_path %></li>
+      <li><%= link_to "<i class='fa fa-users'></i> Users".html_safe, admin_users_path %></li>
+      <li><%= link_to "<i class='fa fa-database'></i> Jobs".html_safe, admin_jobs_path %></li>
+      <li><%= link_to "<i class='fa fa-cubes'></i> Activity".html_safe, admin_activities_path %></li>
       <li><%= link_to "Subscriptions", admin_subscriptions_path %></li>
-      <li><%= link_to "Photos", admin_photos_path %></li>
+      <li><%= link_to "<i class='fa fa-photo'></i> Photos".html_safe, admin_photos_path %></li>
       <li><%= link_to "Blobs", admin_blobs_path %></li>
       <li><%= link_to "Sessions", admin_sessions_path %></li>
     <% end %>