Moved to assets for sla, overview and jobs.

This commit is contained in:
Martin Edenhofer 2016-03-20 21:04:58 +01:00
parent 30e28e71f6
commit d4ec678238
8 changed files with 121 additions and 134 deletions

View file

@ -542,7 +542,7 @@ class App.Controller extends Spine.Controller
el.html App.view('generic/page_loading')()
else
@html App.view('generic/page_loading')()
@initLoadingDoneDelay = @delay(later, 2800)
@initLoadingDoneDelay = @delay(later, 1800)
stopLoading: =>
return if !@initLoadingDoneDelay

View file

@ -124,7 +124,10 @@ class App.ControllerGenericIndex extends App.Controller
# fetch all
if !@disableInitFetch
App[ @genericObject ].fetch()
App[ @genericObject ].fetchFull(
->
clear: true
)
release: =>
if @subscribeId

View file

@ -12,26 +12,17 @@ class Index extends App.ControllerContent
# check authentication
return if !@authenticate(false, 'Admin')
@interval(@load, 60000)
#@load()
load: =>
@startLoading()
@ajax(
id: 'calendar_index'
type: 'GET'
url: @apiPath + '/calendars'
processData: true
success: (data, status, xhr) =>
@subscribeId = App.Calendar.subscribe(@render)
callback = (data) =>
App.Config.set('ical_feeds', data.ical_feeds)
App.Config.set('timezones', data.timezones)
# load assets
App.Collection.loadAssets(data.assets)
@stopLoading()
@render(data)
@render()
@startLoading()
App.Calendar.fetchFull(
callback
clear: true
)
render: =>

View file

@ -327,7 +327,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
level1 = []
dropdown = {}
roles = App.Session.get( 'roles' )
roles = App.Session.get('roles')
for item in navbar
if typeof item.callback is 'function'
@ -339,11 +339,11 @@ class App.Navigation extends App.ControllerWidgetPermanent
if !item.role
match = 1
if !roles && item.role
match = _.include( item.role, 'Anybody' )
match = _.include(item.role, 'Anybody')
if roles
for role in roles
if !match
match = _.include( item.role, role.name )
match = _.include(item.role, role.name)
if match
level1.push item
@ -359,11 +359,11 @@ class App.Navigation extends App.ControllerWidgetPermanent
if !itemSub.role
match = 1
if !roles
match = _.include( itemSub.role, 'Anybody' )
match = _.include(itemSub.role, 'Anybody')
if roles
for role in roles
if !match
match = _.include( itemSub.role, role.name )
match = _.include(itemSub.role, role.name)
if match
dropdown[ item.parent ].push itemSub
@ -371,13 +371,13 @@ class App.Navigation extends App.ControllerWidgetPermanent
# find parent
for itemLevel1 in level1
if itemLevel1.target is item.parent
sub = @getOrder( dropdown[ item.parent ] )
sub = @getOrder(dropdown[ item.parent ])
itemLevel1.child = sub
# clean up, only show navbar items with existing childrens
clean_list = []
for item in level1
if !item.child || item.child && !_.isEmpty( item.child )
if !item.child || item.child && !_.isEmpty(item.child)
clean_list.push item
nav = @getOrder(clean_list)
return nav
@ -435,11 +435,11 @@ class App.Navigation extends App.ControllerWidgetPermanent
delete NavBarRight[key]
if !@Session.get()
@Config.set( 'NavBarRight', NavBarRight )
@Config.set('NavBarRight', NavBarRight)
return
# add new views
items = App.RecentView.search(sortBy: 'created_at', order: 'DESC' )
items = App.RecentView.search(sortBy: 'created_at', order: 'DESC')
items = @prepareForObjectList(items)
prio = 80
for item in items
@ -460,12 +460,12 @@ class App.Navigation extends App.ControllerWidgetPermanent
type: 'recentViewed'
}
@Config.set( 'NavBarRight', NavBarRight )
@Config.set('NavBarRight', NavBarRight)
fetchRecentView: =>
load = (items) =>
App.RecentView.refresh( items, { clear: true } )
load = (data) =>
App.RecentView.refresh(data.stream, clear: true)
@renderPersonal()
App.RecentView.fetchFull(load)
App.Config.set( 'navigation', App.Navigation, 'Navigations' )
App.Config.set('navigation', App.Navigation, 'Navigations')

