diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/core/context/context.component.ts')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/src/app/core/context/context.component.ts | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/context/context.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/context/context.component.ts new file mode 100644 index 000000000..8de611307 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/context/context.component.ts @@ -0,0 +1,70 @@ +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Event, NavigationEnd, Router } from '@angular/router'; + +import { NEVER, Subscription } from 'rxjs'; +import { filter } from 'rxjs/operators'; + +import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon'; +import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service'; +import { Permissions } from '~/app/shared/models/permissions'; +import { AuthStorageService } from '~/app/shared/services/auth-storage.service'; +import { + FeatureTogglesMap$, + FeatureTogglesService +} from '~/app/shared/services/feature-toggles.service'; +import { TimerService } from '~/app/shared/services/timer.service'; + +@Component({ + selector: 'cd-context', + templateUrl: './context.component.html', + styleUrls: ['./context.component.scss'] +}) +export class ContextComponent implements OnInit, OnDestroy { + readonly REFRESH_INTERVAL = 5000; + private subs = new Subscription(); + private rgwUrlPrefix = '/rgw'; + permissions: Permissions; + featureToggleMap$: FeatureTogglesMap$; + isRgwRoute = document.location.href.includes(this.rgwUrlPrefix); + + constructor( + private authStorageService: AuthStorageService, + private featureToggles: FeatureTogglesService, + private router: Router, + private timerService: TimerService, + public rgwDaemonService: RgwDaemonService + ) {} + + ngOnInit() { + this.permissions = this.authStorageService.getPermissions(); + this.featureToggleMap$ = this.featureToggles.get(); + // Check if route belongs to RGW: + this.subs.add( + this.router.events + .pipe(filter((event: Event) => event instanceof NavigationEnd)) + .subscribe(() => (this.isRgwRoute = this.router.url.startsWith(this.rgwUrlPrefix))) + ); + // Set daemon list polling only when in RGW route: + this.subs.add( + this.timerService + .get(() => (this.isRgwRoute ? this.rgwDaemonService.list() : NEVER), this.REFRESH_INTERVAL) + .subscribe() + ); + } + + ngOnDestroy() { + this.subs.unsubscribe(); + } + + onDaemonSelection(daemon: RgwDaemon) { + this.rgwDaemonService.selectDaemon(daemon); + this.reloadData(); + } + + private reloadData() { + const currentUrl = this.router.url; + this.router.navigateByUrl(this.rgwUrlPrefix, { skipLocationChange: true }).finally(() => { + this.router.navigate([currentUrl]); + }); + } +} |