From: Christian Heller Date: Mon, 17 Feb 2025 04:45:59 +0000 (+0100) Subject: Link tags everywhere to tag-filtered files listing. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/todo?a=commitdiff_plain;p=ytplom Link tags everywhere to tag-filtered files listing. --- diff --git a/src/templates/_base.tmpl b/src/templates/_base.tmpl index 62443c8..e90f9f8 100644 --- a/src/templates/_base.tmpl +++ b/src/templates/_base.tmpl @@ -61,16 +61,29 @@ function player_command(command) { }); } +function father_tag_links(parent_element, tags) { + tags.forEach((tag) => { + const a_tag = new_child_to('a', parent_element, tag); + a_tag.href = `?needed_tag=${encodeURIComponent(tag)}`; + parent_element.appendChild(document.createTextNode(' ')); + }); +} + event_handlers.push(function(data) { // update player state for (const [id, text] of [ - ["playing_tags", data.title_tags ? `(tags: ${data.title_tags})` : ""], ["a_playing", data.title], ["player_state", data.is_running ? (data.is_playing ? "playing:" : "paused:") : "stopped" + (data.title ? ':' : '')], ["btn_play", data.is_playing ? "pause" : "play"]]) { - document.getElementById(id).textContent = text; } + document.getElementById(id).textContent = text; + } + const span_tags = document.getElementById("playing_tags"); + span_tags.innerHTML = ""; + father_tag_links(span_tags, data.title_tags); for (const btn of document.getElementsByClassName("btn_if_can_play")) { - btn.disabled = !data.can_play; } - document.getElementById("a_playing").href = data.title_digest ? `${PATH_PREFIX_FILE}${data.title_digest}` : PATH_PLAYLIST ; }) + btn.disabled = !data.can_play; + } + document.getElementById("a_playing").href = data.title_digest ? `${PATH_PREFIX_FILE}${data.title_digest}` : PATH_PLAYLIST ; +}) {% block script %} {% endblock %} diff --git a/src/templates/file_data.tmpl b/src/templates/file_data.tmpl index 634f41a..a2eea56 100644 --- a/src/templates/file_data.tmpl +++ b/src/templates/file_data.tmpl @@ -50,7 +50,7 @@ no {% for tag in file.tags_showable %} -{{tag}} +{{tag}} {% endfor %} {% if allow_edit %} diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl index cd7dcf1..88bc7a7 100644 --- a/src/templates/files.tmpl +++ b/src/templates/files.tmpl @@ -6,7 +6,7 @@ const PATH_FILES_JSON = "/{{page_names.files_json}}"; const all_tags = {{showable_tags|tojson|safe}}; -var needed_tags = []; +var needed_tags = {{needed_tags|tojson|safe}}; var filtered_files = []; function select_tag() { @@ -64,7 +64,7 @@ async function update_files_list() { btn_inject.onclick = function() { player_command(`inject_${file.digest}`) }; btn_inject.disabled = !file.present; btn_inject.textContent = 'inject'; - new_child_to('td', tr, file.tags_showable.join(", ")); + father_tag_links(new_child_to('td', tr), file.tags_showable); const td_link = new_child_to('td', tr); const a = new_child_to('a', td_link, file.rel_path); a.href = `${PATH_PREFIX_FILE}${file.digest}`; diff --git a/src/ytplom/http.py b/src/ytplom/http.py index e1d893a..59da51c 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -256,11 +256,11 @@ class _TaskHandler(PlomHttpHandler): conn, self.server.player.current_digest) if last_sent < self.server.player.last_update: last_sent = self.server.player.last_update - title, tags, digest = '', '', '' + title, digest, tags = '', '', [] if selected: - tags = selected.tags_showable.joined title = str(selected.rel_path) digest = selected.digest.b64 + tags = selected.tags_showable.as_str_list payload['is_running'] = self.server.player.is_running payload['is_playing'] = self.server.player.is_playing payload['can_play'] = self.server.player.can_play @@ -291,8 +291,9 @@ class _TaskHandler(PlomHttpHandler): def _send_files_index(self) -> None: with DbConn() as conn: showable_tags = sorted(list(VideoFile.all_tags_showable(conn))) - self._send_rendered_template(_NAME_TEMPLATE_FILES, - {'showable_tags': showable_tags}) + self._send_rendered_template(_NAME_TEMPLATE_FILES, { + 'showable_tags': showable_tags, + 'needed_tags': self.params.all_for('needed_tag')}) def _send_files_json(self) -> None: with DbConn() as conn: