cleaning up polling code
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import helper from '../utils/helper'
|
||||
import eventHandler from '../lib/eventHandler';
|
||||
import Http from '../lib/http'
|
||||
|
||||
const basePath = "/apps/ncdownloader/status/";
|
||||
const tableContainer = ".table";
|
||||
export default {
|
||||
@@ -18,33 +16,30 @@ export default {
|
||||
}
|
||||
let name = type + "-downloads";
|
||||
//avoid repeated click
|
||||
if (currentType === name && helper.enabledPolling) {
|
||||
if (currentType === name && helper.isPolling()) {
|
||||
return;
|
||||
}
|
||||
helper.enabledPolling = 1;
|
||||
//$(tableContainer).removeClass().addClass("table " + name);
|
||||
container.setAttribute("type", name);
|
||||
container.className = "table " + name;
|
||||
let delay = 15000;
|
||||
if (['active', 'youtube-dl'].includes(type)) {
|
||||
delay = 1500;
|
||||
}
|
||||
helper.loop(helper.refresh, delay, ...[path])
|
||||
helper.polling(delay, path);
|
||||
};
|
||||
eventHandler.add("click",".waiting-downloads a",event => clickHandler(event, 'waiting'));
|
||||
eventHandler.add("click",".complete-downloads a",event => clickHandler(event, 'complete'));
|
||||
eventHandler.add("click",".active-downloads a",event => clickHandler(event, 'active'));
|
||||
eventHandler.add("click",".fail-downloads a",event => clickHandler(event, 'fail'));
|
||||
eventHandler.add("click",".youtube-dl-downloads a",event => clickHandler(event, 'youtube-dl'));
|
||||
eventHandler.add("click", "#ncdownloader-table-wrapper",".download-file-folder", function (event) {
|
||||
eventHandler.add("click", ".waiting-downloads a", event => clickHandler(event, 'waiting'));
|
||||
eventHandler.add("click", ".complete-downloads a", event => clickHandler(event, 'complete'));
|
||||
eventHandler.add("click", ".active-downloads a", event => clickHandler(event, 'active'));
|
||||
eventHandler.add("click", ".fail-downloads a", event => clickHandler(event, 'fail'));
|
||||
eventHandler.add("click", ".youtube-dl-downloads a", event => clickHandler(event, 'youtube-dl'));
|
||||
eventHandler.add("click", "#ncdownloader-table-wrapper", ".download-file-folder", function (event) {
|
||||
event.stopPropagation();
|
||||
const path = "/apps/ncdownloader/update";
|
||||
let url = helper.generateUrl(path);
|
||||
Http.getInstance(url).setMethod('GET').send();
|
||||
event.preventDefault();
|
||||
let ele = event.target;
|
||||
let url = ele.getAttribute("href");
|
||||
helper.scanFolder().then(() => {
|
||||
helper.redirect(url);
|
||||
});
|
||||
});
|
||||
helper.polling(function (url) {
|
||||
url = helper.generateUrl(url);
|
||||
Http.getInstance(url).setMethod('GET').send();
|
||||
}, 60000, "/apps/ncdownloader/update");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user