From 7240068463889ec07564cf29c6a0e4834c3da8a6 Mon Sep 17 00:00:00 2001
From: simplefl <phoenixfl@gmx.de>
Date: Sat, 18 Jul 2015 12:33:09 +0200
Subject: [PATCH] Display nsltv seperated in calender widget.

---
 app/helpers/application_helper.rb    | 20 +++++++++++++++++++-
 app/views/widgets/_calendar.html.erb | 23 ++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2c44635..fcf1e89 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -171,8 +171,26 @@ module ApplicationHelper
     end
   end
 
+  def nsltv_regex
+    /\[NSLTV\]/i
+  end
+
   def upcoming_matches
-    GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset).upcoming.sort_by do |event|
+    GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset).
+      upcoming.
+      find_all{|e|
+       not nsltv_regex =~ (e.summary)
+      }.sort_by do |event|
+      event.start
+    end
+  end
+
+  def upcoming_nsltv
+    GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset).
+      upcoming.
+      find_all{|e|
+       nsltv_regex =~ (e.summary)
+      }.sort_by do |event|
       event.start
     end
   end
diff --git a/app/views/widgets/_calendar.html.erb b/app/views/widgets/_calendar.html.erb
index ccb3094..9dc7fbd 100644
--- a/app/views/widgets/_calendar.html.erb
+++ b/app/views/widgets/_calendar.html.erb
@@ -2,7 +2,7 @@
   <div class="widget calendar">
     <h4><%= t('widget.schedule') %></h4>
 
-    <div class="widget-content-wrapper">      
+    <div class="widget-content-wrapper">
       <% upcoming_matches.group_by{ |e| e.start.month }.each do |month, events| %>
         <% events.group_by { |e| e.start.day }.each do |day, day_events| %>
           <div class="separator"><%= day_events.first.start.strftime("%A, %e %B") %></div>
@@ -19,3 +19,24 @@
     </div>
   </div>
 <% end %>
+<% if upcoming_nsltv.size > 0 %>
+  <div class="widget calendar">
+    <h4>NSLTV</h4>
+
+    <div class="widget-content-wrapper">
+      <% upcoming_nsltv.group_by{ |e| e.start.month }.each do |month, events| %>
+        <% events.group_by { |e| e.start.day }.each do |day, day_events| %>
+          <div class="separator"><%= day_events.first.start.strftime("%A, %e %B") %></div>
+            <% day_events.each do |event| %>
+              <div class="entry">
+                <p class="summary">
+                  <span class="time"><%= event.start.strftime("%H:%M %Z") %></span>
+                  <%= event.formatted_summary.sub(nsltv_regex, '') %>
+                </p>
+              </div>
+            <% end %>
+        <% end %>
+      <% end %>
+    </div>
+  </div>
+<% end %>