Skip to content

Commit

Permalink
Merge 8c8dbce into 57e4966
Browse files Browse the repository at this point in the history
  • Loading branch information
ar4s committed Sep 13, 2016
2 parents 57e4966 + 8c8dbce commit 1e56be9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/ralph/admin/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
{% block content %}
<div class="row">
<div class="small-8 large-8 columns">
{% cache 60 summary %}
{% ralph_summary %}
{% endcache %}
<div class="capacities module">
<div class="summary module row">
{% cache 60 summary %}
{% ralph_summary %}
{% endcache %}
</div>
{% my_services request.user %}
<div class="capacities module row">
{% cache 60 dc_capacity %}
{% dc_capacity data_centers %}
{% endcache %}
Expand Down
44 changes: 44 additions & 0 deletions src/ralph/admin/templates/admin/templatetags/my_services.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% load cache i18n dashboard_tags %}

{% if services %}
{% cache 60 my_services request.user %}
<div class="services module row">
<table class="full">
<h2>{% trans "My services" %}</h2>
<thead>
<tr>
<th>{% trans "Service" %}</th>
<th>{% trans "Environment" %}</th>
<th>{% trans "Assets count" %}</th>
</tr>
</thead>
<tbody>
{% for service in services %}
<tr>
<td rowspan="{{ service.serviceenvironment_set.count|add:"1" }}">
<a href="{% url 'admin:data_center_dchost_changelist' %}?service_env={% for service_env in service.serviceenvironment_set.all %}{{ service_env.id }}{% if not forloop.last %},{% endif %}{% endfor %}">{{ service }}</a>
</td>
</tr>
{% for service_env in service.serviceenvironment_set.all %}
<tr>
<td>
<a href="{% url 'admin:data_center_dchost_changelist' %}?service_env={{ service_env.id }}">
{{ service_env.environment }} ({{ service_env.baseobject_set.count }})
</a>
</td>
<td>
{% regroup service_env.baseobject_set.all by content_type as content_types %}
{% for type in content_types %}
<ul>
<li>{% get_objects_summary service_env type.grouper type.list %}</li>
</ul>
{% endfor %}
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
{% endcache %}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="{{ url }}">{{ name }}: {{ count }}</a>
25 changes: 25 additions & 0 deletions src/ralph/admin/templatetags/dashboard_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.template import Library
from django.utils.text import slugify

from ralph.assets.models.assets import Service
from ralph.data_center.models import (
DataCenter,
DataCenterAsset,
Expand Down Expand Up @@ -109,3 +110,27 @@ def ralph_summary():

})
return {'results': results}


@register.inclusion_tag('admin/templatetags/my_services.html')
def my_services(user):
return {
'services': Service.objects.prefetch_related(
'serviceenvironment_set__environment',
'serviceenvironment_set__baseobject_set__content_type'
).filter(technical_owners=user)
}


@register.inclusion_tag('admin/templatetags/objects_summary.html')
def get_objects_summary(service_env, content_type, objects):
from django.core.urlresolvers import reverse
opts = content_type.model_class()._meta
url = reverse(
'admin:{}_{}_changelist'.format(opts.app_label, opts.model_name)
)
return {
'url': '{}?service_env={}'.format(url, service_env.id),
'name': opts.verbose_name,
'count': len(objects),
}
11 changes: 7 additions & 4 deletions src/ralph/static/src/scss/components/dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@
& > .row {
margin-top: 10px;
}
.module {
.row.module {
border-bottom: 1px solid #ddd;
margin-bottom: 10px;
h2 {
color: #555;
font-size: 1.5rem;
text-align: left;
}
&:last-child {
border-bottom: none;
}
}
.capacities {
border-bottom: 1px solid #ddd;
}
.recent-actions {
.actionlist {
Expand Down

0 comments on commit 1e56be9

Please sign in to comment.