Merge pull request #139 from simple-login/sort
More options for sorting and filtering aliases
This commit is contained in:
commit
d554c9e9e8
|
@ -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,19 @@ 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 alias_filter == "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)
|
||||||
|
elif sort == "new2old":
|
||||||
|
q = q.order_by(Alias.created_at.desc())
|
||||||
|
elif sort == "a2z":
|
||||||
|
q = q.order_by(Alias.email)
|
||||||
|
elif sort == "z2a":
|
||||||
|
q = q.order_by(Alias.email.desc())
|
||||||
else:
|
else:
|
||||||
# default sorting
|
# default sorting
|
||||||
q = q.order_by(latest_activity.desc())
|
q = q.order_by(latest_activity.desc())
|
||||||
|
|
|
@ -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,24 +61,53 @@
|
||||||
</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>
|
||||||
<option value="old2new" {% if sort == "old2new" %} selected {% endif %}>
|
<option value="old2new" {% if sort == "old2new" %} selected {% endif %}>
|
||||||
Oldest Alias to Newest
|
Alias Old-Recent
|
||||||
|
</option>
|
||||||
|
<option value="old2new" {% if sort == "new2old" %} selected {% endif %}>
|
||||||
|
Alias Recent-Old
|
||||||
|
</option>
|
||||||
|
<option value="a2z" {% if sort == "a2z" %} selected {% endif %}>
|
||||||
|
Alias A-Z
|
||||||
|
</option>
|
||||||
|
<option value="z2a" {% if sort == "z2a" %} selected {% endif %}>
|
||||||
|
Alias Z-A
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
|
@ -3,7 +3,6 @@ from flask_login import login_required, current_user
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
from app import email_utils
|
|
||||||
from app.api.serializer import get_alias_infos_with_pagination_v2
|
from app.api.serializer import get_alias_infos_with_pagination_v2
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
@ -13,7 +12,6 @@ from app.models import (
|
||||||
ClientUser,
|
ClientUser,
|
||||||
DeletedAlias,
|
DeletedAlias,
|
||||||
AliasGeneratorEnum,
|
AliasGeneratorEnum,
|
||||||
Mailbox,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,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"):
|
||||||
|
@ -61,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:
|
||||||
|
@ -77,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,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -95,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)
|
||||||
|
@ -120,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,
|
||||||
|
@ -128,4 +133,5 @@ def index():
|
||||||
show_intro=show_intro,
|
show_intro=show_intro,
|
||||||
page=page,
|
page=page,
|
||||||
sort=sort,
|
sort=sort,
|
||||||
|
filter=alias_filter,
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,17 +8,15 @@ from flask import Flask, redirect, url_for, render_template, request, jsonify, f
|
||||||
from flask_admin import Admin
|
from flask_admin import Admin
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
||||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||||
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
||||||
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
|
||||||
|
|
||||||
|
|
||||||
from app import paddle_utils
|
from app import paddle_utils
|
||||||
from app.admin_model import SLModelView, SLAdminIndexView
|
from app.admin_model import SLModelView, SLAdminIndexView
|
||||||
from app.api.base import api_bp
|
from app.api.base import api_bp
|
||||||
from app.auth.base import auth_bp
|
from app.auth.base import auth_bp
|
||||||
from app.config import (
|
from app.config import (
|
||||||
DEBUG,
|
|
||||||
DB_URI,
|
DB_URI,
|
||||||
FLASK_SECRET,
|
FLASK_SECRET,
|
||||||
SENTRY_DSN,
|
SENTRY_DSN,
|
||||||
|
@ -182,6 +180,11 @@ def fake_data():
|
||||||
EmailLog.create(user_id=user.id, contact_id=contact.id)
|
EmailLog.create(user_id=user.id, contact_id=contact.id)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
# have some disabled alias
|
||||||
|
if i % 5 == 0:
|
||||||
|
a.enabled = False
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
||||||
CustomDomain.create(
|
CustomDomain.create(
|
||||||
user_id=user.id, domain="very-long-domain.com.net.org", verified=True
|
user_id=user.id, domain="very-long-domain.com.net.org", verified=True
|
||||||
|
|
Loading…
Reference in a new issue