Skip to content

Commit

Permalink
fix(radarr-settings): this.normalForm is undefined (#5207)
Browse files Browse the repository at this point in the history
Fixes #4994
  • Loading branch information
AlexandrePicavet authored Jan 3, 2025
1 parent 3234204 commit dc2b958
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<settings-menu></settings-menu>
<div *ngIf="form" class="small-middle-container">
<div *ngIf="form$ | async as form" class="small-middle-container">
<fieldset>
<legend>Radarr Settings</legend>
<div class="md-form-field" style="margin-top:1em;"></div>
Expand Down Expand Up @@ -33,4 +33,4 @@
</div>
</form>
</fieldset>
</div>
</div>
80 changes: 55 additions & 25 deletions src/Ombi/ClientApp/src/app/settings/radarr/radarr.component.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import { Component, OnInit, QueryList, ViewChildren } from "@angular/core";
import { Component, OnDestroy, OnInit, QueryList, ViewChildren } from "@angular/core";
import { UntypedFormBuilder, UntypedFormGroup } from "@angular/forms";
import { RadarrFacade } from "app/state/radarr";

import { IMinimumAvailability, IRadarrCombined, IRadarrProfile, IRadarrRootFolder } from "../../interfaces";
import { NotificationService } from "../../services";
import { FeaturesFacade } from "../../state/features/features.facade";
import { RadarrFormComponent } from "./components/radarr-form.component";
import { Observable, ReplaySubject, Subject, combineLatest, map, switchMap, takeUntil, tap } from "rxjs";

@Component({
templateUrl: "./radarr.component.html",
styleUrls: ["./radarr.component.scss"]
})
export class RadarrComponent implements OnInit {
export class RadarrComponent implements OnInit, OnDestroy {

public qualities: IRadarrProfile[];
public rootFolders: IRadarrRootFolder[];
public minimumAvailabilityOptions: IMinimumAvailability[];
public profilesRunning: boolean;
public rootFoldersRunning: boolean;
public form: UntypedFormGroup;
public is4kEnabled: boolean = false;

@ViewChildren('4kForm') public form4k: QueryList<RadarrFormComponent>;
@ViewChildren('normalForm') public normalForm: QueryList<RadarrFormComponent>;
public readonly form$: Observable<UntypedFormGroup>;

constructor(private radarrFacade: RadarrFacade,
private notificationService: NotificationService,
private featureFacade: FeaturesFacade,
private fb: UntypedFormBuilder) { }
private readonly form4k$: ReplaySubject<QueryList<RadarrFormComponent>>;
private readonly normalForm$: ReplaySubject<QueryList<RadarrFormComponent>>;
private readonly destroyed$: Subject<void>;

constructor(
private readonly radarrFacade: RadarrFacade,
private readonly notificationService: NotificationService,
private readonly featureFacade: FeaturesFacade,
readonly fb: UntypedFormBuilder
) {
this.form4k$ = new ReplaySubject();
this.normalForm$ = new ReplaySubject();
this.destroyed$ = new Subject();

public ngOnInit() {
this.is4kEnabled = this.featureFacade.is4kEnabled();
this.radarrFacade.state$()
.subscribe(x => {
this.form = this.fb.group({
radarr: this.fb.group({
this.form$ = radarrFacade.state$()
.pipe(
map(x => fb.group({
radarr: fb.group({
enabled: [x.settings.radarr.enabled],
apiKey: [x.settings.radarr.apiKey],
defaultQualityProfile: [+x.settings.radarr.defaultQualityProfile],
Expand All @@ -50,7 +55,7 @@ export class RadarrComponent implements OnInit {
minimumAvailability: [x.settings.radarr.minimumAvailability],
scanForAvailability: [x.settings.radarr.scanForAvailability]
}),
radarr4K: this.fb.group({
radarr4K: fb.group({
enabled: [x.settings.radarr4K.enabled],
apiKey: [x.settings.radarr4K.apiKey],
defaultQualityProfile: [+x.settings.radarr4K.defaultQualityProfile],
Expand All @@ -65,19 +70,44 @@ export class RadarrComponent implements OnInit {
minimumAvailability: [x.settings.radarr4K.minimumAvailability],
scanForAvailability: [x.settings.radarr4K.scanForAvailability]
}),
});
this.normalForm.changes.forEach((comp => {
comp.first.toggleValidators();
}))
if (this.is4kEnabled) {
this.form4k.changes.forEach((comp => {
comp.first.toggleValidators();
}))
}
});
)
}

@ViewChildren('4kForm')
protected set form4k(component: QueryList<RadarrFormComponent>) {
this.form4k$.next(component);
}

@ViewChildren('normalForm')
protected set normalForm(component: QueryList<RadarrFormComponent>) {
this.normalForm$.next(component);
}

public ngOnInit() {
this.is4kEnabled = this.featureFacade.is4kEnabled();

combineLatest([this.form$, this.normalForm$])
.pipe(
switchMap(([, normalForm]) => normalForm.changes),
tap(comp => comp.first.toggleValidators()),
takeUntil(this.destroyed$)
).subscribe();

if (this.is4kEnabled) {
combineLatest([this.form$, this.form4k$])
.pipe(
switchMap(([, form4k]) => form4k.changes),
tap(comp => comp.first.toggleValidators()),
takeUntil(this.destroyed$)
).subscribe();
}
}

public ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
}

public onSubmit(form: UntypedFormGroup) {
if (form.invalid) {
Expand Down

0 comments on commit dc2b958

Please sign in to comment.