Improved calendar management.

This commit is contained in:
Martin Edenhofer 2016-11-10 16:11:59 +01:00
parent fc8008b7e4
commit a787d66486
8 changed files with 77 additions and 29 deletions

View file

@ -59,7 +59,9 @@ class App.UiElement.holiday_selector
# check if entry already exists
exists = item.find("[data-date=#{date}]").get(0)
return if exists
if exists
alert(App.i18n.translateInline('Aready exists!'))
return
# reset form input
$(e.target).closest('tr').find('.js-summary').val('')

View file

@ -2,8 +2,9 @@
class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement
@render: (attribute, params) ->
ical_feeds = App.Config.get('ical_feeds') || {}
item = $( App.view('generic/ical_feed')( attribute: attribute, ical_feeds: ical_feeds ) )
icalFeeds = App.Config.get('ical_feeds') || {}
icalFeedsSorted = App.Utils.sortByValue(icalFeeds)
item = $( App.view('generic/ical_feed')( attribute: attribute, icalFeeds: icalFeedsSorted ) )
updateCheckList = ->
return if item.find('.js-checkList').prop('checked')
@ -25,7 +26,7 @@ class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement
item.find('.js-shadow').val( item.find('.js-list').val() )
# set inital state
if ical_feeds[attribute.value]
if icalFeeds[attribute.value]
updateCheckList()
else
updateCheckManual()

View file

@ -51,7 +51,7 @@ class Index extends App.ControllerSubContent
if itemTime < till && itemTime > from
if calendar.public_holidays[day] && calendar.public_holidays[day].active
public_holidays_preview[day] = calendar.public_holidays[day]
calendar.public_holidays_preview = public_holidays_preview
calendar.public_holidays_preview = App.Utils.sortByKey(public_holidays_preview)
# show description button, only if content exists
showDescription = false
@ -78,7 +78,6 @@ class Index extends App.ControllerSubContent
object: 'Calendar'
objects: 'Calendars'
genericObject: 'Calendar'
callback: @load
container: @el.closest('.content')
large: true
)
@ -92,7 +91,6 @@ class Index extends App.ControllerSubContent
object: 'Calendar'
objects: 'Calendars'
genericObject: 'Calendar'
callback: @load
container: @el.closest('.content')
large: true
)
@ -107,17 +105,12 @@ class Index extends App.ControllerSubContent
callback: @load
)
default: (e) =>
default: (e) ->
e.preventDefault()
id = $(e.target).closest('.action').data('id')
item = App.Calendar.find(id)
item.default = true
item.save(
done: =>
@load()
fail: =>
@load()
)
item.save()
description: (e) =>
new App.ControllerGenericDescription(

View file

@ -666,6 +666,46 @@ class App.Utils
# check length, remove longer positions
"#{result[1]}.#{result[2].substr(0,positions)}"
@sortByValue: (options, order = 'ASC') ->
# sort by name
byNames = []
byNamesWithValue = {}
for i, value of options
valueTmp = value.toString().toLowerCase()
byNames.push valueTmp
byNamesWithValue[valueTmp] = [i, value]
byNames = byNames.sort()
# do a reverse, if needed
if order == 'DESC'
byNames = byNames.reverse()
optionsNew = {}
for i in byNames
ref = byNamesWithValue[i]
optionsNew[ref[0]] = ref[1]
optionsNew
@sortByKey: (options, order = 'ASC') ->
# sort by name
byKeys = []
for i, value of options
if i.toString
iTmp = i.toString().toLowerCase()
else
iTmp = i
byKeys.push iTmp
byKeys = byKeys.sort()
# do a reverse, if needed
if order == 'DESC'
byKeys = byKeys.reverse()
optionsNew = {}
for i in byKeys
optionsNew[i] = options[i]
optionsNew
@formatTime: (num, digits) ->
# input validation

View file

@ -25,7 +25,7 @@
<% end %>
<% end %>
<tr>
<tr class="settings-list-controlRow">
<td>
<td class="settings-list-control-cell js-datePicker">
<!-- not supported right now by ff

View file

@ -6,7 +6,7 @@
<%- @Icon('checkbox-checked', 'icon-checked') %>
</label>
<td><%- @Tdate(@placeholderDate) %>
<td><input class="form-control form-control--small js-summary" type="text" name="<%= @placeholderSummary %>" value="<%= @placeholderSummary %>" required/>
<td class="settings-list-control-cell"><input class="form-control form-control--small js-summary" type="text" name="<%= @nameSummary %>" value="<%= @placeholderSummary %>" required/>
<td class="settings-list-row-control">
<div class="btn btn--text js-remove">
<%- @Icon('trash') %> <%- @T('Remove') %>

View file

@ -10,7 +10,7 @@
<div class="u-inlineBlock u-positionOrigin">
<select class="form-control form-control--small js-list">
<option value="">-</option>
<% for url, name of @ical_feeds: %>
<% for url, name of @icalFeeds: %>
<option value="<%= url %>" <% if @attribute.value is url: %>selected<%end%>><%- @T(name) %></option>
<% end %>
</select>

View file

@ -220,6 +220,12 @@ returns
def sync(without_save = nil)
return if !ical_url
# only sync every 5 days
cache_key = "CalendarIcal::#{id}"
cache = Cache.get(cache_key)
return if !last_log && cache && cache[:ical_url] == ical_url
begin
events = {}
if ical_url && !ical_url.empty?
@ -255,6 +261,11 @@ returns
}
}
self.last_log = nil
cache = Cache.write(
cache_key,
{ public_holidays: public_holidays, ical_url: ical_url },
{ expires_in: 5.days },
)
rescue => e
self.last_log = e.inspect
end
@ -312,23 +323,23 @@ returns
# check if min one is set to default true
def min_one_check
Calendar.all.each { |calendar|
return true if calendar.default
}
first = Calendar.order(:created_at, :id).limit(1).first
first.default = true
first.save
if !Calendar.find_by(default: true)
first = Calendar.order(:created_at, :id).limit(1).first
first.default = true
first.save
end
# check if sla's are refer to an existing calendar
default_calendar = Calendar.find_by(default: true)
Sla.all.each { |sla|
if !sla.calendar_id
sla.calendar_id = first.id
sla.save
sla.calendar_id = default_calendar.id
sla.save!
next
end
if !Calendar.find_by(id: sla.calendar_id)
sla.calendar_id = first.id
sla.save
sla.calendar_id = default_calendar.id
sla.save!
end
}
end
@ -342,9 +353,10 @@ returns
def validate_public_holidays
# fillup feed info
before = public_holidays_was
public_holidays.each { |day, meta|
if public_holidays_was && public_holidays_was[day] && public_holidays_was[day]['feed']
meta['feed'] = public_holidays_was[day]['feed']
if before && before[day] && before[day]['feed']
meta['feed'] = before[day]['feed']
end
meta['active'] = if meta['active']
true