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')() 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

View file

@ -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

View file

@ -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: =>

View file

@ -463,8 +463,8 @@ class App.Navigation extends App.ControllerWidgetPermanent
@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)

View file

@ -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()

View file

@ -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)

View file

@ -302,6 +302,8 @@ class App.Model extends Spine.Model
### ###
@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,7 +339,10 @@ 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())
@ -423,7 +431,6 @@ class App.Model extends Spine.Model
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
@ -462,8 +469,14 @@ class App.Model extends Spine.Model
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,6 +487,10 @@ 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)
@ -482,8 +499,8 @@ class App.Model extends Spine.Model
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)

View file

@ -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