Skip to content

Commit fef02a3

Browse files
committed
Feat: Add search option in inbox
1 parent 5671a08 commit fef02a3

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

saythanks/core.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ def index():
9898
auth_domain=auth_domain)
9999

100100

101-
@app.route('/inbox')
101+
@app.route('/inbox', methods=['POST', 'GET'])
102102
@requires_auth
103103
def inbox():
104-
105104
# Auth0 stored account information.
106105
profile = session['profile']
107106

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

112111
is_email_enabled = storage.Inbox.is_email_enabled(inbox_db.slug)
113-
# Send over the list of all given notes for the user.
112+
if request.method == "GET":
113+
# Send over the list of all given notes for the user.
114+
return render_template('inbox.htm.j2',
115+
user=profile, notes=inbox_db.notes,
116+
inbox=inbox_db, is_enabled=is_enabled,
117+
is_email_enabled=is_email_enabled)
118+
search_str = request.form['search_str']
114119
return render_template('inbox.htm.j2',
115-
user=profile, notes=inbox_db.notes,
116-
inbox=inbox_db, is_enabled=is_enabled,
117-
is_email_enabled=is_email_enabled)
120+
user=profile, notes=inbox_db.search_notes(search_str),
121+
is_email_enabled=is_email_enabled)
122+
118123

119124

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

saythanks/storage.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ def notes(self):
208208
for n in r
209209
]
210210
return notes[::-1]
211+
212+
def search_notes(self, search_str):
213+
"""Returns a list of notes, queried by search string "param" """
214+
q = sqlalchemy.text("""SELECT * from notes where ( body LIKE '%' || :param || '%' or byline LIKE '%' || :param || '%' ) and inboxes_auth_id = :auth_id""")
215+
r = conn.execute(q, param=search_str, auth_id=self.auth_id).fetchall()
216+
217+
notes = [
218+
Note.from_inbox(
219+
self.slug,
220+
n["body"], n["byline"], n["archived"], n["uuid"], n["timestamp"]
221+
)
222+
for n in r
223+
]
224+
return notes[::-1]
211225

212226
def export(self, file_format):
213227
q = sqlalchemy.text("SELECT * from notes where inboxes_auth_id = :auth_id and archived = 'f'")

saythanks/templates/inbox.htm.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@
7272
<h3>Notes of Thankfulness:</h3>
7373
</p>
7474

75-
75+
<form action="/inbox" method="POST">
76+
<input type="text" style="font-size:14px" size=28 placeholder="Search by message body or byline" name="search_str">
77+
<button style="font-size:10px" type="submit">Search</button>
78+
</form>
7679
<table>
7780
<thead>
7881
<tr>

0 commit comments

Comments
 (0)