mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-28 07:30:56 +03:00
Added task settings
Added support for task errors Added support for lt, gt etc. db comparisons Added task to delete old files
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<h4 mat-dialog-title><ng-container i18n="Task settings">Task settings - {{task.title}}</ng-container></h4>
|
||||
|
||||
<mat-dialog-content>
|
||||
<div *ngIf="task_key === 'delete_old_files'">
|
||||
<mat-form-field color="accent">
|
||||
<mat-label i18n="Delete files older than">Delete files older than</mat-label>
|
||||
<input [(ngModel)]="new_options['threshold_days']" matInput required>
|
||||
<span matTextSuffix>days</span>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<mat-checkbox [(ngModel)]="new_options['auto_confirm']" i18n="Do not ask for confirmation">Do not ask for confirmation</mat-checkbox>
|
||||
</div>
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions>
|
||||
<button mat-button mat-dialog-close>
|
||||
<ng-container *ngIf="optionsChanged()" i18n="Task settings cancel button">Cancel</ng-container>
|
||||
<ng-container *ngIf="!optionsChanged()" i18n="Task settings close button">Close</ng-container>
|
||||
</button>
|
||||
<button mat-button [disabled]="!optionsChanged()" (click)="saveSettings()"><ng-container i18n="Save button">Save</ng-container></button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TaskSettingsComponent } from './task-settings.component';
|
||||
|
||||
describe('TaskSettingsComponent', () => {
|
||||
let component: TaskSettingsComponent;
|
||||
let fixture: ComponentFixture<TaskSettingsComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ TaskSettingsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(TaskSettingsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
46
src/app/components/task-settings/task-settings.component.ts
Normal file
46
src/app/components/task-settings/task-settings.component.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { Task } from 'api-types';
|
||||
import { PostsService } from 'app/posts.services';
|
||||
|
||||
@Component({
|
||||
selector: 'app-task-settings',
|
||||
templateUrl: './task-settings.component.html',
|
||||
styleUrls: ['./task-settings.component.scss']
|
||||
})
|
||||
export class TaskSettingsComponent {
|
||||
task_key: string;
|
||||
new_options = {};
|
||||
task: Task = null;
|
||||
|
||||
constructor(private postsService: PostsService, @Inject(MAT_DIALOG_DATA) public data: {task: Task}) {
|
||||
this.task_key = this.data.task.key;
|
||||
this.task = this.data.task;
|
||||
if (!this.task.options) {
|
||||
this.task.options = {};
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getSettings();
|
||||
}
|
||||
|
||||
getSettings(): void {
|
||||
this.postsService.getTask(this.task_key).subscribe(res => {
|
||||
this.task = res['task'];
|
||||
this.new_options = JSON.parse(JSON.stringify(this.task['options'])) || {};
|
||||
});
|
||||
}
|
||||
|
||||
saveSettings(): void {
|
||||
this.postsService.updateTaskOptions(this.task_key, this.new_options).subscribe(() => {
|
||||
this.getSettings();
|
||||
}, () => {
|
||||
this.getSettings();
|
||||
});
|
||||
}
|
||||
|
||||
optionsChanged(): boolean {
|
||||
return JSON.stringify(this.new_options) !== JSON.stringify(this.task.options);
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,9 @@
|
||||
<ng-container *ngIf="element.key == 'youtubedl_update_check'">
|
||||
<ng-container i18n="Update binary to">Update binary to:</ng-container> {{element.data}}
|
||||
</ng-container>
|
||||
<ng-container *ngIf="element.key == 'delete_old_files'">
|
||||
<ng-container i18n="Delete old files">Delete old files:</ng-container> {{element.data.uids.length}}
|
||||
</ng-container>
|
||||
</button>
|
||||
</ng-container>
|
||||
</div>
|
||||
@@ -71,6 +74,12 @@
|
||||
<div class="col-3">
|
||||
<button (click)="scheduleTask(element)" mat-icon-button matTooltip="Schedule" i18n-matTooltip="Schedule"><mat-icon>schedule</mat-icon></button>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<button (click)="openTaskSettings(element)" mat-icon-button matTooltip="Settings" i18n-matTooltip="Settings"><mat-icon>settings</mat-icon></button>
|
||||
</div>
|
||||
<div *ngIf="element.error" class="col-3">
|
||||
<button (click)="showError(element)" mat-icon-button matTooltip="Show error" i18n-matTooltip="Show error"><mat-icon>warning</mat-icon></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</mat-cell>
|
||||
@@ -80,7 +89,7 @@
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
|
||||
<mat-paginator [pageSizeOptions]="[5, 10, 20]"
|
||||
<mat-paginator [pageSizeOptions]="[10, 20]"
|
||||
showFirstLastButtons
|
||||
aria-label="Select page of tasks">
|
||||
</mat-paginator>
|
||||
|
||||
@@ -29,4 +29,8 @@ mat-header-cell, mat-cell {
|
||||
|
||||
.rounded {
|
||||
border-radius: 16px 16px 16px 16px !important;
|
||||
}
|
||||
|
||||
::ng-deep mat-row {
|
||||
height: fit-content !important;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { Component, EventEmitter, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
@@ -8,6 +8,8 @@ import { RestoreDbDialogComponent } from 'app/dialogs/restore-db-dialog/restore-
|
||||
import { UpdateTaskScheduleDialogComponent } from 'app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component';
|
||||
import { PostsService } from 'app/posts.services';
|
||||
import { Task } from 'api-types';
|
||||
import { TaskSettingsComponent } from '../task-settings/task-settings.component';
|
||||
import { Clipboard } from '@angular/cdk/clipboard';
|
||||
|
||||
@Component({
|
||||
selector: 'app-tasks',
|
||||
@@ -29,7 +31,7 @@ export class TasksComponent implements OnInit {
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
|
||||
constructor(private postsService: PostsService, private dialog: MatDialog) { }
|
||||
constructor(private postsService: PostsService, private dialog: MatDialog, private clipboard: Clipboard) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.postsService.initialized) {
|
||||
@@ -117,6 +119,14 @@ export class TasksComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
openTaskSettings(task: Task): void {
|
||||
this.dialog.open(TaskSettingsComponent, {
|
||||
data: {
|
||||
task: task
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getDBBackups(): void {
|
||||
this.postsService.getDBBackups().subscribe(res => {
|
||||
this.db_backups = res['db_backups'];
|
||||
@@ -157,4 +167,24 @@ export class TasksComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
showError(task: Task): void {
|
||||
const copyToClipboardEmitter = new EventEmitter<boolean>();
|
||||
this.dialog.open(ConfirmDialogComponent, {
|
||||
data: {
|
||||
dialogTitle: $localize`Error for: ${task['title']}`,
|
||||
dialogText: task['error'],
|
||||
submitText: $localize`Copy to clipboard`,
|
||||
cancelText: $localize`Close`,
|
||||
closeOnSubmit: false,
|
||||
onlyEmitOnDone: true,
|
||||
doneEmitter: copyToClipboardEmitter
|
||||
}
|
||||
});
|
||||
copyToClipboardEmitter.subscribe((done: boolean) => {
|
||||
if (done) {
|
||||
this.postsService.openSnackBar($localize`Copied to clipboard!`);
|
||||
this.clipboard.copy(task['error']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user