Added config option for deliver alarm for events or not (because of Lightning Calendar and not closable alarm windows).

This commit is contained in:
Martin Edenhofer 2016-02-29 13:05:21 +01:00
parent 077eae7ced
commit 84581e372d
4 changed files with 96 additions and 39 deletions

View file

@ -42,12 +42,17 @@ class CalendarSubscriptions extends App.Controller
for i, checkbox of @options.serializeArray() for i, checkbox of @options.serializeArray()
[state, option] = checkbox.name.split('/') [state, option] = checkbox.name.split('/')
if state && option
@preferences[state][option] = true @preferences[state][option] = true
else
@preferences[checkbox.name] = true
@store() @store()
setAllPreferencesToFalse: -> setAllPreferencesToFalse: ->
@preferences.alarm = false
for state of @preferences for state of @preferences
if _.isObject(@preferences)
@preferences[state].own = false @preferences[state].own = false
@preferences[state].not_assigned = false @preferences[state].not_assigned = false
@ -69,13 +74,12 @@ class CalendarSubscriptions extends App.Controller
success: (data, status, xhr) => success: (data, status, xhr) =>
App.User.full( App.User.full(
App.Session.get( 'id' ), App.Session.get('id')
=> =>
@notify( @notify(
type: 'success' type: 'success'
msg: App.i18n.translateContent('Successfully!') msg: App.i18n.translateContent('Successfully!')
) )
,
true true
) )

View file

@ -18,6 +18,21 @@
</form> </form>
<h3><%- @T('Subscription Settings') %></h3> <h3><%- @T('Subscription Settings') %></h3>
<div class="form-group">
<div class="formGroup-label">
<label for="notification-sound"><%- @T('Alarm') %></label>
</div>
<div class="controls">
<p>
<label class="checkbox-replacement inline-label">
<input type="checkbox" name="alarm" value="true" <% if @preferences.alarm: %>checked<% end %>/>
<%- @Icon('checkbox', 'icon-unchecked') %>
<%- @Icon('checkbox-checked', 'icon-checked') %>
</label>
<%- @T('Add alarm to pending reminder and escalated tickets.') %>
</p>
</div>
</div>
<table class="settings-list"> <table class="settings-list">
<thead> <thead>
<tr> <tr>
@ -28,6 +43,7 @@
</thead> </thead>
<tbody> <tbody>
<% for stateType, options of @preferences: %> <% for stateType, options of @preferences: %>
<% if _.isObject(options): %>
<tr> <tr>
<td style="text-transform: capitalize"> <td style="text-transform: capitalize">
<%= @translationTable[stateType] %> <%= @translationTable[stateType] %>
@ -50,6 +66,7 @@
<input class="form-control form-control--borderless js-select is-hidden" readonly value="<%- @baseurl %>/ical/tickets/<%= stateType %>"> <input class="form-control form-control--borderless js-select is-hidden" readonly value="<%- @baseurl %>/ical/tickets/<%= stateType %>">
</tr> </tr>
<% end %> <% end %>
<% end %>
</tbody> </tbody>
</table> </table>
</div> </div>

View file

