Improved sync and reopen of tasks.
This commit is contained in:
parent
2dc2287a2d
commit
6e882a7afb
2 changed files with 26 additions and 20 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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() || []
|
||||
|
||||
|
|
Loading…
Reference in a new issue