@drax/crud-vue 0.11.3 → 0.11.5
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
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.11.
|
|
6
|
+
"version": "0.11.5",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"format": "prettier --write src/"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@drax/common-front": "^0.11.
|
|
27
|
+
"@drax/common-front": "^0.11.5",
|
|
28
28
|
"@drax/crud-front": "^0.11.3",
|
|
29
|
-
"@drax/crud-share": "^0.11.
|
|
29
|
+
"@drax/crud-share": "^0.11.5",
|
|
30
30
|
"@drax/media-vue": "^0.11.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"vue-tsc": "^2.1.10",
|
|
65
65
|
"vuetify": "^3.7.1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "e67f10f0af29468c9d30f16135cfdbdff166d916"
|
|
68
68
|
}
|
package/src/EntityCrud.ts
CHANGED
package/src/components/Crud.vue
CHANGED
|
@@ -22,6 +22,28 @@ onBeforeMount(() => {
|
|
|
22
22
|
prepareFilters()
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
const emit = defineEmits(['created', 'updated', 'deleted', 'viewed'])
|
|
26
|
+
|
|
27
|
+
async function submit() {
|
|
28
|
+
let result = await onSubmit(form.value)
|
|
29
|
+
switch (result.status) {
|
|
30
|
+
case "created":
|
|
31
|
+
emit("created", result.item)
|
|
32
|
+
break
|
|
33
|
+
case "updated":
|
|
34
|
+
emit("updated", result.item)
|
|
35
|
+
break
|
|
36
|
+
case "deleted":
|
|
37
|
+
emit("deleted")
|
|
38
|
+
break
|
|
39
|
+
case "viewed":
|
|
40
|
+
emit("deleted")
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
25
47
|
</script>
|
|
26
48
|
|
|
27
49
|
<template>
|
|
@@ -73,7 +95,7 @@ onBeforeMount(() => {
|
|
|
73
95
|
:error="error"
|
|
74
96
|
:operation="operation"
|
|
75
97
|
:readonly="operation === 'delete'"
|
|
76
|
-
@submit="
|
|
98
|
+
@submit="submit"
|
|
77
99
|
@cancel="onCancel"
|
|
78
100
|
>
|
|
79
101
|
|
|
@@ -30,7 +30,7 @@ const title = computed(() => {
|
|
|
30
30
|
</script>
|
|
31
31
|
|
|
32
32
|
<template>
|
|
33
|
-
<v-dialog v-model="dialog" :fullscreen="entity.dialogFullscreen">
|
|
33
|
+
<v-dialog v-model="dialog" :fullscreen="entity.dialogFullscreen" :max-width="entity.dialogMaxWidth">
|
|
34
34
|
<v-card>
|
|
35
35
|
<v-toolbar>
|
|
36
36
|
<v-toolbar-title>{{title}}</v-toolbar-title>
|
|
@@ -99,7 +99,7 @@ const {
|
|
|
99
99
|
:entity="entity"
|
|
100
100
|
v-model="valueModel[field.name]"
|
|
101
101
|
:clearable="false"
|
|
102
|
-
:readonly="readonly"
|
|
102
|
+
:readonly="readonly || field.readonly"
|
|
103
103
|
:variant="variant"
|
|
104
104
|
:prepend-inner-icon="field?.prependInnerIcon"
|
|
105
105
|
:prepend-icon="field?.prependIcon"
|
|
@@ -115,7 +115,7 @@ const {
|
|
|
115
115
|
<v-card-actions>
|
|
116
116
|
<v-spacer></v-spacer>
|
|
117
117
|
<v-btn variant="text" color="grey" @click="cancel">{{ t('action.cancel') }}</v-btn>
|
|
118
|
-
<v-btn variant="flat" v-if="operation != 'view'" :color="submitColor" @click="submit">
|
|
118
|
+
<v-btn variant="flat" v-if="operation != 'view'" :color="submitColor" @click="submit" :loading="store.loading">
|
|
119
119
|
{{ operation ? t('action.' + operation) : t('action.sent') }}
|
|
120
120
|
</v-btn>
|
|
121
121
|
</v-card-actions>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {IDraxPaginateResult, IEntityCrud} from "@drax/crud-share";
|
|
2
2
|
import {useCrudStore} from "../stores/UseCrudStore";
|
|
3
|
-
import {computed} from "vue";
|
|
3
|
+
import {computed, toRaw} from "vue";
|
|
4
4
|
|
|
5
5
|
export function useCrud(entity: IEntityCrud) {
|
|
6
6
|
|
|
@@ -242,22 +242,20 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
242
242
|
store.setInputErrors(null)
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
function onSubmit(formData: any) {
|
|
245
|
+
async function onSubmit(formData: any): Promise<{status:string,item?:any}> {
|
|
246
246
|
store.setInputErrors(null)
|
|
247
247
|
switch (store.operation) {
|
|
248
248
|
case "view":
|
|
249
249
|
closeDialog()
|
|
250
|
-
|
|
250
|
+
return {status: 'viewed'}
|
|
251
251
|
case "create":
|
|
252
|
-
doCreate(formData)
|
|
253
|
-
break
|
|
252
|
+
return doCreate(formData)
|
|
254
253
|
case "edit":
|
|
255
|
-
doUpdate(formData)
|
|
256
|
-
break
|
|
254
|
+
return doUpdate(formData)
|
|
257
255
|
case "delete":
|
|
258
|
-
doDelete(formData)
|
|
259
|
-
break
|
|
256
|
+
return doDelete(formData)
|
|
260
257
|
}
|
|
258
|
+
return {status: 'unknown'}
|
|
261
259
|
}
|
|
262
260
|
|
|
263
261
|
function openDialog() {
|
|
@@ -270,26 +268,33 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
270
268
|
|
|
271
269
|
async function doCreate(formData: any) {
|
|
272
270
|
try {
|
|
273
|
-
|
|
271
|
+
store.setLoading(true)
|
|
272
|
+
let item = await entity?.provider.create(toRaw(formData))
|
|
274
273
|
await doPaginate()
|
|
275
274
|
closeDialog()
|
|
276
275
|
store.showMessage("Entity created successfully!")
|
|
276
|
+
return {status: 'created', item: item}
|
|
277
277
|
} catch (e: any) {
|
|
278
278
|
if (e.inputErrors) {
|
|
279
279
|
store.setInputErrors(e.inputErrors)
|
|
280
280
|
}
|
|
281
281
|
store.setError(e.message || "An error occurred while creating the entity")
|
|
282
282
|
console.error("Error creating entity", e)
|
|
283
|
+
return {status: 'error'}
|
|
284
|
+
} finally {
|
|
285
|
+
store.setLoading(false)
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
}
|
|
286
289
|
|
|
287
290
|
async function doUpdate(formData: any) {
|
|
288
291
|
try {
|
|
289
|
-
|
|
292
|
+
store.setLoading(true)
|
|
293
|
+
let item = await entity?.provider.update(formData.id, toRaw(formData))
|
|
290
294
|
await doPaginate()
|
|
291
295
|
closeDialog()
|
|
292
296
|
store.showMessage("Entity updated successfully!")
|
|
297
|
+
return {status: 'updated', item: item}
|
|
293
298
|
} catch (e: any) {
|
|
294
299
|
//console.log("inputErrors", e.inputErrors)
|
|
295
300
|
if (e.inputErrors) {
|
|
@@ -297,19 +302,27 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
297
302
|
}
|
|
298
303
|
store.setError(e.message || "An error occurred while updating the entity")
|
|
299
304
|
console.error("Error updating entity", e)
|
|
305
|
+
return {status: 'error'}
|
|
306
|
+
} finally {
|
|
307
|
+
store.setLoading(false)
|
|
300
308
|
}
|
|
301
309
|
|
|
302
310
|
}
|
|
303
311
|
|
|
304
312
|
async function doDelete(formData: any) {
|
|
305
313
|
try {
|
|
306
|
-
|
|
314
|
+
store.setLoading(true)
|
|
315
|
+
await entity?.provider.delete(formData.id)
|
|
307
316
|
await doPaginate()
|
|
308
317
|
closeDialog()
|
|
309
318
|
store.showMessage("Entity deleted successfully!")
|
|
319
|
+
return {status: 'deleted'}
|
|
310
320
|
} catch (e: any) {
|
|
311
321
|
store.setError(e.message || "An error occurred while deleting the entity")
|
|
312
322
|
console.error("Error updating entity", e)
|
|
323
|
+
return {status: 'error'}
|
|
324
|
+
} finally {
|
|
325
|
+
store.setLoading(false)
|
|
313
326
|
}
|
|
314
327
|
|
|
315
328
|
}
|