Support alias filter
This commit is contained in:
parent
12714ae601
commit
7b2e4da87f
|
@ -113,7 +113,7 @@ def get_alias_infos_with_pagination(user, page_id=0, query=None) -> [AliasInfo]:
|
||||||
|
|
||||||
|
|
||||||
def get_alias_infos_with_pagination_v2(
|
def get_alias_infos_with_pagination_v2(
|
||||||
user, page_id=0, query=None, sort=None
|
user, page_id=0, query=None, sort=None, alias_filter=None
|
||||||
) -> [AliasInfo]:
|
) -> [AliasInfo]:
|
||||||
ret = []
|
ret = []
|
||||||
latest_activity = func.max(
|
latest_activity = func.max(
|
||||||
|
@ -139,8 +139,10 @@ def get_alias_infos_with_pagination_v2(
|
||||||
or_(Alias.email.ilike(f"%{query}%"), Alias.note.ilike(f"%{query}%"))
|
or_(Alias.email.ilike(f"%{query}%"), Alias.note.ilike(f"%{query}%"))
|
||||||
)
|
)
|
||||||
|
|
||||||
if sort == "enabled":
|
if alias_filter == "enabled":
|
||||||
q = q.filter(Alias.enabled)
|
q = q.filter(Alias.enabled)
|
||||||
|
elif alias_filter == "disabled":
|
||||||
|
q = q.filter(Alias.enabled == False)
|
||||||
|
|
||||||
if sort == "old2new":
|
if sort == "old2new":
|
||||||
q = q.order_by(Alias.created_at)
|
q = q.order_by(Alias.created_at)
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
|
|
||||||
{% block default_content %}
|
{% block default_content %}
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-lg-6 pt-1">
|
|
||||||
|
<div class="col-lg-6 pt-1" style="max-width: 25em">
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<input type="hidden" name="form-name" value="create-custom-email">
|
<input type="hidden" name="form-name" value="create-custom-email">
|
||||||
|
@ -60,12 +61,13 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6 pt-1">
|
|
||||||
|
<div class="col-lg-auto pt-1 flex-grow-1">
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<form method="get" class="form-inline">
|
<form method="get" class="form-inline">
|
||||||
<select name="sort"
|
<select name="sort"
|
||||||
onchange="this.form.submit()"
|
onchange="this.form.submit()"
|
||||||
class="form-control custom-select mr-3">
|
class="form-control custom-select mr-3 shadow">
|
||||||
<option value="" {% if sort == "" %} selected {% endif %}>
|
<option value="" {% if sort == "" %} selected {% endif %}>
|
||||||
Sort by most recent activity
|
Sort by most recent activity
|
||||||
</option>
|
</option>
|
||||||
|
@ -81,15 +83,31 @@
|
||||||
<option value="z2a" {% if sort == "z2a" %} selected {% endif %}>
|
<option value="z2a" {% if sort == "z2a" %} selected {% endif %}>
|
||||||
Alias Z-A
|
Alias Z-A
|
||||||
</option>
|
</option>
|
||||||
<option value="enabled" {% if sort == "enabled" %} selected {% endif %}>
|
</select>
|
||||||
Only Enabled Alias
|
|
||||||
|
<select name="filter"
|
||||||
|
onchange="this.form.submit()"
|
||||||
|
class="form-control custom-select mr-3 shadow">
|
||||||
|
<option value="" {% if filter == "" %} selected {% endif %}>
|
||||||
|
All Aliases
|
||||||
|
</option>
|
||||||
|
<option value="enabled" {% if filter == "enabled" %} selected {% endif %}>
|
||||||
|
Only Enabled Aliases
|
||||||
|
</option>
|
||||||
|
<option value="disabled" {% if filter == "disabled" %} selected {% endif %}>
|
||||||
|
Only Disabled Aliases
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<input type="search" name="query" placeholder="Enter to search for alias"
|
<input type="search" name="query" placeholder="Enter to search for alias"
|
||||||
class="form-control shadow"
|
class="form-control shadow mr-2"
|
||||||
style="max-width: 15em"
|
style="max-width: 15em"
|
||||||
value="{{ query }}">
|
value="{{ query }}">
|
||||||
|
|
||||||
|
{% if query or sort or filter %}
|
||||||
|
<a href="{{ url_for('dashboard.index') }}"
|
||||||
|
class="btn btn-light">Reset</a>
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,6 +20,7 @@ from app.models import (
|
||||||
def index():
|
def index():
|
||||||
query = request.args.get("query") or ""
|
query = request.args.get("query") or ""
|
||||||
sort = request.args.get("sort") or ""
|
sort = request.args.get("sort") or ""
|
||||||
|
alias_filter = request.args.get("filter") or ""
|
||||||
|
|
||||||
page = 0
|
page = 0
|
||||||
if request.args.get("page"):
|
if request.args.get("page"):
|
||||||
|
@ -59,6 +60,7 @@ def index():
|
||||||
highlight_alias_id=alias.id,
|
highlight_alias_id=alias.id,
|
||||||
query=query,
|
query=query,
|
||||||
sort=sort,
|
sort=sort,
|
||||||
|
filter=alias_filter,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@ -75,6 +77,7 @@ def index():
|
||||||
highlight_alias_id=alias.id,
|
highlight_alias_id=alias.id,
|
||||||
query=query,
|
query=query,
|
||||||
sort=sort,
|
sort=sort,
|
||||||
|
filter=alias_filter,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -93,7 +96,9 @@ def index():
|
||||||
LOG.error("alias %s has been added before to DeletedAlias", email)
|
LOG.error("alias %s has been added before to DeletedAlias", email)
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
|
|
||||||
return redirect(url_for("dashboard.index", query=query, sort=sort))
|
return redirect(
|
||||||
|
url_for("dashboard.index", query=query, sort=sort, filter=alias_filter)
|
||||||
|
)
|
||||||
|
|
||||||
client_users = (
|
client_users = (
|
||||||
ClientUser.filter_by(user_id=current_user.id)
|
ClientUser.filter_by(user_id=current_user.id)
|
||||||
|
@ -118,7 +123,9 @@ def index():
|
||||||
return render_template(
|
return render_template(
|
||||||
"dashboard/index.html",
|
"dashboard/index.html",
|
||||||
client_users=client_users,
|
client_users=client_users,
|
||||||
alias_infos=get_alias_infos_with_pagination_v2(current_user, page, query, sort),
|
alias_infos=get_alias_infos_with_pagination_v2(
|
||||||
|
current_user, page, query, sort, alias_filter
|
||||||
|
),
|
||||||
highlight_alias_id=highlight_alias_id,
|
highlight_alias_id=highlight_alias_id,
|
||||||
query=query,
|
query=query,
|
||||||
AliasGeneratorEnum=AliasGeneratorEnum,
|
AliasGeneratorEnum=AliasGeneratorEnum,
|
||||||
|
@ -126,4 +133,5 @@ def index():
|
||||||
show_intro=show_intro,
|
show_intro=show_intro,
|
||||||
page=page,
|
page=page,
|
||||||
sort=sort,
|
sort=sort,
|
||||||
|
filter=alias_filter,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue