Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add search option in inbox #258

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions saythanks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ def index():
auth_domain=auth_domain)


@app.route('/inbox')
@app.route('/inbox', methods=['POST', 'GET'])
@requires_auth
def inbox():

# Auth0 stored account information.
profile = session['profile']

Expand All @@ -110,11 +109,17 @@ def inbox():
is_enabled = storage.Inbox.is_enabled(inbox_db.slug)

is_email_enabled = storage.Inbox.is_email_enabled(inbox_db.slug)
# Send over the list of all given notes for the user.
if request.method == "GET":
# Send over the list of all given notes for the user.
return render_template('inbox.htm.j2',
user=profile, notes=inbox_db.notes,
inbox=inbox_db, is_enabled=is_enabled,
is_email_enabled=is_email_enabled)
search_str = request.form['search_str']
return render_template('inbox.htm.j2',
user=profile, notes=inbox_db.notes,
inbox=inbox_db, is_enabled=is_enabled,
is_email_enabled=is_email_enabled)
user=profile, notes=inbox_db.search_notes(search_str),
is_email_enabled=is_email_enabled)



@app.route('/inbox/export/<format>')
Expand Down Expand Up @@ -346,3 +351,4 @@ def callback_handling():
# Using nickname by default, can be changed manually later if needed.
storage.Inbox.store(nickname, userid, email)
return redirect(url_for('inbox'))

14 changes: 14 additions & 0 deletions saythanks/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ def notes(self):
for n in r
]
return notes[::-1]

def search_notes(self, search_str):
"""Returns a list of notes, queried by search string "param" """
q = sqlalchemy.text("""SELECT * from notes where ( body LIKE '%' || :param || '%' or byline LIKE '%' || :param || '%' ) and inboxes_auth_id = :auth_id""")
r = conn.execute(q, param=search_str, auth_id=self.auth_id).fetchall()

notes = [
Note.from_inbox(
self.slug,
n["body"], n["byline"], n["archived"], n["uuid"], n["timestamp"]
)
for n in r
]
return notes[::-1]

def export(self, file_format):
q = sqlalchemy.text("SELECT * from notes where inboxes_auth_id = :auth_id and archived = 'f'")
Expand Down
5 changes: 4 additions & 1 deletion saythanks/templates/inbox.htm.j2
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
<h3>Notes of Thankfulness:</h3>
</p>


<form action="/inbox" method="POST">
<input type="text" style="font-size:14px" size=28 placeholder="Search by message body or byline" name="search_str">
<button style="font-size:10px" type="submit">Search</button>
</form>
<table>
<thead>
<tr>
Expand Down