From 92be2a120ea4b195ce37fbe47cb2f1df9c96609e Mon Sep 17 00:00:00 2001 From: RemixDev Date: Tue, 14 Apr 2020 16:48:13 +0200 Subject: [PATCH] Added clear and cancel queue buttons --- public/css/style.css | 3 +++ public/index.html | 4 +++ public/js/app.js | 1 - public/js/downloadList.js | 56 ++++++++++++++++++++++++++++++++------- public/js/init.js | 7 ++--- public/js/utils.js | 5 ++-- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index feb57c5..399d9f1 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -427,3 +427,6 @@ input[type="text"], input[type="password"], input[type="number"]{ color: var(--primary-text); margin-bottom: 8px; } +.right{ + float: right; +} diff --git a/public/index.html b/public/index.html index 7881909..0a6c888 100644 --- a/public/index.html +++ b/public/index.html @@ -359,6 +359,10 @@

Settings

chevron_right +
+ clear_all + delete_sweep +
diff --git a/public/js/app.js b/public/js/app.js index 8a59fdc..3325b93 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -67,7 +67,6 @@ function clickElement(button){ } function sendAddToQueue(url, bitrate = null){ - console.log(url) socket.emit("addToQueue", {url: url, bitrate:bitrate}) } diff --git a/public/js/downloadList.js b/public/js/downloadList.js index 7b2bc2d..513c91a 100644 --- a/public/js/downloadList.js +++ b/public/js/downloadList.js @@ -1,23 +1,28 @@ var queueList = {} var queue = [] +var queueComplete = [] socket.on("init_downloadQueue", function(data){ + console.log(data) + if (data.queueComplete.length){ + data.queueComplete.forEach(item=>{ + addToQueue(data.queueList[item]) + }) + } if (data.currentItem){ addToQueue(data['queueList'][data.currentItem]) - $('#bar_' + data.currentItem).removeClass('indeterminate').addClass('determinate') - $('#bar_' + data.currentItem).css('width', data['queueList'][data.currentItem].progress + '%') - if (queueList[data.currentItem].failed >= 1){ - $("#download_"+data.currentItem+" .download_info_status").append(`(${queueList[data.currentItem].failed}error_outline)`) - } } - data['queue'].forEach(item=>{ - addToQueue(data['queueList'][item]) + data.queue.forEach(item=>{ + addToQueue(data.queueList[item]) }) }) function addToQueue(queueItem){ queueList[queueItem.uuid] = queueItem - queue.push(queueItem.uuid) + if ((queueItem.downloaded + queueItem.failed) == queueItem.size) + queueComplete.push(queueItem.uuid) + else + queue.push(queueItem.uuid) $("#download_list").append( `
@@ -35,6 +40,23 @@ function addToQueue(queueItem){ remove
`) + if (queueItem.progress>0){ + $('#bar_' + queueItem.uuid).removeClass('indeterminate').addClass('determinate') + } + $('#bar_' +queueItem.uuid).css('width', queueItem.progress + '%') + if (queueItem.failed >= 1){ + $("#download_"+queueItem.uuid+" .download_info_status").append(`(${queueItem.failed}error_outline)`) + } + if ((queueItem.downloaded + queueItem.failed) == queueItem.size){ + let result_icon = $('#download_'+queueItem.uuid).find('.queue_icon') + if (queueItem.failed == 0){ + result_icon.text("done") + }else if (queueItem.failed == queueItem.size){ + result_icon.text("error") + }else{ + result_icon.text("warning") + } + } } socket.on("addedToQueue", function(queueItem){ @@ -80,7 +102,7 @@ socket.on("finishDownload", function(uuid){ let index = queue.indexOf(uuid) if (index > -1){ queue.splice(index, 1) - delete queueList[uuid] + queueComplete.push(uuid) } if (queue.length <= 0){ toast('All downloads completed!', 'done_all') @@ -91,9 +113,25 @@ socket.on("finishDownload", function(uuid){ socket.on("removedAllDownloads", function(){ queue = [] queueList = {} + queueComplete = [] $("#download_list").html("") }) +socket.on("removedFinishedDownloads", function(){ + queueComplete.forEach((item) => { + $("#download_"+item).remove() + }) + queueComplete = [] +}) + +$("#clean_queue").on("click", function(){ + socket.emit("removeFinishedDownloads") +}) + +$("#cancel_queue").on("click", function(){ + socket.emit("cancelAllDownloads") +}) + socket.on("updateQueue", function(update){ if (update.uuid && queue.indexOf(update.uuid) > -1){ if (update.downloaded){ diff --git a/public/js/init.js b/public/js/init.js index 66a747e..d5e8808 100644 --- a/public/js/init.js +++ b/public/js/init.js @@ -9,8 +9,8 @@ toastsWithId = {} function toast(msg, icon=null, dismiss=true, id=null){ if (toastsWithId[id]){ - toastObj = toastsWithId[id] - toastDOM = $(`div.toastify[toast_id=${id}]`) + let toastObj = toastsWithId[id] + let toastDOM = $(`div.toastify[toast_id=${id}]`) if (msg){ toastDOM.find(".toast-message").html(msg) } @@ -21,6 +21,7 @@ function toast(msg, icon=null, dismiss=true, id=null){ icon = `${icon}` toastDOM.find(".toast-icon").html(icon) } + console.log(dismiss) if (dismiss !== null && dismiss){ setTimeout(function(){ toastObj.hideToast() @@ -34,7 +35,7 @@ function toast(msg, icon=null, dismiss=true, id=null){ icon = `
` else icon = `${icon}` - toastObj = Toastify({ + let toastObj = Toastify({ text: `${icon}${msg}`, duration: dismiss ? 3000 : 0, gravity: 'bottom', diff --git a/public/js/utils.js b/public/js/utils.js index 69075f5..8bca0ed 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -1,11 +1,12 @@ function isValidURL(text){ - if (text.toLowerCase().startsWith("http")) + if (text.toLowerCase().startsWith("http")){ if (text.toLowerCase().indexOf("deezer.com") >= 0 || text.toLowerCase().indexOf("open.spotify.com") >= 0) return true - else if (text.toLowerCase().startsWith("spotify:")) + }else if (text.toLowerCase().startsWith("spotify:")) return true return false } + function convertDuration(duration) { //convert from seconds only to mm:ss format var mm, ss