deb-horizon/openstack_dashboard
Tyr Johanson fca46ab60f 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-07-13 15:38:07 -07:00
..
api Merge "Show instance lock/unlock actions based on the locked status" 2016-06-17 23:54:54 +00:00
conf Updating heat policy file 2016-06-14 11:01:45 -06:00
contrib Add Line Charts to the Theme Preview Page 2016-06-21 18:51:58 -07:00
dashboards Merge "Add check whether nova is enable or not in aggregate panel" 2016-06-21 19:12:41 +00:00
django_pyscss_fix Workaround for 'File exists' test failure 2014-09-30 06:43:22 -05:00
enabled Generic details display framework 2016-05-16 11:39:57 -06:00
local Merge "Show instance lock/unlock actions based on the locked status" 2016-06-17 23:54:54 +00:00
locale Imported Translations from Zanata 2016-06-21 07:25:40 +00:00
management Update WSGI app creation to be compatible with Django 1.7 or greater 2015-09-21 15:36:19 +02:00
static Merge "Fix css class for cancel button on metadata modal" 2016-06-22 10:04:43 +00:00
templates Pre-populate the Angular template cache and allow template overrides 2016-07-13 15:38:07 -07:00
templatetags Pass page_url instead of whole request to render 2016-05-31 10:34:52 +00:00
test Pre-populate the Angular template cache and allow template overrides 2016-07-13 15:38:07 -07:00
themes Modals should inherit from the theme 2016-06-21 15:54:00 -07:00
usage Reduce the default date range on Overview panel to 1 day 2016-05-31 17:57:53 +03:00
utils admin permissions depends on OPENSTACK_KEYSTONE_ADMIN_ROLES 2016-06-10 07:23:09 +00:00
wsgi Update WSGI app creation to be compatible with Django 1.7 2014-10-16 13:57:45 +01:00
__init__.py
.eslintrc Add selective ESLint rule activation for Horizon Legacy JS 2015-07-08 17:06:15 -07:00
context_processors.py Support javascript translation for plugin 2016-01-11 13:46:05 -08:00
exceptions.py Excise Trove from Horizon 2015-12-22 02:01:07 -07:00
hooks.py Remove extraneous vim configuration comments 2014-05-06 15:30:10 +08:00
karma.conf.js Output JS Karma test coverage reports to ./cover/ 2016-06-02 14:35:39 +00:00
policy.py Retrieve domain scoped token 2016-03-08 15:17:38 -08:00
settings.py Pre-populate the Angular template cache and allow template overrides 2016-07-13 15:38:07 -07:00
static_settings.py Pre-populate the Angular template cache and allow template overrides 2016-07-13 15:38:07 -07:00
theme_settings.py Dynamic Themes 2016-02-25 09:49:43 -08:00
urls.py Update URLs to Django 1.8+ style 2016-03-28 11:03:08 +01:00
views.py Retrieve domain scoped token 2016-03-08 15:17:38 -08:00