diff --git a/orchestra/contrib/musician/settings.py b/orchestra/contrib/musician/settings.py index 18c878a9..0836a2eb 100644 --- a/orchestra/contrib/musician/settings.py +++ b/orchestra/contrib/musician/settings.py @@ -9,7 +9,7 @@ def getsetting(name): # provide a default value allowing to overwrite it for each type of account def allowed_resources_default_factory(): - return {'mailbox': 2} + return {'mailbox': 2, 'database': 1, 'account': 2, 'nextcloud': 2,} DEFAULTS = { # allowed resources limit hardcoded because cannot be retrieved from the API. @@ -21,11 +21,17 @@ DEFAULTS = { # 'disk': 1024, # 'traffic': 2048, 'mailbox': 2, + 'database': 1, + 'account': 2, + 'nextcloud': 2, }, 'ASSOCIATION': { # 'disk': 5 * 1024, # 'traffic': 20 * 1024, 'mailbox': 10, + 'database': 1, + 'account': 8, + 'nextcloud': 10, } } ), diff --git a/orchestra/contrib/musician/static/musician/css/default.css b/orchestra/contrib/musician/static/musician/css/default.css index 3f743f42..9e26ced9 100644 --- a/orchestra/contrib/musician/static/musician/css/default.css +++ b/orchestra/contrib/musician/static/musician/css/default.css @@ -276,11 +276,32 @@ h1.service-name { font-weight: 900; } +.card.resource-usage.resource-database h5.card-title:after { + content: "\f1c0"; + font-weight: 900; +} + .card.resource-usage.resource-notifications h5.card-title:after { content: "\f0f3"; font-weight: 900; } +.card.resource-usage.resource-domains h5.card-title:after { + content: "\f7a2"; + font-weight: 900; +} + +.card.resource-usage.resource-nextcloud h5.card-title:after { + content: "\f0c2"; + font-weight: 900; +} + +.card.resource-usage.resource-list h5.card-title:after { + content: "\f674"; + font-weight: 900; +} + + .card.card-profile .card-header { background: white; border-bottom: none; diff --git a/orchestra/contrib/musician/templates/musician/dashboard2.html b/orchestra/contrib/musician/templates/musician/dashboard2.html index cb70f99e..f83018ba 100644 --- a/orchestra/contrib/musician/templates/musician/dashboard2.html +++ b/orchestra/contrib/musician/templates/musician/dashboard2.html @@ -11,30 +11,60 @@ {% endif %}
+ {% for resource, usage in resource_usage.items %}
-
+
{{ usage.verbose_name }}
- {% include "musician/components/usage_progress_bar.html" with detail=usage.data %} +
+ {% if usage.data and usage.data.used %} + {{ usage.data.used|floatformat }} {{ usage.data.unit }} + {% endif %} +
+ {% if usage.data.progres_bar %} +
+
+
+ {% endif %} {% if usage.data.alert %}
{{ usage.data.alert }}
{% endif %}
-
- {% endfor %} -
-
-
{% trans "Notifications" %}
- {% for message in notifications %} -

{{ message }}

- {% empty %} -

{% trans "There is no notifications at this time." %}

- {% endfor %} + +
+
    + {% for obj_data in usage.objects %} +
  • + {{ obj_data }} + {{ obj_data.used }} {{ obj_data.resource.unit }} +
  • + {% endfor %} +
+ {% endfor %} + +
+
+
{% trans "Domains" %}
+
{{ domains|length }} {% trans "Domains" %}
+
+
+
    + {% for domain in domains %} +
  • + {{ domain }} + +
  • + {% endfor %} +
