From 5dc5822a4fb61b3bcd685848f547a3509ac779bd Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Tue, 3 Jul 2018 10:05:30 +0100 Subject: [PATCH] mgr/dashboard: Usage of 'BehaviorSubject' in summary Signed-off-by: Ricardo Marques --- .../src/app/ceph/block/rbd-list/rbd-list.component.ts | 3 +++ .../navigation/dashboard-help/dashboard-help.component.ts | 3 +++ .../app/core/navigation/navigation/navigation.component.ts | 3 +++ .../core/navigation/task-manager/task-manager.component.ts | 3 +++ .../frontend/src/app/shared/services/summary.service.ts | 4 ++-- .../frontend/src/app/shared/services/task-manager.service.ts | 3 +++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts index d05fec8325f..17819e54a7f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-list/rbd-list.component.ts @@ -112,6 +112,9 @@ export class RbdListComponent implements OnInit, OnDestroy { ]; this.summaryService.get().subscribe((resp: any) => { + if (!resp) { + return; + } this.loadImages(resp.executing_tasks); this.summaryDataSubscription = this.summaryService.summaryData$.subscribe((data: any) => { this.loadImages(data.executing_tasks); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/dashboard-help/dashboard-help.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/dashboard-help/dashboard-help.component.ts index 10adf680618..74a554a177e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/dashboard-help/dashboard-help.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/dashboard-help/dashboard-help.component.ts @@ -17,6 +17,9 @@ export class DashboardHelpComponent implements OnInit { ngOnInit() { const subs = this.summaryService.summaryData$.subscribe((summary: any) => { + if (!summary) { + return; + } const releaseName = this.cephReleaseNamePipe.transform(summary.version); this.docsUrl = `http://docs.ceph.com/docs/${releaseName}/mgr/dashboard/`; subs.unsubscribe(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts index 9372e75d857..ec45878d86c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts @@ -23,6 +23,9 @@ export class NavigationComponent implements OnInit { ngOnInit() { this.summaryService.summaryData$.subscribe((data: any) => { + if (!data) { + return; + } this.summaryData = data; }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts index 0c07f881c4d..102628c136a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts @@ -23,6 +23,9 @@ export class TaskManagerComponent implements OnInit { ngOnInit() { this.summaryService.summaryData$.subscribe((data: any) => { + if (!data) { + return; + } this._handleTasks(data.executing_tasks, data.finished_tasks); this._setIcon(data.executing_tasks.length); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts index c2fafa20118..6a03d06efda 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable, NgZone } from '@angular/core'; -import { Subject } from 'rxjs'; +import { BehaviorSubject } from 'rxjs'; import { AuthStorageService } from './auth-storage.service'; import { ServicesModule } from './services.module'; @@ -11,7 +11,7 @@ import { ServicesModule } from './services.module'; }) export class SummaryService { // Observable sources - private summaryDataSource = new Subject(); + private summaryDataSource = new BehaviorSubject(null); // Observable streams summaryData$ = this.summaryDataSource.asObservable(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.ts index 9eedf43e2ff..078d54747ca 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.ts @@ -28,6 +28,9 @@ export class TaskManagerService { constructor(summaryService: SummaryService) { summaryService.summaryData$.subscribe((data: any) => { + if (!data) { + return; + } const executingTasks = data.executing_tasks; const finishedTasks = data.finished_tasks; const newSubscriptions: Array = []; -- 2.39.5