From 2cea56ac22b859aa9d1c6cdd9734fd470591fb89 Mon Sep 17 00:00:00 2001 From: MatthijsSmets Date: Fri, 12 Jan 2024 16:25:58 +0100 Subject: [PATCH] chore: add showMultipleFiles to settings form, to allow general reset --- .../table-settings-modal.component.html | 2 + .../table-settings-modal.component.ts | 54 +++++++++++++------ src/app/shared/services/settings.service.ts | 16 ++++-- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/app/debug/table/table-settings-modal/table-settings-modal.component.html b/src/app/debug/table/table-settings-modal/table-settings-modal.component.html index bd930b78..cf59fdaa 100644 --- a/src/app/debug/table/table-settings-modal/table-settings-modal.component.html +++ b/src/app/debug/table/table-settings-modal/table-settings-modal.component.html @@ -15,6 +15,8 @@
Debug tree
diff --git a/src/app/debug/table/table-settings-modal/table-settings-modal.component.ts b/src/app/debug/table/table-settings-modal/table-settings-modal.component.ts index b8a12927..3cf268aa 100644 --- a/src/app/debug/table/table-settings-modal/table-settings-modal.component.ts +++ b/src/app/debug/table/table-settings-modal/table-settings-modal.component.ts @@ -1,4 +1,11 @@ -import { Component, ElementRef, EventEmitter, OnDestroy, Output, ViewChild } from '@angular/core'; +import { + Component, + ElementRef, + EventEmitter, + OnDestroy, + Output, + ViewChild, +} from '@angular/core'; import { UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { HttpService } from '../../../shared/services/http.service'; @@ -14,18 +21,18 @@ import { Subscription } from 'rxjs'; }) export class TableSettingsModalComponent implements OnDestroy { @ViewChild('modal') modal!: ElementRef; + showMultipleAtATime!: boolean; + showMultipleAtATimeSubscription!: Subscription; settingsForm = new UntypedFormGroup({ + showMultipleFilesAtATime: new UntypedFormControl(false), generatorEnabled: new UntypedFormControl('Enabled'), regexFilter: new UntypedFormControl(''), transformationEnabled: new UntypedFormControl(true), transformation: new UntypedFormControl(''), }); - @Output() openLatestReportsEvent = new EventEmitter(); @ViewChild(ToastComponent) toastComponent!: ToastComponent; saving: boolean = false; - showMultipleAtATime!: boolean; - showMultipleAtATimeSubscription!: Subscription; constructor( private modalService: NgbModal, @@ -40,12 +47,16 @@ export class TableSettingsModalComponent implements OnDestroy { this.showMultipleAtATimeSubscription.unsubscribe(); } - subscribeToSettingsServiceObservables() { - this.showMultipleAtATimeSubscription = this.settingsService.showMultipleAtATimeObservable.subscribe( - (value: boolean) => { - this.showMultipleAtATime = value; - } - ); + subscribeToSettingsServiceObservables(): void { + this.showMultipleAtATimeSubscription = + this.settingsService.showMultipleAtATimeObservable.subscribe( + (value: boolean) => { + this.showMultipleAtATime = value; + this.settingsForm + .get('showMultipleFilesAtATime') + ?.setValue(this.showMultipleAtATime); + } + ); } setShowMultipleAtATime() { @@ -72,9 +83,14 @@ export class TableSettingsModalComponent implements OnDestroy { saveSettings(): void { const form: any = this.settingsForm.value; this.cookieService.set('generatorEnabled', form.generatorEnabled); - this.cookieService.set('transformationEnabled', form.transformationEnabled.toString()); + this.cookieService.set( + 'transformationEnabled', + form.transformationEnabled.toString() + ); this.httpService.postTransformation(form.transformation).subscribe(); - const generatorEnabled: string = String(form.generatorEnabled === 'Enabled'); + const generatorEnabled: string = String( + form.generatorEnabled === 'Enabled' + ); let data: any = { generatorEnabled: generatorEnabled, regexFilter: form.regexFilter, @@ -93,14 +109,20 @@ export class TableSettingsModalComponent implements OnDestroy { } factoryReset(): void { - this.httpService.resetSettings().subscribe((response) => this.saveResponseSetting(response)); + this.settingsForm.reset(); + this.settingsService.setShowMultipleAtATime(); + this.httpService + .resetSettings() + .subscribe((response) => this.saveResponseSetting(response)); this.httpService.getTransformation(true).subscribe((resp) => { this.settingsForm.get('transformation')?.setValue(resp.transformation); }); } loadSettings(): void { - this.httpService.getSettings().subscribe((response) => this.saveResponseSetting(response)); + this.httpService + .getSettings() + .subscribe((response) => this.saveResponseSetting(response)); if (this.cookieService.get('transformationEnabled')) { this.settingsForm .get('transformationEnabled') @@ -108,7 +130,9 @@ export class TableSettingsModalComponent implements OnDestroy { } this.httpService.getTransformation(false).subscribe((response) => { - this.settingsForm.get('transformation')?.setValue(response.transformation); + this.settingsForm + .get('transformation') + ?.setValue(response.transformation); }); } diff --git a/src/app/shared/services/settings.service.ts b/src/app/shared/services/settings.service.ts index 959541c8..f61ee9f2 100644 --- a/src/app/shared/services/settings.service.ts +++ b/src/app/shared/services/settings.service.ts @@ -9,19 +9,25 @@ export class SettingsService { this.loadSettingsFromLocalStorage(); } - //Show multiple files in debug tre + //Show multiple files in debug tree private showMultipleAtATimeKey: string = 'showMultipleFilesAtATime'; private showMultipleAtATime: boolean = false; private showMultipleAtATimeSubject: Subject = new ReplaySubject(1); - public showMultipleAtATimeObservable: Observable = this.showMultipleAtATimeSubject.asObservable(); + public showMultipleAtATimeObservable: Observable = + this.showMultipleAtATimeSubject.asObservable(); - public setShowMultipleAtATime(value: boolean): void { + public setShowMultipleAtATime(value: boolean = false): void { this.showMultipleAtATime = value; this.showMultipleAtATimeSubject.next(this.showMultipleAtATime); - localStorage.setItem(this.showMultipleAtATimeKey, String(this.showMultipleAtATime)); + localStorage.setItem( + this.showMultipleAtATimeKey, + String(this.showMultipleAtATime) + ); } private loadSettingsFromLocalStorage(): void { - this.setShowMultipleAtATime(Boolean(localStorage.getItem(this.showMultipleAtATimeKey))); + this.setShowMultipleAtATime( + localStorage.getItem(this.showMultipleAtATimeKey) === 'true' + ); } }