mirror of
https://github.com/simple-login/app.git
synced 2025-02-24 15:53:22 +08:00
improve dashboard page
This commit is contained in:
parent
5b8bc68da1
commit
d929cea771
3 changed files with 114 additions and 62 deletions
|
@ -9,7 +9,7 @@
|
|||
{% block default_content %}
|
||||
<div class="page-header row">
|
||||
<h3 class="page-title col">
|
||||
Alias Activity {{ alias }}
|
||||
{{ alias }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
|
@ -22,11 +22,7 @@
|
|||
<tr>
|
||||
<th>Activity</th>
|
||||
<th>Website Email</th>
|
||||
|
||||
<th>
|
||||
Forward/Reply
|
||||
</th>
|
||||
|
||||
<th></th>
|
||||
<th>Alias</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -35,66 +35,39 @@
|
|||
<table class="table table-hover table-outline table-vcenter text-nowrap card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>
|
||||
Used On
|
||||
<i class="fe fe-help-circle" data-toggle="tooltip"
|
||||
title="List of app/website that has received this email"></i>
|
||||
<th>Alias</th>
|
||||
<th>Activity <i class="fe fe-help-circle" data-toggle="tooltip" title="Stats on this alias"></i>
|
||||
</th>
|
||||
<th>Actions</th>
|
||||
<th>
|
||||
Email Forwarding
|
||||
<th>Email Forwarding <i class="fe fe-help-circle" data-toggle="tooltip" title="Block/unblock an alias"></i>
|
||||
</th>
|
||||
<th>Delete</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for gen_email in gen_emails %}
|
||||
{% for alias_info in aliases %}
|
||||
{% set gen_email = alias_info.gen_email %}
|
||||
|
||||
<tr {% if gen_email.id == highlight_gen_email_id %} class="highlight-row" {% endif %}>
|
||||
|
||||
<td>
|
||||
<div>
|
||||
<a href="mailto: {{ gen_email.email }}">{{ gen_email.email }}</a>
|
||||
<a href="mailto: {{ gen_email.email }}">{{ gen_email.email }}</a>
|
||||
{% if gen_email.enabled %}
|
||||
<span class="icon clipboard" data-clipboard-text="{{ gen_email.email }}">
|
||||
<i class="dropdown-icon fe fe-clipboard"></i>
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
Created {{ gen_email.created_at | dt }}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{% for client_user in gen_email.client_users %}
|
||||
{{ client_user.client.name }} <br>
|
||||
{% endfor %}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
{% if gen_email.enabled %}
|
||||
<button class="clipboard btn btn-secondary btn-sm"
|
||||
data-toggle="tooltip"
|
||||
title="Copy the alias to clipboard"
|
||||
data-clipboard-text="{{ gen_email.email }}">
|
||||
Copy
|
||||
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
{% if gen_email.enabled %}
|
||||
<form method="post">
|
||||
<input type="hidden" name="form-name" value="trigger-email">
|
||||
<input type="hidden" name="gen-email-id" value="{{ gen_email.id }}">
|
||||
|
||||
|
||||
<button class="btn btn-secondary btn-sm"
|
||||
data-toggle="tooltip"
|
||||
title="Send a test email to the alias."
|
||||
{% if loop.index ==1 %}
|
||||
data-intro="By triggering the test email,
|
||||
SimpleLogin server will send an email to this alias
|
||||
and this email should arrive to your personal email inbox 🚀"
|
||||
{% endif %}
|
||||
>Trigger Test Email
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
<div>{{ alias_info.nb_forward }} forwarded</div>
|
||||
<div>{{ alias_info.nb_blocked }} blocked</div>
|
||||
<div>{{ alias_info.nb_reply }} reply</div>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
@ -126,13 +99,37 @@
|
|||
</td>
|
||||
|
||||
<td>
|
||||
<form method="post">
|
||||
<input type="hidden" name="form-name" value="delete-email">
|
||||
<input type="hidden" name="gen-email-id" value="{{ gen_email.id }}">
|
||||
<span class="icon delete-email">
|
||||
<i class="fe fe-trash"></i>
|
||||
</span>
|
||||
</form>
|
||||
<div class="item-action dropdown">
|
||||
<a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fe fe-more-vertical"></i></a>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<a href="{{ url_for('dashboard.alias_log', alias=gen_email.email) }}"
|
||||
class="dropdown-item">
|
||||
<i class="dropdown-icon fe fe-activity"></i>
|
||||
Activity
|
||||
</a>
|
||||
|
||||
{% if gen_email.enabled %}
|
||||
<form method="post">
|
||||
<a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon fe fe-send"></i>
|
||||
<input type="hidden" name="form-name" value="trigger-email">
|
||||
<input type="hidden" name="gen-email-id"
|
||||
value="{{ gen_email.id }}">
|
||||
<span class="trigger-email"> Send email to alias </span>
|
||||
</a>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<div class="dropdown-divider"></div>
|
||||
|
||||
<form method="post">
|
||||
<a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon fe fe-trash"></i>
|
||||
<input type="hidden" name="form-name" value="delete-email">
|
||||
<input type="hidden" name="gen-email-id" value="{{ gen_email.id }}">
|
||||
<span class="delete-email"> Delete </span>
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
@ -246,6 +243,18 @@
|
|||
});
|
||||
});
|
||||
|
||||
$(".trigger-email").on("click", function (e) {
|
||||
notie.confirm({
|
||||
text: "SimpleLogin server will send an email to this alias and it should arrive to your inbox, please confirm",
|
||||
cancelCallback: () => {
|
||||
// nothing to do
|
||||
},
|
||||
submitCallback: () => {
|
||||
$(this).closest("form").submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".custom-switch-input").change(function (e) {
|
||||
var message = "";
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from flask import render_template, request, redirect, url_for, flash, session
|
||||
from flask_login import login_required, current_user
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
@ -7,7 +9,15 @@ from app.config import HIGHLIGHT_GEN_EMAIL_ID
|
|||
from app.dashboard.base import dashboard_bp
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import GenEmail, ClientUser
|
||||
from app.models import GenEmail, ClientUser, ForwardEmail, ForwardEmailLog
|
||||
|
||||
|
||||
@dataclass
|
||||
class AliasInfo:
|
||||
gen_email: GenEmail
|
||||
nb_forward: int
|
||||
nb_blocked: int
|
||||
nb_reply: int
|
||||
|
||||
|
||||
@dashboard_bp.route("/", methods=["GET", "POST"])
|
||||
|
@ -97,6 +107,43 @@ def index():
|
|||
return render_template(
|
||||
"dashboard/index.html",
|
||||
client_users=client_users,
|
||||
aliases=get_alias_info(current_user.id),
|
||||
gen_emails=gen_emails,
|
||||
highlight_gen_email_id=highlight_gen_email_id,
|
||||
)
|
||||
|
||||
|
||||
def get_alias_info(user_id) -> [AliasInfo]:
|
||||
aliases = {} # dict of alias and AliasInfo
|
||||
q = db.session.query(GenEmail, ForwardEmail, ForwardEmailLog).filter(
|
||||
GenEmail.user_id == user_id,
|
||||
GenEmail.id == ForwardEmail.gen_email_id,
|
||||
ForwardEmail.id == ForwardEmailLog.forward_id,
|
||||
)
|
||||
|
||||
for ge, fe, fel in q:
|
||||
if ge.email not in aliases:
|
||||
aliases[ge.email] = AliasInfo(
|
||||
gen_email=ge, nb_blocked=0, nb_forward=0, nb_reply=0
|
||||
)
|
||||
|
||||
alias_info = aliases[ge.email]
|
||||
if fel.is_reply:
|
||||
alias_info.nb_reply += 1
|
||||
elif fel.blocked:
|
||||
alias_info.nb_blocked += 1
|
||||
else:
|
||||
alias_info.nb_forward += 1
|
||||
|
||||
# also add alias that has no forward email or log
|
||||
q = (
|
||||
db.session.query(GenEmail)
|
||||
.filter(GenEmail.email.notin_(aliases.keys()))
|
||||
.filter(GenEmail.user_id == user_id)
|
||||
)
|
||||
for ge in q:
|
||||
aliases[ge.email] = AliasInfo(
|
||||
gen_email=ge, nb_blocked=0, nb_forward=0, nb_reply=0
|
||||
)
|
||||
|
||||
return list(aliases.values())
|
||||
|
|
Loading…
Reference in a new issue