+
+
+
- {% endblock %} + diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index 2633c8f7..ed1215b4 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -69,9 +69,24 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): context = super().get_context_data(**kwargs) related_resources = self.get_all_resources() - # print([ x.resource for x in related_resources.filter(resource_id__verbose_name='mailbox-disk')]) - - + + # TODO: que mostrar en el panel + # account + account = related_resources.filter(resource_id__verbose_name='account-disk') + # account_trafic = related_resources.filter(resource_id__verbose_name='account-traffic') + # print(account_trafic.first()) + # /admin/resources/resourcedata/17000 + # mailbox + mailboxes = related_resources.filter(resource_id__verbose_name='mailbox-disk') + # lists + lists = related_resources.filter(resource_id__verbose_name='list-traffic') + # Database + databases = related_resources.filter(resource_id__verbose_name='database-disk') + # nextcloud + nextcloud = related_resources.filter(resource_id__verbose_name='nextcloud-disk') + # domains + domains = Domain.objects.filter(account_id=self.request.user) + # TODO(@slamora) update when backend supports notifications notifications = [] @@ -81,7 +96,11 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): # TODO(@slamora) update when backend provides resource usage data resource_usage = { - 'mailbox': self.get_mailbox_usage(profile_type), + 'account': self.get_account_usage(profile_type, account), + 'mailbox': self.get_resource_usage(profile_type, mailboxes, 'mailbox'), + 'database': self.get_resource_usage(profile_type, databases, 'database'), + 'nextcloud': self.get_resource_usage(profile_type, nextcloud, 'nextcloud'), + 'list': self.get_resource_usage(profile_type, lists, 'Mailman list Traffic'), } support_email = getattr(settings, "USER_SUPPORT_EMAIL", "suport@pangea.org") @@ -91,7 +110,7 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): support_email, ) context.update({ - # 'domains': domains, + 'domains': domains, 'resource_usage': resource_usage, 'notifications': notifications, "support_email_anchor": support_email_anchor, @@ -99,7 +118,6 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): return context - def get_all_resources(self): user = self.request.user resources = Resource.objects.select_related('content_type') @@ -117,27 +135,58 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): qset = Q(qset) | Q(content_type_id=ct_id, object_id__in=ids, resource__is_active=True) return ResourceData.objects.filter(qset) - - def get_mailbox_usage(self, profile_type): - allowed_mailboxes = ALLOWED_RESOURCES[profile_type]['mailbox'] - total_mailboxes = len(self.orchestra.retrieve_mailbox_list()) - mailboxes_left = allowed_mailboxes - total_mailboxes - + def get_resource_usage(self, profile_type, resource_data, name_resource): + limit_rs = 0 + total_rs = len(resource_data) + rs_left = 0 alert = '' - if mailboxes_left < 0: - alert = format_html("{} extra mailboxes", mailboxes_left * -1) - elif mailboxes_left <= 1: - alert = format_html("{} mailbox left", mailboxes_left) + progres_bar = False + + if ALLOWED_RESOURCES[profile_type].get(name_resource): + progres_bar = True + limit_rs = ALLOWED_RESOURCES[profile_type][name_resource] + rs_left = limit_rs - total_rs + + alert = '' + if rs_left < 0: + alert = format_html(f"{rs_left * -1} extra {name_resource}") + elif rs_left <= 1: + alert = format_html(f"{rs_left} {name_resource} left") return { - 'verbose_name': _('Mailboxes'), + 'verbose_name': _(name_resource.capitalize()), 'data': { - 'used': total_mailboxes, - 'total': allowed_mailboxes, + 'progres_bar': progres_bar, + 'used': total_rs, + 'total': limit_rs, 'alert': alert, - 'unit': 'mailboxes', - 'percent': get_bootstraped_percent(total_mailboxes, allowed_mailboxes), + 'unit': name_resource.capitalize(), + 'percent': get_bootstraped_percent(total_rs, limit_rs), }, + 'objects': resource_data, + } + + def get_account_usage(self, profile_type, account): + allowed_size = ALLOWED_RESOURCES[profile_type]['account'] + total_size = account.first().used + size_left = allowed_size - total_size + + alert = '' + if size_left < 0: + alert = format_html(f"{size_left * -1} extra size") + elif size_left <= 1: + alert = format_html(f"{size_left} size left") + return { + 'verbose_name': _('Account'), + 'data': { + 'progres_bar': True, + 'used': total_size, + 'total': allowed_size, + 'alert': alert, + 'unit': 'GiB Size', + 'percent': get_bootstraped_percent(total_size, allowed_size), + }, + 'objects': account, }