Merge pull request #571 from lvank/master

Add a "download selected" button for non-autostarted downloads
This commit is contained in:
Alex 2025-01-14 15:49:46 +02:00 committed by GitHub
commit ec38f905b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View file

@ -126,6 +126,7 @@
<div class="metube-section-header">Downloading</div>
<div class="px-2 py-3 border-bottom">
<button type="button" class="btn btn-link text-decoration-none px-0 me-4" disabled #queueDelSelected (click)="delSelectedDownloads('queue')"><fa-icon [icon]="faTrashAlt"></fa-icon>&nbsp; Cancel selected</button>
<button type="button" class="btn btn-link text-decoration-none px-0 me-4" disabled #queueDownloadSelected (click)="startSelectedDownloads('queue')"><fa-icon [icon]="faDownload"></fa-icon>&nbsp; Download selected</button>
</div>
<div class="overflow-auto">
<table class="table">

View file

@ -33,6 +33,7 @@ export class AppComponent implements AfterViewInit {
@ViewChild('queueMasterCheckbox') queueMasterCheckbox: MasterCheckboxComponent;
@ViewChild('queueDelSelected') queueDelSelected: ElementRef;
@ViewChild('queueDownloadSelected') queueDownloadSelected: ElementRef;
@ViewChild('doneMasterCheckbox') doneMasterCheckbox: MasterCheckboxComponent;
@ViewChild('doneDelSelected') doneDelSelected: ElementRef;
@ViewChild('doneClearCompleted') doneClearCompleted: ElementRef;
@ -180,6 +181,7 @@ export class AppComponent implements AfterViewInit {
queueSelectionChanged(checked: number) {
this.queueDelSelected.nativeElement.disabled = checked == 0;
this.queueDownloadSelected.nativeElement.disabled = checked == 0;
}
doneSelectionChanged(checked: number) {
@ -228,6 +230,10 @@ export class AppComponent implements AfterViewInit {
this.downloads.delById(where, [id]).subscribe();
}
startSelectedDownloads(where: string){
this.downloads.startByFilter(where, dl => dl.checked).subscribe();
}
delSelectedDownloads(where: string) {
this.downloads.delByFilter(where, dl => dl.checked).subscribe();
}

View file

@ -118,6 +118,12 @@ export class DownloadsService {
return this.http.post('delete', {where: where, ids: ids});
}
public startByFilter(where: string, filter: (dl: Download) => boolean) {
let ids: string[] = [];
this[where].forEach((dl: Download) => { if (filter(dl)) ids.push(dl.url) });
return this.startById(ids);
}
public delByFilter(where: string, filter: (dl: Download) => boolean) {
let ids: string[] = [];
this[where].forEach((dl: Download) => { if (filter(dl)) ids.push(dl.url) });