mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-24 06:55:23 -07:00
added state
This commit is contained in:
parent
1e0b355731
commit
0b620f7da4
13 changed files with 187 additions and 40 deletions
|
@ -14,6 +14,7 @@ import { BrowserModule } from "@angular/platform-browser";
|
||||||
import { ButtonModule } from "primeng/button";
|
import { ButtonModule } from "primeng/button";
|
||||||
import { CUSTOMIZATION_INITIALIZER } from "./state/customization/customization-initializer";
|
import { CUSTOMIZATION_INITIALIZER } from "./state/customization/customization-initializer";
|
||||||
import { SONARR_INITIALIZER } from "./state/sonarr/sonarr-initializer";
|
import { SONARR_INITIALIZER } from "./state/sonarr/sonarr-initializer";
|
||||||
|
import { RADARR_INITIALIZER } from "./state/radarr/radarr-initializer";
|
||||||
import { ConfirmDialogModule } from "primeng/confirmdialog";
|
import { ConfirmDialogModule } from "primeng/confirmdialog";
|
||||||
import { CookieComponent } from "./auth/cookie.component";
|
import { CookieComponent } from "./auth/cookie.component";
|
||||||
import { CookieService } from "ng2-cookies";
|
import { CookieService } from "ng2-cookies";
|
||||||
|
@ -24,6 +25,7 @@ import { DialogModule } from "primeng/dialog";
|
||||||
import { FEATURES_INITIALIZER } from "./state/features/features-initializer";
|
import { FEATURES_INITIALIZER } from "./state/features/features-initializer";
|
||||||
import { FeatureState } from "./state/features";
|
import { FeatureState } from "./state/features";
|
||||||
import { SonarrSettingsState } from "./state/sonarr";
|
import { SonarrSettingsState } from "./state/sonarr";
|
||||||
|
import { RadarrSettingsState } from "./state/radarr";
|
||||||
import { JwtModule } from "@auth0/angular-jwt";
|
import { JwtModule } from "@auth0/angular-jwt";
|
||||||
import { LandingPageComponent } from "./landingpage/landingpage.component";
|
import { LandingPageComponent } from "./landingpage/landingpage.component";
|
||||||
import { LandingPageService } from "./services";
|
import { LandingPageService } from "./services";
|
||||||
|
@ -163,7 +165,7 @@ export function JwtTokenGetter() {
|
||||||
}),
|
}),
|
||||||
SidebarModule,
|
SidebarModule,
|
||||||
MatNativeDateModule, MatIconModule, MatSidenavModule, MatListModule, MatToolbarModule, LayoutModule, MatSlideToggleModule,
|
MatNativeDateModule, MatIconModule, MatSidenavModule, MatListModule, MatToolbarModule, LayoutModule, MatSlideToggleModule,
|
||||||
NgxsModule.forRoot([CustomizationState, FeatureState, SonarrSettingsState], {
|
NgxsModule.forRoot([CustomizationState, FeatureState, SonarrSettingsState, RadarrSettingsState], {
|
||||||
developmentMode: !environment.production,
|
developmentMode: !environment.production,
|
||||||
}),
|
}),
|
||||||
...environment.production ? [] :
|
...environment.production ? [] :
|
||||||
|
@ -212,6 +214,7 @@ export function JwtTokenGetter() {
|
||||||
FEATURES_INITIALIZER,
|
FEATURES_INITIALIZER,
|
||||||
SONARR_INITIALIZER,
|
SONARR_INITIALIZER,
|
||||||
CUSTOMIZATION_INITIALIZER,
|
CUSTOMIZATION_INITIALIZER,
|
||||||
|
RADARR_INITIALIZER,
|
||||||
{
|
{
|
||||||
provide: APP_BASE_HREF,
|
provide: APP_BASE_HREF,
|
||||||
useValue: window["baseHref"]
|
useValue: window["baseHref"]
|
||||||
|
|
|
@ -6,14 +6,13 @@ import { TranslateService } from "@ngx-translate/core";
|
||||||
import { APP_BASE_HREF } from "@angular/common";
|
import { APP_BASE_HREF } from "@angular/common";
|
||||||
import { AuthService } from "../auth/auth.service";
|
import { AuthService } from "../auth/auth.service";
|
||||||
import { IAuthenticationSettings, ICustomizationSettings } from "../interfaces";
|
import { IAuthenticationSettings, ICustomizationSettings } from "../interfaces";
|
||||||
import { PlexTvService } from "../services";
|
import { PlexTvService, StatusService, SettingsService } from "../services";
|
||||||
import { SettingsService } from "../services";
|
|
||||||
import { StatusService } from "../services";
|
|
||||||
|
|
||||||
import { StorageService } from "../shared/storage/storage-service";
|
import { StorageService } from "../shared/storage/storage-service";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
import { MatSnackBar } from "@angular/material/snack-bar";
|
||||||
import { CustomizationFacade } from "../state/customization";
|
import { CustomizationFacade } from "../state/customization";
|
||||||
import { SonarrFacade } from "app/state/sonarr";
|
import { SonarrFacade } from "app/state/sonarr";
|
||||||
|
import { RadarrFacade } from "app/state/radarr";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: "./login.component.html",
|
templateUrl: "./login.component.html",
|
||||||
|
@ -62,6 +61,7 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
private plexTv: PlexTvService,
|
private plexTv: PlexTvService,
|
||||||
private store: StorageService,
|
private store: StorageService,
|
||||||
private sonarrFacade: SonarrFacade,
|
private sonarrFacade: SonarrFacade,
|
||||||
|
private radarrFacade: RadarrFacade,
|
||||||
private readonly notify: MatSnackBar
|
private readonly notify: MatSnackBar
|
||||||
) {
|
) {
|
||||||
this.href = href;
|
this.href = href;
|
||||||
|
@ -89,7 +89,7 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (authService.loggedIn()) {
|
if (authService.loggedIn()) {
|
||||||
this.router.navigate(["/"]);
|
this.loadStores();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
if (this.authService.loggedIn()) {
|
if (this.authService.loggedIn()) {
|
||||||
this.ngOnDestroy();
|
this.ngOnDestroy();
|
||||||
this.sonarrFacade.load().subscribe();
|
this.loadStores();
|
||||||
this.router.navigate(["/"]);
|
this.router.navigate(["/"]);
|
||||||
} else {
|
} else {
|
||||||
this.notify.open(this.errorBody, "OK", {
|
this.notify.open(this.errorBody, "OK", {
|
||||||
|
@ -221,7 +221,7 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
this.oAuthWindow.close();
|
this.oAuthWindow.close();
|
||||||
}
|
}
|
||||||
this.oauthLoading = false;
|
this.oauthLoading = false;
|
||||||
this.sonarrFacade.load().subscribe();
|
this.loadStores();
|
||||||
this.router.navigate(["search"]);
|
this.router.navigate(["search"]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
if (this.authService.loggedIn()) {
|
if (this.authService.loggedIn()) {
|
||||||
this.ngOnDestroy();
|
this.ngOnDestroy();
|
||||||
this.sonarrFacade.load().subscribe();
|
this.loadStores();
|
||||||
this.router.navigate(["/"]);
|
this.router.navigate(["/"]);
|
||||||
} else {
|
} else {
|
||||||
this.notify.open(this.errorBody, "OK", {
|
this.notify.open(this.errorBody, "OK", {
|
||||||
|
@ -274,4 +274,9 @@ export class LoginComponent implements OnDestroy, OnInit {
|
||||||
public ngOnDestroy() {
|
public ngOnDestroy() {
|
||||||
clearInterval(this.pinTimer);
|
clearInterval(this.pinTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadStores() {
|
||||||
|
this.sonarrFacade.load().subscribe();
|
||||||
|
this.radarrFacade.load().subscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ export class MovieDetailsComponent implements OnInit{
|
||||||
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
|
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
|
||||||
|
|
||||||
if (this.isAdmin) {
|
if (this.isAdmin) {
|
||||||
this.showAdvanced = await this.radarrService.isRadarrEnabled();
|
this.showAdvanced = await firstValueFrom(this.radarrService.isRadarrEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.imdbId) {
|
if (this.imdbId) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { HttpClient } from "@angular/common/http";
|
||||||
import { Injectable, Inject } from "@angular/core";
|
import { Injectable, Inject } from "@angular/core";
|
||||||
import { Observable } from "rxjs";
|
import { Observable } from "rxjs";
|
||||||
|
|
||||||
import { IRadarrProfile, IRadarrRootFolder } from "../../interfaces";
|
import { IRadarrProfile, IRadarrRootFolder, ITag } from "../../interfaces";
|
||||||
import { IRadarrSettings } from "../../interfaces";
|
import { IRadarrSettings } from "../../interfaces";
|
||||||
import { ServiceHelpers } from "../service.helpers";
|
import { ServiceHelpers } from "../service.helpers";
|
||||||
|
|
||||||
|
@ -23,10 +23,20 @@ export class RadarrService extends ServiceHelpers {
|
||||||
public getRootFoldersFromSettings(): Observable<IRadarrRootFolder[]> {
|
public getRootFoldersFromSettings(): Observable<IRadarrRootFolder[]> {
|
||||||
return this.http.get<IRadarrRootFolder[]>(`${this.url}/RootFolders/`, { headers: this.headers });
|
return this.http.get<IRadarrRootFolder[]>(`${this.url}/RootFolders/`, { headers: this.headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
public getQualityProfilesFromSettings(): Observable<IRadarrProfile[]> {
|
public getQualityProfilesFromSettings(): Observable<IRadarrProfile[]> {
|
||||||
return this.http.get<IRadarrProfile[]>(`${this.url}/Profiles/`, { headers: this.headers });
|
return this.http.get<IRadarrProfile[]>(`${this.url}/Profiles/`, { headers: this.headers });
|
||||||
}
|
}
|
||||||
public isRadarrEnabled(): Promise<boolean> {
|
|
||||||
return this.http.get<boolean>(`${this.url}/enabled/`, { headers: this.headers }).toPromise();
|
public isRadarrEnabled(): Observable<boolean> {
|
||||||
|
return this.http.get<boolean>(`${this.url}/enabled/`, { headers: this.headers });
|
||||||
|
}
|
||||||
|
|
||||||
|
public getTagsWithSettings(settings: IRadarrSettings): Observable<ITag[]> {
|
||||||
|
return this.http.post<ITag[]>(`${this.url}/enabled/`, JSON.stringify(settings), { headers: this.headers });
|
||||||
|
}
|
||||||
|
|
||||||
|
public getTags(): Observable<ITag[]> {
|
||||||
|
return this.http.get<ITag[]>(`${this.url}/enabled/`, { headers: this.headers })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { Component, OnInit, QueryList, ViewChild, ViewChildren } from "@angular/core";
|
import { Component, OnInit, QueryList, ViewChildren } from "@angular/core";
|
||||||
import { UntypedFormBuilder, UntypedFormGroup } from "@angular/forms";
|
import { UntypedFormBuilder, UntypedFormGroup } from "@angular/forms";
|
||||||
|
import { RadarrFacade } from "app/state/radarr";
|
||||||
|
|
||||||
import { IMinimumAvailability, IRadarrCombined, IRadarrProfile, IRadarrRootFolder } from "../../interfaces";
|
import { IMinimumAvailability, IRadarrCombined, IRadarrProfile, IRadarrRootFolder } from "../../interfaces";
|
||||||
import { NotificationService, SettingsService } from "../../services";
|
import { NotificationService } from "../../services";
|
||||||
import { FeaturesFacade } from "../../state/features/features.facade";
|
import { FeaturesFacade } from "../../state/features/features.facade";
|
||||||
import { RadarrFormComponent } from "./components/radarr-form.component";
|
import { RadarrFormComponent } from "./components/radarr-form.component";
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ export class RadarrComponent implements OnInit {
|
||||||
@ViewChildren('4kForm') public form4k: QueryList<RadarrFormComponent>;
|
@ViewChildren('4kForm') public form4k: QueryList<RadarrFormComponent>;
|
||||||
@ViewChildren('normalForm') public normalForm: QueryList<RadarrFormComponent>;
|
@ViewChildren('normalForm') public normalForm: QueryList<RadarrFormComponent>;
|
||||||
|
|
||||||
constructor(private settingsService: SettingsService,
|
constructor(private radarrFacade: RadarrFacade,
|
||||||
private notificationService: NotificationService,
|
private notificationService: NotificationService,
|
||||||
private featureFacade: FeaturesFacade,
|
private featureFacade: FeaturesFacade,
|
||||||
private fb: UntypedFormBuilder) { }
|
private fb: UntypedFormBuilder) { }
|
||||||
|
@ -31,34 +32,34 @@ export class RadarrComponent implements OnInit {
|
||||||
|
|
||||||
public ngOnInit() {
|
public ngOnInit() {
|
||||||
this.is4kEnabled = this.featureFacade.is4kEnabled();
|
this.is4kEnabled = this.featureFacade.is4kEnabled();
|
||||||
this.settingsService.getRadarr()
|
this.radarrFacade.state$()
|
||||||
.subscribe(x => {
|
.subscribe(x => {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
radarr: this.fb.group({
|
radarr: this.fb.group({
|
||||||
enabled: [x.radarr.enabled],
|
enabled: [x.settings.radarr.enabled],
|
||||||
apiKey: [x.radarr.apiKey],
|
apiKey: [x.settings.radarr.apiKey],
|
||||||
defaultQualityProfile: [+x.radarr.defaultQualityProfile],
|
defaultQualityProfile: [+x.settings.radarr.defaultQualityProfile],
|
||||||
defaultRootPath: [x.radarr.defaultRootPath],
|
defaultRootPath: [x.settings.radarr.defaultRootPath],
|
||||||
ssl: [x.radarr.ssl],
|
ssl: [x.settings.radarr.ssl],
|
||||||
subDir: [x.radarr.subDir],
|
subDir: [x.settings.radarr.subDir],
|
||||||
ip: [x.radarr.ip],
|
ip: [x.settings.radarr.ip],
|
||||||
port: [x.radarr.port],
|
port: [x.settings.radarr.port],
|
||||||
addOnly: [x.radarr.addOnly],
|
addOnly: [x.settings.radarr.addOnly],
|
||||||
minimumAvailability: [x.radarr.minimumAvailability],
|
minimumAvailability: [x.settings.radarr.minimumAvailability],
|
||||||
scanForAvailability: [x.radarr.scanForAvailability]
|
scanForAvailability: [x.settings.radarr.scanForAvailability]
|
||||||
}),
|
}),
|
||||||
radarr4K: this.fb.group({
|
radarr4K: this.fb.group({
|
||||||
enabled: [x.radarr4K.enabled],
|
enabled: [x.settings.radarr4K.enabled],
|
||||||
apiKey: [x.radarr4K.apiKey],
|
apiKey: [x.settings.radarr4K.apiKey],
|
||||||
defaultQualityProfile: [+x.radarr4K.defaultQualityProfile],
|
defaultQualityProfile: [+x.settings.radarr4K.defaultQualityProfile],
|
||||||
defaultRootPath: [x.radarr4K.defaultRootPath],
|
defaultRootPath: [x.settings.radarr4K.defaultRootPath],
|
||||||
ssl: [x.radarr4K.ssl],
|
ssl: [x.settings.radarr4K.ssl],
|
||||||
subDir: [x.radarr4K.subDir],
|
subDir: [x.settings.radarr4K.subDir],
|
||||||
ip: [x.radarr4K.ip],
|
ip: [x.settings.radarr4K.ip],
|
||||||
port: [x.radarr4K.port],
|
port: [x.settings.radarr4K.port],
|
||||||
addOnly: [x.radarr4K.addOnly],
|
addOnly: [x.settings.radarr4K.addOnly],
|
||||||
minimumAvailability: [x.radarr4K.minimumAvailability],
|
minimumAvailability: [x.settings.radarr4K.minimumAvailability],
|
||||||
scanForAvailability: [x.radarr4K.scanForAvailability]
|
scanForAvailability: [x.settings.radarr4K.scanForAvailability]
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
this.normalForm.changes.forEach((comp => {
|
this.normalForm.changes.forEach((comp => {
|
||||||
|
@ -92,7 +93,7 @@ export class RadarrComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = <IRadarrCombined> form.value;
|
const settings = <IRadarrCombined> form.value;
|
||||||
this.settingsService.saveRadarr(settings).subscribe(x => {
|
this.radarrFacade.updateSettings(settings).subscribe(x => {
|
||||||
if (x) {
|
if (x) {
|
||||||
this.notificationService.success("Successfully saved Radarr settings");
|
this.notificationService.success("Successfully saved Radarr settings");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -80,7 +80,7 @@ export class AdminRequestDialogComponent implements OnInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.data.type === RequestType.movie) {
|
if (this.data.type === RequestType.movie) {
|
||||||
this.radarrEnabled = await this.radarrService.isRadarrEnabled();
|
this.radarrEnabled = await firstValueFrom(this.radarrService.isRadarrEnabled());
|
||||||
if (this.radarrEnabled) {
|
if (this.radarrEnabled) {
|
||||||
this.radarrService.getQualityProfilesFromSettings().subscribe(c => {
|
this.radarrService.getQualityProfilesFromSettings().subscribe(c => {
|
||||||
this.radarrProfiles = c;
|
this.radarrProfiles = c;
|
||||||
|
|
4
src/Ombi/ClientApp/src/app/state/radarr/index.ts
Normal file
4
src/Ombi/ClientApp/src/app/state/radarr/index.ts
Normal file
|
@ -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],
|
||||||
|
};
|
10
src/Ombi/ClientApp/src/app/state/radarr/radarr.actions.ts
Normal file
10
src/Ombi/ClientApp/src/app/state/radarr/radarr.actions.ts
Normal file
|
@ -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) { }
|
||||||
|
}
|
27
src/Ombi/ClientApp/src/app/state/radarr/radarr.facade.ts
Normal file
27
src/Ombi/ClientApp/src/app/state/radarr/radarr.facade.ts
Normal file
|
@ -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);
|
||||||
|
}
|
26
src/Ombi/ClientApp/src/app/state/radarr/radarr.selectors.ts
Normal file
26
src/Ombi/ClientApp/src/app/state/radarr/radarr.selectors.ts
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
41
src/Ombi/ClientApp/src/app/state/radarr/radarr.state.ts
Normal file
41
src/Ombi/ClientApp/src/app/state/radarr/radarr.state.ts
Normal file
|
@ -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})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
8
src/Ombi/ClientApp/src/app/state/radarr/types.ts
Normal file
8
src/Ombi/ClientApp/src/app/state/radarr/types.ts
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue