]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Display logged in user
authorguodan1 <guodan1@lenovo.com>
Wed, 26 Sep 2018 03:15:40 +0000 (11:15 +0800)
committerguodan <guodan1@lenovo.com>
Wed, 3 Oct 2018 10:36:50 +0000 (18:36 +0800)
Signed-off-by: guodan1 <guodan1@lenovo.com>
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.html [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.scss [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.spec.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/identity/identity.component.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation.module.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html

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 (file)
index 0000000..c72b7f6
--- /dev/null
@@ -0,0 +1,30 @@
+<div dropdown>
+  <a dropdownToggle
+     class="dropdown-toggle"
+     data-toggle="dropdown"
+     i18n-title
+     title="Logged in user">
+    <i class="fa fa-user fa-fw"></i>
+    <span class="caret"></span>
+  </a>
+  <ul *dropdownMenu
+      class="dropdown-menu dropdown-menu-right"
+      role="menu">
+    <li class="disabled"
+        role="menuitem">
+      <a i18n
+         class="dropdown-item disabled"
+         href="#">Signed in as
+        <strong>{{ username }}</strong>
+      </a>
+    </li>
+    <li class="divider dropdown-divider"></li>
+    <li role="menuitem">
+      <a class="dropdown-item"
+         (click)="logout()">
+        <i class="fa fa-sign-out fa-fw"></i>
+        <span i18n> Sign out</span>
+      </a>
+    </li>
+  </ul>
+</div>
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 (file)
index 0000000..e69de29
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 (file)
index 0000000..17f0ac0
--- /dev/null
@@ -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<IdentityComponent>;
+
+  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 (file)
index 0000000..ffa18b1
--- /dev/null
@@ -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']);
+    });
+  }
+}
index f35e78fd7337b2238f52612b5dbd57493e175f94..0b74b9bbdfde0fbe14a96eb61bc08ac4a6de4f5f 100644 (file)
@@ -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]
 })
index 910e759212aaaf1c6426078d1be4c2af3506d345..b1786224ea01ff06cba67960bc25068845199606 100644 (file)
       <li>
         <cd-administration class="oa-navbar"></cd-administration>
       </li>
-      <li class="tc_logout">
-        <cd-logout class="oa-navbar"></cd-logout>
+      <li>
+        <cd-identity class="oa-navbar"></cd-identity>
       </li>
     </ul>
     <!-- /.navbar-utility -->