aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2008-03-14 11:08:41 +0000
committerfrancis <francis>2008-03-14 11:08:41 +0000
commit3b846c4414aa0e7bf3638b92fe0c6928a8b4c6f6 (patch)
treefd68afdcc167cd262a95ca868d1efdc9bbeada83
parent29bc26f5feddcd72cddc8d7b2fcb9e4eeba19736 (diff)
Overview admin page.
-rw-r--r--app/controllers/admin_controller.rb24
-rw-r--r--app/views/admin/index.rhtml64
-rw-r--r--app/views/layouts/admin.rhtml3
3 files changed, 87 insertions, 4 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 76fb8de07..4713af8a9 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -4,9 +4,29 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: admin_controller.rb,v 1.2 2007-10-31 17:25:29 francis Exp $
+# $Id: admin_controller.rb,v 1.3 2008-03-14 11:08:41 francis Exp $
class AdminController < ApplicationController
- layout "admin"
+ layout "admin"
+
+ def index
+ @user_count = User.count
+ @public_body_count = PublicBody.count
+ @info_request_count = InfoRequest.count
+
+ @events_title = "Events in last week"
+ date_back_to = Time.now - 1.week
+ if params[:month]
+ @events_title = "Events in last month"
+ date_back_to = Time.now - 1.month
+ end
+ if params[:all]
+ @events_title = "Events, all time"
+ date_back_to = Time.now - 1000.years
+ end
+
+ @events = InfoRequestEvent.find(:all, :order => "created_at desc, id desc",
+ :conditions => ["created_at > ? ", date_back_to])
+ end
end
diff --git a/app/views/admin/index.rhtml b/app/views/admin/index.rhtml
index 13cc52554..01ab163be 100644
--- a/app/views/admin/index.rhtml
+++ b/app/views/admin/index.rhtml
@@ -1,3 +1,65 @@
-<!-- nothing here yet, just show navigation -->
+<% @title = "Overview" %>
+<h1><%=@title%></h1>
+<ul>
+<li><%=@public_body_count%> public bodies</li>
+<li><%=@info_request_count%> requests</li>
+<li><%=@user_count%> users</li>
+</ul>
+
+<h2><%=h @events_title%></h2>
+<a href="?">Week</a>
+| <a href="?month=1">Month</a>
+| <a href="?all=1">All time</a>
+
+<% last_date = nil %>
+<% for event in @events %>
+ <% if last_date != event.created_at.to_date %>
+ <h2><%= simple_date(event.created_at) %></h2>
+ <% end %>
+ <% last_date = event.created_at.to_date %>
+
+ <p>
+ '<%= link_to h(event.info_request.title), 'request/show/' + event.info_request.id.to_s %>'
+ <% if event.event_type == 'edit' %>
+ was edited by administrator <%=h event.params[:editor] %>.
+ <% for p in ['title', 'prominence', 'described_state', 'awaiting_description']
+ if event.params[p.to_sym] != event.params[('old_'+p).to_sym]
+ %> Changed <%=p%> from '<%=h event.params[('old_'+p).to_sym]%>' to '<%=h event.params[p.to_sym] %>'. <%
+ end
+ end
+ %>
+ <% elsif event.event_type == 'edit_outgoing' %>
+ <% outgoing_messages = OutgoingMessage.find(:all, event.params[:outgoing_message_id].to_i) %>
+ had outgoing message edited by administrator <%=h event.params[:editor] %>.
+ <% if outgoing_messages.size > 0 %>
+ <% outgoing_message = outgoing_messages[0] %>
+ <% for p in ['body']
+ if event.params[p.to_sym] != event.params[('old_'+p).to_sym]
+ %> Changed <%=p%> from '<%=h event.params[('old_'+p).to_sym]%>' to '<%=h event.params[p.to_sym] %>'. <%
+ end
+ end
+ %>
+ <% else %>
+ Missing outgoing message, internal error.
+ <% end %>
+ <% elsif event.event_type == 'response' %>
+ <% incoming_message = IncomingMessage.find(event.params[:incoming_message_id]) %>
+ received
+ <%= link_to 'a response',
+ main_url(show_response_url(:id => incoming_message.info_request.id, :incoming_message_id => incoming_message.id)) %>
+
+ from <%=h event.info_request.public_body.name %>.
+ <% elsif event.event_type == 'sent' %>
+ was initially sent to <%=h event.params[:email]%> at <%=h event.info_request.public_body.name %>.
+ <% elsif event.event_type == 'resent' %>
+ had the request resent to <%=h event.params[:email]%> at <%=h event.info_request.public_body.name %>.
+ <% elsif event.event_type == 'followup_sent' %>
+ <% outgoing_messages = OutgoingMessage.find(:all, event.params[:outgoing_message_id].to_i) %>
+ had a follow up message sent to <%=h event.info_request.public_body.name %>.
+ <% else %>
+ had '<%=event.event_type%>' done to it, parameters <%=h event.params_yaml%>.
+ <% end %>
+ </p>
+<% end %>
diff --git a/app/views/layouts/admin.rhtml b/app/views/layouts/admin.rhtml
index d2fe60a44..1e6424b0f 100644
--- a/app/views/layouts/admin.rhtml
+++ b/app/views/layouts/admin.rhtml
@@ -11,7 +11,8 @@
<body>
<p><b>FOIFA admin interface:</b>
- <%= link_to 'Public bodies', admin_url('body/list') %>
+ <%= link_to 'Overview', admin_url('') %>
+ | <%= link_to 'Public bodies', admin_url('body/list') %>
| <%= link_to 'Requests', admin_url('request/list') %>
| <%= link_to 'Users', admin_url('user/list') %>
</p>