2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 import { HttpClient } from '@angular/common/http';
22 import { Injectable } from '@angular/core';
23 import { BehaviorSubject, Observable } from 'rxjs';
24 import { shareReplay, tap } from 'rxjs/operators';
25 import { RicInstance, RicRegion } from '../../interfaces/dashboard.types';
26 import { DashboardService } from '../dashboard/dashboard.service';
31 export class InstanceSelectorService {
33 private allInstances: Observable<RicRegion[]>;
34 private selectedInstance: BehaviorSubject<RicInstance> = new BehaviorSubject<RicInstance>({ key: '', name: '' });
37 private dashboardSvc: DashboardService,
38 private httpClient: HttpClient) {
41 getAllInstances(): Observable<RicRegion[]> {
42 if (this.allInstances) {
43 return this.allInstances;
45 const path = this.dashboardSvc.buildPath('admin', null, 'instance');
46 return this.allInstances = this.httpClient.get<RicRegion[]>(path)
52 // This method may return the BehaviorSubject with empty value
53 // Afther subscribe that BehaviorSubject
54 // Please make sure this BehaviorSubject has non empty value
55 getSelectedInstance(): BehaviorSubject<RicInstance> {
56 return this.selectedInstance;
59 updateSelectedInstance(instance: RicInstance) {
60 this.selectedInstance.next(instance);