Files
MireaFrontend/src/pages/setup/logging/logging.component.ts

85 lines
2.8 KiB
TypeScript

import {Component} from '@angular/core';
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
import {NavigationService} from "@service/navigation.service";
import SetupService from "@api/v1/setup.service";
import {MatFormFieldModule} from "@angular/material/form-field";
import {MatSelectModule} from "@angular/material/select";
import {MatInput} from "@angular/material/input";
import {MatTooltip} from "@angular/material/tooltip";
import {MatCheckbox} from "@angular/material/checkbox";
import {of} from "rxjs";
@Component({
selector: 'app-logging',
standalone: true,
imports: [
ReactiveFormsModule,
MatFormFieldModule,
MatSelectModule,
MatInput,
MatTooltip,
MatCheckbox
],
templateUrl: './logging.component.html'
})
export class LoggingComponent {
protected loggingSettings!: FormGroup;
protected isEnabledLoggingChange(check: boolean) {
if (check) {
this.loggingSettings.get('logPath')?.enable();
this.loggingSettings.get('logName')?.enable();
} else {
this.loggingSettings.get('logPath')?.disable();
this.loggingSettings.get('logName')?.disable();
}
}
constructor(
private navigationService: NavigationService, private formBuilder: FormBuilder, private api: SetupService) {
this.navigationService.setSkipButtonState(true);
this.navigationService.skipButtonAction = () => this.api.setLogging(null);
this.loggingSettings = this.formBuilder.group({
enabled: [true, Validators.required],
logPath: [''],
logName: [''],
seqServer: [''],
seqKey: ['']
}
);
this.navigationService.setNextButtonState(this.loggingSettings.valid);
this.loggingSettings.valueChanges.subscribe(() => {
this.navigationService.setNextButtonState(this.loggingSettings.valid);
});
this.navigationService.nextButtonAction = () => {
return this.api.setLogging({
enableLogToFile: this.loggingSettings.get('enabled')?.value,
logFileName: this.loggingSettings.get('logName')?.value,
logFilePath: this.loggingSettings.get('logPath')?.value,
apiServerSeq: this.loggingSettings.get('seqServer')?.value,
apiKeySeq: this.loggingSettings.get('seqKey')?.value
}
);
};
api.loggingConfiguration().subscribe(x => {
if (!x)
return;
this.navigationService.skipButtonAction = () => of(true);
this.navigationService.triggerAutoSkip(this.navigationService.skipButtonAction);
this.loggingSettings.get('enabled')?.setValue(x.enableLogToFile);
this.loggingSettings.get('logName')?.setValue(x.logFileName);
this.loggingSettings.get('logPath')?.setValue(x.logFilePath);
this.loggingSettings.get('seqServer')?.setValue(x.apiServerSeq);
this.loggingSettings.get('seqKey')?.setValue(x.apiKeySeq);
});
}
}