Improved visualisation of errors.
This commit is contained in:
parent
8ff2318539
commit
a3daad2917
5 changed files with 44 additions and 26 deletions
|
@ -12,7 +12,8 @@ class Index extends App.ControllerContent
|
||||||
# check authentication
|
# check authentication
|
||||||
return if !@authenticate()
|
return if !@authenticate()
|
||||||
|
|
||||||
@load()
|
@interval(@load, 60000)
|
||||||
|
#@load()
|
||||||
|
|
||||||
load: =>
|
load: =>
|
||||||
@ajax(
|
@ajax(
|
||||||
|
|
|
@ -11,7 +11,8 @@ class Index extends App.ControllerContent
|
||||||
# check authentication
|
# check authentication
|
||||||
return if !@authenticate()
|
return if !@authenticate()
|
||||||
|
|
||||||
@load()
|
@interval(@load, 60000)
|
||||||
|
#@load()
|
||||||
|
|
||||||
load: =>
|
load: =>
|
||||||
@ajax(
|
@ajax(
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<% if calendar.last_log: %><div class="action-row"><div class="alert alert--danger"><%= calendar.last_log %></div></div><% end %>
|
||||||
<div class="action-row">
|
<div class="action-row">
|
||||||
<div class="label"><%- @T('Timezone') %></div> <%= calendar.timezone %>
|
<div class="label"><%- @T('Timezone') %></div> <%= calendar.timezone %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -52,8 +52,7 @@
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<% if !_.isEmpty(channel.last_log_in): %>
|
<% if !_.isEmpty(channel.last_log_in): %>
|
||||||
<div>
|
<div class="alert alert--danger">
|
||||||
<%- @T('Notice') %>:<br>
|
|
||||||
<%= channel.last_log_in %>
|
<%= channel.last_log_in %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -76,8 +75,7 @@
|
||||||
<%- @T('Protocol') %>: <%= channel.options.outbound.adapter %>
|
<%- @T('Protocol') %>: <%= channel.options.outbound.adapter %>
|
||||||
</a>
|
</a>
|
||||||
<% if !_.isEmpty(channel.last_log_out): %>
|
<% if !_.isEmpty(channel.last_log_out): %>
|
||||||
<div>
|
<div class="alert alert--danger">
|
||||||
<%- @T('Notice') %>:<br>
|
|
||||||
<%= channel.last_log_out %>
|
<%= channel.last_log_out %>
|
||||||
<div>
|
<div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -132,10 +130,10 @@
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<% if channel.status_in is 'error': %>
|
<% if channel.status_in is 'error': %>
|
||||||
<div><%= channel.last_log_in %></div>
|
<div class="alert alert--danger"><%= channel.last_log_in %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if channel.status_out is 'error': %>
|
<% if channel.status_out is 'error': %>
|
||||||
<div><%= channel.last_log_out %></div>
|
<div class="alert alert--danger"><%= channel.last_log_out %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,6 +4,8 @@ class Calendar < ApplicationModel
|
||||||
store :business_hours
|
store :business_hours
|
||||||
store :public_holidays
|
store :public_holidays
|
||||||
|
|
||||||
|
before_create :fetch_ical
|
||||||
|
before_update :fetch_ical
|
||||||
after_create :sync_default, :min_one_check
|
after_create :sync_default, :min_one_check
|
||||||
after_update :sync_default, :min_one_check
|
after_update :sync_default, :min_one_check
|
||||||
after_destroy :min_one_check
|
after_destroy :min_one_check
|
||||||
|
@ -207,37 +209,47 @@ returns
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def sync
|
def sync(without_save = nil)
|
||||||
return if !ical_url
|
return if !ical_url
|
||||||
events = Calendar.parse(ical_url)
|
begin
|
||||||
|
events = Calendar.parse(ical_url)
|
||||||
|
|
||||||
# sync with public_holidays
|
# sync with public_holidays
|
||||||
if !public_holidays
|
if !public_holidays
|
||||||
self.public_holidays = {}
|
self.public_holidays = {}
|
||||||
end
|
|
||||||
events.each {|day, summary|
|
|
||||||
if !public_holidays[day]
|
|
||||||
public_holidays[day] = {}
|
|
||||||
end
|
end
|
||||||
|
events.each {|day, summary|
|
||||||
|
if !public_holidays[day]
|
||||||
|
public_holidays[day] = {}
|
||||||
|
end
|
||||||
|
|
||||||
# ignore if already added or changed
|
# ignore if already added or changed
|
||||||
next if public_holidays[day].key?('active')
|
next if public_holidays[day].key?('active')
|
||||||
|
|
||||||
# create new entry
|
# create new entry
|
||||||
public_holidays[day] = {
|
public_holidays[day] = {
|
||||||
active: true,
|
active: true,
|
||||||
summary: summary,
|
summary: summary,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
self.last_log = nil
|
||||||
self.last_log = ''
|
rescue => e
|
||||||
|
self.last_log = e.inspect
|
||||||
|
end
|
||||||
|
|
||||||
self.last_sync = Time.zone.now
|
self.last_sync = Time.zone.now
|
||||||
save
|
if !without_save
|
||||||
|
save
|
||||||
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parse(location)
|
def self.parse(location)
|
||||||
if location =~ /^http/i
|
if location =~ /^http/i
|
||||||
result = UserAgent.get(location)
|
result = UserAgent.get(location)
|
||||||
|
if !result.success?
|
||||||
|
fail result.error
|
||||||
|
end
|
||||||
cal_file = result.body
|
cal_file = result.body
|
||||||
else
|
else
|
||||||
cal_file = File.open(location)
|
cal_file = File.open(location)
|
||||||
|
@ -298,4 +310,9 @@ returns
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# fetch ical feed
|
||||||
|
def fetch_ical
|
||||||
|
sync(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue