src/app/pages/dashboard-page/dashboard-page.component.ts
Dashboard page component
selector | app-dashboard-page |
styleUrls | dashboard-page.component.scss |
templateUrl | ./dashboard-page.component.html |
Properties |
|
Methods |
constructor(auth: FirebaseAuthService)
|
||||||||
Constructor
Parameters :
|
ngOnInit |
ngOnInit()
|
Initialize component
Returns :
void
|
dashboardAdmin |
dashboardAdmin:
|
Type : TemplateRef<any>
|
Decorators : ViewChild
|
TemplateRef dashboard admin |
dashboardPhotographer |
dashboardPhotographer:
|
Type : TemplateRef<any>
|
Decorators : ViewChild
|
TemplateRef dashboard photographer |
dashboardUser |
dashboardUser:
|
Type : TemplateRef<any>
|
Decorators : ViewChild
|
TemplateRef dashboard user |
loadingTmpl |
loadingTmpl:
|
Type : TemplateRef<any>
|
Decorators : ViewChild
|
TemplateRef loading |
Private log |
log:
|
Default value : Log.create('DashboardPageComponent')
|
Logger |
Public template |
template:
|
Type : TemplateRef<any>
|
Template ref |
Public user |
user:
|
Type : User
|
Firebase user |
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { Log } from 'ng2-logger';
import { User } from '../../classes/user';
import { FirebaseAuthService } from '../../services/auth/firebase-auth/firebase-auth.service';
/**
* Dashboard page component
* @author Daniel Sogl
*/
@Component({
selector: 'app-dashboard-page',
templateUrl: './dashboard-page.component.html',
styleUrls: ['./dashboard-page.component.scss']
})
export class DashboardPageComponent implements OnInit {
/** Logger */
private log = Log.create('DashboardPageComponent');
/** Firebase user */
public user: User;
/** Template ref */
public template: TemplateRef<any>;
/** TemplateRef loading */
@ViewChild('loadingTmpl') loadingTmpl: TemplateRef<any>;
/** TemplateRef dashboard user */
@ViewChild('dashboardUser') dashboardUser: TemplateRef<any>;
/** TemplateRef dashboard photographer */
@ViewChild('dashboardPhotographer') dashboardPhotographer: TemplateRef<any>;
/** TemplateRef dashboard admin */
@ViewChild('dashboardAdmin') dashboardAdmin: TemplateRef<any>;
/**
* Constructor
* @param {FirebaseAuthService} auth Firebase Auth Service
*/
constructor(private auth: FirebaseAuthService) {}
/**
* Initialize component
*/
ngOnInit() {
this.log.color = 'orange';
this.log.d('Component initialized');
this.template = this.loadingTmpl;
this.auth.user.subscribe((user: any) => {
if (user) {
this.user = user;
this.log.d('Loaded user', this.user);
if (this.user.roles.admin) {
this.template = this.dashboardAdmin;
} else if (this.user.roles.user) {
this.template = this.dashboardUser;
} else {
this.template = this.dashboardPhotographer;
}
}
});
}
}
<div class="row mt-5 pt-5">
<div class="col text-center">
<ng-container *ngTemplateOutlet="template"></ng-container>
</div>
</div>
<ng-template #loadingTmpl>
<mdb-spinner spinnerType="big" spinnerColor="blue"></mdb-spinner>
</ng-template>
<ng-template #dashboardUser>
<app-dashboard-user></app-dashboard-user>
</ng-template>
<ng-template #dashboardPhotographer>
<app-dashboard-photographer></app-dashboard-photographer>
</ng-template>
<ng-template #dashboardAdmin>
<app-dashboard-admin></app-dashboard-admin>
</ng-template>