Improved reload of full collections.

This commit is contained in:
Martin Edenhofer 2012-10-23 22:25:42 +02:00
parent 19ce86dbf2
commit a6f71a0bd7
8 changed files with 47 additions and 16 deletions

View file

@ -66,7 +66,7 @@ class App.Auth
# refresh/load 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
Spine.trigger 'navrebuild', data.session

View file

@ -9,6 +9,11 @@ class App.Collection
_instance ?= new _Singleton
_instance.load( args )
@reset: ( args ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.reset( args )
@find: ( type, id, callback, force ) ->
if _instance == undefined
_instance ?= new _Singleton
@ -58,6 +63,16 @@ class _Singleton
console.log 'loadCollection:trigger', type, 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
@_loadCollectionAll()
@ -71,6 +86,22 @@ class _Singleton
console.log('load INIT', 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) ->
console.log( 'load', params )

View file

@ -1,5 +1,5 @@
module ExtraCollection
def session(collections)
def session( collections, user )
# all base stuff
collections['Role'] = Role.all
@ -7,7 +7,7 @@ module ExtraCollection
collections['Organization'] = Organization.all
end
def push(collections)
def push( collections, user )
# all base stuff
collections['Role'] = Role.all

View file

@ -1,5 +1,5 @@
module ExtraCollection
def session(collections)
def session( collections, user )
collections['Network'] = Network.all
collections['NetworkCategory'] = Network::Category.all
@ -7,7 +7,7 @@ module ExtraCollection
collections['NetworkPrivacy'] = Network::Privacy.all
end
def push(collections)
def push( collections, user )
collections['Network'] = Network.all
collections['NetworkCategory'] = Network::Category.all

View file

@ -1,5 +1,5 @@
module ExtraCollection
def session(collections)
def session( collections, user )
# all ticket stuff
collections['TicketStateType'] = Ticket::StateType.all
@ -15,7 +15,7 @@ module ExtraCollection
collections['EmailAddress'] = EmailAddress.all
end
def push(collections)
def push( collections, user )
# all ticket stuff
collections['TicketStateType'] = Ticket::StateType.all

View file

@ -21,7 +21,7 @@ class SessionsController < ApplicationController
user = User.find_fulldata(user.id)
# auto population of default collections
default_collection = SessionHelper::default_collections()
default_collection = SessionHelper::default_collections(user)
# set session user_id
session[:user_id] = user['id']
@ -82,7 +82,7 @@ class SessionsController < ApplicationController
user = User.user_data_full( user_id )
# auto population of default collections
default_collection = SessionHelper::default_collections()
default_collection = SessionHelper::default_collections(user)
# return current session
render :json => {

View file

@ -1,5 +1,5 @@
module SessionHelper
def self.default_collections
def self.default_collections(user)
# auto population collections, store all here
default_collection = {}
@ -9,12 +9,12 @@ module SessionHelper
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
for file in files
load file
ExtraCollection.session(default_collection)
ExtraCollection.session( default_collection, user )
end
return default_collection
end
def self.push_collections
def self.push_collections(user)
# auto population collections, store all here
push_collections = {}
@ -24,7 +24,7 @@ module SessionHelper
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
for file in files
load file
ExtraCollection.push(push_collections)
ExtraCollection.push( push_collections, user )
end
return push_collections

View file

@ -338,7 +338,7 @@ class UserState
collections = CacheIn.get( cache_key )
if !collections
collections = {}
push_collection = SessionHelper::push_collections()
push_collection = SessionHelper::push_collections(user)
push_collection.each { | key, value |
collections[ key ] = true
}
@ -351,7 +351,7 @@ class UserState
cache_key = @cache_key + '_push_collections_' + key
if CacheIn.expired(cache_key)
if push_collection.empty?
push_collection = SessionHelper::push_collections()
push_collection = SessionHelper::push_collections(user)
end
push_collection_cache = CacheIn.get( cache_key, { :re_expire => true } )
self.log 'notice', "---user - fetch push_collection data " + cache_key
@ -576,7 +576,7 @@ class ClientState
data['collections'] = {}
data['collections'][key] = push_collections
self.transaction({
:event => 'loadCollection',
:event => 'restCollection',
:data => data,
})