Add counts to index pages

Add counts to index pages for Nodes, Images and Roles.

Change-Id: I8b52fe05fb9fc3dac9675cdddf8cc9750aa55ee8
This commit is contained in:
Ana Krivokapic 2014-10-29 17:04:02 +01:00
parent 730ab80935
commit f14da6cb4f
9 changed files with 44 additions and 9 deletions

View File

@ -3,7 +3,7 @@
{% block title %}{% trans 'Provisioning Images' %}{% endblock %}
{% block page_header %}
{% include 'horizon/common/_page_header.html' with title=_('Provisioning Images') %}
{% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Provisioning Images') %}
{% endblock page_header %}
{% block main %}

View File

@ -25,15 +25,18 @@ from openstack_dashboard.dashboards.project.images.images import views
from tuskar_ui import api as tuskar_api
from tuskar_ui.infrastructure.images import forms
from tuskar_ui.infrastructure.images import tables
import tuskar_ui.infrastructure.views as infrastructure_views
from tuskar_ui.utils import utils
LOG = logging.getLogger(__name__)
class IndexView(horizon_tables.DataTableView):
class IndexView(infrastructure_views.ItemCountMixin,
horizon_tables.DataTableView):
table_class = tables.ImagesTable
template_name = "infrastructure/images/index.html"
@memoized.memoized_method
def get_data(self):
images = []
filters = self.get_filters()

View File

@ -4,7 +4,7 @@
{% block title %}{% trans 'Nodes' %}{% endblock %}
{% block page_header %}
{% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Nodes') items_count=nodes_count %}
{% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Nodes') %}
{% endblock page_header %}
{% block main %}

View File

@ -54,7 +54,7 @@ class NodesTests(test.BaseAdminViewTests, helpers.APITestCase):
'list.return_value': [],
}) as mock:
res = self.client.get(INDEX_URL)
self.assertEqual(mock.list.call_count, 5)
self.assertEqual(mock.list.call_count, 6)
self.assertTemplateUsed(
res, 'infrastructure/nodes/index.html')
@ -75,7 +75,7 @@ class NodesTests(test.BaseAdminViewTests, helpers.APITestCase):
'list.return_value': nodes,
}) as Node:
res = self.client.get(INDEX_URL + '?tab=nodes__' + tab_name)
self.assertEqual(Node.list.call_count, 5)
self.assertEqual(Node.list.call_count, 6)
self.assertTemplateUsed(
res, 'infrastructure/nodes/index.html')

View File

@ -28,10 +28,12 @@ from tuskar_ui import api
from tuskar_ui.infrastructure.nodes import forms
from tuskar_ui.infrastructure.nodes import tables
from tuskar_ui.infrastructure.nodes import tabs
import tuskar_ui.infrastructure.views as infrastructure_views
from tuskar_ui.utils import metering as metering_utils
class IndexView(horizon_tabs.TabbedTableView):
class IndexView(infrastructure_views.ItemCountMixin,
horizon_tabs.TabbedTableView):
tab_group_class = tabs.NodeTabs
template_name = 'infrastructure/nodes/index.html'
@ -54,6 +56,10 @@ class IndexView(horizon_tabs.TabbedTableView):
context['header_actions'].append(upload_action)
return context
@memoized.memoized_method
def get_data(self):
return api.node.Node.list(self.request)
class RegisterView(horizon_forms.ModalFormView):
form_class = forms.RegisterNodeFormset

View File

@ -3,7 +3,7 @@
{% block title %}{% trans 'Deployment Roles' %}{% endblock %}
{% block page_header %}
{% include 'horizon/common/_page_header.html' with title=_('Deployment Roles') %}
{% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Deployment Roles') %}
{% endblock page_header %}
{% block main %}

View File

@ -28,6 +28,7 @@ from openstack_dashboard.api import base as api_base
from tuskar_ui import api
from tuskar_ui.infrastructure.roles import tables
from tuskar_ui.infrastructure.roles import workflows as role_workflows
import tuskar_ui.infrastructure.views as infrastructure_views
from tuskar_ui.utils import metering as metering_utils
@ -50,10 +51,12 @@ class StackMixin(object):
return api.heat.Stack.get_by_plan(self.request, plan)
class IndexView(horizon_tables.DataTableView):
class IndexView(infrastructure_views.ItemCountMixin,
horizon_tables.DataTableView):
table_class = tables.RolesTable
template_name = "infrastructure/roles/index.html"
@utils.memoized.memoized
def get_data(self):
roles = api.tuskar.Role.list(self.request)
plan = api.tuskar.Plan.get_the_plan(self.request)

View File

@ -7,7 +7,7 @@
<em>{{ request.session.domain_context_name }}:</em>
{% endif %}
{{ title }}
{% if items_count %}
{% if items_count or items_count == 0%}
<span class="badge">
{{ items_count }}
</span>

View File

@ -0,0 +1,23 @@
# -*- coding: utf8 -*-
#
# 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.
class ItemCountMixin(object):
def get_items_count(self):
return len(self.get_data())
def get_context_data(self, **kwargs):
context = super(ItemCountMixin, self).get_context_data(**kwargs)
context['items_count'] = self.get_items_count()
return context