drop curray
use vanilla js array methods instead
This commit is contained in:
parent
9d0528902a
commit
ed354e93a9
7 changed files with 71 additions and 63 deletions
|
|
@ -59,25 +59,24 @@ export class AddNewTorrentComponent implements OnInit {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.settingsService.get().subscribe((settings) => {
|
this.settingsService.get().subscribe((settings) => {
|
||||||
const providerSetting = settings.first((m) => m.key === 'Provider:Provider');
|
const providerSetting = settings.find((m) => m.key === 'Provider:Provider');
|
||||||
this.provider = providerSetting.enumValues[providerSetting.value as number];
|
this.provider = providerSetting.enumValues[providerSetting.value as number];
|
||||||
this.downloadClient = settings.first((m) => m.key === 'DownloadClient:Client')?.value as number;
|
this.downloadClient = settings.find((m) => m.key === 'DownloadClient:Client')?.value as number;
|
||||||
|
|
||||||
this.category = settings.first((m) => m.key === 'Gui:Default:Category')?.value as string;
|
this.category = settings.find((m) => m.key === 'Gui:Default:Category')?.value as string;
|
||||||
this.hostDownloadAction = this.downloadAction = settings.first((m) => m.key === 'Gui:Default:HostDownloadAction')
|
this.hostDownloadAction = this.downloadAction = settings.find((m) => m.key === 'Gui:Default:HostDownloadAction')
|
||||||
?.value as number;
|
?.value as number;
|
||||||
this.downloadAction =
|
this.downloadAction =
|
||||||
settings.first((m) => m.key === 'Gui:Default:OnlyDownloadAvailableFiles')?.value === true ? 1 : 0;
|
settings.find((m) => m.key === 'Gui:Default:OnlyDownloadAvailableFiles')?.value === true ? 1 : 0;
|
||||||
this.finishedAction = settings.first((m) => m.key === 'Gui:Default:FinishedAction')?.value as number;
|
this.finishedAction = settings.find((m) => m.key === 'Gui:Default:FinishedAction')?.value as number;
|
||||||
this.downloadMinSize = settings.first((m) => m.key === 'Gui:Default:MinFileSize')?.value as number;
|
this.downloadMinSize = settings.find((m) => m.key === 'Gui:Default:MinFileSize')?.value as number;
|
||||||
this.includeRegex = settings.first((m) => m.key === 'Gui:Default:IncludeRegex')?.value as string;
|
this.includeRegex = settings.find((m) => m.key === 'Gui:Default:IncludeRegex')?.value as string;
|
||||||
this.excludeRegex = settings.first((m) => m.key === 'Gui:Default:ExcludeRegex')?.value as string;
|
this.excludeRegex = settings.find((m) => m.key === 'Gui:Default:ExcludeRegex')?.value as string;
|
||||||
this.torrentRetryAttempts = settings.first((m) => m.key === 'Gui:Default:TorrentRetryAttempts')?.value as number;
|
this.torrentRetryAttempts = settings.find((m) => m.key === 'Gui:Default:TorrentRetryAttempts')?.value as number;
|
||||||
this.downloadRetryAttempts = settings.first((m) => m.key === 'Gui:Default:DownloadRetryAttempts')
|
this.downloadRetryAttempts = settings.find((m) => m.key === 'Gui:Default:DownloadRetryAttempts')?.value as number;
|
||||||
?.value as number;
|
this.torrentDeleteOnError = settings.find((m) => m.key === 'Gui:Default:DeleteOnError')?.value as number;
|
||||||
this.torrentDeleteOnError = settings.first((m) => m.key === 'Gui:Default:DeleteOnError')?.value as number;
|
this.torrentLifetime = settings.find((m) => m.key === 'Gui:Default:TorrentLifetime')?.value as number;
|
||||||
this.torrentLifetime = settings.first((m) => m.key === 'Gui:Default:TorrentLifetime')?.value as number;
|
this.priority = settings.find((m) => m.key === 'Gui:Default:Priority')?.value as number;
|
||||||
this.priority = settings.first((m) => m.key === 'Gui:Default:Priority')?.value as number;
|
|
||||||
|
|
||||||
this.setFinishAction();
|
this.setFinishAction();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import 'curray';
|
|
||||||
import { ClipboardModule } from '@angular/cdk/clipboard';
|
import { ClipboardModule } from '@angular/cdk/clipboard';
|
||||||
import { APP_BASE_HREF } from '@angular/common';
|
import { APP_BASE_HREF } from '@angular/common';
|
||||||
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ export class SettingsComponent implements OnInit {
|
||||||
|
|
||||||
public reset(): void {
|
public reset(): void {
|
||||||
this.settingsService.get().subscribe((settings) => {
|
this.settingsService.get().subscribe((settings) => {
|
||||||
this.tabs = settings.where((m) => m.key.indexOf(':') === -1);
|
this.tabs = settings.filter((m) => m.key.indexOf(':') === -1);
|
||||||
|
|
||||||
for (let tab of this.tabs) {
|
for (let tab of this.tabs) {
|
||||||
tab.settings = settings.where((m) => m.key.indexOf(`${tab.key}:`) > -1);
|
tab.settings = settings.filter((m) => m.key.indexOf(`${tab.key}:`) > -1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,7 @@ export class SettingsComponent implements OnInit {
|
||||||
public ok(): void {
|
public ok(): void {
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
|
|
||||||
const settingsToSave = this.tabs.selectMany((m) => m.settings).where((m) => m.type !== 'Object');
|
const settingsToSave = this.tabs.flatMap((m) => m.settings).filter((m) => m.type !== 'Object');
|
||||||
|
|
||||||
this.settingsService.update(settingsToSave).subscribe(
|
this.settingsService.update(settingsToSave).subscribe(
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -67,8 +67,8 @@ export class SettingsComponent implements OnInit {
|
||||||
|
|
||||||
public testDownloadPath(): void {
|
public testDownloadPath(): void {
|
||||||
const settingDownloadPath = this.tabs
|
const settingDownloadPath = this.tabs
|
||||||
.first((m) => m.key === 'DownloadClient')
|
.find((m) => m.key === 'DownloadClient')
|
||||||
.settings.first((m) => m.key === 'DownloadClient:DownloadPath').value as string;
|
.settings.find((m) => m.key === 'DownloadClient:DownloadPath').value as string;
|
||||||
|
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
this.testPathError = null;
|
this.testPathError = null;
|
||||||
|
|
@ -121,11 +121,11 @@ export class SettingsComponent implements OnInit {
|
||||||
|
|
||||||
public testAria2cConnection(): void {
|
public testAria2cConnection(): void {
|
||||||
const settingAria2cUrl = this.tabs
|
const settingAria2cUrl = this.tabs
|
||||||
.first((m) => m.key === 'DownloadClient')
|
.find((m) => m.key === 'DownloadClient')
|
||||||
.settings.first((m) => m.key === 'DownloadClient:Aria2cUrl').value as string;
|
.settings.find((m) => m.key === 'DownloadClient:Aria2cUrl').value as string;
|
||||||
const settingAria2cSecret = this.tabs
|
const settingAria2cSecret = this.tabs
|
||||||
.first((m) => m.key === 'DownloadClient')
|
.find((m) => m.key === 'DownloadClient')
|
||||||
.settings.first((m) => m.key === 'DownloadClient:Aria2cSecret').value as string;
|
.settings.find((m) => m.key === 'DownloadClient:Aria2cSecret').value as string;
|
||||||
|
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
this.testAria2cConnectionError = null;
|
this.testAria2cConnectionError = null;
|
||||||
|
|
|
||||||
|
|
@ -15,25 +15,25 @@ export class TorrentStatusPipe implements PipeTransform {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (torrent.downloads.length > 0) {
|
if (torrent.downloads.length > 0) {
|
||||||
const allFinished = torrent.downloads.all((m) => m.completed != null);
|
const allFinished = torrent.downloads.every((m) => m.completed != null);
|
||||||
|
|
||||||
if (allFinished) {
|
if (allFinished) {
|
||||||
return 'Finished';
|
return 'Finished';
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloading = torrent.downloads.where((m) => m.downloadStarted && !m.downloadFinished && m.bytesDone > 0);
|
const downloading = torrent.downloads.filter((m) => m.downloadStarted && !m.downloadFinished && m.bytesDone > 0);
|
||||||
const downloaded = torrent.downloads.where((m) => m.downloadFinished != null);
|
const downloaded = torrent.downloads.filter((m) => m.downloadFinished != null);
|
||||||
|
|
||||||
if (downloading.length > 0) {
|
if (downloading.length > 0) {
|
||||||
const bytesDone = downloading.sum((m) => m.bytesDone);
|
const bytesDone = downloading.reduce((sum, m) => sum + m.bytesDone, 0);
|
||||||
const bytesTotal = downloading.sum((m) => m.bytesTotal);
|
const bytesTotal = downloading.reduce((sum, m) => sum + m.bytesTotal, 0);
|
||||||
let progress = (bytesDone / bytesTotal) * 100;
|
let progress = (bytesDone / bytesTotal) * 100;
|
||||||
|
|
||||||
if (isNaN(progress)) {
|
if (isNaN(progress)) {
|
||||||
progress = 0;
|
progress = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let allSpeeds = downloading.sum((m) => m.speed);
|
let allSpeeds = downloading.reduce((sum, m) => sum + m.speed, 0);
|
||||||
|
|
||||||
let speed: string | string[] = '0';
|
let speed: string | string[] = '0';
|
||||||
|
|
||||||
|
|
@ -44,12 +44,12 @@ export class TorrentStatusPipe implements PipeTransform {
|
||||||
} (${progress.toFixed(2)}% - ${speed}/s)`;
|
} (${progress.toFixed(2)}% - ${speed}/s)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unpacking = torrent.downloads.where((m) => m.unpackingStarted && !m.unpackingFinished && m.bytesDone > 0);
|
const unpacking = torrent.downloads.filter((m) => m.unpackingStarted && !m.unpackingFinished && m.bytesDone > 0);
|
||||||
const unpacked = torrent.downloads.where((m) => m.unpackingFinished != null);
|
const unpacked = torrent.downloads.filter((m) => m.unpackingFinished != null);
|
||||||
|
|
||||||
if (unpacking.length > 0) {
|
if (unpacking.length > 0) {
|
||||||
const bytesDone = unpacking.sum((m) => m.bytesDone);
|
const bytesDone = unpacking.reduce((sum, m) => sum + m.bytesDone, 0);
|
||||||
const bytesTotal = unpacking.sum((m) => m.bytesTotal);
|
const bytesTotal = unpacking.reduce((sum, m) => sum + m.bytesTotal, 0);
|
||||||
let progress = (bytesDone / bytesTotal) * 100;
|
let progress = (bytesDone / bytesTotal) * 100;
|
||||||
|
|
||||||
if (isNaN(progress)) {
|
if (isNaN(progress)) {
|
||||||
|
|
@ -61,13 +61,13 @@ export class TorrentStatusPipe implements PipeTransform {
|
||||||
)}%)`;
|
)}%)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const queuedForUnpacking = torrent.downloads.where((m) => m.unpackingQueued && !m.unpackingStarted);
|
const queuedForUnpacking = torrent.downloads.filter((m) => m.unpackingQueued && !m.unpackingStarted);
|
||||||
|
|
||||||
if (queuedForUnpacking.length > 0) {
|
if (queuedForUnpacking.length > 0) {
|
||||||
return `Queued for unpacking`;
|
return `Queued for unpacking`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const queuedForDownload = torrent.downloads.where((m) => !m.downloadStarted && !m.downloadFinished);
|
const queuedForDownload = torrent.downloads.filter((m) => !m.downloadStarted && !m.downloadFinished);
|
||||||
|
|
||||||
if (queuedForDownload.length > 0) {
|
if (queuedForDownload.length > 0) {
|
||||||
return `Queued for downloading`;
|
return `Queued for downloading`;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
(click)="toggleSelect(torrent.torrentId)"
|
(click)="toggleSelect(torrent.torrentId)"
|
||||||
[checked]="selectedTorrents.contains(torrent.torrentId)"
|
[checked]="selectedTorrents.includes(torrent.torrentId)"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td (click)="openTorrent(torrent.torrentId)" class="break-all">
|
<td (click)="openTorrent(torrent.torrentId)" class="break-all">
|
||||||
|
|
|
||||||
|
|
@ -163,30 +163,40 @@ export class TorrentTableComponent implements OnInit {
|
||||||
public changeSettingsModal(): void {
|
public changeSettingsModal(): void {
|
||||||
this.changeSettingsError = null;
|
this.changeSettingsError = null;
|
||||||
|
|
||||||
const selectedTorrents = this.torrents.where((m) => this.selectedTorrents.indexOf(m.torrentId) > -1);
|
const selectedTorrents = this.torrents.filter((m) => this.selectedTorrents.indexOf(m.torrentId) > -1);
|
||||||
|
|
||||||
this.updateSettingsDownloadClient =
|
this.updateSettingsDownloadClient = selectedTorrents.every(
|
||||||
selectedTorrents.distinctBy((m) => m.downloadClient).count() == 1 ? selectedTorrents[0].downloadClient : null;
|
(m, _, arr) => m.downloadClient === arr[0].downloadClient,
|
||||||
this.updateSettingsHostDownloadAction =
|
)
|
||||||
selectedTorrents.distinctBy((m) => m.hostDownloadAction).count() == 1
|
? selectedTorrents[0].downloadClient
|
||||||
? selectedTorrents[0].hostDownloadAction
|
: null;
|
||||||
: null;
|
this.updateSettingsHostDownloadAction = selectedTorrents.every(
|
||||||
this.updateSettingsCategory =
|
(m, _, arr) => m.hostDownloadAction === arr[0].hostDownloadAction,
|
||||||
selectedTorrents.distinctBy((m) => m.category).count() == 1 ? selectedTorrents[0].category : null;
|
)
|
||||||
this.updateSettingsPriority =
|
? selectedTorrents[0].hostDownloadAction
|
||||||
selectedTorrents.distinctBy((m) => m.priority).count() == 1 ? selectedTorrents[0].priority : null;
|
: null;
|
||||||
this.updateSettingsDownloadRetryAttempts =
|
this.updateSettingsCategory = selectedTorrents.every((m, _, arr) => m.category === arr[0].category)
|
||||||
selectedTorrents.distinctBy((m) => m.downloadRetryAttempts).count() == 1
|
? selectedTorrents[0].category
|
||||||
? selectedTorrents[0].downloadRetryAttempts
|
: null;
|
||||||
: null;
|
this.updateSettingsPriority = selectedTorrents.every((m, _, arr) => m.priority === arr[0].priority)
|
||||||
this.updateSettingsTorrentRetryAttempts =
|
? selectedTorrents[0].priority
|
||||||
selectedTorrents.distinctBy((m) => m.torrentRetryAttempts).count() == 1
|
: null;
|
||||||
? selectedTorrents[0].torrentRetryAttempts
|
this.updateSettingsDownloadRetryAttempts = selectedTorrents.every(
|
||||||
: null;
|
(m, _, arr) => m.downloadRetryAttempts === arr[0].downloadRetryAttempts,
|
||||||
this.updateSettingsDeleteOnError =
|
)
|
||||||
selectedTorrents.distinctBy((m) => m.deleteOnError).count() == 1 ? selectedTorrents[0].deleteOnError : null;
|
? selectedTorrents[0].downloadRetryAttempts
|
||||||
this.updateSettingsTorrentLifetime =
|
: null;
|
||||||
selectedTorrents.distinctBy((m) => m.lifetime).count() == 1 ? selectedTorrents[0].lifetime : null;
|
this.updateSettingsTorrentRetryAttempts = selectedTorrents.every(
|
||||||
|
(m, _, arr) => m.torrentRetryAttempts === arr[0].torrentRetryAttempts,
|
||||||
|
)
|
||||||
|
? selectedTorrents[0].torrentRetryAttempts
|
||||||
|
: null;
|
||||||
|
this.updateSettingsDeleteOnError = selectedTorrents.every((m, _, arr) => m.deleteOnError === arr[0].deleteOnError)
|
||||||
|
? selectedTorrents[0].deleteOnError
|
||||||
|
: null;
|
||||||
|
this.updateSettingsTorrentLifetime = selectedTorrents.every((m, _, arr) => m.lifetime === arr[0].lifetime)
|
||||||
|
? selectedTorrents[0].lifetime
|
||||||
|
: null;
|
||||||
|
|
||||||
this.isChangeSettingsModalActive = true;
|
this.isChangeSettingsModalActive = true;
|
||||||
}
|
}
|
||||||
|
|
@ -200,7 +210,7 @@ export class TorrentTableComponent implements OnInit {
|
||||||
|
|
||||||
let calls: Observable<void>[] = [];
|
let calls: Observable<void>[] = [];
|
||||||
|
|
||||||
const selectedTorrents = this.torrents.where((m) => this.selectedTorrents.indexOf(m.torrentId) > -1);
|
const selectedTorrents = this.torrents.filter((m) => this.selectedTorrents.indexOf(m.torrentId) > -1);
|
||||||
|
|
||||||
selectedTorrents.forEach((torrent) => {
|
selectedTorrents.forEach((torrent) => {
|
||||||
if (this.updateSettingsDownloadClient != null) {
|
if (this.updateSettingsDownloadClient != null) {
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ export class TorrentComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public update(torrents: Torrent[]): void {
|
public update(torrents: Torrent[]): void {
|
||||||
const updatedTorrent = torrents.firstOrDefault((m) => m.torrentId === this.torrent.torrentId);
|
const updatedTorrent = torrents.find((m) => m.torrentId === this.torrent.torrentId);
|
||||||
|
|
||||||
if (updatedTorrent == null) {
|
if (updatedTorrent == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue