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,14 +42,19 @@ class CalendarSubscriptions extends App.Controller
for i, checkbox of @options.serializeArray()
[state, option] = checkbox.name.split('/')
@preferences[state][option] = true
if state && option
@preferences[state][option] = true
else
@preferences[checkbox.name] = true
@store()
setAllPreferencesToFalse: ->
@preferences.alarm = false
for state of @preferences
@preferences[state].own = false
@preferences[state].not_assigned = false
if _.isObject(@preferences)
@preferences[state].own = false
@preferences[state].not_assigned = false
store: ->
# get data
@ -69,22 +74,21 @@ class CalendarSubscriptions extends App.Controller
success: (data, status, xhr) =>
App.User.full(
App.Session.get( 'id' ),
App.Session.get('id')
=>
@notify(
type: 'success'
msg: App.i18n.translateContent( 'Successfully!' )
msg: App.i18n.translateContent('Successfully!')
)
,
true
)
error: (xhr, status, error) =>
@render()
data = JSON.parse( xhr.responseText )
data = JSON.parse(xhr.responseText)
@notify(
type: 'error'
msg: App.i18n.translateContent( data.message )
msg: App.i18n.translateContent(data.message)
)
App.Config.set( 'CalendarSubscriptions', { prio: 3000, name: 'Calendar', parent: '#profile', target: '#profile/calendar_subscriptions', role: ['Agent'], controller: CalendarSubscriptions }, 'NavBarProfile' )

View file

@ -18,6 +18,21 @@
</form>
<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">
<thead>
<tr>
@ -28,27 +43,29 @@
</thead>
<tbody>
<% for stateType, options of @preferences: %>
<tr>
<td style="text-transform: capitalize">
<%= @translationTable[stateType] %>
<td>
<label class="inline-label checkbox-replacement">
<input type="checkbox" name="<%= stateType %>/own"<%= if options.own then ' checked' %>>
<%- @Icon('checkbox', 'icon-unchecked') %>
<%- @Icon('checkbox-checked', 'icon-checked') %>
<span class="label-text"><%- @T('My Tickets') %></span>
</label>
<td>
<label class="inline-label checkbox-replacement">
<input type="checkbox" name="<%= stateType %>/not_assigned"<%= if options.not_assigned then ' checked' %>>
<%- @Icon('checkbox', 'icon-unchecked') %>
<%- @Icon('checkbox-checked', 'icon-checked') %>
<span class="label-text"><%- @T('Not Assigned') %></span>
</label>
<td>
<div class="btn btn--table btn--text js-showLink"><%- @T('Show') %></div>
<input class="form-control form-control--borderless js-select is-hidden" readonly value="<%- @baseurl %>/ical/tickets/<%= stateType %>">
</tr>
<% if _.isObject(options): %>
<tr>
<td style="text-transform: capitalize">
<%= @translationTable[stateType] %>
<td>
<label class="inline-label checkbox-replacement">
<input type="checkbox" name="<%= stateType %>/own"<%= if options.own then ' checked' %>>
<%- @Icon('checkbox', 'icon-unchecked') %>
<%- @Icon('checkbox-checked', 'icon-checked') %>
<span class="label-text"><%- @T('My Tickets') %></span>
</label>
<td>
<label class="inline-label checkbox-replacement">
<input type="checkbox" name="<%= stateType %>/not_assigned"<%= if options.not_assigned then ' checked' %>>
<%- @Icon('checkbox', 'icon-unchecked') %>
<%- @Icon('checkbox-checked', 'icon-checked') %>
<span class="label-text"><%- @T('Not Assigned') %></span>
</label>
<td>
<div class="btn btn--table btn--text js-showLink"><%- @T('Show') %></div>
<input class="form-control form-control--borderless js-select is-hidden" readonly value="<%- @baseurl %>/ical/tickets/<%= stateType %>">
</tr>
<% end %>
<% end %>
</tbody>
</table>

View file

@ -20,6 +20,16 @@ class CalendarSubscriptions::Tickets
events_data
end
def alarm?
alarm = false
return alarm if @preferences.empty?
return alarm if !@preferences[:alarm]
@preferences[:alarm]
end
def owner_ids(method)
owner_ids = []
@ -138,10 +148,12 @@ class CalendarSubscriptions::Tickets
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[:description] = "T##{ticket.number}"
event_data[:alarm] = {
summary: event_data[:summary],
trigger: '-PT1M',
}
if alarm?
event_data[:alarm] = {
summary: event_data[:summary],
trigger: '-PT1M',
}
end
events_data.push event_data
end
@ -190,10 +202,12 @@ class CalendarSubscriptions::Tickets
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[:description] = "T##{ticket.number}"
event_data[:alarm] = {
summary: event_data[:summary],
trigger: '-PT1M',
}
if alarm?
event_data[:alarm] = {
summary: event_data[:summary],
trigger: '-PT1M',
}
end
events_data.push event_data
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].summary, 'new ticket: \'some title1 - new - group_calendar\'')
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].summary, 'new ticket: \'some title1 - escalation - group_calendar\'')
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].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].has_alarm?, false)
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].description, "T##{ticket5.number}")
assert_equal(cal.events[3].has_alarm?, false)
if !agent1.preferences[:calendar_subscriptions]
agent1.preferences[:calendar_subscriptions] = {}
@ -260,7 +264,8 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
pending: {
own: true,
not_assigned: true,
}
},
alarm: true,
}
agent1.save!
@ -276,34 +281,42 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
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].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].summary, 'new ticket: \'some title2 - escalation - group_calendar\'')
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].summary, 'new ticket: \'some title1 - new - group_calendar\'')
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].summary, 'new ticket: \'some title1 - escalation - group_calendar\'')
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].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].has_alarm?, true)
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].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].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].has_alarm?, true)
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].description, "T##{ticket5.number}")
assert_equal(cal.events[7].has_alarm?, true)
# check agent 2
calendar_subscriptions = CalendarSubscriptions.new(agent2)
@ -346,7 +359,8 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
pending: {
own: true,
not_assigned: true,
}
},
alarm: false,
}
agent2.save!
@ -362,34 +376,42 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase
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].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].summary, 'new ticket: \'some title2 - escalation - group_default\'')
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].summary, 'new ticket: \'some title1 - new - group_default\'')
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].summary, 'new ticket: \'some title1 - escalation - group_default\'')
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].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].has_alarm?, false)
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].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].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].has_alarm?, false)
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].description, "T##{ticket6.number}")
assert_equal(cal.events[7].has_alarm?, false)
end