@drax/crud-vue 0.37.0 → 0.37.1
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.37.
|
|
6
|
+
"version": "0.37.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@drax/common-front": "^0.37.0",
|
|
28
|
-
"@drax/crud-front": "^0.37.
|
|
28
|
+
"@drax/crud-front": "^0.37.1",
|
|
29
29
|
"@drax/crud-share": "^0.37.0",
|
|
30
30
|
"@drax/media-vue": "^0.37.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
+
"dayjs": "^1.11.13",
|
|
33
34
|
"pinia": "^2.2.2",
|
|
34
35
|
"vue": "^3.5.7",
|
|
35
36
|
"vue-i18n": "^9.14.0",
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
"vue-tsc": "^2.1.10",
|
|
65
66
|
"vuetify": "^3.8.2"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "e4be12cd506bf5255e0f8b26b89cdd2a660a523d"
|
|
68
69
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed,
|
|
3
|
-
import type { IEntityCrud
|
|
2
|
+
import { computed, type PropType } from 'vue'
|
|
3
|
+
import type { IEntityCrud } from '@drax/crud-share'
|
|
4
4
|
import { useCrudStore } from '../stores/UseCrudStore'
|
|
5
5
|
import { useI18n } from 'vue-i18n'
|
|
6
6
|
import { useFilterIcon } from '../composables/useFilterIcon'
|
|
7
|
-
import { useCrudRefDisplay } from '../composables/useCrudRefDisplay'
|
|
8
7
|
import dayjs from "dayjs";
|
|
9
8
|
import CrudRefDisplay from "./CrudRefDisplay.vue";
|
|
10
9
|
|
|
11
|
-
const { t
|
|
10
|
+
const { t} = useI18n()
|
|
12
11
|
const store = useCrudStore()
|
|
13
12
|
const { filterIcon } = useFilterIcon()
|
|
14
|
-
const { refDisplay } = useCrudRefDisplay()
|
|
15
13
|
|
|
16
14
|
const props = defineProps({
|
|
17
15
|
entity: {
|
|
@@ -87,22 +85,6 @@ const getFilterValue = (filter: any) => {
|
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
|
|
90
|
-
// watch(activeFilters, async (filters) => {
|
|
91
|
-
// for (const filter of filters) {
|
|
92
|
-
// filter.display = await getFilterValue(filter)
|
|
93
|
-
// }
|
|
94
|
-
// }, { immediate: true, deep: true })
|
|
95
|
-
//
|
|
96
|
-
// const renegerateDisplay = async () => {
|
|
97
|
-
// for (const filter of activeFilters.value) {
|
|
98
|
-
// filter.display = await getFilterValue(filter)
|
|
99
|
-
// }
|
|
100
|
-
// }
|
|
101
|
-
//
|
|
102
|
-
// onMounted(() => {
|
|
103
|
-
// renegerateDisplay()
|
|
104
|
-
// })
|
|
105
|
-
|
|
106
88
|
const removeFilter = (index: number) => {
|
|
107
89
|
const filter = store.filters[index]
|
|
108
90
|
const filterDef = props.entity.filters[index]
|
|
@@ -114,14 +96,6 @@ const removeFilter = (index: number) => {
|
|
|
114
96
|
emit('filterRemoved')
|
|
115
97
|
}
|
|
116
98
|
|
|
117
|
-
const clearAllFilters = () => {
|
|
118
|
-
store.filters.forEach((filter: any, index: any) => {
|
|
119
|
-
const filterDef = props.entity.filters[index]
|
|
120
|
-
filter.value = filterDef.default
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
emit('filtersCleared')
|
|
124
|
-
}
|
|
125
99
|
|
|
126
100
|
const emit = defineEmits(['filterRemoved', 'filtersCleared'])
|
|
127
101
|
</script>
|
|
@@ -146,7 +120,6 @@ const emit = defineEmits(['filterRemoved', 'filtersCleared'])
|
|
|
146
120
|
|
|
147
121
|
<span class="font-weight-medium">{{ getFilterLabel(filter) }}</span>
|
|
148
122
|
<v-icon :icon="filterIcon(filter)" size="x-small" class="mx-1" />
|
|
149
|
-
<!-- <span>{{ getFilterValue(filter) }}</span>-->
|
|
150
123
|
<span v-if="['ref','array.ref'].includes(filter.type)">
|
|
151
124
|
<crud-ref-display
|
|
152
125
|
:ref-display="filter.refDisplay"
|
|
@@ -168,12 +168,12 @@ defineEmits(['import', 'export', 'create', 'update', 'delete', 'view', 'edit'])
|
|
|
168
168
|
/>
|
|
169
169
|
|
|
170
170
|
<crud-update-button
|
|
171
|
-
v-if="entity.isEditable && entity.isItemEditable(item) && hasPermission(entity.permissions
|
|
171
|
+
v-if="entity.isEditable && entity.isItemEditable(item) && hasPermission(entity.permissions?.update)"
|
|
172
172
|
@click="$emit('edit', item)"
|
|
173
173
|
/>
|
|
174
174
|
|
|
175
175
|
<crud-delete-button
|
|
176
|
-
v-if="entity.isDeletable && hasPermission(entity.permissions
|
|
176
|
+
v-if="entity.isDeletable && hasPermission(entity.permissions?.delete)"
|
|
177
177
|
@click="$emit('delete', item)"
|
|
178
178
|
/>
|
|
179
179
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {onMounted, ref, computed} from "vue";
|
|
3
3
|
import type {PropType} from "vue";
|
|
4
4
|
import type {IEntityCrud} from "@drax/crud-share";
|
|
5
|
-
import type {IDraxFieldFilter} from "@drax/crud-share
|
|
5
|
+
import type {IDraxFieldFilter} from "@drax/crud-share";
|
|
6
6
|
|
|
7
7
|
const {entity, value, refDisplay} = defineProps({
|
|
8
8
|
entity: {type: Object as PropType<IEntityCrud | undefined>, required: true},
|
|
@@ -2,13 +2,13 @@ import type {IDraxPaginateResult, IEntityCrud} from "@drax/crud-share";
|
|
|
2
2
|
import {useCrudStore} from "../stores/UseCrudStore";
|
|
3
3
|
import {computed, nextTick, toRaw} from "vue";
|
|
4
4
|
import getItemId from "../helpers/getItemId";
|
|
5
|
-
import {
|
|
5
|
+
import {useI18n} from "vue-i18n";
|
|
6
6
|
|
|
7
7
|
export function useCrud(entity: IEntityCrud) {
|
|
8
8
|
|
|
9
9
|
const store = useCrudStore()
|
|
10
10
|
|
|
11
|
-
const {
|
|
11
|
+
const {t: $t} = useI18n()
|
|
12
12
|
|
|
13
13
|
const exportError = computed({
|
|
14
14
|
get() {
|
|
@@ -224,7 +224,7 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
224
224
|
.forEach(field => {
|
|
225
225
|
if (item[field.name] && Array.isArray(item[field.name])) {
|
|
226
226
|
item[field.name] = item[field.name].map(((i: any) => getItemId(i) ? getItemId(i) : i))
|
|
227
|
-
}else{
|
|
227
|
+
} else {
|
|
228
228
|
item[field.name] = []
|
|
229
229
|
}
|
|
230
230
|
})
|
|
@@ -252,10 +252,10 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
252
252
|
openDialog()
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
function cloneItem(item: object):object {
|
|
256
|
-
try{
|
|
255
|
+
function cloneItem(item: object): object {
|
|
256
|
+
try {
|
|
257
257
|
return JSON.parse(JSON.stringify(item))
|
|
258
|
-
}catch (error){
|
|
258
|
+
} catch (error) {
|
|
259
259
|
console.error("Error cloning item", error)
|
|
260
260
|
return ({})
|
|
261
261
|
}
|
|
@@ -273,7 +273,7 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
273
273
|
store.setInputErrors(null)
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
async function onSubmit(formData: any): Promise<{status:string,item?:any}> {
|
|
276
|
+
async function onSubmit(formData: any): Promise<{ status: string, item?: any }> {
|
|
277
277
|
store.setInputErrors(null)
|
|
278
278
|
switch (store.operation) {
|
|
279
279
|
case "view":
|
|
@@ -300,11 +300,14 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
300
300
|
async function doCreate(formData: any) {
|
|
301
301
|
try {
|
|
302
302
|
store.setLoading(true)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
303
|
+
if (entity?.provider.create) {
|
|
304
|
+
let item = await entity?.provider.create(toRaw(formData))
|
|
305
|
+
await doPaginate()
|
|
306
|
+
closeDialog()
|
|
307
|
+
store.showMessage("Entity created successfully!")
|
|
308
|
+
return {status: 'created', item: item}
|
|
309
|
+
}
|
|
310
|
+
throw new Error("provider.create not implemented")
|
|
308
311
|
} catch (e: any) {
|
|
309
312
|
if (e.inputErrors) {
|
|
310
313
|
store.setInputErrors(e.inputErrors)
|
|
@@ -321,11 +324,15 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
321
324
|
async function doUpdate(formData: any) {
|
|
322
325
|
try {
|
|
323
326
|
store.setLoading(true)
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
if (entity?.provider.update) {
|
|
328
|
+
let item = await entity?.provider.update(getItemId(formData), toRaw(formData))
|
|
329
|
+
await doPaginate()
|
|
330
|
+
closeDialog()
|
|
331
|
+
store.showMessage("Entity updated successfully!")
|
|
332
|
+
return {status: 'updated', item: item}
|
|
333
|
+
}
|
|
334
|
+
throw new Error("provider.update not implemented")
|
|
335
|
+
|
|
329
336
|
} catch (e: any) {
|
|
330
337
|
//console.log("inputErrors", e.inputErrors)
|
|
331
338
|
if (e.inputErrors) {
|
|
@@ -343,11 +350,14 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
343
350
|
async function doDelete(formData: any) {
|
|
344
351
|
try {
|
|
345
352
|
store.setLoading(true)
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
353
|
+
if (entity?.provider.delete) {
|
|
354
|
+
await entity?.provider.delete(getItemId(formData))
|
|
355
|
+
await doPaginate()
|
|
356
|
+
closeDialog()
|
|
357
|
+
store.showMessage("Entity deleted successfully!")
|
|
358
|
+
return {status: 'deleted'}
|
|
359
|
+
}
|
|
360
|
+
throw new Error("provider.delete not implemented")
|
|
351
361
|
} catch (e: any) {
|
|
352
362
|
store.setError(e.message || "An error occurred while deleting the entity")
|
|
353
363
|
console.error("Error updating entity", e)
|
|
@@ -366,7 +376,7 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
366
376
|
store.setFilters(entity.formFilters)
|
|
367
377
|
}
|
|
368
378
|
|
|
369
|
-
async function clearFilters(){
|
|
379
|
+
async function clearFilters() {
|
|
370
380
|
prepareFilters()
|
|
371
381
|
store.setSearch("")
|
|
372
382
|
search.value = ""
|
|
@@ -376,7 +386,7 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
376
386
|
|
|
377
387
|
}
|
|
378
388
|
|
|
379
|
-
async function applyFilters(){
|
|
389
|
+
async function applyFilters() {
|
|
380
390
|
await doPaginate()
|
|
381
391
|
}
|
|
382
392
|
|