Fixed downloads not sorting properly

Confirm dialog can now be a selection list
This commit is contained in:
Isaac Abadi
2022-05-21 21:26:25 -04:00
parent 71d5a64272
commit bf64d97b72
6 changed files with 89 additions and 27 deletions

View File

@@ -3,7 +3,7 @@
<mat-table style="overflow: hidden" [ngClass]="uids ? 'rounded-top' : null" matSort [dataSource]="dataSource">
<!-- Date Column -->
<ng-container matColumnDef="date">
<ng-container matColumnDef="timestamp_start">
<mat-header-cell *matHeaderCellDef mat-sort-header> <ng-container i18n="Date">Date</ng-container> </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.timestamp_start | date: 'short'}} </mat-cell>
</ng-container>
@@ -19,7 +19,7 @@
</ng-container>
<!-- Subscription Column -->
<ng-container matColumnDef="subscription">
<ng-container matColumnDef="sub_name">
<mat-header-cell *matHeaderCellDef mat-sort-header> <ng-container i18n="Subscription">Subscription</ng-container> </mat-header-cell>
<mat-cell *matCellDef="let element">
<ng-container *ngIf="element.sub_name">
@@ -32,13 +32,13 @@
</ng-container>
<!-- Stage Column -->
<ng-container matColumnDef="stage">
<ng-container matColumnDef="step_index">
<mat-header-cell *matHeaderCellDef mat-sort-header> <ng-container i18n="Stage">Stage</ng-container> </mat-header-cell>
<mat-cell *matCellDef="let element"> {{STEP_INDEX_TO_LABEL[element.step_index]}} </mat-cell>
</ng-container>
<!-- Progress Column -->
<ng-container matColumnDef="progress">
<ng-container matColumnDef="percent_complete">
<mat-header-cell *matHeaderCellDef mat-sort-header> <ng-container i18n="Progress">Progress</ng-container> </mat-header-cell>
<mat-cell *matCellDef="let element">
<ng-container *ngIf="element.percent_complete">
@@ -82,7 +82,7 @@
<div *ngIf="!uids" class="downloads-action-button-div">
<button [disabled]="!running_download_exists" mat-stroked-button (click)="pauseAllDownloads()"><ng-container i18n="Pause all downloads">Pause all downloads</ng-container></button>
<button style="margin-left: 10px;" [disabled]="!paused_download_exists" mat-stroked-button (click)="resumeAllDownloads()"><ng-container i18n="Resume all downloads">Resume all downloads</ng-container></button>
<button color="warn" style="margin-left: 10px;" mat-stroked-button (click)="clearFinishedDownloads()"><ng-container i18n="Clear finished downloads">Clear finished downloads</ng-container></button>
<button color="warn" style="margin-left: 10px;" mat-stroked-button (click)="clearDownloadsByType()"><ng-container i18n="Clear downloads">Clear downloads</ng-container></button>
</div>
</div>

View File

@@ -61,7 +61,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
3: $localize`Complete`
}
displayedColumns: string[] = ['date', 'title', 'stage', 'subscription', 'progress', 'actions'];
displayedColumns: string[] = ['timestamp_start', 'title', 'step_index', 'sub_name', 'percent_complete', 'actions'];
dataSource = null; // new MatTableDataSource<Download>();
downloads_retrieved = false;
@@ -104,7 +104,6 @@ export class DownloadsComponent implements OnInit, OnDestroy {
getCurrentDownloads(): void {
this.postsService.getCurrentDownloads(this.uids).subscribe(res => {
this.downloads_retrieved = true;
if (res['downloads'] !== null
&& res['downloads'] !== undefined
&& JSON.stringify(this.downloads) !== JSON.stringify(res['downloads'])) {
@@ -114,12 +113,12 @@ export class DownloadsComponent implements OnInit, OnDestroy {
this.dataSource = new MatTableDataSource<Download>(this.downloads);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.paused_download_exists = this.downloads.find(download => download['paused'] && !download['error']);
this.running_download_exists = this.downloads.find(download => !download['paused'] && !download['finished']);
} else {
// failed to get downloads
}
this.downloads_retrieved = true;
});
}
@@ -134,7 +133,7 @@ export class DownloadsComponent implements OnInit, OnDestroy {
});
dialogRef.afterClosed().subscribe(confirmed => {
if (confirmed) {
this.postsService.clearFinishedDownloads().subscribe(res => {
this.postsService.clearDownloads(true, false, false).subscribe(res => {
if (!res['success']) {
this.postsService.openSnackBar('Failed to clear finished downloads!');
}
@@ -143,6 +142,47 @@ export class DownloadsComponent implements OnInit, OnDestroy {
});
}
clearDownloadsByType(): void {
const clearEmitter = new EventEmitter<boolean>();
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
dialogType: 'selection_list',
dialogTitle: $localize`Clear downloads`,
dialogText: $localize`Select downloads to clear`,
submitText: $localize`Clear`,
doneEmitter: clearEmitter,
warnSubmitColor: true,
list: [
{
title: $localize`Finished downloads`,
key: 'clear_finished'
},
{
title: $localize`Paused downloads`,
key: 'clear_paused'
},
{
title: $localize`Errored downloads`,
key: 'clear_errors'
}
]
}
});
clearEmitter.subscribe((done: boolean) => {
if (done) {
const selected_items = dialogRef.componentInstance.selected_items;
this.postsService.clearDownloads(selected_items.includes('clear_finished'), selected_items.includes('clear_paused'), selected_items.includes('clear_errors')).subscribe(res => {
if (!res['success']) {
this.postsService.openSnackBar($localize`Failed to clear finished downloads!`);
} else {
this.postsService.openSnackBar($localize`Cleared downloads!`);
dialogRef.close();
}
});
}
});
}
pauseDownload(download_uid: string): void {
this.postsService.pauseDownload(download_uid).subscribe(res => {
if (!res['success']) {