diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 55877649f..9890278d2 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -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 diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee index 23cc3f193..8e408c16c 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/attribute_bar.coffee @@ -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 diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/taskbar_watcher.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/taskbar_watcher.coffee index 84d9ebf59..75b03bb10 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/taskbar_watcher.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/taskbar_watcher.coffee @@ -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('
') @el.append('') @@ -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 diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.coffee index b022c0f88..d9b22e9fc 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.coffee @@ -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] diff --git a/app/models/taskbar.rb b/app/models/taskbar.rb index 0138a7b29..868adc216 100644 --- a/app/models/taskbar.rb +++ b/app/models/taskbar.rb @@ -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 }