From 286c229ef9f58eb7369eab03a4631a42dc31b382 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 20 Nov 2018 12:17:23 -0300 Subject: [PATCH] Initialization and settings upgrades --- tests/dummy/app/routes/application.coffee | 47 +++++++++++++++----- tests/dummy/app/templates/application.emblem | 17 ++++--- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/tests/dummy/app/routes/application.coffee b/tests/dummy/app/routes/application.coffee index f7f2144..c3a638d 100644 --- a/tests/dummy/app/routes/application.coffee +++ b/tests/dummy/app/routes/application.coffee @@ -25,18 +25,41 @@ export default Ember.Route.extend DunlopApplicationRoute, # record.unloadRecord() preloadResources: -> - @store.findAll 'panda/workflow-instance-type' - @store.findAll 'panda/organization' - @store.findAll 'user' - @store.findAll 'panda/tracker-subject' - @set 'router.globals.adapters', @store.findAll 'panda/adapter' - #Ember.RSVP.all([ - # @store.findAll 'workflow-instance-type' - # @store.findAll 'organization' - # @store.findAll 'user' - # @store.findAll 'tracker-subject' - #]).then => - # @set 'router.globals.preload_resources_fulfilled', true + Ember.RSVP.all([ + @store.findAll 'panda/workflow-instance-type' + @store.findAll 'panda/organization' + @store.findAll 'user' + @store.findAll 'panda/tracker-subject' + @store.findAll 'panda/adapter' + @store.query('dunlop/user-filter', q: {scope_key_matches: 'panda/%'}) + @load_backend_settings() + ]).catch((reason) => + @get('initial_resources_reject')(reason) + ).then (results...) => + @set 'router.globals.adapters', results[4] #.content ? this is a promise, could be an array @store.peekAll('panda/adapter') + @get('initial_resources_resolve')() + + load_backend_settings: -> + session = @get('session') + url = "#{config.apiHost}/#{config.apiNamespace}/settings" + success = (settings) => + # iterate for data bindings (environment) + return unless settings.data? + for setting in settings.data + @set "router.globals.#{setting.id}", setting.attributes.value + #Ember.assign @get('router.globals'), settings + window.app_globals = @get('router.globals') + request = + url: url + type: 'GET' + contentType: "application/json" + success: success + dataType: "json" + if get(session, 'isAuthenticated') + session.authorize 'authorizer:devise', (key, authorization) -> + request.crossDomain = true + request.headers = {"#{key}": authorization} + Ember.$.ajax request actions: debug: -> debugger diff --git a/tests/dummy/app/templates/application.emblem b/tests/dummy/app/templates/application.emblem index 7c21e96..0d288e7 100644 --- a/tests/dummy/app/templates/application.emblem +++ b/tests/dummy/app/templates/application.emblem @@ -14,15 +14,14 @@ .ui.floating.info.message i.close.icon{action (mut globals.flash.notice) ''} = globals.flash.notice - = outlet - /if globals.preload_resources_fulfilled - / = outlet - /else - / .ui.icon.message - / i.notched.circle.loading.icon - / .content - / .header Preloading resources... - / p Loading resources globally required before continuing with the application. + if globals.initial_resources_fulfilled + = outlet + else + .ui.icon.message + i.notched.circle.loading.icon + .content + .header Initial resources not loaded... + p Loading resources globally required before continuing with the application. /button.basic.button{ action 'debug'} debug = outlet 'modal'