Init version of session disable to only have one active browser window with tasks.
This commit is contained in:
parent
37321055fd
commit
b7a675874c
7 changed files with 126 additions and 8 deletions
|
@ -439,7 +439,8 @@ class App.ErrorModal extends App.ControllerModal
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
@html App.view('error')(
|
@html App.view('modal')(
|
||||||
|
title: 'Error',
|
||||||
message: @message
|
message: @message
|
||||||
detail: @detail
|
detail: @detail
|
||||||
close: @close
|
close: @close
|
||||||
|
@ -448,3 +449,40 @@ class App.ErrorModal extends App.ControllerModal
|
||||||
backdrop: false,
|
backdrop: false,
|
||||||
keyboard: false,
|
keyboard: false,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class App.SessionReloadModal extends App.ControllerModal
|
||||||
|
constructor: ->
|
||||||
|
super
|
||||||
|
@render()
|
||||||
|
|
||||||
|
render: ->
|
||||||
|
@html App.view('modal')(
|
||||||
|
title: @title || '?'
|
||||||
|
message: @message || '?'
|
||||||
|
detail: @detail
|
||||||
|
close: @close
|
||||||
|
button: @button
|
||||||
|
)
|
||||||
|
@modalShow(
|
||||||
|
backdrop: @backdrop,
|
||||||
|
keyboard: @keyboard,
|
||||||
|
)
|
||||||
|
|
||||||
|
modalHide: (e) ->
|
||||||
|
@reload(e)
|
||||||
|
|
||||||
|
submit: (e) ->
|
||||||
|
@reload(e)
|
||||||
|
|
||||||
|
reload: (e) ->
|
||||||
|
if e
|
||||||
|
e.preventDefault()
|
||||||
|
if window.location.reload
|
||||||
|
window.location.reload()
|
||||||
|
return true
|
||||||
|
if window.location.href
|
||||||
|
window.location.href = window.location.href
|
||||||
|
return true
|
||||||
|
|
||||||
|
throw "Cant reload page!"
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,34 @@ class App.TaskWidget extends App.Controller
|
||||||
App.TaskManager.reset()
|
App.TaskManager.reset()
|
||||||
@el.html('')
|
@el.html('')
|
||||||
|
|
||||||
|
# only do take over check after spool messages are finised
|
||||||
|
App.Event.bind 'spool:sent', (data) =>
|
||||||
|
@spoolSent = true
|
||||||
|
|
||||||
|
# session take over message
|
||||||
|
App.Event.bind 'session:takeover', (data) =>
|
||||||
|
|
||||||
|
# only if spool messages are already sent
|
||||||
|
return if !@spoolSent
|
||||||
|
|
||||||
|
# check if error message is already shown
|
||||||
|
if !@error
|
||||||
|
|
||||||
|
# only if new client id isnt own client id
|
||||||
|
if data.client_id isnt App.TaskManager.clientId()
|
||||||
|
@error = new App.SessionReloadModal(
|
||||||
|
title: 'Session'
|
||||||
|
message: 'Session taken over... please reload page or work with other browser window.'
|
||||||
|
keyboard: false
|
||||||
|
backdrop: true
|
||||||
|
close: true
|
||||||
|
button: 'Reload application'
|
||||||
|
)
|
||||||
|
|
||||||
|
# disable all delay's and interval's
|
||||||
|
App.Delay.reset()
|
||||||
|
App.Interval.reset()
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
|
|
||||||
return if _.isEmpty( @Session.all() )
|
return if _.isEmpty( @Session.all() )
|
||||||
|
|
|
@ -16,6 +16,11 @@ class App.Delay
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
_instance.clearLevel( level )
|
_instance.clearLevel( level )
|
||||||
|
|
||||||
|
@reset: ( level ) ->
|
||||||
|
if _instance == undefined
|
||||||
|
_instance ?= new _Singleton
|
||||||
|
_instance.reset( level )
|
||||||
|
|
||||||
@_all: ->
|
@_all: ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
|
@ -78,6 +83,12 @@ class _Singleton extends Spine.Module
|
||||||
@clear( key, level )
|
@clear( key, level )
|
||||||
@levelStack[level] = {}
|
@levelStack[level] = {}
|
||||||
|
|
||||||
|
reset: ->
|
||||||
|
for level, items of @levelStack
|
||||||
|
for key, data of items
|
||||||
|
@clear( key, level )
|
||||||
|
@levelStack[level] = {}
|
||||||
|
|
||||||
_all: ->
|
_all: ->
|
||||||
return @levelStack
|
return @levelStack
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,11 @@ class App.Interval
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
_instance.clearLevel( level )
|
_instance.clearLevel( level )
|
||||||
|
|
||||||
|
@reset: ( level ) ->
|
||||||
|
if _instance == undefined
|
||||||
|
_instance ?= new _Singleton
|
||||||
|
_instance.reset( level )
|
||||||
|
|
||||||
@_all: ->
|
@_all: ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
|
@ -76,5 +81,11 @@ class _Singleton extends Spine.Module
|
||||||
@clear( key, level )
|
@clear( key, level )
|
||||||
@levelStack[level] = {}
|
@levelStack[level] = {}
|
||||||
|
|
||||||
|
reset: ->
|
||||||
|
for level, items of @levelStack
|
||||||
|
for key, data of items
|
||||||
|
@clear( key, level )
|
||||||
|
@levelStack[level] = {}
|
||||||
|
|
||||||
_all: ->
|
_all: ->
|
||||||
return @levelStack
|
return @levelStack
|
||||||
|
|
|
@ -54,6 +54,11 @@ class App.TaskManager
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
_instance.workerAll()
|
_instance.workerAll()
|
||||||
|
|
||||||
|
@clientId: ->
|
||||||
|
if _instance == undefined
|
||||||
|
_instance ?= new _Singleton
|
||||||
|
_instance.clientId()
|
||||||
|
|
||||||
class _Singleton extends App.Controller
|
class _Singleton extends App.Controller
|
||||||
@include App.Log
|
@include App.Log
|
||||||
|
|
||||||
|
@ -230,6 +235,7 @@ class _Singleton extends App.Controller
|
||||||
if !task
|
if !task
|
||||||
throw "No such task with '#{key}' of order"
|
throw "No such task with '#{key}' of order"
|
||||||
prio++
|
prio++
|
||||||
|
if task.prio isnt prio
|
||||||
task.prio = prio
|
task.prio = prio
|
||||||
task.save()
|
task.save()
|
||||||
|
|
||||||
|
@ -237,11 +243,30 @@ class _Singleton extends App.Controller
|
||||||
App.Taskbar.deleteAll()
|
App.Taskbar.deleteAll()
|
||||||
App.Event.trigger 'ui:rerender'
|
App.Event.trigger 'ui:rerender'
|
||||||
|
|
||||||
|
clientId: =>
|
||||||
|
if !@clientIdInt
|
||||||
|
@clientIdInt = Math.floor( Math.random() * 99999999 )
|
||||||
|
@clientIdInt
|
||||||
|
|
||||||
tasksInitial: =>
|
tasksInitial: =>
|
||||||
# reopen tasks
|
# reopen tasks
|
||||||
# App.Taskbar.fetch()
|
# App.Taskbar.fetch()
|
||||||
tasks = @all()
|
tasks = @all()
|
||||||
return if !tasks
|
return if !tasks
|
||||||
|
|
||||||
|
# check if we have different
|
||||||
|
|
||||||
|
# broadcast to other browser instance
|
||||||
|
App.WebSocket.send(
|
||||||
|
action: 'broadcast'
|
||||||
|
event: 'session:takeover'
|
||||||
|
spool: true
|
||||||
|
data:
|
||||||
|
recipient:
|
||||||
|
user_id: [ App.Session.get( 'id' ) ]
|
||||||
|
client_id: @clientId()
|
||||||
|
)
|
||||||
|
|
||||||
task_count = 0
|
task_count = 0
|
||||||
for task in tasks
|
for task in tasks
|
||||||
task_count += 1
|
task_count += 1
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<% if @close: %>
|
<% if @close: %>
|
||||||
<a href="#" class="close">×</a>
|
<a href="#" class="close">×</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
<h2><%- @T( 'Error' ) %></h2>
|
<h2><%- @T( @title ) %></h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form class="form-horizontal">
|
<form class="form-horizontal">
|
||||||
|
@ -13,8 +13,10 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<!--
|
<% if @button: %>
|
||||||
<button class="btn btn-primary submit"><%- @T( 'Submit' ) %></button>
|
<button class="btn btn-primary submit"><%- @T( @button ) %></button>
|
||||||
|
<% end %>
|
||||||
|
<% if @cancel: %>
|
||||||
<button class="btn cancel"><%- @T( 'Cancel' ) %></button>
|
<button class="btn cancel"><%- @T( 'Cancel' ) %></button>
|
||||||
-->
|
<% end %>
|
||||||
</div>
|
</div>
|
|
@ -172,6 +172,9 @@ EventMachine.run {
|
||||||
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# send spool:sent event to client
|
||||||
|
@clients[client_id][:websocket].send( '[{"event":"spool:sent"}]' )
|
||||||
end
|
end
|
||||||
|
|
||||||
# get session
|
# get session
|
||||||
|
|
Loading…
Reference in a new issue