import { Component , OnDestroy , OnInit } from '@angular/core' ; import { GroupService } from '../../services/group.service' ; import { ActivatedRoute , Router } from '@angular/router' ; import { Right } from '../../models/right' ; import { Group } from '../../models/group' ; import { takeUntil } from 'rxjs/operators' ; import { ReplaySubject } from 'rxjs' ; import { ToastService } from '../../../layout/toast/toast.service' ; @ Component ( { selector : 'cmdb-group-add' , templateUrl : './group-add.component.html' , styleUrls : [ './group-add.component.scss' ] } ) export class GroupAddComponent implements OnDestroy { public rights : Array < Right > = [ ] ; public valid : boolean = false ; private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; constructor ( private route , private router , private toastService , private groupService ) { this . rights = this . route . snapshot . data . rights as Array < Right > ; } param group public save ( group ) { if ( this . valid ) { this . groupService . postGroup ( group ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( g ) => { this . toastService . success ( `Group ${ g . label } was added!` ) ; this . router . navigate ( [ '/' , 'management' , 'groups' ] ) ; } ) ; } } /**
     * Auto unsubscribe on component destroy.
     */ public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }