lkt-item-crud 2.0.19 → 2.0.21
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.css +1 -1
- package/dist/build.d.ts +6 -6
- package/dist/build.js +702 -628
- package/dist/components/ButtonNav.vue.d.ts +24 -89
- package/dist/functions/modifications-functions.d.ts +4 -0
- package/dist/lib-components/LktItemCrud.vue.d.ts +10 -3
- package/package.json +1 -1
- package/src/components/ButtonNav.vue +208 -83
- package/src/lib-components/LktItemCrud.vue +103 -15
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { debug } from '../functions/debug';
|
|
6
6
|
import {
|
|
7
7
|
ButtonConfig,
|
|
8
|
-
ensureButtonConfig,
|
|
8
|
+
ensureButtonConfig, FormUiConfig,
|
|
9
9
|
getDefaultValues,
|
|
10
10
|
ItemCrud,
|
|
11
11
|
ItemCrudButtonNavPosition,
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
ItemCrudMode,
|
|
14
14
|
ItemCrudView,
|
|
15
15
|
LktObject,
|
|
16
|
-
LktSettings,
|
|
16
|
+
LktSettings,
|
|
17
|
+
ModalConfig,
|
|
18
|
+
ModificationView,
|
|
17
19
|
NotificationType,
|
|
18
20
|
TablePermission,
|
|
19
21
|
ToastConfig,
|
|
@@ -24,6 +26,7 @@
|
|
|
24
26
|
import ButtonNav from '../components/ButtonNav.vue';
|
|
25
27
|
import { openToast } from 'lkt-toast';
|
|
26
28
|
import { useRouter } from 'vue-router';
|
|
29
|
+
import { getModificationsDataState } from '../functions/modifications-functions';
|
|
27
30
|
|
|
28
31
|
// defineOptions({
|
|
29
32
|
// inheritAttrs: false
|
|
@@ -40,7 +43,8 @@
|
|
|
40
43
|
'update:editing',
|
|
41
44
|
'update:perms',
|
|
42
45
|
'update:customData',
|
|
43
|
-
'update:
|
|
46
|
+
'update:modifications',
|
|
47
|
+
'update:modificationView',
|
|
44
48
|
'read',
|
|
45
49
|
'create',
|
|
46
50
|
'update',
|
|
@@ -53,6 +57,7 @@
|
|
|
53
57
|
|
|
54
58
|
const isLoading = ref(true),
|
|
55
59
|
item = ref(props.modelValue),
|
|
60
|
+
itemModifications = ref(props.modifications),
|
|
56
61
|
custom = ref(props.customData),
|
|
57
62
|
permissions = ref(props.perms),
|
|
58
63
|
editMode = ref(props.editing),
|
|
@@ -61,6 +66,7 @@
|
|
|
61
66
|
showStoreMessage = ref(false),
|
|
62
67
|
httpStatus = ref(200),
|
|
63
68
|
dataState = ref(new DataState(item.value, props.dataStateConfig)),
|
|
69
|
+
modificationsDataState = ref(new DataState(itemModifications.value, props.dataStateConfig)),
|
|
64
70
|
dataChanged = ref(false),
|
|
65
71
|
readDataState = ref(new DataState(props.readData)),
|
|
66
72
|
createMode = ref(props.mode === ItemCrudMode.Create),
|
|
@@ -71,6 +77,16 @@
|
|
|
71
77
|
canDrop = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.Drop)),
|
|
72
78
|
canSwitchEditMode = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.SwitchEditMode));
|
|
73
79
|
|
|
80
|
+
const pickedModificationView = ref(props.visibleView);
|
|
81
|
+
|
|
82
|
+
watch(() => props.visibleView, (v) => {
|
|
83
|
+
pickedModificationView.value = v
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
watch(pickedModificationView, (v) => {
|
|
87
|
+
emit('update:modificationView', v);
|
|
88
|
+
})
|
|
89
|
+
|
|
74
90
|
watch(() => props.mode, (v) => {
|
|
75
91
|
createMode.value = v === ItemCrudMode.Create;
|
|
76
92
|
})
|
|
@@ -81,6 +97,21 @@
|
|
|
81
97
|
watch(() => props.customData, (v) => {custom.value = v});
|
|
82
98
|
watch(custom, (v) => {emit('update:customData', v)});
|
|
83
99
|
|
|
100
|
+
watch(() => props.modifications, (v) => {
|
|
101
|
+
modificationsDataState.value.increment(v);
|
|
102
|
+
itemModifications.value = v
|
|
103
|
+
}, {deep: true});
|
|
104
|
+
|
|
105
|
+
watch(itemModifications, (v) => {
|
|
106
|
+
resetFormDifferencesChecker();
|
|
107
|
+
modificationsDataState.value.increment(v);
|
|
108
|
+
|
|
109
|
+
if (computedEditableView.value === ModificationView.Modifications) {
|
|
110
|
+
dataChanged.value = modificationsDataState.value.changed();
|
|
111
|
+
}
|
|
112
|
+
emit('update:modifications', v)
|
|
113
|
+
}, {deep: true});
|
|
114
|
+
|
|
84
115
|
const safeCreateButton = ref(ensureButtonConfig(props.createButton, LktSettings.defaultCreateButton)),
|
|
85
116
|
safeUpdateButton = ref(ensureButtonConfig(props.updateButton, LktSettings.defaultUpdateButton)),
|
|
86
117
|
safeDropButton = ref(ensureButtonConfig(props.dropButton, LktSettings.defaultDropButton)),
|
|
@@ -133,11 +164,17 @@
|
|
|
133
164
|
}
|
|
134
165
|
httpSuccessRead.value = true;
|
|
135
166
|
item.value = r.data;
|
|
167
|
+
itemModifications.value = Array.isArray(r.modifications) ? {} : r.modifications;
|
|
136
168
|
permissions.value = r.perms;
|
|
137
169
|
dataState.value.increment(item.value).turnStoredIntoOriginal();
|
|
170
|
+
modificationsDataState.value.increment(itemModifications.value).turnStoredIntoOriginal();
|
|
138
171
|
dataChanged.value = dataState.value.changed();
|
|
139
172
|
readDataState.value.turnStoredIntoOriginal();
|
|
140
173
|
|
|
174
|
+
if (Object.keys(itemModifications.value).length > 0) {
|
|
175
|
+
pickedModificationView.value = ModificationView.Modifications;
|
|
176
|
+
}
|
|
177
|
+
|
|
141
178
|
if (typeof props.events?.httpEnd === 'function') {
|
|
142
179
|
props.events.httpEnd({
|
|
143
180
|
httpResponse: r,
|
|
@@ -169,10 +206,13 @@
|
|
|
169
206
|
debug('item updated -> override with: ', override);
|
|
170
207
|
if (typeof override === 'object') item.value = override;
|
|
171
208
|
}
|
|
209
|
+
resetFormDifferencesChecker();
|
|
172
210
|
emit('update:modelValue', item.value);
|
|
173
211
|
debug('item updated -> update dataState');
|
|
174
212
|
dataState.value.increment(v);
|
|
175
|
-
|
|
213
|
+
if (computedEditableView.value === ModificationView.Current) {
|
|
214
|
+
dataChanged.value = dataState.value.changed();
|
|
215
|
+
}
|
|
176
216
|
nextTick(() => itemBeingEdited.value = false);
|
|
177
217
|
}, { deep: true });
|
|
178
218
|
|
|
@@ -195,6 +235,13 @@
|
|
|
195
235
|
emit('update:editing', v);
|
|
196
236
|
});
|
|
197
237
|
|
|
238
|
+
const formDifferencesChecker = ref(undefined);
|
|
239
|
+
const resetFormDifferencesChecker = () => {
|
|
240
|
+
if (computedHasForm.value) {
|
|
241
|
+
formDifferencesChecker.value = getModificationsDataState(item.value, itemModifications.value, props.form);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
198
245
|
onMounted(() => {
|
|
199
246
|
// Fetch item
|
|
200
247
|
if (props.readResource && !createMode.value) fetchItem();
|
|
@@ -360,6 +407,10 @@
|
|
|
360
407
|
|
|
361
408
|
|
|
362
409
|
const closeConfirm = computed(() => {
|
|
410
|
+
if (!computedHasButtons.value) return '';
|
|
411
|
+
if (computedEditableView.value === ModificationView.Modifications) {
|
|
412
|
+
return modificationsDataState.value.changed() ? props.modalConfig?.closeConfirm : '';
|
|
413
|
+
}
|
|
363
414
|
return dataState.value.changed() ? props.modalConfig?.closeConfirm : '';
|
|
364
415
|
});
|
|
365
416
|
|
|
@@ -394,7 +445,6 @@
|
|
|
394
445
|
ableToUpdate = computed(() => {
|
|
395
446
|
if (props.mode !== ItemCrudMode.Update || !canUpdate.value) return false;
|
|
396
447
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
397
|
-
console.log('ableToUpdate', validForm.value);
|
|
398
448
|
if (computedHasForm.value && !validForm.value) return false;
|
|
399
449
|
|
|
400
450
|
if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled({
|
|
@@ -448,7 +498,20 @@
|
|
|
448
498
|
}),
|
|
449
499
|
computedHasForm = computed(() => {
|
|
450
500
|
return typeof props.form === 'object' && Object.keys(props.form).length > 0;
|
|
451
|
-
})
|
|
501
|
+
}),
|
|
502
|
+
computedModificationViews = computed(() => {
|
|
503
|
+
if (Object.keys(itemModifications.value).length === 0) return [];
|
|
504
|
+
return props.modificationViews;
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
const computedEditableView = computed(() => {
|
|
508
|
+
if (Object.keys(itemModifications.value).length === 0) return ModificationView.Current;
|
|
509
|
+
return ModificationView.Modifications;
|
|
510
|
+
})
|
|
511
|
+
|
|
512
|
+
const computedHasButtons = computed(() => {
|
|
513
|
+
return createMode.value || canUpdate.value || canDrop.value;
|
|
514
|
+
})
|
|
452
515
|
</script>
|
|
453
516
|
|
|
454
517
|
<template>
|
|
@@ -457,13 +520,15 @@
|
|
|
457
520
|
v-bind="computedContainerAttrs"
|
|
458
521
|
class="lkt-item-crud"
|
|
459
522
|
>
|
|
460
|
-
<template v-if="groupButton !== false && groupButtonAsModalActions" #header-actions>
|
|
523
|
+
<template v-if="groupButton !== false && groupButtonAsModalActions && computedHasButtons" #header-actions>
|
|
461
524
|
<button-nav
|
|
462
525
|
ref="buttonNav"
|
|
463
526
|
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top"
|
|
464
527
|
v-model:loading="isLoading"
|
|
465
528
|
v-model:editing="editMode"
|
|
529
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
466
530
|
:item="item"
|
|
531
|
+
:modifications="itemModifications"
|
|
467
532
|
:mode="mode"
|
|
468
533
|
:view="view"
|
|
469
534
|
:grouped="true"
|
|
@@ -483,6 +548,8 @@
|
|
|
483
548
|
:able-to-update="ableToUpdate"
|
|
484
549
|
:able-to-drop="ableToDrop"
|
|
485
550
|
:perms="permissions"
|
|
551
|
+
:modification-view="computedModificationViews"
|
|
552
|
+
:editable-view="computedEditableView"
|
|
486
553
|
@create="onCreate"
|
|
487
554
|
@save="onUpdate"
|
|
488
555
|
@drop="onDrop"
|
|
@@ -517,10 +584,15 @@
|
|
|
517
584
|
|
|
518
585
|
<button-nav
|
|
519
586
|
ref="buttonNav"
|
|
520
|
-
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top
|
|
587
|
+
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top
|
|
588
|
+
&& (groupButton === false || !groupButtonAsModalActions)
|
|
589
|
+
&& computedHasButtons
|
|
590
|
+
"
|
|
521
591
|
v-model:loading="isLoading"
|
|
522
592
|
v-model:editing="editMode"
|
|
593
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
523
594
|
:item="item"
|
|
595
|
+
:modifications="itemModifications"
|
|
524
596
|
:mode="mode"
|
|
525
597
|
:view="view"
|
|
526
598
|
:grouped="groupButton !== false"
|
|
@@ -540,6 +612,8 @@
|
|
|
540
612
|
:able-to-update="ableToUpdate"
|
|
541
613
|
:able-to-drop="ableToDrop"
|
|
542
614
|
:perms="permissions"
|
|
615
|
+
:modification-view="computedModificationViews"
|
|
616
|
+
:editable-view="computedEditableView"
|
|
543
617
|
@create="onCreate"
|
|
544
618
|
@save="onUpdate"
|
|
545
619
|
@drop="onDrop"
|
|
@@ -570,12 +644,22 @@
|
|
|
570
644
|
can-close
|
|
571
645
|
v-on:close="showStoreMessage = false" />
|
|
572
646
|
|
|
573
|
-
<
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
647
|
+
<template v-if="computedHasForm">
|
|
648
|
+
<lkt-form
|
|
649
|
+
v-model="item"
|
|
650
|
+
v-model:modifications="itemModifications"
|
|
651
|
+
v-model:valid="validForm"
|
|
652
|
+
v-bind="<FormUiConfig>{
|
|
653
|
+
...formUiConfig,
|
|
654
|
+
form,
|
|
655
|
+
differencesTableConfig,
|
|
656
|
+
visibleView: pickedModificationView,
|
|
657
|
+
modificationDataState: formDifferencesChecker,
|
|
658
|
+
editableViews: [computedEditableView],
|
|
659
|
+
disabled: !editMode,
|
|
660
|
+
}"
|
|
661
|
+
/>
|
|
662
|
+
</template>
|
|
579
663
|
|
|
580
664
|
<template v-else>
|
|
581
665
|
<slot name="item"
|
|
@@ -596,10 +680,12 @@
|
|
|
596
680
|
|
|
597
681
|
<button-nav
|
|
598
682
|
ref="buttonNav"
|
|
599
|
-
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Bottom && (groupButton === false || !groupButtonAsModalActions)"
|
|
683
|
+
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Bottom && (groupButton === false || !groupButtonAsModalActions) && computedHasButtons"
|
|
600
684
|
v-model:loading="isLoading"
|
|
601
685
|
v-model:editing="editMode"
|
|
686
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
602
687
|
:item="item"
|
|
688
|
+
:modifications="itemModifications"
|
|
603
689
|
:mode="mode"
|
|
604
690
|
:view="view"
|
|
605
691
|
:grouped="groupButton !== false"
|
|
@@ -619,6 +705,8 @@
|
|
|
619
705
|
:able-to-update="ableToUpdate"
|
|
620
706
|
:able-to-drop="ableToDrop"
|
|
621
707
|
:perms="permissions"
|
|
708
|
+
:modification-view="computedModificationViews"
|
|
709
|
+
:editable-view="computedEditableView"
|
|
622
710
|
@create="onCreate"
|
|
623
711
|
@save="onUpdate"
|
|
624
712
|
@drop="onDrop"
|