quasar-ui-danx 0.4.20 → 0.4.21
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/danx.es.js +1974 -1953
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +46 -46
- package/dist/danx.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/formats.ts +6 -0
- package/src/helpers/objectStore.ts +29 -0
package/package.json
CHANGED
package/src/helpers/formats.ts
CHANGED
@@ -144,6 +144,9 @@ export function fElapsedTime(start: string, end?: string) {
|
|
144
144
|
* Formats an amount into USD currency format
|
145
145
|
*/
|
146
146
|
export function fCurrency(amount: number, options?: object) {
|
147
|
+
if (amount === null || amount === undefined || isNaN(amount)) {
|
148
|
+
return "$-";
|
149
|
+
}
|
147
150
|
return new Intl.NumberFormat("en-US", {
|
148
151
|
style: "currency",
|
149
152
|
currency: "USD",
|
@@ -179,6 +182,9 @@ export function fShortCurrency(value: string | number, options?: { round: boolea
|
|
179
182
|
* Formats a number into a shorthand human-readable format (ie: 1.2M or 5K)
|
180
183
|
*/
|
181
184
|
export function fShortNumber(value: string | number, options?: { round: boolean }) {
|
185
|
+
if (value === "" || value === null || value === undefined) {
|
186
|
+
return "-";
|
187
|
+
}
|
182
188
|
const shorts = [
|
183
189
|
{ pow: 3, unit: "K" },
|
184
190
|
{ pow: 6, unit: "M" },
|
@@ -1,9 +1,19 @@
|
|
1
1
|
import { uid } from "quasar";
|
2
2
|
import { ShallowReactive, shallowReactive } from "vue";
|
3
3
|
import { TypedObject } from "../types";
|
4
|
+
import { FlashMessages } from "./FlashMessages";
|
4
5
|
|
5
6
|
const store = new Map<string, any>();
|
6
7
|
|
8
|
+
export function storeObjects<T extends TypedObject>(newObjects: T[]) {
|
9
|
+
for (const index in newObjects) {
|
10
|
+
if (newObjects[index] && typeof newObjects[index] === "object") {
|
11
|
+
newObjects[index] = storeObject(newObjects[index]);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
return newObjects;
|
15
|
+
}
|
16
|
+
|
7
17
|
/**
|
8
18
|
* Store an object in the object store via type + id
|
9
19
|
* Returns the stored object that should be used instead of the passed object as the returned object is shared across the system
|
@@ -56,3 +66,22 @@ export function storeObject<T extends TypedObject>(newObject: T): ShallowReactiv
|
|
56
66
|
store.set(objectKey, reactiveObject);
|
57
67
|
return reactiveObject;
|
58
68
|
}
|
69
|
+
|
70
|
+
export async function autoRefreshObject<T extends TypedObject>(object: T, condition: (object: T) => boolean, callback: (object: T) => Promise<T>, interval = 3000) {
|
71
|
+
if (!object?.id || !object?.__type) {
|
72
|
+
throw new Error("Invalid stored object. Cannot auto-refresh");
|
73
|
+
}
|
74
|
+
|
75
|
+
if (condition(object)) {
|
76
|
+
console.log("condition true", object);
|
77
|
+
const refreshedObject = await callback(object);
|
78
|
+
|
79
|
+
if (!refreshedObject.id) {
|
80
|
+
return FlashMessages.error(`Failed to refresh ${object.__type} (${object.id}) status: ` + object.name);
|
81
|
+
}
|
82
|
+
|
83
|
+
storeObject(refreshedObject);
|
84
|
+
}
|
85
|
+
|
86
|
+
setTimeout(() => autoRefreshObject(object, condition, callback), interval);
|
87
|
+
}
|