commit:     cd5e000195d4afaadaa227e9d6b92580d1573fed
Author:     Alex Legler <alex <AT> a3li <DOT> li>
AuthorDate: Thu Apr 17 16:41:16 2014 +0000
Commit:     Alex Legler <a3li <AT> gentoo <DOT> org>
CommitDate: Thu Apr 17 16:41:16 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/infra-status.git;a=commit;h=cd5e0001

Implement starts_at

start_at marks the date when an event (maintenance usually) described in the 
notice starts.
This is then the date when effects like force_state are applied.

---
 lib/helpers.rb      | 11 ++++++++++-
 lib/notice_store.rb | 20 +++++++++++++++++++-
 views/index.erb     |  2 +-
 views/layout.erb    |  4 ++++
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lib/helpers.rb b/lib/helpers.rb
index aaaf632..ec65b37 100644
--- a/lib/helpers.rb
+++ b/lib/helpers.rb
@@ -20,7 +20,7 @@ helpers do
 
   def service_info(service)
     content = ''
-    active_notices = NoticeStore.instance.active_notices_for(service)
+    active_notices = NoticeStore.instance.visible_notices_for(service)
 
     unless (forced_state = get_forced_state(active_notices)) == nil
       content << status_icon(forced_state)
@@ -87,4 +87,13 @@ helpers do
       date.rfc2822
     end
   end
+
+  def humanize(secs)
+    [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, 
name|
+      if secs > 0
+        secs, n = secs.divmod(count)
+        "#{n.to_i} #{name}" unless name == :seconds
+      end
+    }.compact.reverse.join(' ')
+  end
 end
\ No newline at end of file

diff --git a/lib/notice_store.rb b/lib/notice_store.rb
index 1d29fdd..c3c7093 100644
--- a/lib/notice_store.rb
+++ b/lib/notice_store.rb
@@ -34,11 +34,23 @@ class NoticeStore
     @notices
   end
 
+  def visible_notices
+    notices.select do |notice|
+      is_active = notice['active']
+      is_active &= notice['expire_at'] >= DateTime.now if notice.has_key? 
'expire_at'
+      is_active &= notice['created_at'] <= DateTime.now if notice.has_key? 
'created_at'
+
+      is_active
+    end
+
+  end
+
   def active_notices
     notices.select do |notice|
       is_active = notice['active']
       is_active &= notice['expire_at'] >= DateTime.now if notice.has_key? 
'expire_at'
       is_active &= notice['created_at'] <= DateTime.now if notice.has_key? 
'created_at'
+      is_active &= notice['starts_at'] <= DateTime.now if notice.has_key? 
'starts_at'
 
       is_active
     end
@@ -50,6 +62,12 @@ class NoticeStore
     end
   end
 
+  def visible_notices_for(service)
+    visible_notices.select do |notice|
+      notice.has_key? 'affects' and notice['affects'].include? service
+    end
+  end
+
   def notice(id)
     notices.each do |notice|
       return notice if notice['id'] == id
@@ -95,7 +113,7 @@ class Notice
   def initialize(id, metadata, content)
     @metadata = metadata
 
-    %w[created_at eta expire_at].each do |key|
+    %w[created_at eta expire_at starts_at].each do |key|
       @metadata[key] = DateTime.parse(@metadata[key]) if @metadata.has_key? key
     end
 

diff --git a/views/index.erb b/views/index.erb
index beea7c0..98869a2 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -94,4 +94,4 @@
 
 <h2>Maintenance and Outage Notices</h2>
 
-<%= partial :notice, :collection => NoticeStore.instance.active_notices %>
\ No newline at end of file
+<%= partial :notice, :collection => NoticeStore.instance.visible_notices %>
\ No newline at end of file

diff --git a/views/layout.erb b/views/layout.erb
index d43b914..c31a71a 100644
--- a/views/layout.erb
+++ b/views/layout.erb
@@ -122,6 +122,10 @@
     var d=document, g=d.createElement("script"), 
s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
     g.defer=true; g.async=true; g.src=u+"piwik.js"; 
s.parentNode.insertBefore(g,s);
   })();
+
+  jQuery(function($) {
+    $('.has-tooltip').tooltip()
+  });
 </script>
 </body>
 </html>

Reply via email to