import { Component , OnDestroy , OnInit } from '@angular/core' ; import { CmdbType } from '../../models/cmdb-type' ; import { TypeService } from '../../services/type.service' ; import { Subscription } from 'rxjs' ; import { CmdbCategory } from '../../models/cmdb-category' ; import { CategoryService } from '../../services/category.service' ; import { Router } from '@angular/router' ; import { SidebarService } from '../../../layout/services/sidebar.service' ; import { APIGetMultiResponse } from '../../../services/models/api-response' ; @ Component ( { selector : 'cmdb-category-add' , templateUrl : './category-add.component.html' , styleUrls : [ './category-add.component.scss' ] } ) export class CategoryAddComponent implements OnInit , OnDestroy { /**
     * Validation indication for button disable
     */ public formValid : boolean = false ; /**
     * Subscription for getUncategorizedTypes
     */ private typeServiceSubscription : Subscription = new Subscription ( ) ; /**
     * Subscription for category add call
     */ private categorySubmitSubscription : Subscription = new Subscription ( ) ; /**
     * List of uncategorized types
     */ public unAssignedTypes : CmdbType [ ] ; /**
     * Instance list of types based on the ids inside the category types list
     */ public assignedTypes : CmdbType [ ] ; constructor ( private categoryService , private typeService , private router , private sidebarService ) { this . unAssignedTypes = [ ] ; this . assignedTypes = [ ] ; } public ngOnInit ( ) { this . typeServiceSubscription = this . typeService . getUncategorizedTypes ( ) . subscribe ( ( apiResponse ) => { this . unAssignedTypes = apiResponse . results as Array < CmdbType > ; } ) ; } public ngOnDestroy ( ) { this . typeServiceSubscription . unsubscribe ( ) ; this . categorySubmitSubscription . unsubscribe ( ) ; } param category public onSave ( category ) { if ( this . formValid ) { this . categorySubmitSubscription = this . categoryService . postCategory ( category ) . subscribe ( ( ) => { this . sidebarService . loadCategoryTree ( ) ; this . router . navigate ( [ '/' , 'framework' , 'category' ] ) ; } ) ; } } }