Auto-collect app/ instead of only app/core/

Angular code for openstack_dashboard is almost finished
migrating to openstack_dashboard/static/app/.

Previously, the root module of app (app.module.js) was explicitly
included from _conf.html so that environment variables from Django
could be captured in the 'horizon.app.conf' constant.

This prevented auto-collection at the static/app/ level because
app.module.js will be included twice (once from _conf.html, and
again during auto-collection)

It turns out that 'horizon.app.conf' is unnecessary as an Angular
constant. It's only use is to initialize the 'horizon.conf' global
provided by horizon.js.

This patch refactors _conf.html to directly initialize horizon.conf.
This removes the need for app.module.js to be included from
_conf.html, which allows us to change the auto-collection directory
to 'app/'.

Now all files in horizon/static and openstack_dashboard/static/app
are auto-collected, without including app.module.js twice. All new
angular files are expected to live in one of these two locations,
minimizing changes to static_settings.py to include new files for
auto-collection

Change-Id: I95b6f13c85eb08c875885812a7db054a5aa6e7c2
Partial-Bug: #1458697
Closes-Bug: #1477825
This commit is contained in:
Tyr Johanson 2015-07-24 16:34:57 -06:00
parent 55d88786fd
commit 66485be81a
4 changed files with 21 additions and 32 deletions

View File

@ -38,6 +38,11 @@ var Horizon = function () {
.replace(/\//g, '/'); .replace(/\//g, '/');
}; };
/* Storage for backend configuration variables which the frontend
* should be aware of.
*/
horizon.conf = {};
return horizon; return horizon;
}; };

View File

@ -59,20 +59,11 @@
.concat(horizonPlugInModules) .concat(horizonPlugInModules)
) )
.constant('horizon.app.conf', {
// Placeholders; updated by Django.
static_url: null,
ajax: {
queue_limit: null
}
})
.run(updateHorizon); .run(updateHorizon);
updateHorizon.$inject = [ updateHorizon.$inject = [
'gettextCatalog', 'gettextCatalog',
'horizon.framework.conf.spinner_options', 'horizon.framework.conf.spinner_options',
'horizon.app.conf',
'horizon.framework.util.tech-debt.helper-functions', 'horizon.framework.util.tech-debt.helper-functions',
'$cookieStore', '$cookieStore',
'$http', '$http',
@ -82,7 +73,6 @@
function updateHorizon( function updateHorizon(
gettextCatalog, gettextCatalog,
spinnerOptions, spinnerOptions,
hzConfig,
hzUtils, hzUtils,
$cookieStore, $cookieStore,
$http, $http,
@ -93,9 +83,7 @@
//expose the configuration for horizon legacy variable //expose the configuration for horizon legacy variable
horizon.utils = hzUtils; horizon.utils = hzUtils;
horizon.conf = angular.extend({ horizon.conf.spinner_options = spinnerOptions;
spinner_options: spinnerOptions
}, hzConfig);
horizon.cookies = angular.extend({}, $cookieStore, { horizon.cookies = angular.extend({}, $cookieStore, {
put: put, put: put,

View File

@ -153,5 +153,5 @@ def find_static_files(ROOT_PATH, HORIZON_CONFIG):
file_discovery.populate_horizon_config( file_discovery.populate_horizon_config(
HORIZON_CONFIG, HORIZON_CONFIG,
os.path.join(ROOT_PATH, 'static/'), os.path.join(ROOT_PATH, 'static/'),
sub_path='app/core/' sub_path='app/'
) )

View File

@ -13,36 +13,32 @@
{% endcompress %} {% endcompress %}
<script type='text/javascript' charset='utf-8'> <script type='text/javascript' charset='utf-8'>
(function (global) {
'use strict';
// make translation info available on client // make translation info available on client
horizon.languageCode = '{{ LANGUAGE_CODE }}'; horizon.languageCode = '{{ LANGUAGE_CODE }}';
horizon.languageBidi = '{{ LANGUAGE_BIDI }}'; horizon.languageBidi = '{{ LANGUAGE_BIDI }}';
horizon.datepickerLocale = '{{ DATEPICKER_LOCALE }}'; horizon.datepickerLocale = '{{ DATEPICKER_LOCALE }}';
/* Load angular modules extensions list before we include angular/horizon.js */ /* Load angular modules extensions list before we include angular/horizon.js */
var horizonPlugInModules = {{ HORIZON_CONFIG.angular_modules|default:"[]"|safe }}; global.horizonPlugInModules = {{ HORIZON_CONFIG.angular_modules|default:"[]"|safe }};
</script>
{% compress js %} /* Storage for backend configuration variables which the frontend
<script src="{{ STATIC_URL }}app/app.module.js"></script>
{% endcompress %}
<script type='text/javascript' charset='utf-8'>
/* Storage for backend configuration variables which the frontend
* should be aware of. * should be aware of.
*/ */
var conf = horizon.conf;
angular.module('horizon.app') conf.static_url = "{{ STATIC_URL }}";
.config(['horizon.app.conf', function (hzConfig) { conf.ajax = {
hzConfig.static_url = "{{ STATIC_URL }}";
hzConfig.ajax = {
queue_limit: {{ HORIZON_CONFIG.ajax_queue_limit|default:"null" }} queue_limit: {{ HORIZON_CONFIG.ajax_queue_limit|default:"null" }}
}; };
hzConfig.auto_fade_alerts = { conf.auto_fade_alerts = {
delay: {{ HORIZON_CONFIG.auto_fade_alerts.delay|default:"3000" }}, delay: {{ HORIZON_CONFIG.auto_fade_alerts.delay|default:"3000" }},
fade_duration: {{ HORIZON_CONFIG.auto_fade_alerts.fade_duration|default:"1500" }}, fade_duration: {{ HORIZON_CONFIG.auto_fade_alerts.fade_duration|default:"1500" }},
types: {{ HORIZON_CONFIG.auto_fade_alerts.types|default:"[]"|safe }} types: {{ HORIZON_CONFIG.auto_fade_alerts.types|default:"[]"|safe }}
}; };
hzConfig.disable_password_reveal = {{ HORIZON_CONFIG.disable_password_reveal|yesno:"true,false" }}; conf.disable_password_reveal =
}]); {{ HORIZON_CONFIG.disable_password_reveal|yesno:"true,false" }};
})(this);
</script> </script>