From 37dd1a25cb6e6c447c6a1cab580831337d139b60 Mon Sep 17 00:00:00 2001 From: MattBild <34771705+mattbild@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:12:00 +0200 Subject: [PATCH 1/7] [DONE] fix filters on events (#916) * fix filters on events * flake8 changes needed * events : hide/ show aside filters * Js doc + aria-hidden sur icones * change html and css to match video cards * ajout submit bouton invisible sur fieldset * add JsDoc * translation and pydoc * css in dedicated file * edit pydoc * remove deprecated request.is_ajax() * edit pydoc --- pod/live/static/css/event.css | 6 +- pod/live/static/css/event_list.css | 4 + pod/live/static/js/filter_aside_event_list.js | 128 ++++++++++++++++++ pod/live/templates/live/direct.html | 16 +-- pod/live/templates/live/directs.html | 2 +- pod/live/templates/live/directs_all.html | 10 +- pod/live/templates/live/event-all-info.html | 2 +- pod/live/templates/live/event-info.html | 16 +-- pod/live/templates/live/event-script.html | 2 +- pod/live/templates/live/event.html | 18 +-- pod/live/templates/live/event_card.html | 4 +- pod/live/templates/live/event_delete.html | 2 +- pod/live/templates/live/event_edit.html | 6 +- .../templates/live/event_immediate_edit.html | 2 +- pod/live/templates/live/event_videos.html | 4 +- pod/live/templates/live/events.html | 11 +- pod/live/templates/live/events_list.html | 88 +++++++----- pod/live/templates/live/events_next.html | 4 +- pod/live/templates/live/filter_aside.html | 44 +++--- pod/live/templates/live/my_events.html | 10 +- pod/live/utils.py | 2 +- pod/live/views.py | 118 +++++++++++----- pod/video_encode_transcript/utils.py | 2 +- 23 files changed, 351 insertions(+), 150 deletions(-) create mode 100644 pod/live/static/css/event_list.css create mode 100644 pod/live/static/js/filter_aside_event_list.js diff --git a/pod/live/static/css/event.css b/pod/live/static/css/event.css index 331566be25..16bfe0589e 100644 --- a/pod/live/static/css/event.css +++ b/pod/live/static/css/event.css @@ -6,4 +6,8 @@ } .video-js .vjs-remaining-time { display: none; -} \ No newline at end of file +} + .filter-event-img { + max-height:32px; + max-width:32px; +} diff --git a/pod/live/static/css/event_list.css b/pod/live/static/css/event_list.css new file mode 100644 index 0000000000..d8b38cec81 --- /dev/null +++ b/pod/live/static/css/event_list.css @@ -0,0 +1,4 @@ +.event-card-container { + min-width: 12rem; + min-height: 11rem; +} diff --git a/pod/live/static/js/filter_aside_event_list.js b/pod/live/static/js/filter_aside_event_list.js new file mode 100644 index 0000000000..d49bec6f4c --- /dev/null +++ b/pod/live/static/js/filter_aside_event_list.js @@ -0,0 +1,128 @@ + + + let loader = document.querySelector(".lds-ring"); + let checkedInputs = []; + + /** + * Enable /disable all checkboxes. + * + * @param {boolean} value + */ + function disableCheckboxes(value) { + document + .querySelectorAll("input[type=checkbox]") + .forEach((checkbox) => { + checkbox.disabled = value; + }); + } + + /** + * Return url with filters params. + * + * @returns {string} + */ + function getUrlForRefresh() { + let newUrl = window.location.pathname + "?"; + + checkedInputs.forEach((input) => { + newUrl += input.name + "=" + input.value + "&"; + }); + + // Add page parameter + newUrl += "page=1"; + return newUrl; + } + + /** + * Remove loader height. + * + * @param height + * @returns {number} + */ + function getHeightMinusLoader(height) { + let loader_style = getComputedStyle(loader); + let loader_height = loader_style.height; + loader_height = loader_height.replace("px", ""); + return height - loader_height; + } + + /** + * Async request to refresh view with filtered events list. + */ + function refreshEvents() { + + // Erase list and enable loader + const events_content = document.getElementById("events_content"); + let width = events_content.offsetWidth; + let height = getHeightMinusLoader(events_content.offsetHeight); + + events_content.innerHTML = "
"; + loader.classList.add("show"); + + let url = getUrlForRefresh(); + + // Async GET request wth parameters by fetch method + fetch(url, { + method: "GET", + headers: { + "X-CSRFToken": "{{ csrf_token }}", + "X-Requested-With": "XMLHttpRequest" + }, + cache: "no-store" + }) + .then((response) => response.text()) + .then((data) => { + // parse data into html and replace videos list + let parser = new DOMParser(); + let html = parser.parseFromString(data, "text/html").body; + events_content.outerHTML = html.innerHTML; + + // change url with params sent + window.history.pushState({}, "", url); + }) + .catch(() => { + events_content.innerHTML = gettext("An Error occurred while processing."); + }) + .finally(() => { + // Re-enable inputs and dismiss loader + disableCheckboxes(false); + loader.classList.remove("show"); + }); + } + + /** + * Check or uncheck checkbox regarding url params. + * + * @param el + */ + function setCheckboxStatus(el) { + let currentUrl = window.location.href; + el.checked = currentUrl.includes("type="+ el.value + "&"); + } + + /** + * Add listener to refresh events list on checkbox status change. + * + * @param el + */ + function addCheckboxListener(el) { + el.addEventListener("change", () => { + checkedInputs = []; + disableCheckboxes(true); + document + .querySelectorAll("#collapseFilterType input[type=checkbox]:checked") + .forEach((e) => { + checkedInputs.push(e); + }); + refreshEvents(); + }); + } + + // On page load + document + .querySelectorAll("#collapseFilterType input[type=checkbox]") + .forEach((el) => { + setCheckboxStatus(el); + addCheckboxListener(el); + }); + diff --git a/pod/live/templates/live/direct.html b/pod/live/templates/live/direct.html index 6f7228f493..00775ef3f4 100644 --- a/pod/live/templates/live/direct.html +++ b/pod/live/templates/live/direct.html @@ -33,7 +33,7 @@{% if otherbroadcaster.status %} - + {{ otherbroadcaster.name }} {% else %} - + {{ otherbroadcaster.name }} ({% trans "no broadcast in progress" %}) {% endif %} @@ -146,7 +146,7 @@
- + {% trans "access map" %} diff --git a/pod/live/templates/live/directs.html b/pod/live/templates/live/directs.html index 177f0b4de8..fb30bdb0a6 100644 --- a/pod/live/templates/live/directs.html +++ b/pod/live/templates/live/directs.html @@ -15,7 +15,7 @@ {% block page_title %}{{building.name}}{% endblock %} {% block page_content %} -
- {% if broadcaster.status %} {{broadcaster.name}} - {% else %} {{broadcaster.name}} ({% trans "no broadcast in progress" %}){% endif %} + {% if broadcaster.status %} {{broadcaster.name}} + {% else %} {{broadcaster.name}} ({% trans "no broadcast in progress" %}){% endif %}
{% empty %}{% trans "Sorry, no lives found." %}
{% endfor %}
+
{% endif %}
diff --git a/pod/live/templates/live/event-all-info.html b/pod/live/templates/live/event-all-info.html
index 71f755b4e3..05d2d4a499 100644
--- a/pod/live/templates/live/event-all-info.html
+++ b/pod/live/templates/live/event-all-info.html
@@ -7,7 +7,7 @@
{% if event.description %}
{{ event.description|safe }} {% trans 'Summary' %}
+ {% trans 'Summary' %}
{% trans 'Type:' %}