From 941b12aec2c02e84d19224d57069f6f12c74df89 Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Thu, 25 Sep 2014 15:36:21 -0700 Subject: [PATCH] Autoconfiguration before bootstrap. This patch delays the application bootstrap until we've tried to load and inject parameters saved in an external configuration file. If that file isn't there, the application will fall back to its own sane defaults, however this will give us an opportunity to more gracefully configure the webclient for each install. Example: Client and API are not on the same host. Change-Id: I1d0ce573dd05faa1efb325871ad5c30f08529205 --- src/app/storyboard/auto_configuration.js | 50 ++++++++++++++++++++++++ src/index.html | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/app/storyboard/auto_configuration.js diff --git a/src/app/storyboard/auto_configuration.js b/src/app/storyboard/auto_configuration.js new file mode 100644 index 00000000..1e716d5c --- /dev/null +++ b/src/app/storyboard/auto_configuration.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/* + * Automatic configuration loader. Checks the /config endpoint, and if + * it receives a JSON hash will load all the found values into the application + * module. + */ +angular.element(document) + .ready(function () { + 'use strict'; + + var initInjector = angular.injector(['ng']); + var $http = initInjector.get('$http'); + var $log = initInjector.get('$log'); + + function initializeApplication(config) { + // Load everything we got into our module. + for (var key in config) { + $log.debug('Configuration: ' + key + ' -> ' + config[key]); + angular.module('storyboard').constant(key, config[key]); + } + angular.bootstrap(document, ['storyboard']); + } + + $log.info('Attempting to load parameters from ./config.json'); + $http.get('./config.json').then( + function (response) { + initializeApplication(response.data); + }, + function () { + $log.warn('Cannot load ./config.json, using defaults.'); + initializeApplication({}); + } + ); + } +); \ No newline at end of file diff --git a/src/index.html b/src/index.html index 3af1c7f9..a47bc25c 100644 --- a/src/index.html +++ b/src/index.html @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. --> - +