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: ->
|
||||
@html App.view('error')(
|
||||
@html App.view('modal')(
|
||||
title: 'Error',
|
||||
message: @message
|
||||
detail: @detail
|
||||
close: @close
|
||||
|
@ -448,3 +449,40 @@ class App.ErrorModal extends App.ControllerModal
|
|||
backdrop: 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()
|
||||
@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: ->
|
||||
|
||||
return if _.isEmpty( @Session.all() )
|
||||
|
|
|
@ -16,6 +16,11 @@ class App.Delay
|
|||
_instance ?= new _Singleton
|
||||
_instance.clearLevel( level )
|
||||
|
||||
@reset: ( level ) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.reset( level )
|
||||
|
||||
@_all: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
|
@ -78,6 +83,12 @@ class _Singleton extends Spine.Module
|
|||
@clear( key, level )
|
||||
@levelStack[level] = {}
|
||||
|
||||
reset: ->
|
||||
for level, items of @levelStack
|
||||
for key, data of items
|
||||
@clear( key, level )
|
||||
@levelStack[level] = {}
|
||||
|
||||
_all: ->
|
||||
return @levelStack
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ class App.Interval
|
|||
_instance ?= new _Singleton
|
||||
_instance.clearLevel( level )
|
||||
|
||||
@reset: ( level ) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.reset( level )
|
||||
|
||||
@_all: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
|
@ -76,5 +81,11 @@ class _Singleton extends Spine.Module
|
|||
@clear( key, level )
|
||||
@levelStack[level] = {}
|
||||
|
||||
reset: ->
|
||||
for level, items of @levelStack
|
||||
for key, data of items
|
||||
@clear( key, level )
|
||||
@levelStack[level] = {}
|
||||
|
||||
_all: ->
|
||||
return @levelStack
|
||||
|
|
|
@ -54,6 +54,11 @@ class App.TaskManager
|
|||
_instance ?= new _Singleton
|
||||
_instance.workerAll()
|
||||
|
||||
@clientId: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.clientId()
|
||||
|
||||
class _Singleton extends App.Controller
|
||||
@include App.Log
|
||||
|
||||
|
@ -230,6 +235,7 @@ class _Singleton extends App.Controller
|
|||
if !task
|
||||
throw "No such task with '#{key}' of order"
|
||||
prio++
|
||||
if task.prio isnt prio
|
||||
task.prio = prio
|
||||
task.save()
|
||||
|
||||
|
@ -237,11 +243,30 @@ class _Singleton extends App.Controller
|
|||
App.Taskbar.deleteAll()
|
||||
App.Event.trigger 'ui:rerender'
|
||||
|
||||
clientId: =>
|
||||
if !@clientIdInt
|
||||
@clientIdInt = Math.floor( Math.random() * 99999999 )
|
||||
@clientIdInt
|
||||
|
||||
tasksInitial: =>
|
||||
# reopen tasks
|
||||
# App.Taskbar.fetch()
|
||||
tasks = @all()
|
||||
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
|
||||
for task in tasks
|
||||
task_count += 1
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<% if @close: %>
|
||||
<a href="#" class="close">×</a>
|
||||
<% end %>
|
||||
<h2><%- @T( 'Error' ) %></h2>
|
||||
<h2><%- @T( @title ) %></h2>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal">
|
||||
|
@ -13,8 +13,10 @@
|
|||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<!--
|
||||
<button class="btn btn-primary submit"><%- @T( 'Submit' ) %></button>
|
||||
<% if @button: %>
|
||||
<button class="btn btn-primary submit"><%- @T( @button ) %></button>
|
||||
<% end %>
|
||||
<% if @cancel: %>
|
||||
<button class="btn cancel"><%- @T( 'Cancel' ) %></button>
|
||||
-->
|
||||
<% end %>
|
||||
</div>
|
|
@ -172,6 +172,9 @@ EventMachine.run {
|
|||
|
||||
end
|
||||
}
|
||||
|
||||
# send spool:sent event to client
|
||||
@clients[client_id][:websocket].send( '[{"event":"spool:sent"}]' )
|
||||
end
|
||||
|
||||
# get session
|
||||
|
|
Loading…
Reference in a new issue