From: Daniel Pittman <[email protected]>

Rather than displaying a single, giant list of delayed_job failures on this
page, we want to split it out into two lists: one unread, which is important,
and one read, which isn't so much.

This does the basic controller logic to support displaying those two pages,
fetching the right content from the database, paginating as appropriate, and
generally getting data to views in the right order.

Signed-off-by: Randall Hansen <[email protected]>
---
Local-branch: ticket/master/7967-delayed-job-warnings
 app/controllers/delayed_job_failures_controller.rb |   32 ++++++++++++++-----
 app/views/delayed_job_failures/index.html.haml     |    9 +++--
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/app/controllers/delayed_job_failures_controller.rb 
b/app/controllers/delayed_job_failures_controller.rb
index e121d9d..ca066dc 100644
--- a/app/controllers/delayed_job_failures_controller.rb
+++ b/app/controllers/delayed_job_failures_controller.rb
@@ -1,14 +1,7 @@
 class DelayedJobFailuresController < ApplicationController
   def index
-    respond_to do |format|
-      format.html do
-        @delayed_job_failures = paginate_scope(DelayedJobFailure.all(:order => 
'created_at DESC'))
-      end
-
-      format.all do
-        @delayed_job_failures = DelayedJobFailure.all(:order => 'created_at 
DESC')
-      end
-    end
+    @read = false
+    @delayed_job_failures = get_failures(@read)
 
     if params.has_key? :mark_all_read then
       DelayedJobFailure.transaction do
@@ -21,4 +14,25 @@ class DelayedJobFailuresController < ApplicationController
       end
     end
   end
+
+  def read
+    @read = true
+    @delayed_job_failures = get_failures(true)
+    render 'delayed_job_failures/index'
+  end
+
+  protected
+  def get_failures(read)
+    respond_to do |format|
+      format.html do
+        paginate_scope(DelayedJobFailure.all(:order => 'created_at DESC',
+                                             :conditions => { :read => read }))
+      end
+
+      format.all do
+        DelayedJobFailure.all(:order => 'created_at DESC',
+                              :conditions => { :read => read })
+      end
+    end
+  end
 end
diff --git a/app/views/delayed_job_failures/index.html.haml 
b/app/views/delayed_job_failures/index.html.haml
index cb1e0e6..847aa92 100644
--- a/app/views/delayed_job_failures/index.html.haml
+++ b/app/views/delayed_job_failures/index.html.haml
@@ -2,10 +2,11 @@
 #main
   .header
     %h2
-      Delayed Job Failures
-      %span.count= page_entries_info(@delayed_job_failures, { :entry_name => 
"failure" } )
-    - form_tag request.url, :class => 'REVISIT', :method => :post do
-      %button{:name => :mark_all_read} Mark all Read
+      &= "#{@read ? 'Read' : 'Unread'} Delayed Job Failures"
+      %span.count= page_entries_info(@delayed_job_failures, { :entry_name => 
"#{@read ? 'read' : 'unread'} failure" } )
+    - if @read == false
+      - form_tag request.url, :class => 'REVISIT', :method => :post do
+        %button{:name => :mark_all_read} Mark all Read
 
   .item
     %ul
-- 
1.7.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to