import { CreateValue, ReadValue, UpdateValue } from '@dasch-swiss/dsp-js'; import { FormControl, FormGroup, ValidatorFn } from '@angular/forms'; import { Subscription } from 'rxjs'; export declare abstract class BaseValueComponent { shouldShowComment: boolean; /** * Value to be displayed, if any. */ abstract displayValue?: ReadValue; /** * Sets the mode of the component. */ mode: 'read' | 'update' | 'create' | 'search'; /** * Parent FormGroup that contains all child FormGroups */ parentForm?: FormGroup; /** * name of the FormGroup, used to add to the parentForm because the name needs to be unique */ formName: string; /** * Controls if the value should be required. */ valueRequiredValidator: boolean; /** * FormControl element for the value. */ abstract valueFormControl: FormControl; /** * FormControl element for the comment on the value. */ abstract commentFormControl: FormControl; /** * FormGroup that contains FormControl elements. */ abstract form: FormGroup; /** * Subscription used for when the value changes. */ abstract valueChangesSubscription: Subscription; /** * Custom validators for a specific value type. * Can be initialized to an empty array if not needed. */ abstract customValidators: ValidatorFn[]; /** * Standard implementation for comparison of primitive values. * Returns true if two values are equal. * * @param initValue Initially given value. * @param curValue Current value. */ standardValueComparisonFunc(initValue: any, curValue: any): boolean; /** * Standard implementation to determine if a value or comment have been changed. * * @param initValue Initially given value. * @param initComment Initially given comment. * @param commentFormControl FormControl of the current comment. */ standardValidatorFunc: (val: any, comment: string, commentCtrl: FormControl) => ValidatorFn; /** * Returns the initially given value set via displayValue. * Returns null if no value was given. */ abstract getInitValue(): any; /** * Returns the initially given value comment set via displayValue. * Returns null if no value comment was given. */ getInitComment(): string | null; /** * Resets the form control elements * with displayValue's value and value comment. * Depending on the mode, validators are reset. */ resetFormControl(): void; /** * Unsubscribes from the valueChangesSubscription */ unsubscribeFromValueChanges(): void; /** * Hide comment field by default if in READ mode */ updateCommentVisibility(): void; /** * Toggles visibility of the comment field regardless of the mode */ toggleCommentVisibility(): void; /** * Returns a value that is to be created. * Returns false if invalid. */ abstract getNewValue(): CreateValue | false; /** * Returns a value that is to be updated. * Returns false if invalid. */ abstract getUpdatedValue(): UpdateValue | false; /** * Add the value components FormGroup to a parent FormGroup if one is defined */ addToParentFormGroup(name: string, form: FormGroup): void; /** * Remove the value components FormGroup from a parent FormGroup if one is defined */ removeFromParentFormGroup(name: string): void; /** * Checks if the value is empty. */ isEmptyVal(): boolean; }