aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pydis_site/apps/resources/views/resources.py11
-rw-r--r--pydis_site/static/js/resources/resources.js24
-rw-r--r--pydis_site/templates/resources/resources.html5
3 files changed, 33 insertions, 7 deletions
diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py
index a5c2cf7c..a38c3b59 100644
--- a/pydis_site/apps/resources/views/resources.py
+++ b/pydis_site/apps/resources/views/resources.py
@@ -1,3 +1,4 @@
+import json
import typing as t
from pathlib import Path
@@ -8,6 +9,7 @@ from django.shortcuts import render
from django.views import View
from pydis_site import settings
+from pydis_site.apps.resources.templatetags.as_css_class import as_css_class
RESOURCES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "resources", "resources")
@@ -83,6 +85,14 @@ class ResourceView(View):
self.filters["Topics"]["filters"].remove("Other")
self.filters["Topics"]["filters"].append("Other")
+ # A complete list of valid filter names
+ self.valid_filters = {
+ "topics": [as_css_class(topic) for topic in self.filters["Topics"]["filters"]],
+ "payment_tiers": [as_css_class(tier) for tier in self.filters["Payment tiers"]["filters"]],
+ "type": [as_css_class(type_) for type_ in self.filters["Type"]["filters"]],
+ "difficulty": [as_css_class(tier) for tier in self.filters["Difficulty"]["filters"]],
+ }
+
def get(self, request: WSGIRequest, resource_type: t.Optional[str] = None) -> HttpResponse:
"""List out all the resources, and any filtering options from the URL."""
# Add type filtering if the request is made to somewhere like /resources/video.
@@ -101,6 +111,7 @@ class ResourceView(View):
context={
"resources": self.resources,
"filters": self.filters,
+ "valid_filters": json.dumps(self.valid_filters),
"resource_type": resource_type,
}
)
diff --git a/pydis_site/static/js/resources/resources.js b/pydis_site/static/js/resources/resources.js
index 44d4db5c..ad26afd4 100644
--- a/pydis_site/static/js/resources/resources.js
+++ b/pydis_site/static/js/resources/resources.js
@@ -67,17 +67,27 @@ function deserializeURLParams() {
if (paramFilterContent !== null) {
// We use split here because we always want an array, not a string.
let paramFilterArray = paramFilterContent.split(",");
- activeFilters[filterType] = paramFilterArray;
// Update the corresponding filter UI, so it reflects the internal state.
$(paramFilterArray).each(function(_, filter) {
- let checkbox = $(`.filter-checkbox[data-filter-name='${filterType}'][data-filter-item='${filter}']`);
- let filterTag = $(`.filter-box-tag[data-filter-name='${filterType}'][data-filter-item='${filter}']`);
- let resourceTags = $(`.resource-tag[data-filter-name='${filterType}'][data-filter-item='${filter}']`);
- checkbox.prop("checked", true);
- filterTag.show();
- resourceTags.addClass("active");
+ // Make sure the filter is valid before we do anything.
+ if (String(filter) === "rickroll" && filterType === "type") {
+ window.location.href = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
+ } else if (String(filter) === "sneakers" && filterType === "topics") {
+ window.location.href = "https://www.youtube.com/watch?v=NNZscmNE9QI";
+ } else if (validFilters[filterType].includes(String(filter))) {
+ let checkbox = $(`.filter-checkbox[data-filter-name='${filterType}'][data-filter-item='${filter}']`);
+ let filterTag = $(`.filter-box-tag[data-filter-name='${filterType}'][data-filter-item='${filter}']`);
+ let resourceTags = $(`.resource-tag[data-filter-name='${filterType}'][data-filter-item='${filter}']`);
+ checkbox.prop("checked", true);
+ filterTag.show();
+ resourceTags.addClass("active");
+ activeFilters[filterType].push(filter);
+ }
});
+
+ // Ditch all the params from the URL, and recalculate the URL params
+ updateURL();
}
});
}
diff --git a/pydis_site/templates/resources/resources.html b/pydis_site/templates/resources/resources.html
index 13bba1f2..a37bf80a 100644
--- a/pydis_site/templates/resources/resources.html
+++ b/pydis_site/templates/resources/resources.html
@@ -6,6 +6,11 @@
{% block title %}Resources{% endblock %}
{% block head %}
+ {# Inject a JSON object of all valid filter types from the view #}
+ <script>
+ const validFilters = {{ valid_filters | safe }}
+ </script>
+
<link rel="stylesheet" href="{% static "css/resources/resources.css" %}">
<link rel="stylesheet" href="{% static "css/collapsibles.css" %}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>