1 import { Component, Input, NgZone, OnChanges, OnDestroy } from '@angular/core';
3 import * as _ from 'lodash';
4 import { Subscription, timer } from 'rxjs';
6 import { CephfsService } from '../../../shared/api/cephfs.service';
7 import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
8 import { Permission } from '../../../shared/models/permissions';
9 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
12 selector: 'cd-cephfs-tabs',
13 templateUrl: './cephfs-tabs.component.html',
14 styleUrls: ['./cephfs-tabs.component.scss']
16 export class CephfsTabsComponent implements OnChanges, OnDestroy {
22 grafanaPermission: Permission;
26 clients: Record<string, any> = {
28 status: ViewCacheStatus.ValueNone
32 details: Record<string, any> = {
41 directoriesSelected = false;
44 private reloadSubscriber: Subscription;
47 private ngZone: NgZone,
48 private authStorageService: AuthStorageService,
49 private cephfsService: CephfsService
51 this.grafanaPermission = this.authStorageService.getPermissions().grafana;
55 if (!this.selection) {
56 this.unsubscribeInterval();
59 if (this.selection.id !== this.id) {
60 this.setupSelected(this.selection.id, this.selection.mdsmap.info);
64 private setupSelected(id: number, mdsInfo: any) {
66 const firstMds: any = _.first(Object.values(mdsInfo));
67 this.grafanaId = firstMds && firstMds['name'];
77 status: ViewCacheStatus.ValueNone
79 this.updateInterval();
82 private updateInterval() {
83 this.unsubscribeInterval();
84 this.subscribeInterval();
87 private unsubscribeInterval() {
88 if (this.reloadSubscriber) {
89 this.reloadSubscriber.unsubscribe();
93 private subscribeInterval() {
94 this.ngZone.runOutsideAngular(
96 (this.reloadSubscriber = timer(0, 5000).subscribe(() =>
97 this.ngZone.run(() => this.refresh())
103 this.cephfsService.getTabs(this.id).subscribe(
109 this.clients.status = ViewCacheStatus.ValueException;
115 const data = _.cloneDeep(this.data); // Forces update of tab tables on tab switch
117 this.clients = data.clients;
120 standbys: data.standbys,
123 mdsCounters: data.mds_counters,
129 this.unsubscribeInterval();