import { Component , OnDestroy , OnInit } from '@angular/core' ; import { ConfigEditBaseComponent } from '../config.edit' ; import { NgbDateAdapter , NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap' ; import { CustomDateParserFormatter , NgbStringAdapter } from '../../../../../settings/date-settings/date-settings-formatter.service' ; import { ReplaySubject } from 'rxjs' ; import { FormControl , Validators } from '@angular/forms' ; import { takeUntil } from 'rxjs/operators' ; import { DateSettingsService } from '../../../../../settings/services/date-settings.service' ; @ Component ( { selector : 'cmdb-date-field-edit' , templateUrl : './date-field-edit.component.html' , providers : [ { provide : NgbDateAdapter , useClass : NgbStringAdapter } , { provide : NgbDateParserFormatter , useClass : CustomDateParserFormatter } ] } ) export class DateFieldEditComponent extends ConfigEditBaseComponent implements OnInit , OnDestroy { protected protected subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; public datePlaceholder = 'YYYY-MM-DD' ; public requiredControl : FormControl = new FormControl ( false ) ; public nameControl : FormControl = new FormControl ( '' , Validators . required ) ; public labelControl : FormControl = new FormControl ( '' , Validators . required ) ; public descriptionControl : FormControl = new FormControl ( undefined ) ; public valueControl : FormControl = new FormControl ( undefined ) ; public helperTextControl : FormControl = new FormControl ( undefined ) ; constructor ( private dateSettingsService ) { super ( ) ; } public ngOnInit ( ) { this . dateSettingsService . getDateSettings ( ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( dateSettings ) => { this . datePlaceholder = dateSettings . date_format ; } ) ; this . form . addControl ( 'required' , this . requiredControl ) ; this . form . addControl ( 'name' , this . nameControl ) ; this . form . addControl ( 'label' , this . labelControl ) ; this . form . addControl ( 'description' , this . descriptionControl ) ; this . form . addControl ( 'value' , this . valueControl ) ; this . form . addControl ( 'helperText' , this . helperTextControl ) ; this . disableControlOnEdit ( this . nameControl ) ; this . patchData ( this . data , this . form ) ; } public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } /**
     * Resets the date to null.
     */ public resetDate ( ) { this . valueControl . setValue ( undefined ) ; this . data . value = null ; } }