import { Component , Input , OnInit } from '@angular/core' ; import { BehaviorSubject } from 'rxjs' ; import { FormControl , FormGroup , Validators } from '@angular/forms' ; import { FileMetadata } from '../../model/metadata' ; import { checkFolderExistsValidator , FileService } from '../../service/file.service' ; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' ; @ Component ( { selector : 'cmdb-rename-dialog' , templateUrl : './rename-dialog.component.html' , styleUrls : [ './rename-dialog.component.scss' ] } ) export class RenameDialogComponent implements OnInit { private selectedFileElement : BehaviorSubject < any > ; @ Input ( ) set selectedFileFolder ( value ) { this . selectedFileElement = value ; } get selectedFileFolder ( ) : BehaviorSubject < any > { return this . selectedFileElement ; } public basicForm : FormGroup ; static generateMetaData ( value ) { const fileElement = value . getValue ( ) ; return new FileMetadata ( { folder : fileElement == null ? false : fileElement . metadata . folder , parent : fileElement == null ? null : fileElement . metadata . parent } ) ; } constructor ( private fileService , public activeModal ) { } public ngOnInit ( ) { const placeholder = this . selectedFileElement . getValue ( ) ? this . selectedFileElement . getValue ( ) . filename : '' ; this . basicForm = new FormGroup ( { name : new FormControl ( placeholder , Validators . required ) } ) ; this . basicForm . get ( 'name' ) . setAsyncValidators ( checkFolderExistsValidator ( this . fileService , RenameDialogComponent . generateMetaData ( this . selectedFileFolder ) ) ) ; } public get name ( ) { return this . basicForm . get ( 'name' ) ; } }