mirror of https://github.com/Ombi-app/Ombi
Merge branch 'develop' of https://github.com/Ombi-app/Ombi into develop
commit
12e8559e86
File diff suppressed because one or more lines are too long
@ -1,124 +1,143 @@
|
||||
import { Component, Inject, OnInit } from "@angular/core";
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from "@angular/forms";
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
|
||||
import { SonarrFacade } from "app/state/sonarr";
|
||||
import { firstValueFrom, Observable } from "rxjs";
|
||||
import { startWith, map } from "rxjs/operators";
|
||||
import { ILanguageProfiles, IRadarrProfile, IRadarrRootFolder, ISonarrProfile, ISonarrRootFolder, IUserDropdown, RequestType } from "../../interfaces";
|
||||
import { IdentityService, RadarrService, SonarrService } from "../../services";
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { RadarrFacade } from 'app/state/radarr';
|
||||
import { SonarrFacade } from 'app/state/sonarr';
|
||||
import { firstValueFrom, Observable } from 'rxjs';
|
||||
import { startWith, map } from 'rxjs/operators';
|
||||
import {
|
||||
ILanguageProfiles,
|
||||
IRadarrProfile,
|
||||
IRadarrRootFolder,
|
||||
ISonarrProfile,
|
||||
ISonarrRootFolder,
|
||||
IUserDropdown,
|
||||
RequestType,
|
||||
} from '../../interfaces';
|
||||
import { IdentityService, RadarrService, SonarrService } from '../../services';
|
||||
|
||||
export interface IAdminRequestDialogData {
|
||||
type: RequestType,
|
||||
id: number
|
||||
type: RequestType;
|
||||
id: number;
|
||||
is4k: boolean | null;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: "admin-request-dialog",
|
||||
templateUrl: "admin-request-dialog.component.html",
|
||||
styleUrls: [ "admin-request-dialog.component.scss" ]
|
||||
selector: 'admin-request-dialog',
|
||||
templateUrl: 'admin-request-dialog.component.html',
|
||||
styleUrls: ['admin-request-dialog.component.scss'],
|
||||
})
|
||||
export class AdminRequestDialogComponent implements OnInit {
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<AdminRequestDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: IAdminRequestDialogData,
|
||||
private identityService: IdentityService,
|
||||
private sonarrService: SonarrService,
|
||||
private radarrService: RadarrService,
|
||||
private fb: UntypedFormBuilder,
|
||||
private sonarrFacade: SonarrFacade
|
||||
) {}
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<AdminRequestDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: IAdminRequestDialogData,
|
||||
private identityService: IdentityService,
|
||||
private sonarrService: SonarrService,
|
||||
private radarrService: RadarrService,
|
||||
private fb: UntypedFormBuilder,
|
||||
private sonarrFacade: SonarrFacade,
|
||||
private radarrFacade: RadarrFacade,
|
||||
) {}
|
||||
|
||||
public form: UntypedFormGroup;
|
||||
public RequestType = RequestType;
|
||||
public form: UntypedFormGroup;
|
||||
public RequestType = RequestType;
|
||||
|
||||
public options: IUserDropdown[];
|
||||
public filteredOptions: Observable<IUserDropdown[]>;
|
||||
public userId: string;
|
||||
public options: IUserDropdown[];
|
||||
public filteredOptions: Observable<IUserDropdown[]>;
|
||||
public userId: string;
|
||||
|
||||
public radarrEnabled: boolean;
|
||||
public sonarrEnabled: boolean;
|
||||
public radarrEnabled: boolean;
|
||||
public radarr4kEnabled: boolean;
|
||||
public sonarrEnabled: boolean;
|
||||
|
||||
public sonarrProfiles: ISonarrProfile[];
|
||||
public sonarrRootFolders: ISonarrRootFolder[];
|
||||
public sonarrLanguageProfiles: ILanguageProfiles[];
|
||||
public radarrProfiles: IRadarrProfile[];
|
||||
public radarrRootFolders: IRadarrRootFolder[];
|
||||
public sonarrProfiles: ISonarrProfile[];
|
||||
public sonarrRootFolders: ISonarrRootFolder[];
|
||||
public sonarrLanguageProfiles: ILanguageProfiles[];
|
||||
public radarrProfiles: IRadarrProfile[];
|
||||
public radarrRootFolders: IRadarrRootFolder[];
|
||||
|
||||
public async ngOnInit() {
|
||||
public async ngOnInit() {
|
||||
this.form = this.fb.group({
|
||||
username: [null],
|
||||
sonarrPathId: [null],
|
||||
sonarrFolderId: [null],
|
||||
sonarrLanguageId: [null],
|
||||
radarrPathId: [null],
|
||||
radarrFolderId: [null],
|
||||
});
|
||||
|
||||
this.form = this.fb.group({
|
||||
username: [null],
|
||||
sonarrPathId: [null],
|
||||
sonarrFolderId: [null],
|
||||
sonarrLanguageId: [null],
|
||||
radarrPathId: [null],
|
||||
radarrFolderId: [null]
|
||||
})
|
||||
this.options = await firstValueFrom(this.identityService.getUsersDropdown());
|
||||
|
||||
this.options = await firstValueFrom(this.identityService.getUsersDropdown());
|
||||
this.filteredOptions = this.form.controls['username'].valueChanges.pipe(
|
||||
startWith(''),
|
||||
map((value) => this._filter(value)),
|
||||
);
|
||||
|
||||
this.filteredOptions = this.form.controls['username'].valueChanges.pipe(
|
||||
startWith(""),
|
||||
map((value) => this._filter(value))
|
||||
);
|
||||
if (this.data.type === RequestType.tvShow) {
|
||||
this.sonarrEnabled = this.sonarrFacade.isEnabled();
|
||||
if (this.sonarrEnabled) {
|
||||
console.log(this.sonarrFacade.version());
|
||||
if (this.sonarrFacade.version()[0] === '3') {
|
||||
this.sonarrService.getV3LanguageProfilesWithoutSettings().subscribe((profiles: ILanguageProfiles[]) => {
|
||||
this.sonarrLanguageProfiles = profiles;
|
||||
});
|
||||
}
|
||||
this.sonarrService.getQualityProfilesWithoutSettings().subscribe((c) => {
|
||||
this.sonarrProfiles = c;
|
||||
});
|
||||
this.sonarrService.getRootFoldersWithoutSettings().subscribe((c) => {
|
||||
this.sonarrRootFolders = c;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.data.type === RequestType.movie) {
|
||||
this.radarrEnabled = this.radarrFacade.isEnabled();
|
||||
this.radarr4kEnabled = this.radarrFacade.is4KEnabled();
|
||||
|
||||
if (this.data.type === RequestType.tvShow) {
|
||||
this.sonarrEnabled = this.sonarrFacade.isEnabled();
|
||||
if (this.sonarrEnabled) {
|
||||
console.log(this.sonarrFacade.version());
|
||||
if (this.sonarrFacade.version()[0] === "3") {
|
||||
this.sonarrService.getV3LanguageProfilesWithoutSettings().subscribe((profiles: ILanguageProfiles[]) => {
|
||||
this.sonarrLanguageProfiles = profiles;
|
||||
})
|
||||
}
|
||||
this.sonarrService.getQualityProfilesWithoutSettings().subscribe(c => {
|
||||
this.sonarrProfiles = c;
|
||||
});
|
||||
this.sonarrService.getRootFoldersWithoutSettings().subscribe(c => {
|
||||
this.sonarrRootFolders = c;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.data.type === RequestType.movie) {
|
||||
this.radarrEnabled = await this.radarrService.isRadarrEnabled();
|
||||
if (this.radarrEnabled) {
|
||||
this.radarrService.getQualityProfilesFromSettings().subscribe(c => {
|
||||
this.radarrProfiles = c;
|
||||
});
|
||||
this.radarrService.getRootFoldersFromSettings().subscribe(c => {
|
||||
this.radarrRootFolders = c;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.data.is4k ?? false) {
|
||||
if (this.radarr4kEnabled) {
|
||||
this.radarrService.getQualityProfiles4kFromSettings().subscribe((c) => {
|
||||
this.radarrProfiles = c;
|
||||
});
|
||||
this.radarrService.getRootFolders4kFromSettings().subscribe((c) => {
|
||||
this.radarrRootFolders = c;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (this.radarrEnabled) {
|
||||
this.radarrService.getQualityProfilesFromSettings().subscribe((c) => {
|
||||
this.radarrProfiles = c;
|
||||
});
|
||||
this.radarrService.getRootFoldersFromSettings().subscribe((c) => {
|
||||
this.radarrRootFolders = c;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public displayFn(user: IUserDropdown): string {
|
||||
const username = user?.username ? user.username : "";
|
||||
const email = user?.email ? `(${user.email})` : "";
|
||||
if (username || email) {
|
||||
return `${username} ${email}`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
public displayFn(user: IUserDropdown): string {
|
||||
const username = user?.username ? user.username : '';
|
||||
const email = user?.email ? `(${user.email})` : '';
|
||||
if (username || email) {
|
||||
return `${username} ${email}`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
private _filter(value: string | IUserDropdown): IUserDropdown[] {
|
||||
const filterValue =
|
||||
typeof value === "string"
|
||||
? value.toLowerCase()
|
||||
: value.username.toLowerCase();
|
||||
private _filter(value: string | IUserDropdown): IUserDropdown[] {
|
||||
const filterValue = typeof value === 'string' ? value.toLowerCase() : value.username.toLowerCase();
|
||||
|
||||
return this.options.filter((option) =>
|
||||
option.username.toLowerCase().includes(filterValue)
|
||||
);
|
||||
}
|
||||
return this.options.filter((option) => option.username.toLowerCase().includes(filterValue));
|
||||
}
|
||||
|
||||
public async submitRequest() {
|
||||
const model = this.form.value;
|
||||
model.radarrQualityOverrideTitle = this.radarrProfiles?.filter(x => x.id == model.radarrPathId)[0]?.name;
|
||||
model.radarrRootFolderTitle = this.radarrRootFolders?.filter(x => x.id == model.radarrFolderId)[0]?.path;
|
||||
model.sonarrRootFolderTitle = this.sonarrRootFolders?.filter(x => x.id == model.sonarrFolderId)[0]?.path;
|
||||
model.sonarrQualityOverrideTitle = this.sonarrProfiles?.filter(x => x.id == model.sonarrPathId)[0]?.name;
|
||||
model.sonarrLanguageProfileTitle = this.sonarrLanguageProfiles?.filter(x => x.id == model.sonarrLanguageId)[0]?.name;
|
||||
this.dialogRef.close(model);
|
||||
}
|
||||
public async submitRequest() {
|
||||
const model = this.form.value;
|
||||
model.radarrQualityOverrideTitle = this.radarrProfiles?.filter((x) => x.id == model.radarrPathId)[0]?.name;
|
||||
model.radarrRootFolderTitle = this.radarrRootFolders?.filter((x) => x.id == model.radarrFolderId)[0]?.path;
|
||||
model.sonarrRootFolderTitle = this.sonarrRootFolders?.filter((x) => x.id == model.sonarrFolderId)[0]?.path;
|
||||
model.sonarrQualityOverrideTitle = this.sonarrProfiles?.filter((x) => x.id == model.sonarrPathId)[0]?.name;
|
||||
model.sonarrLanguageProfileTitle = this.sonarrLanguageProfiles?.filter((x) => x.id == model.sonarrLanguageId)[0]?.name;
|
||||
this.dialogRef.close(model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
export * from './radarr.state';
|
||||
export * from './radarr.actions';
|
||||
export * from './radarr.facade';
|
||||
export * from './radarr.selectors';
|
@ -0,0 +1,12 @@
|
||||
import { APP_INITIALIZER } from "@angular/core";
|
||||
import { Observable } from "rxjs";
|
||||
import { RadarrFacade } from "./radarr.facade";
|
||||
|
||||
export const RADARR_INITIALIZER = {
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: (radarrFacade: RadarrFacade) => (): Observable<unknown> => {
|
||||
return radarrFacade.load();
|
||||
},
|
||||
multi: true,
|
||||
deps: [RadarrFacade],
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
import { IRadarrCombined } from "../../interfaces";
|
||||
|
||||
export class LoadSettings {
|
||||
public static readonly type = '[Radarr] LoadSettings';
|
||||
}
|
||||
|
||||
export class UpdateSettings {
|
||||
public static readonly type = '[Radarr] UpdateSettings';
|
||||
constructor(public settings: IRadarrCombined) { }
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import { IRadarrCombined } from "../../interfaces";
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Observable } from "rxjs";
|
||||
import { Store } from "@ngxs/store";
|
||||
import { RadarrState } from "./types";
|
||||
import { RadarrSelectors } from "./radarr.selectors";
|
||||
import { LoadSettings, UpdateSettings } from "./radarr.actions";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RadarrFacade {
|
||||
|
||||
public constructor(private store: Store) {}
|
||||
|
||||
public state$ = (): Observable<RadarrState> => this.store.select(RadarrSelectors.state);
|
||||
|
||||
public updateSettings = (settings: IRadarrCombined): Observable<unknown> => this.store.dispatch(new UpdateSettings(settings));
|
||||
|
||||
public load = (): Observable<unknown> => this.store.dispatch(new LoadSettings());
|
||||
|
||||
public settings = (): IRadarrCombined => this.store.selectSnapshot(RadarrSelectors.settings);
|
||||
|
||||
public isEnabled = (): boolean => this.store.selectSnapshot(RadarrSelectors.isEnabled);
|
||||
|
||||
public is4KEnabled = (): boolean => this.store.selectSnapshot(RadarrSelectors.is4KEnabled);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
import { RadarrState, RADARR_STATE_TOKEN } from "./types";
|
||||
import { Selector } from "@ngxs/store";
|
||||
import { IRadarrCombined } from "../../interfaces";
|
||||
|
||||
export class RadarrSelectors {
|
||||
|
||||
@Selector([RADARR_STATE_TOKEN])
|
||||
public static state(state: RadarrState): RadarrState {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Selector([RadarrSelectors.state])
|
||||
public static settings(state: RadarrState): IRadarrCombined {
|
||||
return state.settings;
|
||||
}
|
||||
|
||||
@Selector([RadarrSelectors.settings])
|
||||
public static isEnabled(settings: IRadarrCombined): boolean {
|
||||
return settings?.radarr?.enabled ?? false;
|
||||
}
|
||||
|
||||
@Selector([RadarrSelectors.settings])
|
||||
public static is4KEnabled(settings: IRadarrCombined): boolean {
|
||||
return settings?.radarr4K?.enabled ?? false;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
import { Action, State, StateContext } from "@ngxs/store";
|
||||
|
||||
import { RadarrState, RADARR_STATE_TOKEN } from "./types";
|
||||
import { SettingsService } from "../../services";
|
||||
import { AuthService } from "../../auth/auth.service";
|
||||
import { Injectable } from "@angular/core";
|
||||
import { combineLatest, Observable, of } from "rxjs";
|
||||
import { map, tap } from "rxjs/operators";
|
||||
import { IRadarrCombined } from "../../interfaces";
|
||||
import { LoadSettings, UpdateSettings } from "./radarr.actions";
|
||||
|
||||
@State({
|
||||
name: RADARR_STATE_TOKEN
|
||||
})
|
||||
@Injectable()
|
||||
export class RadarrSettingsState {
|
||||
constructor(private settingsService: SettingsService, private authService: AuthService) { }
|
||||
|
||||
@Action(LoadSettings)
|
||||
public load({ setState }: StateContext<RadarrState>): Observable<RadarrState> {
|
||||
const isAdmin = this.authService.isAdmin();
|
||||
const calls = isAdmin ? [this.settingsService.getRadarr()] : [of({})];
|
||||
|
||||
return combineLatest(calls).pipe(
|
||||
tap(([settings]) =>
|
||||
{
|
||||
setState({settings: settings as IRadarrCombined});
|
||||
}),
|
||||
map((result) => <RadarrState>{settings: result[0]})
|
||||
);
|
||||
}
|
||||
|
||||
@Action(UpdateSettings)
|
||||
public enable(ctx: StateContext<RadarrState>, { settings }: UpdateSettings): Observable<RadarrState> {
|
||||
const state = ctx.getState();
|
||||
return this.settingsService.saveRadarr(settings).pipe(
|
||||
tap((_) => ctx.setState({...state, settings})),
|
||||
map(_ => <RadarrState>{...state, settings})
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import { IRadarrCombined } from "../../interfaces";
|
||||
import { StateToken } from "@ngxs/store";
|
||||
|
||||
export const RADARR_STATE_TOKEN = new StateToken<RadarrState>('RadarrState');
|
||||
|
||||
export interface RadarrState {
|
||||
settings: IRadarrCombined;
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"version": "4.33.0"
|
||||
"version": "4.35.1"
|
||||
}
|
Loading…
Reference in new issue