Improved reload of full collections.
This commit is contained in:
parent
19ce86dbf2
commit
a6f71a0bd7
|
@ -66,7 +66,7 @@ class App.Auth
|
||||||
|
|
||||||
# refresh/load default collections
|
# refresh/load default collections
|
||||||
for key, value of data.default_collections
|
for key, value of data.default_collections
|
||||||
App.Collection.load( type: key, data: value )
|
App.Collection.rest( type: key, data: value )
|
||||||
|
|
||||||
# rebuild navbar with new navbar items
|
# rebuild navbar with new navbar items
|
||||||
Spine.trigger 'navrebuild', data.session
|
Spine.trigger 'navrebuild', data.session
|
||||||
|
|
|
@ -9,6 +9,11 @@ class App.Collection
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
_instance.load( args )
|
_instance.load( args )
|
||||||
|
|
||||||
|
@reset: ( args ) ->
|
||||||
|
if _instance == undefined
|
||||||
|
_instance ?= new _Singleton
|
||||||
|
_instance.reset( args )
|
||||||
|
|
||||||
@find: ( type, id, callback, force ) ->
|
@find: ( type, id, callback, force ) ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
_instance ?= new _Singleton
|
_instance ?= new _Singleton
|
||||||
|
@ -58,6 +63,16 @@ class _Singleton
|
||||||
console.log 'loadCollection:trigger', type, data.collections[type]
|
console.log '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
|
||||||
|
Spine.bind 'restCollection', (data) =>
|
||||||
|
|
||||||
|
# load collections
|
||||||
|
if data.collections
|
||||||
|
for type of data.collections
|
||||||
|
|
||||||
|
console.log 'restCollection:trigger', type, data.collections[type]
|
||||||
|
@reset( localStorage: data.localStorage, type: type, data: data.collections[type] )
|
||||||
|
|
||||||
# find collections to load
|
# find collections to load
|
||||||
@_loadCollectionAll()
|
@_loadCollectionAll()
|
||||||
|
|
||||||
|
@ -71,6 +86,22 @@ class _Singleton
|
||||||
console.log('load INIT', data)
|
console.log('load INIT', data)
|
||||||
@load( data )
|
@load( data )
|
||||||
|
|
||||||
|
reset: (params) ->
|
||||||
|
console.log( 'reset', params )
|
||||||
|
|
||||||
|
# remove permanent storage
|
||||||
|
list = App.Store.list()
|
||||||
|
for key in list
|
||||||
|
parts = key.split('::')
|
||||||
|
if parts[0] is 'collection' && parts[1] is params.type
|
||||||
|
App.Store.delete(key)
|
||||||
|
|
||||||
|
# empty in-memory
|
||||||
|
App[ params.type ].refresh( [], { clear: true } )
|
||||||
|
|
||||||
|
# load with new data
|
||||||
|
@load(params)
|
||||||
|
|
||||||
load: (params) ->
|
load: (params) ->
|
||||||
console.log( 'load', params )
|
console.log( 'load', params )
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module ExtraCollection
|
module ExtraCollection
|
||||||
def session(collections)
|
def session( collections, user )
|
||||||
|
|
||||||
# all base stuff
|
# all base stuff
|
||||||
collections['Role'] = Role.all
|
collections['Role'] = Role.all
|
||||||
|
@ -7,7 +7,7 @@ module ExtraCollection
|
||||||
collections['Organization'] = Organization.all
|
collections['Organization'] = Organization.all
|
||||||
|
|
||||||
end
|
end
|
||||||
def push(collections)
|
def push( collections, user )
|
||||||
|
|
||||||
# all base stuff
|
# all base stuff
|
||||||
collections['Role'] = Role.all
|
collections['Role'] = Role.all
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module ExtraCollection
|
module ExtraCollection
|
||||||
def session(collections)
|
def session( collections, user )
|
||||||
|
|
||||||
collections['Network'] = Network.all
|
collections['Network'] = Network.all
|
||||||
collections['NetworkCategory'] = Network::Category.all
|
collections['NetworkCategory'] = Network::Category.all
|
||||||
|
@ -7,7 +7,7 @@ module ExtraCollection
|
||||||
collections['NetworkPrivacy'] = Network::Privacy.all
|
collections['NetworkPrivacy'] = Network::Privacy.all
|
||||||
|
|
||||||
end
|
end
|
||||||
def push(collections)
|
def push( collections, user )
|
||||||
|
|
||||||
collections['Network'] = Network.all
|
collections['Network'] = Network.all
|
||||||
collections['NetworkCategory'] = Network::Category.all
|
collections['NetworkCategory'] = Network::Category.all
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module ExtraCollection
|
module ExtraCollection
|
||||||
def session(collections)
|
def session( collections, user )
|
||||||
|
|
||||||
# all ticket stuff
|
# all ticket stuff
|
||||||
collections['TicketStateType'] = Ticket::StateType.all
|
collections['TicketStateType'] = Ticket::StateType.all
|
||||||
|
@ -15,7 +15,7 @@ module ExtraCollection
|
||||||
collections['EmailAddress'] = EmailAddress.all
|
collections['EmailAddress'] = EmailAddress.all
|
||||||
|
|
||||||
end
|
end
|
||||||
def push(collections)
|
def push( collections, user )
|
||||||
|
|
||||||
# all ticket stuff
|
# all ticket stuff
|
||||||
collections['TicketStateType'] = Ticket::StateType.all
|
collections['TicketStateType'] = Ticket::StateType.all
|
||||||
|
|
|
@ -21,7 +21,7 @@ class SessionsController < ApplicationController
|
||||||
user = User.find_fulldata(user.id)
|
user = User.find_fulldata(user.id)
|
||||||
|
|
||||||
# auto population of default collections
|
# auto population of default collections
|
||||||
default_collection = SessionHelper::default_collections()
|
default_collection = SessionHelper::default_collections(user)
|
||||||
|
|
||||||
# set session user_id
|
# set session user_id
|
||||||
session[:user_id] = user['id']
|
session[:user_id] = user['id']
|
||||||
|
@ -82,7 +82,7 @@ class SessionsController < ApplicationController
|
||||||
user = User.user_data_full( user_id )
|
user = User.user_data_full( user_id )
|
||||||
|
|
||||||
# auto population of default collections
|
# auto population of default collections
|
||||||
default_collection = SessionHelper::default_collections()
|
default_collection = SessionHelper::default_collections(user)
|
||||||
|
|
||||||
# return current session
|
# return current session
|
||||||
render :json => {
|
render :json => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module SessionHelper
|
module SessionHelper
|
||||||
def self.default_collections
|
def self.default_collections(user)
|
||||||
|
|
||||||
# auto population collections, store all here
|
# auto population collections, store all here
|
||||||
default_collection = {}
|
default_collection = {}
|
||||||
|
@ -9,12 +9,12 @@ module SessionHelper
|
||||||
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
|
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
|
||||||
for file in files
|
for file in files
|
||||||
load file
|
load file
|
||||||
ExtraCollection.session(default_collection)
|
ExtraCollection.session( default_collection, user )
|
||||||
end
|
end
|
||||||
|
|
||||||
return default_collection
|
return default_collection
|
||||||
end
|
end
|
||||||
def self.push_collections
|
def self.push_collections(user)
|
||||||
|
|
||||||
# auto population collections, store all here
|
# auto population collections, store all here
|
||||||
push_collections = {}
|
push_collections = {}
|
||||||
|
@ -24,7 +24,7 @@ module SessionHelper
|
||||||
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
|
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
|
||||||
for file in files
|
for file in files
|
||||||
load file
|
load file
|
||||||
ExtraCollection.push(push_collections)
|
ExtraCollection.push( push_collections, user )
|
||||||
end
|
end
|
||||||
|
|
||||||
return push_collections
|
return push_collections
|
||||||
|
|
|
@ -338,7 +338,7 @@ class UserState
|
||||||
collections = CacheIn.get( cache_key )
|
collections = CacheIn.get( cache_key )
|
||||||
if !collections
|
if !collections
|
||||||
collections = {}
|
collections = {}
|
||||||
push_collection = SessionHelper::push_collections()
|
push_collection = SessionHelper::push_collections(user)
|
||||||
push_collection.each { | key, value |
|
push_collection.each { | key, value |
|
||||||
collections[ key ] = true
|
collections[ key ] = true
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ class UserState
|
||||||
cache_key = @cache_key + '_push_collections_' + key
|
cache_key = @cache_key + '_push_collections_' + key
|
||||||
if CacheIn.expired(cache_key)
|
if CacheIn.expired(cache_key)
|
||||||
if push_collection.empty?
|
if push_collection.empty?
|
||||||
push_collection = SessionHelper::push_collections()
|
push_collection = SessionHelper::push_collections(user)
|
||||||
end
|
end
|
||||||
push_collection_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
push_collection_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
self.log 'notice', "---user - fetch push_collection data " + cache_key
|
self.log 'notice', "---user - fetch push_collection data " + cache_key
|
||||||
|
@ -576,7 +576,7 @@ class ClientState
|
||||||
data['collections'] = {}
|
data['collections'] = {}
|
||||||
data['collections'][key] = push_collections
|
data['collections'][key] = push_collections
|
||||||
self.transaction({
|
self.transaction({
|
||||||
:event => 'loadCollection',
|
:event => 'restCollection',
|
||||||
:data => data,
|
:data => data,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue