Skip to content

Commit

Permalink
feat: add show all option to club announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Oct 2, 2024
1 parent 66cf9ff commit 89a0435
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 80 deletions.
20 changes: 11 additions & 9 deletions intranet/apps/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -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,
}
)

Expand Down Expand Up @@ -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 = []
Expand Down
4 changes: 3 additions & 1 deletion intranet/static/js/dashboard/announcements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -182,4 +184,4 @@ function filterClubAnnouncements() {
});
}
updatePartiallyHidden();
}
}
141 changes: 71 additions & 70 deletions intranet/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ <h2>{{ dashboard_header }}</h2>
Request Post
</a>
{% else %}
{% if view_announcements_url != "club_announcements" %}
<a class="button club-announcements-button" href="{% url 'club_announcements' %}{% if "show_all" in request.GET %}?show_all=1{% endif %}">
<i class="fas fa-users"></i>
Club Announcements
</a>
{% endif %}
{% if announcements_admin %}
{% if view_announcements_url == "club_announcements" %}
<a class="button announcement-request" href="{% url 'add_club_announcement' %}">
<i class="fas fa-plus"></i>
Post
{% if view_announcements_url != "club_announcements" %}
<a class="button club-announcements-button" href="{% url 'club_announcements' %}{% if "show_all" in request.GET %}?show_all=1{% endif %}">
<i class="fas fa-users"></i>
Club Announcements
</a>
{% else %}
{% endif %}
{% if announcements_admin %}
{% if view_announcements_url == "club_announcements" %}
<a class="button announcement-request" href="{% url 'add_club_announcement' %}">
<i class="fas fa-plus"></i>
Post
</a>
{% endif %}
{% if request.GET.show_all is not None and request.GET.show_all != "0" %}
<a class="button" href="{% url view_announcements_url %}">
<i class="fas fa-times"></i> Don't Show All
Expand All @@ -139,28 +139,28 @@ <h2>{{ dashboard_header }}</h2>
Show All
</a>
{% endif %}
<a class="button announcement-add" href="{% url 'add_announcement' %}">
<i class="fas fa-plus"></i>
Add
</a>
{% endif %}
{% else %}
{% if view_announcements_url != "club_announcements" %}
<a class="button announcement-add" href="{% url 'add_announcement' %}">
<i class="fas fa-plus"></i>
Add
</a>
{% endif %}
{% else %}
{% if view_announcements_url == "club_announcements" %}
{% if request.user.is_club_officer or request.user.is_club_sponsor %}
<a class="button announcement-request" href="{% url 'add_club_announcement' %}">
<i class="fas fa-plus"></i>
Post
</a>
{% endif %}
{% else %}
<a class="button announcement-request" href="{% url 'request_announcement' %}">
<i class="far fa-file-alt"></i>
Request Post
</a>
{% endif %}

{% if view_announcements_url == "club_announcements" %}
{% if request.user.is_club_officer or request.user.is_club_sponsor %}
<a class="button announcement-request" href="{% url 'add_club_announcement' %}">
<i class="fas fa-plus"></i>
Post
</a>
{% endif %}
{% else %}
<a class="button announcement-request" href="{% url 'request_announcement' %}">
<i class="far fa-file-alt"></i>
Request Post
</a>
{% endif %}

{% endif %}
{% endif %}
</span>
</div>
Expand Down Expand Up @@ -264,46 +264,47 @@ <h3 class="club-announcements-header">
</div>
{% endfor %}
{% if not request.user.is_restricted %}

{% if page_num == 1 and view_announcements_url != "announcements_archive" and view_announcements_url != "club_announcements" %}
<a href="{% url 'announcements_archive' %}" class="button" style="float:left"><i class="fas fa-archive" style="width: 13px"></i> View Archive</a>
{% endif %}
{% if page_obj.num_pages > 1 %}
<div style="display:grid;grid-template-columns:1fr max-content 1fr">
<div style="text-align:center;grid-column-start:2">
<a {% if prev_page > 0 %}
href="{% url view_announcements_url %}?{% query_transform request page=prev_page %}"
{% else %}
disabled
{% endif %}
class="button"
>&lt;</a>

{% for page in page_obj|page_list:items %}
<a {% if page %} class="button" {% else %} class="ellipses" {% endif %}
{% if page == items.number %} style="background-image: linear-gradient(to bottom, #858585 0%, #5f5f5f 100%); color: white;" {% endif %}
href="{% url view_announcements_url %}{% if page %}?{% query_transform request page=page %}{% else %}#{% endif %}">{{ page|default:"..." }}</a>
{% endfor %}

<a {% if more_items %}
href="{% url view_announcements_url %}?{% query_transform request page=next_page %}"
{% else %}
disabled
{% endif %}
class="button"
>&gt;</a>
</div>
<div style="text-align:right">
<form action="{% url view_announcements_url %}" method="get" style="display:inline;float:right">
<input name="page" type="number"
min="1" max={{ page_obj.num_pages }} class="dashboard-textinput" style="width: 75px"
placeholder={{ items.number }}> of {{ page_obj.num_pages }}
<input type="submit" value="Go"/>
</form>
</div>
<div id="subscriptions-pagination">
{% if page_num == 1 and view_announcements_url != "announcements_archive" and view_announcements_url != "club_announcements" %}
<a href="{% url 'announcements_archive' %}" class="button" style="float:left"><i class="fas fa-archive" style="width: 13px"></i> View Archive</a>
{% endif %}
{% if page_obj.num_pages > 1 %}
<div style="display:grid;grid-template-columns:1fr max-content 1fr">
<div style="text-align:center;grid-column-start:2">
<a {% if prev_page > 0 %}
href="{% url view_announcements_url %}?{% query_transform request page=prev_page %}"
{% else %}
disabled
{% endif %}
class="button"
>&lt;</a>

{% for page in page_obj|page_list:items %}
<a {% if page %} class="button" {% else %} class="ellipses" {% endif %}
{% if page == items.number %} style="background-image: linear-gradient(to bottom, #858585 0%, #5f5f5f 100%); color: white;" {% endif %}
href="{% url view_announcements_url %}{% if page %}?{% query_transform request page=page %}{% else %}#{% endif %}">{{ page|default:"..." }}</a>
{% endfor %}

<a {% if more_items %}
href="{% url view_announcements_url %}?{% query_transform request page=next_page %}"
{% else %}
disabled
{% endif %}
class="button"
>&gt;</a>
</div>
<div style="text-align:right">
<form action="{% url view_announcements_url %}" method="get" style="display:inline;float:right">
<input name="page" type="number"
min="1" max={{ page_obj.num_pages }} class="dashboard-textinput" style="width: 75px"
placeholder={{ items.number }}> of {{ page_obj.num_pages }}
<input type="submit" value="Go"/>
</form>
</div>
</div>
{% endif %}
</div>
{% endif %}
{% endif %}
</div>
</div>

Expand Down

0 comments on commit 89a0435

Please sign in to comment.