View file

@ -11,20 +11,16 @@ class Index extends App.ControllerContent
# check authentication
return if !@authenticate(false, 'Admin')
@interval(@load, 60000)
#@load()
@subscribeCalendarId = App.Calendar.subscribe(@render)
@subscribeSlaId = App.Sla.subscribe(@render)
load: =>
@startLoading()
@ajax(
id: 'sla_index'
type: 'GET'
url: @apiPath + '/slas'
processData: true
success: (data, status, xhr) =>
App.Collection.loadAssets(data.assets)
callback = =>
@stopLoading()
@render(data)
@render()
@startLoading()
App.Sla.fetchFull(
callback
clear: true
)
render: =>
@ -56,8 +52,10 @@ class Index extends App.ControllerContent
)
release: =>
if @subscribeId
App.Calendar.unsubscribe(@subscribeId)
if @subscribeCalendarId
App.Calendar.unsubscribe(@subscribeCalendarId)
if @subscribeSlaId
App.Sla.unsubscribe(@subscribeSlaId)
new: (e) ->
e.preventDefault()

View file

@ -153,9 +153,9 @@ class App.OnlineNotificationWidget extends App.Controller
@toggle.popover('hide')
fetch: =>
load = (items) =>
load = (data) =>
@fetchedData = true
App.OnlineNotification.refresh(items, { clear: true })
App.OnlineNotification.refresh(data.stream, clear: true)
@updateContent()
App.OnlineNotification.fetchFull(load)

View file

