]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/context/context.component.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / context / context.component.ts
CommitLineData
f67539c2
TL
1import { Component, OnDestroy, OnInit } from '@angular/core';
2import { Event, NavigationEnd, Router } from '@angular/router';
3
4import { NEVER, Subscription } from 'rxjs';
5import { filter } from 'rxjs/operators';
6
7import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
8import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
9import { Permissions } from '~/app/shared/models/permissions';
10import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
11import {
12 FeatureTogglesMap$,
13 FeatureTogglesService
14} from '~/app/shared/services/feature-toggles.service';
15import { TimerService } from '~/app/shared/services/timer.service';
16
17@Component({
18 selector: 'cd-context',
19 templateUrl: './context.component.html',
20 styleUrls: ['./context.component.scss']
21})
22export class ContextComponent implements OnInit, OnDestroy {
23 readonly REFRESH_INTERVAL = 5000;
24 private subs = new Subscription();
25 private rgwUrlPrefix = '/rgw';
26 permissions: Permissions;
27 featureToggleMap$: FeatureTogglesMap$;
28 isRgwRoute = document.location.href.includes(this.rgwUrlPrefix);
29
30 constructor(
31 private authStorageService: AuthStorageService,
32 private featureToggles: FeatureTogglesService,
33 private router: Router,
34 private timerService: TimerService,
35 public rgwDaemonService: RgwDaemonService
36 ) {}
37
38 ngOnInit() {
39 this.permissions = this.authStorageService.getPermissions();
40 this.featureToggleMap$ = this.featureToggles.get();
41 // Check if route belongs to RGW:
42 this.subs.add(
43 this.router.events
44 .pipe(filter((event: Event) => event instanceof NavigationEnd))
45 .subscribe(() => (this.isRgwRoute = this.router.url.includes(this.rgwUrlPrefix)))
46 );
47 // Set daemon list polling only when in RGW route:
48 this.subs.add(
49 this.timerService
50 .get(() => (this.isRgwRoute ? this.rgwDaemonService.list() : NEVER), this.REFRESH_INTERVAL)
51 .subscribe()
52 );
53 }
54
55 ngOnDestroy() {
56 this.subs.unsubscribe();
57 }
58
59 onDaemonSelection(daemon: RgwDaemon) {
60 this.rgwDaemonService.selectDaemon(daemon);
61 this.reloadData();
62 }
63
64 private reloadData() {
65 const currentUrl = this.router.url;
66 this.router.navigateByUrl(this.rgwUrlPrefix, { skipLocationChange: true }).finally(() => {
67 this.router.navigate([currentUrl]);
68 });
69 }
70}