Skip to content

Commit

Permalink
Merge pull request BlitzKraft#258 from tushar5526/search
Browse files Browse the repository at this point in the history
Feat: Add search option in inbox
  • Loading branch information
kgashok committed Nov 29, 2022
2 parents 5671a08 + fef02a3 commit 0a0ad8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
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

0 comments on commit 0a0ad8a

Please sign in to comment.