]> git.mdlowis.com Git - proto/atv.git/commitdiff
small cleanup
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 18 Mar 2024 02:41:36 +0000 (22:41 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 18 Mar 2024 02:41:36 +0000 (22:41 -0400)
atv/assets/admin.html
atv/assets/control.html
atv/assets/index.html
atv/assets/style.css
atv/assets/ui.js [new file with mode: 0644]
atv/bin/atv
atv/lib/atv/database.rb

index a27b3da2e1e96020f48ae7d4bf5621b4f4d40301..8036324cfc3910bcfcb22d421e0445897950999f 100644 (file)
 </article>
 
 <script type="text/javascript" src="client.js"></script>
+<script type="text/javascript" src="ui.js"></script>
 
 <script>
-const UI = (()=>{
-    const self = {};
-
-    let queue = [];
-    let items = {};
-    let path = [];
-
-    const showBrowser = ()=>{
-        path = [];
-        browseView.style.display = "flex";
-        mainView.style.display = "none";
-    };
-
-    const showMain = ()=>{
-        path = [];
-        browseView.style.display = "none";
-        mainView.style.display = "flex";
-    };
-
-    // Button handlers
-    self.play_pause  = ()=>{ Client.play_pause(); };
-    self.chan_next   = ()=>{ Client.chan_next(); };
-    self.chan_prev   = ()=>{ Client.chan_prev(); };
-    self.skip        = ()=>{ Client.skip(); };
-    self.select_file = ()=>{ showBrowser(); };
-    self.cancel      = ()=>{ showMain(); };
-
-    self.enqueue = (path)=>{
-        console.log(path);
-        Client.send("enqueue", { path: path });
-        showMain();
-    };
-
-    self.set_items = (new_items)=>{
-        items = new_items;
-        refreshItems();
-    };
-
-    self.set_queue = (new_queue)=>{
-        queue = new_queue;
-        refreshQueue();
-    };
-
-    self.set_play_state = (up_now, up_next, playing)=>{
-        currVid.innerText = up_now;
-        nextVid.innerText = up_next;
-        playBtn.value = (playing ? "Pause" : "Play");
-    };
-
-    self.browse_up = ()=>{
-        path.pop();
-        refreshItems();
-    };
-
-
-
-    const refreshQueue = ()=>{
-        if (queue.length > 0) {
-            queueList.innerHTML = "";
-            for (const item of queue) {
-                const el = document.createElement("div");
-                el.innerText = item.path;
-                queueList.appendChild(el);
-            }
-        } else {
-            queueList.innerHTML = "The queue is currently empty";
-        }
-    };
-
-    const getLocalRoot = ()=>{
-        let root = items;
-        for (const dir of path) {
-            root = root[dir];
-        }
-        return root;
-    };
-
-    const linkDown = (dir)=>{
-        path.push(dir);
-        refreshItems();
-    };
-
-    const refreshItems = ()=>{
-        const dir = getLocalRoot();
-        currDir.innerText = (path[path.length - 1] || "Root");
-
-        itemList.innerText = "";
-        for (const item in dir) {
-            const el = document.createElement("div");
-            const link = document.createElement("a");
-            link.innerText = item;
-            link.href = '#';
-            if ('path' in dir[item]) {
-                link.onclick = ()=>{ self.enqueue(dir[item].path); };
-            } else {
-                link.onclick = ()=>{ linkDown(item); };
-            }
-            el.appendChild(link);
-            itemList.appendChild(el);
-        }
-    };
-
-    return self;
-})();
-
-
 (()=>{
-    let items = {}
-    let path = [];
-
     Client.connect((data)=>{
         console.log(data);
         if (cmd.cmd === "items")
@@ -189,50 +81,6 @@ const UI = (()=>{
             );
         }
     });
-
-
-
-
-//    const getLocalRoot = ()=>{
-//        let root = items;
-//        for (const dir of path) {
-//            root = root[dir];
-//        }
-//        return root;
-//    };
-//
-//    const linkDown = (dir)=>{
-//        path.push(dir);
-//        showItems();
-//    };
-//
-//    const linkUp = ()=>{
-//        path.slice(-1);
-//        showItems();
-//    };
-//
-//    const showItem = (item, isFile, fileData) => {
-//        const el = document.createElement("div");
-//        const link = document.createElement("a");
-//        link.innerText = item;
-//        link.href = '#';
-//        if (!isFile) {
-//            link.onclick = ()=>{ linkDown(item); };
-//        } else {
-//            link.onclick = ()=>{ Client.enqueue(fileData.path); };
-//        }
-//        el.appendChild(link);
-//        itemList.appendChild(el);
-//    }
-//
-//    const showItems = ()=>{
-//        const dir = getLocalRoot();
-//        itemList.innerText = "";
-//        for (const item in dir) {
-//            showItem(item, ('path' in dir[item]), dir[item]);
-//        }
-//    };
-
 })();
 
 
index d1c0cbec68b345ae6e246c56d0c62c178625148c..72c103cb238f4c83ae0b46ec0c5d01c40dcf7e5b 100644 (file)
 </article>
 
 <script type="text/javascript" src="client.js"></script>
+<script type="text/javascript" src="ui.js"></script>
 
 <script>
-const UI = (()=>{
-    const self = {};
-
-    let queue = [];
-    let items = {};
-    let path = [];
-
-    const showBrowser = ()=>{
-        path = [];
-        browseView.style.display = "flex";
-        mainView.style.display = "none";
-    };
-
-    const showMain = ()=>{
-        path = [];
-        browseView.style.display = "none";
-        mainView.style.display = "flex";
-    };
-
-    // Button handlers
-    self.play_pause  = ()=>{ Client.play_pause(); };
-    self.chan_next   = ()=>{ Client.chan_next(); };
-    self.chan_prev   = ()=>{ Client.chan_prev(); };
-    self.select_file = ()=>{ showBrowser(); };
-    self.cancel      = ()=>{ showMain(); };
-
-    self.enqueue = (path)=>{
-        console.log(path);
-        Client.send("enqueue", { path: path });
-        showMain();
-    };
-
-    self.set_items = (new_items)=>{
-        items = new_items;
-        refreshItems();
-    };
-
-    self.set_queue = (new_queue)=>{
-        queue = new_queue;
-        refreshQueue();
-    };
-
-    self.set_play_state = (up_now, up_next, playing)=>{
-        currVid.innerText = up_now;
-        nextVid.innerText = up_next;
-    };
-
-    self.browse_up = ()=>{
-        path.pop();
-        refreshItems();
-    };
-
-    const refreshQueue = ()=>{
-        if (queue.length > 0) {
-            queueList.innerHTML = "";
-            for (const item of queue) {
-                const el = document.createElement("div");
-                el.innerText = item.path;
-                queueList.appendChild(el);
-            }
-        } else {
-            queueList.innerHTML = "The queue is currently empty";
-        }
-    };
-
-    const getLocalRoot = ()=>{
-        let root = items;
-        for (const dir of path) {
-            root = root[dir];
-        }
-        return root;
-    };
-
-    const linkDown = (dir)=>{
-        path.push(dir);
-        refreshItems();
-    };
-
-    const refreshItems = ()=>{
-        const dir = getLocalRoot();
-        currDir.innerText = (path[path.length - 1] || "Root");
-
-        itemList.innerText = "";
-        for (const item in dir) {
-            const el = document.createElement("div");
-            el.innerText = item;
-            if ('path' in dir[item]) {
-                el.onclick = ()=>{ self.enqueue(dir[item].path); };
-            } else {
-                el.onclick = ()=>{ linkDown(item); };
-            }
-            itemList.appendChild(el);
-
-
-
-//            const link = document.createElement("a");
-//            link.innerText = item;
-//            link.href = '#';
-//            if ('path' in dir[item]) {
-//                link.onclick = ()=>{ self.enqueue(dir[item].path); };
-//            } else {
-//                link.onclick = ()=>{ linkDown(item); };
-//            }
-//            el.appendChild(link);
-//            itemList.appendChild(el);
-        }
-    };
-
-    return self;
-})();
-
-
 (()=>{
-    let items = {}
-    let path = [];
-
     Client.connect((data)=>{
         console.log(data);
         if (cmd.cmd === "items")
@@ -193,53 +79,7 @@ const UI = (()=>{
             );
         }
     });
-
-
-
-
-//    const getLocalRoot = ()=>{
-//        let root = items;
-//        for (const dir of path) {
-//            root = root[dir];
-//        }
-//        return root;
-//    };
-//
-//    const linkDown = (dir)=>{
-//        path.push(dir);
-//        showItems();
-//    };
-//
-//    const linkUp = ()=>{
-//        path.slice(-1);
-//        showItems();
-//    };
-//
-//    const showItem = (item, isFile, fileData) => {
-//        const el = document.createElement("div");
-//        const link = document.createElement("a");
-//        link.innerText = item;
-//        link.href = '#';
-//        if (!isFile) {
-//            link.onclick = ()=>{ linkDown(item); };
-//        } else {
-//            link.onclick = ()=>{ Client.enqueue(fileData.path); };
-//        }
-//        el.appendChild(link);
-//        itemList.appendChild(el);
-//    }
-//
-//    const showItems = ()=>{
-//        const dir = getLocalRoot();
-//        itemList.innerText = "";
-//        for (const item in dir) {
-//            showItem(item, ('path' in dir[item]), dir[item]);
-//        }
-//    };
-
 })();
-
-
 </script>
 </body>
 </html>
index 8a01eada2ed6365f7fe62073551a6b93ee8f8c2c..f51496a242f617afcf8ec15049d0ba7572153649 100644 (file)
@@ -3,40 +3,10 @@
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <meta name="viewport" content="width=device-width,initial-scale=1">
+  <link rel="stylesheet" href="style.css">
   <style>
     html, body {
-      margin: 0;
-      padding: 0;
-      width: 100%;
-      height: 100%;
-      max-height: 100%;
       background-color: #000;
-      overflow: hidden;
-    }
-
-    .badge {
-        position: absolute;
-        bottom: 1em;
-        color: white;
-        font-family: sans-serif;
-        background-color: black;
-    }
-
-    .badge span {
-        display: block;
-        width: 100%;
-        text-align: center;
-    }
-
-    .channelBadge {
-        position: absolute;
-        top: 0em;
-        color: white;
-        font-family: sans-serif;
-        font-size: 3em;
-        background-color: black;
-        width: 100%;
-        text-align: center;
     }
   </style>
 </head>
@@ -116,6 +86,7 @@ const connect = ()=>{
 
     ws.onmessage = (event)=>{
         const msg = JSON.parse(event.data);
+        if (msg["cmd"] != "queue")
         {
             console.log(msg);
             const prev = current;
index 55a8595def5482aead03f17ef667ad17002bb098..cf1229c1297889ceeb56d1baeca162c2cf54114c 100644 (file)
@@ -8,6 +8,31 @@
       overflow: hidden;
     }
 
+    .badge {
+        position: absolute;
+        bottom: 1em;
+        color: white;
+        font-family: sans-serif;
+        background-color: black;
+    }
+
+    .badge span {
+        display: block;
+        width: 100%;
+        text-align: center;
+    }
+
+    .channelBadge {
+        position: absolute;
+        top: 0em;
+        color: white;
+        font-family: sans-serif;
+        font-size: 3em;
+        background-color: black;
+        width: 100%;
+        text-align: center;
+    }
+
     .table {
         display: block;
     }
diff --git a/atv/assets/ui.js b/atv/assets/ui.js
new file mode 100644 (file)
index 0000000..b30c941
--- /dev/null
@@ -0,0 +1,101 @@
+const UI = (()=>{
+    const self = {};
+
+    let queue = [];
+    let items = {};
+    let path = [];
+
+    const showBrowser = ()=>{
+        path = [];
+        browseView.style.display = "flex";
+        mainView.style.display = "none";
+    };
+
+    const showMain = ()=>{
+        path = [];
+        browseView.style.display = "none";
+        mainView.style.display = "flex";
+    };
+
+    // Button handlers
+    self.play_pause  = ()=>{ Client.play_pause(); };
+    self.chan_next   = ()=>{ Client.chan_next(); };
+    self.chan_prev   = ()=>{ Client.chan_prev(); };
+    self.skip        = ()=>{ Client.skip(); };
+    self.select_file = ()=>{ showBrowser(); };
+    self.cancel      = ()=>{ showMain(); };
+
+    self.enqueue = (path)=>{
+        console.log(path);
+        Client.send("enqueue", { path: path });
+        showMain();
+    };
+
+    self.set_items = (new_items)=>{
+        items = new_items;
+        refreshItems();
+    };
+
+    self.set_queue = (new_queue)=>{
+        queue = new_queue;
+        refreshQueue();
+    };
+
+    self.set_play_state = (up_now, up_next, playing)=>{
+        currVid.innerText = up_now;
+        nextVid.innerText = up_next;
+        if (document.getElementById("playBtn")) {
+            playBtn.value = (playing ? "Pause" : "Play");
+        }
+    };
+
+    self.browse_up = ()=>{
+        path.pop();
+        refreshItems();
+    };
+
+    const refreshQueue = ()=>{
+        if (queue.length > 0) {
+            queueList.innerHTML = "";
+            for (const item of queue) {
+                const el = document.createElement("div");
+                el.innerText = item.path;
+                queueList.appendChild(el);
+            }
+        } else {
+            queueList.innerHTML = "The queue is currently empty";
+        }
+    };
+
+    const getLocalRoot = ()=>{
+        let root = items;
+        for (const dir of path) {
+            root = root[dir];
+        }
+        return root;
+    };
+
+    const linkDown = (dir)=>{
+        path.push(dir);
+        refreshItems();
+    };
+
+    const refreshItems = ()=>{
+        const dir = getLocalRoot();
+        currDir.innerText = (path[path.length - 1] || "Root");
+
+        itemList.innerText = "";
+        for (const item in dir) {
+            const el = document.createElement("div");
+            el.innerText = item;
+            if ('path' in dir[item]) {
+                el.onclick = ()=>{ self.enqueue(dir[item].path); };
+            } else {
+                el.onclick = ()=>{ linkDown(item); };
+            }
+            itemList.appendChild(el);
+        }
+    };
+
+    return self;
+})();
index c46cfbf6b25c1b3b7217ce30df62cfab24899e97..089761698a4e4b97e1c78d8fba73def39b8bd030 100755 (executable)
@@ -42,6 +42,7 @@ if File.exist? CONFIG_PATH
   CONFIG = JSON.parse(File.read(CONFIG_PATH))
 else
   CONFIG = DEFAULT_CONFIG
+  File.open(CONFIG_PATH, "wb") {|f| f.write JSON.dump(CONFIG) }
 end
 
 # Update website files first
index 90d0065eac464fb6d2fa2cc0e9798f0e81294b9f..abd613ea01520d3a5ffca6605215f64625f721e8 100644 (file)
@@ -9,6 +9,7 @@ module ATV
       @path = "#{root}/index.json"
       @data = {}
       @dirs = scan_dirs
+      pp scan_dirs
       load()
     end