File

src/app/pages/dashboard-page/dashboard-page.component.ts

Description

Dashboard page component

Implements

OnInit

Example

Metadata

selector app-dashboard-page
styleUrls dashboard-page.component.scss
templateUrl ./dashboard-page.component.html

Index

Properties
Methods

Constructor

constructor(auth: FirebaseAuthService)

Constructor

Parameters :
Name Type Optional Description
auth FirebaseAuthService

Firebase Auth Service

Methods

ngOnInit
ngOnInit()

Initialize component

Returns : void

Properties

dashboardAdmin
dashboardAdmin: TemplateRef<any>
Type : TemplateRef<any>
Decorators : ViewChild

TemplateRef dashboard admin

dashboardPhotographer
dashboardPhotographer: TemplateRef<any>
Type : TemplateRef<any>
Decorators : ViewChild

TemplateRef dashboard photographer

dashboardUser
dashboardUser: TemplateRef<any>
Type : TemplateRef<any>
Decorators : ViewChild

TemplateRef dashboard user

loadingTmpl
loadingTmpl: TemplateRef<any>
Type : TemplateRef<any>
Decorators : ViewChild

TemplateRef loading

Private log
log:
Default value : Log.create('DashboardPageComponent')

Logger

Public template
template: TemplateRef<any>
Type : TemplateRef<any>

Template ref

Public user
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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""