implement protection plan detail page

Change-Id: I83d68e4822934dd178102eca92dfd5709d44d1d3
Closes-Bug: #1583408
This commit is contained in:
zhangshuai
2016-06-12 19:53:27 +08:00
parent 75dfa3512b
commit 14cade6a6b
6 changed files with 174 additions and 0 deletions

View File

@@ -101,6 +101,7 @@ class ProtectionPlanFilterAction(tables.FilterAction):
class ProtectionPlansTable(tables.DataTable):
name = tables.Column('name',
link="horizon:smaug:protectionplans:detail",
verbose_name=_('Name'))
status = tables.Column('status',
@@ -113,3 +114,13 @@ class ProtectionPlansTable(tables.DataTable):
DeleteProtectionPlansAction)
table_actions = (ProtectionPlanFilterAction, CreateProtectionPlanLink,
DeleteProtectionPlansAction)
class DetailTable(tables.DataTable):
id = tables.Column("id", verbose_name=_("ID"))
type = tables.Column("type", verbose_name=_("TYPE"))
class Meta(object):
name = "protectionresources"
verbose_name = _("Protection Resources")
hidden_title = False

View File

@@ -21,4 +21,6 @@ urlpatterns = [
url(r'^create/$', views.CreateView.as_view(), name='create'),
url(r'^(?P<plan_id>[^/]+)/scheduleprotect/$',
views.ScheduleProtectView.as_view(), name='scheduleprotect'),
url(r'^(?P<plan_id>[^/]+)/detail/$',
views.DetailView.as_view(), name='detail'),
]

View File

@@ -20,6 +20,7 @@ from horizon import exceptions
from horizon import forms as horizon_forms
from horizon import tables as horizon_tables
from horizon.utils import memoized
from horizon import views as horizon_views
from smaug_dashboard.api import smaug as smaugclient
from smaug_dashboard.protectionplans import forms
@@ -154,3 +155,67 @@ class ScheduleProtectView(horizon_forms.ModalFormView):
return {'id': plan.id,
'name': plan.name,
'provider_id': plan.provider_id}
class DetailView(horizon_views.HorizonTemplateView):
template_name = 'protectionplans/detail.html'
page_title = "{{ plan.name }}"
def get_context_data(self, **kwargs):
context = super(DetailView, self).get_context_data(**kwargs)
plan = self.get_data()
table = tables.ProtectionPlansTable(self.request)
context["plan"] = plan
context["provider"] = self.get_provider(plan.provider_id)
context["instances"] = self.get_instances(plan.resources)
context["url"] = reverse("horizon:smaug:protectionplans:index")
context["actions"] = table.render_row_actions(plan)
return context
@memoized.memoized_method
def get_data(self):
try:
return smaugclient.plan_get(self.request, self.kwargs['plan_id'])
except Exception:
exceptions.handle(
self.request,
_('Unable to retrieve protection plan details.'),
redirect=reverse("horizon:smaug:protectionplans:index"))
@memoized.memoized_method
def get_provider(self, provider_id):
provider = None
if provider_id:
try:
provider = smaugclient.provider_get(self.request, provider_id)
except Exception:
exceptions.handle(
self.request,
_('Unable to retrieve protection provider details.'),
redirect=reverse("horizon:smaug:protectionplans:index"))
return provider
@memoized.memoized_method
def get_instances(self, instances):
try:
result = []
for instance in instances:
instance["showid"] = str(uuid.uuid4())
result.append(protectables.Instances(self, instance))
detail_instance = smaugclient.protectable_get_instance(
self.request,
instance["type"].strip(),
instance["id"].strip())
if detail_instance.dependent_resources:
for dependent in detail_instance.dependent_resources:
dependent["showid"] = str(uuid.uuid4())
dependent["showparentid"] = instance["showid"]
result.append(
protectables.Instances(self, dependent))
return result
except Exception:
exceptions.handle(
self.request,
_('Unable to get instances.'),
redirect=reverse("horizon:smaug:protectionplans:index"))

View File

@@ -0,0 +1,21 @@
/* Copyright (c) 2016 Huawei, 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
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.
*/
horizon.protectionplans_detail = {
init: function() {
/* init resource tree */
$("#protectionplanDetailResource").treetable({ expandable: true });
}
};

View File

@@ -0,0 +1,59 @@
{% load i18n %}
{% load static %}
{% load compress %}
{% block css %}
{% compress css %}
<link rel="stylesheet" href="{% static 'smaugdashboard/css/jquery.treetable.css' %}">
{% endcompress %}
{% endblock %}
<div class="detail">
<dl class="dl-horizontal">
<dt>{% trans "Plan Name" %}</dt>
<dd>{{ plan.name }}</dd>
<dt>{% trans "Plan Status" %}</dt>
<dd>{{ plan.status }}</dd>
<dt>{% trans "Protection Provider" %}</dt>
<dd>{{ provider.name }}</dd>
</dl>
</div>
<div class="table_wrapper">
<table id="protectionplanDetailResource" class="{% block table_css_classes %}table table-striped datatable {{ table.css_classes }}{% endblock %}">
<thead>
<tr class="table_column_header">
<th {{ column.attr_string|safe }}>
Resource Name
</th>
<th {{ column.attr_string|safe }}>
Resource Type
</th>
</tr>
</thead>
<tbody>
{% for instance in instances %}
<tr data-tt-id="{{ instance.showid }}"
resource-id="{{ instance.id }}"
{% if instance.showparentid != None %}
data-tt-parent-id="{{ instance.showparentid }}"
{% endif %}>
<td>
<span class="logoresource"></span>
<span class="spanresource">{{instance.name}}</span>
</td>
<td>
<span class="spanresource">{{instance.type}}</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script type="text/javascript">
$(function() {
"use strict";
horizon.protectionplans_detail.init();
});
</script>

View File

@@ -0,0 +1,16 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Protection Plan Details" %}{% endblock %}
{% block page_header %}
{% include 'horizon/common/_detail_header.html' %}
{% endblock %}
{% block main %}
<div class="row">
<div class="col-sm-12">
{% include "protectionplans/_detail.html" %}
</div>
</div>
{% endblock %}