File

projects/maplander/core/src/lib/interceptors/loader/loader.component.ts

Implements

OnInit OnDestroy

Metadata

selector lib-loader
styleUrls ./loader.component.scss
templateUrl ./loader.component.html

Index

Properties
Methods

Constructor

constructor(_platformId: Object, _loader: LoaderService)
Parameters :
Name Type Optional
_platformId Object No
_loader LoaderService No

Methods

Private clearTimeOut
clearTimeOut()
Returns : void
Private createTimer
createTimer()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Private _subscription
Type : Subscription
Private _timeOut
Type : any
Public show
Type : boolean
Public text
Type : string
import {Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '@angular/core';
import {LoaderService} from './loader.service';
import {Subscription} from 'rxjs';
import {isPlatformBrowser} from '@angular/common';

@Component({
  selector: 'lib-loader',
  templateUrl: './loader.component.html',
  styleUrls: ['./loader.component.scss']
})
export class LoaderComponent implements OnInit, OnDestroy {

  public show: boolean;
  public text: string;
  private _timeOut: any;
  private _subscription: Subscription;

  constructor(
    @Inject(PLATFORM_ID) private _platformId: Object,
    private _loader: LoaderService
  ) {
    this.show = false;
    this.text = '';
    this._subscription = new Subscription();
  }

  ngOnInit() {
    this._subscription.add(
      this._loader.getProgress().subscribe(value => {
        this.text = '';
        this.show = value;
        if (isPlatformBrowser(this._platformId)) {
          this.createTimer();
        }
      })
    );
  }

  ngOnDestroy(): void {
    this._subscription.unsubscribe();
  }

  private createTimer(): void {
    if (this.show) {
      if (this._timeOut) {
        this.clearTimeOut();
      }
      this._timeOut = setTimeout(() => {
        if (this.show) {
          this.text = 'Esta operaciĆ³n puede durar varios minutos...';
        }
        clearTimeout(this._timeOut);
        this._timeOut = null;
      }, 60000);
    } else if (this._timeOut) {
      this.clearTimeOut();
    }
  }

  private clearTimeOut(): void {
    clearTimeout(this._timeOut);
    this._timeOut = null;
  }

}
<ng-template [ngIf]="show">
  <div class="container">
    <mat-card>
      <mat-progress-spinner mode="indeterminate" color="primary" [diameter]="35"></mat-progress-spinner>
      <ng-template [ngIf]="text !== ''">
        <p>{{text}}</p>
      </ng-template>
    </mat-card>
  </div>
</ng-template>

./loader.component.scss

.container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  display: flex;
  background: rgba(255, 255, 255, 0.6);

  mat-card {
    padding: 16px;
    margin: auto;
    box-sizing: border-box;
    background-color: #323232;

    p {
      width: 150px;
      margin: 16px 0 0 0;
      color: white;
      font-size: 12px;
    }

    mat-progress-spinner {
      margin: 0 auto;
    }
  }
}

.hidden {
  display: none !important;
}

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""