@live-change/frontend-auto-form 0.9.12 → 0.9.14
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/front/src/components/crud/EditorButtons.vue +4 -1
- package/front/src/components/crud/ModelList.vue +22 -12
- package/front/src/components/crud/ModelView.vue +73 -21
- package/front/src/components/form/AutoField.vue +4 -3
- package/front/src/components/form/AutoInput.vue +2 -0
- package/front/src/components/view/AutoView.vue +78 -17
- package/front/src/components/view/AutoViewField.vue +120 -0
- package/front/src/components/view/DefaultFieldView.vue +82 -0
- package/front/src/components/view/JsonView.vue +39 -0
- package/front/src/components/view/ObjectView.vue +58 -0
- package/front/src/components/view/StringView.vue +36 -0
- package/front/src/components/view/provideAutoViewComponents.js +14 -0
- package/front/src/logic/editorData.js +6 -0
- package/front/src/pages/List.vue +1 -1
- package/front/src/pages/View.vue +1 -3
- package/index.js +13 -0
- package/package.json +13 -13
|
@@ -69,7 +69,10 @@
|
|
|
69
69
|
|
|
70
70
|
import { validateData } from "@live-change/vue3-components"
|
|
71
71
|
const validationResult = computed(() => {
|
|
72
|
-
const currentValue =
|
|
72
|
+
const currentValue = {
|
|
73
|
+
...(editor.value.identifiers),
|
|
74
|
+
...(editor.value.value.value),
|
|
75
|
+
}
|
|
73
76
|
const validationResult = validateData(model.value, currentValue, 'validation', appContext,
|
|
74
77
|
props.propName, props.rootValue, true)
|
|
75
78
|
const softValidationResult = validateData(model.value, currentValue, 'softValidation', appContext,
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div>
|
|
3
3
|
<!-- <h4>definition</h4>
|
|
4
4
|
<pre>{{ modelDefinition }}</pre>-->
|
|
5
5
|
|
|
6
6
|
<div class="surface-card w-full p-3 shadow-1 border-round mb-2">
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
<slot name="header">
|
|
8
|
+
<div class="">
|
|
9
|
+
Service <strong>{{ service }}</strong>
|
|
10
|
+
</div>
|
|
11
|
+
<div class="text-2xl">
|
|
12
|
+
<strong>{{ pluralize(model) }}</strong>
|
|
13
|
+
<span class="ml-1">list</span>
|
|
14
|
+
</div>
|
|
15
|
+
</slot>
|
|
14
16
|
</div>
|
|
15
17
|
|
|
16
18
|
<div class="surface-card p-3 shadow-1 border-round" v-if="modelsPathRangeFunction">
|
|
@@ -58,7 +60,7 @@
|
|
|
58
60
|
</div>
|
|
59
61
|
</div>
|
|
60
62
|
|
|
61
|
-
<div class="mt-3 flex flex-row justify-content-end mr-2">
|
|
63
|
+
<div v-if="modelDefinition.value?.crud?.create" class="mt-3 flex flex-row justify-content-end mr-2">
|
|
62
64
|
<router-link :to="createRoute" class="no-underline2">
|
|
63
65
|
<Button icon="pi pi-plus" :label="'Create new '+model" />
|
|
64
66
|
</router-link>
|
|
@@ -69,6 +71,8 @@
|
|
|
69
71
|
|
|
70
72
|
<script setup>
|
|
71
73
|
|
|
74
|
+
import Button from "primevue/button"
|
|
75
|
+
|
|
72
76
|
import { ref, computed, onMounted, defineProps, toRefs } from 'vue'
|
|
73
77
|
import { RangeViewer, injectComponent } from "@live-change/vue3-components"
|
|
74
78
|
import pluralize from 'pluralize'
|
|
@@ -81,9 +85,13 @@
|
|
|
81
85
|
model: {
|
|
82
86
|
type: String,
|
|
83
87
|
required: true,
|
|
84
|
-
}
|
|
88
|
+
},
|
|
89
|
+
identifiers: {
|
|
90
|
+
type: Object,
|
|
91
|
+
default: () => ({})
|
|
92
|
+
},
|
|
85
93
|
})
|
|
86
|
-
const { service, model } = toRefs(props)
|
|
94
|
+
const { service, model, identifiers } = toRefs(props)
|
|
87
95
|
|
|
88
96
|
import AutoObjectIdentification from './AutoObjectIdentification.vue'
|
|
89
97
|
|
|
@@ -118,6 +126,7 @@
|
|
|
118
126
|
if(!path[config.service]) return null
|
|
119
127
|
if(!path[config.service][rangeView]) return null
|
|
120
128
|
return (range) => path[config.service][rangeView]({
|
|
129
|
+
...identifiers.value,
|
|
121
130
|
...(config.reverse ? reverseRange(range) : range),
|
|
122
131
|
})
|
|
123
132
|
})
|
|
@@ -164,7 +173,8 @@
|
|
|
164
173
|
name: 'auto-form:editor',
|
|
165
174
|
params: {
|
|
166
175
|
serviceName: service.value,
|
|
167
|
-
modelName: model.
|
|
176
|
+
modelName: model.value,
|
|
177
|
+
identifiers: Object.values(identifiers.value)
|
|
168
178
|
}
|
|
169
179
|
}))
|
|
170
180
|
|
|
@@ -1,30 +1,75 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div>
|
|
3
|
-
<h4>identifiers</h4>
|
|
4
|
-
<pre>{{ identifiers }}</pre>
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
<!-- <h4>identifiers</h4>
|
|
5
|
+
<pre>{{ identifiers }}</pre>
|
|
6
|
+
|
|
7
|
+
<h4>definition</h4>
|
|
8
|
+
<pre>{{ modelDefinition }}</pre>
|
|
9
|
+
|
|
10
|
+
<h4>object</h4>
|
|
11
|
+
<pre>{{ object }}</pre>-->
|
|
12
|
+
|
|
13
|
+
<div class="surface-card p-3 shadow-1 border-round mb-4">
|
|
14
|
+
|
|
15
|
+
<div class="">
|
|
16
|
+
Service <strong>{{ service }}</strong>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="text-2xl mb-4">
|
|
19
|
+
<strong>{{ model }}</strong>
|
|
20
|
+
<ObjectIdentification
|
|
21
|
+
:objectType="service + '_' + model"
|
|
22
|
+
:object="object.to ?? object.id"
|
|
23
|
+
:data="object"
|
|
24
|
+
class="ml-2"
|
|
25
|
+
/>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<AutoView :value="object" :root-value="object" :i18n="i18n" :attributes="attributes"
|
|
29
|
+
:definition="modelDefinition" />
|
|
8
30
|
|
|
9
|
-
<div class="">
|
|
10
|
-
Service <strong>{{ service }}</strong>
|
|
11
31
|
</div>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
|
|
33
|
+
<div v-for="itemRelation of itemRelations">
|
|
34
|
+
<ModelList :service="itemRelation.from.serviceName" :model="itemRelation.from.name"
|
|
35
|
+
:identifiers="relatedIdentifiers">
|
|
36
|
+
<template #header>
|
|
37
|
+
<div class="text-xl">
|
|
38
|
+
<ObjectIdentification
|
|
39
|
+
:objectType="service + '_' + model"
|
|
40
|
+
:object="object.to ?? object.id"
|
|
41
|
+
:data="object"
|
|
42
|
+
class="mr-2"
|
|
43
|
+
/>
|
|
44
|
+
<span class="mr-2 font-medium">{{ model }}'s</span>
|
|
45
|
+
<span class="font-bold">{{ pluralize(itemRelation.from.name) }}</span>:
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
</ModelList>
|
|
50
|
+
|
|
51
|
+
<pre>{{ relatedIdentifiers }}</pre>
|
|
52
|
+
|
|
53
|
+
<pre>{{ itemRelation }}</pre>
|
|
54
|
+
|
|
20
55
|
</div>
|
|
21
56
|
|
|
57
|
+
<!-- <div class="surface-card p-3 shadow-1 border-round">
|
|
58
|
+
|
|
59
|
+
<h4>Backward relations</h4>
|
|
60
|
+
<pre>{{ backwardRelations }}</pre>
|
|
61
|
+
|
|
62
|
+
</div>-->
|
|
63
|
+
|
|
22
64
|
</div>
|
|
23
65
|
</template>
|
|
24
66
|
|
|
25
67
|
<script setup>
|
|
26
68
|
|
|
69
|
+
import AutoView from '../view/AutoView.vue'
|
|
70
|
+
import ModelList from './ModelList.vue'
|
|
27
71
|
|
|
72
|
+
import pluralize from 'pluralize'
|
|
28
73
|
import { ref, computed, onMounted, defineProps, defineEmits, toRefs } from 'vue'
|
|
29
74
|
import { RangeViewer, injectComponent } from "@live-change/vue3-components"
|
|
30
75
|
|
|
@@ -39,13 +84,9 @@
|
|
|
39
84
|
},
|
|
40
85
|
identifiers: {
|
|
41
86
|
type: Object,
|
|
42
|
-
default:
|
|
43
|
-
},
|
|
44
|
-
draft: {
|
|
45
|
-
type: Boolean,
|
|
46
|
-
default: false
|
|
87
|
+
default: () => ({})
|
|
47
88
|
},
|
|
48
|
-
|
|
89
|
+
attributes: {
|
|
49
90
|
type: Object,
|
|
50
91
|
default: () => ({})
|
|
51
92
|
},
|
|
@@ -54,7 +95,7 @@
|
|
|
54
95
|
default: ''
|
|
55
96
|
}
|
|
56
97
|
})
|
|
57
|
-
const { service, model, identifiers,
|
|
98
|
+
const { service, model, identifiers, attributes, i18n } = toRefs(props)
|
|
58
99
|
|
|
59
100
|
const emit = defineEmits(['saved', 'draftSaved', 'draftDiscarded', 'saveError', 'created' ])
|
|
60
101
|
|
|
@@ -77,6 +118,14 @@
|
|
|
77
118
|
return api.services?.[service.value]?.models?.[model.value]
|
|
78
119
|
})
|
|
79
120
|
|
|
121
|
+
import { getForwardRelations, getBackwardRelations } from '../../logic/relations.js'
|
|
122
|
+
const forwardRelations = computed(() => getForwardRelations(modelDefinition.value, () => true, api))
|
|
123
|
+
const backwardRelations = computed(() => getBackwardRelations(modelDefinition.value, api))
|
|
124
|
+
|
|
125
|
+
const itemRelations = computed(
|
|
126
|
+
() => backwardRelations.value.filter(relation => relation.relation === 'itemOf')
|
|
127
|
+
)
|
|
128
|
+
|
|
80
129
|
import viewData from '../../logic/viewData.js'
|
|
81
130
|
|
|
82
131
|
const viewDataPromise = viewData({
|
|
@@ -90,6 +139,9 @@
|
|
|
90
139
|
viewDataPromise
|
|
91
140
|
])
|
|
92
141
|
|
|
142
|
+
const relatedIdentifiers = computed(() => ({
|
|
143
|
+
[model.value[0].toLowerCase() + model.value.slice(1)]: object.value.to ?? object.value.id
|
|
144
|
+
}))
|
|
93
145
|
|
|
94
146
|
</script>
|
|
95
147
|
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
import AutoInput from "./AutoInput.vue"
|
|
43
43
|
|
|
44
44
|
import { inputs, types } from '../../config.js'
|
|
45
|
-
import { computed, getCurrentInstance, inject, toRefs, onMounted, ref } from 'vue'
|
|
45
|
+
import { computed, getCurrentInstance, inject, toRefs, onMounted, ref, useId } from 'vue'
|
|
46
46
|
|
|
47
47
|
const isMounted = ref(false)
|
|
48
48
|
onMounted(() => isMounted.value = true)
|
|
@@ -94,8 +94,7 @@
|
|
|
94
94
|
}
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
const
|
|
98
|
-
const uid = computed(() => isMounted.value ? 'field_'+instanceUid.toFixed().padStart(6, '0') : undefined)
|
|
97
|
+
const uid = useId()
|
|
99
98
|
|
|
100
99
|
const emit = defineEmits(['update:modelValue'])
|
|
101
100
|
|
|
@@ -105,6 +104,8 @@
|
|
|
105
104
|
if(definition.value?.if) {
|
|
106
105
|
if(definition.value?.if.function) {
|
|
107
106
|
return eval(`(${definition.value.if.function})`)
|
|
107
|
+
} else {
|
|
108
|
+
throw new Error('Unknown if type' + JSON.stringify(definition.value.if))
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
return false
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
:value="value?.[property]"
|
|
5
|
-
:definition="definition.properties[property]"
|
|
6
|
-
:label="property"
|
|
7
|
-
:rootValue="props.rootValue" :propName="(propName ? propName + '.' : '') + property"
|
|
8
|
-
:i18n="i18n"
|
|
9
|
-
class="col-12" />
|
|
10
|
-
</div>
|
|
2
|
+
<!-- <pre>{{ viewComponentRequest }}</pre>-->
|
|
3
|
+
<component v-if="viewComponent && visible" :is="viewComponent" v-bind="attributes" :i18n="i18n" />
|
|
11
4
|
</template>
|
|
12
5
|
|
|
13
6
|
<script setup>
|
|
14
|
-
|
|
7
|
+
import { injectComponent } from '@live-change/vue3-components'
|
|
15
8
|
|
|
16
|
-
import { computed, inject, getCurrentInstance, toRefs } from 'vue'
|
|
9
|
+
import { computed, inject, getCurrentInstance, toRefs, defineAsyncComponent } from 'vue'
|
|
17
10
|
|
|
18
11
|
const props = defineProps({
|
|
19
12
|
value: {},
|
|
@@ -37,16 +30,84 @@
|
|
|
37
30
|
items: {
|
|
38
31
|
type: String
|
|
39
32
|
}
|
|
33
|
+
},
|
|
34
|
+
class: {},
|
|
35
|
+
style: {},
|
|
36
|
+
attributes: {
|
|
37
|
+
type: Object,
|
|
38
|
+
default: () => ({})
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const { value, definition, propName, rootValue, visibleProperties } = toRefs(props)
|
|
43
|
+
|
|
44
|
+
const definitionIf = computed(() => {
|
|
45
|
+
if(definition.value?.if) {
|
|
46
|
+
if(definition.value?.if.function) {
|
|
47
|
+
return eval(`(${definition.value.if.function})`)
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('Unknown if type' + JSON.stringify(definition.value.if))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const visible = computed(() => {
|
|
56
|
+
if(!definition.value) return false
|
|
57
|
+
if(definitionIf.value) {
|
|
58
|
+
//console.log("DIF", propName.value, definitionIf.value, 'IN', props.rootValue)
|
|
59
|
+
return definitionIf.value({
|
|
60
|
+
source: definition.value,
|
|
61
|
+
props: props.rootValue,
|
|
62
|
+
propName: props.propName
|
|
63
|
+
})
|
|
40
64
|
}
|
|
65
|
+
return true
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const viewFilter = computed(() => {
|
|
69
|
+
const filter = definition?.view?.componentFilter
|
|
70
|
+
if(filter) {
|
|
71
|
+
if(filter.function) {
|
|
72
|
+
return eval(`(${filter.function})`)
|
|
73
|
+
} else {
|
|
74
|
+
throw new Error('Unknown filter type' + JSON.stringify(filter))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return undefined
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const viewComponentRequest = computed(() => (definition.value?.view?.componentRequest ?? {
|
|
81
|
+
...(definition.value?.view?.componentRequestProperties),
|
|
82
|
+
name: 'AutoView',
|
|
83
|
+
type: definition.value.type ?? 'Object',
|
|
84
|
+
view: definition?.view?.name ?? definition?.view,
|
|
85
|
+
filter: viewFilter.value
|
|
86
|
+
}))
|
|
87
|
+
|
|
88
|
+
const viewComponent = computed(() => {
|
|
89
|
+
const type = definition.value.type ?? 'Object'
|
|
90
|
+
const defaultComponent = (type === 'Object')
|
|
91
|
+
? defineAsyncComponent(() => import('./ObjectView.vue'))
|
|
92
|
+
: defineAsyncComponent(() => import('./JsonView.vue'))
|
|
93
|
+
return injectComponent(viewComponentRequest.value, defineAsyncComponent(() => import('./JsonView.vue')))
|
|
41
94
|
})
|
|
42
95
|
|
|
43
|
-
const
|
|
96
|
+
const viewClass = computed(() => [definition.value?.view?.class, props.class])
|
|
97
|
+
const viewStyle = computed(() => [definition.value?.view?.style, props.style])
|
|
44
98
|
|
|
45
|
-
const
|
|
46
|
-
visibleProperties.value
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
99
|
+
const attributes = computed(() => ({
|
|
100
|
+
visibleProperties: visibleProperties.value,
|
|
101
|
+
i18n: i18n.value,
|
|
102
|
+
...(definition.value?.view?.attributes),
|
|
103
|
+
...(props.attributes),
|
|
104
|
+
value: value.value,
|
|
105
|
+
definition: definition.value,
|
|
106
|
+
class: viewClass.value,
|
|
107
|
+
style: viewStyle.value,
|
|
108
|
+
rootValue: rootValue.value,
|
|
109
|
+
propName: propName.value,
|
|
110
|
+
}))
|
|
50
111
|
|
|
51
112
|
</script>
|
|
52
113
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component v-if="fieldComponent && visible" :is="fieldComponent" v-bind="attributes" :i18n="i18n" />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup>
|
|
6
|
+
import { injectComponent } from '@live-change/vue3-components'
|
|
7
|
+
|
|
8
|
+
import { computed, inject, getCurrentInstance, toRefs } from 'vue'
|
|
9
|
+
import DefaultFieldView from './DefaultFieldView.vue'
|
|
10
|
+
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
name: {
|
|
13
|
+
type: String
|
|
14
|
+
},
|
|
15
|
+
label: {
|
|
16
|
+
type: String
|
|
17
|
+
},
|
|
18
|
+
value: {},
|
|
19
|
+
definition: {
|
|
20
|
+
type: Object
|
|
21
|
+
},
|
|
22
|
+
rootValue: {
|
|
23
|
+
type: Object,
|
|
24
|
+
default: () => ({})
|
|
25
|
+
},
|
|
26
|
+
propName: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: ''
|
|
29
|
+
},
|
|
30
|
+
i18n: {
|
|
31
|
+
type: String,
|
|
32
|
+
default: ''
|
|
33
|
+
},
|
|
34
|
+
visibleProperties: {
|
|
35
|
+
type: Array,
|
|
36
|
+
items: {
|
|
37
|
+
type: String
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
class: {},
|
|
41
|
+
style: {},
|
|
42
|
+
attributes: {
|
|
43
|
+
type: Object,
|
|
44
|
+
default: () => ({})
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const { value, definition, propName, rootValue, label, name } = toRefs(props)
|
|
49
|
+
|
|
50
|
+
const definitionIf = computed(() => {
|
|
51
|
+
if(definition.value?.if) {
|
|
52
|
+
if(definition.value?.if.function) {
|
|
53
|
+
return eval(`(${definition.value.if.function})`)
|
|
54
|
+
} else {
|
|
55
|
+
throw new Error('Unknown if type' + JSON.stringify(definition.value.if))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const visible = computed(() => {
|
|
62
|
+
if(!definition.value) return false
|
|
63
|
+
if(definitionIf.value) {
|
|
64
|
+
//console.log("DIF", propName.value, definitionIf.value, 'IN', props.rootValue)
|
|
65
|
+
return definitionIf.value({
|
|
66
|
+
source: definition.value,
|
|
67
|
+
props: props.rootValue,
|
|
68
|
+
propName: props.propName
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
return true
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const fieldFilter = computed(() => {
|
|
75
|
+
const filter = definition?.view?.fieldComponentFilter
|
|
76
|
+
if(filter) {
|
|
77
|
+
if(filter.function) {
|
|
78
|
+
return eval(`(${filter.function})`)
|
|
79
|
+
} else {
|
|
80
|
+
throw new Error('Unknown filter type' + JSON.stringify(filter))
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return undefined
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const fieldComponent = computed(() => injectComponent(definition.value?.view?.fieldComponentRequest ?? {
|
|
87
|
+
...(definition.value?.view?.fieldComponentRequestProperties),
|
|
88
|
+
name: 'AutoFieldView',
|
|
89
|
+
type: definition.type ?? 'Object',
|
|
90
|
+
view: definition?.view?.name ?? definition?.view,
|
|
91
|
+
filter: fieldFilter.value
|
|
92
|
+
}, DefaultFieldView))
|
|
93
|
+
|
|
94
|
+
const fieldClass = computed(() => [definition.value?.view?.fieldClass, props.class])
|
|
95
|
+
const fieldStyle = computed(() => [definition.value?.view?.fieldStyle, props.style])
|
|
96
|
+
|
|
97
|
+
const viewClass = computed(() => [definition.value?.view?.class, props.viewClass])
|
|
98
|
+
const viewStyle = computed(() => [definition.value?.view?.style, props.viewStyle])
|
|
99
|
+
|
|
100
|
+
const attributes = computed(() => ({
|
|
101
|
+
i18n: i18n.value,
|
|
102
|
+
name: name.value,
|
|
103
|
+
label: label.value,
|
|
104
|
+
...(definition.value?.view?.attributes),
|
|
105
|
+
...(props.attributes),
|
|
106
|
+
value: value.value,
|
|
107
|
+
definition: definition.value,
|
|
108
|
+
class: fieldClass.value,
|
|
109
|
+
style: fieldStyle.value,
|
|
110
|
+
viewClass: viewClass.value,
|
|
111
|
+
viewStyle: viewStyle.value,
|
|
112
|
+
rootValue: rootValue.value,
|
|
113
|
+
propName: propName.value,
|
|
114
|
+
}))
|
|
115
|
+
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<style scoped>
|
|
119
|
+
|
|
120
|
+
</style>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="field" :class="fieldClass" :style="fieldStyle">
|
|
3
|
+
<slot name="label"
|
|
4
|
+
v-bind="{ uid, value, definition, viewClass, viewStyle, attributes, propName, rootValue, i18n }">
|
|
5
|
+
<label :for="uid" class="font-medium text-lg">{{ t( label ) }}</label>
|
|
6
|
+
</slot>
|
|
7
|
+
<slot v-bind="{ uid, value, definition, viewClass, viewStyle, attributes, propName, rootValue, i18n }">
|
|
8
|
+
<AutoView :value="value" :definition="definition"
|
|
9
|
+
:class="viewClass" :style="viewStyle"
|
|
10
|
+
:attributes="attributes"
|
|
11
|
+
:propName="propName"
|
|
12
|
+
:rootValue="rootValue"
|
|
13
|
+
:id="uid"
|
|
14
|
+
:i18n="i18n" />
|
|
15
|
+
</slot>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup>
|
|
20
|
+
|
|
21
|
+
import AutoView from "./AutoView.vue"
|
|
22
|
+
|
|
23
|
+
import { computed, getCurrentInstance, inject, toRefs, onMounted, ref, useId } from 'vue'
|
|
24
|
+
|
|
25
|
+
const isMounted = ref(false)
|
|
26
|
+
onMounted(() => isMounted.value = true)
|
|
27
|
+
|
|
28
|
+
import { useI18n } from 'vue-i18n'
|
|
29
|
+
const { t, rt } = useI18n()
|
|
30
|
+
|
|
31
|
+
const props = defineProps({
|
|
32
|
+
value: {},
|
|
33
|
+
definition: {
|
|
34
|
+
type: Object
|
|
35
|
+
},
|
|
36
|
+
name: {
|
|
37
|
+
type: String
|
|
38
|
+
},
|
|
39
|
+
label: {
|
|
40
|
+
type: String
|
|
41
|
+
},
|
|
42
|
+
class: {},
|
|
43
|
+
style: {},
|
|
44
|
+
viewClass: {},
|
|
45
|
+
viewStyle: {},
|
|
46
|
+
attributes: {
|
|
47
|
+
type: Object,
|
|
48
|
+
default: () => ({})
|
|
49
|
+
},
|
|
50
|
+
rootValue: {
|
|
51
|
+
type: Object,
|
|
52
|
+
default: () => ({})
|
|
53
|
+
},
|
|
54
|
+
propName: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: ''
|
|
57
|
+
},
|
|
58
|
+
i18n: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: ''
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const instanceUid = getCurrentInstance().uid
|
|
65
|
+
const uid = useId()
|
|
66
|
+
|
|
67
|
+
const emit = defineEmits(['update:modelValue'])
|
|
68
|
+
|
|
69
|
+
const { error, definition, value } = toRefs(props)
|
|
70
|
+
|
|
71
|
+
const label = computed(() => props.i18n + (props.label || definition.value.label || props.name))
|
|
72
|
+
|
|
73
|
+
const viewClass = computed(() => [definition.value?.view?.class, props.viewClass, 'ml-1'])
|
|
74
|
+
const viewStyle = computed(() => [definition.value?.view?.style, props.viewStyle])
|
|
75
|
+
const fieldClass = computed(() => [definition.value?.view?.class, props.class])
|
|
76
|
+
const fieldStyle = computed(() => [definition.value?.view?.style, props.style])
|
|
77
|
+
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<style scoped>
|
|
81
|
+
|
|
82
|
+
</style>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<pre>{{ JSON.stringify(value, null, 2) }}</pre>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup>
|
|
8
|
+
import AutoViewField from "./AutoViewField.vue"
|
|
9
|
+
|
|
10
|
+
import { computed, inject, getCurrentInstance, toRefs } from 'vue'
|
|
11
|
+
|
|
12
|
+
const props = defineProps({
|
|
13
|
+
value: {},
|
|
14
|
+
definition: {
|
|
15
|
+
type: Object
|
|
16
|
+
},
|
|
17
|
+
rootValue: {
|
|
18
|
+
type: Object,
|
|
19
|
+
default: () => ({})
|
|
20
|
+
},
|
|
21
|
+
propName: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: ''
|
|
24
|
+
},
|
|
25
|
+
class: {},
|
|
26
|
+
style: {},
|
|
27
|
+
i18n: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: ''
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const { value, definition, propName } = toRefs(props)
|
|
34
|
+
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<style scoped>
|
|
38
|
+
|
|
39
|
+
</style>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="definition" class="grid formgrid p-fluid mt-2 mb-2">
|
|
3
|
+
<AutoViewField v-for="property in propertiesList" :key="property"
|
|
4
|
+
:value="value?.[property]"
|
|
5
|
+
:definition="definition.properties[property]"
|
|
6
|
+
:label="property"
|
|
7
|
+
:name="property"
|
|
8
|
+
:rootValue="props.rootValue" :propName="(propName ? propName + '.' : '') + property"
|
|
9
|
+
:i18n="i18n"
|
|
10
|
+
class="col-12" />
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup>
|
|
15
|
+
import AutoViewField from "./AutoViewField.vue"
|
|
16
|
+
|
|
17
|
+
import { computed, inject, getCurrentInstance, toRefs } from 'vue'
|
|
18
|
+
|
|
19
|
+
const props = defineProps({
|
|
20
|
+
value: {},
|
|
21
|
+
definition: {
|
|
22
|
+
type: Object
|
|
23
|
+
},
|
|
24
|
+
rootValue: {
|
|
25
|
+
type: Object,
|
|
26
|
+
default: () => ({})
|
|
27
|
+
},
|
|
28
|
+
propName: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: ''
|
|
31
|
+
},
|
|
32
|
+
i18n: {
|
|
33
|
+
type: String,
|
|
34
|
+
default: ''
|
|
35
|
+
},
|
|
36
|
+
visibleProperties: {
|
|
37
|
+
type: Array,
|
|
38
|
+
items: {
|
|
39
|
+
type: String
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const { value, definition, propName, visibleProperties } = toRefs(props)
|
|
45
|
+
|
|
46
|
+
const propertiesList = computed(() =>
|
|
47
|
+
visibleProperties.value ??
|
|
48
|
+
props.definition.visibleProperties ??
|
|
49
|
+
(definition.value.properties
|
|
50
|
+
? Object.keys(definition.value.properties).filter(key => props.definition.properties[key])
|
|
51
|
+
: [])
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<style scoped>
|
|
57
|
+
|
|
58
|
+
</style>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
{{ value }}
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup>
|
|
8
|
+
|
|
9
|
+
import { computed, inject, getCurrentInstance, toRefs } from 'vue'
|
|
10
|
+
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
value: {},
|
|
13
|
+
definition: {
|
|
14
|
+
type: Object
|
|
15
|
+
},
|
|
16
|
+
rootValue: {
|
|
17
|
+
type: Object,
|
|
18
|
+
default: () => ({})
|
|
19
|
+
},
|
|
20
|
+
propName: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: ''
|
|
23
|
+
},
|
|
24
|
+
i18n: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: ''
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const { value, definition, propName } = toRefs(props)
|
|
31
|
+
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<style scoped>
|
|
35
|
+
|
|
36
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { provideComponent } from '@live-change/vue3-components'
|
|
2
|
+
import { defineAsyncComponent } from 'vue'
|
|
3
|
+
|
|
4
|
+
export default function provideAutoViewComponents() {
|
|
5
|
+
provideComponent({
|
|
6
|
+
name: 'AutoView',
|
|
7
|
+
type: 'Object'
|
|
8
|
+
}, defineAsyncComponent(() => import('./ObjectView.vue')))
|
|
9
|
+
|
|
10
|
+
provideComponent({
|
|
11
|
+
name: 'AutoView',
|
|
12
|
+
type: 'String'
|
|
13
|
+
}, defineAsyncComponent(() => import('./StringView.vue')))
|
|
14
|
+
}
|
|
@@ -77,7 +77,11 @@ export default function editorData(options) {
|
|
|
77
77
|
|
|
78
78
|
const updateAction = api.actions[serviceName][crudMethods.update]
|
|
79
79
|
const createOrUpdateAction = api.actions[serviceName][crudMethods.createOrUpdate]
|
|
80
|
+
if(!updateAction && !createOrUpdateAction)
|
|
81
|
+
throw new Error('update or createOrUpdate action must be defined in model or options')
|
|
80
82
|
const createAction = api.actions[serviceName][crudMethods.create]
|
|
83
|
+
if(isNew && !createAction && !createOrUpdateAction)
|
|
84
|
+
throw new Error('create action must be defined in model or options')
|
|
81
85
|
const createOrUpdateDraftAction = draft && api.actions.draft.setOrUpdateMyDraft
|
|
82
86
|
const removeDraftAction = draft && api.actions.draft.resetMyDraft
|
|
83
87
|
|
|
@@ -184,6 +188,7 @@ export default function editorData(options) {
|
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
return {
|
|
191
|
+
identifiers,
|
|
187
192
|
value: synchronizedData.value,
|
|
188
193
|
changed,
|
|
189
194
|
save,
|
|
@@ -228,6 +233,7 @@ export default function editorData(options) {
|
|
|
228
233
|
}
|
|
229
234
|
|
|
230
235
|
return {
|
|
236
|
+
identifiers,
|
|
231
237
|
value: synchronizedData.value,
|
|
232
238
|
changed: synchronizedData.changed,
|
|
233
239
|
save: synchronizedData.save,
|
package/front/src/pages/List.vue
CHANGED
package/front/src/pages/View.vue
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="w-full lg:w-8 md:w-11">
|
|
3
|
-
<div class="surface-card p-3 shadow-1 border-round">
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
<ModelView :service="serviceName" :model="modelName" :identifiers="identifiersObject" />
|
|
6
5
|
|
|
7
|
-
</div>
|
|
8
6
|
</div>
|
|
9
7
|
</template>
|
|
10
8
|
|
package/index.js
CHANGED
|
@@ -9,7 +9,20 @@ export { inputConfig }
|
|
|
9
9
|
|
|
10
10
|
import editorData from './front/src/logic/editorData.js'
|
|
11
11
|
export { editorData }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
import AutoView from './front/src/components/view/AutoView.vue'
|
|
15
|
+
import AutoViewField from './front/src/components/view/AutoViewField.vue'
|
|
16
|
+
import DefaultFieldView from './front/src/components/view/DefaultFieldView.vue'
|
|
17
|
+
import JsonView from './front/src/components/view/JsonView.vue'
|
|
18
|
+
import ObjectView from './front/src/components/view/ObjectView.vue'
|
|
19
|
+
export { AutoView, AutoViewField, DefaultFieldView, JsonView, ObjectView }
|
|
20
|
+
|
|
21
|
+
import provideAutoViewComponents from './front/src/components/view/provideAutoViewComponents.js'
|
|
22
|
+
export { provideAutoViewComponents }
|
|
23
|
+
|
|
12
24
|
import viewData from './front/src/logic/viewData.js'
|
|
25
|
+
export { viewData }
|
|
13
26
|
|
|
14
27
|
export * from './front/src/logic/relations.js'
|
|
15
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/frontend-auto-form",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.14",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"memDev": "node server/start.js memDev --enableSessions --initScript ./init.js --dbAccess",
|
|
6
6
|
"localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@fortawesome/fontawesome-free": "^6.5.2",
|
|
25
|
-
"@live-change/cli": "^0.9.
|
|
26
|
-
"@live-change/dao": "^0.9.
|
|
27
|
-
"@live-change/dao-vue3": "^0.9.
|
|
28
|
-
"@live-change/dao-websocket": "^0.9.
|
|
29
|
-
"@live-change/framework": "^0.9.
|
|
30
|
-
"@live-change/image-frontend": "^0.9.
|
|
31
|
-
"@live-change/image-service": "^0.9.
|
|
32
|
-
"@live-change/session-service": "^0.9.
|
|
33
|
-
"@live-change/vue3-components": "^0.9.
|
|
34
|
-
"@live-change/vue3-ssr": "^0.9.
|
|
25
|
+
"@live-change/cli": "^0.9.14",
|
|
26
|
+
"@live-change/dao": "^0.9.14",
|
|
27
|
+
"@live-change/dao-vue3": "^0.9.14",
|
|
28
|
+
"@live-change/dao-websocket": "^0.9.14",
|
|
29
|
+
"@live-change/framework": "^0.9.14",
|
|
30
|
+
"@live-change/image-frontend": "^0.9.14",
|
|
31
|
+
"@live-change/image-service": "^0.9.14",
|
|
32
|
+
"@live-change/session-service": "^0.9.14",
|
|
33
|
+
"@live-change/vue3-components": "^0.9.14",
|
|
34
|
+
"@live-change/vue3-ssr": "^0.9.14",
|
|
35
35
|
"@vueuse/core": "^10.11.0",
|
|
36
36
|
"codeceptjs-assert": "^0.0.5",
|
|
37
37
|
"compression": "^1.7.4",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vue3-scroll-border": "0.1.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@live-change/codeceptjs-helper": "^0.9.
|
|
55
|
+
"@live-change/codeceptjs-helper": "^0.9.14",
|
|
56
56
|
"codeceptjs": "^3.6.5",
|
|
57
57
|
"generate-password": "1.7.1",
|
|
58
58
|
"playwright": "1.48.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"author": "Michał Łaszczewski <michal@laszczewski.pl>",
|
|
64
64
|
"license": "ISC",
|
|
65
65
|
"description": "",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "5d0f137a1a16f892868719d919f4a76584fa879f"
|
|
67
67
|
}
|