]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / navigation / about / about.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core';
2
3 import { detect } from 'detect-browser';
4 import { BsModalRef } from 'ngx-bootstrap/modal';
5 import { Subscription } from 'rxjs';
6 import { environment } from '../../../../environments/environment';
7 import { UserService } from '../../../shared/api/user.service';
8 import { AppConstants } from '../../../shared/constants/app.constants';
9 import { Permission } from '../../../shared/models/permissions';
10 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
11 import { SummaryService } from '../../../shared/services/summary.service';
12
13 @Component({
14 selector: 'cd-about',
15 templateUrl: './about.component.html',
16 styleUrls: ['./about.component.scss']
17 })
18 export class AboutComponent implements OnInit, OnDestroy {
19 modalVariables: any;
20 versionNumber: string;
21 versionHash: string;
22 versionName: string;
23 subs: Subscription;
24 userPermission: Permission;
25 projectConstants: typeof AppConstants;
26 hostAddr: string;
27 copyright: string;
28
29 constructor(
30 public modalRef: BsModalRef,
31 private summaryService: SummaryService,
32 private userService: UserService,
33 private authStorageService: AuthStorageService
34 ) {
35 this.userPermission = this.authStorageService.getPermissions().user;
36 }
37
38 ngOnInit() {
39 this.copyright = 'Copyright(c) ' + environment.year + ' Ceph contributors.';
40 this.projectConstants = AppConstants;
41 this.hostAddr = window.location.hostname;
42 this.modalVariables = this.setVariables();
43 this.subs = this.summaryService.subscribe((summary) => {
44 const version = summary.version.replace('ceph version ', '').split(' ');
45 this.hostAddr = summary.mgr_host.replace(/(^\w+:|^)\/\//, '').replace(/\/$/, '');
46 this.versionNumber = version[0];
47 this.versionHash = version[1];
48 this.versionName = version.slice(2, version.length).join(' ');
49 });
50 }
51
52 ngOnDestroy(): void {
53 this.subs.unsubscribe();
54 }
55
56 setVariables() {
57 const project = {} as any;
58 project.user = localStorage.getItem('dashboard_username');
59 project.role = 'user';
60 if (this.userPermission.read) {
61 this.userService.get(project.user).subscribe((data: any) => {
62 project.role = data.roles;
63 });
64 }
65 const browser = detect();
66 project.browserName = browser && browser.name ? browser.name : 'Not detected';
67 project.browserVersion = browser && browser.version ? browser.version : 'Not detected';
68 project.browserOS = browser && browser.os ? browser.os : 'Not detected';
69 return project;
70 }
71 }