Merge "Add plugin xstatic modules support"

This commit is contained in:
Zuul 2018-03-20 17:25:56 +00:00 committed by Gerrit Code Review
commit 1cdafd8895
6 changed files with 54 additions and 6 deletions

View File

@ -79,6 +79,29 @@ A list of scss files to be included in the compressed set of files that are
loaded on every page. We recommend one scss file per dashboard, use @import if loaded on every page. We recommend one scss file per dashboard, use @import if
you need to include additional scss files for panels. you need to include additional scss files for panels.
``ADD_XSTATIC_MODULES``
-----------------------
.. versionadded:: 14.0.0(Rocky)
A list of xstatic modules containing javascript and scss files to be included
in the compressed set of files that are loaded on every page. Related files
specified in ``ADD_XSTATIC_MODULES`` do not need to be included in
``ADD_JS_FILES``. This option expects a list of tuples, each consists of
a xstatic module and a list of javascript files to be loaded if any.
For more details, please check the comment of ``BASE_XSTATIC_MODULES``
in openstack_dashboard/utils/settings.py.
Example:
.. code-block:: python
ADD_XSTATIC_MODULES = [
('xstatic.pkg.foo', ['foo.js']),
('xstatic.pkg.bar', None),
]
.. _auto_discover_static_files: .. _auto_discover_static_files:
``AUTO_DISCOVER_STATIC_FILES`` ``AUTO_DISCOVER_STATIC_FILES``

View File

