Show address mailbox disk usage.

This commit is contained in:
Santiago Lamora 2020-02-17 12:05:55 +01:00
parent 425d090522
commit 0fa26d799b
2 changed files with 29 additions and 8 deletions

View file

@ -229,13 +229,29 @@ class MailService(OrchestraModel):
def type_detail(self): def type_detail(self):
if self.type == self.FORWARD: if self.type == self.FORWARD:
return self.data['forward'] return self.data['forward']
# TODO(@slamora) retrieve mailbox usage
return { # retrieve mailbox usage
'usage': 250, try:
'total': 500, resource = self.data['mailboxes'][0]['resources']
'unit': 'MB', resource_disk = {}
'percent': 50, for r in resource:
} if r['name'] == 'disk':
resource_disk = r
break
mailbox_details = {
'usage': resource_disk['used'],
'total': resource_disk['allocated'],
'unit': resource_disk['unit'],
}
# get percent and round to be 0, 25, 50 or 100
# to set progress bar width using CSS classes (e.g. w-25)
percent = float(resource_disk['used']) / resource_disk['allocated']
mailbox_details['percent'] = round(percent * 4) * 100 // 4
except (IndexError, KeyError):
mailbox_details = {}
return mailbox_details
class MailinglistService(OrchestraModel): class MailinglistService(OrchestraModel):

View file

@ -1,5 +1,5 @@
{% comment %} {% comment %}
Resource usage rendered as bootstrap progress bar Resource usage rendered as bootstrap progress bar
Expected parameter: detail Expected parameter: detail
Expected structure: dictionary or object with attributes: Expected structure: dictionary or object with attributes:
@ -8,8 +8,13 @@ Expected structure: dictionary or object with attributes:
- unit (string): 'MB' - unit (string): 'MB'
- percent (int: [0, 25, 50, 75, 100]: 75 - percent (int: [0, 25, 50, 75, 100]: 75
{% endcomment %} {% endcomment %}
<div class="text-center"> <div class="text-center">
{% if detail %}
{{ detail.usage }} of {{ detail.total }}{{ detail.unit }} {{ detail.usage }} of {{ detail.total }}{{ detail.unit }}
{% else %}
N/A
{% endif %}
</div> </div>
<div class="progress"> <div class="progress">
<div class="progress-bar bg-secondary w-{{ detail.percent }}" role="progressbar" aria-valuenow="{{ detail.usage }}" <div class="progress-bar bg-secondary w-{{ detail.percent }}" role="progressbar" aria-valuenow="{{ detail.usage }}"