import { Component } from '@angular/core' ; import { CmdbStatus } from '../../models/cmdb-status' ; import { StatusService } from '../../services/status.service' ; import { FormControl , FormGroup , Validators } from '@angular/forms' ; import { Router } from '@angular/router' ; @ Component ( { selector : 'cmdb-status-add' , templateUrl : './status-add.component.html' , styleUrls : [ './status-add.component.scss' ] } ) export class StatusAddComponent { public shortMaxLength : number = 5 ; public addStatusForm : FormGroup ; constructor ( private statusService , private router ) { this . addStatusForm = new FormGroup ( { name : new FormControl ( '' , Validators . required ) , label : new FormControl ( '' , Validators . required ) , short : new FormControl ( '' , Validators . maxLength ( this . shortMaxLength ) ) } ) ; } public get name ( ) { return this . addStatusForm . get ( 'name' ) ; } public get label ( ) { return this . addStatusForm . get ( 'label' ) ; } public get controls ( ) { return this . addStatusForm . controls ; } public saveStatus ( ) { this . addStatusForm . markAllAsTouched ( ) ; if ( this . addStatusForm . valid ) { const newStatus = this . addStatusForm . getRawValue ( ) ; this . statusService . postStatus ( newStatus ) . subscribe ( ( newPublicID ) => { this . router . navigate ( [ `/framework/status/` ] ) ; } , error => { console . error ( error ) ; } ) ; } } }