lkt-item-crud 2.0.18 → 2.0.20
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 +696 -613
- 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 +15 -6
- package/package.json +1 -1
- package/src/components/ButtonNav.vue +208 -83
- package/src/lib-components/LktItemCrud.vue +108 -14
|
@@ -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,6 +43,8 @@
|
|
|
40
43
|
'update:editing',
|
|
41
44
|
'update:perms',
|
|
42
45
|
'update:customData',
|
|
46
|
+
'update:modifications',
|
|
47
|
+
'update:modificationView',
|
|
43
48
|
'read',
|
|
44
49
|
'create',
|
|
45
50
|
'update',
|
|
@@ -52,13 +57,16 @@
|
|
|
52
57
|
|
|
53
58
|
const isLoading = ref(true),
|
|
54
59
|
item = ref(props.modelValue),
|
|
60
|
+
itemModifications = ref(props.modifications),
|
|
55
61
|
custom = ref(props.customData),
|
|
56
62
|
permissions = ref(props.perms),
|
|
57
63
|
editMode = ref(props.editing),
|
|
64
|
+
validForm = ref(false),
|
|
58
65
|
httpSuccessRead = ref(false),
|
|
59
66
|
showStoreMessage = ref(false),
|
|
60
67
|
httpStatus = ref(200),
|
|
61
68
|
dataState = ref(new DataState(item.value, props.dataStateConfig)),
|
|
69
|
+
modificationsDataState = ref(new DataState(itemModifications.value, props.dataStateConfig)),
|
|
62
70
|
dataChanged = ref(false),
|
|
63
71
|
readDataState = ref(new DataState(props.readData)),
|
|
64
72
|
createMode = ref(props.mode === ItemCrudMode.Create),
|
|
@@ -69,6 +77,16 @@
|
|
|
69
77
|
canDrop = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.Drop)),
|
|
70
78
|
canSwitchEditMode = computed(() => !createMode.value && Array.isArray(permissions.value) && permissions.value.includes(TablePermission.SwitchEditMode));
|
|
71
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
|
+
|
|
72
90
|
watch(() => props.mode, (v) => {
|
|
73
91
|
createMode.value = v === ItemCrudMode.Create;
|
|
74
92
|
})
|
|
@@ -79,6 +97,21 @@
|
|
|
79
97
|
watch(() => props.customData, (v) => {custom.value = v});
|
|
80
98
|
watch(custom, (v) => {emit('update:customData', v)});
|
|
81
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
|
+
|
|
82
115
|
const safeCreateButton = ref(ensureButtonConfig(props.createButton, LktSettings.defaultCreateButton)),
|
|
83
116
|
safeUpdateButton = ref(ensureButtonConfig(props.updateButton, LktSettings.defaultUpdateButton)),
|
|
84
117
|
safeDropButton = ref(ensureButtonConfig(props.dropButton, LktSettings.defaultDropButton)),
|
|
@@ -131,11 +164,17 @@
|
|
|
131
164
|
}
|
|
132
165
|
httpSuccessRead.value = true;
|
|
133
166
|
item.value = r.data;
|
|
167
|
+
itemModifications.value = r.modifications;
|
|
134
168
|
permissions.value = r.perms;
|
|
135
169
|
dataState.value.increment(item.value).turnStoredIntoOriginal();
|
|
170
|
+
modificationsDataState.value.increment(itemModifications.value).turnStoredIntoOriginal();
|
|
136
171
|
dataChanged.value = dataState.value.changed();
|
|
137
172
|
readDataState.value.turnStoredIntoOriginal();
|
|
138
173
|
|
|
174
|
+
if (Object.keys(itemModifications.value).length > 0) {
|
|
175
|
+
pickedModificationView.value = ModificationView.Modifications;
|
|
176
|
+
}
|
|
177
|
+
|
|
139
178
|
if (typeof props.events?.httpEnd === 'function') {
|
|
140
179
|
props.events.httpEnd({
|
|
141
180
|
httpResponse: r,
|
|
@@ -167,10 +206,13 @@
|
|
|
167
206
|
debug('item updated -> override with: ', override);
|
|
168
207
|
if (typeof override === 'object') item.value = override;
|
|
169
208
|
}
|
|
209
|
+
resetFormDifferencesChecker();
|
|
170
210
|
emit('update:modelValue', item.value);
|
|
171
211
|
debug('item updated -> update dataState');
|
|
172
212
|
dataState.value.increment(v);
|
|
173
|
-
|
|
213
|
+
if (computedEditableView.value === ModificationView.Current) {
|
|
214
|
+
dataChanged.value = dataState.value.changed();
|
|
215
|
+
}
|
|
174
216
|
nextTick(() => itemBeingEdited.value = false);
|
|
175
217
|
}, { deep: true });
|
|
176
218
|
|
|
@@ -193,6 +235,13 @@
|
|
|
193
235
|
emit('update:editing', v);
|
|
194
236
|
});
|
|
195
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
|
+
|
|
196
245
|
onMounted(() => {
|
|
197
246
|
// Fetch item
|
|
198
247
|
if (props.readResource && !createMode.value) fetchItem();
|
|
@@ -392,6 +441,7 @@
|
|
|
392
441
|
ableToUpdate = computed(() => {
|
|
393
442
|
if (props.mode !== ItemCrudMode.Update || !canUpdate.value) return false;
|
|
394
443
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
444
|
+
if (computedHasForm.value && !validForm.value) return false;
|
|
395
445
|
|
|
396
446
|
if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled({
|
|
397
447
|
prop: item.value
|
|
@@ -403,6 +453,7 @@
|
|
|
403
453
|
ableToCreate = computed(() => {
|
|
404
454
|
if (props.mode !== ItemCrudMode.Create) return false;
|
|
405
455
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
456
|
+
if (computedHasForm.value && !validForm.value) return false;
|
|
406
457
|
|
|
407
458
|
if (typeof safeCreateButton.value?.disabled === 'function') return !safeCreateButton.value.disabled({
|
|
408
459
|
prop: item.value
|
|
@@ -440,7 +491,19 @@
|
|
|
440
491
|
};
|
|
441
492
|
}
|
|
442
493
|
return {};
|
|
443
|
-
})
|
|
494
|
+
}),
|
|
495
|
+
computedHasForm = computed(() => {
|
|
496
|
+
return typeof props.form === 'object' && Object.keys(props.form).length > 0;
|
|
497
|
+
}),
|
|
498
|
+
computedModificationViews = computed(() => {
|
|
499
|
+
if (Object.keys(itemModifications.value).length === 0) return [];
|
|
500
|
+
return props.modificationViews;
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const computedEditableView = computed(() => {
|
|
504
|
+
if (Object.keys(itemModifications.value).length === 0) return ModificationView.Current;
|
|
505
|
+
return ModificationView.Modifications;
|
|
506
|
+
})
|
|
444
507
|
</script>
|
|
445
508
|
|
|
446
509
|
<template>
|
|
@@ -455,7 +518,9 @@
|
|
|
455
518
|
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top"
|
|
456
519
|
v-model:loading="isLoading"
|
|
457
520
|
v-model:editing="editMode"
|
|
521
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
458
522
|
:item="item"
|
|
523
|
+
:modifications="itemModifications"
|
|
459
524
|
:mode="mode"
|
|
460
525
|
:view="view"
|
|
461
526
|
:grouped="true"
|
|
@@ -475,6 +540,8 @@
|
|
|
475
540
|
:able-to-update="ableToUpdate"
|
|
476
541
|
:able-to-drop="ableToDrop"
|
|
477
542
|
:perms="permissions"
|
|
543
|
+
:modification-view="computedModificationViews"
|
|
544
|
+
:editable-view="computedEditableView"
|
|
478
545
|
@create="onCreate"
|
|
479
546
|
@save="onUpdate"
|
|
480
547
|
@drop="onDrop"
|
|
@@ -512,7 +579,9 @@
|
|
|
512
579
|
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top && (groupButton === false || !groupButtonAsModalActions)"
|
|
513
580
|
v-model:loading="isLoading"
|
|
514
581
|
v-model:editing="editMode"
|
|
582
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
515
583
|
:item="item"
|
|
584
|
+
:modifications="itemModifications"
|
|
516
585
|
:mode="mode"
|
|
517
586
|
:view="view"
|
|
518
587
|
:grouped="groupButton !== false"
|
|
@@ -532,6 +601,8 @@
|
|
|
532
601
|
:able-to-update="ableToUpdate"
|
|
533
602
|
:able-to-drop="ableToDrop"
|
|
534
603
|
:perms="permissions"
|
|
604
|
+
:modification-view="computedModificationViews"
|
|
605
|
+
:editable-view="computedEditableView"
|
|
535
606
|
@create="onCreate"
|
|
536
607
|
@save="onUpdate"
|
|
537
608
|
@drop="onDrop"
|
|
@@ -561,16 +632,35 @@
|
|
|
561
632
|
quick
|
|
562
633
|
can-close
|
|
563
634
|
v-on:close="showStoreMessage = false" />
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
635
|
+
|
|
636
|
+
<template v-if="computedHasForm">
|
|
637
|
+
<lkt-form
|
|
638
|
+
v-model="item"
|
|
639
|
+
v-model:modifications="itemModifications"
|
|
640
|
+
v-model:valid="validForm"
|
|
641
|
+
v-bind="<FormUiConfig>{
|
|
642
|
+
form,
|
|
643
|
+
differencesTableConfig,
|
|
644
|
+
visibleView: pickedModificationView,
|
|
645
|
+
modificationDataState: formDifferencesChecker,
|
|
646
|
+
editableViews: [computedEditableView],
|
|
647
|
+
disabled: !editMode,
|
|
648
|
+
}"
|
|
649
|
+
/>
|
|
650
|
+
</template>
|
|
651
|
+
|
|
652
|
+
<template v-else>
|
|
653
|
+
<slot name="item"
|
|
654
|
+
:item="item"
|
|
655
|
+
:loading="isLoading"
|
|
656
|
+
:edit-mode="editMode"
|
|
657
|
+
:is-create="createMode"
|
|
658
|
+
:can-update="canUpdate"
|
|
659
|
+
:can-drop="canDrop"
|
|
660
|
+
:item-being-edited="itemBeingEdited"
|
|
661
|
+
:perms="permissions"
|
|
662
|
+
/>
|
|
663
|
+
</template>
|
|
574
664
|
</div>
|
|
575
665
|
<lkt-http-info :code="httpStatus" v-else-if="notificationType === NotificationType.Inline" />
|
|
576
666
|
</div>
|
|
@@ -581,7 +671,9 @@
|
|
|
581
671
|
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Bottom && (groupButton === false || !groupButtonAsModalActions)"
|
|
582
672
|
v-model:loading="isLoading"
|
|
583
673
|
v-model:editing="editMode"
|
|
674
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
584
675
|
:item="item"
|
|
676
|
+
:modifications="itemModifications"
|
|
585
677
|
:mode="mode"
|
|
586
678
|
:view="view"
|
|
587
679
|
:grouped="groupButton !== false"
|
|
@@ -601,6 +693,8 @@
|
|
|
601
693
|
:able-to-update="ableToUpdate"
|
|
602
694
|
:able-to-drop="ableToDrop"
|
|
603
695
|
:perms="permissions"
|
|
696
|
+
:modification-view="computedModificationViews"
|
|
697
|
+
:editable-view="computedEditableView"
|
|
604
698
|
@create="onCreate"
|
|
605
699
|
@save="onUpdate"
|
|
606
700
|
@drop="onDrop"
|