summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/spinner/spinner.component.ts
blob: ebaca62760c186e6b30fd65f9304bfafb1f46610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {Component} from '@angular/core';
import {Subject} from 'rxjs/Subject';
import * as _ from 'lodash';

@Component({
  selector : 'spinner-component',
  templateUrl: './spinner.component.html',
  styleUrls : ['./spinner.component.scss'],
  providers : []

})
export class SpinnerComponent{
  show : boolean;
  size = "large";
  global = true;

  requestMap = {};

  static showSpinner: Subject<SpinnerInfo> = new Subject<SpinnerInfo>();

  constructor(){
    SpinnerComponent.showSpinner.subscribe((spinnerInfo) => {
      let status = spinnerInfo['status'];
      let requestType = spinnerInfo['requestType'];
      let requestUrl = spinnerInfo['requestUrl'];

      if(status && requestType === 'json'){
        this.requestMap[requestUrl] = true;
      }else {
        delete this.requestMap[requestUrl]
      }
      this.show = !_.isEmpty(this.requestMap) && this.requestMap !== undefined;

    })
  }
}


export class SpinnerInfo {
  status : boolean;
  requestUrl : string;
  requestType : string;

  constructor(status : boolean, requestUrl : string, requestType : string){
    this.status = status;
    this.requestUrl = requestUrl;
    this.requestType = requestType;
  }
}