added options for tracking youtube-dl downloads;bugs fixing
This commit is contained in:
@@ -25,7 +25,10 @@ const buttonHandler = (event, type) => {
|
||||
return;
|
||||
}
|
||||
if (data.hasOwnProperty('result')) {
|
||||
helper.message("Success for " + data['result']);
|
||||
helper.message("Success " + data['result']);
|
||||
}
|
||||
if (data.hasOwnProperty('message')) {
|
||||
helper.message(data.message);
|
||||
}
|
||||
if (row && removeRow)
|
||||
row.remove();
|
||||
|
||||
@@ -47,10 +47,10 @@ const helper = {
|
||||
|
||||
return magnetURI.test(url.trim());
|
||||
},
|
||||
message: function (message) {
|
||||
message: function (message,duration = 5000) {
|
||||
Toastify({
|
||||
text: message,
|
||||
duration: 3000,
|
||||
duration:duration,
|
||||
newWindow: true,
|
||||
close: true,
|
||||
gravity: "top", // `top` or `bottom`
|
||||
|
||||
@@ -20,46 +20,49 @@ const createInputBox = (event, type) => {
|
||||
let height = $(window).scrollTop();
|
||||
if (height > 50)
|
||||
$("html, body").animate({ scrollTop: 0 }, "fast");
|
||||
let name;
|
||||
let name, path;
|
||||
switch (type) {
|
||||
case "ytdl":
|
||||
name = t("ncdownloader", 'YTDL Download');
|
||||
path = basePath + "/youtube/new";
|
||||
break;
|
||||
case "search":
|
||||
name = t("ncdownloader", 'Search');
|
||||
path = basePath + "/search";
|
||||
break;
|
||||
default:
|
||||
name = t("ncdownloader", 'New Download');
|
||||
path = basePath + "/new";
|
||||
}
|
||||
let container;
|
||||
if (type === 'search') {
|
||||
container = inputBox.getInstance(name, type).addSpinner().create();
|
||||
container = inputBox.getInstance(name, type, path).create().addSpinner();
|
||||
//container.appendChild(inputBox.createLoading());
|
||||
} else {
|
||||
container = inputBox.getInstance(name, type).create();
|
||||
container = inputBox.getInstance(name, type, path).create().getContainer();
|
||||
}
|
||||
$("#ncdownloader-form-wrapper").append(container);
|
||||
}
|
||||
|
||||
const toggleButton = element => {
|
||||
if (!element.previousSibling) {
|
||||
const toggleSpinner = element => {
|
||||
let spinner = element.previousSibling || element.nextSibling
|
||||
|
||||
if (!spinner) {
|
||||
return;
|
||||
}
|
||||
if (element.style.display === 'none') {
|
||||
element.style.display = 'block'
|
||||
element.previousSibling.style.display = 'none';
|
||||
spinner.style.display = 'none';
|
||||
} else {
|
||||
element.style.display = 'none'
|
||||
element.previousSibling.style.display = 'block';
|
||||
spinner.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
const inputHandler = (event) => {
|
||||
event.preventDefault();
|
||||
let element = event.target;
|
||||
// element.textContent = '';
|
||||
//$(element).append(inputBox.createLoading());
|
||||
toggleButton(element);
|
||||
toggleSpinner(element);
|
||||
let inputData = helper.getData('form-input-wrapper');
|
||||
let inputValue = inputData.form_input_text;
|
||||
if (inputData.type !== 'search' && !helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) {
|
||||
@@ -67,10 +70,10 @@ const inputHandler = (event) => {
|
||||
return;
|
||||
}
|
||||
if (inputData.type === 'ytdl') {
|
||||
helper.message(t("ncdownloader", "YTDL Download initiated"));
|
||||
helper.message(t("ncdownloader", "Please check your download folder for progress"), 5000);
|
||||
}
|
||||
if (inputData.type === 'search') {
|
||||
//there is a scheduled 60s-interval update running in the background, this is to prevent it from running when searching
|
||||
//a scheduled 60s-interval update is running in the background, this is to prevent it from interfering when searching
|
||||
helper.enabledPolling = 0;
|
||||
nctable.getInstance().loading();
|
||||
}
|
||||
@@ -79,7 +82,7 @@ const inputHandler = (event) => {
|
||||
if (data !== null && data.hasOwnProperty("file")) {
|
||||
helper.message(t("ncdownloader", "Downloading" + " " + data.file));
|
||||
}
|
||||
toggleButton(element);
|
||||
toggleSpinner(element);
|
||||
if (data && data.title) {
|
||||
const tableInst = nctable.getInstance(data.title, data.row);
|
||||
tableInst.actionLink = false;
|
||||
|
||||
@@ -3,23 +3,35 @@ import helper from './helper'
|
||||
|
||||
|
||||
class inputBox {
|
||||
constructor(name, id) {
|
||||
path;
|
||||
constructor(name, id, path = null) {
|
||||
this.name = name;
|
||||
this.container = this._createForm();
|
||||
this.textInput = this._createTextInput(id);
|
||||
this.controlsContainer = this._createControlsContainer();
|
||||
this.id = id;
|
||||
this.path = path;
|
||||
}
|
||||
static getInstance(name, id) {
|
||||
return new inputBox(name, id);
|
||||
static getInstance(name, id, path = null) {
|
||||
return new inputBox(name, id, path);
|
||||
}
|
||||
create() {
|
||||
this.container = this._createForm();
|
||||
this.textInput = this._createTextInput(this.id);
|
||||
this.controlsContainer = this._createControlsContainer();
|
||||
this.container.appendChild(this.textInput);
|
||||
this.controlsContainer.appendChild(this._createControls());
|
||||
this.container.appendChild(this.controlsContainer);
|
||||
return this;
|
||||
}
|
||||
|
||||
getContainer() {
|
||||
return this.container;
|
||||
}
|
||||
setPath(path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
_createControlsContainer() {
|
||||
let div = document.createElement("div");
|
||||
|
||||
div.classList.add("controls-container");
|
||||
return div;
|
||||
}
|
||||
@@ -36,6 +48,9 @@ class inputBox {
|
||||
textInput.setAttribute('id', "form_input_text");
|
||||
textInput.setAttribute('data-type', id);
|
||||
textInput.setAttribute('value', '');
|
||||
if (this.path) {
|
||||
textInput.setAttribute('data-path', this.path);
|
||||
}
|
||||
textInput.classList.add('form-input-text');
|
||||
return textInput;
|
||||
}
|
||||
@@ -55,7 +70,7 @@ class inputBox {
|
||||
let element = doc.querySelector(".bs-spinner");
|
||||
element.style.display = 'none';
|
||||
this.controlsContainer.appendChild(element);
|
||||
return this;
|
||||
return this.container;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,6 +89,9 @@ class ncTable {
|
||||
let container = document.createElement("div");
|
||||
container.classList.add("button-container");
|
||||
element[key].forEach(value => {
|
||||
if (!value.name) {
|
||||
return;
|
||||
}
|
||||
container.appendChild(this.createActionButton(value.name, value.path));
|
||||
})
|
||||
rowItem.appendChild(container);
|
||||
|
||||
@@ -6,9 +6,12 @@ const tableContainer = ".table";
|
||||
export default {
|
||||
run: function () {
|
||||
|
||||
const eventHandler = (event, type) => {
|
||||
const clickHandler = (event, type) => {
|
||||
event.preventDefault();
|
||||
const path = basePath + type;
|
||||
let path = basePath + type;
|
||||
if (type === "youtube-dl") {
|
||||
path = "/apps/ncdownloader/youtube/get";
|
||||
}
|
||||
let name = type + "-downloads";
|
||||
//avoid repeated click
|
||||
if ($(tableContainer).attr("type") === name && helper.enabledPolling) {
|
||||
@@ -18,19 +21,28 @@ export default {
|
||||
$(tableContainer).removeClass().addClass("table " + name);
|
||||
$(tableContainer).attr("type", name);
|
||||
let delay = 15000;
|
||||
if (name === "active-downloads") {
|
||||
if (['active', 'youtube-dl'].includes(type)) {
|
||||
delay = 1500;
|
||||
}
|
||||
helper.loop(helper.refresh, delay, ...[path])
|
||||
};
|
||||
$(".waiting-downloads").on("click", event => eventHandler(event, 'waiting'));
|
||||
$(".complete-downloads").on("click", event => eventHandler(event, 'complete'));
|
||||
$(".active-downloads").on("click", event => eventHandler(event, 'active'));
|
||||
$(".fail-downloads").on("click", event => eventHandler(event, 'fail'));
|
||||
$(".waiting-downloads").on("click", event => clickHandler(event, 'waiting'));
|
||||
$(".complete-downloads").on("click", event => clickHandler(event, 'complete'));
|
||||
$(".active-downloads").on("click", event => clickHandler(event, 'active'));
|
||||
$(".fail-downloads").on("click", event => clickHandler(event, 'fail'));
|
||||
$(".youtube-dl-downloads").on("click", event => clickHandler(event, 'youtube-dl'));
|
||||
|
||||
$("#ncdownloader-table-wrapper").on("click", ".download-file-folder", function (event) {
|
||||
event.stopPropagation();
|
||||
const path = "/apps/ncdownloader/update";
|
||||
let url = helper.generateUrl(path);
|
||||
Http.getInstance(url).setMethod('GET').send();
|
||||
});
|
||||
|
||||
helper.refresh(basePath + "waiting")
|
||||
helper.refresh(basePath + "complete")
|
||||
helper.refresh(basePath + "fail")
|
||||
helper.refresh("/apps/ncdownloader/youtube/get")
|
||||
|
||||
helper.loop(helper.refresh, 1000, basePath + "active");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user