From e60ab33e90c9ca839f08581d03e91f5f2118a0f5 Mon Sep 17 00:00:00 2001 From: guodan1 Date: Wed, 26 Sep 2018 11:15:40 +0800 Subject: [PATCH] mgr/dashboard: Display logged in user Signed-off-by: guodan1 --- .../identity/identity.component.html | 30 +++++++++++++++++++ .../identity/identity.component.scss | 0 .../identity/identity.component.spec.ts | 27 +++++++++++++++++ .../navigation/identity/identity.component.ts | 30 +++++++++++++++++++ .../app/core/navigation/navigation.module.ts | 4 ++- .../navigation/navigation.component.html | 4 +-- 6 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.html create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.scss create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.spec.ts create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.ts diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.html b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.html new file mode 100644 index 0000000000000..c72b7f62513e2 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.html @@ -0,0 +1,30 @@ +
+ + + + + +
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.scss b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.scss new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.spec.ts new file mode 100644 index 0000000000000..17f0ac0bfb8d1 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.spec.ts @@ -0,0 +1,27 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { configureTestBed } from '../../../../testing/unit-test-helper'; +import { SharedModule } from '../../../shared/shared.module'; +import { IdentityComponent } from './identity.component'; + +describe('IdentityComponent', () => { + let component: IdentityComponent; + let fixture: ComponentFixture; + + configureTestBed({ + imports: [HttpClientTestingModule, SharedModule, RouterTestingModule], + declarations: [IdentityComponent] + }); + + beforeEach(() => { + fixture = TestBed.createComponent(IdentityComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.ts new file mode 100644 index 0000000000000..ffa18b1bd78b6 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.ts @@ -0,0 +1,30 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { AuthService } from '../../../shared/api/auth.service'; +import { AuthStorageService } from '../../../shared/services/auth-storage.service'; + +@Component({ + selector: 'cd-identity', + templateUrl: './identity.component.html', + styleUrls: ['./identity.component.scss'] +}) +export class IdentityComponent implements OnInit { + username: string; + + constructor( + private router: Router, + private authStorageService: AuthStorageService, + private authService: AuthService + ) {} + + ngOnInit() { + this.username = this.authStorageService.getUsername(); + } + + logout() { + this.authService.logout(() => { + this.router.navigate(['/login']); + }); + } +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation.module.ts index f35e78fd7337b..0b74b9bbdfde0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation.module.ts @@ -11,6 +11,7 @@ import { AboutComponent } from './about/about.component'; import { AdministrationComponent } from './administration/administration.component'; import { BreadcrumbsComponent } from './breadcrumbs/breadcrumbs.component'; import { DashboardHelpComponent } from './dashboard-help/dashboard-help.component'; +import { IdentityComponent } from './identity/identity.component'; import { NavigationComponent } from './navigation/navigation.component'; import { NotificationsComponent } from './notifications/notifications.component'; import { TaskManagerComponent } from './task-manager/task-manager.component'; @@ -35,7 +36,8 @@ import { TaskManagerComponent } from './task-manager/task-manager.component'; NotificationsComponent, TaskManagerComponent, DashboardHelpComponent, - AdministrationComponent + AdministrationComponent, + IdentityComponent ], exports: [NavigationComponent, BreadcrumbsComponent] }) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html index 910e759212aaa..b1786224ea01f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html @@ -199,8 +199,8 @@
  • -
  • - +
  • +
  • -- 2.39.5