From 89a0435a198d7fc9ca3a2b833526193fa951f951 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Wed, 2 Oct 2024 16:30:23 -0400 Subject: [PATCH] feat: add show all option to club announcements --- intranet/apps/dashboard/views.py | 20 +-- intranet/static/js/dashboard/announcements.js | 4 +- intranet/templates/dashboard/dashboard.html | 141 +++++++++--------- 3 files changed, 85 insertions(+), 80 deletions(-) diff --git a/intranet/apps/dashboard/views.py b/intranet/apps/dashboard/views.py index c1faae131e5..75491698171 100644 --- a/intranet/apps/dashboard/views.py +++ b/intranet/apps/dashboard/views.py @@ -231,7 +231,7 @@ def get_announcements_list(request, context): # Show all announcements if user has admin permissions and the # show_all GET argument is given. announcements = Announcement.objects.all() - elif context["show_expired"]: + elif context["show_expired"] or context["show_all"]: announcements = Announcement.objects.visible_to_user(user) else: announcements = Announcement.objects.visible_to_user(user).filter(expiration_date__gt=timezone.now()) @@ -293,7 +293,7 @@ def filter_club_announcements(user, user_hidden_announcements, club_items): return visible, hidden, unsubscribed -def paginate_announcements_list(request, context, items, visible_club_items, more_club_items): +def paginate_announcements_list(request, context, items, visible_club_items): """ Paginate ``items`` in groups of 15 @@ -315,14 +315,16 @@ def paginate_announcements_list(request, context, items, visible_club_items, mor prev_page = items.previous_page_number() if items.has_previous() else 0 next_page = items.next_page_number() if more_items else 0 - context.update( - {"items": items, "page_num": page_num, "prev_page": prev_page, "next_page": next_page, "more_items": more_items, "page_obj": paginator} - ) club_items = visible_club_items[:15] - context.update( { "club_items": club_items, + "items": items, + "page_num": page_num, + "prev_page": prev_page, + "next_page": next_page, + "more_items": more_items, + "page_obj": paginator, } ) @@ -495,11 +497,11 @@ def dashboard_view(request, show_widgets=True, show_expired=False, show_hidden_c if not show_hidden_club: # Dashboard - visible_club_items, hidden_club_items, other_club_items = filter_club_announcements(user, user_hidden_announcements, club_items) - context, items = paginate_announcements_list(request, context, items, visible_club_items, hidden_club_items or other_club_items) + visible_club_items, _hidden_club_items, _other_club_items = filter_club_announcements(user, user_hidden_announcements, club_items) + context, items = paginate_announcements_list(request, context, items, visible_club_items) else: # Club announcements only - context, items = paginate_announcements_list(request, context, club_items, [], []) + context, items = paginate_announcements_list(request, context, club_items, visible_club_items=[]) if ignore_dashboard_types is None: ignore_dashboard_types = [] diff --git a/intranet/static/js/dashboard/announcements.js b/intranet/static/js/dashboard/announcements.js index 9b5e8b7a438..98a10c34f4b 100644 --- a/intranet/static/js/dashboard/announcements.js +++ b/intranet/static/js/dashboard/announcements.js @@ -44,12 +44,14 @@ $(document).ready(function() { $(".subscribed-filter").click(function () { $(".unsubscribed-filter").removeClass("active"); + $("#subscriptions-pagination").css("display", ""); $(this).addClass("active"); filterClubAnnouncements(); }); $(".unsubscribed-filter").click(function () { $(".subscribed-filter").removeClass("active"); + $("#subscriptions-pagination").css("display", "none"); $(this).addClass("active"); filterClubAnnouncements(); }); @@ -182,4 +184,4 @@ function filterClubAnnouncements() { }); } updatePartiallyHidden(); -} \ No newline at end of file +} diff --git a/intranet/templates/dashboard/dashboard.html b/intranet/templates/dashboard/dashboard.html index 66d9928068b..7c05ffd4255 100644 --- a/intranet/templates/dashboard/dashboard.html +++ b/intranet/templates/dashboard/dashboard.html @@ -117,19 +117,19 @@

{{ dashboard_header }}

Request Post {% else %} - {% if view_announcements_url != "club_announcements" %} - - - Club Announcements - - {% endif %} - {% if announcements_admin %} - {% if view_announcements_url == "club_announcements" %} - - - Post + {% if view_announcements_url != "club_announcements" %} + + + Club Announcements - {% else %} + {% endif %} + {% if announcements_admin %} + {% if view_announcements_url == "club_announcements" %} + + + Post + + {% endif %} {% if request.GET.show_all is not None and request.GET.show_all != "0" %} Don't Show All @@ -139,28 +139,28 @@

{{ dashboard_header }}

Show All
{% endif %} - - - Add - - {% endif %} - {% else %} + {% if view_announcements_url != "club_announcements" %} + + + Add + + {% endif %} + {% else %} + {% if view_announcements_url == "club_announcements" %} + {% if request.user.is_club_officer or request.user.is_club_sponsor %} + + + Post + + {% endif %} + {% else %} + + + Request Post + + {% endif %} - {% if view_announcements_url == "club_announcements" %} - {% if request.user.is_club_officer or request.user.is_club_sponsor %} - - - Post - {% endif %} - {% else %} - - - Request Post - - {% endif %} - - {% endif %} {% endif %} @@ -264,46 +264,47 @@

{% endfor %} {% if not request.user.is_restricted %} - - {% if page_num == 1 and view_announcements_url != "announcements_archive" and view_announcements_url != "club_announcements" %} - View Archive - {% endif %} - {% if page_obj.num_pages > 1 %} -
-
- 0 %} - href="{% url view_announcements_url %}?{% query_transform request page=prev_page %}" - {% else %} - disabled - {% endif %} - class="button" - >< - - {% for page in page_obj|page_list:items %} - {{ page|default:"..." }} - {% endfor %} - - > -
-
-
- of {{ page_obj.num_pages }} - -
-
+
+ {% if page_num == 1 and view_announcements_url != "announcements_archive" and view_announcements_url != "club_announcements" %} + View Archive + {% endif %} + {% if page_obj.num_pages > 1 %} +
+ +
+
+ of {{ page_obj.num_pages }} + +
+
+
+ {% endif %}
{% endif %} - {% endif %}