Skip to content

Commit

Permalink
Pretty quota status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Aug 26, 2023
1 parent cd7f779 commit a0dbd68
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
17 changes: 16 additions & 1 deletion app/static/app/css/sb-admin-2.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,26 @@ body {
margin-right: 0;
}

.navbar-top-links .dropdown-menu li a {
.navbar-top-links .dropdown-menu li a{
padding: 3px 20px;
min-height: 0;
}

.navbar-top-links .dropdown-menu li div.info-item{
padding: 3px 8px;
min-height: 0;
}

.navbar-top-links .dropdown-menu li div.info-item.quotas{
min-width: 190px;
}

.navbar-top-links .dropdown-menu li .progress{
margin-bottom: 0;
margin-top: 6px;
}


.navbar-top-links .dropdown-menu li a div {
white-space: normal;
}
Expand Down
28 changes: 21 additions & 7 deletions app/templates/app/logged_in_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,31 @@
</a>
<ul class="dropdown-menu dropdown-user">
<li class="user-profile">
{% blocktrans with user=user.username %}Hello, {{ user }}!{% endblocktrans %}<br/>
<span class="email">{{ user.email }}</span>
<div class="info-item">
{% blocktrans with user=user.username %}Hello, {{ user }}!{% endblocktrans %}<br/>
<span class="email">{{ user.email }}</span>
</div>
</li>
{% if user.profile.has_quota %}
<li class="divider"></li>
<li class="divider"></li>

{% with tot_quota=user.profile.quota %}
{% with used_quota=user.profile.used_quota_cached %}
{% percentage 0 tot_quota as perc_quota %}

Tot: {{ tot_quota }} Used: {{ used_quota }}
Perc: {{ perc_quota|floatformat:0 }}
{% percentage used_quota tot_quota as perc_quota %}
{% percentage used_quota tot_quota 100 as bar_width %}

<li>
<div class="info-item quotas">
{% with usage=perc_quota|floatformat:0 used=used_quota|storage_size total=tot_quota|storage_size %}
<i class="fa fa-database fa-fw"></i> {% blocktrans %}{{used}} of {{total}} used{% endblocktrans %}
<div class="progress">
<div class="progress-bar progress-bar-{% if perc_quota <= 100 %}success{% else %}warning{% endif %} active" style="width: {{ bar_width }}%">
{{usage}}%
</div>
</div>
{% endwith %}
</div>
</li>

{% endwith %}{% endwith %}
{% endif %}
Expand Down
14 changes: 13 additions & 1 deletion app/templatetags/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import datetime

import math
import logging
from django import template
from webodm import settings

register = template.Library()
logger = logging.getLogger('app.logger')

@register.filter
def storage_size(megabytes):
k = 1000
k2 = k ** 2
k3 = k ** 3
if megabytes <= k2:
return str(round(megabytes / k, 2)) + ' GB'
elif megabytes <= k3:
return str(round(megabytes / k2, 2)) + ' TB'
else:
return str(round(megabytes / k3, 2)) + ' PB'

@register.simple_tag
def percentage(num, den, maximum=None):
if den == 0:
Expand Down

0 comments on commit a0dbd68

Please sign in to comment.