diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 42adb0ec..299e3577 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -20,6 +20,61 @@ {% endblock %} {% block default_content %} + +
+
+
+
+
{{ stats.nb_alias }}
+
Aliases
+
+
+
+
+
+
+
{{ stats.nb_active_alias }}
+
Active Aliases
+
+
+
+
+
+
+
{{ stats.nb_forward }}
+
Forwards
+
+
+
+
+
+
+
{{ stats.nb_reply }}
+
Replies
+
+
+
+
+
+
+
{{ stats.nb_directory }}
+
Directories
+
+
+
+
+
+
+
{{ stats.nb_domain }}
+
Domains
+
+
+
+ +
+ + +
@@ -62,53 +117,65 @@
-
-
-
- +
+
- + +
+ + - + - {% if query or sort or filter %} - Reset - {% endif %} - + + + {% if query or sort or filter %} + Reset + {% endif %} + +
+ + + Filters + + + + +
@@ -169,7 +236,7 @@
-
+
{% if alias_info.latest_email_log != None %} @@ -199,15 +266,7 @@ {% else %} No Activity. Alias created {{ alias.created_at | dt }} {% endif %} -
- {{ alias_info.nb_forward }} forwards, - {{ alias_info.nb_blocked }} blocks, - {{ alias_info.nb_reply }} replies - - See All  → -
@@ -250,6 +309,14 @@
{% endif %} + {{ alias_info.nb_forward }} forwards, + {{ alias_info.nb_blocked }} blocks, + {{ alias_info.nb_reply }} replies + + See All  → + + {% if mailboxes|length > 1 %}
Current mailbox
@@ -336,7 +403,7 @@
- + {% endfor %} @@ -582,4 +649,26 @@ }) + + + {% endblock %} diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index b595bc18..00c0ac9d 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -1,3 +1,5 @@ +from dataclasses import dataclass + from flask import render_template, request, redirect, url_for, flash from flask_login import login_required, current_user from sqlalchemy.exc import IntegrityError @@ -12,9 +14,45 @@ from app.models import ( ClientUser, DeletedAlias, AliasGeneratorEnum, + User, + EmailLog, + CustomDomain, + Directory, ) +@dataclass +class Stats: + nb_alias: int + nb_active_alias: int + nb_forward: int + nb_reply: int + nb_domain: int + nb_directory: int + + +def get_stats(user: User) -> Stats: + nb_alias = Alias.query.filter_by(user_id=user.id).count() + nb_active_alias = Alias.query.filter_by(user_id=user.id, enabled=True).count() + nb_forward = EmailLog.query.filter_by( + user_id=user.id, is_reply=False, blocked=False, bounced=False + ).count() + nb_reply = EmailLog.query.filter_by( + user_id=user.id, is_reply=True, blocked=False, bounced=False + ).count() + nb_domain = CustomDomain.query.filter_by(user_id=user.id).count() + nb_directory = Directory.query.filter_by(user_id=user.id).count() + + data = locals() + # to keep only Stats field + data = { + k: v + for (k, v) in data.items() + if k in vars(Stats)["__dataclass_fields__"].keys() + } + return Stats(**data) + + @dashboard_bp.route("/", methods=["GET", "POST"]) @login_required def index(): @@ -120,6 +158,8 @@ def index(): current_user.intro_shown = True db.session.commit() + stats = get_stats(current_user) + return render_template( "dashboard/index.html", client_users=client_users, @@ -134,4 +174,5 @@ def index(): page=page, sort=sort, filter=alias_filter, + stats=stats, ) diff --git a/static/package-lock.json b/static/package-lock.json index aa84bd2b..d2a84667 100644 --- a/static/package-lock.json +++ b/static/package-lock.json @@ -98,6 +98,11 @@ "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==" + }, + "vue": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.11.tgz", + "integrity": "sha512-VfPwgcGABbGAue9+sfrD4PuwFar7gPb1yl1UK1MwXoQPAw0BKSqWfoYCT/ThFrdEVWoI51dBuyCoiNU9bZDZxQ==" } } } diff --git a/static/package.json b/static/package.json index 05a5b9c0..d41cfa1c 100644 --- a/static/package.json +++ b/static/package.json @@ -21,6 +21,7 @@ "intro.js": "^2.9.3", "notie": "^4.3.1", "qrious": "^4.0.2", - "toastr": "^2.1.4" + "toastr": "^2.1.4", + "vue": "^2.6.11" } } diff --git a/templates/menu.html b/templates/menu.html index 872d42db..dde6b2ee 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -3,7 +3,7 @@ - Alias + Aliases @@ -11,21 +11,21 @@ - API Key + API Keys