+ Are you sure you want to continue?
+
+
+
+
+
diff --git a/src/app/top-bar/top-bar.component.ts b/src/app/top-bar/top-bar.component.ts
index ad4c0d4..bf6d5c2 100644
--- a/src/app/top-bar/top-bar.component.ts
+++ b/src/app/top-bar/top-bar.component.ts
@@ -1,10 +1,11 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {MenuService} from '../service/menu.service';
import {AuthService} from '../service/auth.service';
-import {mainMenuItems} from '../main-menu-items';
+import {brokerMenuItems, mainMenuItems, peopleMenuItems, userMenuItems} from '../main-menu-items';
import {apiV1LoginResponse} from '../models/api-v1-login-response';
import {Subscription} from 'rxjs';
+
@Component({
selector: 'app-top-bar',
templateUrl: './top-bar.component.html',
@@ -12,11 +13,16 @@ import {Subscription} from 'rxjs';
})
export class TopBarComponent implements OnInit , OnDestroy {
login = false;
- Avatar = './assets/img/avatar.png';
+ Avatar = './assets/img/logout.png';
public items: any[] = mainMenuItems;
private loginSub: Subscription;
+ public showMenu = true;
+
+ public opened = false;
- constructor(private menuService: MenuService, private authService: AuthService,) { }
+ constructor(private menuService: MenuService,
+ private authService: AuthService) {
+ }
ngOnInit(): void {
this.initAndSubLogin();
@@ -24,15 +30,39 @@ export class TopBarComponent implements OnInit , OnDestroy {
public initAndSubLogin(): void{
this.login = this.authService.loggedIn.login;
- console.log('subscribe auto login');
+ this.selectMenuShow(this.authService.loggedIn.role);
+ // console.log('subscribe auto login', this.authService.loggedIn);
this.loginSub = this.authService.loginSuccess.subscribe(
(rsp: apiV1LoginResponse) => {
this.login = rsp.login;
+ this.selectMenuShow(rsp.role);
console.log ('topbar received auth events', rsp);
}
);
}
+ private selectMenuShow(role: string): void {
+ this.showMenu = true;
+ switch ( role ){
+ case 'admin':
+ this.items = mainMenuItems;
+ break;
+ case 'broker':
+ this.items = brokerMenuItems;
+ break;
+ case 'user':
+ this.items = userMenuItems;
+ break;
+ case 'people':
+ this.items = peopleMenuItems;
+ break;
+
+ default:
+ this.showMenu = false;
+ }
+
+ }
+
// check menuItem has fontawesome
public menuItemHasFontawesome(item: any): boolean {
return item.hasOwnProperty('fa');
@@ -57,4 +87,14 @@ export class TopBarComponent implements OnInit , OnDestroy {
this.loginSub.unsubscribe();
}
+ public logout(): void{
+ this.opened = true;
+ }
+
+ public close(action: string): void {
+ this.opened = false;
+ if ( action === 'yes') {
+ this.authService.logout();
+ }
+ }
}
diff --git a/src/assets/img/logout.png b/src/assets/img/logout.png
new file mode 100644
index 0000000..2e3e758
Binary files /dev/null and b/src/assets/img/logout.png differ