2015-01-13 14:45:07 +01:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
"""
|
|
|
|
This file contains configuration for the locations of all the static file
|
|
|
|
libraries, such as JavaScript and CSS libraries. Packagers for individual
|
|
|
|
distributions can edit or replace this file, in order to change the paths
|
|
|
|
to match their distribution's standards.
|
|
|
|
"""
|
|
|
|
|
2015-07-17 15:58:34 +10:00
|
|
|
import os
|
|
|
|
|
2015-01-13 14:45:07 +01:00
|
|
|
import xstatic.main
|
|
|
|
import xstatic.pkg.angular
|
|
|
|
import xstatic.pkg.angular_bootstrap
|
2016-05-13 17:45:10 +03:00
|
|
|
import xstatic.pkg.angular_fileupload
|
2015-07-21 13:11:05 -07:00
|
|
|
import xstatic.pkg.angular_gettext
|
2015-03-30 18:41:47 -07:00
|
|
|
import xstatic.pkg.angular_lrdragndrop
|
Add Angular Schema Form
This patch adds Angular Schema Form[1] and its requirements to Horizon.
There are a number of advantages to this over the current methods of
defining forms and workflows:
- All fields have an individual template, making theming improvements,
bug fixes, and bootstrap conformity easier.
- The file and line count, especially for workflows, is dramatically
reduced. The Create Net workflow, for example, goes from 12+ files to
2, with a big reduction in boilerplate HTML.
- All field validation messages are standardised, so we can match them
across Horizon and plugins
What this patch contains:
- Many common form fields, including things like the themable checkboxes
and selects.
- A basic modal template that can be passed with ui-bootstraps $modal
service to take advantage of schema-form
Next steps:
- Remove the other modal templates so we can standardise. A single
template opened from the $modal service is fine, and we shouldn't need
several directives. In this case, we should deprecate them, as the
modal forms will be used elsewhere.
- Map commonly used form items, like transfer tables, to a schema form
type like array (they serve similar purposes, so maybe thats what
should be replaced)
- Use themable selects instead of regular ones
1. http://schemaform.io/
Co-Authored-By: Tyr Johanson <tyr@hpe.com>
Implements: blueprint angular-schema-form
Change-Id: Ib22b2d0db2c4d4775fdef62a180cc994e8ae6280
2016-06-22 11:52:53 +01:00
|
|
|
import xstatic.pkg.angular_schema_form
|
2015-01-13 14:45:07 +01:00
|
|
|
import xstatic.pkg.angular_smart_table
|
|
|
|
import xstatic.pkg.bootstrap_datepicker
|
|
|
|
import xstatic.pkg.bootstrap_scss
|
2015-07-01 19:30:56 -07:00
|
|
|
import xstatic.pkg.bootswatch
|
2015-01-13 14:45:07 +01:00
|
|
|
import xstatic.pkg.d3
|
|
|
|
import xstatic.pkg.font_awesome
|
|
|
|
import xstatic.pkg.hogan
|
|
|
|
import xstatic.pkg.jasmine
|
|
|
|
import xstatic.pkg.jquery
|
|
|
|
import xstatic.pkg.jquery_migrate
|
|
|
|
import xstatic.pkg.jquery_quicksearch
|
|
|
|
import xstatic.pkg.jquery_tablesorter
|
|
|
|
import xstatic.pkg.jquery_ui
|
|
|
|
import xstatic.pkg.jsencrypt
|
2015-07-01 19:30:56 -07:00
|
|
|
import xstatic.pkg.mdi
|
Add Angular Schema Form
This patch adds Angular Schema Form[1] and its requirements to Horizon.
There are a number of advantages to this over the current methods of
defining forms and workflows:
- All fields have an individual template, making theming improvements,
bug fixes, and bootstrap conformity easier.
- The file and line count, especially for workflows, is dramatically
reduced. The Create Net workflow, for example, goes from 12+ files to
2, with a big reduction in boilerplate HTML.
- All field validation messages are standardised, so we can match them
across Horizon and plugins
What this patch contains:
- Many common form fields, including things like the themable checkboxes
and selects.
- A basic modal template that can be passed with ui-bootstraps $modal
service to take advantage of schema-form
Next steps:
- Remove the other modal templates so we can standardise. A single
template opened from the $modal service is fine, and we shouldn't need
several directives. In this case, we should deprecate them, as the
modal forms will be used elsewhere.
- Map commonly used form items, like transfer tables, to a schema form
type like array (they serve similar purposes, so maybe thats what
should be replaced)
- Use themable selects instead of regular ones
1. http://schemaform.io/
Co-Authored-By: Tyr Johanson <tyr@hpe.com>
Implements: blueprint angular-schema-form
Change-Id: Ib22b2d0db2c4d4775fdef62a180cc994e8ae6280
2016-06-22 11:52:53 +01:00
|
|
|
import xstatic.pkg.objectpath
|
2015-01-13 14:45:07 +01:00
|
|
|
import xstatic.pkg.rickshaw
|
2015-07-01 19:30:56 -07:00
|
|
|
import xstatic.pkg.roboto_fontface
|
2015-01-13 14:45:07 +01:00
|
|
|
import xstatic.pkg.spin
|
2014-12-31 14:51:20 -05:00
|
|
|
import xstatic.pkg.termjs
|
Add Angular Schema Form
This patch adds Angular Schema Form[1] and its requirements to Horizon.
There are a number of advantages to this over the current methods of
defining forms and workflows:
- All fields have an individual template, making theming improvements,
bug fixes, and bootstrap conformity easier.
- The file and line count, especially for workflows, is dramatically
reduced. The Create Net workflow, for example, goes from 12+ files to
2, with a big reduction in boilerplate HTML.
- All field validation messages are standardised, so we can match them
across Horizon and plugins
What this patch contains:
- Many common form fields, including things like the themable checkboxes
and selects.
- A basic modal template that can be passed with ui-bootstraps $modal
service to take advantage of schema-form
Next steps:
- Remove the other modal templates so we can standardise. A single
template opened from the $modal service is fine, and we shouldn't need
several directives. In this case, we should deprecate them, as the
modal forms will be used elsewhere.
- Map commonly used form items, like transfer tables, to a schema form
type like array (they serve similar purposes, so maybe thats what
should be replaced)
- Use themable selects instead of regular ones
1. http://schemaform.io/
Co-Authored-By: Tyr Johanson <tyr@hpe.com>
Implements: blueprint angular-schema-form
Change-Id: Ib22b2d0db2c4d4775fdef62a180cc994e8ae6280
2016-06-22 11:52:53 +01:00
|
|
|
import xstatic.pkg.tv4
|
2015-01-13 14:45:07 +01:00
|
|
|
|
2015-07-17 15:58:34 +10:00
|
|
|
from horizon.utils import file_discovery
|
|
|
|
|
Pre-populate the Angular template cache and allow template overrides
This patch populates the Angular template cache from Django.
This eliminates the need for Angular to do an http get for every HTML
fragment.
In addition, now that we are filling the template cache, this patch
introduces the logic needed to override any Angular template HTML from
the current theme.
How it works:
A new template tag is created called "template_cache_preloads". This
tag is used in _scripts.html to generate a list of text/javascript
script tags, each one containing an Angular "run" method that loads
a template contents into the Angular template cache. The first time
any Horizon page is loaded after server start, the template cache
preloads are computed for the current theme.
The output of this tag is cached for 30 days in Django using the
"cache" tag. Further, that cached result is wrapped in a "compress js"
tag to collapse the individual <script> tags into 1 block of
javascript, and compress like all other javascript Horizon serves to
the client.
Finally, when using offline compression, the compressor evaluates the
nodelist (HTML content) of _scripts.html, notices the compress tag
and builds the template cache preloads for each possible theme. Later,
at runtime, when the preloads are generated for the current theme, the
compressor gets the result from the Django cache, and hashes the
contents to determine which manifest file to serve to the client.
Since the preloads generated at run-time are identical to those
generated off-line, the compressor hash matches an existing manifest
which is served to the client.
Notice that even though the template cache pre-loads are generated
off-line...the template_cache_preloads tag will be executed once
every 30 days anyway. However, since the result matches the off-line
compression, the existing manifest continues to be served to the client.
Finally, this patch ALSO watches for 'post_compress' signals. If it
detects that the angular template preloads have been re-compressed, it
clears the old version from the Django cache.
To test the template caching:
- Run horizon
- View page source
- Notice the new <script type="text/javascript"> tags contained in
the body (only visible if COMPRESS_ENABLED=False
- Open the javascript inspector
- Load launch instance
- Notice there are no longer http calls to load each HTML fragment
used by the Angular launch instance
To test the override:
- Set the DEFAULT_THEME='material'
- Create /horizon/openstack_dashboard/themes/material/\
static/templates/framework/widgets/help-panel/help-panel.html
- Set the content to <h1>TEST</h1>
- Run Horizon and open launch instance.
- The help content should contain "TEST"
To test the new template tag:
- set a breakpoint or print in angular.py:template_cache_preloads
and observe when it is called during off-line or run-time use
Co-Authored-By: Diana Whitten <hurgleburgler@gmail.com>
Implements: blueprint angular-template-overrides
Change-Id: I0e4e2623be58abbc68c6e02b2e9c5d7cdaba8e4d
2016-05-31 12:52:14 -06:00
|
|
|
from openstack_dashboard import theme_settings
|
|
|
|
|
2015-01-13 14:45:07 +01:00
|
|
|
|
2015-03-23 08:26:01 -06:00
|
|
|
def get_staticfiles_dirs(webroot='/'):
|
|
|
|
STATICFILES_DIRS = [
|
|
|
|
('horizon/lib/angular',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.angular,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/angular',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.angular_bootstrap,
|
|
|
|
root_url=webroot).base_dir),
|
2016-05-13 17:45:10 +03:00
|
|
|
('horizon/lib/angular',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.angular_fileupload,
|
|
|
|
root_url=webroot).base_dir),
|
2015-07-21 13:11:05 -07:00
|
|
|
('horizon/lib/angular',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.angular_gettext,
|
|
|
|
root_url=webroot).base_dir),
|
2015-03-23 08:26:01 -06:00
|
|
|
('horizon/lib/angular',
|
2015-03-30 18:41:47 -07:00
|
|
|
xstatic.main.XStatic(xstatic.pkg.angular_lrdragndrop,
|
2015-03-23 08:26:01 -06:00
|
|
|
root_url=webroot).base_dir),
|
Add Angular Schema Form
This patch adds Angular Schema Form[1] and its requirements to Horizon.
There are a number of advantages to this over the current methods of
defining forms and workflows:
- All fields have an individual template, making theming improvements,
bug fixes, and bootstrap conformity easier.
- The file and line count, especially for workflows, is dramatically
reduced. The Create Net workflow, for example, goes from 12+ files to
2, with a big reduction in boilerplate HTML.
- All field validation messages are standardised, so we can match them
across Horizon and plugins
What this patch contains:
- Many common form fields, including things like the themable checkboxes
and selects.
- A basic modal template that can be passed with ui-bootstraps $modal
service to take advantage of schema-form
Next steps:
- Remove the other modal templates so we can standardise. A single
template opened from the $modal service is fine, and we shouldn't need
several directives. In this case, we should deprecate them, as the
modal forms will be used elsewhere.
- Map commonly used form items, like transfer tables, to a schema form
type like array (they serve similar purposes, so maybe thats what
should be replaced)
- Use themable selects instead of regular ones
1. http://schemaform.io/
Co-Authored-By: Tyr Johanson <tyr@hpe.com>
Implements: blueprint angular-schema-form
Change-Id: Ib22b2d0db2c4d4775fdef62a180cc994e8ae6280
2016-06-22 11:52:53 +01:00
|
|
|
('horizon/lib/angular',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.angular_schema_form,
|
|
|
|
root_url=webroot).base_dir),
|
2015-03-23 08:26:01 -06:00
|
|
|
('horizon/lib/angular',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.angular_smart_table,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/bootstrap_datepicker',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.bootstrap_datepicker,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('bootstrap',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.bootstrap_scss,
|
|
|
|
root_url=webroot).base_dir),
|
2015-07-01 19:30:56 -07:00
|
|
|
('horizon/lib/bootswatch',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.bootswatch,
|
|
|
|
root_url=webroot).base_dir),
|
2015-03-23 08:26:01 -06:00
|
|
|
('horizon/lib',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.d3,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.hogan,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/font-awesome',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.font_awesome,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/jasmine',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jasmine,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/jquery',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jquery,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/jquery',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jquery_migrate,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/jquery',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jquery_quicksearch,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/jquery',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jquery_tablesorter,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib/jsencrypt',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jsencrypt,
|
|
|
|
root_url=webroot).base_dir),
|
2015-07-01 19:30:56 -07:00
|
|
|
('horizon/lib/mdi',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.mdi,
|
|
|
|
root_url=webroot).base_dir),
|
Add Angular Schema Form
This patch adds Angular Schema Form[1] and its requirements to Horizon.
There are a number of advantages to this over the current methods of
defining forms and workflows:
- All fields have an individual template, making theming improvements,
bug fixes, and bootstrap conformity easier.
- The file and line count, especially for workflows, is dramatically
reduced. The Create Net workflow, for example, goes from 12+ files to
2, with a big reduction in boilerplate HTML.
- All field validation messages are standardised, so we can match them
across Horizon and plugins
What this patch contains:
- Many common form fields, including things like the themable checkboxes
and selects.
- A basic modal template that can be passed with ui-bootstraps $modal
service to take advantage of schema-form
Next steps:
- Remove the other modal templates so we can standardise. A single
template opened from the $modal service is fine, and we shouldn't need
several directives. In this case, we should deprecate them, as the
modal forms will be used elsewhere.
- Map commonly used form items, like transfer tables, to a schema form
type like array (they serve similar purposes, so maybe thats what
should be replaced)
- Use themable selects instead of regular ones
1. http://schemaform.io/
Co-Authored-By: Tyr Johanson <tyr@hpe.com>
Implements: blueprint angular-schema-form
Change-Id: Ib22b2d0db2c4d4775fdef62a180cc994e8ae6280
2016-06-22 11:52:53 +01:00
|
|
|
('horizon/lib/objectpath',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.objectpath,
|
|
|
|
root_url=webroot).base_dir),
|
2015-03-23 08:26:01 -06:00
|
|
|
('horizon/lib',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.rickshaw,
|
|
|
|
root_url=webroot).base_dir),
|
2015-07-01 19:30:56 -07:00
|
|
|
('horizon/lib/roboto_fontface',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.roboto_fontface,
|
|
|
|
root_url=webroot).base_dir),
|
2015-03-23 08:26:01 -06:00
|
|
|
('horizon/lib',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.spin,
|
|
|
|
root_url=webroot).base_dir),
|
|
|
|
('horizon/lib',
|
2015-07-01 19:30:56 -07:00
|
|
|
xstatic.main.XStatic(xstatic.pkg.termjs,
|
|
|
|
root_url=webroot).base_dir),
|
Add Angular Schema Form
This patch adds Angular Schema Form[1] and its requirements to Horizon.
There are a number of advantages to this over the current methods of
defining forms and workflows:
- All fields have an individual template, making theming improvements,
bug fixes, and bootstrap conformity easier.
- The file and line count, especially for workflows, is dramatically
reduced. The Create Net workflow, for example, goes from 12+ files to
2, with a big reduction in boilerplate HTML.
- All field validation messages are standardised, so we can match them
across Horizon and plugins
What this patch contains:
- Many common form fields, including things like the themable checkboxes
and selects.
- A basic modal template that can be passed with ui-bootstraps $modal
service to take advantage of schema-form
Next steps:
- Remove the other modal templates so we can standardise. A single
template opened from the $modal service is fine, and we shouldn't need
several directives. In this case, we should deprecate them, as the
modal forms will be used elsewhere.
- Map commonly used form items, like transfer tables, to a schema form
type like array (they serve similar purposes, so maybe thats what
should be replaced)
- Use themable selects instead of regular ones
1. http://schemaform.io/
Co-Authored-By: Tyr Johanson <tyr@hpe.com>
Implements: blueprint angular-schema-form
Change-Id: Ib22b2d0db2c4d4775fdef62a180cc994e8ae6280
2016-06-22 11:52:53 +01:00
|
|
|
('horizon/lib/tv4',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.tv4,
|
|
|
|
root_url=webroot).base_dir),
|
2015-03-23 08:26:01 -06:00
|
|
|
]
|
2015-01-13 14:45:07 +01:00
|
|
|
|
2015-03-23 08:26:01 -06:00
|
|
|
if xstatic.main.XStatic(xstatic.pkg.jquery_ui,
|
|
|
|
root_url=webroot).version.startswith('1.10.'):
|
|
|
|
# The 1.10.x versions already contain the 'ui' directory.
|
|
|
|
STATICFILES_DIRS.append(
|
|
|
|
('horizon/lib/jquery-ui',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jquery_ui,
|
|
|
|
root_url=webroot).base_dir))
|
|
|
|
else:
|
|
|
|
# Newer versions dropped the directory, add it to keep the path the
|
|
|
|
# same.
|
|
|
|
STATICFILES_DIRS.append(
|
|
|
|
('horizon/lib/jquery-ui/ui',
|
|
|
|
xstatic.main.XStatic(xstatic.pkg.jquery_ui,
|
|
|
|
root_url=webroot).base_dir))
|
2015-01-13 14:45:07 +01:00
|
|
|
|
2015-03-23 08:26:01 -06:00
|
|
|
return STATICFILES_DIRS
|
2015-07-17 15:58:34 +10:00
|
|
|
|
|
|
|
|
Pre-populate the Angular template cache and allow template overrides
This patch populates the Angular template cache from Django.
This eliminates the need for Angular to do an http get for every HTML
fragment.
In addition, now that we are filling the template cache, this patch
introduces the logic needed to override any Angular template HTML from
the current theme.
How it works:
A new template tag is created called "template_cache_preloads". This
tag is used in _scripts.html to generate a list of text/javascript
script tags, each one containing an Angular "run" method that loads
a template contents into the Angular template cache. The first time
any Horizon page is loaded after server start, the template cache
preloads are computed for the current theme.
The output of this tag is cached for 30 days in Django using the
"cache" tag. Further, that cached result is wrapped in a "compress js"
tag to collapse the individual <script> tags into 1 block of
javascript, and compress like all other javascript Horizon serves to
the client.
Finally, when using offline compression, the compressor evaluates the
nodelist (HTML content) of _scripts.html, notices the compress tag
and builds the template cache preloads for each possible theme. Later,
at runtime, when the preloads are generated for the current theme, the
compressor gets the result from the Django cache, and hashes the
contents to determine which manifest file to serve to the client.
Since the preloads generated at run-time are identical to those
generated off-line, the compressor hash matches an existing manifest
which is served to the client.
Notice that even though the template cache pre-loads are generated
off-line...the template_cache_preloads tag will be executed once
every 30 days anyway. However, since the result matches the off-line
compression, the existing manifest continues to be served to the client.
Finally, this patch ALSO watches for 'post_compress' signals. If it
detects that the angular template preloads have been re-compressed, it
clears the old version from the Django cache.
To test the template caching:
- Run horizon
- View page source
- Notice the new <script type="text/javascript"> tags contained in
the body (only visible if COMPRESS_ENABLED=False
- Open the javascript inspector
- Load launch instance
- Notice there are no longer http calls to load each HTML fragment
used by the Angular launch instance
To test the override:
- Set the DEFAULT_THEME='material'
- Create /horizon/openstack_dashboard/themes/material/\
static/templates/framework/widgets/help-panel/help-panel.html
- Set the content to <h1>TEST</h1>
- Run Horizon and open launch instance.
- The help content should contain "TEST"
To test the new template tag:
- set a breakpoint or print in angular.py:template_cache_preloads
and observe when it is called during off-line or run-time use
Co-Authored-By: Diana Whitten <hurgleburgler@gmail.com>
Implements: blueprint angular-template-overrides
Change-Id: I0e4e2623be58abbc68c6e02b2e9c5d7cdaba8e4d
2016-05-31 12:52:14 -06:00
|
|
|
def find_static_files(
|
|
|
|
HORIZON_CONFIG,
|
|
|
|
AVAILABLE_THEMES,
|
|
|
|
THEME_COLLECTION_DIR,
|
|
|
|
ROOT_PATH):
|
2015-09-16 16:19:07 -06:00
|
|
|
import horizon
|
|
|
|
import openstack_dashboard
|
|
|
|
os_dashboard_home_dir = openstack_dashboard.__path__[0]
|
|
|
|
horizon_home_dir = horizon.__path__[0]
|
|
|
|
|
2015-07-17 15:58:34 +10:00
|
|
|
# note the path must end in a '/' or the resultant file paths will have a
|
|
|
|
# leading "/"
|
|
|
|
file_discovery.populate_horizon_config(
|
|
|
|
HORIZON_CONFIG,
|
2015-09-16 16:19:07 -06:00
|
|
|
os.path.join(horizon_home_dir, 'static/')
|
2015-07-17 15:58:34 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
# filter out non-angular javascript code and lib
|
|
|
|
HORIZON_CONFIG['js_files'] = ([f for f in HORIZON_CONFIG['js_files']
|
|
|
|
if not f.startswith('horizon/')])
|
|
|
|
|
|
|
|
# note the path must end in a '/' or the resultant file paths will have a
|
|
|
|
# leading "/"
|
|
|
|
file_discovery.populate_horizon_config(
|
|
|
|
HORIZON_CONFIG,
|
2015-09-16 16:19:07 -06:00
|
|
|
os.path.join(os_dashboard_home_dir, 'static/'),
|
2015-07-24 16:34:57 -06:00
|
|
|
sub_path='app/'
|
2015-07-17 15:58:34 +10:00
|
|
|
)
|
Pre-populate the Angular template cache and allow template overrides
This patch populates the Angular template cache from Django.
This eliminates the need for Angular to do an http get for every HTML
fragment.
In addition, now that we are filling the template cache, this patch
introduces the logic needed to override any Angular template HTML from
the current theme.
How it works:
A new template tag is created called "template_cache_preloads". This
tag is used in _scripts.html to generate a list of text/javascript
script tags, each one containing an Angular "run" method that loads
a template contents into the Angular template cache. The first time
any Horizon page is loaded after server start, the template cache
preloads are computed for the current theme.
The output of this tag is cached for 30 days in Django using the
"cache" tag. Further, that cached result is wrapped in a "compress js"
tag to collapse the individual <script> tags into 1 block of
javascript, and compress like all other javascript Horizon serves to
the client.
Finally, when using offline compression, the compressor evaluates the
nodelist (HTML content) of _scripts.html, notices the compress tag
and builds the template cache preloads for each possible theme. Later,
at runtime, when the preloads are generated for the current theme, the
compressor gets the result from the Django cache, and hashes the
contents to determine which manifest file to serve to the client.
Since the preloads generated at run-time are identical to those
generated off-line, the compressor hash matches an existing manifest
which is served to the client.
Notice that even though the template cache pre-loads are generated
off-line...the template_cache_preloads tag will be executed once
every 30 days anyway. However, since the result matches the off-line
compression, the existing manifest continues to be served to the client.
Finally, this patch ALSO watches for 'post_compress' signals. If it
detects that the angular template preloads have been re-compressed, it
clears the old version from the Django cache.
To test the template caching:
- Run horizon
- View page source
- Notice the new <script type="text/javascript"> tags contained in
the body (only visible if COMPRESS_ENABLED=False
- Open the javascript inspector
- Load launch instance
- Notice there are no longer http calls to load each HTML fragment
used by the Angular launch instance
To test the override:
- Set the DEFAULT_THEME='material'
- Create /horizon/openstack_dashboard/themes/material/\
static/templates/framework/widgets/help-panel/help-panel.html
- Set the content to <h1>TEST</h1>
- Run Horizon and open launch instance.
- The help content should contain "TEST"
To test the new template tag:
- set a breakpoint or print in angular.py:template_cache_preloads
and observe when it is called during off-line or run-time use
Co-Authored-By: Diana Whitten <hurgleburgler@gmail.com>
Implements: blueprint angular-template-overrides
Change-Id: I0e4e2623be58abbc68c6e02b2e9c5d7cdaba8e4d
2016-05-31 12:52:14 -06:00
|
|
|
|
|
|
|
# Discover theme static resources, and in particular any
|
|
|
|
# static HTML (client-side) that the theme overrides
|
|
|
|
theme_static_files = {}
|
|
|
|
theme_info = theme_settings.get_theme_static_dirs(
|
|
|
|
AVAILABLE_THEMES,
|
|
|
|
THEME_COLLECTION_DIR,
|
|
|
|
ROOT_PATH)
|
|
|
|
|
|
|
|
for url, path in theme_info:
|
|
|
|
discovered_files = {}
|
|
|
|
|
|
|
|
# discover static files provided by the theme
|
|
|
|
file_discovery.populate_horizon_config(
|
|
|
|
discovered_files,
|
|
|
|
path
|
|
|
|
)
|
|
|
|
|
|
|
|
# Get the theme name from the theme url
|
|
|
|
theme_name = url.split('/')[-1]
|
|
|
|
|
|
|
|
# build a dictionary of this theme's static HTML templates.
|
|
|
|
# For each overridden template, strip off the '/templates/' part of the
|
|
|
|
# theme filename then use that name as the key, and the location in the
|
|
|
|
# theme directory as the value. This allows the quick lookup of
|
|
|
|
# theme path for any file overridden by a theme template
|
|
|
|
template_overrides = {}
|
|
|
|
for theme_file in discovered_files['external_templates']:
|
|
|
|
# Example:
|
|
|
|
# external_templates_dict[
|
|
|
|
# 'framework/widgets/help-panel/help-panel.html'
|
|
|
|
# ] = 'themes/material/templates/framework/widgets/\
|
|
|
|
# help-panel/help-panel.html'
|
|
|
|
(templates_part, override_path) = theme_file.split('/templates/')
|
|
|
|
template_overrides[override_path] = 'themes/' +\
|
|
|
|
theme_name + theme_file
|
|
|
|
|
|
|
|
discovered_files['template_overrides'] = template_overrides
|
|
|
|
|
|
|
|
# Save all of the discovered file info for this theme in our
|
|
|
|
# 'theme_files' object using the theme name as the key
|
|
|
|
theme_static_files[theme_name] = discovered_files
|
|
|
|
|
|
|
|
# Add the theme file info to the horizon config for use by template tags
|
|
|
|
HORIZON_CONFIG['theme_static_files'] = theme_static_files
|