lkt-item-crud 2.0.19 → 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 +700 -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 +9 -3
- package/package.json +1 -1
- package/src/components/ButtonNav.vue +208 -83
- package/src/lib-components/LktItemCrud.vue +88 -12
|
@@ -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 = 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();
|
|
@@ -394,7 +441,6 @@
|
|
|
394
441
|
ableToUpdate = computed(() => {
|
|
395
442
|
if (props.mode !== ItemCrudMode.Update || !canUpdate.value) return false;
|
|
396
443
|
if (!props.enabledSaveWithoutChanges && !dataChanged.value) return false;
|
|
397
|
-
console.log('ableToUpdate', validForm.value);
|
|
398
444
|
if (computedHasForm.value && !validForm.value) return false;
|
|
399
445
|
|
|
400
446
|
if (typeof safeUpdateButton.value?.disabled === 'function') return !safeUpdateButton.value.disabled({
|
|
@@ -448,7 +494,16 @@
|
|
|
448
494
|
}),
|
|
449
495
|
computedHasForm = computed(() => {
|
|
450
496
|
return typeof props.form === 'object' && Object.keys(props.form).length > 0;
|
|
451
|
-
})
|
|
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
|
+
})
|
|
452
507
|
</script>
|
|
453
508
|
|
|
454
509
|
<template>
|
|
@@ -463,7 +518,9 @@
|
|
|
463
518
|
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top"
|
|
464
519
|
v-model:loading="isLoading"
|
|
465
520
|
v-model:editing="editMode"
|
|
521
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
466
522
|
:item="item"
|
|
523
|
+
:modifications="itemModifications"
|
|
467
524
|
:mode="mode"
|
|
468
525
|
:view="view"
|
|
469
526
|
:grouped="true"
|
|
@@ -483,6 +540,8 @@
|
|
|
483
540
|
:able-to-update="ableToUpdate"
|
|
484
541
|
:able-to-drop="ableToDrop"
|
|
485
542
|
:perms="permissions"
|
|
543
|
+
:modification-view="computedModificationViews"
|
|
544
|
+
:editable-view="computedEditableView"
|
|
486
545
|
@create="onCreate"
|
|
487
546
|
@save="onUpdate"
|
|
488
547
|
@drop="onDrop"
|
|
@@ -520,7 +579,9 @@
|
|
|
520
579
|
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Top && (groupButton === false || !groupButtonAsModalActions)"
|
|
521
580
|
v-model:loading="isLoading"
|
|
522
581
|
v-model:editing="editMode"
|
|
582
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
523
583
|
:item="item"
|
|
584
|
+
:modifications="itemModifications"
|
|
524
585
|
:mode="mode"
|
|
525
586
|
:view="view"
|
|
526
587
|
:grouped="groupButton !== false"
|
|
@@ -540,6 +601,8 @@
|
|
|
540
601
|
:able-to-update="ableToUpdate"
|
|
541
602
|
:able-to-drop="ableToDrop"
|
|
542
603
|
:perms="permissions"
|
|
604
|
+
:modification-view="computedModificationViews"
|
|
605
|
+
:editable-view="computedEditableView"
|
|
543
606
|
@create="onCreate"
|
|
544
607
|
@save="onUpdate"
|
|
545
608
|
@drop="onDrop"
|
|
@@ -570,12 +633,21 @@
|
|
|
570
633
|
can-close
|
|
571
634
|
v-on:close="showStoreMessage = false" />
|
|
572
635
|
|
|
573
|
-
<
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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>
|
|
579
651
|
|
|
580
652
|
<template v-else>
|
|
581
653
|
<slot name="item"
|
|
@@ -599,7 +671,9 @@
|
|
|
599
671
|
v-if="buttonNavPosition === ItemCrudButtonNavPosition.Bottom && (groupButton === false || !groupButtonAsModalActions)"
|
|
600
672
|
v-model:loading="isLoading"
|
|
601
673
|
v-model:editing="editMode"
|
|
674
|
+
v-model:picked-modification-view="pickedModificationView"
|
|
602
675
|
:item="item"
|
|
676
|
+
:modifications="itemModifications"
|
|
603
677
|
:mode="mode"
|
|
604
678
|
:view="view"
|
|
605
679
|
:grouped="groupButton !== false"
|
|
@@ -619,6 +693,8 @@
|
|
|
619
693
|
:able-to-update="ableToUpdate"
|
|
620
694
|
:able-to-drop="ableToDrop"
|
|
621
695
|
:perms="permissions"
|
|
696
|
+
:modification-view="computedModificationViews"
|
|
697
|
+
:editable-view="computedEditableView"
|
|
622
698
|
@create="onCreate"
|
|
623
699
|
@save="onUpdate"
|
|
624
700
|
@drop="onDrop"
|