From 18d1b598455fc8eb943b25a2d6510e30da03e963 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sat, 25 Apr 2020 23:07:34 +0200 Subject: [PATCH 1/5] add vuejs to package.json --- app/dashboard/templates/dashboard/index.html | 2 +- static/package-lock.json | 5 +++++ static/package.json | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 42adb0ec..207dd38b 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -336,7 +336,7 @@ - + {% endfor %} 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" } } From c350bca488cec821a1b569654919e9598aae28f9 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sun, 26 Apr 2020 18:24:43 +0200 Subject: [PATCH 2/5] collapsible filters --- app/dashboard/templates/dashboard/index.html | 122 ++++++++++++------- 1 file changed, 78 insertions(+), 44 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 207dd38b..ccbbeda7 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -62,53 +62,65 @@ -
-
-
- +
+
- + +
+ + - + - {% if query or sort or filter %} - Reset - {% endif %} - + + + {% if query or sort or filter %} + Reset + {% endif %} + +
+ + + Filters + + + + +
@@ -582,4 +594,26 @@ }) + + + {% endblock %} From 76b4611bc2ad839fda80741e69d2ce700e5457fd Mon Sep 17 00:00:00 2001 From: Son NK Date: Sun, 26 Apr 2020 18:49:23 +0200 Subject: [PATCH 3/5] Show global stats --- app/dashboard/templates/dashboard/index.html | 55 ++++++++++++++++++++ app/dashboard/views/index.py | 41 +++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index ccbbeda7..11251acc 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
+
+
+
+ +
+ + +
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, ) From 5bcc2138cfa0714f31a190cc1e2102928374c482 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sun, 26 Apr 2020 18:49:46 +0200 Subject: [PATCH 4/5] Fix wording in menu: use plurial for consistency --- templates/menu.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From 131a0473fdd49ca7aac28c973a2f8bfc3636d7e5 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sun, 26 Apr 2020 18:53:00 +0200 Subject: [PATCH 5/5] Move alias activity details into collapsed section --- app/dashboard/templates/dashboard/index.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 11251acc..299e3577 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -236,7 +236,7 @@
-
+
{% if alias_info.latest_email_log != None %} @@ -266,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  → -
@@ -317,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