Skip to content

Commit

Permalink
feat: allow searching club announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
UsernameDP authored and JasonGrace2282 committed Oct 4, 2024
1 parent 8d4abda commit 5681005
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
23 changes: 23 additions & 0 deletions intranet/apps/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,27 @@ class RawPaginationData(TypedDict, Generic[T]):
page_obj: Paginator[T]


def filter_announcements_by_search(request, items):
if "search" not in request.GET:
return items
searchParam = request.GET["search"]
if len(searchParam.strip()) == 0:
return items
searchParam = searchParam.lower()

def filterMethod(item):
return searchParam in item.title.lower() or searchParam in item.content.lower()

filteredItems = list(filter(filterMethod, items))

sorted_announcements = sorted(
filteredItems,
key=lambda announcement: (searchParam.lower() not in announcement.title.lower(), searchParam.lower() not in announcement.content.lower()),
)

return sorted_announcements


def paginate_announcements_list_raw(
request: HttpRequest,
items: Sequence[T],
Expand Down Expand Up @@ -358,6 +379,8 @@ def paginate_announcements_list_raw(
else:
page_num = DEFAULT_PAGE_NUM

items = filter_announcements_by_search(request, items)

paginator = Paginator(items, 15)
if page_num not in paginator.page_range:
page_num = DEFAULT_PAGE_NUM
Expand Down
8 changes: 7 additions & 1 deletion intranet/static/js/dashboard/announcements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global $ */
$(document).ready(function() {
$(document).ready(function () {
updatePartiallyHidden();

filterClubAnnouncements();
Expand Down Expand Up @@ -62,6 +62,12 @@ $(document).ready(function() {
filterClubAnnouncements();
});

$("#subscribed-announcement-search").submit((e) => {
e.preventDefault();
const value = $("#subscribed-announcement-search-input").val();
window.location.replace("/announcements/club?search=" + value);
})

});

function updatePartiallyHidden() {
Expand Down
9 changes: 7 additions & 2 deletions intranet/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@
<div class="warning-announcement">{{ dash_warning|safe|linebreaks }}</div>
{% endif %}

<div class="announcements-header">
<div class="announcements-header" style="">

<h2>{{ dashboard_header }}</h2>
<span class="announcements-icon-wrapper" style="display: flex; flex-direction: row;">
{% if view_announcements_url == "club_announcements" %}
<form id="subscribed-announcement-search" style="display: flex; margin-right:1px">
<input id="subscribed-announcement-search-input" type="text" placeholder="Search Club Announcements" style="width: 15rem;" class="dashboard-textinput" onsubmit="" >
</form>
{% endif %}

<span class="announcements-icon-wrapper">
{% if show_expired or not show_widgets %}
<a href="{% url 'index' %}" class="button" style="float:left"><i class="fas fa-arrow-left" style="width: 11px"></i> Dashboard</a>
&nbsp;
Expand Down

0 comments on commit 5681005

Please sign in to comment.