implement checkpoint detail page
It includes python, html and js features. Change-Id: I39699ddef9a866f504c353d114e3cb63196b2cd2 Closes-Bug:#1591795
This commit is contained in:
@@ -60,6 +60,12 @@ class DeleteCheckpointsAction(tables.DeleteAction):
|
||||
checkpoint_id=obj_id)
|
||||
|
||||
|
||||
def get_provider_link(checkpoint):
|
||||
"""url Two args"""
|
||||
return reverse("horizon:smaug:checkpoints:detail",
|
||||
args=(checkpoint.provider_id, checkpoint.id))
|
||||
|
||||
|
||||
def get_plan_name(obj):
|
||||
name = ""
|
||||
plan = getattr(obj, 'protection_plan')
|
||||
@@ -71,6 +77,7 @@ def get_plan_name(obj):
|
||||
class CheckpointsTable(tables.DataTable):
|
||||
checkpointId = tables.Column(
|
||||
"id",
|
||||
link=get_provider_link,
|
||||
verbose_name=_('Checkpoint ID'))
|
||||
protectionProvider = tables.Column(
|
||||
"provider_name",
|
||||
@@ -86,3 +93,11 @@ class CheckpointsTable(tables.DataTable):
|
||||
name = 'checkpoints'
|
||||
verbose_name = _('Checkpoints')
|
||||
row_actions = (RestoreCheckpointLink, DeleteCheckpointsAction)
|
||||
|
||||
|
||||
class DetailTable(tables.DataTable):
|
||||
|
||||
class Meta(object):
|
||||
name = "protectionresources"
|
||||
verbose_name = _("Protection Resources")
|
||||
hidden_title = False
|
||||
|
||||
@@ -23,4 +23,7 @@ urlpatterns = [
|
||||
url(r'^(?P<provider_id>[^/]+)/checkpoints/'
|
||||
r'(?P<checkpoint_id>[^/]+)/restore$',
|
||||
views.CheckpointsRestoreView.as_view(), name='restore'),
|
||||
url(r'^(?P<provider_id>[^/]+)/checkpoints/'
|
||||
r'(?P<checkpoint_id>[^/]+)/detail/$',
|
||||
views.DetailView.as_view(), name='detail'),
|
||||
]
|
||||
|
||||
@@ -237,3 +237,71 @@ class CheckpointsRestoreView(horizon_forms.ModalFormView):
|
||||
result.showid,
|
||||
results
|
||||
)
|
||||
|
||||
|
||||
class DetailView(horizon_tables.DataTableView):
|
||||
table_class = tables.DetailTable
|
||||
template_name = 'checkpoints/detail.html'
|
||||
page_title = _("{{ checkpoint.protection_plan.name }}")
|
||||
|
||||
@memoized.memoized_method
|
||||
def get_checkpoint_data(self):
|
||||
try:
|
||||
provider_id = self.kwargs['provider_id']
|
||||
checkpoint_id = self.kwargs['checkpoint_id']
|
||||
checkpoint = smaugclient.checkpoint_get(self.request,
|
||||
provider_id,
|
||||
checkpoint_id)
|
||||
except Exception:
|
||||
checkpoint = []
|
||||
msg = _('checkpoint list can not be retrieved.')
|
||||
exceptions.handle(self.request, msg)
|
||||
return checkpoint
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(DetailView, self).get_context_data(**kwargs)
|
||||
checkpoint = self.get_checkpoint_data()
|
||||
context["checkpoint"] = checkpoint
|
||||
provider_id = self.kwargs['provider_id']
|
||||
provider = smaugclient.provider_get(self.request, provider_id)
|
||||
context["provider_name"] = provider.name
|
||||
context["resources"] = self.get_resources()
|
||||
context["url"] = reverse("horizon:smaug:protectionplans:index")
|
||||
return context
|
||||
|
||||
@memoized.memoized_method
|
||||
def get_resources(self):
|
||||
results = []
|
||||
try:
|
||||
provider_id = self.kwargs['provider_id']
|
||||
checkpoint_id = self.kwargs['checkpoint_id']
|
||||
checkpoint = smaugclient.checkpoint_get(self.request,
|
||||
provider_id,
|
||||
checkpoint_id)
|
||||
graphnodes = utils.deserialize_resource_graph(
|
||||
checkpoint.resource_graph)
|
||||
self.get_results(graphnodes, None, results)
|
||||
except Exception:
|
||||
exceptions.handle(
|
||||
self.request,
|
||||
_('Unable to retrieve checkpoint details.'),
|
||||
redirect=reverse("horizon:smaug:checkpoints:index"))
|
||||
return results
|
||||
|
||||
def get_results(self, graphnodes, showparentid, results):
|
||||
for graphnode in graphnodes:
|
||||
if graphnode is not None:
|
||||
# add graph node to results
|
||||
resource = {}
|
||||
resource["id"] = graphnode.value.id
|
||||
resource["type"] = graphnode.value.type
|
||||
resource["name"] = graphnode.value.name
|
||||
resource["showid"] = str(uuid.uuid4())
|
||||
resource["showparentid"] = showparentid
|
||||
result = protectables.Instances(self, resource)
|
||||
results.append(result)
|
||||
# add child graph nodes to results
|
||||
self.get_results(graphnode.child_nodes,
|
||||
result.showid,
|
||||
results
|
||||
)
|
||||
|
||||
@@ -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.checkpoints_detail = {
|
||||
init: function() {
|
||||
/* init resource tree */
|
||||
$("#checkpointDetailResource").treetable({ expandable: true });
|
||||
}
|
||||
};
|
||||
62
smaug_dashboard/templates/checkpoints/_detail.html
Normal file
62
smaug_dashboard/templates/checkpoints/_detail.html
Normal file
@@ -0,0 +1,62 @@
|
||||
{% 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 "Protection Provider" %}:</dt>
|
||||
<dd>{{ provider_name }}</dd>
|
||||
<dt>{% trans "Protection Plan" %}:</dt>
|
||||
<dd>{{ checkpoint.protection_plan.name }}</dd>
|
||||
<dt>{% trans "Status" %}:</dt>
|
||||
<dd>{{ checkpoint.status }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="table_wrapper">
|
||||
<table id="checkpointDetailResource"
|
||||
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 resource in resources %}
|
||||
<tr data-tt-id="{{ resource.showid }}"
|
||||
resource-id="{{ resource.id }}"
|
||||
{% if resource.showparentid != None %}
|
||||
data-tt-parent-id="{{ resource.showparentid }}"
|
||||
{% endif %}>
|
||||
<td>
|
||||
<span class="logoresource"></span>
|
||||
<span class="spanresource">{{ resource.name }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="spanresource">{{ resource.type }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
"use strict";
|
||||
horizon.checkpoints_detail.init();
|
||||
});
|
||||
</script>
|
||||
16
smaug_dashboard/templates/checkpoints/detail.html
Normal file
16
smaug_dashboard/templates/checkpoints/detail.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Check Point Details" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include 'horizon/common/_detail_header.html' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% include 'checkpoints/_detail.html' %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user