toSignal via Gemini

This commit is contained in:
2026-08-18 07:55:54 +00:00
parent 59eb45da96
commit 993f83c786
350 changed files with 6231 additions and 9801 deletions
+18 -33
View File
@@ -1,5 +1,5 @@
import { Component, OnInit, inject } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { Component, computed, inject, signal } from '@angular/core';
import { form, FormField } from '@angular/forms/signals';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatDatepickerModule } from '@angular/material/datepicker';
@@ -28,49 +28,34 @@ import { SettingsService } from './settings.service';
MatInputModule,
MatSlideToggleModule,
MatTabsModule,
ReactiveFormsModule,
MatCardModule,
FormField,
],
})
export class SettingsComponent implements OnInit {
export class SettingsComponent {
private route = inject(ActivatedRoute);
private router = inject(Router);
private dialog = inject(MatDialog);
private snackBar = inject(MatSnackBar);
auth = inject(AuthService);
private ser = inject(SettingsService);
prefillCustomerDiscountResource = this.ser.getPrefillCustomerDiscount();
prefillCustomerDiscount = computed(() => this.prefillCustomerDiscountResource.value()?.value ?? false);
prefillCustomerDiscount = true;
version: string;
maintenanceForm: FormGroup<{
startDate: FormControl<Date>;
finishDate: FormControl<Date>;
}>;
version = environment.version;
formModel = signal({
startDate: new Date(),
finishDate: new Date(),
});
maintenanceForm = form(this.formModel);
beerFile: File | null = null;
saleFile: File | null = null;
constructor() {
this.version = environment.version;
this.maintenanceForm = new FormGroup({
startDate: new FormControl(new Date(), { nonNullable: true }),
finishDate: new FormControl(new Date(), { nonNullable: true }),
});
}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as {
prefillCustomerDiscount: boolean;
};
this.prefillCustomerDiscount = data.prefillCustomerDiscount;
});
}
togglePrefill() {
this.ser.setPrefillCustomerDiscount(!this.prefillCustomerDiscount).subscribe((x) => {
this.prefillCustomerDiscount = x;
this.ser.setPrefillCustomerDiscount(!this.prefillCustomerDiscount()).subscribe((x) => {
this.prefillCustomerDiscountResource.value.set(x);
});
}
@@ -83,7 +68,7 @@ export class SettingsComponent implements OnInit {
}
runMaintenance() {
const formModel = this.maintenanceForm.value;
const formModel = this.formModel();
const startDate = moment(formModel.startDate).format('DD-MMM-YYYY');
const finishDate = moment(formModel.finishDate).format('DD-MMM-YYYY');
@@ -95,8 +80,8 @@ export class SettingsComponent implements OnInit {
next: () => {
this.snackBar.open('Maintenance done', 'Success');
},
error: (error) => {
this.snackBar.open(error, 'Danger');
error: (error: unknown) => {
this.snackBar.open(error as string, 'Danger');
},
});
}