lkt-item-crud 2.0.16 → 2.0.18
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/build.d.ts +6 -6
- package/dist/build.js +429 -396
- package/dist/lib-components/LktItemCrud.vue.d.ts +11 -0
- package/package.json +1 -1
- package/src/lib-components/LktItemCrud.vue +63 -17
|
@@ -65,6 +65,8 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
|
|
|
65
65
|
perms: (...args: any[]) => void;
|
|
66
66
|
"update:editing": (...args: any[]) => void;
|
|
67
67
|
"update:modelValue": (...args: any[]) => void;
|
|
68
|
+
"update:perms": (...args: any[]) => void;
|
|
69
|
+
"update:customData": (...args: any[]) => void;
|
|
68
70
|
"before-save": (...args: any[]) => void;
|
|
69
71
|
"modified-data": (...args: any[]) => void;
|
|
70
72
|
}, string, import("vue").PublicProps, Readonly<ItemCrudConfig> & Readonly<{
|
|
@@ -76,6 +78,8 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
|
|
|
76
78
|
onPerms?: ((...args: any[]) => any) | undefined;
|
|
77
79
|
"onUpdate:editing"?: ((...args: any[]) => any) | undefined;
|
|
78
80
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
81
|
+
"onUpdate:perms"?: ((...args: any[]) => any) | undefined;
|
|
82
|
+
"onUpdate:customData"?: ((...args: any[]) => any) | undefined;
|
|
79
83
|
"onBefore-save"?: ((...args: any[]) => any) | undefined;
|
|
80
84
|
"onModified-data"?: ((...args: any[]) => any) | undefined;
|
|
81
85
|
}>, {
|
|
@@ -83,8 +87,13 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
|
|
|
83
87
|
title: string;
|
|
84
88
|
mode: ItemCrudMode;
|
|
85
89
|
modelValue: LktObject;
|
|
90
|
+
events: {
|
|
91
|
+
httpStart?: undefined | Function;
|
|
92
|
+
httpEnd?: (data: import("lkt-vue-kernel").ClickEventArgs) => void | undefined;
|
|
93
|
+
};
|
|
86
94
|
editing: boolean;
|
|
87
95
|
perms: import("lkt-vue-kernel").ValidTablePermission[];
|
|
96
|
+
customData: LktObject;
|
|
88
97
|
editModeButton: ButtonConfig | false;
|
|
89
98
|
dropButton: ButtonConfig | false;
|
|
90
99
|
createButton: ButtonConfig | false;
|
|
@@ -101,6 +110,8 @@ declare const __VLS_component: import("vue").DefineComponent<ItemCrudConfig, {
|
|
|
101
110
|
beforeEmitUpdate: Function;
|
|
102
111
|
notificationType: NotificationType;
|
|
103
112
|
enabledSaveWithoutChanges: boolean;
|
|
113
|
+
redirectOnCreate: string | ((id: number | string) => string);
|
|
114
|
+
redirectOnDrop: string | (() => string);
|
|
104
115
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
105
116
|
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
106
117
|
export default _default;
|
package/package.json
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { __ } from 'lkt-i18n';
|
|
24
24
|
import ButtonNav from '../components/ButtonNav.vue';
|
|
25
25
|
import { openToast } from 'lkt-toast';
|
|
26
|
+
import { useRouter } from 'vue-router';
|
|
26
27
|
|
|
27
28
|
// defineOptions({
|
|
28
29
|
// inheritAttrs: false
|
|
@@ -30,11 +31,15 @@
|
|
|
30
31
|
|
|
31
32
|
const props = withDefaults(defineProps<ItemCrudConfig>(), getDefaultValues(ItemCrud));
|
|
32
33
|
|
|
34
|
+
const router = useRouter();
|
|
35
|
+
|
|
33
36
|
const slots: SetupContext['slots'] = useSlots();
|
|
34
37
|
|
|
35
38
|
const emit = defineEmits([
|
|
36
39
|
'update:modelValue',
|
|
37
40
|
'update:editing',
|
|
41
|
+
'update:perms',
|
|
42
|
+
'update:customData',
|
|
38
43
|
'read',
|
|
39
44
|
'create',
|
|
40
45
|
'update',
|
|
@@ -47,7 +52,8 @@
|
|
|
47
52
|
|
|
48
53
|
const isLoading = ref(true),
|
|
49
54
|
item = ref(props.modelValue),
|
|
50
|
-
|
|
55
|
+
custom = ref(props.customData),
|
|
56
|
+
permissions = ref(props.perms),
|
|
51
57
|
editMode = ref(props.editing),
|
|
52
58
|
httpSuccessRead = ref(false),
|
|
53
59
|
showStoreMessage = ref(false),
|
|
@@ -59,14 +65,20 @@
|
|
|
59
65
|
itemBeingEdited = ref(false),
|
|
60
66
|
itemCreated = ref(false),
|
|
61
67
|
buttonNav = ref(null),
|
|
62
|
-
canUpdate = computed(() => !createMode.value && Array.isArray(
|
|
63
|
-
canDrop = computed(() => !createMode.value && Array.isArray(
|
|
64
|
-
canSwitchEditMode = computed(() => !createMode.value && Array.isArray(
|
|
68
|
+
canUpdate = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.Update)),
|
|
69
|
+
canDrop = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.Drop)),
|
|
70
|
+
canSwitchEditMode = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.SwitchEditMode));
|
|
65
71
|
|
|
66
72
|
watch(() => props.mode, (v) => {
|
|
67
73
|
createMode.value = v === ItemCrudMode.Create;
|
|
68
74
|
})
|
|
69
75
|
|
|
76
|
+
watch(() => props.perms, (v) => {permissions.value = v});
|
|
77
|
+
watch(permissions, (v) => {emit('update:perms', v)});
|
|
78
|
+
|
|
79
|
+
watch(() => props.customData, (v) => {custom.value = v});
|
|
80
|
+
watch(custom, (v) => {emit('update:customData', v)});
|
|
81
|
+
|
|
70
82
|
const safeCreateButton = ref(ensureButtonConfig(props.createButton, LktSettings.defaultCreateButton)),
|
|
71
83
|
safeUpdateButton = ref(ensureButtonConfig(props.updateButton, LktSettings.defaultUpdateButton)),
|
|
72
84
|
safeDropButton = ref(ensureButtonConfig(props.dropButton, LktSettings.defaultDropButton)),
|
|
@@ -95,23 +107,40 @@
|
|
|
95
107
|
httpStatus.value = -1;
|
|
96
108
|
showStoreMessage.value = false;
|
|
97
109
|
|
|
110
|
+
if (typeof props.events?.httpStart === 'function') {
|
|
111
|
+
props.events.httpStart();
|
|
112
|
+
}
|
|
113
|
+
|
|
98
114
|
try {
|
|
99
|
-
const r = await httpCall(props.readResource, props.readData);
|
|
115
|
+
const r: HTTPResponse = await httpCall(props.readResource, props.readData);
|
|
100
116
|
debug('fetchItem -> response', r);
|
|
101
117
|
isLoading.value = false;
|
|
102
118
|
httpStatus.value = r.httpStatus;
|
|
119
|
+
custom.value = r.custom;
|
|
103
120
|
if (!r.success) {
|
|
104
121
|
httpSuccessRead.value = false;
|
|
105
122
|
httpStatus.value = r.httpStatus;
|
|
123
|
+
|
|
124
|
+
if (typeof props.events?.httpEnd === 'function') {
|
|
125
|
+
props.events.httpEnd({
|
|
126
|
+
httpResponse: r,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
106
129
|
emit('error', r.httpStatus);
|
|
107
130
|
return;
|
|
108
131
|
}
|
|
109
132
|
httpSuccessRead.value = true;
|
|
110
133
|
item.value = r.data;
|
|
111
|
-
|
|
134
|
+
permissions.value = r.perms;
|
|
112
135
|
dataState.value.increment(item.value).turnStoredIntoOriginal();
|
|
113
136
|
dataChanged.value = dataState.value.changed();
|
|
114
137
|
readDataState.value.turnStoredIntoOriginal();
|
|
138
|
+
|
|
139
|
+
if (typeof props.events?.httpEnd === 'function') {
|
|
140
|
+
props.events.httpEnd({
|
|
141
|
+
httpResponse: r,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
115
144
|
emit('read', r);
|
|
116
145
|
|
|
117
146
|
} catch (e) {
|
|
@@ -145,7 +174,7 @@
|
|
|
145
174
|
nextTick(() => itemBeingEdited.value = false);
|
|
146
175
|
}, { deep: true });
|
|
147
176
|
|
|
148
|
-
watch(
|
|
177
|
+
watch(permissions, () => emit('perms', permissions.value));
|
|
149
178
|
watch(dataChanged, (v) => {
|
|
150
179
|
emit('modified-data', v);
|
|
151
180
|
});
|
|
@@ -199,11 +228,16 @@
|
|
|
199
228
|
}
|
|
200
229
|
return true;
|
|
201
230
|
},
|
|
202
|
-
doAutoReloadId = (r?: HTTPResponse) => {
|
|
231
|
+
doAutoReloadId = (r?: HTTPResponse, redirect?: string|Function) => {
|
|
203
232
|
debug('doAutoReloadId -> enter: ', r);
|
|
204
233
|
if (typeof r !== 'undefined' && r.autoReloadId) {
|
|
205
234
|
debug('doAutoReloadId -> autoReloadId detected: ', r.autoReloadId);
|
|
206
|
-
if (
|
|
235
|
+
if (typeof redirect !== 'undefined') {
|
|
236
|
+
let route = redirect;
|
|
237
|
+
if (typeof redirect === 'function') route = redirect(r.autoReloadId);
|
|
238
|
+
router.push(route);
|
|
239
|
+
}
|
|
240
|
+
else if (!computedInsideModal.value) {
|
|
207
241
|
debug('doAutoReloadId -> outsideModal');
|
|
208
242
|
props.readData['id'] = r.autoReloadId;
|
|
209
243
|
debug('doAutoReloadId -> turning off create mode');
|
|
@@ -239,7 +273,7 @@
|
|
|
239
273
|
positionX: ToastPositionX.Right,
|
|
240
274
|
});
|
|
241
275
|
}
|
|
242
|
-
doAutoReloadId(r);
|
|
276
|
+
doAutoReloadId(r, props.redirectOnCreate);
|
|
243
277
|
debug('onCreate -> beforeEmitCreate');
|
|
244
278
|
emit('create', r);
|
|
245
279
|
},
|
|
@@ -296,6 +330,12 @@
|
|
|
296
330
|
//@ts-ignore
|
|
297
331
|
closeModal(props.modalConfig.modalName, props.modalConfig.modalKey);
|
|
298
332
|
}
|
|
333
|
+
|
|
334
|
+
if (typeof props.redirectOnDrop !== 'undefined') {
|
|
335
|
+
let route = props.redirectOnDrop;
|
|
336
|
+
if (typeof props.redirectOnDrop === 'function') route = props.redirectOnDrop();
|
|
337
|
+
router.push(route);
|
|
338
|
+
}
|
|
299
339
|
},
|
|
300
340
|
doSave = () => {
|
|
301
341
|
// @ts-ignore
|
|
@@ -353,7 +393,9 @@
|
|
|
353
393
|
if (props.mode !== ItemCrudMode.Update || !canUpdate.value) return false;
|
|
354
394
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
355
395
|
|
|
356
|
-
if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled(
|
|
396
|
+
if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled({
|
|
397
|
+
prop: item.value
|
|
398
|
+
});
|
|
357
399
|
if (typeof safeUpdateButton.value?.disabled === 'boolean') return !safeUpdateButton.value.disabled;
|
|
358
400
|
|
|
359
401
|
return true;
|
|
@@ -362,7 +404,9 @@
|
|
|
362
404
|
if (props.mode !== ItemCrudMode.Create) return false;
|
|
363
405
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
364
406
|
|
|
365
|
-
if (typeof safeCreateButton.value?.disabled === 'function') return !safeCreateButton.value.disabled(
|
|
407
|
+
if (typeof safeCreateButton.value?.disabled === 'function') return !safeCreateButton.value.disabled({
|
|
408
|
+
prop: item.value
|
|
409
|
+
});
|
|
366
410
|
if (typeof safeCreateButton.value?.disabled === 'boolean') return !safeCreateButton.value.disabled;
|
|
367
411
|
|
|
368
412
|
return true;
|
|
@@ -371,7 +415,9 @@
|
|
|
371
415
|
|
|
372
416
|
if (!canDrop.value) return false;
|
|
373
417
|
|
|
374
|
-
if (typeof safeDropButton.value?.disabled === 'function') return !safeDropButton.value.disabled(
|
|
418
|
+
if (typeof safeDropButton.value?.disabled === 'function') return !safeDropButton.value.disabled({
|
|
419
|
+
prop: item.value
|
|
420
|
+
});
|
|
375
421
|
if (typeof safeDropButton.value?.disabled === 'boolean') return !safeDropButton.value.disabled;
|
|
376
422
|
|
|
377
423
|
return true;
|
|
@@ -428,7 +474,7 @@
|
|
|
428
474
|
:able-to-create="ableToCreate"
|
|
429
475
|
:able-to-update="ableToUpdate"
|
|
430
476
|
:able-to-drop="ableToDrop"
|
|
431
|
-
:perms="
|
|
477
|
+
:perms="permissions"
|
|
432
478
|
@create="onCreate"
|
|
433
479
|
@save="onUpdate"
|
|
434
480
|
@drop="onDrop"
|
|
@@ -485,7 +531,7 @@
|
|
|
485
531
|
:able-to-create="ableToCreate"
|
|
486
532
|
:able-to-update="ableToUpdate"
|
|
487
533
|
:able-to-drop="ableToDrop"
|
|
488
|
-
:perms="
|
|
534
|
+
:perms="permissions"
|
|
489
535
|
@create="onCreate"
|
|
490
536
|
@save="onUpdate"
|
|
491
537
|
@drop="onDrop"
|
|
@@ -523,7 +569,7 @@
|
|
|
523
569
|
:can-update="canUpdate"
|
|
524
570
|
:can-drop="canDrop"
|
|
525
571
|
:item-being-edited="itemBeingEdited"
|
|
526
|
-
:perms="
|
|
572
|
+
:perms="permissions"
|
|
527
573
|
/>
|
|
528
574
|
</div>
|
|
529
575
|
<lkt-http-info :code="httpStatus" v-else-if="notificationType === NotificationType.Inline" />
|
|
@@ -554,7 +600,7 @@
|
|
|
554
600
|
:able-to-create="ableToCreate"
|
|
555
601
|
:able-to-update="ableToUpdate"
|
|
556
602
|
:able-to-drop="ableToDrop"
|
|
557
|
-
:perms="
|
|
603
|
+
:perms="permissions"
|
|
558
604
|
@create="onCreate"
|
|
559
605
|
@save="onUpdate"
|
|
560
606
|
@drop="onDrop"
|