From 6123910ff2856d1321142c094811ea7e359c679a Mon Sep 17 00:00:00 2001 From: Pedro Gonzalez Gomez Date: Mon, 25 Jul 2022 21:50:47 +0200 Subject: [PATCH] mgr/dashboard: details card mgr/dashboard: added interface, changed html table to list, using mgrModuleService now Signed-off-by: Pedro Gonzalez Gomez --- .../dashboard/dashboard.component.html | 9 ++- .../dashboard/dashboard.component.spec.ts | 55 ++++++++++++++++++- .../dashboard/dashboard.component.ts | 36 +++++++++++- .../src/app/shared/models/cd-details.ts | 5 ++ 4 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-details.ts diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html index 24cfd5445b4c1..c384687fbdad3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html @@ -3,7 +3,14 @@ - Text +
+
FSID
+
{{ detailsCardData.fsid }}
+
Orchestror
+
{{ detailsCardData.orchestrator }}
+
Ceph version
+
{{ detailsCardData.cephVersion }}
+
{ let component: DashboardComponent; let fixture: ComponentFixture; + let configurationService: ConfigurationService; + let orchestratorService: MgrModuleService; + + const configValueData: any = { + value: [ + { + section: 'mgr', + value: 'e90a0d58-658e-4148-8f61-e896c86f0696' + } + ] + }; + + const orchData: any = { + log_level: '', + log_to_cluster: false, + log_to_cluster_level: 'info', + log_to_file: false, + orchestrator: 'cephadm' + }; configureTestBed({ - imports: [RouterTestingModule], - declarations: [DashboardComponent, CardComponent] + imports: [HttpClientTestingModule], + declarations: [DashboardComponent, CardComponent], + providers: [{ provide: SummaryService, useClass: SummaryServiceMock }] }); beforeEach(() => { fixture = TestBed.createComponent(DashboardComponent); component = fixture.componentInstance; + configurationService = TestBed.inject(ConfigurationService); + orchestratorService = TestBed.inject(MgrModuleService); }); it('should create', () => { @@ -27,4 +67,13 @@ describe('CardComponent', () => { const dashboardCards = fixture.debugElement.nativeElement.querySelectorAll('cd-card'); expect(dashboardCards.length).toBe(6); }); + + it('should get corresponding data into detailsCardData', () => { + spyOn(configurationService, 'get').and.returnValue(of(configValueData)); + spyOn(orchestratorService, 'getConfig').and.returnValue(of(orchData)); + component.ngOnInit(); + expect(component.detailsCardData.fsid).toBe('e90a0d58-658e-4148-8f61-e896c86f0696'); + expect(component.detailsCardData.orchestrator).toBe('Cephadm'); + expect(component.detailsCardData.cephVersion).toBe('17.0.0-12222-gcd0cd7cb quincy (dev)'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts index e18b06df0333c..775c5eabe5ab2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts @@ -1,8 +1,40 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; + +import { ConfigurationService } from '~/app/shared/api/configuration.service'; +import { MgrModuleService } from '~/app/shared/api/mgr-module.service'; +import { DashboardDetails } from '~/app/shared/models/cd-details'; +import { SummaryService } from '~/app/shared/services/summary.service'; @Component({ selector: 'cd-dashboard', templateUrl: './dashboard.component.html', styleUrls: ['./dashboard.component.scss'] }) -export class DashboardComponent {} +export class DashboardComponent implements OnInit { + detailsCardData: DashboardDetails = {}; + + constructor( + private summaryService: SummaryService, + private configService: ConfigurationService, + private mgrModuleService: MgrModuleService + ) {} + + ngOnInit() { + this.getDetailsCardData(); + } + + getDetailsCardData() { + this.configService.get('fsid').subscribe((data) => { + this.detailsCardData.fsid = data['value'][0]['value']; + }); + this.mgrModuleService.getConfig('orchestrator').subscribe((data) => { + const orchStr = data['orchestrator']; + this.detailsCardData.orchestrator = orchStr.charAt(0).toUpperCase() + orchStr.slice(1); + }); + this.summaryService.subscribe((summary) => { + const version = summary.version.replace('ceph version ', '').split(' '); + this.detailsCardData.cephVersion = + version[0] + ' ' + version.slice(2, version.length).join(' '); + }); + } +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-details.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-details.ts new file mode 100644 index 0000000000000..d021f19eba733 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-details.ts @@ -0,0 +1,5 @@ +export interface DashboardDetails { + fsid?: string; + orchestrator?: string; + cephVersion?: string; +} -- 2.39.5