diff options
author | Rob Cresswell <robert.cresswell@outlook.com> | 2016-02-19 15:29:10 +0000 |
---|---|---|
committer | Diana Whitten <hurgleburgler@gmail.com> | 2016-05-05 23:12:59 +0000 |
commit | d5b24d7b9760a68072cfed390c66a9433b415275 (patch) | |
tree | 5ae80c65efb78d25a841efae3eeaa2734f39e30d /horizon/templatetags | |
parent | a55663a49a989f2855426de0d14457b57be12455 (diff) | |
download | horizon-d5b24d7b9760a68072cfed390c66a9433b415275.tar.gz |
Use breadcrumb nav across Horizon
We've added breadcrumbs to the Details pages, but its a pretty
inconsistent experience. This patch adds breadcrumbs to the base
template, making the breadcrumbs consistent across all pages; this will
be useful when the side nav is hidden for responsive design. This patch
also makes the breadcrumbs on the detail pages behave better with
theming.
- Made the detail header and actions avoid using floats
- Moved breadcrumb truncating to the front end, so that it can be
customised easily via CSS
- Manually added breadcrumb for ngcontainers page
- Removed overly specific HTML check from Key Pair Details test
- Fixed <dt> alignment on Key Pair Details page
Closes-Bug: 1554812
Partially-Implements: blueprint navigation-improvements
Change-Id: Ibcd4c369b5d8ad62f7c839c0deeaefc750677b40
Diffstat (limited to 'horizon/templatetags')
-rw-r--r-- | horizon/templatetags/breadcrumb_nav.py | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/horizon/templatetags/breadcrumb_nav.py b/horizon/templatetags/breadcrumb_nav.py index 4d2bfcb4b..f2cacb389 100644 --- a/horizon/templatetags/breadcrumb_nav.py +++ b/horizon/templatetags/breadcrumb_nav.py @@ -1,4 +1,4 @@ -# Copyright 2015 Cisco Systems, Inc. +# Copyright 2016 Cisco Systems, Inc. # # 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 @@ -17,11 +17,44 @@ from django import template register = template.Library() -@register.inclusion_tag('horizon/common/_breadcrumb_nav.html', +@register.inclusion_tag('bootstrap/breadcrumb.html', takes_context=True) def breadcrumb_nav(context): - return {'actions': context.get('actions'), - 'breadcrumb': context.get('custom_breadcrumb'), - 'url': context.get('url'), - 'page_title': context['page_title'], - 'panel': context.request.horizon['panel'], } + """A logic heavy function for automagically creating a breadcrumb. + It uses the dashboard, panel group(if it exists), then current panel. + Can also use a "custom_breadcrumb" context item to add extra items. + """ + breadcrumb = [] + dashboard = context.request.horizon['dashboard'] + try: + panel_groups = dashboard.get_panel_groups() + except KeyError: + panel_groups = None + panel_group = None + panel = context.request.horizon['panel'] + + # Add panel group, if there is one + if panel_groups: + for group in panel_groups.values(): + if panel.slug in group.panels and group.slug != 'default': + panel_group = group + break + + # Remove panel reference if that is the current page + if panel.get_absolute_url() == context.request.path: + panel = None + + # Get custom breadcrumb, if there is one. + custom_breadcrumb = context.get('custom_breadcrumb') + + # Build list of tuples (name, optional url) + breadcrumb.append((dashboard.name,)) + if panel_group: + breadcrumb.append((panel_group.name,)) + if panel: + breadcrumb.append((panel.name, panel.get_absolute_url())) + if custom_breadcrumb: + breadcrumb.extend(custom_breadcrumb) + breadcrumb.append((context.get('page_title'),)) + + return {'breadcrumb': breadcrumb} |