Context selection for project and region
Providing the mechanism to easily switch between projects and regions. Only shows domain info if OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT is set to True in settings. Will add domain switching for v3 once support for it is complete. Will add advance filtering rules in follow up patch. Co-Authored-By: David Lyle <david.lyle@hp.com> Implements: blueprint context-selection Change-Id: Ie6e81eebe822ab2394b07345d148a1c06a33a25f
This commit is contained in:
parent
59e410eb24
commit
7dd2aa8b4a
@ -0,0 +1,75 @@
|
||||
|
||||
.context-selection {
|
||||
display: inline-block;
|
||||
|
||||
.dropdown-toggle {
|
||||
border: none;
|
||||
background: transparent;
|
||||
font-size: $font-size-base;
|
||||
color: $gray;
|
||||
|
||||
.context-overview {
|
||||
padding: 0 0.25em;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown-menu {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.dropdown-header {
|
||||
font-size: $font-size-small
|
||||
}
|
||||
|
||||
.context-lists {
|
||||
display: table;
|
||||
padding: 0.5em 1em;
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: 100%;
|
||||
margin-top: 1em;
|
||||
padding: 0.4em 1em;
|
||||
background: whitesmoke;
|
||||
border-top: 1px solid $gray-light;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
cursor: not-allowed;
|
||||
color: $gray-light;
|
||||
}
|
||||
|
||||
a {
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
em {
|
||||
font-size: $font-size-large;
|
||||
font-weight: bold;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
ul {
|
||||
display: table-cell;
|
||||
padding-left: 1em;
|
||||
|
||||
li {
|
||||
padding-left: 0;
|
||||
font-size: $font-size-base;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
max-width: 160px;
|
||||
}
|
||||
|
||||
li .glyphicon-ok {
|
||||
margin-left: 0.2em;
|
||||
}
|
||||
}
|
||||
|
||||
ul:not(:last-child) {
|
||||
border-right: 1px solid $gray-light;
|
||||
}
|
||||
}
|
@ -134,7 +134,6 @@ dt {
|
||||
|
||||
.topbar .switcher_bar div {
|
||||
padding: 2px 10px 1px;
|
||||
font-size: 11px !important;
|
||||
line-height: 20px;
|
||||
color: $gray;
|
||||
text-decoration: none;
|
||||
@ -145,6 +144,7 @@ dt {
|
||||
|
||||
.topbar .context-box {
|
||||
display: inline;
|
||||
@import "_context_selection";
|
||||
}
|
||||
|
||||
.hide_image {
|
||||
|
@ -1,48 +1,27 @@
|
||||
{% load branding i18n %}
|
||||
{% load url from future %}
|
||||
{% load context_selection %}
|
||||
|
||||
<h1 class="brand"><a href="{% site_branding_link %}">{% site_branding %}</a></h1>
|
||||
|
||||
<div class="context-box">
|
||||
{% with num_of_tenants=authorized_tenants|length %}
|
||||
<div id="tenant_switcher" class="dropdown switcher_bar {% if num_of_tenants == 1 %} hide_image {% endif %}" tabindex="1">
|
||||
{% if num_of_tenants > 1 %}
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#tenant_switcher">
|
||||
{% endif %}
|
||||
<div>{{ request.user.project_name }}</div>
|
||||
{% if num_of_tenants > 1 %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if num_of_tenants > 1 %}
|
||||
<ul id="tenant_list" class="dropdown-menu">
|
||||
<li class='divider'></li>
|
||||
{% for tenant in authorized_tenants %}
|
||||
{% if tenant.enabled and tenant.id != request.user.tenant_id %}
|
||||
<li><a href="{% url 'switch_tenants' tenant.id %}?next={{ request.horizon.dashboard.get_absolute_url }}">{{ tenant.name }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
|
||||
{% with num_of_regions=request.user.available_services_regions|length %}
|
||||
{% if num_of_regions > 1 %}
|
||||
<div id="services_region_switcher" class="dropdown switcher_bar" tabindex="1">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#services_region_switcher">
|
||||
<div>{{ request.user.services_region }}</div>
|
||||
</a>
|
||||
|
||||
<ul id="services_regions_list" class="dropdown-menu">
|
||||
<li class='divider'></li>
|
||||
{% for region in request.user.available_services_regions %}
|
||||
<li><a href="{% url 'switch_services_region' region %}?next={{ request.horizon.panel.get_absolute_url }}">{{ region }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<div class="dropdown context-selection">
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
{% show_overview %}
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<div class="context-lists">
|
||||
{% show_domain_list %}
|
||||
{% show_project_list %}
|
||||
{% show_region_list %}
|
||||
</div>
|
||||
<div class="footer disabled">
|
||||
<span class="glyphicon glyphicon-cog"></span>
|
||||
{% trans "Filter selections" %}
|
||||
</div>
|
||||
</div><!-- end of dropdown-menu -->
|
||||
</div><!-- end of context-selection -->
|
||||
</div><!-- end of context-box -->
|
||||
|
||||
<div id="user_info" class="pull-right">
|
||||
<div id="profile_editor_switcher" class="dropdown switcher_bar" tabindex='1'>
|
||||
|
@ -0,0 +1,12 @@
|
||||
{% load i18n %}
|
||||
{% if domain_supported %}
|
||||
<ul>
|
||||
<li class="dropdown-header">{% trans "Domains:" %}</li>
|
||||
<li>
|
||||
<a class="disabled">
|
||||
{{ domain_name }}
|
||||
<span class="glyphicon glyphicon-ok"></span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
@ -0,0 +1,13 @@
|
||||
<span class="glyphicon glyphicon-list-alt"></span>
|
||||
<span class="context-overview">
|
||||
{% if domain_supported %}
|
||||
<span>{{ domain_name }}</span>
|
||||
<em>·</em>
|
||||
{% endif %}
|
||||
<span>{{ project_name }}</span>
|
||||
{% if multi_region %}
|
||||
<em>·</em>
|
||||
<span>{{ region_name }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
<span class="caret"></span>
|
@ -0,0 +1,16 @@
|
||||
{% load i18n %}
|
||||
{% with dashboard_url=request.horizon.dashboard.get_absolute_url %}
|
||||
<ul>
|
||||
<li class="dropdown-header">{% trans "Projects:" %}</li>
|
||||
{% for project in projects %}
|
||||
<li>
|
||||
<a href="{% url 'switch_tenants' project.id %}?next={{ dashboard_url }}">
|
||||
{{ project.name }}
|
||||
{% if project.enabled and project.id == project_id %}
|
||||
<span class="glyphicon glyphicon-ok"></span>
|
||||
{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endwith %}
|
@ -0,0 +1,18 @@
|
||||
{% load i18n %}
|
||||
{% if multi_region %}
|
||||
{% with panel_url=request.horizon.panel.get_absolute_url %}
|
||||
<ul>
|
||||
<li class="dropdown-header">{% trans "Regions:" %}</li>
|
||||
{% for region in regions %}
|
||||
<li>
|
||||
<a href="{% url 'switch_services_region' region %}?next={{ panel_url }}">
|
||||
{{ region }}
|
||||
{% if region == region_name %}
|
||||
<span class="glyphicon glyphicon-ok"></span>
|
||||
{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endwith %}
|
||||
{% endif %}
|
0
openstack_dashboard/templatetags/__init__.py
Normal file
0
openstack_dashboard/templatetags/__init__.py
Normal file
86
openstack_dashboard/templatetags/context_selection.py
Normal file
86
openstack_dashboard/templatetags/context_selection.py
Normal file
@ -0,0 +1,86 @@
|
||||
# Copyright 2014 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from django import template
|
||||
|
||||
from openstack_dashboard.api import keystone
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
def is_multidomain_supported():
|
||||
return (keystone.VERSIONS.active >= 3 and
|
||||
getattr(settings,
|
||||
'OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT',
|
||||
False))
|
||||
|
||||
|
||||
@register.inclusion_tag('context_selection/_overview.html',
|
||||
takes_context=True)
|
||||
def show_overview(context):
|
||||
if 'request' not in context:
|
||||
return {}
|
||||
request = context['request']
|
||||
context = {'domain_supported': is_multidomain_supported(),
|
||||
'domain_name': request.user.user_domain_id,
|
||||
'project_name': request.user.project_name,
|
||||
'multi_region':
|
||||
len(request.user.available_services_regions) > 1,
|
||||
'region_name': request.user.services_region,
|
||||
'request': request}
|
||||
|
||||
return context
|
||||
|
||||
|
||||
@register.inclusion_tag('context_selection/_domain_list.html',
|
||||
takes_context=True)
|
||||
def show_domain_list(context):
|
||||
# TODO(Thai): once domain switching is support, need to revisit
|
||||
if 'request' not in context:
|
||||
return {}
|
||||
request = context['request']
|
||||
context = {'domain_supported': is_multidomain_supported(),
|
||||
'domain_name': request.user.user_domain_id,
|
||||
'request': request}
|
||||
return context
|
||||
|
||||
|
||||
@register.inclusion_tag('context_selection/_project_list.html',
|
||||
takes_context=True)
|
||||
def show_project_list(context):
|
||||
if 'request' not in context:
|
||||
return {}
|
||||
request = context['request']
|
||||
context = {'projects': context['authorized_tenants'],
|
||||
'project_id': request.user.project_id,
|
||||
'request': request}
|
||||
return context
|
||||
|
||||
|
||||
@register.inclusion_tag('context_selection/_region_list.html',
|
||||
takes_context=True)
|
||||
def show_region_list(context):
|
||||
if 'request' not in context:
|
||||
return {}
|
||||
request = context['request']
|
||||
context = {'multi_region':
|
||||
len(request.user.available_services_regions) > 1,
|
||||
'region_name': request.user.services_region,
|
||||
'regions': request.user.available_services_regions,
|
||||
'request': request}
|
||||
return context
|
Loading…
x
Reference in New Issue
Block a user