From f99c72907cb14b6411bedeac6350d3388c2a8e20 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 20 Oct 2013 14:24:18 +0200 Subject: [PATCH] Improved way how to load/reset collections. --- .../javascripts/app/lib/app_post/auth.js.coffee | 5 +++-- .../javascripts/app/lib/app_post/collection.js.coffee | 11 ++++++----- app/controllers/sessions_controller.rb | 8 ++++---- lib/sessions/backend/collections.rb | 3 +-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/auth.js.coffee b/app/assets/javascripts/app/lib/app_post/auth.js.coffee index af6aa6093..288ad5c5e 100644 --- a/app/assets/javascripts/app/lib/app_post/auth.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/auth.js.coffee @@ -84,9 +84,10 @@ class App.Auth App.Session.set( key, value ) # refresh default collections - for key, value of data.default_collections - App[key].refresh( value, options: { clear: true } ) + if data.collections + App.Event.trigger 'resetCollection', data.collections + # trigger auth ok with new session data App.Event.trigger( 'auth', data.session ) # init of i18n diff --git a/app/assets/javascripts/app/lib/app_post/collection.js.coffee b/app/assets/javascripts/app/lib/app_post/collection.js.coffee index 98aff762e..1b38112e8 100644 --- a/app/assets/javascripts/app/lib/app_post/collection.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/collection.js.coffee @@ -31,13 +31,14 @@ class _collectionSingleton extends Spine.Module # add trigger - bind new events App.Event.bind 'resetCollection', (data) => + if !data + @log 'error', 'resetCollection:trigger, got no data, cant for collections' + return # load collections - if data.collections - for type of data.collections - - @log 'debug', 'resetCollection:trigger', type, data.collections[type] - @reset( localStorage: data.localStorage, type: type, data: data.collections[type] ) + for type, collection of data + @log 'debug', 'resetCollection:trigger', type, collection + @reset( localStorage: data.localStorage, type: type, data: collection ) # find collections to load @_loadObjectsFromLocalStore() diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 27e355a03..9bdc5b11c 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -31,7 +31,7 @@ class SessionsController < ApplicationController user.activity_stream_log( 'session started', user.id, true ) # auto population of default collections - default_collection = SessionHelper::default_collections(user) + collections = SessionHelper::default_collections(user) # set session user_id user = User.find_fulldata(user.id) @@ -50,9 +50,9 @@ class SessionsController < ApplicationController # return new session data render :json => { - :session => user, - :default_collections => default_collection, - :logon_session => logon_session_key, + :session => user, + :collections => collections, + :logon_session => logon_session_key, }, :status => :created end diff --git a/lib/sessions/backend/collections.rb b/lib/sessions/backend/collections.rb index 600dd1012..2eaf6ab11 100644 --- a/lib/sessions/backend/collections.rb +++ b/lib/sessions/backend/collections.rb @@ -56,8 +56,7 @@ module Sessions::Backend::Collections # send update to browser data = {} - data['collections'] = {} - data['collections'][key] = push_collections + data[key] = push_collections client.send({ :event => 'resetCollection', :data => data,