@drax/crud-vue 0.5.1 → 0.5.2
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/package.json +3 -3
- package/src/EntityCrud.ts +3 -4
- package/src/components/Crud.vue +6 -5
- package/src/components/CrudForm.vue +10 -3
- package/src/components/CrudFormField.vue +1 -2
- package/src/components/CrudList.vue +5 -2
- package/src/components/buttons/CrudExportButton.vue +2 -2
- package/src/components/buttons/CrudImportButton.vue +2 -2
- package/src/composables/UseCrud.ts +6 -3
- package/src/stores/UseCrudStore.ts +4 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.5.
|
|
6
|
+
"version": "0.5.2",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@drax/common-front": "^0.5.1",
|
|
28
28
|
"@drax/crud-front": "^0.5.1",
|
|
29
|
-
"@drax/crud-share": "^0.5.
|
|
29
|
+
"@drax/crud-share": "^0.5.2"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"pinia": "^2.2.2",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"vue-tsc": "^2.0.11",
|
|
64
64
|
"vuetify": "^3.7.1"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "6f854dbeb2af7bca32ed35bcec2f8e48790a73b9"
|
|
67
67
|
}
|
package/src/EntityCrud.ts
CHANGED
|
@@ -90,10 +90,9 @@ class EntityCrud implements IEntityCrud{
|
|
|
90
90
|
return {}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return field && this.rules[field] ? this.rules[field] :
|
|
96
|
-
}
|
|
93
|
+
getRule(field:string|undefined):Array<Function>|undefined {
|
|
94
|
+
console.log("Getting rule for field: ", field, this.rules)
|
|
95
|
+
return field && this.rules[field] && this.rules[field].length > 0 ? this.rules[field] : undefined
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
get isEditable(){
|
package/src/components/Crud.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type
|
|
2
|
+
import {onBeforeMount, type PropType} from "vue";
|
|
3
3
|
import type {IEntityCrud} from "@drax/crud-share";
|
|
4
4
|
import CrudList from "./CrudList.vue";
|
|
5
5
|
import CrudForm from "./CrudForm.vue";
|
|
@@ -7,24 +7,25 @@ import CrudNotify from "./CrudNotify.vue";
|
|
|
7
7
|
import CrudDialog from "./CrudDialog.vue";
|
|
8
8
|
import {useCrud} from "../composables/UseCrud";
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
const {entity} = defineProps({
|
|
12
11
|
entity: {type: Object as PropType<IEntityCrud>, required: true},
|
|
13
12
|
})
|
|
14
13
|
|
|
15
14
|
const {
|
|
16
|
-
onCreate, onEdit, onDelete, onCancel, onSubmit,
|
|
15
|
+
onCreate, onEdit, onDelete, onCancel, onSubmit,resetCrudStore,
|
|
17
16
|
operation, dialog, form, notify, error, message, doExport
|
|
18
17
|
} = useCrud(entity);
|
|
19
18
|
|
|
19
|
+
onBeforeMount(() => {
|
|
20
|
+
resetCrudStore()
|
|
21
|
+
})
|
|
22
|
+
|
|
20
23
|
</script>
|
|
21
24
|
|
|
22
25
|
<template>
|
|
23
26
|
<v-container fluid class="mt-5">
|
|
24
27
|
<v-card>
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
29
|
<crud-list
|
|
29
30
|
:entity="entity"
|
|
30
31
|
@create="onCreate"
|
|
@@ -5,8 +5,9 @@ import CrudFormField from "./CrudFormField.vue";
|
|
|
5
5
|
import type {TOperation} from "../interfaces/TOperation";
|
|
6
6
|
import type {IEntityCrud} from "@drax/crud-share";
|
|
7
7
|
import {useI18n} from "vue-i18n";
|
|
8
|
+
import {useCrudStore} from "../stores/UseCrudStore";
|
|
8
9
|
const {t,te} = useI18n()
|
|
9
|
-
|
|
10
|
+
const store = useCrudStore()
|
|
10
11
|
const valueModel = defineModel({type: [Object]})
|
|
11
12
|
|
|
12
13
|
|
|
@@ -20,10 +21,13 @@ const {entity} = defineProps({
|
|
|
20
21
|
const valid = ref()
|
|
21
22
|
const formRef = ref()
|
|
22
23
|
|
|
23
|
-
function submit() {
|
|
24
|
-
|
|
24
|
+
async function submit() {
|
|
25
|
+
store.resetErrors()
|
|
26
|
+
await formRef.value.validate()
|
|
25
27
|
if(valid.value) {
|
|
26
28
|
emit('submit',valueModel.value)
|
|
29
|
+
}else{
|
|
30
|
+
console.log('Invalid form')
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
@@ -38,6 +42,9 @@ const emit = defineEmits(['submit', 'cancel'])
|
|
|
38
42
|
<template>
|
|
39
43
|
<v-form v-model="valid" ref="formRef" @submit.prevent >
|
|
40
44
|
<v-card flat>
|
|
45
|
+
|
|
46
|
+
<v-card-subtitle v-if="valueModel._id">ID: {{valueModel._id}}</v-card-subtitle>
|
|
47
|
+
|
|
41
48
|
<v-card-text v-if="error">
|
|
42
49
|
<v-alert color="error">{{ te(error) ? t(error) : error }}</v-alert>
|
|
43
50
|
</v-card-text>
|
|
@@ -32,7 +32,7 @@ const label = computed(() => {
|
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
const rules = computed(() => {
|
|
35
|
-
return entity.
|
|
35
|
+
return entity.getRule(field.name) as any
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
const inputErrors = computed(() =>
|
|
@@ -44,7 +44,6 @@ const inputErrors = computed(() =>
|
|
|
44
44
|
<template>
|
|
45
45
|
|
|
46
46
|
<div v-if="field && field.type">
|
|
47
|
-
|
|
48
47
|
<v-text-field
|
|
49
48
|
v-if="field.type === 'string'"
|
|
50
49
|
type="text"
|
|
@@ -13,7 +13,7 @@ import type {IEntityCrud} from "@drax/crud-share";
|
|
|
13
13
|
import {useI18n} from "vue-i18n";
|
|
14
14
|
import type {IEntityCrudHeader} from "@drax/crud-share";
|
|
15
15
|
|
|
16
|
-
const {t} = useI18n()
|
|
16
|
+
const {t,te} = useI18n()
|
|
17
17
|
const {hasPermission} = useAuth()
|
|
18
18
|
|
|
19
19
|
const {entity} = defineProps({
|
|
@@ -26,7 +26,10 @@ const {
|
|
|
26
26
|
} = useCrud(entity)
|
|
27
27
|
|
|
28
28
|
const actions: IEntityCrudHeader[] = [{title: t('action.actions'), key: 'actions', sortable: false, align: 'end', minWidth: '140px'}]
|
|
29
|
-
const tHeaders: IEntityCrudHeader[] = entity.headers.map(header => ({
|
|
29
|
+
const tHeaders: IEntityCrudHeader[] = entity.headers.map(header => ({
|
|
30
|
+
...header,
|
|
31
|
+
title: te(`${entity.name.toLowerCase()}.fields.${header.title}`) ? t(`${entity.name.toLowerCase()}.fields.${header.title}`) : header.title
|
|
32
|
+
}))
|
|
30
33
|
|
|
31
34
|
const headers: IEntityCrudHeader[] = [...tHeaders, ...actions]
|
|
32
35
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type {PropType} from "vue";
|
|
3
|
-
import
|
|
3
|
+
import type {IEntityCrud} from "@drax/crud-share"
|
|
4
4
|
import {useCrud} from "../../composables/UseCrud";
|
|
5
5
|
import {useI18n} from "vue-i18n";
|
|
6
6
|
|
|
7
7
|
const {t} = useI18n()
|
|
8
8
|
|
|
9
9
|
const {entity} = defineProps({
|
|
10
|
-
entity: {type: Object as PropType<
|
|
10
|
+
entity: {type: Object as PropType<IEntityCrud>, required: true},
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
const {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type {PropType} from "vue";
|
|
3
|
-
import
|
|
3
|
+
import type {IEntityCrud} from "@drax/crud-share"
|
|
4
4
|
import {useCrud} from "../../composables/UseCrud";
|
|
5
5
|
import {useI18n} from "vue-i18n";
|
|
6
6
|
|
|
7
7
|
const {t} = useI18n()
|
|
8
8
|
const {entity} = defineProps({
|
|
9
|
-
entity: {type: Object as PropType<
|
|
9
|
+
entity: {type: Object as PropType<IEntityCrud>, required: true},
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
const {
|
|
@@ -31,7 +31,7 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
31
31
|
try {
|
|
32
32
|
|
|
33
33
|
if(!entity?.provider.export) {
|
|
34
|
-
throw new Error("
|
|
34
|
+
throw new Error("provider.export not implemented")
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const headers: string = entity.exportHeaders.join(',')
|
|
@@ -106,7 +106,6 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
function onSubmit(formData: any) {
|
|
109
|
-
console.log("formData", formData)
|
|
110
109
|
store.setInputErrors(null)
|
|
111
110
|
switch (store.operation) {
|
|
112
111
|
case "create":
|
|
@@ -167,6 +166,10 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
167
166
|
|
|
168
167
|
}
|
|
169
168
|
|
|
169
|
+
function resetCrudStore(){
|
|
170
|
+
store.$reset()
|
|
171
|
+
}
|
|
172
|
+
|
|
170
173
|
const dialog = computed({get(){return store.dialog} , set(value){store.setDialog(value)}})
|
|
171
174
|
const operation = computed({get(){return store.operation} , set(value){store.setOperation(value)}})
|
|
172
175
|
const form = computed({get(){return store.form} , set(value){store.setForm(value)}})
|
|
@@ -186,7 +189,7 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
186
189
|
const exportListVisible = computed({get(){return store.exportListVisible} , set(value){store.setExportListVisible(value)}})
|
|
187
190
|
|
|
188
191
|
return {
|
|
189
|
-
loadItems: doPaginate, doExport, onCreate, onEdit, onDelete, onCancel, onSubmit,
|
|
192
|
+
loadItems: doPaginate, doExport, onCreate, onEdit, onDelete, onCancel, onSubmit,resetCrudStore,
|
|
190
193
|
operation, dialog, form, notify, error, message, formValid,
|
|
191
194
|
loading, itemsPerPage, page, sortBy, search, totalItems, items,
|
|
192
195
|
exportFiles,exportLoading,exportListVisible
|
|
@@ -84,6 +84,10 @@ export const useCrudStore = defineStore('CrudStore', {
|
|
|
84
84
|
setInputErrors(inputErrors: any) {
|
|
85
85
|
this.inputErrors = inputErrors
|
|
86
86
|
},
|
|
87
|
+
resetErrors(){
|
|
88
|
+
this.inputErrors = null
|
|
89
|
+
this.error = ''
|
|
90
|
+
},
|
|
87
91
|
setExportFiles(exportFiles: string[]) {
|
|
88
92
|
this.exportFiles = exportFiles
|
|
89
93
|
},
|