|
|
@ -1,15 +1,25 @@ |
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit, inject, input, effect, signal } from '@angular/core'; |
|
|
import { |
|
|
|
|
|
ChangeDetectionStrategy, |
|
|
|
|
|
Component, |
|
|
|
|
|
effect, |
|
|
|
|
|
inject, |
|
|
|
|
|
input, |
|
|
|
|
|
OnDestroy, |
|
|
|
|
|
OnInit, |
|
|
|
|
|
signal, |
|
|
|
|
|
} from '@angular/core'; |
|
|
import { combineLatest, Subscription, timer } from 'rxjs'; |
|
|
import { combineLatest, Subscription, timer } from 'rxjs'; |
|
|
import { HttpWaitService, RouterWaitService, SubscriptionService } from '@abp/ng.core'; |
|
|
import { HttpWaitService, RouterWaitService, SubscriptionService } from '@abp/ng.core'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
|
selector: 'abp-loader-bar', |
|
|
selector: 'abp-loader-bar', |
|
|
template: ` |
|
|
template: ` |
|
|
<div id="abp-loader-bar" [class]="containerClass()" [class.is-loading]="isLoading()"> |
|
|
<div id="abp-loader-bar" [class]="containerClass()" [class.is-loading]="isLoading()"> |
|
|
<div |
|
|
<div |
|
|
class="abp-progress" |
|
|
class="abp-progress" |
|
|
[class.progressing]="progressLevel" |
|
|
[class.progressing]="progressLevel() > 0" |
|
|
[style.width.vw]="progressLevel" |
|
|
[style.width.vw]="progressLevel()" |
|
|
[style]="{ |
|
|
[style]="{ |
|
|
'background-color': color(), |
|
|
'background-color': color(), |
|
|
'box-shadow': boxShadow, |
|
|
'box-shadow': boxShadow, |
|
|
@ -22,7 +32,6 @@ import { HttpWaitService, RouterWaitService, SubscriptionService } from '@abp/ng |
|
|
imports: [], |
|
|
imports: [], |
|
|
}) |
|
|
}) |
|
|
export class LoaderBarComponent implements OnDestroy, OnInit { |
|
|
export class LoaderBarComponent implements OnDestroy, OnInit { |
|
|
private cdRef = inject(ChangeDetectorRef); |
|
|
|
|
|
private subscription = inject(SubscriptionService); |
|
|
private subscription = inject(SubscriptionService); |
|
|
private httpWaitService = inject(HttpWaitService); |
|
|
private httpWaitService = inject(HttpWaitService); |
|
|
private routerWaitService = inject(RouterWaitService); |
|
|
private routerWaitService = inject(RouterWaitService); |
|
|
@ -32,8 +41,8 @@ export class LoaderBarComponent implements OnDestroy, OnInit { |
|
|
readonly color = input('#77b6ff'); |
|
|
readonly color = input('#77b6ff'); |
|
|
|
|
|
|
|
|
protected readonly isLoading = signal(false); |
|
|
protected readonly isLoading = signal(false); |
|
|
|
|
|
protected readonly progressLevel = signal(0); |
|
|
|
|
|
|
|
|
progressLevel = 0; |
|
|
|
|
|
interval = new Subscription(); |
|
|
interval = new Subscription(); |
|
|
timer = new Subscription(); |
|
|
timer = new Subscription(); |
|
|
intervalPeriod = 350; |
|
|
intervalPeriod = 350; |
|
|
@ -41,28 +50,25 @@ export class LoaderBarComponent implements OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
constructor() { |
|
|
constructor() { |
|
|
effect(() => { |
|
|
effect(() => { |
|
|
const value = this.isLoadingInput(); |
|
|
this.isLoading.set(this.isLoadingInput()); |
|
|
this.isLoading.set(value); |
|
|
|
|
|
this.cdRef.detectChanges(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private readonly clearProgress = () => { |
|
|
private readonly clearProgress = () => { |
|
|
this.progressLevel = 0; |
|
|
this.progressLevel.set(0); |
|
|
this.cdRef.detectChanges(); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
private readonly reportProgress = () => { |
|
|
private readonly reportProgress = () => { |
|
|
if (this.progressLevel < 75) { |
|
|
const current = this.progressLevel(); |
|
|
this.progressLevel += 1 + Math.random() * 9; |
|
|
if (current < 75) { |
|
|
} else if (this.progressLevel < 90) { |
|
|
this.progressLevel.set(current + 1 + Math.random() * 9); |
|
|
this.progressLevel += 0.4; |
|
|
} else if (current < 90) { |
|
|
} else if (this.progressLevel < 100) { |
|
|
this.progressLevel.set(current + 0.4); |
|
|
this.progressLevel += 0.1; |
|
|
} else if (current < 100) { |
|
|
|
|
|
this.progressLevel.set(current + 0.1); |
|
|
} else { |
|
|
} else { |
|
|
this.interval.unsubscribe(); |
|
|
this.interval.unsubscribe(); |
|
|
} |
|
|
} |
|
|
this.cdRef.detectChanges(); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
get boxShadow(): string { |
|
|
get boxShadow(): string { |
|
|
@ -91,8 +97,7 @@ export class LoaderBarComponent implements OnDestroy, OnInit { |
|
|
if (this.isLoading() || !this.interval.closed) return; |
|
|
if (this.isLoading() || !this.interval.closed) return; |
|
|
|
|
|
|
|
|
this.isLoading.set(true); |
|
|
this.isLoading.set(true); |
|
|
this.progressLevel = 0; |
|
|
this.progressLevel.set(0); |
|
|
this.cdRef.detectChanges(); |
|
|
|
|
|
this.interval = timer(0, this.intervalPeriod).subscribe(this.reportProgress); |
|
|
this.interval = timer(0, this.intervalPeriod).subscribe(this.reportProgress); |
|
|
this.timer.unsubscribe(); |
|
|
this.timer.unsubscribe(); |
|
|
} |
|
|
} |
|
|
@ -100,7 +105,7 @@ export class LoaderBarComponent implements OnDestroy, OnInit { |
|
|
stopLoading() { |
|
|
stopLoading() { |
|
|
this.interval.unsubscribe(); |
|
|
this.interval.unsubscribe(); |
|
|
|
|
|
|
|
|
this.progressLevel = 100; |
|
|
this.progressLevel.set(100); |
|
|
this.isLoading.set(false); |
|
|
this.isLoading.set(false); |
|
|
|
|
|
|
|
|
if (!this.timer.closed) return; |
|
|
if (!this.timer.closed) return; |
|
|
|