Improved calendar management.
This commit is contained in:
parent
fc8008b7e4
commit
a787d66486
8 changed files with 77 additions and 29 deletions
|
@ -59,7 +59,9 @@ class App.UiElement.holiday_selector
|
||||||
|
|
||||||
# check if entry already exists
|
# check if entry already exists
|
||||||
exists = item.find("[data-date=#{date}]").get(0)
|
exists = item.find("[data-date=#{date}]").get(0)
|
||||||
return if exists
|
if exists
|
||||||
|
alert(App.i18n.translateInline('Aready exists!'))
|
||||||
|
return
|
||||||
|
|
||||||
# reset form input
|
# reset form input
|
||||||
$(e.target).closest('tr').find('.js-summary').val('')
|
$(e.target).closest('tr').find('.js-summary').val('')
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement
|
class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement
|
||||||
@render: (attribute, params) ->
|
@render: (attribute, params) ->
|
||||||
|
|
||||||
ical_feeds = App.Config.get('ical_feeds') || {}
|
icalFeeds = App.Config.get('ical_feeds') || {}
|
||||||
item = $( App.view('generic/ical_feed')( attribute: attribute, ical_feeds: ical_feeds ) )
|
icalFeedsSorted = App.Utils.sortByValue(icalFeeds)
|
||||||
|
item = $( App.view('generic/ical_feed')( attribute: attribute, icalFeeds: icalFeedsSorted ) )
|
||||||
|
|
||||||
updateCheckList = ->
|
updateCheckList = ->
|
||||||
return if item.find('.js-checkList').prop('checked')
|
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() )
|
item.find('.js-shadow').val( item.find('.js-list').val() )
|
||||||
|
|
||||||
# set inital state
|
# set inital state
|
||||||
if ical_feeds[attribute.value]
|
if icalFeeds[attribute.value]
|
||||||
updateCheckList()
|
updateCheckList()
|
||||||
else
|
else
|
||||||
updateCheckManual()
|
updateCheckManual()
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Index extends App.ControllerSubContent
|
||||||
if itemTime < till && itemTime > from
|
if itemTime < till && itemTime > from
|
||||||
if calendar.public_holidays[day] && calendar.public_holidays[day].active
|
if calendar.public_holidays[day] && calendar.public_holidays[day].active
|
||||||
public_holidays_preview[day] = calendar.public_holidays[day]
|
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
|
# show description button, only if content exists
|
||||||
showDescription = false
|
showDescription = false
|
||||||
|
@ -78,7 +78,6 @@ class Index extends App.ControllerSubContent
|
||||||
object: 'Calendar'
|
object: 'Calendar'
|
||||||
objects: 'Calendars'
|
objects: 'Calendars'
|
||||||
genericObject: 'Calendar'
|
genericObject: 'Calendar'
|
||||||
callback: @load
|
|
||||||
container: @el.closest('.content')
|
container: @el.closest('.content')
|
||||||
large: true
|
large: true
|
||||||
)
|
)
|
||||||
|
@ -92,7 +91,6 @@ class Index extends App.ControllerSubContent
|
||||||
object: 'Calendar'
|
object: 'Calendar'
|
||||||
objects: 'Calendars'
|
objects: 'Calendars'
|
||||||
genericObject: 'Calendar'
|
genericObject: 'Calendar'
|
||||||
callback: @load
|
|
||||||
container: @el.closest('.content')
|
container: @el.closest('.content')
|
||||||
large: true
|
large: true
|
||||||
)
|
)
|
||||||
|
@ -107,17 +105,12 @@ class Index extends App.ControllerSubContent
|
||||||
callback: @load
|
callback: @load
|
||||||
)
|
)
|
||||||
|
|
||||||
default: (e) =>
|
default: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
id = $(e.target).closest('.action').data('id')
|
id = $(e.target).closest('.action').data('id')
|
||||||
item = App.Calendar.find(id)
|
item = App.Calendar.find(id)
|
||||||
item.default = true
|
item.default = true
|
||||||
item.save(
|
item.save()
|
||||||
done: =>
|
|
||||||
@load()
|
|
||||||
fail: =>
|
|
||||||
@load()
|
|
||||||
)
|
|
||||||
|
|
||||||
description: (e) =>
|
description: (e) =>
|
||||||
new App.ControllerGenericDescription(
|
new App.ControllerGenericDescription(
|
||||||
|
|
|
@ -666,6 +666,46 @@ class App.Utils
|
||||||
# check length, remove longer positions
|
# check length, remove longer positions
|
||||||
"#{result[1]}.#{result[2].substr(0,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) ->
|
@formatTime: (num, digits) ->
|
||||||
|
|
||||||
# input validation
|
# input validation
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<tr>
|
<tr class="settings-list-controlRow">
|
||||||
<td>
|
<td>
|
||||||
<td class="settings-list-control-cell js-datePicker">
|
<td class="settings-list-control-cell js-datePicker">
|
||||||
<!-- not supported right now by ff
|
<!-- not supported right now by ff
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<%- @Icon('checkbox-checked', 'icon-checked') %>
|
<%- @Icon('checkbox-checked', 'icon-checked') %>
|
||||||
</label>
|
</label>
|
||||||
<td><%- @Tdate(@placeholderDate) %>
|
<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">
|
<td class="settings-list-row-control">
|
||||||
<div class="btn btn--text js-remove">
|
<div class="btn btn--text js-remove">
|
||||||
<%- @Icon('trash') %> <%- @T('Remove') %>
|
<%- @Icon('trash') %> <%- @T('Remove') %>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="u-inlineBlock u-positionOrigin">
|
<div class="u-inlineBlock u-positionOrigin">
|
||||||
<select class="form-control form-control--small js-list">
|
<select class="form-control form-control--small js-list">
|
||||||
<option value="">-</option>
|
<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>
|
<option value="<%= url %>" <% if @attribute.value is url: %>selected<%end%>><%- @T(name) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -220,6 +220,12 @@ returns
|
||||||
|
|
||||||
def sync(without_save = nil)
|
def sync(without_save = nil)
|
||||||
return if !ical_url
|
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
|
begin
|
||||||
events = {}
|
events = {}
|
||||||
if ical_url && !ical_url.empty?
|
if ical_url && !ical_url.empty?
|
||||||
|
@ -255,6 +261,11 @@ returns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.last_log = nil
|
self.last_log = nil
|
||||||
|
cache = Cache.write(
|
||||||
|
cache_key,
|
||||||
|
{ public_holidays: public_holidays, ical_url: ical_url },
|
||||||
|
{ expires_in: 5.days },
|
||||||
|
)
|
||||||
rescue => e
|
rescue => e
|
||||||
self.last_log = e.inspect
|
self.last_log = e.inspect
|
||||||
end
|
end
|
||||||
|
@ -312,23 +323,23 @@ returns
|
||||||
|
|
||||||
# check if min one is set to default true
|
# check if min one is set to default true
|
||||||
def min_one_check
|
def min_one_check
|
||||||
Calendar.all.each { |calendar|
|
if !Calendar.find_by(default: true)
|
||||||
return true if calendar.default
|
first = Calendar.order(:created_at, :id).limit(1).first
|
||||||
}
|
first.default = true
|
||||||
first = Calendar.order(:created_at, :id).limit(1).first
|
first.save
|
||||||
first.default = true
|
end
|
||||||
first.save
|
|
||||||
|
|
||||||
# check if sla's are refer to an existing calendar
|
# check if sla's are refer to an existing calendar
|
||||||
|
default_calendar = Calendar.find_by(default: true)
|
||||||
Sla.all.each { |sla|
|
Sla.all.each { |sla|
|
||||||
if !sla.calendar_id
|
if !sla.calendar_id
|
||||||
sla.calendar_id = first.id
|
sla.calendar_id = default_calendar.id
|
||||||
sla.save
|
sla.save!
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
if !Calendar.find_by(id: sla.calendar_id)
|
if !Calendar.find_by(id: sla.calendar_id)
|
||||||
sla.calendar_id = first.id
|
sla.calendar_id = default_calendar.id
|
||||||
sla.save
|
sla.save!
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -342,9 +353,10 @@ returns
|
||||||
def validate_public_holidays
|
def validate_public_holidays
|
||||||
|
|
||||||
# fillup feed info
|
# fillup feed info
|
||||||
|
before = public_holidays_was
|
||||||
public_holidays.each { |day, meta|
|
public_holidays.each { |day, meta|
|
||||||
if public_holidays_was && public_holidays_was[day] && public_holidays_was[day]['feed']
|
if before && before[day] && before[day]['feed']
|
||||||
meta['feed'] = public_holidays_was[day]['feed']
|
meta['feed'] = before[day]['feed']
|
||||||
end
|
end
|
||||||
meta['active'] = if meta['active']
|
meta['active'] = if meta['active']
|
||||||
true
|
true
|
||||||
|
|
Loading…
Reference in a new issue