Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {Component} from '@angular/core'; |
| 2 | import {Subject} from 'rxjs/Subject'; |
| 3 | import * as _ from 'lodash'; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 4 | |
| 5 | @Component({ |
| 6 | selector : 'spinner-component', |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 7 | templateUrl: './spinner.component.html', |
| 8 | styleUrls : ['./spinner.component.scss'], |
| 9 | providers : [] |
| 10 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 11 | }) |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 12 | export class SpinnerComponent{ |
| 13 | show : boolean; |
| 14 | size = "large"; |
| 15 | global = true; |
| 16 | |
| 17 | requestMap = {}; |
| 18 | |
| 19 | static showSpinner: Subject<SpinnerInfo> = new Subject<SpinnerInfo>(); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 20 | |
| 21 | constructor(){ |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 22 | SpinnerComponent.showSpinner.subscribe((spinnerInfo) => { |
| 23 | let status = spinnerInfo['status']; |
| 24 | let requestType = spinnerInfo['requestType']; |
| 25 | let requestUrl = spinnerInfo['requestUrl']; |
| 26 | |
| 27 | if(status && requestType === 'json'){ |
| 28 | this.requestMap[requestUrl] = true; |
| 29 | }else { |
| 30 | delete this.requestMap[requestUrl] |
| 31 | } |
| 32 | console.log(this.requestMap); |
| 33 | this.show = !_.isEmpty(this.requestMap) && this.requestMap !== undefined; |
| 34 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 35 | }) |
| 36 | } |
| 37 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 38 | |
| 39 | |
| 40 | export class SpinnerInfo { |
| 41 | status : boolean; |
| 42 | requestUrl : string; |
| 43 | requestType : string; |
| 44 | |
| 45 | constructor(status : boolean, requestUrl : string, requestType : string){ |
| 46 | this.status = status; |
| 47 | this.requestUrl = requestUrl; |
| 48 | this.requestType = requestType; |
| 49 | } |
| 50 | } |