From 945d6056af52678fc512c4b5226f6ca29773ca78 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 17 Mar 2024 22:41:36 -0400 Subject: [PATCH] small cleanup --- atv/assets/admin.html | 154 +------------------------------------- atv/assets/control.html | 162 +--------------------------------------- atv/assets/index.html | 33 +------- atv/assets/style.css | 25 +++++++ atv/assets/ui.js | 101 +++++++++++++++++++++++++ atv/bin/atv | 1 + atv/lib/atv/database.rb | 1 + 7 files changed, 132 insertions(+), 345 deletions(-) create mode 100644 atv/assets/ui.js diff --git a/atv/assets/admin.html b/atv/assets/admin.html index a27b3da..8036324 100644 --- a/atv/assets/admin.html +++ b/atv/assets/admin.html @@ -58,118 +58,10 @@ + + diff --git a/atv/assets/index.html b/atv/assets/index.html index 8a01ead..f51496a 100644 --- a/atv/assets/index.html +++ b/atv/assets/index.html @@ -3,40 +3,10 @@ + @@ -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; diff --git a/atv/assets/style.css b/atv/assets/style.css index 55a8595..cf1229c 100644 --- a/atv/assets/style.css +++ b/atv/assets/style.css @@ -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 index 0000000..b30c941 --- /dev/null +++ b/atv/assets/ui.js @@ -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; +})(); diff --git a/atv/bin/atv b/atv/bin/atv index c46cfbf..0897616 100755 --- a/atv/bin/atv +++ b/atv/bin/atv @@ -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 diff --git a/atv/lib/atv/database.rb b/atv/lib/atv/database.rb index 90d0065..abd613e 100644 --- a/atv/lib/atv/database.rb +++ b/atv/lib/atv/database.rb @@ -9,6 +9,7 @@ module ATV @path = "#{root}/index.json" @data = {} @dirs = scan_dirs + pp scan_dirs load() end -- 2.55.0