import { Component , Input } from '@angular/core' ; import { CmdbTypeSection } from '../../../models/cmdb-type' ; import { CmdbMode } from '../../../modes.enum' ; import { FormGroup } from '@angular/forms' ; @ Component ( { selector : 'cmdb-base-section' , templateUrl : './base-section.component.html' , styleUrls : [ './base-section.component.scss' ] } ) export class BaseSectionComponent { /**
     * Modes for html usage.
     */ public MODES = CmdbMode ; /**
     * Form for every object create or edit.
     */ @ Input ( ) public form : FormGroup ; /**
     * Separated form for things like bulk change. Saves changes.
     */ @ Input ( ) public changeForm : FormGroup ; @ Input ( ) public fields : Array < any > = [ ] ; public values : Array < any > = [ ] ; @ Input ( 'values' ) public set Values ( val ) { if ( val ) { this . values = val ; } } @ Input ( ) public mode : CmdbMode = CmdbMode . View ; @ Input ( ) public section : CmdbTypeSection ; constructor ( ) { } public getFieldByName ( name ) { const field = this . fields . find ( f => f . name === name ) ; switch ( field . type ) { case 'ref' : { field . default = parseInt ( field . default , 10 ) ; break ; } default : { if ( ! field . default ) { field . default = field . value ; } break ; } } return field ; } public getValueByName ( name ) { const fieldFound = this . values . find ( field => field . name === name ) ; if ( fieldFound === undefined ) { return undefined ; } return fieldFound . value ; } }