display new alias on top
This commit is contained in:
parent
711ae83751
commit
58504e3b8d
|
@ -48,16 +48,18 @@
|
||||||
{% for alias_info in aliases %}
|
{% for alias_info in aliases %}
|
||||||
{% set gen_email = alias_info.gen_email %}
|
{% set gen_email = alias_info.gen_email %}
|
||||||
|
|
||||||
<tr {% if gen_email.id == highlight_gen_email_id %} class="highlight-row" {% endif %}>
|
<tr {% if alias_info.highlight %} class="highlight-row" {% endif %}>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<div>
|
<div>
|
||||||
<a href="mailto: {{ gen_email.email }}">{{ gen_email.email }}</a>
|
<a href="mailto: {{ gen_email.email }}">{{ gen_email.email }}</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
Created {{ gen_email.created_at | dt }}
|
Created {{ gen_email.created_at | dt }}
|
||||||
</div>
|
</div>
|
||||||
|
{% if alias_info.highlight %}
|
||||||
|
<span class="text-success">New</span>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -20,6 +20,7 @@ class AliasInfo:
|
||||||
nb_reply: int
|
nb_reply: int
|
||||||
|
|
||||||
show_intro_test_send_email: bool = False
|
show_intro_test_send_email: bool = False
|
||||||
|
highlight: bool = False
|
||||||
|
|
||||||
|
|
||||||
@dashboard_bp.route("/", methods=["GET", "POST"])
|
@dashboard_bp.route("/", methods=["GET", "POST"])
|
||||||
|
@ -99,23 +100,15 @@ def index():
|
||||||
|
|
||||||
sorted(client_users, key=lambda cu: cu.client.name)
|
sorted(client_users, key=lambda cu: cu.client.name)
|
||||||
|
|
||||||
gen_emails = (
|
|
||||||
GenEmail.filter_by(user_id=current_user.id)
|
|
||||||
.order_by(GenEmail.email)
|
|
||||||
.options(joinedload(GenEmail.client_users))
|
|
||||||
.all()
|
|
||||||
)
|
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"dashboard/index.html",
|
"dashboard/index.html",
|
||||||
client_users=client_users,
|
client_users=client_users,
|
||||||
aliases=get_alias_info(current_user.id),
|
aliases=get_alias_info(current_user.id, highlight_gen_email_id),
|
||||||
gen_emails=gen_emails,
|
|
||||||
highlight_gen_email_id=highlight_gen_email_id,
|
highlight_gen_email_id=highlight_gen_email_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_alias_info(user_id) -> [AliasInfo]:
|
def get_alias_info(user_id, highlight_gen_email_id=None) -> [AliasInfo]:
|
||||||
aliases = {} # dict of alias and AliasInfo
|
aliases = {} # dict of alias and AliasInfo
|
||||||
q = db.session.query(GenEmail, ForwardEmail, ForwardEmailLog).filter(
|
q = db.session.query(GenEmail, ForwardEmail, ForwardEmailLog).filter(
|
||||||
GenEmail.user_id == user_id,
|
GenEmail.user_id == user_id,
|
||||||
|
@ -126,7 +119,11 @@ def get_alias_info(user_id) -> [AliasInfo]:
|
||||||
for ge, fe, fel in q:
|
for ge, fe, fel in q:
|
||||||
if ge.email not in aliases:
|
if ge.email not in aliases:
|
||||||
aliases[ge.email] = AliasInfo(
|
aliases[ge.email] = AliasInfo(
|
||||||
gen_email=ge, nb_blocked=0, nb_forward=0, nb_reply=0
|
gen_email=ge,
|
||||||
|
nb_blocked=0,
|
||||||
|
nb_forward=0,
|
||||||
|
nb_reply=0,
|
||||||
|
highlight=ge.id == highlight_gen_email_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
alias_info = aliases[ge.email]
|
alias_info = aliases[ge.email]
|
||||||
|
@ -145,11 +142,25 @@ def get_alias_info(user_id) -> [AliasInfo]:
|
||||||
)
|
)
|
||||||
for ge in q:
|
for ge in q:
|
||||||
aliases[ge.email] = AliasInfo(
|
aliases[ge.email] = AliasInfo(
|
||||||
gen_email=ge, nb_blocked=0, nb_forward=0, nb_reply=0
|
gen_email=ge,
|
||||||
|
nb_blocked=0,
|
||||||
|
nb_forward=0,
|
||||||
|
nb_reply=0,
|
||||||
|
highlight=ge.id == highlight_gen_email_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
ret = list(aliases.values())
|
ret = list(aliases.values())
|
||||||
|
|
||||||
|
# make sure the highlighted alias is the first element
|
||||||
|
highlight_index = None
|
||||||
|
for ix, alias in enumerate(ret):
|
||||||
|
if alias.highlight:
|
||||||
|
highlight_index = ix
|
||||||
|
break
|
||||||
|
|
||||||
|
if highlight_index:
|
||||||
|
ret.insert(0, ret.pop(highlight_index))
|
||||||
|
|
||||||
# only show intro on the first enabled alias
|
# only show intro on the first enabled alias
|
||||||
for alias in ret:
|
for alias in ret:
|
||||||
if alias.gen_email.enabled:
|
if alias.gen_email.enabled:
|
||||||
|
|
Loading…
Reference in a new issue