Skip to content

Commit 3fe2a36

Browse files
committed
mgr/dashboard: refactor about.component.ts
Fixes https://tracker.ceph.com/issues/70900 - add i18n - cleanup unused variable - use constants Signed-off-by: Afreen Misbah <[email protected]>
1 parent 583d50a commit 3fe2a36

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<button type="button"
44
class="btn-close float-end"
55
aria-label="Close"
6+
i18n-aria-label
67
(click)="activeModal.close()">
78
</button>
89
</div>
@@ -14,7 +15,7 @@ <h3>
1415
<strong>{{ projectConstants.projectName }}</strong>
1516
</h3>
1617
<div class="product-versions">
17-
<strong>Version</strong>
18+
<strong i18n>Version</strong>
1819
<br>
1920
{{ versionNumber }}
2021
{{ versionHash }}
@@ -23,17 +24,17 @@ <h3>
2324
</div>
2425
<br>
2526
<dl>
26-
<dt>Ceph Manager</dt>
27+
<dt i18n>Ceph Manager</dt>
2728
<dd>{{ hostAddr }}</dd>
28-
<dt>User</dt>
29+
<dt i18n>User</dt>
2930
<dd>{{ modalVariables.user }}</dd>
30-
<dt>User Role</dt>
31+
<dt i18n>User Role</dt>
3132
<dd>{{ modalVariables.role }}</dd>
32-
<dt>Browser</dt>
33+
<dt i18n>Browser</dt>
3334
<dd>{{ modalVariables.browserName }}</dd>
34-
<dt>Browser Version</dt>
35+
<dt i18n>Browser Version</dt>
3536
<dd>{{ modalVariables.browserVersion }}</dd>
36-
<dt>Browser OS</dt>
37+
<dt i18n>Browser OS</dt>
3738
<dd>{{ modalVariables.browserOS }}</dd>
3839
</dl>
3940
</div>

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { detect } from 'detect-browser';
55
import { Subscription } from 'rxjs';
66

77
import { UserService } from '~/app/shared/api/user.service';
8-
import { AppConstants } from '~/app/shared/constants/app.constants';
8+
import { AppConstants, USER, VERSION_PREFIX } from '~/app/shared/constants/app.constants';
9+
import { LocalStorage } from '~/app/shared/enum/local-storage-enum';
910
import { Permission } from '~/app/shared/models/permissions';
1011
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
1112
import { SummaryService } from '~/app/shared/services/summary.service';
@@ -40,7 +41,7 @@ export class AboutComponent implements OnInit, OnDestroy {
4041
this.hostAddr = window.location.hostname;
4142
this.modalVariables = this.setVariables();
4243
this.subs = this.summaryService.subscribe((summary) => {
43-
const version = summary.version.replace('ceph version ', '').split(' ');
44+
const version = summary.version.replace(`${VERSION_PREFIX} `, '').split(' ');
4445
this.hostAddr = summary.mgr_host.replace(/(^\w+:|^)\/\//, '').replace(/\/$/, '');
4546
this.versionNumber = version[0];
4647
this.versionHash = version[1];
@@ -53,18 +54,19 @@ export class AboutComponent implements OnInit, OnDestroy {
5354
}
5455

5556
setVariables() {
57+
const NOT_AVAILABLE = $localize`Not available`;
5658
const project = {} as any;
57-
project.user = localStorage.getItem('dashboard_username');
58-
project.role = 'user';
59+
project.user = localStorage.getItem(LocalStorage.DASHBOARD_USRENAME);
60+
project.role = USER;
5961
if (this.userPermission.read) {
6062
this.userService.get(project.user).subscribe((data: any) => {
6163
project.role = data.roles;
6264
});
6365
}
6466
const browser = detect();
65-
project.browserName = browser && browser.name ? browser.name : 'Not detected';
66-
project.browserVersion = browser && browser.version ? browser.version : 'Not detected';
67-
project.browserOS = browser && browser.os ? browser.os : 'Not detected';
67+
project.browserName = browser && browser.name ? browser.name : NOT_AVAILABLE;
68+
project.browserVersion = browser && browser.version ? browser.version : NOT_AVAILABLE;
69+
project.browserOS = browser && browser.os ? browser.os : NOT_AVAILABLE;
6870
return project;
6971
}
7072
}

src/pybind/mgr/dashboard/frontend/src/app/shared/constants/app.constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,6 @@ export const SSL_CIPHERS = [
370370
'POLY1305',
371371
'DHE'
372372
];
373+
374+
export const USER = 'user';
375+
export const VERSION_PREFIX = 'ceph version';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export enum LocalStorage {
2+
DASHBOARD_USRENAME = 'dashboard_username'
3+
}

0 commit comments

Comments
 (0)