int-field.component.ts (1-317) import { ChangeDetectionStrategy, Component, DestroyRef,…
- User
int-field.component.ts (1-317)
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject, input, output, signal, } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { FormControl, FormGroup, ReactiveFormsModule, Validators, } from '@angular/forms'; import { startWith } from 'rxjs'; import { fieldGeneratorMap, GeneratorType } from '../schema-config.model'; import { compareToOtherFieldValidator } from '../../shared/validators/compare-to-other-field-validator.validator'; import { matchingArrayLengthsValidator } from '../../shared/validators/matching-array-lenghts-validator.validator'; import { SchemaFormFieldGeneratorService } from '../../shared/services/schema-form-field-generator.service'; import { TitleCasePipe } from '@angular/common'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; import { MatSelectModule } from '@angular/material/select'; import { RepeatMaskDirective } from '../../shared/directives/repeat-mask.directive'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { ErrorMessagePipe } from '../../shared/pipes/error-message.pipe'; import { integersCommaSeparatedValidator } from '../../shared/validators/integers-comma-separate-validator.validator'; import { isIntegerValidator } from '../../shared/validators/is-integer-validator.validator';
type IntFieldGenerator = | { type: GeneratorType.Uniform; min: number; max: number } | { type: GeneratorType.Enum; values: number[]; weights: number[] } | { type: GeneratorType.NumericRange; start: number; step: number } | { type: GeneratorType.Values; values: number[] };
interface IntFieldForm { type: FormControl; min?: FormControl; max?: FormControl; values?: FormControl; weights?: FormControl; start?: FormControl; step?: FormControl; }
@Component({ selector: 'app-int-field', standalone: true, imports: [ MatFormFieldModule, MatSelectModule, ReactiveFormsModule, MatInputModule, ReactiveFormsModule, TitleCasePipe, RepeatMaskDirective, MatButtonModule, MatIconModule, ErrorMessagePipe, ], templateUrl: './int-field.component.html', styleUrl: './int-field.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, }) export class IntFieldComponent implements OnInit { private readonly schemaFormFieldGeneratorSvc = inject( SchemaFormFieldGeneratorService, ); private readonly destroyRef = inject(DestroyRef);
public readonly autoRenew = signal(true);
public readonly generatorTypes = input.required();
public readonly changeField = output<{ schema: IntFieldGenerator | undefined; valid: boolean; }>();
public readonly type = this.schemaFormFieldGeneratorSvc.getTypeField(); public readonly min = this.schemaFormFieldGeneratorSvc.getMinField([ Validators.min(-2147483648), isIntegerValidator, compareToOtherFieldValidator( 'max', (min: number, max: number) => +min < +max, 'minGreaterThanMax', ), ]); public readonly max = this.schemaFormFieldGeneratorSvc.getMaxField([ Validators.max(2147483648), isIntegerValidator, compareToOtherFieldValidator( 'min', (max: number, min: number) => +min < +max, 'MaxSmallerThanMin', ), ]); public readonly values = this.schemaFormFieldGeneratorSvc.getValuesField([ integersCommaSeparatedValidator, ]); public readonly weights = this.schemaFormFieldGeneratorSvc.getWeightsField(); public readonly start = this.schemaFormFieldGeneratorSvc.getStartField(); public readonly step = this.schemaFormFieldGeneratorSvc.getStepField(); public readonly fieldForm = new FormGroup({ type: this.type, });
- Assistant