From 6b1f4d1a7997ece6d2590f606d769168fdc83c07 Mon Sep 17 00:00:00 2001 From: simplefl 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 @@

<%= t('widget.schedule') %>

-
+
<% upcoming_matches.group_by{ |e| e.start.month }.each do |month, events| %> <% events.group_by { |e| e.start.day }.each do |day, day_events| %>
<%= day_events.first.start.strftime("%A, %e %B") %>
@@ -19,3 +19,24 @@
<% end %> +<% if upcoming_nsltv.size > 0 %> +
+

NSLTV

+ +
+ <% upcoming_nsltv.group_by{ |e| e.start.month }.each do |month, events| %> + <% events.group_by { |e| e.start.day }.each do |day, day_events| %> +
<%= day_events.first.start.strftime("%A, %e %B") %>
+ <% day_events.each do |event| %> +
+

+ <%= event.start.strftime("%H:%M %Z") %> + <%= event.formatted_summary.sub(nsltv_regex, '') %> +

+
+ <% end %> + <% end %> + <% end %> +
+
+<% end %>