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) => {
|
||||
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.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.hostDownloadAction = this.downloadAction = settings.first((m) => m.key === 'Gui:Default:HostDownloadAction')
|
||||
this.category = settings.find((m) => m.key === 'Gui:Default:Category')?.value as string;
|
||||
this.hostDownloadAction = this.downloadAction = settings.find((m) => m.key === 'Gui:Default:HostDownloadAction')
|
||||
?.value as number;
|
||||
this.downloadAction =
|
||||
settings.first((m) => m.key === 'Gui:Default:OnlyDownloadAvailableFiles')?.value === true ? 1 : 0;
|
||||
this.finishedAction = settings.first((m) => m.key === 'Gui:Default:FinishedAction')?.value as number;
|
||||
this.downloadMinSize = settings.first((m) => m.key === 'Gui:Default:MinFileSize')?.value as number;
|
||||
this.includeRegex = settings.first((m) => m.key === 'Gui:Default:IncludeRegex')?.value as string;
|
||||
this.excludeRegex = settings.first((m) => m.key === 'Gui:Default:ExcludeRegex')?.value as string;
|
||||
this.torrentRetryAttempts = settings.first((m) => m.key === 'Gui:Default:TorrentRetryAttempts')?.value as number;
|
||||
this.downloadRetryAttempts = settings.first((m) => m.key === 'Gui:Default:DownloadRetryAttempts')
|
||||
?.value as number;
|
||||
this.torrentDeleteOnError = settings.first((m) => m.key === 'Gui:Default:DeleteOnError')?.value as number;
|
||||
this.torrentLifetime = settings.first((m) => m.key === 'Gui:Default:TorrentLifetime')?.value as number;
|
||||
this.priority = settings.first((m) => m.key === 'Gui:Default:Priority')?.value as number;
|
||||
settings.find((m) => m.key === 'Gui:Default:OnlyDownloadAvailableFiles')?.value === true ? 1 : 0;
|
||||
this.finishedAction = settings.find((m) => m.key === 'Gui:Default:FinishedAction')?.value as number;
|
||||
this.downloadMinSize = settings.find((m) => m.key === 'Gui:Default:MinFileSize')?.value as number;
|
||||
this.includeRegex = settings.find((m) => m.key === 'Gui:Default:IncludeRegex')?.value as string;
|
||||
this.excludeRegex = settings.find((m) => m.key === 'Gui:Default:ExcludeRegex')?.value as string;
|
||||
this.torrentRetryAttempts = settings.find((m) => m.key === 'Gui:Default:TorrentRetryAttempts')?.value as number;
|
||||
this.downloadRetryAttempts = settings.find((m) => m.key === 'Gui:Default:DownloadRetryAttempts')?.value as number;
|
||||
this.torrentDeleteOnError = settings.find((m) => m.key === 'Gui:Default:DeleteOnError')?.value as number;
|
||||
this.torrentLifetime = settings.find((m) => m.key === 'Gui:Default:TorrentLifetime')?.value as number;
|
||||
this.priority = settings.find((m) => m.key === 'Gui:Default:Priority')?.value as number;
|
||||
|
||||
this.setFinishAction();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import 'curray';
|
||||
import { ClipboardModule } from '@angular/cdk/clipboard';
|
||||
import { APP_BASE_HREF } from '@angular/common';
|
||||
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
||||
|
|
|
|||
|
|
@ -39,10 +39,10 @@ export class SettingsComponent implements OnInit {
|
|||
|
||||
public reset(): void {
|
||||
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) {
|
||||
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 {
|
||||
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(
|
||||
() => {
|
||||
|
|
@ -67,8 +67,8 @@ export class SettingsComponent implements OnInit {
|
|||
|
||||
public testDownloadPath(): void {
|
||||
const settingDownloadPath = this.tabs
|
||||
.first((m) => m.key === 'DownloadClient')
|
||||
.settings.first((m) => m.key === 'DownloadClient:DownloadPath').value as string;
|
||||
.find((m) => m.key === 'DownloadClient')
|
||||
.settings.find((m) => m.key === 'DownloadClient:DownloadPath').value as string;
|
||||
|
||||
this.saving = true;
|
||||
this.testPathError = null;
|
||||
|
|
@ -121,11 +121,11 @@ export class SettingsComponent implements OnInit {
|
|||
|
||||
public testAria2cConnection(): void {
|
||||
const settingAria2cUrl = this.tabs
|
||||
.first((m) => m.key === 'DownloadClient')
|
||||
.settings.first((m) => m.key === 'DownloadClient:Aria2cUrl').value as string;
|
||||
.find((m) => m.key === 'DownloadClient')
|
||||
.settings.find((m) => m.key === 'DownloadClient:Aria2cUrl').value as string;
|
||||
const settingAria2cSecret = this.tabs
|
||||
.first((m) => m.key === 'DownloadClient')
|
||||
.settings.first((m) => m.key === 'DownloadClient:Aria2cSecret').value as string;
|
||||
.find((m) => m.key === 'DownloadClient')
|
||||
.settings.find((m) => m.key === 'DownloadClient:Aria2cSecret').value as string;
|
||||
|
||||
this.saving = true;
|
||||
this.testAria2cConnectionError = null;
|
||||
|
|
|
|||
|
|
@ -15,25 +15,25 @@ export class TorrentStatusPipe implements PipeTransform {
|
|||
}
|
||||
|
||||
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) {
|
||||
return 'Finished';
|
||||
}
|
||||
|
||||
const downloading = torrent.downloads.where((m) => m.downloadStarted && !m.downloadFinished && m.bytesDone > 0);
|
||||
const downloaded = torrent.downloads.where((m) => m.downloadFinished != null);
|
||||
const downloading = torrent.downloads.filter((m) => m.downloadStarted && !m.downloadFinished && m.bytesDone > 0);
|
||||
const downloaded = torrent.downloads.filter((m) => m.downloadFinished != null);
|
||||
|
||||
if (downloading.length > 0) {
|
||||
const bytesDone = downloading.sum((m) => m.bytesDone);
|
||||
const bytesTotal = downloading.sum((m) => m.bytesTotal);
|
||||
const bytesDone = downloading.reduce((sum, m) => sum + m.bytesDone, 0);
|
||||
const bytesTotal = downloading.reduce((sum, m) => sum + m.bytesTotal, 0);
|
||||
let progress = (bytesDone / bytesTotal) * 100;
|
||||
|
||||
if (isNaN(progress)) {
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
let allSpeeds = downloading.sum((m) => m.speed);
|
||||
let allSpeeds = downloading.reduce((sum, m) => sum + m.speed, 0);
|
||||
|
||||
let speed: string | string[] = '0';
|
||||
|
||||
|
|
@ -44,12 +44,12 @@ export class TorrentStatusPipe implements PipeTransform {
|
|||
} (${progress.toFixed(2)}% - ${speed}/s)`;
|
||||
}
|
||||
|
||||
const unpacking = torrent.downloads.where((m) => m.unpackingStarted && !m.unpackingFinished && m.bytesDone > 0);
|
||||
const unpacked = torrent.downloads.where((m) => m.unpackingFinished != null);
|
||||
const unpacking = torrent.downloads.filter((m) => m.unpackingStarted && !m.unpackingFinished && m.bytesDone > 0);
|
||||
const unpacked = torrent.downloads.filter((m) => m.unpackingFinished != null);
|
||||
|
||||
if (unpacking.length > 0) {
|
||||
const bytesDone = unpacking.sum((m) => m.bytesDone);
|
||||
const bytesTotal = unpacking.sum((m) => m.bytesTotal);
|
||||
const bytesDone = unpacking.reduce((sum, m) => sum + m.bytesDone, 0);
|
||||
const bytesTotal = unpacking.reduce((sum, m) => sum + m.bytesTotal, 0);
|
||||
let progress = (bytesDone / bytesTotal) * 100;
|
||||
|
||||
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) {
|
||||
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) {
|
||||
return `Queued for downloading`;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
<input
|
||||
type="checkbox"
|
||||
(click)="toggleSelect(torrent.torrentId)"
|
||||
[checked]="selectedTorrents.contains(torrent.torrentId)"
|
||||
[checked]="selectedTorrents.includes(torrent.torrentId)"
|
||||
/>
|
||||
</td>
|
||||
<td (click)="openTorrent(torrent.torrentId)" class="break-all">
|
||||
|
|
|
|||
|
|
@ -163,30 +163,40 @@ export class TorrentTableComponent implements OnInit {
|
|||
public changeSettingsModal(): void {
|
||||
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 =
|
||||
selectedTorrents.distinctBy((m) => m.downloadClient).count() == 1 ? selectedTorrents[0].downloadClient : null;
|
||||
this.updateSettingsHostDownloadAction =
|
||||
selectedTorrents.distinctBy((m) => m.hostDownloadAction).count() == 1
|
||||
? selectedTorrents[0].hostDownloadAction
|
||||
: null;
|
||||
this.updateSettingsCategory =
|
||||
selectedTorrents.distinctBy((m) => m.category).count() == 1 ? selectedTorrents[0].category : null;
|
||||
this.updateSettingsPriority =
|
||||
selectedTorrents.distinctBy((m) => m.priority).count() == 1 ? selectedTorrents[0].priority : null;
|
||||
this.updateSettingsDownloadRetryAttempts =
|
||||
selectedTorrents.distinctBy((m) => m.downloadRetryAttempts).count() == 1
|
||||
? selectedTorrents[0].downloadRetryAttempts
|
||||
: null;
|
||||
this.updateSettingsTorrentRetryAttempts =
|
||||
selectedTorrents.distinctBy((m) => m.torrentRetryAttempts).count() == 1
|
||||
? selectedTorrents[0].torrentRetryAttempts
|
||||
: null;
|
||||
this.updateSettingsDeleteOnError =
|
||||
selectedTorrents.distinctBy((m) => m.deleteOnError).count() == 1 ? selectedTorrents[0].deleteOnError : null;
|
||||
this.updateSettingsTorrentLifetime =
|
||||
selectedTorrents.distinctBy((m) => m.lifetime).count() == 1 ? selectedTorrents[0].lifetime : null;
|
||||
this.updateSettingsDownloadClient = selectedTorrents.every(
|
||||
(m, _, arr) => m.downloadClient === arr[0].downloadClient,
|
||||
)
|
||||
? selectedTorrents[0].downloadClient
|
||||
: null;
|
||||
this.updateSettingsHostDownloadAction = selectedTorrents.every(
|
||||
(m, _, arr) => m.hostDownloadAction === arr[0].hostDownloadAction,
|
||||
)
|
||||
? selectedTorrents[0].hostDownloadAction
|
||||
: null;
|
||||
this.updateSettingsCategory = selectedTorrents.every((m, _, arr) => m.category === arr[0].category)
|
||||
? selectedTorrents[0].category
|
||||
: null;
|
||||
this.updateSettingsPriority = selectedTorrents.every((m, _, arr) => m.priority === arr[0].priority)
|
||||
? selectedTorrents[0].priority
|
||||
: null;
|
||||
this.updateSettingsDownloadRetryAttempts = selectedTorrents.every(
|
||||
(m, _, arr) => m.downloadRetryAttempts === arr[0].downloadRetryAttempts,
|
||||
)
|
||||
? selectedTorrents[0].downloadRetryAttempts
|
||||
: 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;
|
||||
}
|
||||
|
|
@ -200,7 +210,7 @@ export class TorrentTableComponent implements OnInit {
|
|||
|
||||
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) => {
|
||||
if (this.updateSettingsDownloadClient != null) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ export class TorrentComponent implements OnInit {
|
|||
}
|
||||
|
||||
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) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue