import { Injectable } from '@angular/core' ; import { ClusterHome } from '../classes/clusterHome' ; import { Observable , Subject , BehaviorSubject } from 'rxjs' ; import { ClusterDictionary , ConsumerDictionary , TopicDictionary , BurrowService } from './burrow.service' ; import { ConsumerComponent } from '../components/consumer.component' ; @ Injectable ( ) export class HomeService { private _viewTopicList : BehaviorSubject < boolean > = new BehaviorSubject ( false ) ; get viewTopicList ( ) : Observable < boolean > { return this . _viewTopicList . asObservable ( ) ; } private _viewConsumerList : BehaviorSubject < boolean > = new BehaviorSubject ( false ) ; get viewConsumerList ( ) : Observable < boolean > { return this . _viewConsumerList . asObservable ( ) ; } private _listTitle : BehaviorSubject < string > = new BehaviorSubject ( 'Please Select a Cluster' ) ; get listTitle ( ) : Observable < string > { return this . _listTitle . asObservable ( ) ; } clusters : Observable < ClusterDictionary > ; private currentCluster : ClusterHome ; private _selectedCluster : BehaviorSubject < ClusterHome > = new BehaviorSubject ( null ) ; get selectedCluster ( ) : Observable < ClusterHome > { return this . _selectedCluster . asObservable ( ) ; } get loadedCluster ( ) : ClusterHome { return this . currentCluster ; } constructor ( private burrowService ) { this . clusters = this . burrowService . clusters ; this . burrowService . loadHomeView ( ) ; } viewConsumers ( cluster ) { this . burrowService . loadConsumers ( cluster ) ; this . setCurrentCluster ( cluster ) ; this . _viewTopicList . next ( false ) ; this . _viewConsumerList . next ( true ) ; this . _listTitle . next ( 'Available Consumers' ) ; } viewTopics ( cluster ) { this . burrowService . loadTopics ( cluster ) ; this . setCurrentCluster ( cluster ) ; this . _viewTopicList . next ( true ) ; this . _viewConsumerList . next ( false ) ; this . _listTitle . next ( 'Available Topics' ) ; } private setCurrentCluster ( cluster ) { this . _selectedCluster . next ( cluster ) ; this . currentCluster = cluster ; } }