Moved to assets for sla, overview and jobs.
This commit is contained in:
parent
30e28e71f6
commit
d4ec678238
8 changed files with 121 additions and 134 deletions
|
@ -542,7 +542,7 @@ class App.Controller extends Spine.Controller
|
||||||
el.html App.view('generic/page_loading')()
|
el.html App.view('generic/page_loading')()
|
||||||
else
|
else
|
||||||
@html App.view('generic/page_loading')()
|
@html App.view('generic/page_loading')()
|
||||||
@initLoadingDoneDelay = @delay(later, 2800)
|
@initLoadingDoneDelay = @delay(later, 1800)
|
||||||
|
|
||||||
stopLoading: =>
|
stopLoading: =>
|
||||||
return if !@initLoadingDoneDelay
|
return if !@initLoadingDoneDelay
|
||||||
|
|
|
@ -124,7 +124,10 @@ class App.ControllerGenericIndex extends App.Controller
|
||||||
|
|
||||||
# fetch all
|
# fetch all
|
||||||
if !@disableInitFetch
|
if !@disableInitFetch
|
||||||
App[ @genericObject ].fetch()
|
App[ @genericObject ].fetchFull(
|
||||||
|
->
|
||||||
|
clear: true
|
||||||
|
)
|
||||||
|
|
||||||
release: =>
|
release: =>
|
||||||
if @subscribeId
|
if @subscribeId
|
||||||
|
|
|
@ -12,26 +12,17 @@ class Index extends App.ControllerContent
|
||||||
# check authentication
|
# check authentication
|
||||||
return if !@authenticate(false, 'Admin')
|
return if !@authenticate(false, 'Admin')
|
||||||
|
|
||||||
@interval(@load, 60000)
|
@subscribeId = App.Calendar.subscribe(@render)
|
||||||
#@load()
|
|
||||||
|
|
||||||
load: =>
|
|
||||||
@startLoading()
|
|
||||||
@ajax(
|
|
||||||
id: 'calendar_index'
|
|
||||||
type: 'GET'
|
|
||||||
url: @apiPath + '/calendars'
|
|
||||||
processData: true
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
|
|
||||||
|
callback = (data) =>
|
||||||
App.Config.set('ical_feeds', data.ical_feeds)
|
App.Config.set('ical_feeds', data.ical_feeds)
|
||||||
App.Config.set('timezones', data.timezones)
|
App.Config.set('timezones', data.timezones)
|
||||||
|
|
||||||
# load assets
|
|
||||||
App.Collection.loadAssets(data.assets)
|
|
||||||
|
|
||||||
@stopLoading()
|
@stopLoading()
|
||||||
@render(data)
|
@render()
|
||||||
|
@startLoading()
|
||||||
|
App.Calendar.fetchFull(
|
||||||
|
callback
|
||||||
|
clear: true
|
||||||
)
|
)
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
|
|
|
@ -327,7 +327,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
||||||
level1 = []
|
level1 = []
|
||||||
dropdown = {}
|
dropdown = {}
|
||||||
|
|
||||||
roles = App.Session.get( 'roles' )
|
roles = App.Session.get('roles')
|
||||||
|
|
||||||
for item in navbar
|
for item in navbar
|
||||||
if typeof item.callback is 'function'
|
if typeof item.callback is 'function'
|
||||||
|
@ -339,11 +339,11 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
||||||
if !item.role
|
if !item.role
|
||||||
match = 1
|
match = 1
|
||||||
if !roles && item.role
|
if !roles && item.role
|
||||||
match = _.include( item.role, 'Anybody' )
|
match = _.include(item.role, 'Anybody')
|
||||||
if roles
|
if roles
|
||||||
for role in roles
|
for role in roles
|
||||||
if !match
|
if !match
|
||||||
match = _.include( item.role, role.name )
|
match = _.include(item.role, role.name)
|
||||||
|
|
||||||
if match
|
if match
|
||||||
level1.push item
|
level1.push item
|
||||||
|
@ -359,11 +359,11 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
||||||
if !itemSub.role
|
if !itemSub.role
|
||||||
match = 1
|
match = 1
|
||||||
if !roles
|
if !roles
|
||||||
match = _.include( itemSub.role, 'Anybody' )
|
match = _.include(itemSub.role, 'Anybody')
|
||||||
if roles
|
if roles
|
||||||
for role in roles
|
for role in roles
|
||||||
if !match
|
if !match
|
||||||
match = _.include( itemSub.role, role.name )
|
match = _.include(itemSub.role, role.name)
|
||||||
|
|
||||||
if match
|
if match
|
||||||
dropdown[ item.parent ].push itemSub
|
dropdown[ item.parent ].push itemSub
|
||||||
|
@ -371,13 +371,13 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
||||||
# find parent
|
# find parent
|
||||||
for itemLevel1 in level1
|
for itemLevel1 in level1
|
||||||
if itemLevel1.target is item.parent
|
if itemLevel1.target is item.parent
|
||||||
sub = @getOrder( dropdown[ item.parent ] )
|
sub = @getOrder(dropdown[ item.parent ])
|
||||||
itemLevel1.child = sub
|
itemLevel1.child = sub
|
||||||
|
|
||||||
# clean up, only show navbar items with existing childrens
|
# clean up, only show navbar items with existing childrens
|
||||||
clean_list = []
|
clean_list = []
|
||||||
for item in level1
|
for item in level1
|
||||||
if !item.child || item.child && !_.isEmpty( item.child )
|
if !item.child || item.child && !_.isEmpty(item.child)
|
||||||
clean_list.push item
|
clean_list.push item
|
||||||
nav = @getOrder(clean_list)
|
nav = @getOrder(clean_list)
|
||||||
return nav
|
return nav
|
||||||
|
@ -435,11 +435,11 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
||||||
delete NavBarRight[key]
|
delete NavBarRight[key]
|
||||||
|
|
||||||
if !@Session.get()
|
if !@Session.get()
|
||||||
@Config.set( 'NavBarRight', NavBarRight )
|
@Config.set('NavBarRight', NavBarRight)
|
||||||
return
|
return
|
||||||
|
|
||||||
# add new views
|
# add new views
|
||||||
items = App.RecentView.search(sortBy: 'created_at', order: 'DESC' )
|
items = App.RecentView.search(sortBy: 'created_at', order: 'DESC')
|
||||||
items = @prepareForObjectList(items)
|
items = @prepareForObjectList(items)
|
||||||
prio = 80
|
prio = 80
|
||||||
for item in items
|
for item in items
|
||||||
|
@ -460,12 +460,12 @@ class App.Navigation extends App.ControllerWidgetPermanent
|
||||||
type: 'recentViewed'
|
type: 'recentViewed'
|
||||||
}
|
}
|
||||||
|
|
||||||
@Config.set( 'NavBarRight', NavBarRight )
|
@Config.set('NavBarRight', NavBarRight)
|
||||||
|
|
||||||
fetchRecentView: =>
|
fetchRecentView: =>
|
||||||
load = (items) =>
|
load = (data) =>
|
||||||
App.RecentView.refresh( items, { clear: true } )
|
App.RecentView.refresh(data.stream, clear: true)
|
||||||
@renderPersonal()
|
@renderPersonal()
|
||||||
App.RecentView.fetchFull(load)
|
App.RecentView.fetchFull(load)
|
||||||
|
|
||||||
App.Config.set( 'navigation', App.Navigation, 'Navigations' )
|
App.Config.set('navigation', App.Navigation, 'Navigations')
|
||||||
|
|
|
@ -11,20 +11,16 @@ class Index extends App.ControllerContent
|
||||||
# check authentication
|
# check authentication
|
||||||
return if !@authenticate(false, 'Admin')
|
return if !@authenticate(false, 'Admin')
|
||||||
|
|
||||||
@interval(@load, 60000)
|
@subscribeCalendarId = App.Calendar.subscribe(@render)
|
||||||
#@load()
|
@subscribeSlaId = App.Sla.subscribe(@render)
|
||||||
|
|
||||||
load: =>
|
callback = =>
|
||||||
@startLoading()
|
|
||||||
@ajax(
|
|
||||||
id: 'sla_index'
|
|
||||||
type: 'GET'
|
|
||||||
url: @apiPath + '/slas'
|
|
||||||
processData: true
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
App.Collection.loadAssets(data.assets)
|
|
||||||
@stopLoading()
|
@stopLoading()
|
||||||
@render(data)
|
@render()
|
||||||
|
@startLoading()
|
||||||
|
App.Sla.fetchFull(
|
||||||
|
callback
|
||||||
|
clear: true
|
||||||
)
|
)
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
|
@ -56,8 +52,10 @@ class Index extends App.ControllerContent
|
||||||
)
|
)
|
||||||
|
|
||||||
release: =>
|
release: =>
|
||||||
if @subscribeId
|
if @subscribeCalendarId
|
||||||
App.Calendar.unsubscribe(@subscribeId)
|
App.Calendar.unsubscribe(@subscribeCalendarId)
|
||||||
|
if @subscribeSlaId
|
||||||
|
App.Sla.unsubscribe(@subscribeSlaId)
|
||||||
|
|
||||||
new: (e) ->
|
new: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
|
@ -153,9 +153,9 @@ class App.OnlineNotificationWidget extends App.Controller
|
||||||
@toggle.popover('hide')
|
@toggle.popover('hide')
|
||||||
|
|
||||||
fetch: =>
|
fetch: =>
|
||||||
load = (items) =>
|
load = (data) =>
|
||||||
@fetchedData = true
|
@fetchedData = true
|
||||||
App.OnlineNotification.refresh(items, { clear: true })
|
App.OnlineNotification.refresh(data.stream, clear: true)
|
||||||
@updateContent()
|
@updateContent()
|
||||||
App.OnlineNotification.fetchFull(load)
|
App.OnlineNotification.fetchFull(load)
|
||||||
|
|
||||||
|
|
|
@ -63,15 +63,15 @@ class App.Model extends Spine.Model
|
||||||
iconActivity: (user) ->
|
iconActivity: (user) ->
|
||||||
''
|
''
|
||||||
|
|
||||||
@validate: ( data = {} ) ->
|
@validate: (data = {}) ->
|
||||||
|
|
||||||
# based on model attrbutes
|
# based on model attrbutes
|
||||||
if App[ data['model'] ] && App[ data['model'] ].attributesGet
|
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
|
# based on custom attributes
|
||||||
else if data['model'].configure_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
|
# check required_if attributes
|
||||||
for attributeName, attribute of attributes
|
for attributeName, attribute of attributes
|
||||||
|
@ -186,9 +186,9 @@ class App.Model extends Spine.Model
|
||||||
|
|
||||||
@attributesGet: (screen = undefined, attributes = false) ->
|
@attributesGet: (screen = undefined, attributes = false) ->
|
||||||
if !attributes
|
if !attributes
|
||||||
attributes = clone( App[ @.className ].configure_attributes, true )
|
attributes = clone(App[ @.className ].configure_attributes, true)
|
||||||
else
|
else
|
||||||
attributes = clone( attributes, true )
|
attributes = clone(attributes, true)
|
||||||
|
|
||||||
# in case if no configure_attributes exist
|
# in case if no configure_attributes exist
|
||||||
return {} if !attributes
|
return {} if !attributes
|
||||||
|
@ -198,13 +198,13 @@ class App.Model extends Spine.Model
|
||||||
if screen
|
if screen
|
||||||
for attribute in attributes
|
for attribute in attributes
|
||||||
if attribute.screen
|
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 ]
|
for item, value of attribute.screen[ screen ]
|
||||||
attribute[item] = value
|
attribute[item] = value
|
||||||
attributesNew[ attribute.name ] = attribute
|
attributesNew[ attribute.name ] = attribute
|
||||||
|
|
||||||
# if no screen is given or no attribute has this screen - use default attributes
|
# 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
|
for attribute in attributes
|
||||||
attributesNew[ attribute.name ] = attribute
|
attributesNew[ attribute.name ] = attribute
|
||||||
|
|
||||||
|
@ -238,11 +238,11 @@ class App.Model extends Spine.Model
|
||||||
subscribeId = App[ @className ].subscribe_item(id, callback)
|
subscribeId = App[ @className ].subscribe_item(id, callback)
|
||||||
|
|
||||||
# execute if object already exists
|
# execute if object already exists
|
||||||
if !force && App[ @className ].exists( id )
|
if !force && App[ @className ].exists(id)
|
||||||
data = App[ @className ].find( id )
|
data = App[ @className ].find(id)
|
||||||
data = @_fillUp( data )
|
data = @_fillUp(data)
|
||||||
if callback
|
if callback
|
||||||
callback( data, 'full' )
|
callback(data, 'full')
|
||||||
return subscribeId
|
return subscribeId
|
||||||
|
|
||||||
# store callback and requested id
|
# store callback and requested id
|
||||||
|
@ -270,16 +270,16 @@ class App.Model extends Spine.Model
|
||||||
|
|
||||||
# full / load assets
|
# full / load assets
|
||||||
if data.assets
|
if data.assets
|
||||||
App.Collection.loadAssets( data.assets )
|
App.Collection.loadAssets(data.assets)
|
||||||
|
|
||||||
# find / load object
|
# find / load object
|
||||||
else
|
else
|
||||||
App[ @className ].refresh( data )
|
App[ @className ].refresh(data)
|
||||||
|
|
||||||
# execute callbacks
|
# execute callbacks
|
||||||
if @FULL_CALLBACK[ data.id ]
|
if @FULL_CALLBACK[ data.id ]
|
||||||
for key, callback of @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 ]
|
delete @FULL_CALLBACK[ data.id ][ key ]
|
||||||
if _.isEmpty @FULL_CALLBACK[ data.id ]
|
if _.isEmpty @FULL_CALLBACK[ data.id ]
|
||||||
delete @FULL_CALLBACK[ data.id ]
|
delete @FULL_CALLBACK[ data.id ]
|
||||||
|
@ -297,11 +297,13 @@ class App.Model extends Spine.Model
|
||||||
params =
|
params =
|
||||||
initFetch: true # fetch initial collection
|
initFetch: true # fetch initial collection
|
||||||
|
|
||||||
@subscribeId = App.Model.subscribe( methodWhichIsCalledAtLocalOrServerSiteChange )
|
@subscribeId = App.Model.subscribe(methodWhichIsCalledAtLocalOrServerSiteChange)
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
@subscribe: (callback, param = {}) ->
|
@subscribe: (callback, param = {}) ->
|
||||||
|
|
||||||
|
# global bind to changes
|
||||||
if !@SUBSCRIPTION_COLLECTION
|
if !@SUBSCRIPTION_COLLECTION
|
||||||
@SUBSCRIPTION_COLLECTION = {}
|
@SUBSCRIPTION_COLLECTION = {}
|
||||||
|
|
||||||
|
@ -320,7 +322,10 @@ class App.Model extends Spine.Model
|
||||||
events
|
events
|
||||||
=>
|
=>
|
||||||
App.Log.debug('Model', "server notify collection change #{@className}")
|
App.Log.debug('Model', "server notify collection change #{@className}")
|
||||||
@fetch( {}, { clear: true } )
|
@fetchFull(
|
||||||
|
->
|
||||||
|
clear: true
|
||||||
|
)
|
||||||
|
|
||||||
'Collection::Subscribe::' + @className
|
'Collection::Subscribe::' + @className
|
||||||
)
|
)
|
||||||
|
@ -334,9 +339,12 @@ class App.Model extends Spine.Model
|
||||||
@one 'refresh', (collection) =>
|
@one 'refresh', (collection) =>
|
||||||
@initFetchActive = true
|
@initFetchActive = true
|
||||||
callback(collection)
|
callback(collection)
|
||||||
@fetch( {}, { clear: true } )
|
@fetchFull(
|
||||||
|
->
|
||||||
|
clear: true
|
||||||
|
)
|
||||||
else
|
else
|
||||||
callback( @all() )
|
callback(@all())
|
||||||
|
|
||||||
# return key
|
# return key
|
||||||
key
|
key
|
||||||
|
@ -347,7 +355,7 @@ class App.Model extends Spine.Model
|
||||||
console.log("Item has changed", changedItem, localOrServer)
|
console.log("Item has changed", changedItem, localOrServer)
|
||||||
|
|
||||||
model = App.Model.find(1)
|
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)
|
App.Log.debug('Model', "local change #{@className}", items)
|
||||||
for item in items
|
for item in items
|
||||||
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
|
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
|
||||||
item = App[ @className ]._fillUp( item )
|
item = App[ @className ]._fillUp(item)
|
||||||
callback(item, 'change')
|
callback(item, 'change')
|
||||||
)
|
)
|
||||||
@bind(
|
@bind(
|
||||||
|
@ -386,7 +394,7 @@ class App.Model extends Spine.Model
|
||||||
App.Log.debug('Model', "local remove #{@className}", items)
|
App.Log.debug('Model', "local remove #{@className}", items)
|
||||||
for item in items
|
for item in items
|
||||||
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
|
for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ]
|
||||||
item = App[ @className ]._fillUp( item )
|
item = App[ @className ]._fillUp(item)
|
||||||
callback(item, 'remove')
|
callback(item, 'remove')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -405,7 +413,7 @@ class App.Model extends Spine.Model
|
||||||
# only trigger callbacks if object has changed
|
# only trigger callbacks if object has changed
|
||||||
if !@changeTable[key] || @changeTable[key] isnt item.updated_at
|
if !@changeTable[key] || @changeTable[key] isnt item.updated_at
|
||||||
@changeTable[key] = item.updated_at
|
@changeTable[key] = item.updated_at
|
||||||
item = App[ @className ]._fillUp( item )
|
item = App[ @className ]._fillUp(item)
|
||||||
callback(item, 'refresh')
|
callback(item, 'refresh')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -416,14 +424,13 @@ class App.Model extends Spine.Model
|
||||||
(item) =>
|
(item) =>
|
||||||
if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ]
|
if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ]
|
||||||
genericObject = undefined
|
genericObject = undefined
|
||||||
if App[ @className ].exists( item.id )
|
if App[ @className ].exists(item.id)
|
||||||
genericObject = App[ @className ].find( item.id )
|
genericObject = App[ @className ].find(item.id)
|
||||||
App.Log.debug('Model', "server change on #{@className}.find(#{item.id}) #{item.updated_at}")
|
App.Log.debug('Model', "server change on #{@className}.find(#{item.id}) #{item.updated_at}")
|
||||||
callback = =>
|
callback = =>
|
||||||
if !genericObject || new Date(item.updated_at) >= new Date(genericObject.updated_at)
|
if !genericObject || new Date(item.updated_at) >= new Date(genericObject.updated_at)
|
||||||
App.Log.debug('Model', "request #{@className}.find(#{item.id}) from server")
|
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}")
|
App.Delay.set(callback, 500, item.id, "full-#{@className}")
|
||||||
|
|
||||||
'Item::Subscribe::' + @className
|
'Item::Subscribe::' + @className
|
||||||
|
@ -460,10 +467,16 @@ class App.Model extends Spine.Model
|
||||||
|
|
||||||
fetch full collection (with assets)
|
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"
|
url = "#{@url}/?full=true"
|
||||||
App.Log.debug('Model', "fetchFull collection #{@className}", url)
|
App.Log.debug('Model', "fetchFull collection #{@className}", url)
|
||||||
App.Ajax.request(
|
App.Ajax.request(
|
||||||
|
@ -474,16 +487,20 @@ class App.Model extends Spine.Model
|
||||||
|
|
||||||
App.Log.debug('Model', "got fetchFull collection #{@className}", data)
|
App.Log.debug('Model', "got fetchFull collection #{@className}", data)
|
||||||
|
|
||||||
|
# clear collection
|
||||||
|
if params.clear
|
||||||
|
App[@className].deleteAll()
|
||||||
|
|
||||||
# full / load assets
|
# full / load assets
|
||||||
if data.assets
|
if data.assets
|
||||||
App.Collection.loadAssets( data.assets )
|
App.Collection.loadAssets(data.assets)
|
||||||
|
|
||||||
# find / load object
|
# find / load object
|
||||||
else
|
else
|
||||||
App[ @className ].refresh( data )
|
App[@className].refresh(data)
|
||||||
|
|
||||||
# execute callbacks
|
if callback
|
||||||
callback(data.stream)
|
callback(data)
|
||||||
|
|
||||||
error: (xhr, statusText, error) ->
|
error: (xhr, statusText, error) ->
|
||||||
App.Log.error('Model', statusText, error, url)
|
App.Log.error('Model', statusText, error, url)
|
||||||
|
@ -494,7 +511,7 @@ class App.Model extends Spine.Model
|
||||||
for id, keys of @SUBSCRIPTION_ITEM
|
for id, keys of @SUBSCRIPTION_ITEM
|
||||||
return false if !_.isEmpty(keys)
|
return false if !_.isEmpty(keys)
|
||||||
|
|
||||||
if @SUBSCRIPTION_COLLECTION && !_.isEmpty( @SUBSCRIPTION_COLLECTION )
|
if @SUBSCRIPTION_COLLECTION && !_.isEmpty(@SUBSCRIPTION_COLLECTION)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -502,8 +519,8 @@ class App.Model extends Spine.Model
|
||||||
@_fillUp: (data, classNames = []) ->
|
@_fillUp: (data, classNames = []) ->
|
||||||
|
|
||||||
# fill up via relations
|
# fill up via relations
|
||||||
return data if !App[ @className ].configure_attributes
|
return data if !App[@className].configure_attributes
|
||||||
for attribute in App[ @className ].configure_attributes
|
for attribute in App[@className].configure_attributes
|
||||||
|
|
||||||
# lookup relations
|
# lookup relations
|
||||||
if attribute.relation
|
if attribute.relation
|
||||||
|
@ -512,19 +529,19 @@ class App.Model extends Spine.Model
|
||||||
if !_.contains(classNames, @className)
|
if !_.contains(classNames, @className)
|
||||||
|
|
||||||
# only if relation model exists
|
# only if relation model exists
|
||||||
if App[ attribute.relation ]
|
if App[attribute.relation]
|
||||||
withoutId = attribute.name.substr( 0, attribute.name.length - 3 )
|
withoutId = attribute.name.substr(0, attribute.name.length - 3)
|
||||||
if attribute.name.substr( attribute.name.length - 3, attribute.name.length ) is '_id'
|
if attribute.name.substr(attribute.name.length - 3, attribute.name.length) is '_id'
|
||||||
if data[attribute.name]
|
if data[attribute.name]
|
||||||
|
|
||||||
# only if relation record exists in collection
|
# only if relation record exists in collection
|
||||||
if App[ attribute.relation ].exists( data[attribute.name] )
|
if App[ attribute.relation ].exists(data[attribute.name])
|
||||||
item = App[ attribute.relation ].find( data[attribute.name] )
|
item = App[attribute.relation].find(data[attribute.name])
|
||||||
item = App[ attribute.relation ]._fillUp(item, classNames.concat(@className))
|
item = App[attribute.relation]._fillUp(item, classNames.concat(@className))
|
||||||
data[ withoutId ] = item
|
data[withoutId] = item
|
||||||
else
|
else
|
||||||
if !attribute.do_not_log
|
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
|
data
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
@ -49,51 +49,29 @@ curl http://localhost/api/v1/slas.json -v -u #{login}:#{password}
|
||||||
def index
|
def index
|
||||||
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
||||||
|
|
||||||
assets = {}
|
if params[:full]
|
||||||
|
|
||||||
# calendars
|
# calendars
|
||||||
|
assets = {}
|
||||||
calendar_ids = []
|
calendar_ids = []
|
||||||
Calendar.all.order(:name, :created_at).each {|calendar|
|
Calendar.all.each {|calendar|
|
||||||
calendar_ids.push calendar.id
|
|
||||||
assets = calendar.assets(assets)
|
assets = calendar.assets(assets)
|
||||||
}
|
}
|
||||||
|
|
||||||
# slas
|
# slas
|
||||||
sla_ids = []
|
sla_ids = []
|
||||||
models = Models.all
|
Sla.all.each {|item|
|
||||||
Sla.all.order(:name, :created_at).each {|sla|
|
sla_ids.push item.id
|
||||||
sla_ids.push sla.id
|
assets = item.assets(assets)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
attribute_object = attribute_ref_class.find_by(id: content['value'])
|
|
||||||
assets = attribute_object.assets(assets)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
calendar_ids: calendar_ids,
|
record_ids: sla_ids,
|
||||||
sla_ids: sla_ids,
|
|
||||||
assets: assets,
|
assets: assets,
|
||||||
}, status: :ok
|
}, status: :ok
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
model_index_render(Sla, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
Loading…
Reference in a new issue