zavadil-ts-common 1.2.61 → 1.2.63

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zavadil-ts-common",
3
- "version": "1.2.61",
3
+ "version": "1.2.63",
4
4
  "description": "Common types and components for Typescript UI apps.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -6,7 +6,7 @@ export class UserAlerts {
6
6
 
7
7
  private maxAlerts: number;
8
8
 
9
- public maxVisibilitySecs: number;
9
+ public maxVisibilityMs: number;
10
10
 
11
11
  private em: EventManager;
12
12
 
@@ -14,9 +14,9 @@ export class UserAlerts {
14
14
 
15
15
  public visibleAlerts: Array<UserAlert>;
16
16
 
17
- constructor(maxAlerts: number = 10, maxVisibilitySecs: number = 5) {
17
+ constructor(maxAlerts: number = 20, maxVisibilityMs: number = 7000) {
18
18
  this.maxAlerts = maxAlerts;
19
- this.maxVisibilitySecs = maxVisibilitySecs;
19
+ this.maxVisibilityMs = maxVisibilityMs;
20
20
  this.em = new EventManager();
21
21
  this.alerts = [];
22
22
  this.visibleAlerts = [];
@@ -53,12 +53,12 @@ export class UserAlerts {
53
53
  updateVisibility() {
54
54
  this.visibleAlerts.forEach(
55
55
  a => {
56
- const elapsedMs = DateUtil.getSinceDurationMs(a.time) || 0;
57
- const remainsSecs = this.maxVisibilitySecs - (elapsedMs / 1000);
58
- if (remainsSecs > 0) {
59
- a.remainsSecs = remainsSecs;
56
+ const elapsedMs = DateUtil.getSinceDurationMs(a.time) || this.maxVisibilityMs;
57
+ const remainsMs = this.maxVisibilityMs - elapsedMs;
58
+ if (remainsMs > 0) {
59
+ a.remainsMs = remainsMs;
60
60
  } else {
61
- a.remainsSecs = undefined;
61
+ a.remainsMs = undefined;
62
62
  this.hide(a);
63
63
  }
64
64
  }
@@ -72,8 +72,8 @@ export class UserAlerts {
72
72
  };
73
73
 
74
74
  add(alert: UserAlert) {
75
- if (alert.remainsSecs === undefined) {
76
- alert.remainsSecs = this.maxVisibilitySecs;
75
+ if (alert.remainsMs === undefined) {
76
+ alert.remainsMs = this.maxVisibilityMs;
77
77
  }
78
78
  this.alerts.push(alert);
79
79
  this.visibleAlerts.push(alert);
@@ -8,5 +8,5 @@ export type UserAlert = {
8
8
  time: Date;
9
9
  type: UserAlertType;
10
10
  message: string;
11
- remainsSecs?: number; //remain visible for this amount of seconds
11
+ remainsMs?: number; //remain visible for this amount of seconds
12
12
  }
@@ -1,4 +1,5 @@
1
1
  import {ObjectUtil} from "./ObjectUtil";
2
+ import {NumberUtil} from "./NumberUtil";
2
3
 
3
4
  export class DateUtil {
4
5
 
@@ -93,7 +94,7 @@ export class DateUtil {
93
94
  if (hrs > 0) items.push(`${hrs}h`);
94
95
  if (mins > 0) items.push(`${mins}m`);
95
96
  if (secs > 0 && days === 0 && hrs === 0) items.push(`${secs}s`);
96
- if (ms > 0 && days === 0 && hrs === 0 && mins === 0) items.push(`${ms}ms`);
97
+ if (ms > 0 && days === 0 && hrs === 0 && mins === 0) items.push(`${NumberUtil.round(ms, 2)}ms`);
97
98
 
98
99
  return items.join(' ');
99
100
  }