Added ability to reset tasks

Refactored youtube-dl updating and added youtube-dl update task
This commit is contained in:
Isaac Abadi
2022-04-21 22:04:45 -04:00
parent d2d125743e
commit b53d9c9710
8 changed files with 298 additions and 194 deletions

View File

@@ -50,11 +50,18 @@
<mat-cell *matCellDef="let element">
<div class="container">
<div class="row justify-content-center">
<div *ngIf="element.data?.uids?.length > 0" class="col-12 mt-2">
<div *ngIf="element.data?.uids?.length > 0 || (!element.data?.uids && element.data)" class="col-12 mt-2" style="display: flex; justify-content: center;">
<ng-container>
<button (click)="confirmTask(element.key)" [disabled]="element.running || element.confirming" mat-stroked-button>
<ng-container *ngIf="element.key == 'missing_files_check'" i18n="Clear missing files from DB">Clear missing files from DB:</ng-container>
<ng-container *ngIf="element.key == 'duplicate_files_check'" i18n="Clear duplicate files from DB">Clear duplicate files from DB:</ng-container>&nbsp;{{element.data.uids.length}}
<ng-container *ngIf="element.key == 'missing_files_check'">
<ng-container i18n="Clear missing files from DB">Clear missing files from DB:</ng-container>{{element.data.uids.length}}
</ng-container>
<ng-container *ngIf="element.key == 'duplicate_files_check'">
<ng-container i18n="Clear duplicate files from DB">Clear duplicate files from DB:</ng-container>&nbsp;{{element.data.uids.length}}
</ng-container>
<ng-container *ngIf="element.key == 'youtubedl_update_check'">
<ng-container i18n="Update binary to">Update binary to:</ng-container>&nbsp;{{element.data}}
</ng-container>
</button>
</ng-container>
</div>
@@ -80,6 +87,7 @@
</div>
<button style="margin-top: 10px; margin-left: 5px;" mat-stroked-button (click)="openRestoreDBBackupDialog()" i18n="Restore DB from backup button">Restore DB from backup</button>
<button style="margin-top: 10px; margin-left: 5px;" mat-stroked-button (click)="resetTasks()" color="warn" i18n="Reset tasks button">Reset tasks</button>
</div>
<div *ngIf="(!tasks || tasks.length === 0) && tasks_retrieved">

View File

@@ -3,6 +3,7 @@ import { MatDialog } from '@angular/material/dialog';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { ConfirmDialogComponent } from 'app/dialogs/confirm-dialog/confirm-dialog.component';
import { RestoreDbDialogComponent } from 'app/dialogs/restore-db-dialog/restore-db-dialog.component';
import { UpdateTaskScheduleDialogComponent } from 'app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component';
import { PostsService } from 'app/posts.services';
@@ -125,6 +126,31 @@ export class TasksComponent implements OnInit {
})
}
resetTasks(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: {
dialogTitle: $localize`Reset tasks`,
dialogText: $localize`Would you like to reset your tasks? All your schedules will be removed as well.`,
submitText: $localize`Reset`,
warnSubmitColor: true
}
});
dialogRef.afterClosed().subscribe(confirmed => {
if (confirmed) {
this.postsService.resetTasks().subscribe(res => {
if (res['success']) {
this.postsService.openSnackBar($localize`Tasks successfully reset!`);
} else {
this.postsService.openSnackBar($localize`Failed to reset tasks!`);
}
}, err => {
this.postsService.openSnackBar($localize`Failed to reset tasks!`);
console.error(err);
});
}
});
}
}
export interface Task {

View File

@@ -591,6 +591,10 @@ export class PostsService implements CanActivate {
return this.http.post<SuccessObject>(this.path + 'getTasks', {}, this.httpOptions);
}
resetTasks() {
return this.http.post<SuccessObject>(this.path + 'resetTasks', {}, this.httpOptions);
}
getTask(task_key: string) {
const body: GetTaskRequest = {task_key: task_key};
return this.http.post<GetTaskResponse>(this.path + 'getTask', body, this.httpOptions);