diff --git a/app/assets/javascripts/app/controllers/task_widget.js.coffee b/app/assets/javascripts/app/controllers/task_widget.js.coffee index 8e2061969..53d3d8b94 100644 --- a/app/assets/javascripts/app/controllers/task_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/task_widget.js.coffee @@ -15,11 +15,13 @@ class App.TaskWidget extends App.Controller App.TaskManager.reset() @el.html('') - @interval( - -> App.TaskManager.sync() - 2000, - 'task-widget', - ) + App.TaskManager.syncInitial() + + sync = => + App.TaskManager.sync() + @delay( sync, 2000, 'task-widget' ) + + @delay( sync, 2500, 'task-widget' ) render: -> @@ -47,7 +49,6 @@ class App.TaskWidget extends App.Controller tasks_all = App.TaskManager.all() active_is_closed = false for task_key, task of tasks_all - console.log('--', task_key, task) if task.active && task_key.toString() is key.toString() active_is_closed = true diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee index 8f2d1cf9b..01a1096d8 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.js.coffee @@ -24,6 +24,11 @@ class App.TaskManager _instance ?= new _Singleton _instance.reset() + @syncInitial: -> + if _instance == undefined + _instance ?= new _Singleton + _instance.syncTasksInitial() + @sync: -> if _instance == undefined _instance ?= new _Singleton @@ -36,26 +41,12 @@ class _Singleton extends App.Controller @tasks = {} @task_count = 0 - # reopen tasks - cache = App.Store.get( 'tasks' ) - if cache - task_count = 0 - for task in cache - task_count += 1 - @delay( - -> - task = cache.shift() - App.TaskManager.add(task.type, task.type_id, task.callback, task.params, true) - task_count * 500 - ) - all: -> @tasks add: ( type, type_id, callback, params, to_not_show = false ) -> for key, task of @tasks if task.type is type && task.type_id is type_id - console.log('STOP TASK, already exists', task) return key if to_not_show $('#content').empty() $('.content_permanent').hide() @@ -138,6 +129,20 @@ class _Singleton extends App.Controller syncLoad: => App.Store.get( 'tasks' ) + syncTasksInitial: => + # reopen tasks + store = _.clone(@syncLoad()) + return if !store + task_count = 0 + for task in store + task_count += 1 + @delay( + => + task = store.shift() + @add(task.type, task.type_id, task.callback, task.params, true) + task_count * 500 + ) + syncTasks: => store = @syncLoad() || []