Improved collision detection.
This commit is contained in:
parent
dda715be1b
commit
82cf2168f6
5 changed files with 62 additions and 22 deletions
|
@ -227,6 +227,8 @@ class App.TicketZoom extends App.Controller
|
|||
@positionPageHeaderStart()
|
||||
@autosaveStart()
|
||||
@shortcutNavigationStart()
|
||||
return if !@attributeBar
|
||||
@attributeBar.start()
|
||||
|
||||
pagePosition: (params = {}) =>
|
||||
|
||||
|
@ -285,6 +287,8 @@ class App.TicketZoom extends App.Controller
|
|||
@positionPageHeaderStop()
|
||||
@autosaveStop()
|
||||
@shortcutNavigationstop()
|
||||
return if !@attributeBar
|
||||
@attributeBar.stop()
|
||||
|
||||
changed: =>
|
||||
return false if !@ticket
|
||||
|
@ -417,7 +421,8 @@ class App.TicketZoom extends App.Controller
|
|||
el: elLocal.find('.ticket-meta')
|
||||
)
|
||||
|
||||
new App.TicketZoomAttributeBar(
|
||||
@attributeBar = new App.TicketZoomAttributeBar(
|
||||
ticket: @ticket
|
||||
el: elLocal.find('.js-attributeBar')
|
||||
overview_id: @overview_id
|
||||
callback: @submit
|
||||
|
|
|
@ -49,13 +49,21 @@ class App.TicketZoomAttributeBar extends App.Controller
|
|||
@setSecondaryAction(@secondaryAction, localeEl)
|
||||
|
||||
if @permissionCheck('ticket.agent')
|
||||
new App.TaskbarWatcher(
|
||||
@taskbarWatcher = new App.TaskbarWatcher(
|
||||
task_key: @task_key
|
||||
el: localeEl.filter('.js-avatars')
|
||||
)
|
||||
|
||||
@html localeEl
|
||||
|
||||
start: =>
|
||||
return if !@taskbarWatcher
|
||||
@taskbarWatcher.start()
|
||||
|
||||
stop: =>
|
||||
return if !@taskbarWatcher
|
||||
@taskbarWatcher.stop()
|
||||
|
||||
checkMacroChanges: =>
|
||||
macroLastUpdated = App.Macro.lastUpdatedAt()
|
||||
return if macroLastUpdated is @macroLastUpdated
|
||||
|
|
|
@ -2,6 +2,7 @@ class App.TaskbarWatcher extends App.Controller
|
|||
constructor: ->
|
||||
super
|
||||
@subscribeId = App.TaskManager.preferencesSubscribe(@task_key, @render)
|
||||
App.TaskManager.preferencesTrigger(@task_key)
|
||||
|
||||
release: =>
|
||||
return if !@subscribeId
|
||||
|
@ -10,23 +11,30 @@ class App.TaskbarWatcher extends App.Controller
|
|||
render: (preferences) =>
|
||||
return if !preferences
|
||||
return if !preferences.tasks
|
||||
|
||||
currentUserId = App.Session.get('id')
|
||||
for watcher in preferences.tasks
|
||||
if watcher.user_id != currentUserId
|
||||
if watcher.last_contact
|
||||
watcher.idle = false
|
||||
diff = new Date().getTime() - new Date(watcher.last_contact).getTime()
|
||||
if diff > 300000
|
||||
watcher.idle = true
|
||||
|
||||
return if !@diffrence(@lastTasks, preferences.tasks)
|
||||
@lastTasks = preferences.tasks
|
||||
@lastTasks = clone(preferences.tasks)
|
||||
|
||||
watchers = []
|
||||
currentUserId = App.Session.get('id')
|
||||
@el.empty()
|
||||
for watcher in preferences.tasks
|
||||
if watcher.user_id != currentUserId
|
||||
cssClass = []
|
||||
lastContact = new Date(new Date(watcher.last_contact).getTime() + 5 * 60000)
|
||||
if new Date() > lastContact
|
||||
if watcher.idle
|
||||
cssClass.push('avatar--idle')
|
||||
if watcher.changed
|
||||
cssClass.push('avatar--changed')
|
||||
else
|
||||
cssClass.push('avatar--not-changed')
|
||||
|
||||
@el.append('<div class="js-avatar"></div>')
|
||||
@el.append('<div class="half-spacer"></div>')
|
||||
|
||||
|
@ -42,6 +50,17 @@ class App.TaskbarWatcher extends App.Controller
|
|||
status.append App.Utils.icon('pen')
|
||||
avatar.el.find('.avatar').append status
|
||||
|
||||
start: =>
|
||||
@intervalId = @interval(=>
|
||||
App.TaskManager.preferencesTrigger(@task_key)
|
||||
5 * 60000
|
||||
'ticket-watcher-interval'
|
||||
)
|
||||
|
||||
stop: =>
|
||||
return if !@intervalId
|
||||
@clearInterval(@intervalId)
|
||||
|
||||
diffrence: (lastTasks, newTasks) ->
|
||||
return true if !lastTasks
|
||||
return true if lastTasks.length != newTasks.length
|
||||
|
@ -49,7 +68,5 @@ class App.TaskbarWatcher extends App.Controller
|
|||
return true if !lastTasks[taskPosition] || !newTasks[taskPosition]
|
||||
return true if lastTasks[taskPosition].user_id != newTasks[taskPosition].user_id
|
||||
return true if lastTasks[taskPosition].changed != newTasks[taskPosition].changed
|
||||
if lastTasks[taskPosition].last_contact
|
||||
lastContact = new Date(new Date(lastTasks[taskPosition].last_contact).getTime() + 5 * 60000)
|
||||
return true if new Date() > lastContact
|
||||
return true if lastTasks[taskPosition].idle != newTasks[taskPosition].idle
|
||||
false
|
||||
|
|
|
@ -79,6 +79,10 @@ class App.TaskManager
|
|||
return if !_instance
|
||||
_instance.preferencesUnsubscribe(id)
|
||||
|
||||
@preferencesTrigger: (key) ->
|
||||
return if !_instance
|
||||
_instance.preferencesTrigger(key)
|
||||
|
||||
class _taskManagerSingleton extends App.Controller
|
||||
@include App.LogInclude
|
||||
|
||||
|
@ -93,7 +97,7 @@ class _taskManagerSingleton extends App.Controller
|
|||
|
||||
@bind('taskbar:preferences', (data) =>
|
||||
@tasksPreferences[data.key] = data.preferences
|
||||
@preferencesExecuteCallbacks(data.key)
|
||||
@preferencesTrigger(data.key)
|
||||
)
|
||||
|
||||
init: ->
|
||||
|
@ -228,7 +232,7 @@ class _taskManagerSingleton extends App.Controller
|
|||
delete ui.tasksToUpdate[params.key]
|
||||
ui.allTasksByKey[params.key] = @attributes()
|
||||
ui.tasksPreferences[params.key] = clone(@preferences)
|
||||
ui.preferencesExecuteCallbacks(params.key)
|
||||
ui.preferencesTrigger(params.key)
|
||||
for taskPosition of ui.allTasks
|
||||
if ui.allTasks[taskPosition] && ui.allTasks[taskPosition]['key'] is @key
|
||||
task = @attributes()
|
||||
|
@ -307,9 +311,11 @@ class _taskManagerSingleton extends App.Controller
|
|||
|
||||
# show task content
|
||||
show: (key, params_app) =>
|
||||
controller = @workers[ key ]
|
||||
controller = @workers[key]
|
||||
@shownStore[key] = true
|
||||
|
||||
@preferencesTrigger(key)
|
||||
|
||||
domKey = @domID(key)
|
||||
domStoreItem = @domStore[domKey]
|
||||
if !@$("##{domKey}").get(0) && domStoreItem && domStoreItem.el
|
||||
|
@ -344,7 +350,7 @@ class _taskManagerSingleton extends App.Controller
|
|||
|
||||
# hide task content
|
||||
hide: (key) =>
|
||||
controller = @workers[ key ]
|
||||
controller = @workers[key]
|
||||
@shownStore[key] = false
|
||||
|
||||
element = @$("##{@domID(key)}")
|
||||
|
@ -459,6 +465,7 @@ class _taskManagerSingleton extends App.Controller
|
|||
if worker
|
||||
worker = undefined
|
||||
delete @workers[key]
|
||||
delete @tasksPreferences[key]
|
||||
try
|
||||
element = @$("##{@domID(key)}")
|
||||
element.html('')
|
||||
|
@ -612,6 +619,7 @@ class _taskManagerSingleton extends App.Controller
|
|||
for task in tasks
|
||||
task.active = false
|
||||
@allTasksByKey[task.key] = task.attributes()
|
||||
@tasksPreferences[task.key] = task.preferences
|
||||
|
||||
# reopen tasks
|
||||
App.Event.trigger 'taskbar:init'
|
||||
|
@ -683,7 +691,7 @@ class _taskManagerSingleton extends App.Controller
|
|||
if _.isEmpty(value)
|
||||
delete @tasksPreferencesCallbacks[key]
|
||||
|
||||
preferencesExecuteCallbacks: (key) =>
|
||||
preferencesTrigger: (key) =>
|
||||
return if !@tasksPreferencesCallbacks[key]
|
||||
return if !@tasksPreferences[key]
|
||||
for subscribeId, callback of @tasksPreferencesCallbacks[key]
|
||||
|
|
|
@ -47,16 +47,18 @@ class Taskbar < ApplicationModel
|
|||
# find other same open tasks
|
||||
preferences[:tasks] = []
|
||||
Taskbar.where(key: key).order(:created_at).each { |taskbar|
|
||||
changed = if taskbar.id == id
|
||||
state_changed?
|
||||
else
|
||||
taskbar.state_changed?
|
||||
end
|
||||
if taskbar.id == id
|
||||
local_changed = state_changed?
|
||||
local_last_contact = last_contact
|
||||
else
|
||||
local_changed = taskbar.state_changed?
|
||||
local_last_contact = taskbar.last_contact
|
||||
end
|
||||
task = {
|
||||
id: taskbar.id,
|
||||
user_id: taskbar.user_id,
|
||||
last_contact: taskbar.last_contact,
|
||||
changed: changed,
|
||||
last_contact: local_last_contact,
|
||||
changed: local_changed,
|
||||
}
|
||||
preferences[:tasks].push task
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue