Updated the settings page to hide the Remove Torrent From Provider options when the Download Client Symlink is selected
Defaulted to Remove Torrent From Client when Symlink is selected apart from if No Action is already selected
This commit is contained in:
parent
ee0a631cd9
commit
b87d763ce3
3 changed files with 99 additions and 1 deletions
|
|
@ -6,4 +6,5 @@ export class Setting {
|
||||||
type: string;
|
type: string;
|
||||||
settings: Setting[];
|
settings: Setting[];
|
||||||
enumValues: { [key: string]: string };
|
enumValues: { [key: string]: string };
|
||||||
|
originalEnumValues?: { [key: string]: string };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
{{ setting.displayName }}
|
{{ setting.displayName }}
|
||||||
</label>
|
</label>
|
||||||
<div class="control select is-fullwidth" *ngSwitchCase="'Enum'">
|
<div class="control select is-fullwidth" *ngSwitchCase="'Enum'">
|
||||||
<select [(ngModel)]="setting.value">
|
<select [(ngModel)]="setting.value" (ngModelChange)="onDownloadClientChange(setting.value, setting.key)">
|
||||||
<option [value]="kvp.key" *ngFor="let kvp of setting.enumValues | keyvalue">{{ kvp.value }}</option>
|
<option [value]="kvp.key" *ngFor="let kvp of setting.enumValues | keyvalue">{{ kvp.value }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@ import { Component, OnInit } from '@angular/core';
|
||||||
import { SettingsService } from 'src/app/settings.service';
|
import { SettingsService } from 'src/app/settings.service';
|
||||||
import { Setting } from '../models/setting.model';
|
import { Setting } from '../models/setting.model';
|
||||||
|
|
||||||
|
type Value = string | number | boolean;
|
||||||
|
|
||||||
|
interface Tab {
|
||||||
|
key: string;
|
||||||
|
settings: Setting[];
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-settings',
|
selector: 'app-settings',
|
||||||
templateUrl: './settings.component.html',
|
templateUrl: './settings.component.html',
|
||||||
|
|
@ -27,6 +34,17 @@ export class SettingsComponent implements OnInit {
|
||||||
public testAria2cConnectionError: string = null;
|
public testAria2cConnectionError: string = null;
|
||||||
public testAria2cConnectionSuccess: string = null;
|
public testAria2cConnectionSuccess: string = null;
|
||||||
|
|
||||||
|
readonly DOWNLOAD_CLIENT = 'DownloadClient';
|
||||||
|
readonly DOWNLOAD_CLIENT_KEY = 'DownloadClient:Client';
|
||||||
|
readonly SETTINGS_SECTION_NAMES = ["Provider", "Integrations", "Gui", "Watch"];
|
||||||
|
readonly FINISHED_ACTION_KEY = ":Default:FinishedAction";
|
||||||
|
readonly NO_ACTION = "0";
|
||||||
|
readonly SYMLINK_VALUE = "2";
|
||||||
|
readonly POST_PROCESS_CLIENT_VALUE = "3";
|
||||||
|
readonly REMOVE_PROVIDER_VALUE = "1";
|
||||||
|
readonly REMOVE_PROVIDER_AND_CLIENT_VALUE = "2";
|
||||||
|
readonly HIDDEN_VALUES_ARRAY = [this.REMOVE_PROVIDER_VALUE, this.REMOVE_PROVIDER_AND_CLIENT_VALUE];
|
||||||
|
|
||||||
constructor(private settingsService: SettingsService) {}
|
constructor(private settingsService: SettingsService) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
@ -40,6 +58,7 @@ export class SettingsComponent implements OnInit {
|
||||||
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.where((m) => m.key.indexOf(`${tab.key}:`) > -1);
|
||||||
}
|
}
|
||||||
|
this.updateDownloadClientValue();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,4 +157,82 @@ export class SettingsComponent implements OnInit {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getProviderDefaultTab(sectionName:string){
|
||||||
|
return this.tabs.find((m) => m.key === sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPostDownloadAction(providerDefaultTab: Tab | undefined, sectionName:string): Setting | undefined {
|
||||||
|
return providerDefaultTab?.settings.find((m) => m.key === `${sectionName}${this.FINISHED_ACTION_KEY}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getAllPostDownloadActions(sectionName: string){
|
||||||
|
const providerDefaultTab = this.getProviderDefaultTab(sectionName);
|
||||||
|
return this.getPostDownloadAction(providerDefaultTab, sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public onDownloadClientChange(value: Value, key: string): void {
|
||||||
|
if (this.isDownloadClientKey(key)) {
|
||||||
|
this.toggleRemoveTorrentFromProvider(value);
|
||||||
|
console.log("Value: ", value);
|
||||||
|
this.updatePostDownloadAction(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateDownloadClientValue(): void {
|
||||||
|
const downloadClientValue = this.tabs
|
||||||
|
.find((m) => m.key === this.DOWNLOAD_CLIENT)
|
||||||
|
?.settings.find((m) => m.key === this.DOWNLOAD_CLIENT_KEY)?.value;
|
||||||
|
this.onDownloadClientChange(downloadClientValue.toString(), this.DOWNLOAD_CLIENT_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private isDownloadClientKey(key: string): boolean {
|
||||||
|
return key === this.DOWNLOAD_CLIENT_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private toggleRemoveTorrentFromProvider(value: Value): void {
|
||||||
|
if (value === this.SYMLINK_VALUE) {
|
||||||
|
this.removeHiddenValues();
|
||||||
|
} else {
|
||||||
|
this.addHiddenValues();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleEnumValues(postDownloadAction: Setting) {
|
||||||
|
if (postDownloadAction.originalEnumValues === undefined) {
|
||||||
|
postDownloadAction.originalEnumValues = {...postDownloadAction.enumValues};
|
||||||
|
} else {
|
||||||
|
postDownloadAction.enumValues = {...postDownloadAction.originalEnumValues};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private addHiddenValues(): void {
|
||||||
|
this.SETTINGS_SECTION_NAMES.forEach((sectionName) => {
|
||||||
|
let postDownloadAction = this.getAllPostDownloadActions(sectionName);
|
||||||
|
if (postDownloadAction != null){
|
||||||
|
this.handleEnumValues(postDownloadAction);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeHiddenValues(): void {
|
||||||
|
this.SETTINGS_SECTION_NAMES.forEach((sectionName) => {
|
||||||
|
let postDownloadAction = this.getAllPostDownloadActions(sectionName);
|
||||||
|
if (postDownloadAction != null) {
|
||||||
|
postDownloadAction.originalEnumValues = { ...postDownloadAction.enumValues };
|
||||||
|
this.HIDDEN_VALUES_ARRAY.forEach((hiddenValue) => {
|
||||||
|
delete postDownloadAction.enumValues[hiddenValue];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private updatePostDownloadAction(value: Value): void {
|
||||||
|
this.SETTINGS_SECTION_NAMES.forEach((sectionName) => {
|
||||||
|
let postDownloadAction = this.getAllPostDownloadActions(sectionName);
|
||||||
|
if (postDownloadAction && value === this.SYMLINK_VALUE && postDownloadAction.value.toString() !== this.NO_ACTION) {
|
||||||
|
postDownloadAction.value = this.POST_PROCESS_CLIENT_VALUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue