diff --git a/src/app/pages/system/update/components/train-card/train-card.component.spec.ts b/src/app/pages/system/update/components/train-card/train-card.component.spec.ts index d1f16c6cf5d..8eaf988c5e1 100644 --- a/src/app/pages/system/update/components/train-card/train-card.component.spec.ts +++ b/src/app/pages/system/update/components/train-card/train-card.component.spec.ts @@ -35,7 +35,6 @@ describe('TrainCardComponent', () => { selected: 'some train', } as SystemUpdateTrains)), trainValue$: new BehaviorSubject('train1'), - autoCheckValue$: new BehaviorSubject(false), fullTrainList$: new BehaviorSubject(undefined), selectedTrain$: new BehaviorSubject(undefined), currentTrainDescription$: new BehaviorSubject(''), @@ -71,6 +70,6 @@ describe('TrainCardComponent', () => { 'Check for Updates Daily and Download if Available': true, }); - expect(spectator.inject(TrainService).toggleAutoCheck).toHaveBeenCalled(); + expect(spectator.inject(TrainService).toggleAutoCheck).toHaveBeenCalledWith(true); }); }); diff --git a/src/app/pages/system/update/components/train-card/train-card.component.ts b/src/app/pages/system/update/components/train-card/train-card.component.ts index dca7e94b879..8f1415c2397 100644 --- a/src/app/pages/system/update/components/train-card/train-card.component.ts +++ b/src/app/pages/system/update/components/train-card/train-card.component.ts @@ -67,7 +67,7 @@ export class TrainCardComponent implements OnInit { this.trainService.getTrains(), ]).pipe(untilDestroyed(this)).subscribe({ next: ([isAutoDownloadOn, trains]) => { - this.trainService.autoCheckValue$.next(isAutoDownloadOn); + this.form.controls.auto_check.patchValue(isAutoDownloadOn); this.checkable = true; this.cdr.markForCheck(); this.trainService.fullTrainList$.next(trains.trains); @@ -118,10 +118,6 @@ export class TrainCardComponent implements OnInit { this.form.controls.train.patchValue(trainValue); }); - this.trainService.autoCheckValue$.pipe(untilDestroyed(this)).subscribe((autoCheckValue) => { - this.form.controls.auto_check.patchValue(autoCheckValue); - }); - this.form.controls.train.valueChanges.pipe(pairwise(), untilDestroyed(this)).subscribe(([prevTrain, newTrain]) => { this.trainService.onTrainChanged(newTrain, prevTrain); }); @@ -130,7 +126,7 @@ export class TrainCardComponent implements OnInit { filterAsync(() => this.authService.hasRole(Role.FullAdmin)), untilDestroyed(this), ).subscribe(() => { - this.trainService.toggleAutoCheck(); + this.trainService.toggleAutoCheck(this.form.controls.auto_check.value); }); } } diff --git a/src/app/pages/system/update/services/train.service.ts b/src/app/pages/system/update/services/train.service.ts index 7069bd2e993..7ff593fed12 100644 --- a/src/app/pages/system/update/services/train.service.ts +++ b/src/app/pages/system/update/services/train.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { TranslateService } from '@ngx-translate/core'; import { - BehaviorSubject, Observable, combineLatest, filter, tap, + BehaviorSubject, Observable, combineLatest, } from 'rxjs'; import { SystemUpdateOperationType, SystemUpdateStatus } from 'app/enums/system-update.enum'; import { SystemUpdateTrain, SystemUpdateTrains } from 'app/interfaces/system-update.interface'; @@ -28,7 +28,6 @@ export class TrainService { trainVersion$ = new BehaviorSubject(null); trainValue$ = new BehaviorSubject(''); - autoCheckValue$ = new BehaviorSubject(false); constructor( private updateService: UpdateService, @@ -87,12 +86,8 @@ export class TrainService { }); } - toggleAutoCheck(): void { - this.autoCheckValue$.pipe( - tap((autoCheckValue) => this.ws.call('update.set_auto_download', [autoCheckValue])), - filter(Boolean), - untilDestroyed(this), - ).subscribe(() => { + toggleAutoCheck(autoCheck: boolean): void { + this.ws.call('update.set_auto_download', [autoCheck]).pipe(untilDestroyed(this)).subscribe(() => { this.check(); }); }