From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 17 Feb 2025 01:42:50 +0000 (+0100)
Subject: Add "inject all" button to /files view.
X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/blog?a=commitdiff_plain;h=de900c8b88894409976e08aee26d4209f6d59957;p=ytplom
Add "inject all" button to /files view.
---
diff --git a/src/templates/_base.tmpl b/src/templates/_base.tmpl
index cad70fa..62443c8 100644
--- a/src/templates/_base.tmpl
+++ b/src/templates/_base.tmpl
@@ -53,17 +53,12 @@ async function wrapped_fetch(target, fetch_kwargs=null, verbose=false) {
}
}
-async function post_to(data, target, verbose=false) {
- const fetch_kwargs = {
+function player_command(command) {
+ wrapped_fetch(PATH_PLAYER, {
method: "POST",
headers: {"Content-Type": "application/json"},
- body: JSON.stringify(data)
- };
- wrapped_fetch(target, fetch_kwargs, verbose);
-}
-
-function player_command(command) {
- post_to({command: [command]}, PATH_PLAYER);
+ body: JSON.stringify({command: [command]})
+ });
}
event_handlers.push(function(data) { // update player state
diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl
index d78805b..cd7dcf1 100644
--- a/src/templates/files.tmpl
+++ b/src/templates/files.tmpl
@@ -7,6 +7,7 @@ const PATH_FILES_JSON = "/{{page_names.files_json}}";
const all_tags = {{showable_tags|tojson|safe}};
var needed_tags = [];
+var filtered_files = [];
function select_tag() {
if (tags_select.selectedIndex < 1) {
@@ -50,11 +51,11 @@ async function update_files_list() {
let target = `${PATH_FILES_JSON}?filter_path=${filter_path}`;
if (document.getElementById("input_show_absent").checked) { target = `${target}&show_absent=1`; }
needed_tags.forEach((tag) => target = `${target}&needed_tag=${encodeURIComponent(tag)}`);
- const files_data = await wrapped_fetch(target).then((response) => response.json());
- document.getElementById("files_count").textContent = `${files_data.length}`;
+ filtered_files = await wrapped_fetch(target).then((response) => response.json());
+ document.getElementById("files_count").textContent = `${filtered_files.length}`;
const table = document.getElementById("files_table");
Array.from(document.getElementsByClassName("file_row")).forEach((row) => row.remove());
- files_data.forEach((file) => {
+ filtered_files.forEach((file) => {
const tr = new_child_to('tr', table);
tr.classList.add("file_row");
new_child_to('td', tr, file.size);
@@ -70,6 +71,10 @@ async function update_files_list() {
});
}
+function inject_all() {
+ filtered_files.forEach((file) => { player_command(`inject_${file.digest}`) });
+}
+
window.addEventListener('load', update_filter_inputs);
{% endblock %}
@@ -78,9 +83,12 @@ window.addEventListener('load', update_filter_inputs);
filename pattern: <input id="input_filter_path" oninput="update_files_list()" /><br />
show absent: <input id="input_show_absent" type="checkbox" onclick="update_files_list()" /><br />
needed tags: <select id="tags_select" onchange="select_tag()"></select><br />
-<span id="tags"></span><br />
+<span id="tags"></span>
<hr />
-<p>known files (shown: <span id="files_count">?</span>):</p>
+<p>
+known files (shown: <span id="files_count">?</span>):
+<button onclick="inject_all();">inject all</button>
+</p>
<table id="files_table">
<tr><th>size</th><th>actions</th><th>tags</th><th>path</th></tr>
</table>