-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloading-progress.service.ts
85 lines (70 loc) · 2.33 KB
/
loading-progress.service.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {Injectable} from "@angular/core";
import {Logger} from "@aws-amplify/core";
import {ProgressSpinnerMode} from "@angular/material/progress-spinner";
const log = new Logger("loading");
@Injectable({
providedIn: "root"
})
export class LoadingProgressService {
private maxStages = 8;
private currentStage = 0;
private loadingComplete = false;
public showSpinner = false;
public showProgress = false;
public opacity = 1.0;
public spinnerMode: ProgressSpinnerMode = "determinate";
private _progressPercentage = 0;
public get progressPercentage(): number {
return this._progressPercentage;
}
public set progressPercentage(value: number) {
this._progressPercentage = value;
}
constructor() {
}
public progress(message: string, stage: number = -1) {
this.spinnerMode = "determinate";
if (!this.loadingComplete && stage > 0 && stage > this.currentStage) {
this.currentStage = stage;
this.showSpinner = true;
this._progressPercentage = this.currentStage / this.maxStages;
this.opacity = 1.0;
}
log.info(message);
}
public showDeterminateProgress(message: string, percentage: number) {
this.spinnerMode = "indeterminate";
this.opacity = 0.2;
this.showProgress = true;
this.showSpinner = true;
if (percentage > this._progressPercentage) {
this._progressPercentage = percentage;
}
log.info(message + " " + percentage * 100 + "%");
}
public loaded(): void {
log.info("Finished loading");
this.currentStage = 0;
this.loadingComplete = true;
this.showSpinner = false;
this._progressPercentage = 100;
$("#loading-div").css("opacity", 0.0);
setTimeout(() => $("#loading-div").remove(), 1000);
}
public showIndeterminateSpinner() {
this.showSpinner = true;
this.spinnerMode = "indeterminate";
}
public hideIndeterminateSpinner() {
this.showSpinner = false;
this.spinnerMode = "determinate";
}
public hideSpinner() {
this.showSpinner = false;
}
public hideProgress() {
this._progressPercentage = 0;
this.showProgress = false;
this.showSpinner = false;
}
}