support search on contact page
This commit is contained in:
parent
ac1f56f206
commit
55dcd63654
|
@ -51,19 +51,47 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="post">
|
<div class="row mb-5">
|
||||||
<input type="hidden" name="form-name" value="create">
|
<div class="col-12 col-lg-6 pt-1">
|
||||||
{{ new_contact_form.csrf_token }}
|
|
||||||
|
|
||||||
<label class="form-label">Where do you want to send the email?</label>
|
<form method="post">
|
||||||
|
<input type="hidden" name="form-name" value="create">
|
||||||
|
{{ new_contact_form.csrf_token }}
|
||||||
|
{{ new_contact_form.email(class="form-control", placeholder="First Last <email@example.com>", autofocus=True) }}
|
||||||
|
{{ render_field_errors(new_contact_form.email) }}
|
||||||
|
<div class="small-text">
|
||||||
|
Where do you want to send the email?
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary mt-2">Create reverse-alias</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
{{ new_contact_form.email(class="form-control", placeholder="First Last <email@example.com>", autofocus=True) }}
|
<div class="col-12 col-lg-6 pt-1">
|
||||||
{{ render_field_errors(new_contact_form.email) }}
|
<div class="float-right d-flex">
|
||||||
<button class="btn btn-primary mt-2">Create reverse-alias</button>
|
<form method="post">
|
||||||
</form>
|
<input type="hidden" name="form-name" value="search">
|
||||||
|
|
||||||
|
<input type="search" name="query" value="{{ query }}"
|
||||||
|
placeholder="Enter to search for contacts"
|
||||||
|
class="form-control shadow mr-2"
|
||||||
|
style="max-width: 20em"
|
||||||
|
>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% if query %}
|
||||||
|
{% if highlight_contact_id %}
|
||||||
|
<a href="{{ url_for("dashboard.alias_contact_manager", alias_id=alias.id, highlight_contact_id=highlight_contact_id) }}"
|
||||||
|
class="btn btn-light">Reset</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{{ url_for("dashboard.alias_contact_manager", alias_id=alias.id) }}"
|
||||||
|
class="btn btn-light">Reset</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for contact_info in contact_infos %}
|
{% for contact_info in contact_infos %}
|
||||||
|
|
|
@ -60,7 +60,9 @@ class ContactInfo(object):
|
||||||
latest_email_log: EmailLog
|
latest_email_log: EmailLog
|
||||||
|
|
||||||
|
|
||||||
def get_contact_infos(alias: Alias, page=0, contact_id=None) -> [ContactInfo]:
|
def get_contact_infos(
|
||||||
|
alias: Alias, page=0, contact_id=None, query: str = ""
|
||||||
|
) -> [ContactInfo]:
|
||||||
"""if contact_id is set, only return the contact info for this contact"""
|
"""if contact_id is set, only return the contact info for this contact"""
|
||||||
sub = (
|
sub = (
|
||||||
db.session.query(
|
db.session.query(
|
||||||
|
@ -115,6 +117,14 @@ def get_contact_infos(alias: Alias, page=0, contact_id=None) -> [ContactInfo]:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if query:
|
||||||
|
q = q.filter(
|
||||||
|
or_(
|
||||||
|
Contact.website_email.ilike(f"%{query}%"),
|
||||||
|
Contact.name.ilike(f"%{query}%"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if contact_id:
|
if contact_id:
|
||||||
q = q.filter(Contact.id == contact_id)
|
q = q.filter(Contact.id == contact_id)
|
||||||
|
|
||||||
|
@ -153,6 +163,8 @@ def alias_contact_manager(alias_id):
|
||||||
if request.args.get("page"):
|
if request.args.get("page"):
|
||||||
page = int(request.args.get("page"))
|
page = int(request.args.get("page"))
|
||||||
|
|
||||||
|
query = request.args.get("query") or ""
|
||||||
|
|
||||||
# sanity check
|
# sanity check
|
||||||
if not alias:
|
if not alias:
|
||||||
flash("You do not have access to this page", "warning")
|
flash("You do not have access to this page", "warning")
|
||||||
|
@ -248,7 +260,18 @@ def alias_contact_manager(alias_id):
|
||||||
url_for("dashboard.alias_contact_manager", alias_id=alias_id)
|
url_for("dashboard.alias_contact_manager", alias_id=alias_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
contact_infos = get_contact_infos(alias, page)
|
elif request.form.get("form-name") == "search":
|
||||||
|
query = request.form.get("query")
|
||||||
|
return redirect(
|
||||||
|
url_for(
|
||||||
|
"dashboard.alias_contact_manager",
|
||||||
|
alias_id=alias_id,
|
||||||
|
query=query,
|
||||||
|
highlight_contact_id=highlight_contact_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
contact_infos = get_contact_infos(alias, page, query=query)
|
||||||
last_page = len(contact_infos) < PAGE_LIMIT
|
last_page = len(contact_infos) < PAGE_LIMIT
|
||||||
|
|
||||||
# if highlighted contact isn't included, fetch it
|
# if highlighted contact isn't included, fetch it
|
||||||
|
@ -256,7 +279,8 @@ def alias_contact_manager(alias_id):
|
||||||
contact_ids = [contact_info.contact.id for contact_info in contact_infos]
|
contact_ids = [contact_info.contact.id for contact_info in contact_infos]
|
||||||
if highlight_contact_id and highlight_contact_id not in contact_ids:
|
if highlight_contact_id and highlight_contact_id not in contact_ids:
|
||||||
contact_infos = (
|
contact_infos = (
|
||||||
get_contact_infos(alias, contact_id=highlight_contact_id) + contact_infos
|
get_contact_infos(alias, contact_id=highlight_contact_id, query=query)
|
||||||
|
+ contact_infos
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
|
@ -267,4 +291,5 @@ def alias_contact_manager(alias_id):
|
||||||
highlight_contact_id=highlight_contact_id,
|
highlight_contact_id=highlight_contact_id,
|
||||||
page=page,
|
page=page,
|
||||||
last_page=last_page,
|
last_page=last_page,
|
||||||
|
query=query,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue