@@ -4,70 +4,76 @@ import { NavigationStart, Router } from '@angular/router';
44import { Observable , Subscription } from 'rxjs' ;
55import { filter , map } from 'rxjs/operators' ;
66import { UserInfoService } from 'src/app/modules/user/services/user-info.service' ;
7-
7+ import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service' ;
88@Component ( {
99 selector : 'app-sidebar' ,
1010 templateUrl : './sidebar.component.html' ,
1111 styleUrls : [ './sidebar.component.scss' ] ,
1212} )
1313export class SidebarComponent implements OnInit , OnDestroy {
14- itemsSidebar : ItemSidebar [ ] = [ ] ;
14+ itemsSidebar : ItemSidebar [ ] ;
1515 navStart ;
1616 sidebarItems$ : Subscription ;
17+ userName : string ;
18+ userEmail : string ;
1719
18- constructor (
19- private router : Router ,
20- private userInfoService : UserInfoService ,
21- ) {
20+ constructor ( private router : Router , private userInfoService : UserInfoService , private azureAdB2CService : AzureAdB2CService ) {
2221 this . navStart = this . router . events . pipe (
2322 filter ( ( evt ) => evt instanceof NavigationStart )
2423 ) as Observable < NavigationStart > ;
2524 }
2625
2726 ngOnInit ( ) : void {
28- this . toggleSideBar ( ) ;
2927 const currentRouting = this . router . routerState . snapshot . url ;
3028 this . sidebarItems$ = this . getSidebarItems ( ) . subscribe ( ( ) => this . highlightMenuOption ( currentRouting ) ) ;
3129 this . navStart . subscribe ( ( evt ) => {
3230 this . highlightMenuOption ( evt . url ) ;
3331 } ) ;
32+ if ( this . azureAdB2CService . isLogin ( ) ) {
33+ this . userName = this . azureAdB2CService . getName ( ) ;
34+ this . userEmail = this . azureAdB2CService . getUserEmail ( ) ;
35+ }
3436 }
3537
3638 ngOnDestroy ( ) : void {
3739 this . sidebarItems$ . unsubscribe ( ) ;
3840 }
3941
4042 toggleSideBar ( ) {
41- $ ( '#menu-toggle' ) . on ( 'click' , ( e ) => {
42- e . preventDefault ( ) ;
43- $ ( '#wrapper' ) . toggleClass ( 'toggled' ) ;
44- } ) ;
43+ $ ( '#wrapper' ) . toggleClass ( 'toggled' ) ;
44+ $ ( '#show-sidebar' ) . toggle ( ) ;
45+ $ ( '#hide-sidebar' ) . toggle ( ) ;
4546 }
4647
4748 getSidebarItems ( ) : Observable < void > {
4849 return this . userInfoService . isAdmin ( ) . pipe (
4950 map ( ( isAdmin ) => {
5051 if ( isAdmin ) {
5152 this . itemsSidebar = [
52- { route : '/time-clock' , icon : 'fas fa- clock' , text : 'Time Clock' , active : false } ,
53- { route : '/time-entries' , icon : 'fas fa-list-alt ' , text : 'Time Entries' , active : false } ,
54- { route : '/reports' , icon : 'fas fa-chart-pie ' , text : 'Reports' , active : false } ,
55- { route : '/activities-management' , icon : 'fas fa-file-alt ' , text : 'Activities' , active : false } ,
56- { route : '/customers-management' , icon : 'fas fa-user ' , text : 'Customers' , active : false } ,
57- { route : '/users' , icon : 'fas fa-user ' , text : 'Users' , active : false } ,
53+ { route : '/time-clock' , icon : 'assets/icons/ clock.svg ' , text : 'Time Clock' , active : false } ,
54+ { route : '/time-entries' , icon : 'assets/icons/time-entries.svg ' , text : 'Time Entries' , active : false } ,
55+ { route : '/reports' , icon : 'assets/icons/reports.svg ' , text : 'Reports' , active : false } ,
56+ { route : '/activities-management' , icon : 'assets/icons/activities.svg ' , text : 'Activities' , active : false } ,
57+ { route : '/customers-management' , icon : 'assets/icons/customers.svg ' , text : 'Customers' , active : false } ,
58+ { route : '/users' , icon : 'assets/icons/users.svg ' , text : 'Users' , active : false } ,
5859 ] ;
5960 } else {
6061 this . itemsSidebar = [
61- { route : '/time-clock' , icon : 'fas fa- clock' , text : 'Time Clock' , active : false } ,
62- { route : '/time-entries' , icon : 'fas fa-list-alt ' , text : 'Time Entries' , active : false } ,
62+ { route : '/time-clock' , icon : 'assets/icons/ clock.svg ' , text : 'Time Clock' , active : false } ,
63+ { route : '/time-entries' , icon : 'assets/icons/time-entries.svg ' , text : 'Time Entries' , active : false } ,
6364 ] ;
6465 }
6566 } )
6667 ) ;
6768 }
6869
70+
6971 highlightMenuOption ( route ) {
7072 this . itemsSidebar . map ( ( item ) => ( item . active = false ) ) ;
7173 this . itemsSidebar . filter ( ( item ) => item . route === route ) . map ( ( item ) => ( item . active = true ) ) ;
7274 }
75+
76+ logout ( ) {
77+ this . azureAdB2CService . logout ( ) ;
78+ }
7379}
0 commit comments