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
|
||||
@include App.Log
|
||||
|
||||
constructor: ->
|
||||
super
|
||||
@Config = App.Config
|
||||
|
@ -126,7 +128,6 @@ class App.Controller extends Spine.Controller
|
|||
)
|
||||
|
||||
authenticate: ->
|
||||
console.log 'authenticate', @Session.all()
|
||||
|
||||
# return rtue if session exists
|
||||
return true if @Session.get( 'id' )
|
||||
|
|
|
@ -13,6 +13,8 @@ class App.ControllerForm extends App.Controller
|
|||
@form.html()
|
||||
|
||||
formGen: ->
|
||||
App.Log.log 'ControllerForm', 'debug', 'formGen', @model.configure_attributes
|
||||
|
||||
fieldset = $('<fieldset>')
|
||||
|
||||
for attribute_clean in @model.configure_attributes
|
||||
|
@ -135,6 +137,9 @@ class App.ControllerForm extends App.Controller
|
|||
else
|
||||
attribute.value = ''
|
||||
|
||||
App.Log.log 'ControllerForm', 'debug', 'formGenItem-before', attribute
|
||||
|
||||
|
||||
# build options list based on config
|
||||
@_getConfigOptionList( attribute )
|
||||
|
||||
|
@ -189,7 +194,7 @@ class App.ControllerForm extends App.Controller
|
|||
counter = 0
|
||||
for key of loopData
|
||||
counter =+ 1
|
||||
@log 'kkk', key, loopData[ key ]
|
||||
# @log 'kkk', key, loopData[ key ]
|
||||
|
||||
# clone to keep it untouched for next loop
|
||||
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(
|
||||
source: '/api/users/search',
|
||||
minLength: 2,
|
||||
select: ( event, ui ) =>
|
||||
@log 'selected', event, ui
|
||||
# @log 'selected', event, ui
|
||||
b(event, ui.item.id)
|
||||
)
|
||||
@delay( a, 600 )
|
||||
|
@ -324,7 +329,7 @@ class App.ControllerForm extends App.Controller
|
|||
item = $( App.view('generic/input')( attribute: attribute ) )
|
||||
|
||||
if attribute.onchange
|
||||
@log 'on change', attribute.name
|
||||
# @log 'on change', attribute.name
|
||||
if typeof attribute.onchange is 'function'
|
||||
attribute.onchange(attribute)
|
||||
else
|
||||
|
@ -332,13 +337,13 @@ class App.ControllerForm extends App.Controller
|
|||
a = i.split(/__/)
|
||||
if a[1]
|
||||
if a[0] is attribute.name
|
||||
@log 'aaa', i, a[0], attribute.id
|
||||
# @log 'aaa', i, a[0], attribute.id
|
||||
@attribute = attribute
|
||||
@classname = classname
|
||||
@attributes_clean = attributes_clean
|
||||
@change = a
|
||||
b = =>
|
||||
console.log 'aaa', @attribute
|
||||
# console.log 'aaa', @attribute
|
||||
attribute = @attribute
|
||||
change = @change
|
||||
classname = @classname
|
||||
|
@ -446,22 +451,43 @@ class App.ControllerForm extends App.Controller
|
|||
attribute.options = []
|
||||
|
||||
list = []
|
||||
if attribute.filter && attribute.filter[attribute.name]
|
||||
filter = attribute.filter[attribute.name]
|
||||
if attribute.filter
|
||||
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter', attribute.filter
|
||||
|
||||
# check all records
|
||||
for record in App[attribute.relation].all()
|
||||
# function based filter
|
||||
if typeof attribute.filter is 'function'
|
||||
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter-function'
|
||||
|
||||
# check all filter attributes
|
||||
for key in filter
|
||||
all = App[attribute.relation].all()
|
||||
list = attribute.filter( all )
|
||||
|
||||
# check all filter values as array
|
||||
# if it's matching, use it for selection
|
||||
if record['id'] is key
|
||||
list.push record
|
||||
# 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
|
||||
for record in App[attribute.relation].all()
|
||||
|
||||
# check all filter attributes
|
||||
for key in filter
|
||||
|
||||
# check all filter values as array
|
||||
# if it's matching, use it for selection
|
||||
if record['id'] is key
|
||||
list.push record
|
||||
|
||||
# no data filter matched
|
||||
else
|
||||
App.Log.log 'ControllerForm', 'debug', '_getRelationOptionList:filter-data no filter matched'
|
||||
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
|
||||
@_buildOptionList( list, attribute )
|
||||
|
||||
|
@ -528,7 +554,7 @@ class App.ControllerForm extends App.Controller
|
|||
else if $(form).parents().find('form')[0]
|
||||
form = $(form).parents().find('form')
|
||||
else
|
||||
console.log 'ERROR, no form found!', form
|
||||
App.Log.log 'ControllerForm', 'error', 'no form found!', form
|
||||
|
||||
array = form.serializeArray()
|
||||
for key in array
|
||||
|
@ -555,7 +581,7 @@ class App.ControllerForm extends App.Controller
|
|||
for key of param
|
||||
attributeType = key.split '::'
|
||||
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 ]
|
||||
|
||||
# array need to be converted
|
||||
|
@ -573,19 +599,19 @@ class App.ControllerForm extends App.Controller
|
|||
for key of inputSelectObject
|
||||
param[ key ] = inputSelectObject[ key ]
|
||||
|
||||
console.log 'formParam', form, param
|
||||
App.Log.log 'ControllerForm', 'notice', 'formParam', form, param
|
||||
return param
|
||||
|
||||
|
||||
@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('[type="submit"]').attr('disabled', true)
|
||||
$(form.target).parent().find('[type="reset"]').attr('disabled', true)
|
||||
|
||||
|
||||
@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('[type="submit"]').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] )
|
||||
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')(
|
||||
header: header
|
||||
overview: dataTypesForCols
|
||||
|
|
|
@ -111,6 +111,8 @@ class Index extends App.Controller
|
|||
class: 'active' if @view_mode is 'm'
|
||||
}
|
||||
]
|
||||
if @isRole('Customer')
|
||||
view_modes = []
|
||||
html = App.view('agent_ticket_view')(
|
||||
overview: @overview
|
||||
view_modes: view_modes
|
||||
|
|
|
@ -84,10 +84,18 @@ class Index extends App.Controller
|
|||
if !( 'ticket_priority_id' of defaults )
|
||||
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
|
||||
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: '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: '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', },
|
||||
|
|
|
@ -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
|
||||
constructor: ->
|
||||
super
|
||||
@log 'nav...'
|
||||
@render()
|
||||
|
||||
# update selected item
|
||||
|
@ -12,7 +11,7 @@ class App.Navigation extends App.Controller
|
|||
|
||||
# rebuild nav bar with given user data
|
||||
App.Event.bind 'ajax:auth', (user) =>
|
||||
@log 'navbar rebuild', user
|
||||
@log 'Navigation', 'notice', 'navbar rebuild', user
|
||||
|
||||
if !_.isEmpty( user )
|
||||
cache = App.Store.get( 'navupdate_ticket_overview' )
|
||||
|
|
|
@ -20,17 +20,22 @@ class App.Session
|
|||
_instance ?= new _Singleton
|
||||
_instance.all()
|
||||
|
||||
class _Singleton
|
||||
class _Singleton extends Spine.Module
|
||||
@include App.Log
|
||||
|
||||
constructor: ->
|
||||
@clear()
|
||||
# @log = App.LogModule
|
||||
|
||||
clear: ->
|
||||
@data = {}
|
||||
|
||||
get: ( key ) ->
|
||||
@log 'Session', 'debug', key, @data[key]
|
||||
return @data[key]
|
||||
|
||||
set: ( key, value ) ->
|
||||
@log 'Session', 'debug', 'set', key, value
|
||||
@data[key] = value
|
||||
|
||||
all: ->
|
||||
|
|
|
@ -3,7 +3,7 @@ $ = jQuery.sub()
|
|||
class App.Auth
|
||||
|
||||
@login: (params) ->
|
||||
console.log 'login(...)', params
|
||||
App.Log.log 'Auth', 'notice', 'login', params
|
||||
App.Com.ajax(
|
||||
id: 'login',
|
||||
type: 'POST',
|
||||
|
@ -22,14 +22,14 @@ class App.Auth
|
|||
)
|
||||
|
||||
@loginCheck: ->
|
||||
console.log 'loginCheck(...)'
|
||||
App.Log.log 'Auth', 'notice', 'loginCheck'
|
||||
App.Com.ajax(
|
||||
id: 'login_check',
|
||||
async: false,
|
||||
type: 'GET',
|
||||
url: '/signshow',
|
||||
success: (data, status, xhr) =>
|
||||
console.log 'logincheck:success', data
|
||||
App.Log.log 'Auth', 'notice', 'logincheck:success', data
|
||||
|
||||
# if session is not valid
|
||||
if data.error
|
||||
|
@ -72,7 +72,7 @@ class App.Auth
|
|||
App.Event.trigger 'ajax:auth', data.session
|
||||
|
||||
error: (xhr, statusText, error) =>
|
||||
console.log 'loginCheck:error'#, error, statusText, xhr.statusCode
|
||||
App.Log.log 'Auth', 'notice', 'logincheck:error'
|
||||
|
||||
# empty session
|
||||
App.Session.init()
|
||||
|
@ -85,7 +85,7 @@ class App.Auth
|
|||
)
|
||||
|
||||
@logout: ->
|
||||
console.log 'logout(...)'
|
||||
App.Log.log 'Auth', 'notice', 'logout'
|
||||
App.Com.ajax(
|
||||
id: 'logout',
|
||||
type: 'DELETE',
|
||||
|
|
|
@ -64,7 +64,8 @@ class App.Collection
|
|||
_instance ?= new _Singleton
|
||||
_instance._observeStats()
|
||||
|
||||
class _Singleton
|
||||
class _Singleton extends Spine.Module
|
||||
@include App.Log
|
||||
|
||||
constructor: (@args) ->
|
||||
|
||||
|
@ -75,7 +76,7 @@ class _Singleton
|
|||
if 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] )
|
||||
|
||||
# add trigger - bind new events
|
||||
|
@ -85,7 +86,7 @@ class _Singleton
|
|||
if 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] )
|
||||
|
||||
# find collections to load
|
||||
|
@ -98,11 +99,11 @@ class _Singleton
|
|||
if parts[0] is 'collection'
|
||||
data = App.Store.get( key )
|
||||
if data && data.localStorage
|
||||
console.log('load INIT', data)
|
||||
@log 'Collection', 'debug', 'load INIT', data
|
||||
@load( data )
|
||||
|
||||
reset: (params) ->
|
||||
console.log( 'reset', params )
|
||||
@log 'Collection', 'debug', 'reset', params
|
||||
|
||||
# empty in-memory
|
||||
App[ params.type ].refresh( [], { clear: true } )
|
||||
|
@ -118,7 +119,7 @@ class _Singleton
|
|||
@load(params)
|
||||
|
||||
load: (params) ->
|
||||
console.log( 'load', params )
|
||||
@log 'Collection', 'debug', 'load', params
|
||||
|
||||
return if _.isEmpty( params.data )
|
||||
|
||||
|
@ -156,9 +157,9 @@ class _Singleton
|
|||
callback( data )
|
||||
else
|
||||
if force
|
||||
console.log( 'find forced to load!', type, id )
|
||||
@log 'Collection', 'debug', 'find forced to load!', type, id
|
||||
else
|
||||
console.log( 'find not loaded!', type, id )
|
||||
@log 'Collection', 'debug', 'find not loaded!', type, id
|
||||
if callback
|
||||
|
||||
# execute callback if record got loaded
|
||||
|
@ -251,7 +252,7 @@ class _Singleton
|
|||
return data
|
||||
|
||||
get: (params) ->
|
||||
console.log('get')
|
||||
@log 'Collection', 'debug', 'get', params
|
||||
App[ params.type ].refresh( object, options: { clear: true } )
|
||||
|
||||
all: (params) ->
|
||||
|
|
|
@ -29,7 +29,8 @@ class App.Event
|
|||
_instance ?= new _Singleton
|
||||
_instance._allBindings()
|
||||
|
||||
class _Singleton
|
||||
class _Singleton extends Spine.Module
|
||||
@include App.Log
|
||||
|
||||
constructor: ->
|
||||
@eventCurrent = {}
|
||||
|
@ -59,6 +60,7 @@ class _Singleton
|
|||
}
|
||||
|
||||
# bind
|
||||
@log 'Event', 'debug', 'bind', event, callback
|
||||
Spine.bind( event, callback )
|
||||
|
||||
unbind: ( events, callback, level ) ->
|
||||
|
@ -79,11 +81,13 @@ class _Singleton
|
|||
else
|
||||
return item if item.event isnt event
|
||||
)
|
||||
@log 'Event', 'debug', 'unbind', event, callback
|
||||
Spine.unbind( event, callback )
|
||||
|
||||
trigger: ( events, data ) ->
|
||||
eventList = events.split(' ')
|
||||
for event in eventList
|
||||
@log 'Event', 'debug', 'trigger', event, data
|
||||
Spine.trigger event, data
|
||||
|
||||
_allBindings: ->
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
class App.Run extends App.Controller
|
||||
constructor: ->
|
||||
super
|
||||
@log 'RUN app'
|
||||
@el = $('#app')
|
||||
|
||||
# init collections
|
||||
|
@ -37,13 +36,14 @@ class App.Content extends App.Controller
|
|||
|
||||
constructor: ->
|
||||
super
|
||||
@log 'RUN content'
|
||||
|
||||
Routes = @Config.get( 'Routes' )
|
||||
for route, callback of Routes
|
||||
do (route, callback) =>
|
||||
@route(route, (params) ->
|
||||
|
||||
@log 'Content', 'notice', 'execute page controller', route, params
|
||||
|
||||
# remove observers for page
|
||||
App.Collection.observeUnbindLevel('page')
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ class App.WebSocket
|
|||
|
||||
# The actual Singleton class
|
||||
class _Singleton extends App.Controller
|
||||
@include App.Log
|
||||
|
||||
queue: []
|
||||
supported: true
|
||||
lastSpoolMessage: undefined
|
||||
|
@ -74,7 +76,9 @@ class _Singleton extends App.Controller
|
|||
action: 'spool'
|
||||
if @lastSpoolMessage
|
||||
data['timestamp'] = @lastSpoolMessage
|
||||
@log 'spool', data
|
||||
|
||||
@log 'Event', 'debug', 'spool', data
|
||||
|
||||
# ask for spool messages
|
||||
App.Event.trigger(
|
||||
'ws:send'
|
||||
|
@ -92,25 +96,24 @@ class _Singleton extends App.Controller
|
|||
ping: =>
|
||||
return if !@supported
|
||||
|
||||
# console.log 'send websockend ping'
|
||||
@log 'Event', 'debug', 'send websockend ping'
|
||||
@send( { action: 'ping' } )
|
||||
|
||||
# check if ping is back within 2 min
|
||||
@clearDelay('websocket-ping-check')
|
||||
check = =>
|
||||
console.log 'no websockend ping response, reconnect...'
|
||||
@log 'Event', 'notice', 'no websockend ping response, reconnect...'
|
||||
@close()
|
||||
@delay check, 120000, 'websocket-ping-check'
|
||||
|
||||
pong: ->
|
||||
return if !@supported
|
||||
# console.log 'received websockend ping'
|
||||
@log 'Event', 'debug', 'received websockend ping'
|
||||
|
||||
# test again after 1 min
|
||||
@delay @ping, 60000
|
||||
|
||||
connect: =>
|
||||
# console.log '------------ws connect....--------------'
|
||||
|
||||
if !window.WebSocket
|
||||
@error = new App.ErrorModal(
|
||||
|
@ -127,7 +130,7 @@ class _Singleton extends App.Controller
|
|||
|
||||
# Set event handlers.
|
||||
@ws.onopen = =>
|
||||
console.log( 'onopen' )
|
||||
@log 'Event', 'notice', 'new websocked connection open'
|
||||
|
||||
@connectionEstablished = true
|
||||
|
||||
|
@ -141,7 +144,7 @@ class _Singleton extends App.Controller
|
|||
|
||||
# empty queue
|
||||
for item in @queue
|
||||
# console.log( 'ws:send queue', item )
|
||||
@log 'Event', 'debug', 'empty ws queue', item
|
||||
@send(item)
|
||||
@queue = []
|
||||
|
||||
|
@ -150,7 +153,7 @@ class _Singleton extends App.Controller
|
|||
|
||||
@ws.onmessage = (e) =>
|
||||
pipe = JSON.parse( e.data )
|
||||
console.log( 'ws:onmessage', pipe )
|
||||
@log 'Event', 'debug', 'ws:onmessage', pipe
|
||||
|
||||
# go through all blocks
|
||||
for item in pipe
|
||||
|
@ -161,21 +164,21 @@ class _Singleton extends App.Controller
|
|||
|
||||
# fill 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'] )
|
||||
|
||||
# fire event
|
||||
if item['event']
|
||||
if typeof item['event'] is 'object'
|
||||
for event in item['event']
|
||||
console.log( "ws:onmessage event:" + event )
|
||||
@log 'Event', 'debug', "ws:onmessage event:" + event
|
||||
App.Event.trigger( event, item['data'] )
|
||||
else
|
||||
console.log( "ws:onmessage event:" + item['event'] )
|
||||
@log 'Event', 'debug', "ws:onmessage event:" + item['event']
|
||||
App.Event.trigger( item['event'], item['data'] )
|
||||
|
||||
@ws.onclose = (e) =>
|
||||
console.log( 'onclose', e )
|
||||
@log 'Event', 'debug', "ws:onclose", e
|
||||
|
||||
# set timestamp to get spool messages later
|
||||
if @connectionEstablished
|
||||
|
@ -193,6 +196,6 @@ class _Singleton extends App.Controller
|
|||
# try reconnect after 4.5 sec.
|
||||
@delay @connect, 4500
|
||||
|
||||
@ws.onerror = ->
|
||||
console.log( 'onerror' )
|
||||
@ws.onerror = (e) =>
|
||||
@log 'Event', 'debug', "ws:onerror", e
|
||||
|
||||
|
|
Loading…
Reference in a new issue