From e615cc4d7c82d4776011e26777fcddf24f11a973 Mon Sep 17 00:00:00 2001
From: ABelliqueux
Date: Thu, 6 Oct 2022 20:08:04 +0200
Subject: [PATCH] timeline work
---
app.py | 4 +-
static/script.js | 289 +++++++++++++++++++++++++++++---------------
static/style.css | 44 ++++++-
templates/main.html | 24 +++-
4 files changed, 259 insertions(+), 102 deletions(-)
diff --git a/app.py b/app.py
index b09d0d0..74f4eca 100755
--- a/app.py
+++ b/app.py
@@ -213,7 +213,9 @@ def sendCommand(host, arg0, arg1, arg2):
m3u_content += m3u_prefix + item.get("duration") + ", " + item.get("name") + "\n" + item.get("uri") + "\n"
playlist_duration += int(item.get("duration"))
# ~ item_info = item.get("id") + " : " + item.get("name") + " - " + sec2min( int( item.get("duration") ) )
- item_info = item.get("id") + ";" + item.get("name") + ";" + sec2min( int( item.get("duration") ) )
+ item_info = item.get("id") + ";" + item.get("name") + ";" + sec2min( int( item.get("duration") ) ) + ";"
+ if "current" in item.keys():
+ item_info += item.get("current")
item_list.append(item_info)
playlist_overview = {
diff --git a/static/script.js b/static/script.js
index d321067..4b84966 100644
--- a/static/script.js
+++ b/static/script.js
@@ -1,9 +1,106 @@
+// Timeline drag and drop
+const tl_cont_attr = {id:"tl_cont", ondrop: "drop(event, this)", ondragover:"allowDrop(event)"};
+const tl_drag_attr = {id:"tl_drag", draggable:"true", ondragstart:"drag(event, this)"};
+
+var src_id = "";
+
+function updatePlaylist(){
+ var new_list = [];
+ var media_count = document.getElementById("timeline").children.length;
+ for (i=media_count,l=0;i>l;i--) {
+ //~ new_list.push(document.getElementById("timeline").children[i].children[0].getAttribute("media_id"));
+ toMove = document.getElementById("timeline").children[i-1].children[0].getAttribute("media_id");
+ console.log(toMove);
+ sendCmd("/all/move/" + toMove + "/1");
+ }
+}
+
+function findTargetIndex(element, index, array, thisArg){
+ if (element == this) {
+ return index+1;
+ }
+ return 0;
+};
+
+function moveElements(target) {
+ var elem_list = Array.from(src_id.parentElement.children);
+ var elem_list_slice = elem_list;
+ var source_idx = elem_list.findIndex(findTargetIndex, src_id);
+ var target_idx = elem_list.findIndex(findTargetIndex, target);
+ var idx;
+ if (source_idx < target_idx) {
+ elem_list_slice = elem_list.slice(source_idx+1, target_idx+1);
+ idx = source_idx;
+ } else {
+ elem_list_slice = elem_list.slice(target_idx, source_idx );
+ idx = target_idx+1;
+ }
+ for (i=0, l=elem_list_slice.length; i -1 ) {
- const test_array = [5,6,7,8];
+ const test_array = [21,19,20];
for (i=test_array.length, l=0;i>l;i--){
console.log(test_array[i-1]);
sendCmd("/all/move/" + test_array[i-1] + "/1");
-
};
+ sendCmd("/all/list");
//setInterval( sendCmd, scanInterval, "/all/move/16/1");
};
// On envoie la commande en AJAX
var request = new XMLHttpRequest();
if ( command == "/scan" ) {
- request.onload = refreshInfos(command);
+ request.onload = sendCmd(command);
}
// On construit la commande
request.open("GET", command, true);
@@ -52,98 +149,99 @@ addEventListener("DOMContentLoaded", function() {
// Affichage des infos
function parseResult(command, infos_array) {
- //~ var request = new XMLHttpRequest();
- //~ request.onload = function() {
- //~ if (request.readyState === request.DONE) {
- //~ if (request.status === 200) {
- //~ // responseText is a string, use parse to get an array.
- //~ const infos_array = JSON.parse(request.responseText);
- switch (command) {
- case "/all/status":
- // Iterate over array
- for (var i = 0, l=infos_array.length; i" +
- "Id | " +
- "Filename | " +
- "Duration | " +
- "";
- for (var j = 0, k=items_array.length; j" +
- "" + item_meta[0] + " | " +
- "" + item_meta[1] + " | " +
- "" + item_meta[2] + " | " +
- "" ;
- }
- html_table += "";
- document.getElementById("playlist_"+infos_array[i].host).innerHTML += html_table;
- };
- break;
- case "/scan":
- var host_up = infos_array[0];
- var host_down = infos_array[1];
- for ( var i=0, l=host_up.length; i" +
- "Filename | " +
- "Duration | " +
- "";
- for (var j = 0, k=infos_array.length; j" +
- "" + infos_array[j] + " | " +
- "" + "00:00" + " | " +
- "" ;
- }
- html_table += "";
- document.getElementById("filelist").innerHTML += html_table;
- break;
- case "/all/rssi":
- var signal_color = 40;
- var best_rssi = 30;
- var worst_rssi = 70;
- for (var j = 0, k=infos_array.length; j" +
+ "Id | " +
+ "Filename | " +
+ "Duration | " +
+ "";
+ for (var j = 0, k=items_array.length; j" +
+ "" + item_meta[0] + " | " +
+ "" + item_meta[1] + " | " +
+ "" + item_meta[2] + " | " +
+ "" ;
+ // Timeline
+ var child_node = addElement("div", tl_drag_attr, item_meta, j);
+ var len = document.getElementById("timeline").children.length;
+ if ( len < items_array.length ) {
+ document.getElementById("timeline").appendChild( addElement("div", tl_cont_attr, [], len) );
+ }
+ document.getElementById(tl_cont_attr.id + j).replaceChildren(child_node);
+ if (item_meta[3] != ""){
+ document.getElementById(tl_cont_attr.id + j).children[0].style.borderBottom = "4px solid #ff8300";
+ }
+ }
+ html_table += "";
+ document.getElementById("playlist_"+infos_array[i].host).innerHTML += html_table;
+ };
+ break;
+ case "/scan":
+ var host_up = infos_array[0];
+ var host_down = infos_array[1];
+ for ( var i=0, l=host_up.length; i" +
+ "Filename | " +
+ "Duration | " +
+ "";
+ for (var j = 0, k=infos_array.length; j" +
+ "" + infos_array[j] + " | " +
+ "" + "00:00" + " | " +
+ "" ;
+ }
+ html_table += "";
+ document.getElementById("filelist").innerHTML += html_table;
+ break;
+ case "/all/rssi":
+ var signal_color = 40;
+ var best_rssi = 30;
+ var worst_rssi = 70;
+ for (var j = 0, k=infos_array.length; jXVider
listes
-
+
@@ -55,8 +55,24 @@
-
-
+
+
+
+
+
@@ -66,7 +82,7 @@
-
+
{% endfor %}