import { Component , Input } from '@angular/core' ; import { AbstractControl , FormGroup } from '@angular/forms' ; import { CmdbMode } from '../../modes.enum' ; import { ToastService } from '../../../layout/toast/toast.service' ; import { CmdbTypeSection } from '../../models/cmdb-type' ; export interface ComponentsFields { data : Input ; } @ Component ( { template : '' } ) export class RenderFieldComponent { protected protected section : CmdbTypeSection ; param value constructor @ Input ( 'section' ) public set Section ( value ) { this . section = value ; } protected innerData : any ; public innerValue : any ; public MODES = CmdbMode ; public toast : ToastService ; @ Input ( ) public mode : CmdbMode = this . MODES . View ; @ Input ( ) public parentFormGroup : FormGroup ; @ Input ( ) public changeForm : FormGroup ; @ Input ( 'data' ) public set data ( value ) { this . innerData = value ; } public get data ( ) : any { return this . innerData ; } @ Input ( 'value' ) public set value ( value ) { this . innerValue = value ; } public get value ( ) : any { if ( this . data . value && ( ! this . innerValue || this . innerValue === '' ) ) { this . innerValue = this . data . value ; } return this . innerValue ; } public get controller ( ) : AbstractControl { return this . parentFormGroup . get ( this . data . name ) ; } public constructor ( ) { } public copyToClipboard ( ) { const selBox = document . createElement ( 'textarea' ) ; selBox . value = this . controller . value ; this . generateDataForClipboard ( selBox ) ; } protected generateDataForClipboard ( selBox ) { selBox . style . position = 'fixed' ; selBox . style . left = '0' ; selBox . style . top = '0' ; selBox . style . opacity = '0' ; document . body . appendChild ( selBox ) ; selBox . focus ( ) ; selBox . select ( ) ; this . showToast ( selBox ) ; } protected showToast ( selBox ) { document . execCommand ( 'copy' ) ; document . body . removeChild ( selBox ) ; this . toast . info ( 'Content was copied to clipboard' ) ; } }