@ -20,6 +20,16 @@ class CalendarSubscriptions::Tickets
events_data events_data
end end
def alarm?
alarm = false
return alarm if @preferences.empty?
return alarm if !@preferences[:alarm]
@preferences[:alarm]
end
def owner_ids(method) def owner_ids(method)
owner_ids = [] owner_ids = []
@ -138,10 +148,12 @@ class CalendarSubscriptions::Tickets
event_data[:dtend] = Icalendar::Values::DateTime.new(pending_time, 'tzid' => @tzid) event_data[:dtend] = Icalendar::Values::DateTime.new(pending_time, 'tzid' => @tzid)
event_data[:summary] = "#{translated_state} #{translated_ticket}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}" event_data[:summary] = "#{translated_state} #{translated_ticket}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}"
event_data[:description] = "T##{ticket.number}" event_data[:description] = "T##{ticket.number}"
if alarm?
event_data[:alarm] = { event_data[:alarm] = {
summary: event_data[:summary], summary: event_data[:summary],
trigger: '-PT1M', trigger: '-PT1M',
} }
end
events_data.push event_data events_data.push event_data
end end
@ -190,10 +202,12 @@ class CalendarSubscriptions::Tickets
event_data[:dtend] = Icalendar::Values::DateTime.new(escalation_time, 'tzid' => @tzid) event_data[:dtend] = Icalendar::Values::DateTime.new(escalation_time, 'tzid' => @tzid)
event_data[:summary] = "#{translated_ticket_escalation}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}" event_data[:summary] = "#{translated_ticket_escalation}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}"
event_data[:description] = "T##{ticket.number}" event_data[:description] = "T##{ticket.number}"
if alarm?
event_data[:alarm] = { event_data[:alarm] = {
summary: event_data[:summary], summary: event_data[:summary],
trigger: '-PT1M', trigger: '-PT1M',
} }
end
events_data.push event_data events_data.push event_data
end end

View file