@ -454,11 +454,8 @@ if DEFAULT_THEME_PATH is not None:
_LOG.warning("DEFAULT_THEME_PATH has been deprecated. Please convert " _LOG.warning("DEFAULT_THEME_PATH has been deprecated. Please convert "
"your settings to make use of AVAILABLE_THEMES.") "your settings to make use of AVAILABLE_THEMES.")
# Discover all the directories that contain static files; at the same time # Discover all the directories that contain static files
# discover all the xstatic module entry points to embed in our HTML STATICFILES_DIRS = theme_settings.get_theme_static_dirs(
STATICFILES_DIRS = settings_utils.get_xstatic_dirs(
XSTATIC_MODULES, HORIZON_CONFIG)
STATICFILES_DIRS += theme_settings.get_theme_static_dirs(
AVAILABLE_THEMES, THEME_COLLECTION_DIR, ROOT_PATH) AVAILABLE_THEMES, THEME_COLLECTION_DIR, ROOT_PATH)
# Ensure that we always have a SECRET_KEY set, even when no local_settings.py # Ensure that we always have a SECRET_KEY set, even when no local_settings.py
@ -496,6 +493,13 @@ INSTALLED_APPS[0:0] = ADD_INSTALLED_APPS
NG_TEMPLATE_CACHE_AGE = NG_TEMPLATE_CACHE_AGE if not DEBUG else 0 NG_TEMPLATE_CACHE_AGE = NG_TEMPLATE_CACHE_AGE if not DEBUG else 0
# Include xstatic_modules specified in plugin
XSTATIC_MODULES += HORIZON_CONFIG['xstatic_modules']
# Discover all the xstatic module entry points to embed in our HTML
STATICFILES_DIRS += settings_utils.get_xstatic_dirs(
XSTATIC_MODULES, HORIZON_CONFIG)
# This base context objects gets added to the offline context generator # This base context objects gets added to the offline context generator
# for each theme configured. # for each theme configured.
HORIZON_COMPRESS_OFFLINE_CONTEXT_BASE = { HORIZON_COMPRESS_OFFLINE_CONTEXT_BASE = {

View File

@ -24,6 +24,12 @@ ADD_JS_SPEC_FILES = ['plugin_panel/plugin.spec.js']
# A list of scss files to be included in the compressed set of files # A list of scss files to be included in the compressed set of files
ADD_SCSS_FILES = ['plugin_panel/plugin.scss'] ADD_SCSS_FILES = ['plugin_panel/plugin.scss']
# A list of tuples of xstatic modules and files to be included
# in the compressed set of files
ADD_XSTATIC_MODULES = [
('xstatic.pkg.foo', None)
]
# A list of extensible header views to be displayed # A list of extensible header views to be displayed
ADD_HEADER_SECTIONS = \ ADD_HEADER_SECTIONS = \
['openstack_dashboard.test.test_panels.plugin_panel.views.TestBannerView',] ['openstack_dashboard.test.test_panels.plugin_panel.views.TestBannerView',]

View File

@ -37,6 +37,7 @@ HORIZON_CONFIG.pop('default_dashboard', None)
HORIZON_CONFIG.pop('js_files', None) HORIZON_CONFIG.pop('js_files', None)
HORIZON_CONFIG.pop('js_spec_files', None) HORIZON_CONFIG.pop('js_spec_files', None)
HORIZON_CONFIG.pop('scss_files', None) HORIZON_CONFIG.pop('scss_files', None)
HORIZON_CONFIG.pop('xstatic_modules', None)
util_settings.update_dashboards([panel_config,], HORIZON_CONFIG, INSTALLED_APPS) util_settings.update_dashboards([panel_config,], HORIZON_CONFIG, INSTALLED_APPS)
@ -60,6 +61,8 @@ class PanelPluginTests(test.PluginTestCase):
self.assertEqual(pc.ADD_JS_FILES, HORIZON_CONFIG['js_files']) self.assertEqual(pc.ADD_JS_FILES, HORIZON_CONFIG['js_files'])
self.assertEqual(pc.ADD_JS_SPEC_FILES, HORIZON_CONFIG['js_spec_files']) self.assertEqual(pc.ADD_JS_SPEC_FILES, HORIZON_CONFIG['js_spec_files'])
self.assertEqual(pc.ADD_SCSS_FILES, HORIZON_CONFIG['scss_files']) self.assertEqual(pc.ADD_SCSS_FILES, HORIZON_CONFIG['scss_files'])
self.assertEqual(pc.ADD_XSTATIC_MODULES,
HORIZON_CONFIG['xstatic_modules'])
self.assertEqual(pc.ADD_HEADER_SECTIONS, self.assertEqual(pc.ADD_HEADER_SECTIONS,
HORIZON_CONFIG['header_sections']) HORIZON_CONFIG['header_sections'])

View File

@ -110,6 +110,7 @@ def update_dashboards(modules, horizon_config, installed_apps):
js_files = [] js_files = []
js_spec_files = [] js_spec_files = []
scss_files = [] scss_files = []
xstatic_modules = []
panel_customization = [] panel_customization = []
header_sections = [] header_sections = []
extra_tabs = {} extra_tabs = {}
@ -145,6 +146,7 @@ def update_dashboards(modules, horizon_config, installed_apps):
if f not in existing]) if f not in existing])
js_spec_files.extend(config.get('ADD_JS_SPEC_FILES', [])) js_spec_files.extend(config.get('ADD_JS_SPEC_FILES', []))
scss_files.extend(config.get('ADD_SCSS_FILES', [])) scss_files.extend(config.get('ADD_SCSS_FILES', []))
xstatic_modules.extend(config.get('ADD_XSTATIC_MODULES', []))
update_horizon_config.update( update_horizon_config.update(
config.get('UPDATE_HORIZON_CONFIG', {})) config.get('UPDATE_HORIZON_CONFIG', {}))
if config.get('DASHBOARD'): if config.get('DASHBOARD'):
@ -173,6 +175,7 @@ def update_dashboards(modules, horizon_config, installed_apps):
horizon_config.setdefault('js_files', []).extend(js_files) horizon_config.setdefault('js_files', []).extend(js_files)
horizon_config.setdefault('js_spec_files', []).extend(js_spec_files) horizon_config.setdefault('js_spec_files', []).extend(js_spec_files)
horizon_config.setdefault('scss_files', []).extend(scss_files) horizon_config.setdefault('scss_files', []).extend(scss_files)
horizon_config.setdefault('xstatic_modules', []).extend(xstatic_modules)
horizon_config['extra_tabs'] = extra_tabs horizon_config['extra_tabs'] = extra_tabs
# apps contains reference to applications declared in the enabled folder # apps contains reference to applications declared in the enabled folder
@ -247,7 +250,7 @@ def get_xstatic_dirs(XSTATIC_MODULES, HORIZON_CONFIG):
it must be handled as a special case. it must be handled as a special case.
""" """
STATICFILES_DIRS = [] STATICFILES_DIRS = []
HORIZON_CONFIG['xstatic_lib_files'] = [] HORIZON_CONFIG.setdefault('xstatic_lib_files', [])
for module_name, files in XSTATIC_MODULES: for module_name, files in XSTATIC_MODULES:
module = import_module(module_name) module = import_module(module_name)
if module_name == 'xstatic.pkg.jquery_ui': if module_name == 'xstatic.pkg.jquery_ui':

View File

@ -0,0 +1,9 @@
---
features:
- |
[:bug:`1755339`]
(for horizon plugin developers) A new plugin option ``ADD_XSTATIC_MODULES``
is now available and horizon plugins can add extra xstatic modules via the
horizon plugin "enabled" file. For more detail, see ``ADD_XSTATIC_MODULES``
description in `Pluggable Panels and Groups <https://docs.openstack.org/horizon/latest/configuration/pluggable_panels.html#ADD_XSTATIC_MODULES>`__
in horizon documentation.