Update torrent-table.component.ts

Added retry selected
Added change selected's settings
This commit is contained in:
7go4bs9h 2023-08-24 03:10:06 -04:00 committed by GitHub
parent 71b5ab5406
commit 2d73981314
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,8 +10,10 @@ import { forkJoin, Observable } from 'rxjs';
styleUrls: ['./torrent-table.component.scss'], styleUrls: ['./torrent-table.component.scss'],
}) })
export class TorrentTableComponent implements OnInit { export class TorrentTableComponent implements OnInit {
public torrent: Torrent;
public torrents: Torrent[] = []; public torrents: Torrent[] = [];
public selectedTorrents: string[] = []; public selectedTorrents: string[] = [];
public selectedTorrentsAsObjects: Torrent[] = []
public error: string; public error: string;
public isDeleteModalActive: boolean; public isDeleteModalActive: boolean;
@ -20,6 +22,21 @@ export class TorrentTableComponent implements OnInit {
public deleteData: boolean; public deleteData: boolean;
public deleteRdTorrent: boolean; public deleteRdTorrent: boolean;
public deleteLocalFiles: boolean; public deleteLocalFiles: boolean;
public isRetryModalActive: boolean;
public retryError: string;
public retrying: boolean;
public isUpdateSettingsModalActive: boolean;
public updateSettingsCategory: string;
public updateSettingsPriority: number;
public updateSettingsDownloadRetryAttempts: number;
public updateSettingsTorrentRetryAttempts: number;
public updateSettingsDeleteOnError: number;
public updateSettingsTorrentLifetime: number;
public updateError: string;
public updating: boolean;
constructor(private router: Router, private torrentService: TorrentService) {} constructor(private router: Router, private torrentService: TorrentService) {}
@ -65,34 +82,34 @@ export class TorrentTableComponent implements OnInit {
this.selectedTorrents.push(torrentId); this.selectedTorrents.push(torrentId);
} }
} }
public showDeleteModal(): void { public showDeleteModal(): void {
this.deleteData = false; this.deleteData = false;
this.deleteRdTorrent = false; this.deleteRdTorrent = false;
this.deleteLocalFiles = false; this.deleteLocalFiles = false;
this.deleteError = null; this.deleteError = null;
this.isDeleteModalActive = true; this.isDeleteModalActive = true;
} }
public deleteCancel(): void { public deleteCancel(): void {
this.isDeleteModalActive = false; this.isDeleteModalActive = false;
} }
public deleteOk(): void { public deleteOk(): void {
this.deleting = true; this.deleting = true;
let calls: Observable<void>[] = []; let calls: Observable<void>[] = [];
this.selectedTorrents.forEach((torrentId) => { this.selectedTorrents.forEach((torrentId) => {
calls.push(this.torrentService.delete(torrentId, this.deleteData, this.deleteRdTorrent, this.deleteLocalFiles)); calls.push(this.torrentService.delete(torrentId, this.deleteData, this.deleteRdTorrent, this.deleteLocalFiles));
}); });
forkJoin(calls).subscribe({ forkJoin(calls).subscribe({
complete: () => { complete: () => {
this.isDeleteModalActive = false; this.isDeleteModalActive = false;
this.deleting = false; this.deleting = false;
this.selectedTorrents = []; this.selectedTorrents = [];
}, },
error: (err) => { error: (err) => {
@ -101,4 +118,104 @@ export class TorrentTableComponent implements OnInit {
}, },
}); });
} }
public showRetryModal(): void {
this.retryError = null;
this.isRetryModalActive = true;
}
public retryCancel(): void {
this.isRetryModalActive = false;
}
public retryOk(): void {
this.retrying = true;
let calls: Observable<void>[] = [];
this.selectedTorrents.forEach((torrentId) => {
calls.push(this.torrentService.retry(torrentId));
})
forkJoin(calls).subscribe({
complete: () => {
this.isRetryModalActive = false;
this.retrying = false;
this.selectedTorrents = [];
},
error: (err) => {
this.retryError = err.error;
this.retrying = false;
},
});
}
public getSameValueOrNull(key: string): any {
let newValue: any = null
this.selectedTorrentsAsObjects.forEach((t, i) => {
type ObjectKey = keyof typeof t;
const myVar = key as ObjectKey;
const currentValue = t[myVar]
if (i == 0) {
newValue = currentValue
} else {
if (newValue != currentValue) {
newValue = null
}
}
})
return newValue
}
public showUpdateSettingsModal(): void {
this.selectedTorrentsAsObjects = this.torrents.filter(t => this.selectedTorrents.includes(t.torrentId))
this.updateSettingsCategory = this.getSameValueOrNull('category')
this.updateSettingsPriority = this.getSameValueOrNull('priority');
this.updateSettingsDownloadRetryAttempts = this.getSameValueOrNull('downloadRetryAttempts');
this.updateSettingsTorrentRetryAttempts = this.getSameValueOrNull('torrentRetryAttempts');
this.updateSettingsDeleteOnError = this.getSameValueOrNull('deleteOnError');
this.updateSettingsTorrentLifetime = this.getSameValueOrNull('lifetime');
this.isUpdateSettingsModalActive = true;
}
public updateSettingsCancel(): void {
this.isUpdateSettingsModalActive = false;
}
public updateSettingsOk(): void {
this.updating = true;
let calls: Observable<void>[] = [];
this.selectedTorrentsAsObjects.forEach((torrent) => {
torrent.category = this.updateSettingsCategory;
torrent.priority = this.updateSettingsPriority;
torrent.downloadRetryAttempts = this.updateSettingsDownloadRetryAttempts;
torrent.torrentRetryAttempts = this.updateSettingsTorrentRetryAttempts;
torrent.deleteOnError = this.updateSettingsDeleteOnError;
torrent.lifetime = this.updateSettingsTorrentLifetime;
calls.push(this.torrentService.update(torrent));
})
forkJoin(calls).subscribe({
complete: () => {
this.isUpdateSettingsModalActive = false;
this.updating = false;
this.selectedTorrents = [];
},
error: (err) => {
this.updateError = err.error;
this.updating = false;
},
});
}
} }