zavadil-ts-common 1.2.57 → 1.2.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component/UserAlerts.d.ts +6 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/type/UserAlert.d.ts +1 -0
- package/package.json +1 -1
- package/src/component/UserAlerts.ts +38 -1
- package/src/type/UserAlert.ts +1 -0
@@ -1,18 +1,25 @@
|
|
1
1
|
import {UserAlert, UserAlertType} from "../type";
|
2
2
|
import {EventManager, Func} from "./EventManager";
|
3
|
+
import {DateUtil} from "../util";
|
3
4
|
|
4
5
|
export class UserAlerts {
|
5
6
|
|
6
7
|
private maxAlerts: number;
|
7
8
|
|
9
|
+
public maxVisibilitySecs: number;
|
10
|
+
|
8
11
|
private em: EventManager;
|
9
12
|
|
10
13
|
public alerts: Array<UserAlert>;
|
11
14
|
|
12
|
-
|
15
|
+
public visibleAlerts: Array<UserAlert>;
|
16
|
+
|
17
|
+
constructor(maxAlerts: number = 10, maxVisibilitySecs: number = 5) {
|
13
18
|
this.maxAlerts = maxAlerts;
|
19
|
+
this.maxVisibilitySecs = maxVisibilitySecs;
|
14
20
|
this.em = new EventManager();
|
15
21
|
this.alerts = [];
|
22
|
+
this.visibleAlerts = [];
|
16
23
|
}
|
17
24
|
|
18
25
|
addOnChangeHandler(h: Func) {
|
@@ -29,6 +36,32 @@ export class UserAlerts {
|
|
29
36
|
|
30
37
|
reset() {
|
31
38
|
this.alerts = [];
|
39
|
+
this.visibleAlerts = [];
|
40
|
+
this.triggerChange();
|
41
|
+
}
|
42
|
+
|
43
|
+
hide(alert: UserAlert) {
|
44
|
+
this.visibleAlerts.splice(this.visibleAlerts.indexOf(alert), 1);
|
45
|
+
this.triggerChange();
|
46
|
+
}
|
47
|
+
|
48
|
+
hideAll() {
|
49
|
+
this.visibleAlerts = [];
|
50
|
+
this.triggerChange();
|
51
|
+
}
|
52
|
+
|
53
|
+
updateVisibility() {
|
54
|
+
this.visibleAlerts.forEach(
|
55
|
+
a => {
|
56
|
+
const remainsMs = DateUtil.getSinceDurationMs(a.time);
|
57
|
+
if (remainsMs !== null && remainsMs > 0) {
|
58
|
+
a.remainsSecs = remainsMs * 1000;
|
59
|
+
} else {
|
60
|
+
a.remainsSecs = undefined;
|
61
|
+
this.hide(a);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
);
|
32
65
|
this.triggerChange();
|
33
66
|
}
|
34
67
|
|
@@ -38,7 +71,11 @@ export class UserAlerts {
|
|
38
71
|
};
|
39
72
|
|
40
73
|
add(alert: UserAlert) {
|
74
|
+
if (alert.remainsSecs === undefined) {
|
75
|
+
alert.remainsSecs = this.maxVisibilitySecs;
|
76
|
+
}
|
41
77
|
this.alerts.push(alert);
|
78
|
+
this.visibleAlerts.push(alert);
|
42
79
|
while (this.alerts.length > this.maxAlerts) {
|
43
80
|
this.alerts.shift();
|
44
81
|
}
|