Improved log backend.
This commit is contained in:
parent
545ef60bdd
commit
076b2e344a
13 changed files with 110 additions and 92 deletions
|
@ -1,4 +1,6 @@
|
||||||
class App.Controller extends Spine.Controller
|
class App.Controller extends Spine.Controller
|
||||||
|
@include App.Log
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
@Config = App.Config
|
@Config = App.Config
|
||||||
|
@ -126,7 +128,6 @@ class App.Controller extends Spine.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
authenticate: ->
|
authenticate: ->
|
||||||
console.log 'authenticate', @Session.all()
|
|
||||||
|
|
||||||
# return rtue if session exists
|
# return rtue if session exists
|
||||||
return true if @Session.get( 'id' )
|
return true if @Session.get( 'id' )
|
||||||
|
|
|
@ -13,6 +13,8 @@ class App.ControllerForm extends App.Controller
|
||||||
@form.html()
|
@form.html()
|
||||||
|
|
||||||
formGen: ->
|
formGen: ->
|
||||||
|
App.Log.log 'ControllerForm', 'debug', 'formGen', @model.configure_attributes
|
||||||
|
|
||||||
fieldset = $('<fieldset>')
|
fieldset = $('<fieldset>')
|
||||||
|
|
||||||
for attribute_clean in @model.configure_attributes
|
for attribute_clean in @model.configure_attributes
|
||||||
|
@ -135,6 +137,9 @@ class App.ControllerForm extends App.Controller
|
||||||
else
|
else
|
||||||
attribute.value = ''
|
attribute.value = ''
|
||||||
|
|
||||||
|
App.Log.log 'ControllerForm', 'debug', 'formGenItem-before', attribute
|
||||||
|
|
||||||
|
|
||||||
# build options list based on config
|
# build options list based on config
|
||||||
@_getConfigOptionList( attribute )
|
@_getConfigOptionList( attribute )
|
||||||
|
|
||||||
|
@ -189,7 +194,7 @@ class App.ControllerForm extends App.Controller
|
||||||
counter = 0
|
counter = 0
|
||||||
for key of loopData
|
for key of loopData
|
||||||
counter =+ 1
|
counter =+ 1
|
||||||
@log 'kkk', key, loopData[ key ]
|
# @log 'kkk', key, loopData[ key ]
|
||||||
|
|
||||||
# clone to keep it untouched for next loop
|
# clone to keep it untouched for next loop
|
||||||
select = _.clone( attribute )
|
select = _.clone( attribute )
|
||||||
|
@ -309,12 +314,12 @@ class App.ControllerForm extends App.Controller
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
###
|
###
|
||||||
@log '111111', @local_attribute_full, item
|
# @log '111111', @local_attribute_full, item
|
||||||
$(@local_attribute_full).autocomplete(
|
$(@local_attribute_full).autocomplete(
|
||||||
source: '/api/users/search',
|
source: '/api/users/search',
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
select: ( event, ui ) =>
|
select: ( event, ui ) =>
|
||||||
@log 'selected', event, ui
|
# @log 'selected', event, ui
|
||||||
b(event, ui.item.id)
|
b(event, ui.item.id)
|
||||||
)
|
)
|
||||||
@delay( a, 600 )
|
@delay( a, 600 )
|
||||||
|
@ -324,7 +329,7 @@ class App.ControllerForm extends App.Controller
|
||||||
item = $( App.view('generic/input')( attribute: attribute ) )
|
item = $( App.view('generic/input')( attribute: attribute ) )
|
||||||
|
|
||||||
if attribute.onchange
|
if attribute.onchange
|
||||||
@log 'on change', attribute.name
|
# @log 'on change', attribute.name
|
||||||
if typeof attribute.onchange is 'function'
|
if typeof attribute.onchange is 'function'
|
||||||
attribute.onchange(attribute)
|
attribute.onchange(attribute)
|
||||||
else
|
else
|
||||||
|
@ -332,13 +337,13 @@ class App.ControllerForm extends App.Controller
|
||||||
a = i.split(/__/)
|
a = i.split(/__/)
|
||||||
if a[1]
|
if a[1]
|
||||||
if a[0] is attribute.name
|
if a[0] is attribute.name
|
||||||
@log 'aaa', i, a[0], attribute.id
|
# @log 'aaa', i, a[0], attribute.id
|
||||||
@attribute = attribute
|
@attribute = attribute
|
||||||
@classname = classname
|
@classname = classname
|
||||||
@attributes_clean = attributes_clean
|
@attributes_clean = attributes_clean
|
||||||
@change = a
|
@change = a
|
||||||
b = =>
|
b = =>
|
||||||
console.log 'aaa', @attribute
|
# console.log 'aaa', @attribute
|
||||||
attribute = @attribute
|
attribute = @attribute
|
||||||
change = @change
|
change = @change
|
||||||
classname = @classname
|
classname = @classname
|
||||||
|
@ -446,8 +451,21 @@ class App.ControllerForm extends App.Controller
|
||||||
attribute.options = []
|
attribute.options = []
|
||||||
|
|
||||||
list = []
|
list = []
|
||||||
if attribute.filter && attribute.filter[attribute.name]
|
if attribute.filter
|
||||||
filter = attribute.filter[attribute.name]
|
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter', attribute.filter
|
||||||
|
|
||||||
|
# function based filter
|
||||||
|
if typeof attribute.filter is 'function'
|
||||||
|
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter-function'
|
||||||
|
|
||||||
|
all = App[attribute.relation].all()
|
||||||
|
list = attribute.filter( all )
|
||||||
|
|
||||||
|
# data based filter
|
||||||
|
else if attribute.filter[ attribute.name ]
|
||||||
|
filter = attribute.filter[ attribute.name ]
|
||||||
|
|
||||||
|
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter-data', filter
|
||||||
|
|
||||||
# check all records
|
# check all records
|
||||||
for record in App[attribute.relation].all()
|
for record in App[attribute.relation].all()
|
||||||
|
@ -459,8 +477,16 @@ class App.ControllerForm extends App.Controller
|
||||||
# if it's matching, use it for selection
|
# if it's matching, use it for selection
|
||||||
if record['id'] is key
|
if record['id'] is key
|
||||||
list.push record
|
list.push record
|
||||||
|
|
||||||
|
# no data filter matched
|
||||||
else
|
else
|
||||||
|
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter-data no filter matched'
|
||||||
list = App[attribute.relation].all()
|
list = App[attribute.relation].all()
|
||||||
|
else
|
||||||
|
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter-no filter defined'
|
||||||
|
list = App[attribute.relation].all()
|
||||||
|
|
||||||
|
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList', attribute, list
|
||||||
|
|
||||||
# build options list
|
# build options list
|
||||||
@_buildOptionList( list, attribute )
|
@_buildOptionList( list, attribute )
|
||||||
|
@ -528,7 +554,7 @@ class App.ControllerForm extends App.Controller
|
||||||
else if $(form).parents().find('form')[0]
|
else if $(form).parents().find('form')[0]
|
||||||
form = $(form).parents().find('form')
|
form = $(form).parents().find('form')
|
||||||
else
|
else
|
||||||
console.log 'ERROR, no form found!', form
|
App.Log.log 'ControllerForm', 'error', 'no form found!', form
|
||||||
|
|
||||||
array = form.serializeArray()
|
array = form.serializeArray()
|
||||||
for key in array
|
for key in array
|
||||||
|
@ -555,7 +581,7 @@ class App.ControllerForm extends App.Controller
|
||||||
for key of param
|
for key of param
|
||||||
attributeType = key.split '::'
|
attributeType = key.split '::'
|
||||||
name = attributeType[1]
|
name = attributeType[1]
|
||||||
console.log 'split', key, attributeType, param[ name ]
|
# console.log 'split', key, attributeType, param[ name ]
|
||||||
if attributeType[0] is '{input_select}' && !param[ name ]
|
if attributeType[0] is '{input_select}' && !param[ name ]
|
||||||
|
|
||||||
# array need to be converted
|
# array need to be converted
|
||||||
|
@ -573,19 +599,19 @@ class App.ControllerForm extends App.Controller
|
||||||
for key of inputSelectObject
|
for key of inputSelectObject
|
||||||
param[ key ] = inputSelectObject[ key ]
|
param[ key ] = inputSelectObject[ key ]
|
||||||
|
|
||||||
console.log 'formParam', form, param
|
App.Log.log 'ControllerForm', 'notice', 'formParam', form, param
|
||||||
return param
|
return param
|
||||||
|
|
||||||
|
|
||||||
@disable: (form) ->
|
@disable: (form) ->
|
||||||
console.log 'disable...', $(form.target).parent()
|
App.Log.log 'ControllerForm', 'notice', 'disable...', $(form.target).parent()
|
||||||
$(form.target).parent().find('button').attr('disabled', true)
|
$(form.target).parent().find('button').attr('disabled', true)
|
||||||
$(form.target).parent().find('[type="submit"]').attr('disabled', true)
|
$(form.target).parent().find('[type="submit"]').attr('disabled', true)
|
||||||
$(form.target).parent().find('[type="reset"]').attr('disabled', true)
|
$(form.target).parent().find('[type="reset"]').attr('disabled', true)
|
||||||
|
|
||||||
|
|
||||||
@enable: (form) ->
|
@enable: (form) ->
|
||||||
console.log 'enable...', $(form).parent()
|
App.Log.log 'ControllerForm', 'notice', 'enable...', $(form).parent()
|
||||||
$(form).parent().find('button').attr('disabled', false)
|
$(form).parent().find('button').attr('disabled', false)
|
||||||
$(form).parent().find('[type="submit"]').attr('disabled', false)
|
$(form).parent().find('[type="submit"]').attr('disabled', false)
|
||||||
$(form).parent().find('[type="reset"]').attr('disabled', false)
|
$(form).parent().find('[type="reset"]').attr('disabled', false)
|
||||||
|
|
|
@ -109,7 +109,7 @@ class App.ControllerTable extends App.Controller
|
||||||
record = App.Collection.find( attribute.relation, object[rowWithoutId] )
|
record = App.Collection.find( attribute.relation, object[rowWithoutId] )
|
||||||
object[row.name] = record.name
|
object[row.name] = record.name
|
||||||
|
|
||||||
@log 'table', 'header', header, 'overview', dataTypesForCols, 'objects', data.objects
|
@log 'ControllerTable', 'debug', 'table', 'header', header, 'overview', dataTypesForCols, 'objects', data.objects
|
||||||
table = App.view('generic/table')(
|
table = App.view('generic/table')(
|
||||||
header: header
|
header: header
|
||||||
overview: dataTypesForCols
|
overview: dataTypesForCols
|
||||||
|
|
|
@ -111,6 +111,8 @@ class Index extends App.Controller
|
||||||
class: 'active' if @view_mode is 'm'
|
class: 'active' if @view_mode is 'm'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
if @isRole('Customer')
|
||||||
|
view_modes = []
|
||||||
html = App.view('agent_ticket_view')(
|
html = App.view('agent_ticket_view')(
|
||||||
overview: @overview
|
overview: @overview
|
||||||
view_modes: view_modes
|
view_modes: view_modes
|
||||||
|
|
|
@ -84,10 +84,18 @@ class Index extends App.Controller
|
||||||
if !( 'ticket_priority_id' of defaults )
|
if !( 'ticket_priority_id' of defaults )
|
||||||
defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' )
|
defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' )
|
||||||
|
|
||||||
|
groupFilter = (collection) =>
|
||||||
|
_.filter(
|
||||||
|
collection
|
||||||
|
(item) ->
|
||||||
|
return item if item.name is 'Support'
|
||||||
|
return item if item.name is 'Sales'
|
||||||
|
)
|
||||||
|
|
||||||
# generate form
|
# generate form
|
||||||
configure_attributes = [
|
configure_attributes = [
|
||||||
# { name: 'customer_id', display: 'Customer', tag: 'autocompletion', type: 'text', limit: 100, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">»</a>', callback: @userInfo },
|
# { name: 'customer_id', display: 'Customer', tag: 'autocompletion', type: 'text', limit: 100, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">»</a>', callback: @userInfo },
|
||||||
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: @edit_form, nulloption: true, relation: 'Group', default: defaults['group_id'], class: 'span7', },
|
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: groupFilter, nulloption: true, relation: 'Group', default: defaults['group_id'], class: 'span7', },
|
||||||
# { name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, filter: @edit_form, nulloption: true, relation: 'User', default: defaults['owner_id'], class: 'span7', },
|
# { name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, filter: @edit_form, nulloption: true, relation: 'User', default: defaults['owner_id'], class: 'span7', },
|
||||||
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: false, default: defaults['subject'], class: 'span7', },
|
{ name: 'subject', display: 'Subject', tag: 'input', type: 'text', limit: 100, null: false, default: defaults['subject'], class: 'span7', },
|
||||||
{ name: 'body', display: 'Text', tag: 'textarea', rows: 10, null: false, default: defaults['body'], class: 'span7', },
|
{ name: 'body', display: 'Text', tag: 'textarea', rows: 10, null: false, default: defaults['body'], class: 'span7', },
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
$ = jQuery.sub()
|
|
||||||
|
|
||||||
class Index extends App.Controller
|
|
||||||
# events:
|
|
||||||
# 'submit form': 'submit',
|
|
||||||
# 'click .submit': 'submit',
|
|
||||||
# 'click .cancel': 'cancel',
|
|
||||||
|
|
||||||
constructor: (params) ->
|
|
||||||
super
|
|
||||||
|
|
||||||
# check authentication
|
|
||||||
return if !@authenticate()
|
|
||||||
|
|
||||||
# set title
|
|
||||||
@title 'My Tickets'
|
|
||||||
# @fetch(params)
|
|
||||||
@navupdate '#customer_tickets'
|
|
||||||
|
|
||||||
@render()
|
|
||||||
|
|
||||||
render: ->
|
|
||||||
|
|
||||||
@html App.view('agent_ticket_view')(
|
|
||||||
head: 'My Ticket',
|
|
||||||
# form: @formGen( model: { configure_attributes: configure_attributes, className: 'create' } ),
|
|
||||||
)
|
|
||||||
|
|
||||||
App.Config.set( 'customer_tickets', Index, 'Routes' )
|
|
||||||
|
|
||||||
#App.Config.set( 'CustomerTickets', { prio: 1700, parent: '', name: 'My Tickets', target: '#ticket_view/my_tickets', role: ['Customer'] }, 'NavBar' )
|
|
|
@ -3,7 +3,6 @@ $ = jQuery.sub()
|
||||||
class App.Navigation extends App.Controller
|
class App.Navigation extends App.Controller
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
@log 'nav...'
|
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
# update selected item
|
# update selected item
|
||||||
|
@ -12,7 +11,7 @@ class App.Navigation extends App.Controller
|
||||||
|
|
||||||
# rebuild nav bar with given user data
|
# rebuild nav bar with given user data
|
||||||
App.Event.bind 'ajax:auth', (user) =>
|
App.Event.bind 'ajax:auth', (user) =>
|
||||||
@log 'navbar rebuild', user
|
@log 'Navigation', 'notice', 'navbar rebuild', user
|
||||||
|
|
||||||
if !_.isEmpty( user )
|
if !_.isEmpty( user )
|
||||||
cache = App.Store.get( 'navupdate_ticket_overview' )
|
cache = App.Store.get( 'navupdate_ticket_overview' )
|
||||||
|
|
|
@ -20,17 +20,22 @@ class App.Session
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
_instance.all()
|
_instance.all()
|
||||||
|
|
||||||
class _Singleton
|
class _Singleton extends Spine.Module
|
||||||
|
@include App.Log
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@clear()
|
@clear()
|
||||||
|
# @log = App.LogModule
|
||||||
|
|
||||||
clear: ->
|
clear: ->
|
||||||
@data = {}
|
@data = {}
|
||||||
|
|
||||||
get: ( key ) ->
|
get: ( key ) ->
|
||||||
|
@log 'Session', 'debug', key, @data[key]
|
||||||
return @data[key]
|
return @data[key]
|
||||||
|
|
||||||
set: ( key, value ) ->
|
set: ( key, value ) ->
|
||||||
|
@log 'Session', 'debug', 'set', key, value
|
||||||
@data[key] = value
|
@data[key] = value
|
||||||
|
|
||||||
all: ->
|
all: ->
|
||||||
|
|
|
@ -3,7 +3,7 @@ $ = jQuery.sub()
|
||||||
class App.Auth
|
class App.Auth
|
||||||
|
|
||||||
@login: (params) ->
|
@login: (params) ->
|
||||||
console.log 'login(...)', params
|
App.Log.log 'Auth', 'notice', 'login', params
|
||||||
App.Com.ajax(
|
App.Com.ajax(
|
||||||
id: 'login',
|
id: 'login',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
@ -22,14 +22,14 @@ class App.Auth
|
||||||
)
|
)
|
||||||
|
|
||||||
@loginCheck: ->
|
@loginCheck: ->
|
||||||
console.log 'loginCheck(...)'
|
App.Log.log 'Auth', 'notice', 'loginCheck'
|
||||||
App.Com.ajax(
|
App.Com.ajax(
|
||||||
id: 'login_check',
|
id: 'login_check',
|
||||||
async: false,
|
async: false,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/signshow',
|
url: '/signshow',
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
console.log 'logincheck:success', data
|
App.Log.log 'Auth', 'notice', 'logincheck:success', data
|
||||||
|
|
||||||
# if session is not valid
|
# if session is not valid
|
||||||
if data.error
|
if data.error
|
||||||
|
@ -72,7 +72,7 @@ class App.Auth
|
||||||
App.Event.trigger 'ajax:auth', data.session
|
App.Event.trigger 'ajax:auth', data.session
|
||||||
|
|
||||||
error: (xhr, statusText, error) =>
|
error: (xhr, statusText, error) =>
|
||||||
console.log 'loginCheck:error'#, error, statusText, xhr.statusCode
|
App.Log.log 'Auth', 'notice', 'logincheck:error'
|
||||||
|
|
||||||
# empty session
|
# empty session
|
||||||
App.Session.init()
|
App.Session.init()
|
||||||
|
@ -85,7 +85,7 @@ class App.Auth
|
||||||
)
|
)
|
||||||
|
|
||||||
@logout: ->
|
@logout: ->
|
||||||
console.log 'logout(...)'
|
App.Log.log 'Auth', 'notice', 'logout'
|
||||||
App.Com.ajax(
|
App.Com.ajax(
|
||||||
id: 'logout',
|
id: 'logout',
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
|
|
|
@ -64,7 +64,8 @@ class App.Collection
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
_instance._observeStats()
|
_instance._observeStats()
|
||||||
|
|
||||||
class _Singleton
|
class _Singleton extends Spine.Module
|
||||||
|
@include App.Log
|
||||||
|
|
||||||
constructor: (@args) ->
|
constructor: (@args) ->
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ class _Singleton
|
||||||
if data.collections
|
if data.collections
|
||||||
for type of data.collections
|
for type of data.collections
|
||||||
|
|
||||||
console.log 'loadCollection:trigger', type, data.collections[type]
|
@log 'Collection', 'debug', 'loadCollection:trigger', type, data.collections[type]
|
||||||
@load( localStorage: data.localStorage, type: type, data: data.collections[type] )
|
@load( localStorage: data.localStorage, type: type, data: data.collections[type] )
|
||||||
|
|
||||||
# add trigger - bind new events
|
# add trigger - bind new events
|
||||||
|
@ -85,7 +86,7 @@ class _Singleton
|
||||||
if data.collections
|
if data.collections
|
||||||
for type of data.collections
|
for type of data.collections
|
||||||
|
|
||||||
console.log 'resetCollection:trigger', type, data.collections[type]
|
@log 'Collection', 'debug', 'resetCollection:trigger', type, data.collections[type]
|
||||||
@reset( localStorage: data.localStorage, type: type, data: data.collections[type] )
|
@reset( localStorage: data.localStorage, type: type, data: data.collections[type] )
|
||||||
|
|
||||||
# find collections to load
|
# find collections to load
|
||||||
|
@ -98,11 +99,11 @@ class _Singleton
|
||||||
if parts[0] is 'collection'
|
if parts[0] is 'collection'
|
||||||
data = App.Store.get( key )
|
data = App.Store.get( key )
|
||||||
if data && data.localStorage
|
if data && data.localStorage
|
||||||
console.log('load INIT', data)
|
@log 'Collection', 'debug', 'load INIT', data
|
||||||
@load( data )
|
@load( data )
|
||||||
|
|
||||||
reset: (params) ->
|
reset: (params) ->
|
||||||
console.log( 'reset', params )
|
@log 'Collection', 'debug', 'reset', params
|
||||||
|
|
||||||
# empty in-memory
|
# empty in-memory
|
||||||
App[ params.type ].refresh( [], { clear: true } )
|
App[ params.type ].refresh( [], { clear: true } )
|
||||||
|
@ -118,7 +119,7 @@ class _Singleton
|
||||||
@load(params)
|
@load(params)
|
||||||
|
|
||||||
load: (params) ->
|
load: (params) ->
|
||||||
console.log( 'load', params )
|
@log 'Collection', 'debug', 'load', params
|
||||||
|
|
||||||
return if _.isEmpty( params.data )
|
return if _.isEmpty( params.data )
|
||||||
|
|
||||||
|
@ -156,9 +157,9 @@ class _Singleton
|
||||||
callback( data )
|
callback( data )
|
||||||
else
|
else
|
||||||
if force
|
if force
|
||||||
console.log( 'find forced to load!', type, id )
|
@log 'Collection', 'debug', 'find forced to load!', type, id
|
||||||
else
|
else
|
||||||
console.log( 'find not loaded!', type, id )
|
@log 'Collection', 'debug', 'find not loaded!', type, id
|
||||||
if callback
|
if callback
|
||||||
|
|
||||||
# execute callback if record got loaded
|
# execute callback if record got loaded
|
||||||
|
@ -251,7 +252,7 @@ class _Singleton
|
||||||
return data
|
return data
|
||||||
|
|
||||||
get: (params) ->
|
get: (params) ->
|
||||||
console.log('get')
|
@log 'Collection', 'debug', 'get', params
|
||||||
App[ params.type ].refresh( object, options: { clear: true } )
|
App[ params.type ].refresh( object, options: { clear: true } )
|
||||||
|
|
||||||
all: (params) ->
|
all: (params) ->
|
||||||
|
|
|
@ -29,7 +29,8 @@ class App.Event
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
_instance._allBindings()
|
_instance._allBindings()
|
||||||
|
|
||||||
class _Singleton
|
class _Singleton extends Spine.Module
|
||||||
|
@include App.Log
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@eventCurrent = {}
|
@eventCurrent = {}
|
||||||
|
@ -59,6 +60,7 @@ class _Singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
# bind
|
# bind
|
||||||
|
@log 'Event', 'debug', 'bind', event, callback
|
||||||
Spine.bind( event, callback )
|
Spine.bind( event, callback )
|
||||||
|
|
||||||
unbind: ( events, callback, level ) ->
|
unbind: ( events, callback, level ) ->
|
||||||
|
@ -79,11 +81,13 @@ class _Singleton
|
||||||
else
|
else
|
||||||
return item if item.event isnt event
|
return item if item.event isnt event
|
||||||
)
|
)
|
||||||
|
@log 'Event', 'debug', 'unbind', event, callback
|
||||||
Spine.unbind( event, callback )
|
Spine.unbind( event, callback )
|
||||||
|
|
||||||
trigger: ( events, data ) ->
|
trigger: ( events, data ) ->
|
||||||
eventList = events.split(' ')
|
eventList = events.split(' ')
|
||||||
for event in eventList
|
for event in eventList
|
||||||
|
@log 'Event', 'debug', 'trigger', event, data
|
||||||
Spine.trigger event, data
|
Spine.trigger event, data
|
||||||
|
|
||||||
_allBindings: ->
|
_allBindings: ->
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
class App.Run extends App.Controller
|
class App.Run extends App.Controller
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
@log 'RUN app'
|
|
||||||
@el = $('#app')
|
@el = $('#app')
|
||||||
|
|
||||||
# init collections
|
# init collections
|
||||||
|
@ -37,13 +36,14 @@ class App.Content extends App.Controller
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
@log 'RUN content'
|
|
||||||
|
|
||||||
Routes = @Config.get( 'Routes' )
|
Routes = @Config.get( 'Routes' )
|
||||||
for route, callback of Routes
|
for route, callback of Routes
|
||||||
do (route, callback) =>
|
do (route, callback) =>
|
||||||
@route(route, (params) ->
|
@route(route, (params) ->
|
||||||
|
|
||||||
|
@log 'Content', 'notice', 'execute page controller', route, params
|
||||||
|
|
||||||
# remove observers for page
|
# remove observers for page
|
||||||
App.Collection.observeUnbindLevel('page')
|
App.Collection.observeUnbindLevel('page')
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ class App.WebSocket
|
||||||
|
|
||||||
# The actual Singleton class
|
# The actual Singleton class
|
||||||
class _Singleton extends App.Controller
|
class _Singleton extends App.Controller
|
||||||
|
@include App.Log
|
||||||
|
|
||||||
queue: []
|
queue: []
|
||||||
supported: true
|
supported: true
|
||||||
lastSpoolMessage: undefined
|
lastSpoolMessage: undefined
|
||||||
|
@ -74,7 +76,9 @@ class _Singleton extends App.Controller
|
||||||
action: 'spool'
|
action: 'spool'
|
||||||
if @lastSpoolMessage
|
if @lastSpoolMessage
|
||||||
data['timestamp'] = @lastSpoolMessage
|
data['timestamp'] = @lastSpoolMessage
|
||||||
@log 'spool', data
|
|
||||||
|
@log 'Event', 'debug', 'spool', data
|
||||||
|
|
||||||
# ask for spool messages
|
# ask for spool messages
|
||||||
App.Event.trigger(
|
App.Event.trigger(
|
||||||
'ws:send'
|
'ws:send'
|
||||||
|
@ -92,25 +96,24 @@ class _Singleton extends App.Controller
|
||||||
ping: =>
|
ping: =>
|
||||||
return if !@supported
|
return if !@supported
|
||||||
|
|
||||||
# console.log 'send websockend ping'
|
@log 'Event', 'debug', 'send websockend ping'
|
||||||
@send( { action: 'ping' } )
|
@send( { action: 'ping' } )
|
||||||
|
|
||||||
# check if ping is back within 2 min
|
# check if ping is back within 2 min
|
||||||
@clearDelay('websocket-ping-check')
|
@clearDelay('websocket-ping-check')
|
||||||
check = =>
|
check = =>
|
||||||
console.log 'no websockend ping response, reconnect...'
|
@log 'Event', 'notice', 'no websockend ping response, reconnect...'
|
||||||
@close()
|
@close()
|
||||||
@delay check, 120000, 'websocket-ping-check'
|
@delay check, 120000, 'websocket-ping-check'
|
||||||
|
|
||||||
pong: ->
|
pong: ->
|
||||||
return if !@supported
|
return if !@supported
|
||||||
# console.log 'received websockend ping'
|
@log 'Event', 'debug', 'received websockend ping'
|
||||||
|
|
||||||
# test again after 1 min
|
# test again after 1 min
|
||||||
@delay @ping, 60000
|
@delay @ping, 60000
|
||||||
|
|
||||||
connect: =>
|
connect: =>
|
||||||
# console.log '------------ws connect....--------------'
|
|
||||||
|
|
||||||
if !window.WebSocket
|
if !window.WebSocket
|
||||||
@error = new App.ErrorModal(
|
@error = new App.ErrorModal(
|
||||||
|
@ -127,7 +130,7 @@ class _Singleton extends App.Controller
|
||||||
|
|
||||||
# Set event handlers.
|
# Set event handlers.
|
||||||
@ws.onopen = =>
|
@ws.onopen = =>
|
||||||
console.log( 'onopen' )
|
@log 'Event', 'notice', 'new websocked connection open'
|
||||||
|
|
||||||
@connectionEstablished = true
|
@connectionEstablished = true
|
||||||
|
|
||||||
|
@ -141,7 +144,7 @@ class _Singleton extends App.Controller
|
||||||
|
|
||||||
# empty queue
|
# empty queue
|
||||||
for item in @queue
|
for item in @queue
|
||||||
# console.log( 'ws:send queue', item )
|
@log 'Event', 'debug', 'empty ws queue', item
|
||||||
@send(item)
|
@send(item)
|
||||||
@queue = []
|
@queue = []
|
||||||
|
|
||||||
|
@ -150,7 +153,7 @@ class _Singleton extends App.Controller
|
||||||
|
|
||||||
@ws.onmessage = (e) =>
|
@ws.onmessage = (e) =>
|
||||||
pipe = JSON.parse( e.data )
|
pipe = JSON.parse( e.data )
|
||||||
console.log( 'ws:onmessage', pipe )
|
@log 'Event', 'debug', 'ws:onmessage', pipe
|
||||||
|
|
||||||
# go through all blocks
|
# go through all blocks
|
||||||
for item in pipe
|
for item in pipe
|
||||||
|
@ -161,21 +164,21 @@ class _Singleton extends App.Controller
|
||||||
|
|
||||||
# fill collection
|
# fill collection
|
||||||
if item['collection']
|
if item['collection']
|
||||||
console.log( "ws:onmessage collection:" + item['collection'] )
|
@log 'Event', 'debug', "ws:onmessage collection:" + item['collection']
|
||||||
App.Store.write( item['collection'], item['data'] )
|
App.Store.write( item['collection'], item['data'] )
|
||||||
|
|
||||||
# fire event
|
# fire event
|
||||||
if item['event']
|
if item['event']
|
||||||
if typeof item['event'] is 'object'
|
if typeof item['event'] is 'object'
|
||||||
for event in item['event']
|
for event in item['event']
|
||||||
console.log( "ws:onmessage event:" + event )
|
@log 'Event', 'debug', "ws:onmessage event:" + event
|
||||||
App.Event.trigger( event, item['data'] )
|
App.Event.trigger( event, item['data'] )
|
||||||
else
|
else
|
||||||
console.log( "ws:onmessage event:" + item['event'] )
|
@log 'Event', 'debug', "ws:onmessage event:" + item['event']
|
||||||
App.Event.trigger( item['event'], item['data'] )
|
App.Event.trigger( item['event'], item['data'] )
|
||||||
|
|
||||||
@ws.onclose = (e) =>
|
@ws.onclose = (e) =>
|
||||||
console.log( 'onclose', e )
|
@log 'Event', 'debug', "ws:onclose", e
|
||||||
|
|
||||||
# set timestamp to get spool messages later
|
# set timestamp to get spool messages later
|
||||||
if @connectionEstablished
|
if @connectionEstablished
|
||||||
|
@ -193,6 +196,6 @@ class _Singleton extends App.Controller
|
||||||
# try reconnect after 4.5 sec.
|
# try reconnect after 4.5 sec.
|
||||||
@delay @connect, 4500
|
@delay @connect, 4500
|
||||||
|
|
||||||
@ws.onerror = ->
|
@ws.onerror = (e) =>
|
||||||
console.log( 'onerror' )
|
@log 'Event', 'debug', "ws:onerror", e
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue