diff --git a/doc/source/configuration/pluggable_panels.rst b/doc/source/configuration/pluggable_panels.rst index a03664f811..3cc8a49534 100644 --- a/doc/source/configuration/pluggable_panels.rst +++ b/doc/source/configuration/pluggable_panels.rst @@ -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 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`` diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index b94c47c54e..03b80c43a7 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -454,11 +454,8 @@ if DEFAULT_THEME_PATH is not None: _LOG.warning("DEFAULT_THEME_PATH has been deprecated. Please convert " "your settings to make use of AVAILABLE_THEMES.") -# Discover all the directories that contain static files; at the same time -# discover all the xstatic module entry points to embed in our HTML -STATICFILES_DIRS = settings_utils.get_xstatic_dirs( - XSTATIC_MODULES, HORIZON_CONFIG) -STATICFILES_DIRS += theme_settings.get_theme_static_dirs( +# Discover all the directories that contain static files +STATICFILES_DIRS = theme_settings.get_theme_static_dirs( AVAILABLE_THEMES, THEME_COLLECTION_DIR, ROOT_PATH) # 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 +# 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 # for each theme configured. HORIZON_COMPRESS_OFFLINE_CONTEXT_BASE = { diff --git a/openstack_dashboard/test/test_plugins/panel_config/_10_admin_add_panel.py b/openstack_dashboard/test/test_plugins/panel_config/_10_admin_add_panel.py index 6e0b047b88..ed490549ea 100644 --- a/openstack_dashboard/test/test_plugins/panel_config/_10_admin_add_panel.py +++ b/openstack_dashboard/test/test_plugins/panel_config/_10_admin_add_panel.py @@ -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 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 ADD_HEADER_SECTIONS = \ ['openstack_dashboard.test.test_panels.plugin_panel.views.TestBannerView',] diff --git a/openstack_dashboard/test/test_plugins/panel_tests.py b/openstack_dashboard/test/test_plugins/panel_tests.py index 7b98d00f56..1e29cf3e81 100644 --- a/openstack_dashboard/test/test_plugins/panel_tests.py +++ b/openstack_dashboard/test/test_plugins/panel_tests.py @@ -37,6 +37,7 @@ HORIZON_CONFIG.pop('default_dashboard', None) HORIZON_CONFIG.pop('js_files', None) HORIZON_CONFIG.pop('js_spec_files', None) HORIZON_CONFIG.pop('scss_files', None) +HORIZON_CONFIG.pop('xstatic_modules', None) 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_SPEC_FILES, HORIZON_CONFIG['js_spec_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, HORIZON_CONFIG['header_sections']) diff --git a/openstack_dashboard/utils/settings.py b/openstack_dashboard/utils/settings.py index 145596d802..4100bc54c0 100644 --- a/openstack_dashboard/utils/settings.py +++ b/openstack_dashboard/utils/settings.py @@ -110,6 +110,7 @@ def update_dashboards(modules, horizon_config, installed_apps): js_files = [] js_spec_files = [] scss_files = [] + xstatic_modules = [] panel_customization = [] header_sections = [] extra_tabs = {} @@ -145,6 +146,7 @@ def update_dashboards(modules, horizon_config, installed_apps): if f not in existing]) js_spec_files.extend(config.get('ADD_JS_SPEC_FILES', [])) scss_files.extend(config.get('ADD_SCSS_FILES', [])) + xstatic_modules.extend(config.get('ADD_XSTATIC_MODULES', [])) update_horizon_config.update( config.get('UPDATE_HORIZON_CONFIG', {})) 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_spec_files', []).extend(js_spec_files) horizon_config.setdefault('scss_files', []).extend(scss_files) + horizon_config.setdefault('xstatic_modules', []).extend(xstatic_modules) horizon_config['extra_tabs'] = extra_tabs # 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. """ STATICFILES_DIRS = [] - HORIZON_CONFIG['xstatic_lib_files'] = [] + HORIZON_CONFIG.setdefault('xstatic_lib_files', []) for module_name, files in XSTATIC_MODULES: module = import_module(module_name) if module_name == 'xstatic.pkg.jquery_ui': diff --git a/releasenotes/notes/bug-1755339-2dfa3ce2accb568f.yaml b/releasenotes/notes/bug-1755339-2dfa3ce2accb568f.yaml new file mode 100644 index 0000000000..89cdd32fa5 --- /dev/null +++ b/releasenotes/notes/bug-1755339-2dfa3ce2accb568f.yaml @@ -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 `__ + in horizon documentation.