From a3daad29171c7b1d8521d863ebb4afd995720a17 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 23 Sep 2015 09:10:07 +0200 Subject: [PATCH] Improved visualisation of errors. --- .../app/controllers/calendar.js.coffee | 3 +- .../javascripts/app/controllers/sla.js.coffee | 3 +- .../app/views/calendar/index.jst.eco | 1 + .../channel/email_account_overview.jst.eco | 10 ++-- app/models/calendar.rb | 53 ++++++++++++------- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/app/controllers/calendar.js.coffee b/app/assets/javascripts/app/controllers/calendar.js.coffee index 249556e6c..4d45c3d92 100644 --- a/app/assets/javascripts/app/controllers/calendar.js.coffee +++ b/app/assets/javascripts/app/controllers/calendar.js.coffee @@ -12,7 +12,8 @@ class Index extends App.ControllerContent # check authentication return if !@authenticate() - @load() + @interval(@load, 60000) + #@load() load: => @ajax( diff --git a/app/assets/javascripts/app/controllers/sla.js.coffee b/app/assets/javascripts/app/controllers/sla.js.coffee index d0997edc2..34fe33a0b 100644 --- a/app/assets/javascripts/app/controllers/sla.js.coffee +++ b/app/assets/javascripts/app/controllers/sla.js.coffee @@ -11,7 +11,8 @@ class Index extends App.ControllerContent # check authentication return if !@authenticate() - @load() + @interval(@load, 60000) + #@load() load: => @ajax( diff --git a/app/assets/javascripts/app/views/calendar/index.jst.eco b/app/assets/javascripts/app/views/calendar/index.jst.eco index 2556f9385..a22aa2311 100644 --- a/app/assets/javascripts/app/views/calendar/index.jst.eco +++ b/app/assets/javascripts/app/views/calendar/index.jst.eco @@ -31,6 +31,7 @@ <% end %> + <% if calendar.last_log: %>
<%= calendar.last_log %>
<% end %>
<%- @T('Timezone') %>
<%= calendar.timezone %>
diff --git a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco index 641f62d96..146a327af 100644 --- a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco +++ b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco @@ -52,8 +52,7 @@ <% if !_.isEmpty(channel.last_log_in): %> -
- <%- @T('Notice') %>:
+
<%= channel.last_log_in %>
<% end %> @@ -76,8 +75,7 @@ <%- @T('Protocol') %>: <%= channel.options.outbound.adapter %> <% if !_.isEmpty(channel.last_log_out): %> -
- <%- @T('Notice') %>:
+
<%= channel.last_log_out %>
<% end %> @@ -132,10 +130,10 @@ <% if channel.status_in is 'error': %> -
<%= channel.last_log_in %>
+
<%= channel.last_log_in %>
<% end %> <% if channel.status_out is 'error': %> -
<%= channel.last_log_out %>
+
<%= channel.last_log_out %>
<% end %>
diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 2c4df7dab..071b94f09 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -4,6 +4,8 @@ class Calendar < ApplicationModel store :business_hours store :public_holidays + before_create :fetch_ical + before_update :fetch_ical after_create :sync_default, :min_one_check after_update :sync_default, :min_one_check after_destroy :min_one_check @@ -207,37 +209,47 @@ returns =end - def sync + def sync(without_save = nil) return if !ical_url - events = Calendar.parse(ical_url) + begin + events = Calendar.parse(ical_url) - # sync with public_holidays - if !public_holidays - self.public_holidays = {} - end - events.each {|day, summary| - if !public_holidays[day] - public_holidays[day] = {} + # sync with public_holidays + if !public_holidays + self.public_holidays = {} end + events.each {|day, summary| + if !public_holidays[day] + public_holidays[day] = {} + end - # ignore if already added or changed - next if public_holidays[day].key?('active') + # ignore if already added or changed + next if public_holidays[day].key?('active') - # create new entry - public_holidays[day] = { - active: true, - summary: summary, + # create new entry + public_holidays[day] = { + active: true, + summary: summary, + } } - } - self.last_log = '' + self.last_log = nil + rescue => e + self.last_log = e.inspect + end + self.last_sync = Time.zone.now - save + if !without_save + save + end true end def self.parse(location) if location =~ /^http/i result = UserAgent.get(location) + if !result.success? + fail result.error + end cal_file = result.body else cal_file = File.open(location) @@ -298,4 +310,9 @@ returns end } end + + # fetch ical feed + def fetch_ical + sync(true) + end end