update counters when downloads initiate from search page

This commit is contained in:
huangjx
2022-04-26 17:49:24 +08:00
parent c82594d99e
commit c42be35566
5 changed files with 27 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ return [
'routes' => [
['name' => 'Main#Index', 'url' => '/', 'verb' => 'GET'],
['name' => 'Main#Upload', 'url' => '/upload', 'verb' => 'POST'],
['name' => 'Main#getCounters', 'url' => '/counters', 'verb' => 'GET'],
['name' => 'main#Download', 'url' => '/new', 'verb' => 'POST'],
['name' => 'Aria2#Action', 'url' => '/aria2/{path}', 'verb' => 'POST'],
['name' => 'Aria2#getStatus', 'url' => '/status/{path}', 'verb' => 'POST'],

View File

@@ -5,17 +5,17 @@ namespace OCA\NCDownloader\Controller;
use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\Counters;
use OCA\NCDownloader\Tools\DbHelper;
use OCA\NCDownloader\Tools\folderScan;
use OCA\NCDownloader\Tools\Helper;
use OCA\NCDownloader\Tools\Settings;
use OCA\NCDownloader\Tools\Youtube;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IL10N;
//use OCP\Files\IRootFolder;
use OCP\IL10N;
use OCP\IRequest;
use OC_Util;
use OCA\NCDownloader\Tools\folderScan;
class MainController extends Controller
{
@@ -205,5 +205,14 @@ class MainController extends Controller
$resp = folderScan::create()->scan();
return new JSONResponse($resp);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getCounters(): JSONResponse
{
$counter = $this->counters->getCounters();
return new JSONResponse(['counter' => $counter]);
}
}

View File

@@ -11,6 +11,9 @@ const buttonHandler = (event, type) => {
let url = element.getAttribute("path");
let row, data = {};
let removeRow = true;
if (element.getAttribute("id") == "download-action-button"){
helper.getCounters();
}
if (row = element.closest('.table-row-search')) {
if (element.className == 'icon-clipboard') {
const clippy = new Clipboard(element, row.dataset.link);

View File

@@ -138,12 +138,13 @@ class contentTable {
let button = document.createElement("button");
button.classList.add("icon-" + name);
button.setAttribute("path", path);
button.setAttribute("data", data);
button.setAttribute("data", data || "nodata");
if (name == 'refresh') {
name = helper.t('Redownload');
}
button.setAttribute("data-tippy-content", helper.ucfirst(name));
button.setAttribute("title", helper.ucfirst(name));
button.setAttribute("id", name + "-action-button");
return button;
}

View File

@@ -139,6 +139,13 @@ const helper = {
counter.innerHTML = '<div class="number">' + data[key] + '</div>';
}
},
getCounters() {
let url = helper.generateUrl("apps/ncdownloader/counters");
Http.getInstance(url).setMethod("GET").setHandler(function (data) {
if (data["counter"])
helper.updateCounter(data["counter"]);
}).send();
},
html2DOM: function (htmlString) {
const parser = new window.DOMParser();
let doc = parser.parseFromString(htmlString, "text/html")