removed duplicate code related to download queue

This commit is contained in:
huangjx
2022-04-24 15:38:09 +08:00
parent 71a015e10e
commit 507b43ca3b
3 changed files with 33 additions and 73 deletions

View File

@@ -1,38 +1,32 @@
import helper from '../utils/helper'
import eventHandler from '../lib/eventHandler';
const basePath = "/apps/ncdownloader/status/";
const tableContainer = ".table";
export default {
run: function () {
const clickHandler = (event, type) => {
const clickHandler = (event) => {
event.stopPropagation();
event.preventDefault();
let element = event.target;
helper.hideDownload();
let container = document.querySelector(tableContainer);
let currentType = container.getAttribute("type");
let path = basePath + type;
let name = type + "-downloads";
let currentType = helper.getContentTableType();
let path = element.getAttribute("path");
let name = element.getAttribute("id");
//avoid repeated click
if (currentType === name && helper.isPolling()) {
return;
}
container.setAttribute("type", name);
container.className = "table " + name;
helper.setContentTableType(name);
let delay;
if (!['active', 'youtube-dl'].includes(type)) {
if (!['active-downloads', 'youtube-dl-downloads'].includes(name)) {
delay = 15000;
}
if (type === "youtube-dl") {
if (name === "youtube-dl-downloads") {
helper.pollingYoutube();
} else {
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", ".download-queue a", event => clickHandler(event));
eventHandler.add("click", "#ncdownloader-table-wrapper", ".download-file-folder", function (event) {
event.stopPropagation();
event.preventDefault();

View File

@@ -267,6 +267,15 @@ const helper = {
},
redirect(url) {
window.location.href = url;
},
getContentTableType() {
let container = document.getElementById("ncdownloader-table-wrapper");
return container.getAttribute("type");
},
setContentTableType(name) {
let container = document.getElementById("ncdownloader-table-wrapper");
container.setAttribute("type", name);
container.className = "table " + name;
}
}

View File

@@ -1,5 +1,12 @@
<?php
extract($_);
$downloadsList = [
["name" => "active", "label" => "Active Downloads", "id" => "active-downloads", "path" => "/apps/ncdownloader/status/active"],
["name" => "waiting", "label" => "Waiting Downloads", "id" => "waiting-downloads", "path" => "/apps/ncdownloader/status/waiting"],
["name" => "fail", "label" => "Failed Downloads", "id" => "failed-downloads", "path" => "/apps/ncdownloader/status/fail"],
["name" => "complete", "label" => "Complete Downloads", "id" => "complete-downloads", "path" => "/apps/ncdownloader/status/complete"],
["name" => "youtube-dl", "label" => "Youtube-dl Downloads", "id" => "youtube-dl-downloads", "path" => "/apps/ncdownloader/youtube/get"],
];
?>
<div id="app-navigation">
<?php if (!$ncd_hide_errors): ?>
@@ -33,71 +40,21 @@ extract($_);
</div>
<?php endif;?>
<ul>
<li class="active-downloads">
<?php foreach ($downloadsList as $value): ?>
<li class="download-queue <?php print $value["id"];?>">
<div class="app-navigation-entry-bullet"></div>
<a role="button" tabindex="0" path="/apps/ncdownloader/dl/active">
<?php print($l->t('Active Downloads'));?>
<a role="button" tabindex="0" path="<?php print $value["path"];?>" id="<?php print $value["id"];?>">
<?php print($l->t($value["label"]));?>
</a>
<div class="app-navigation-entry-utils">
<ul>
<li class="app-navigation-entry-utils-counter" id="active-downloads-counter">
<div class="number"><?php print($_['counter']['active']);?></div>
</li>
</ul>
</div>
</li>
<li class="waiting-downloads">
<div class="app-navigation-entry-bullet"></div>
<a role="button" tabindex="0" path="/apps/ncdownloader/dl/waiting">
<?php print($l->t('Waiting Downloads'));?>
</a>
<div class="app-navigation-entry-utils">
<ul>
<li class="app-navigation-entry-utils-counter" id="waiting-downloads-counter">
<div class="number"><?php print($_['counter']['waiting']);?></div>
</li>
</ul>
</div>
</li>
<li class="complete-downloads">
<div class="app-navigation-entry-bullet"></div>
<a role="button" tabindex="0" path="/apps/ncdownloader/dl/complete">
<?php print($l->t('Complete Downloads'));?>
</a>
<div class="app-navigation-entry-utils">
<ul>
<li class="app-navigation-entry-utils-counter" id="complete-downloads-counter">
<div class="number"><?php print($_['counter']['complete']);?></div>
</li>
</ul>
</div>
</li>
<li class="fail-downloads">
<div class="app-navigation-entry-bullet"></div>
<a role="button" tabindex="0" path="/apps/ncdownloader/dl/fail">
<?php print($l->t('Failed Downloads'));?>
</a>
<div class="app-navigation-entry-utils">
<ul>
<li class="app-navigation-entry-utils-counter" id="fail-downloads-counter">
<div class="number"><?php print($_['counter']['fail']);?></div>
</li>
</ul>
</div>
</li>
<li class="youtube-dl-downloads">
<div class="app-navigation-entry-bullet"></div>
<a role="button" tabindex="0">
<?php print($l->t('Youtube-dl Downloads'));?>
</a>
<div class="app-navigation-entry-utils">
<ul>
<li class="app-navigation-entry-utils-counter" id="youtube-dl-downloads-counter">
<div class="number"><?php print($_['counter']['youtube-dl']);?></div>
<li class="app-navigation-entry-utils-counter" id="<?php print $value["name"] . "-downloads-counter";?>">
<div class="number"><?php print($_['counter'][$value["name"]]);?></div>
</li>
</ul>
</div>
</li>
<?php endforeach;?>
</ul>
<div id="app-settings">
<div id="app-settings-header">