Permalink
Browse files

Added actions and views for subscriber index and list.

  • Loading branch information...
1 parent cb1ac6e commit 6bd82831193d11a86b7afdebd24f5ec584026570 @nelstrom committed Jun 15, 2008
@@ -2,7 +2,13 @@ class SubscribersController < ApplicationController
def index
- @hello = "World"
+ @lists = Page.find_all_by_class_name("SubscriberListPage")
+ end
+
+ def list
+ @list = Page.find(params[:id])
+ @subscribers = Subscriber.find_active_subscribers_by_subscriber_list(@list)
+ @unsubscribers = Subscriber.find_unsubscribers_by_subscriber_list(@list)
end
end
View
@@ -16,13 +16,21 @@ def find_active_subscribers
find(:all, :conditions => ["unsubscribed_at IS ?", nil])
end
- def count_active_subscribers
- count(:conditions => ["unsubscribed_at IS ?", nil])
+ def count_active_subscribers(subscriber_list)
+ count(:conditions => ["unsubscribed_at IS ? AND subscriber_list_id = ?", nil, subscriber_list.id])
end
def find_active_subscribers_by_subscriber_list(subscriber_list)
- find(:all, :conditions => ["unsubscribed_at IS ? AND subscriber_list_id = ?", nil, subscriber_list.id])
- end
+ find(:all,
+ :conditions => ["unsubscribed_at IS ? AND subscriber_list_id = ?", nil, subscriber_list.id],
+ :order => "subscribed_at DESC")
+ end
+
+ def find_unsubscribers_by_subscriber_list(subscriber_list)
+ find(:all,
+ :conditions => ["unsubscribed_at IS NOT ? AND subscriber_list_id = ?", nil, subscriber_list.id],
+ :order => "unsubscribed_at DESC")
+ end
end
-end
+end
@@ -1,3 +1,18 @@
<h1>Subscribers</h1>
-Hello <%= @hello %>
+<table>
+ <thead>
+ <th>Subscriber List</th>
+ <th>No. of Subscribers</th>
+ </thead>
+
+<tbody>
+<% @lists.each do |list| %>
+ <tr>
+ <td><a href="<%= url_for :action => "list", :id => list.id %>"><span class="title"><%= list.title %></span></a></td>
+ <td><%= Subscriber.count_active_subscribers(list) %></td>
+ <td><%= link_to "Edit page", page_edit_path(:id => list.id) %></td>
+ </tr>
+<%- end -%>
+</tbody>
+</table>
@@ -0,0 +1,44 @@
+<h1><%= @list.title %></h1>
+<p>Back to <%= link_to "subscriber lists", :action => "index" %></p>
+<p><%= link_to "Edit", page_edit_path(:id => @list.id) %> the page for this subscriber list</p>
+
+<% if @subscribers and !@subscribers.empty? %>
+<h2>Subscribers</h2>
+<table>
+ <tr>
+ <th>email</th>
+ <th>name</th>
+ <th>Subscribed on</th>
+ </tr>
+ <%- @subscribers.each do |subscriber| -%>
+ <tr>
+ <td><%= subscriber.email %></td>
+ <td><%= subscriber.name.blank? ? "-" : subscriber.name %></td>
+ <td><%= subscriber.subscribed_at.strftime("%d %b, %Y") %></td>
+ </tr>
+ <%- end -%>
+</table>
+<%- else -%>
+<p>This list has no subscribers at present.</p>
+<%- end -%>
+
+
+<% if @unsubscribers and !@unsubscribers.empty? %>
+<h2>Cancelled subscriptions</h2>
+The following people have cancelled their subscription to this list.
+<table>
+ <tr>
+ <th>email</th>
+ <th>name</th>
+ <th>Cancelled on</th>
+ </tr>
+ <%- @unsubscribers.each do |unsubscriber| -%>
+ <tr>
+ <td><%= unsubscriber.email %></td>
+ <td><%= unsubscriber.name.blank? ? "-" : unsubscriber.name %></td>
+ <td><%= unsubscriber.subscribed_at.strftime("%d %b, %Y") %></td>
+ </tr>
+ <%- end -%>
+</table>
+<%- end -%>
+
@@ -8,6 +8,7 @@ class SubscriberListsExtension < Radiant::Extension
define_routes do |map|
map.connect 'admin/subscribers/:action', :controller => 'subscribers'
+ map.connect 'admin/subscribers/:action/:id', :controller => 'subscribers'
end
def activate

0 comments on commit 6bd8283

Please sign in to comment.