@ -63,15 +63,15 @@ class App.Model extends Spine.Model
iconActivity: (user) ->
''
@validate: ( data = {} ) ->
@validate: (data = {}) ->
# based on model attrbutes
if App[ data['model'] ] && App[ data['model'] ].attributesGet
attributes = App[ data['model'] ].attributesGet( data['screen'] )
attributes = App[ data['model'] ].attributesGet(data['screen'])
# based on custom attributes
else if data['model'].configure_attributes
attributes = App.Model.attributesGet( data['screen'], data['model'].configure_attributes )
attributes = App.Model.attributesGet(data['screen'], data['model'].configure_attributes)
# check required_if attributes
for attributeName, attribute of attributes
@ -186,9 +186,9 @@ class App.Model extends Spine.Model
@attributesGet: (screen = undefined, attributes = false) ->
if !attributes
attributes = clone( App[ @.className ].configure_attributes, true )
attributes = clone(App[ @.className ].configure_attributes, true)
else
attributes = clone( attributes, true )
attributes = clone(attributes, true)
# in case if no configure_attributes exist
return {} if !attributes
@ -198,13 +198,13 @@ class App.Model extends Spine.Model
if screen
for attribute in attributes
if attribute.screen
if attribute && attribute.screen && attribute.screen[ screen ] && !_.isEmpty( attribute.screen[ screen ] )
if attribute && attribute.screen && attribute.screen[ screen ] && !_.isEmpty(attribute.screen[ screen ])
for item, value of attribute.screen[ screen ]
attribute[item] = value
attributesNew[ attribute.name ] = attribute
# if no screen is given or no attribute has this screen - use default attributes
if !screen || _.isEmpty( attributesNew )
if !screen || _.isEmpty(attributesNew)
for attribute in attributes
attributesNew[ attribute.name ] = attribute
@ -238,11 +238,11 @@ class App.Model extends Spine.Model
subscribeId = App[ @className ].subscribe_item(id, callback)
# execute if object already exists
if !force && App[ @className ].exists( id )
data = App[ @className ].find( id )
data = @_fillUp( data )
if !force && App[ @className ].exists(id)
data = App[ @className ].find(id)
data = @_fillUp(data)
if callback
callback( data, 'full' )
callback(data, 'full')
return subscribeId
# store callback and requested id
@ -270,16 +270,16 @@ class App.Model extends Spine.Model
# full / load assets
if data.assets
App.Collection.loadAssets( data.assets )
App.Collection.loadAssets(data.assets)
# find / load object
else
App[ @className ].refresh( data )
App[ @className ].refresh(data)
# execute callbacks
if @FULL_CALLBACK[ data.id ]
for key, callback of @FULL_CALLBACK[ data.id ]
callback( @_fillUp( App[ @className ].find( data.id ) ) )
callback( @_fillUp( App[ @className ].find(data.id) ) )
delete @FULL_CALLBACK[ data.id ][ key ]
if _.isEmpty @FULL_CALLBACK[ data.id ]
delete @FULL_CALLBACK[ data.id ]
@ -297,11 +297,13 @@ class App.Model extends Spine.Model
params =
initFetch: true # fetch initial collection
@subscribeId = App.Model.subscribe( methodWhichIsCalledAtLocalOrServerSiteChange )
@subscribeId = App.Model.subscribe(methodWhichIsCalledAtLocalOrServerSiteChange)
###
@subscribe: (callback, param = {}) ->
# global bind to changes
if !@SUBSCRIPTION_COLLECTION
@SUBSCRIPTION_COLLECTION = {}
@ -320,7 +322,10 @@ class App.Model extends Spine.Model
events
=>
App.Log.debug('Model', "server notify collection change #{@className}")
@fetch( {}, { clear: true } )
@fetchFull(
->
clear: true
)
'Collection::Subscribe::' + @className
)
@ -334,9 +339,12 @@ class App.Model extends Spine.Model
@one 'refresh', (collection) =>
@initFetchActive = true
callback(collection)
@fetch( {}, { clear: true } )
@fetchFull(
->
clear: true
)
else
callback( @all() )
callback(@all())
# return key
key
@ -347,7 +355,7 @@ class App.Model extends Spine.Model
console.log("Item has changed", changedItem, localOrServer)
model = App.Model.find(1)
@subscribeId = model.subscribe( methodWhichIsCalledAtLocalOrServerSiteChange )
@subscribeId = model.subscribe(methodWhichIsCalledAtLocalOrServerSiteChange)
###
@ -373,7 +381,7 @@ class App.Model extends Spine.Model
App.Log.debug('Model', "local change #{@className}", items)
for item in items
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
item = App[ @className ]._fillUp( item )
item = App[ @className ]._fillUp(item)
callback(item, 'change')
)
@bind(
@ -386,7 +394,7 @@ class App.Model extends Spine.Model
App.Log.debug('Model', "local remove #{@className}", items)
for item in items
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
item = App[ @className ]._fillUp( item )
item = App[ @className ]._fillUp(item)
callback(item, 'remove')
)
@ -405,7 +413,7 @@ class App.Model extends Spine.Model
# only trigger callbacks if object has changed
if !@changeTable[key] || @changeTable[key] isnt item.updated_at
@changeTable[key] = item.updated_at
item = App[ @className ]._fillUp( item )
item = App[ @className ]._fillUp(item)
callback(item, 'refresh')
)
@ -416,14 +424,13 @@ class App.Model extends Spine.Model
(item) =>
if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ]
genericObject = undefined
if App[ @className ].exists( item.id )
genericObject = App[ @className ].find( item.id )
if App[ @className ].exists(item.id)
genericObject = App[ @className ].find(item.id)
App.Log.debug('Model', "server change on #{@className}.find(#{item.id}) #{item.updated_at}")
callback = =>
if !genericObject || new Date(item.updated_at) >= new Date(genericObject.updated_at)
App.Log.debug('Model', "request #{@className}.find(#{item.id}) from server")
@full( item.id, false, true )
@full(item.id, false, true)
App.Delay.set(callback, 500, item.id, "full-#{@className}")
'Item::Subscribe::' + @className
@ -460,10 +467,16 @@ class App.Model extends Spine.Model
fetch full collection (with assets)
App.Model.fetchFull( @callback )
App.Model.fetchFull(@callback)
App.Model.fetchFull(
@callback
clear: true
)
###
@fetchFull: (callback) ->
@fetchFull: (callback, params = {}) ->
url = "#{@url}/?full=true"
App.Log.debug('Model', "fetchFull collection #{@className}", url)
App.Ajax.request(
@ -474,16 +487,20 @@ class App.Model extends Spine.Model
App.Log.debug('Model', "got fetchFull collection #{@className}", data)
# clear collection
if params.clear
App[@className].deleteAll()
# full / load assets
if data.assets
App.Collection.loadAssets( data.assets )
App.Collection.loadAssets(data.assets)
# find / load object
else
App[ @className ].refresh( data )
App[@className].refresh(data)
# execute callbacks
callback(data.stream)
if callback
callback(data)
error: (xhr, statusText, error) ->
App.Log.error('Model', statusText, error, url)
@ -494,7 +511,7 @@ class App.Model extends Spine.Model
for id, keys of @SUBSCRIPTION_ITEM
return false if !_.isEmpty(keys)
if @SUBSCRIPTION_COLLECTION && !_.isEmpty( @SUBSCRIPTION_COLLECTION )
if @SUBSCRIPTION_COLLECTION && !_.isEmpty(@SUBSCRIPTION_COLLECTION)
return false
return true
@ -502,8 +519,8 @@ class App.Model extends Spine.Model
@_fillUp: (data, classNames = []) ->
# fill up via relations
return data if !App[ @className ].configure_attributes
for attribute in App[ @className ].configure_attributes
return data if !App[@className].configure_attributes
for attribute in App[@className].configure_attributes
# lookup relations
if attribute.relation
@ -512,19 +529,19 @@ class App.Model extends Spine.Model
if !_.contains(classNames, @className)
# only if relation model exists
if App[ attribute.relation ]
withoutId = attribute.name.substr( 0, attribute.name.length - 3 )
if attribute.name.substr( attribute.name.length - 3, attribute.name.length ) is '_id'
if App[attribute.relation]
withoutId = attribute.name.substr(0, attribute.name.length - 3)
if attribute.name.substr(attribute.name.length - 3, attribute.name.length) is '_id'
if data[attribute.name]
# only if relation record exists in collection
if App[ attribute.relation ].exists( data[attribute.name] )
item = App[ attribute.relation ].find( data[attribute.name] )
item = App[ attribute.relation ]._fillUp(item, classNames.concat(@className))
data[ withoutId ] = item
if App[ attribute.relation ].exists(data[attribute.name])
item = App[attribute.relation].find(data[attribute.name])
item = App[attribute.relation]._fillUp(item, classNames.concat(@className))
data[withoutId] = item
else
if !attribute.do_not_log
console.log("ERROR, cant find #{ attribute.name } App.#{ attribute.relation }.find(#{ data[attribute.name] }) for '#{ data.constructor.className }' #{ data.displayName() }")
console.log("ERROR, cant find #{attribute.name} App.#{attribute.relation}.find(#{data[attribute.name]}) for '#{data.constructor.className}' #{data.displayName()}")
data
###

View file

@ -49,51 +49,29 @@ curl http://localhost/api/v1/slas.json -v -u #{login}:#{password}
def index
return if deny_if_not_role(Z_ROLENAME_ADMIN)
assets = {}
if params[:full]
# calendars
assets = {}
calendar_ids = []
Calendar.all.order(:name, :created_at).each {|calendar|
calendar_ids.push calendar.id
Calendar.all.each {|calendar|
assets = calendar.assets(assets)
}
# slas
sla_ids = []
models = Models.all
Sla.all.order(:name, :created_at).each {|sla|
sla_ids.push sla.id
assets = sla.assets(assets)
# get assets of condition
sla.condition.each {|item, content|
attribute = item.split(/\./)
next if !attribute[1]
attribute_class = attribute[0].to_classname.constantize
reflection = attribute[1].sub(/_id$/, '')
reflection = reflection.to_sym
next if !models[attribute_class]
next if !models[attribute_class][:reflections]
next if !models[attribute_class][:reflections][reflection]
next if !models[attribute_class][:reflections][reflection].klass
attribute_ref_class = models[attribute_class][:reflections][reflection].klass
if content['value'].class == Array
content['value'].each {|item_id|
attribute_object = attribute_ref_class.find_by(id: item_id)
assets = attribute_object.assets(assets)
Sla.all.each {|item|
sla_ids.push item.id
assets = item.assets(assets)
}
else
attribute_object = attribute_ref_class.find_by(id: content['value'])
assets = attribute_object.assets(assets)
end
}
}
render json: {
calendar_ids: calendar_ids,
sla_ids: sla_ids,
record_ids: sla_ids,
assets: assets,
}, status: :ok
return
end
model_index_render(Sla, params)
end
=begin