quasar-ui-danx 0.4.41 → 0.4.43
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/danx.es.js +3731 -3568
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +68 -68
- package/dist/danx.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/ActionTable/Layouts/ActionTableLayout.vue +4 -1
- package/src/components/ActionTable/controls.ts +1 -1
- package/src/components/PanelsDrawer/PanelsDrawer.vue +15 -4
- package/src/components/Utility/Buttons/ActionButton.vue +67 -9
- package/src/components/Utility/Buttons/index.ts +1 -0
- package/src/components/Utility/Dialogs/InfoDialog.vue +2 -0
- package/src/components/Utility/Files/FilePreview.vue +14 -8
- package/src/components/Utility/Layouts/CollapsableSidebar.vue +41 -51
- package/src/helpers/actions.ts +15 -2
- package/src/helpers/formats.ts +6 -3
- package/src/helpers/objectStore.ts +31 -14
- package/src/helpers/request.ts +20 -10
- package/src/helpers/routes.ts +76 -13
- package/src/types/actions.d.ts +1 -0
- package/src/types/controls.d.ts +7 -3
- package/src/types/requests.d.ts +1 -0
package/package.json
CHANGED
@@ -57,6 +57,7 @@
|
|
57
57
|
:model-value="activePanel"
|
58
58
|
:target="activeItem"
|
59
59
|
:panels="controller.panels"
|
60
|
+
:drawer-class="drawerClass"
|
60
61
|
@update:model-value="panel => controller.activatePanel(activeItem, panel)"
|
61
62
|
@close="controller.setActiveItem(null)"
|
62
63
|
>
|
@@ -91,6 +92,7 @@ export interface ActionTableLayoutProps {
|
|
91
92
|
showFilters?: boolean;
|
92
93
|
tableClass?: string;
|
93
94
|
title?: string;
|
95
|
+
drawerClass?: string;
|
94
96
|
}
|
95
97
|
|
96
98
|
const props = withDefaults(defineProps<ActionTableLayoutProps>(), {
|
@@ -98,7 +100,8 @@ const props = withDefaults(defineProps<ActionTableLayoutProps>(), {
|
|
98
100
|
panelTitleField: "",
|
99
101
|
selection: "multiple",
|
100
102
|
tableClass: "",
|
101
|
-
title: ""
|
103
|
+
title: "",
|
104
|
+
drawerClass: ""
|
102
105
|
});
|
103
106
|
|
104
107
|
const activeFilter = computed(() => props.controller.activeFilter.value);
|
@@ -119,7 +119,7 @@ export function useControls(name: string, options: ListControlsOptions): ListCon
|
|
119
119
|
|
120
120
|
isLoadingFilters.value = true;
|
121
121
|
try {
|
122
|
-
fieldOptions.value = await options.routes.fieldOptions(
|
122
|
+
fieldOptions.value = await options.routes.fieldOptions() || {};
|
123
123
|
} catch (e) {
|
124
124
|
// Fail silently
|
125
125
|
} finally {
|
@@ -9,7 +9,10 @@
|
|
9
9
|
no-route-dismiss
|
10
10
|
@update:show="$emit('close')"
|
11
11
|
>
|
12
|
-
<div
|
12
|
+
<div
|
13
|
+
class="flex flex-col flex-nowrap h-full dx-panels-drawer-content"
|
14
|
+
:class="drawerClass"
|
15
|
+
>
|
13
16
|
<div class="dx-panels-drawer-header flex items-center px-6 py-4">
|
14
17
|
<div class="flex-grow">
|
15
18
|
<slot name="header">
|
@@ -64,6 +67,12 @@
|
|
64
67
|
<slot name="right-sidebar" />
|
65
68
|
</div>
|
66
69
|
</div>
|
70
|
+
<div
|
71
|
+
v-else
|
72
|
+
class="p-8"
|
73
|
+
>
|
74
|
+
<QSkeleton class="h-96" />
|
75
|
+
</div>
|
67
76
|
</div>
|
68
77
|
</div>
|
69
78
|
</ContentDrawer>
|
@@ -76,22 +85,24 @@ import { ContentDrawer } from "../Utility";
|
|
76
85
|
import PanelsDrawerPanels from "./PanelsDrawerPanels";
|
77
86
|
import PanelsDrawerTabs from "./PanelsDrawerTabs";
|
78
87
|
|
79
|
-
export interface
|
88
|
+
export interface PanelsDrawerProps {
|
80
89
|
title?: string,
|
81
90
|
modelValue?: string | number,
|
82
91
|
target: ActionTargetItem;
|
83
92
|
tabsClass?: string | object,
|
84
93
|
panelsClass?: string | object,
|
94
|
+
drawerClass?: string | object,
|
85
95
|
position?: "standard" | "right" | "left";
|
86
96
|
panels: ActionPanel[]
|
87
97
|
}
|
88
98
|
|
89
99
|
defineEmits(["update:model-value", "close"]);
|
90
|
-
const props = withDefaults(defineProps<
|
100
|
+
const props = withDefaults(defineProps<PanelsDrawerProps>(), {
|
91
101
|
title: "",
|
92
102
|
modelValue: null,
|
93
103
|
tabsClass: "w-[13.5rem] flex-shrink-0",
|
94
|
-
panelsClass: "w-
|
104
|
+
panelsClass: "w-full",
|
105
|
+
drawerClass: "",
|
95
106
|
position: "right"
|
96
107
|
});
|
97
108
|
|
@@ -2,8 +2,9 @@
|
|
2
2
|
<QBtn
|
3
3
|
:loading="isSaving"
|
4
4
|
class="shadow-none"
|
5
|
-
:class="colorClass"
|
6
|
-
|
5
|
+
:class="disabled ? disabledClass : colorClass"
|
6
|
+
:disable="disabled"
|
7
|
+
@click="()=> onAction()"
|
7
8
|
>
|
8
9
|
<div class="flex items-center flex-nowrap">
|
9
10
|
<component
|
@@ -26,11 +27,36 @@
|
|
26
27
|
>
|
27
28
|
{{ tooltip }}
|
28
29
|
</QTooltip>
|
30
|
+
<QMenu
|
31
|
+
v-if="isConfirming"
|
32
|
+
:model-value="true"
|
33
|
+
>
|
34
|
+
<div class="p-4 bg-slate-600">
|
35
|
+
<div>{{ confirmText }}</div>
|
36
|
+
<div class="flex items-center flex-nowrap mt-2">
|
37
|
+
<div class="flex-grow">
|
38
|
+
<ActionButton
|
39
|
+
type="cancel"
|
40
|
+
color="gray"
|
41
|
+
@click="isConfirming = false"
|
42
|
+
/>
|
43
|
+
</div>
|
44
|
+
<ActionButton
|
45
|
+
type="confirm"
|
46
|
+
color="green"
|
47
|
+
@click="()=> onAction(true)"
|
48
|
+
/>
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
</QMenu>
|
29
52
|
</QBtn>
|
30
53
|
</template>
|
31
54
|
<script setup lang="ts">
|
32
55
|
import {
|
33
56
|
FaSolidArrowsRotate as RefreshIcon,
|
57
|
+
FaSolidCircleCheck as ConfirmIcon,
|
58
|
+
FaSolidCircleXmark as CancelIcon,
|
59
|
+
FaSolidCopy as CopyIcon,
|
34
60
|
FaSolidPause as PauseIcon,
|
35
61
|
FaSolidPencil as EditIcon,
|
36
62
|
FaSolidPlay as PlayIcon,
|
@@ -38,11 +64,11 @@ import {
|
|
38
64
|
FaSolidStop as StopIcon,
|
39
65
|
FaSolidTrash as TrashIcon
|
40
66
|
} from "danx-icon";
|
41
|
-
import { computed } from "vue";
|
67
|
+
import { computed, ref } from "vue";
|
42
68
|
import { ActionTarget, ResourceAction } from "../../../types";
|
43
69
|
|
44
70
|
export interface ActionButtonProps {
|
45
|
-
type?: "trash" | "trash-red" | "create" | "edit" | "play" | "stop" | "pause" | "refresh";
|
71
|
+
type?: "trash" | "trash-red" | "create" | "edit" | "copy" | "play" | "stop" | "pause" | "refresh" | "confirm" | "cancel";
|
46
72
|
color?: "red" | "blue" | "sky" | "green" | "green-invert" | "lime" | "white" | "gray";
|
47
73
|
icon?: object | string;
|
48
74
|
iconClass?: string;
|
@@ -52,6 +78,10 @@ export interface ActionButtonProps {
|
|
52
78
|
action?: ResourceAction;
|
53
79
|
target?: ActionTarget;
|
54
80
|
input?: object;
|
81
|
+
disabled?: boolean;
|
82
|
+
disabledClass?: string;
|
83
|
+
confirm?: boolean;
|
84
|
+
confirmText?: string;
|
55
85
|
}
|
56
86
|
|
57
87
|
const emit = defineEmits(["success", "error", "always"]);
|
@@ -64,7 +94,9 @@ const props = withDefaults(defineProps<ActionButtonProps>(), {
|
|
64
94
|
tooltip: "",
|
65
95
|
action: null,
|
66
96
|
target: null,
|
67
|
-
input: null
|
97
|
+
input: null,
|
98
|
+
confirmText: "Are you sure?",
|
99
|
+
disabledClass: "text-slate-800 bg-slate-500 opacity-50"
|
68
100
|
});
|
69
101
|
|
70
102
|
const colorClass = computed(() => {
|
@@ -101,11 +133,26 @@ const typeOptions = computed(() => {
|
|
101
133
|
icon: CreateIcon,
|
102
134
|
iconClass: "w-3"
|
103
135
|
};
|
136
|
+
case "confirm":
|
137
|
+
return {
|
138
|
+
icon: ConfirmIcon,
|
139
|
+
iconClass: "w-3"
|
140
|
+
};
|
141
|
+
case "cancel":
|
142
|
+
return {
|
143
|
+
icon: CancelIcon,
|
144
|
+
iconClass: "w-3"
|
145
|
+
};
|
104
146
|
case "edit":
|
105
147
|
return {
|
106
148
|
icon: EditIcon,
|
107
149
|
iconClass: "w-3"
|
108
150
|
};
|
151
|
+
case "copy":
|
152
|
+
return {
|
153
|
+
icon: CopyIcon,
|
154
|
+
iconClass: "w-3"
|
155
|
+
};
|
109
156
|
case "play":
|
110
157
|
return {
|
111
158
|
icon: PlayIcon,
|
@@ -136,19 +183,28 @@ const typeOptions = computed(() => {
|
|
136
183
|
|
137
184
|
const isSaving = computed(() => {
|
138
185
|
if (props.saving) return true;
|
186
|
+
if (props.action) {
|
187
|
+
return props.action.isApplying;
|
188
|
+
}
|
139
189
|
if (props.target) {
|
140
190
|
if (Array.isArray(props.target)) {
|
141
191
|
return props.target.some((t) => t.isSaving);
|
142
192
|
}
|
143
193
|
return props.target.isSaving;
|
144
194
|
}
|
145
|
-
if (props.action) {
|
146
|
-
return props.action.isApplying;
|
147
|
-
}
|
148
195
|
return false;
|
149
196
|
});
|
150
197
|
|
151
|
-
|
198
|
+
const isConfirming = ref(false);
|
199
|
+
function onAction(isConfirmed = false) {
|
200
|
+
if (props.disabled) return;
|
201
|
+
|
202
|
+
// Make sure this action is confirmed if the confirm prop is set
|
203
|
+
if (props.confirm && !isConfirmed) {
|
204
|
+
isConfirming.value = true;
|
205
|
+
return false;
|
206
|
+
}
|
207
|
+
isConfirming.value = false;
|
152
208
|
if (props.action) {
|
153
209
|
props.action.trigger(props.target, props.input).then(async (response) => {
|
154
210
|
emit("success", typeof response.json === "function" ? await response.json() : response);
|
@@ -158,6 +214,8 @@ function onAction() {
|
|
158
214
|
}).finally(() => {
|
159
215
|
emit("always");
|
160
216
|
});
|
217
|
+
} else {
|
218
|
+
emit("always");
|
161
219
|
}
|
162
220
|
}
|
163
221
|
</script>
|
@@ -23,6 +23,7 @@
|
|
23
23
|
:label="doneText"
|
24
24
|
class="dx-dialog-button dx-dialog-button-done"
|
25
25
|
:class="doneClass"
|
26
|
+
:disable="disable"
|
26
27
|
@click="onClose"
|
27
28
|
>
|
28
29
|
<slot name="done-text" />
|
@@ -39,6 +40,7 @@ import DialogLayout from "./DialogLayout";
|
|
39
40
|
const emit = defineEmits(["update:model-value", "close"]);
|
40
41
|
defineProps({
|
41
42
|
...DialogLayout.props,
|
43
|
+
disable: Boolean,
|
42
44
|
doneClass: {
|
43
45
|
type: [String, Object],
|
44
46
|
default: ""
|
@@ -39,18 +39,23 @@
|
|
39
39
|
>
|
40
40
|
<PdfIcon
|
41
41
|
v-if="isPdf"
|
42
|
-
class="w-
|
42
|
+
class="w-3/4"
|
43
43
|
/>
|
44
44
|
<TextFileIcon
|
45
45
|
v-else
|
46
|
-
class="w-
|
46
|
+
class="w-3/4"
|
47
47
|
/>
|
48
|
-
<
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
<template v-if="filename">
|
49
|
+
<div
|
50
|
+
v-if="showFilename"
|
51
|
+
class="text-[.7rem] bg-slate-900 text-slate-300 opacity-80 h-[2.25rem] py-.5 px-1 absolute-bottom"
|
52
|
+
>
|
53
|
+
{{ filename }}
|
54
|
+
</div>
|
55
|
+
<QTooltip v-else>
|
56
|
+
{{ filename }}
|
57
|
+
</QTooltip>
|
58
|
+
</template>
|
54
59
|
</div>
|
55
60
|
</div>
|
56
61
|
<div
|
@@ -152,6 +157,7 @@ export interface FilePreviewProps {
|
|
152
157
|
file?: UploadedFile;
|
153
158
|
relatedFiles?: UploadedFile[];
|
154
159
|
missingIcon?: any;
|
160
|
+
showFilename?: boolean;
|
155
161
|
downloadButtonClass?: string;
|
156
162
|
imageFit?: "cover" | "contain" | "fill" | "none" | "scale-down";
|
157
163
|
downloadable?: boolean;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<template>
|
2
2
|
<div
|
3
|
-
class="dx-collapsable-sidebar overflow-
|
3
|
+
class="dx-collapsable-sidebar overflow-hidden scroll-smooth flex-shrink-0 flex-nowrap transition-all relative"
|
4
4
|
:class="{
|
5
5
|
'is-collapsed': isCollapsed,
|
6
6
|
'is-right-side': rightSide,
|
@@ -8,99 +8,89 @@
|
|
8
8
|
}"
|
9
9
|
:style="style"
|
10
10
|
>
|
11
|
-
<div class="flex-grow max-w-full">
|
11
|
+
<div class="flex-grow max-w-full overflow-y-auto overflow-x-hidden">
|
12
12
|
<slot :is-collapsed="isCollapsed" />
|
13
13
|
</div>
|
14
14
|
<template v-if="!disabled && (!hideToggleOnCollapse || !isCollapsed)">
|
15
15
|
<div
|
16
16
|
v-if="!toggleAtTop"
|
17
|
-
class="flex w-full p-4"
|
18
|
-
:class="
|
17
|
+
class="flex w-full p-4 flex-shrink-0"
|
18
|
+
:class="{'justify-start': rightSide, 'justify-end': !rightSide, ...resolveToggleClass}"
|
19
19
|
>
|
20
20
|
<slot name="toggle">
|
21
21
|
<QBtn
|
22
22
|
class="btn-secondary"
|
23
23
|
@click="toggleCollapse"
|
24
24
|
>
|
25
|
-
<ToggleIcon
|
26
|
-
class="w-5 transition-all"
|
27
|
-
:class="{ 'rotate-180': rightSide ? !isCollapsed : isCollapsed }"
|
28
|
-
/>
|
25
|
+
<ToggleIcon :class="{ 'rotate-180': rightSide ? !isCollapsed : isCollapsed, ...resolvedToggleIconClass }" />
|
29
26
|
</QBtn>
|
30
27
|
</slot>
|
31
28
|
</div>
|
32
29
|
<div
|
33
30
|
v-else
|
34
31
|
class="absolute top-0 right-0 cursor-pointer p-2"
|
35
|
-
:class="
|
32
|
+
:class="resolveToggleClass"
|
36
33
|
@click="toggleCollapse"
|
37
34
|
>
|
38
|
-
<ToggleIcon
|
39
|
-
class="w-5 transition-all"
|
40
|
-
:class="{ 'rotate-180': rightSide ? !isCollapsed : isCollapsed }"
|
41
|
-
/>
|
35
|
+
<ToggleIcon :class="{ 'rotate-180': rightSide ? !isCollapsed : isCollapsed, ...resolvedToggleIconClass }" />
|
42
36
|
</div>
|
43
37
|
</template>
|
44
38
|
</div>
|
45
39
|
</template>
|
46
|
-
<script setup>
|
40
|
+
<script setup lang="ts">
|
47
41
|
import { ChevronLeftIcon as ToggleIcon } from "@heroicons/vue/outline";
|
48
42
|
import { computed, onMounted, ref, watch } from "vue";
|
49
43
|
import { getItem, setItem } from "../../../helpers";
|
44
|
+
import { AnyObject } from "../../../types";
|
50
45
|
|
51
46
|
const emit = defineEmits(["collapse", "update:collapse"]);
|
52
|
-
const props = defineProps
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
},
|
72
|
-
toggleAtTop: Boolean,
|
73
|
-
toggleClass: {
|
74
|
-
type: String,
|
75
|
-
default: ""
|
76
|
-
},
|
77
|
-
hideToggleOnCollapse: Boolean
|
47
|
+
const props = withDefaults(defineProps<{
|
48
|
+
displayClass?: string;
|
49
|
+
toggleClass?: string | AnyObject;
|
50
|
+
toggleIconClass?: string | AnyObject;
|
51
|
+
rightSide?: boolean;
|
52
|
+
maxWidth?: string;
|
53
|
+
minWidth?: string;
|
54
|
+
disabled?: boolean;
|
55
|
+
collapse?: boolean;
|
56
|
+
name?: string;
|
57
|
+
toggleAtTop?: boolean;
|
58
|
+
hideToggleOnCollapse?: boolean;
|
59
|
+
}>(), {
|
60
|
+
displayClass: "flex flex-col",
|
61
|
+
maxWidth: "13.5rem",
|
62
|
+
minWidth: "5.5rem",
|
63
|
+
name: "sidebar",
|
64
|
+
toggleClass: "",
|
65
|
+
toggleIconClass: "w-5 transition-all"
|
78
66
|
});
|
79
67
|
|
80
68
|
const isCollapsed = ref(getItem(props.name + "-is-collapsed", props.collapse));
|
81
69
|
|
82
70
|
function setCollapse(state) {
|
83
|
-
|
84
|
-
|
71
|
+
isCollapsed.value = state;
|
72
|
+
setItem(props.name + "-is-collapsed", !!isCollapsed.value);
|
85
73
|
}
|
86
74
|
|
87
75
|
function toggleCollapse() {
|
88
|
-
|
89
|
-
|
90
|
-
|
76
|
+
setCollapse(!isCollapsed.value);
|
77
|
+
emit("collapse", isCollapsed.value);
|
78
|
+
emit("update:collapse", isCollapsed.value);
|
91
79
|
}
|
92
80
|
|
93
81
|
onMounted(() => {
|
94
|
-
|
95
|
-
|
82
|
+
emit("collapse", isCollapsed.value);
|
83
|
+
emit("update:collapse", isCollapsed.value);
|
96
84
|
});
|
97
85
|
const style = computed(() => {
|
98
|
-
|
99
|
-
|
100
|
-
|
86
|
+
return {
|
87
|
+
width: isCollapsed.value ? props.minWidth : props.maxWidth
|
88
|
+
};
|
101
89
|
});
|
102
90
|
|
91
|
+
const resolveToggleClass = computed(() => typeof props.toggleClass === "string" ? { [props.toggleClass]: true } : props.toggleClass);
|
92
|
+
const resolvedToggleIconClass = computed(() => typeof props.toggleIconClass === "string" ? { [props.toggleIconClass]: true } : props.toggleIconClass);
|
103
93
|
watch(() => props.collapse, () => {
|
104
|
-
|
94
|
+
setCollapse(props.collapse);
|
105
95
|
});
|
106
96
|
</script>
|
package/src/helpers/actions.ts
CHANGED
@@ -3,7 +3,14 @@ import { FaSolidCopy as CopyIcon, FaSolidPencil as EditIcon, FaSolidTrash as Del
|
|
3
3
|
import { uid } from "quasar";
|
4
4
|
import { h, isReactive, Ref, shallowReactive, shallowRef } from "vue";
|
5
5
|
import { ConfirmActionDialog, CreateNewWithNameDialog } from "../components";
|
6
|
-
import type {
|
6
|
+
import type {
|
7
|
+
ActionGlobalOptions,
|
8
|
+
ActionOptions,
|
9
|
+
ActionTarget,
|
10
|
+
ActionTargetItem,
|
11
|
+
ListController,
|
12
|
+
ResourceAction
|
13
|
+
} from "../types";
|
7
14
|
import { FlashMessages } from "./FlashMessages";
|
8
15
|
import { storeObject } from "./objectStore";
|
9
16
|
|
@@ -233,12 +240,18 @@ async function onConfirmAction(action: ActionOptions, target: ActionTarget, inpu
|
|
233
240
|
result = { error: `Action ${action.name} does not support batch actions` };
|
234
241
|
}
|
235
242
|
} else {
|
243
|
+
const __timestamp = Date.now();
|
244
|
+
if (action.optimisticDelete) {
|
245
|
+
storeObject({ ...target, __deleted_at: new Date().toISOString(), __timestamp } as ActionTargetItem);
|
246
|
+
}
|
247
|
+
|
236
248
|
// If the action has an optimistic callback, we call it before the actual action to immediately
|
237
249
|
// update the UI
|
238
250
|
if (typeof action.optimistic === "function") {
|
239
251
|
action.optimistic(action, target, input);
|
252
|
+
storeObject({ ...target, __timestamp } as ActionTargetItem);
|
240
253
|
} else if (action.optimistic) {
|
241
|
-
storeObject({ ...target, ...input });
|
254
|
+
storeObject({ ...target, ...input, __timestamp });
|
242
255
|
}
|
243
256
|
|
244
257
|
result = await action.onAction(action.alias || action.name, target, input);
|
package/src/helpers/formats.ts
CHANGED
@@ -89,11 +89,14 @@ export function fDate(dateTime: string | DateTime | null, { empty = "--", format
|
|
89
89
|
/**
|
90
90
|
* Parses a date string into a Luxon DateTime object
|
91
91
|
*/
|
92
|
-
export function parseDateTime(dateTime: string | DateTime | null): DateTime<boolean> | null {
|
92
|
+
export function parseDateTime(dateTime: string | DateTime | number | null): DateTime<boolean> | null {
|
93
|
+
if (typeof dateTime === "number") {
|
94
|
+
return DateTime.fromMillis(dateTime as number);
|
95
|
+
}
|
93
96
|
if (typeof dateTime === "string") {
|
94
97
|
return parseGenericDateTime(dateTime);
|
95
98
|
}
|
96
|
-
return dateTime || DateTime.fromSQL("0000-00-00 00:00:00");
|
99
|
+
return dateTime as DateTime<boolean> || DateTime.fromSQL("0000-00-00 00:00:00");
|
97
100
|
}
|
98
101
|
|
99
102
|
/**
|
@@ -193,7 +196,7 @@ export function fSecondsToDuration(seconds: number) {
|
|
193
196
|
/**
|
194
197
|
* Formats a duration between two date strings in 00h 00m 00s format
|
195
198
|
*/
|
196
|
-
export function fDuration(start: string, end?: string) {
|
199
|
+
export function fDuration(start: string | number, end?: string | number) {
|
197
200
|
const endDateTime = end ? parseDateTime(end) : DateTime.now();
|
198
201
|
const diff = endDateTime?.diff(parseDateTime(start) || DateTime.now(), ["hours", "minutes", "seconds"]);
|
199
202
|
if (!diff?.isValid) {
|
@@ -22,7 +22,7 @@ export function storeObject<T extends TypedObject>(newObject: T, recentlyStoredO
|
|
22
22
|
if (typeof newObject !== "object") {
|
23
23
|
return newObject;
|
24
24
|
}
|
25
|
-
|
25
|
+
|
26
26
|
const id = newObject?.id || newObject?.name;
|
27
27
|
const type = newObject?.__type;
|
28
28
|
if (!id || !type) return shallowReactive(newObject);
|
@@ -49,6 +49,9 @@ export function storeObject<T extends TypedObject>(newObject: T, recentlyStoredO
|
|
49
49
|
// @ts-expect-error __timestamp is guaranteed to be set in this case on both old and new
|
50
50
|
if (oldObject && newObject.__timestamp < oldObject.__timestamp) {
|
51
51
|
recentlyStoredObjects[objectKey] = oldObject;
|
52
|
+
|
53
|
+
// Recursively store all the children of the object as well
|
54
|
+
storeObjectChildren(newObject, recentlyStoredObjects, oldObject);
|
52
55
|
return oldObject;
|
53
56
|
}
|
54
57
|
|
@@ -59,19 +62,7 @@ export function storeObject<T extends TypedObject>(newObject: T, recentlyStoredO
|
|
59
62
|
recentlyStoredObjects[objectKey] = reactiveObject;
|
60
63
|
|
61
64
|
// Recursively store all the children of the object as well
|
62
|
-
|
63
|
-
const value = newObject[key];
|
64
|
-
if (Array.isArray(value) && value.length > 0) {
|
65
|
-
for (const index in value) {
|
66
|
-
if (value[index] && typeof value[index] === "object") {
|
67
|
-
newObject[key][index] = storeObject(value[index], recentlyStoredObjects);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
} else if (value?.__type) {
|
71
|
-
// @ts-expect-error __type is guaranteed to be set in this case
|
72
|
-
newObject[key] = storeObject(value as TypedObject, recentlyStoredObjects);
|
73
|
-
}
|
74
|
-
}
|
65
|
+
storeObjectChildren(newObject, recentlyStoredObjects);
|
75
66
|
|
76
67
|
Object.assign(reactiveObject, newObject);
|
77
68
|
|
@@ -87,6 +78,32 @@ export function storeObject<T extends TypedObject>(newObject: T, recentlyStoredO
|
|
87
78
|
return reactiveObject;
|
88
79
|
}
|
89
80
|
|
81
|
+
/**
|
82
|
+
* A recursive way to store all the child TypedObjects of a TypedObject.
|
83
|
+
* recentlyStoredObjects is used to avoid infinite recursion
|
84
|
+
* applyToObject is used to apply the stored objects to a different object than the one being stored.
|
85
|
+
* The apply to object is the current object being returned by storeObject() - Normally, the oldObject if it has a more recent timestamp than the newObject being stored.
|
86
|
+
*/
|
87
|
+
function storeObjectChildren<T extends TypedObject>(object: T, recentlyStoredObjects: AnyObject = {}, applyToObject: T | null = null) {
|
88
|
+
applyToObject = applyToObject || object;
|
89
|
+
for (const key of Object.keys(object)) {
|
90
|
+
const value = object[key];
|
91
|
+
if (Array.isArray(value) && value.length > 0) {
|
92
|
+
for (const index in value) {
|
93
|
+
if (value[index] && typeof value[index] === "object") {
|
94
|
+
if (!applyToObject[key]) {
|
95
|
+
applyToObject[key] = [];
|
96
|
+
}
|
97
|
+
applyToObject[key][index] = storeObject(value[index], recentlyStoredObjects);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
} else if (value?.__type) {
|
101
|
+
// @ts-expect-error __type is guaranteed to be set in this case
|
102
|
+
applyToObject[key] = storeObject(value as TypedObject, recentlyStoredObjects);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
90
107
|
/**
|
91
108
|
* Remove an object from all lists in the store
|
92
109
|
*/
|
package/src/helpers/request.ts
CHANGED
@@ -19,8 +19,8 @@ export const request: RequestApi = {
|
|
19
19
|
|
20
20
|
async call(url, options) {
|
21
21
|
options = options || {};
|
22
|
-
const abortKey = options?.abortOn !== undefined ? options.abortOn : url;
|
23
|
-
const timestamp =
|
22
|
+
const abortKey = options?.abortOn !== undefined ? options.abortOn : url + JSON.stringify(options.params || "");
|
23
|
+
const timestamp = Date.now();
|
24
24
|
|
25
25
|
if (abortKey) {
|
26
26
|
const abort = new AbortController();
|
@@ -42,12 +42,20 @@ export const request: RequestApi = {
|
|
42
42
|
options.params[key] = JSON.stringify(value);
|
43
43
|
}
|
44
44
|
}
|
45
|
-
|
45
|
+
|
46
46
|
url += (url.match(/\?/) ? "&" : "?") + new URLSearchParams(options.params).toString();
|
47
47
|
delete options.params;
|
48
48
|
}
|
49
49
|
|
50
|
-
|
50
|
+
let response = null;
|
51
|
+
try {
|
52
|
+
response = await fetch(request.url(url), options);
|
53
|
+
} catch (e) {
|
54
|
+
if (options.ignoreAbort && (e + "").match(/Request was aborted/)) {
|
55
|
+
return { abort: true };
|
56
|
+
}
|
57
|
+
throw e;
|
58
|
+
}
|
51
59
|
|
52
60
|
// Verify the app version of the client and server are matching
|
53
61
|
checkAppVersion(response);
|
@@ -97,12 +105,13 @@ export const request: RequestApi = {
|
|
97
105
|
async get(url, options) {
|
98
106
|
return await request.call(url, {
|
99
107
|
method: "get",
|
108
|
+
...options,
|
100
109
|
headers: {
|
101
110
|
Accept: "application/json",
|
102
111
|
"Content-Type": "application/json",
|
103
|
-
...danxOptions.value.request?.headers
|
104
|
-
|
105
|
-
|
112
|
+
...danxOptions.value.request?.headers,
|
113
|
+
...options?.headers
|
114
|
+
}
|
106
115
|
});
|
107
116
|
},
|
108
117
|
|
@@ -110,12 +119,13 @@ export const request: RequestApi = {
|
|
110
119
|
return await request.call(url, {
|
111
120
|
method: "post",
|
112
121
|
body: data && JSON.stringify(data),
|
122
|
+
...options,
|
113
123
|
headers: {
|
114
124
|
Accept: "application/json",
|
115
125
|
"Content-Type": "application/json",
|
116
|
-
...danxOptions.value.request?.headers
|
117
|
-
|
118
|
-
|
126
|
+
...danxOptions.value.request?.headers,
|
127
|
+
...options?.headers
|
128
|
+
}
|
119
129
|
});
|
120
130
|
}
|
121
131
|
};
|