@ -232,18 +232,22 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
assert_equal(cal.events[0].dtstart, Time.zone.today) assert_equal(cal.events[0].dtstart, Time.zone.today)
assert_equal(cal.events[0].summary, 'new ticket: \'some title1 - new - group_calendar\'') assert_equal(cal.events[0].summary, 'new ticket: \'some title1 - new - group_calendar\'')
assert_equal(cal.events[0].description, "T##{ticket1.number}") assert_equal(cal.events[0].description, "T##{ticket1.number}")
assert_equal(cal.events[0].has_alarm?, false)
assert_equal(cal.events[1].dtstart, Time.zone.today) assert_equal(cal.events[1].dtstart, Time.zone.today)
assert_equal(cal.events[1].summary, 'new ticket: \'some title1 - escalation - group_calendar\'') assert_equal(cal.events[1].summary, 'new ticket: \'some title1 - escalation - group_calendar\'')
assert_equal(cal.events[1].description, "T##{ticket5.number}") assert_equal(cal.events[1].description, "T##{ticket5.number}")
assert_equal(cal.events[1].has_alarm?, false)
assert_equal(cal.events[2].dtstart, Time.zone.today) assert_equal(cal.events[2].dtstart, Time.zone.today)
assert_equal(cal.events[2].summary, 'pending reminder ticket: \'some title1 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[2].summary, 'pending reminder ticket: \'some title1 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[2].description, "T##{ticket3.number}") assert_equal(cal.events[2].description, "T##{ticket3.number}")
assert_equal(cal.events[2].has_alarm?, false)
assert_equal(cal.events[3].dtstart, Time.zone.today) assert_equal(cal.events[3].dtstart, Time.zone.today)
assert_equal(cal.events[3].summary, 'ticket escalation: \'some title1 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[3].summary, 'ticket escalation: \'some title1 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[3].description, "T##{ticket5.number}") assert_equal(cal.events[3].description, "T##{ticket5.number}")
assert_equal(cal.events[3].has_alarm?, false)
if !agent1.preferences[:calendar_subscriptions] if !agent1.preferences[:calendar_subscriptions]
agent1.preferences[:calendar_subscriptions] = {} agent1.preferences[:calendar_subscriptions] = {}
@ -260,7 +264,8 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
pending: { pending: {
own: true, own: true,
not_assigned: true, not_assigned: true,
} },
alarm: true,
} }
agent1.save! agent1.save!
@ -276,34 +281,42 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
assert_equal(cal.events[0].dtstart, Time.zone.today) assert_equal(cal.events[0].dtstart, Time.zone.today)
assert_equal(cal.events[0].summary, 'new ticket: \'some title2 - new - group_calendar\'') assert_equal(cal.events[0].summary, 'new ticket: \'some title2 - new - group_calendar\'')
assert_equal(cal.events[0].description, "T##{ticket7.number}") assert_equal(cal.events[0].description, "T##{ticket7.number}")
assert_equal(cal.events[0].has_alarm?, false)
assert_equal(cal.events[1].dtstart, Time.zone.today) assert_equal(cal.events[1].dtstart, Time.zone.today)
assert_equal(cal.events[1].summary, 'new ticket: \'some title2 - escalation - group_calendar\'') assert_equal(cal.events[1].summary, 'new ticket: \'some title2 - escalation - group_calendar\'')
assert_equal(cal.events[1].description, "T##{ticket11.number}") assert_equal(cal.events[1].description, "T##{ticket11.number}")
assert_equal(cal.events[1].has_alarm?, false)
assert_equal(cal.events[2].dtstart, Time.zone.today) assert_equal(cal.events[2].dtstart, Time.zone.today)
assert_equal(cal.events[2].summary, 'new ticket: \'some title1 - new - group_calendar\'') assert_equal(cal.events[2].summary, 'new ticket: \'some title1 - new - group_calendar\'')
assert_equal(cal.events[2].description, "T##{ticket1.number}") assert_equal(cal.events[2].description, "T##{ticket1.number}")
assert_equal(cal.events[2].has_alarm?, false)
assert_equal(cal.events[3].dtstart, Time.zone.today) assert_equal(cal.events[3].dtstart, Time.zone.today)
assert_equal(cal.events[3].summary, 'new ticket: \'some title1 - escalation - group_calendar\'') assert_equal(cal.events[3].summary, 'new ticket: \'some title1 - escalation - group_calendar\'')
assert_equal(cal.events[3].description, "T##{ticket5.number}") assert_equal(cal.events[3].description, "T##{ticket5.number}")
assert_equal(cal.events[3].has_alarm?, false)
assert_equal(cal.events[4].dtstart, Time.zone.today) assert_equal(cal.events[4].dtstart, Time.zone.today)
assert_equal(cal.events[4].summary, 'pending reminder ticket: \'some title2 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[4].summary, 'pending reminder ticket: \'some title2 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[4].description, "T##{ticket9.number}") assert_equal(cal.events[4].description, "T##{ticket9.number}")
assert_equal(cal.events[4].has_alarm?, true)
assert_equal(cal.events[5].dtstart, Time.zone.today) assert_equal(cal.events[5].dtstart, Time.zone.today)
assert_equal(cal.events[5].summary, 'pending reminder ticket: \'some title1 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[5].summary, 'pending reminder ticket: \'some title1 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[5].description, "T##{ticket3.number}") assert_equal(cal.events[5].description, "T##{ticket3.number}")
assert_equal(cal.events[5].has_alarm?, true)
assert_equal(cal.events[6].dtstart, Time.zone.today) assert_equal(cal.events[6].dtstart, Time.zone.today)
assert_equal(cal.events[6].summary, 'ticket escalation: \'some title2 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[6].summary, 'ticket escalation: \'some title2 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[6].description, "T##{ticket11.number}") assert_equal(cal.events[6].description, "T##{ticket11.number}")
assert_equal(cal.events[6].has_alarm?, true)
assert_equal(cal.events[7].dtstart, Time.zone.today) assert_equal(cal.events[7].dtstart, Time.zone.today)
assert_equal(cal.events[7].summary, 'ticket escalation: \'some title1 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[7].summary, 'ticket escalation: \'some title1 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[7].description, "T##{ticket5.number}") assert_equal(cal.events[7].description, "T##{ticket5.number}")
assert_equal(cal.events[7].has_alarm?, true)
# check agent 2 # check agent 2
calendar_subscriptions = CalendarSubscriptions.new(agent2) calendar_subscriptions = CalendarSubscriptions.new(agent2)
@ -346,7 +359,8 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
pending: { pending: {
own: true, own: true,
not_assigned: true, not_assigned: true,
} },
alarm: false,
} }
agent2.save! agent2.save!
@ -362,34 +376,42 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
assert_equal(cal.events[0].dtstart, Time.zone.today) assert_equal(cal.events[0].dtstart, Time.zone.today)
assert_equal(cal.events[0].summary, 'new ticket: \'some title2 - new - group_default\'') assert_equal(cal.events[0].summary, 'new ticket: \'some title2 - new - group_default\'')
assert_equal(cal.events[0].description, "T##{ticket8.number}") assert_equal(cal.events[0].description, "T##{ticket8.number}")
assert_equal(cal.events[0].has_alarm?, false)
assert_equal(cal.events[1].dtstart, Time.zone.today) assert_equal(cal.events[1].dtstart, Time.zone.today)
assert_equal(cal.events[1].summary, 'new ticket: \'some title2 - escalation - group_default\'') assert_equal(cal.events[1].summary, 'new ticket: \'some title2 - escalation - group_default\'')
assert_equal(cal.events[1].description, "T##{ticket12.number}") assert_equal(cal.events[1].description, "T##{ticket12.number}")
assert_equal(cal.events[1].has_alarm?, false)
assert_equal(cal.events[2].dtstart, Time.zone.today) assert_equal(cal.events[2].dtstart, Time.zone.today)
assert_equal(cal.events[2].summary, 'new ticket: \'some title1 - new - group_default\'') assert_equal(cal.events[2].summary, 'new ticket: \'some title1 - new - group_default\'')
assert_equal(cal.events[2].description, "T##{ticket2.number}") assert_equal(cal.events[2].description, "T##{ticket2.number}")
assert_equal(cal.events[1].has_alarm?, false)
assert_equal(cal.events[3].dtstart, Time.zone.today) assert_equal(cal.events[3].dtstart, Time.zone.today)
assert_equal(cal.events[3].summary, 'new ticket: \'some title1 - escalation - group_default\'') assert_equal(cal.events[3].summary, 'new ticket: \'some title1 - escalation - group_default\'')
assert_equal(cal.events[3].description, "T##{ticket6.number}") assert_equal(cal.events[3].description, "T##{ticket6.number}")
assert_equal(cal.events[3].has_alarm?, false)
assert_equal(cal.events[4].dtstart, Time.zone.today) assert_equal(cal.events[4].dtstart, Time.zone.today)
assert_equal(cal.events[4].summary, 'pending reminder ticket: \'some title2 - pending - group_default\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[4].summary, 'pending reminder ticket: \'some title2 - pending - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[4].description, "T##{ticket10.number}") assert_equal(cal.events[4].description, "T##{ticket10.number}")
assert_equal(cal.events[4].has_alarm?, false)
assert_equal(cal.events[5].dtstart, Time.zone.today) assert_equal(cal.events[5].dtstart, Time.zone.today)
assert_equal(cal.events[5].summary, 'pending reminder ticket: \'some title1 - pending - group_default\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[5].summary, 'pending reminder ticket: \'some title1 - pending - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[5].description, "T##{ticket4.number}") assert_equal(cal.events[5].description, "T##{ticket4.number}")
assert_equal(cal.events[5].has_alarm?, false)
assert_equal(cal.events[6].dtstart, Time.zone.today) assert_equal(cal.events[6].dtstart, Time.zone.today)
assert_equal(cal.events[6].summary, 'ticket escalation: \'some title2 - escalation - group_default\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[6].summary, 'ticket escalation: \'some title2 - escalation - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[6].description, "T##{ticket12.number}") assert_equal(cal.events[6].description, "T##{ticket12.number}")
assert_equal(cal.events[6].has_alarm?, false)
assert_equal(cal.events[7].dtstart, Time.zone.today) assert_equal(cal.events[7].dtstart, Time.zone.today)
assert_equal(cal.events[7].summary, 'ticket escalation: \'some title1 - escalation - group_default\' customer: Notification Customer1 (Selector Org)') assert_equal(cal.events[7].summary, 'ticket escalation: \'some title1 - escalation - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[7].description, "T##{ticket6.number}") assert_equal(cal.events[7].description, "T##{ticket6.number}")
assert_equal(cal.events[7].has_alarm?, false)
end end