1
1
<template >
2
- <KModalEditor
3
- id =" layer-editor"
4
- :ref =" onEditorCreated"
5
- service =" catalog"
6
- :objectId =" layerId"
7
- @applied =" onLayerEdited"
2
+ <KForm
3
+ ref =" formRef"
4
+ :values =" layer"
5
+ :schema =" getFormSchema()"
8
6
/>
9
7
</template >
8
+ <script setup>
9
+ import { ref } from ' vue'
10
10
11
- <script >
12
- import config from ' config'
13
- import { KModalEditor } from ' ../../../core/client/components'
11
+ // Props
12
+ const props = defineProps ({
13
+ layer: {
14
+ type: Object ,
15
+ default : () => null
16
+ }
17
+ })
14
18
15
- export default {
16
- name: ' k-layer-editor' ,
17
- inject: [' kActivity' ],
18
- components: {
19
- KModalEditor
20
- },
21
- props: {
22
- layerId: {
23
- type: String ,
24
- required: true
25
- }
26
- },
27
- methods: {
28
- onEditorCreated (ref ) {
29
- this .editor = ref
30
- },
31
- onLayerEdited (updatedLayer ) {
32
- // Actual layer update should be triggerred by real-time event
33
- // but as we might not always use sockets we should perform it explicitely in this case
34
- if (config .transport !== ' websocket' ) {
35
- if (this .layer .name !== updatedLayer .name ) {
36
- this .kActivity .renameLayer (this .layer .name , updatedLayer .name )
37
- Object .assign (this .layer , updatedLayer)
19
+ // Data
20
+ const formRef = ref (null )
21
+
22
+ // Functions
23
+ function getFormSchema () {
24
+ return {
25
+ $schema: " http://json-schema.org/draft-07/schema#" ,
26
+ $id: " http://www.kalisio.xyz/schemas/catalog.update.json#" ,
27
+ title: " schemas.OBJECT_NAME" ,
28
+ description: " Layer edition schema" ,
29
+ type: " object" ,
30
+ properties: {
31
+ name: {
32
+ type: " string" ,
33
+ maxLength: 128 ,
34
+ minLength: 3 ,
35
+ field: {
36
+ component: " form/KTextField" ,
37
+ label: " schemas.CATALOG_NAME_FIELD_LABEL"
38
+ }
39
+ },
40
+ description: {
41
+ type: " string" ,
42
+ maxLength: 256 ,
43
+ field: {
44
+ component: " form/KTextField" ,
45
+ label: " schemas.CATALOG_DESCRIPTION_FIELD_LABEL"
46
+ }
47
+ },
48
+ featureId: {
49
+ type: " string" ,
50
+ maxLength: 256 ,
51
+ field: {
52
+ component: " form/KTextField" ,
53
+ label: " schemas.CATALOG_FEATURE_ID_FIELD_LABEL"
54
+ }
55
+ },
56
+ featureLabel: {
57
+ type: " string" ,
58
+ maxLength: 256 ,
59
+ field: {
60
+ component: " form/KTextField" ,
61
+ label: " schemas.CATALOG_FEATURE_LABEL_FIELD_LABEL"
38
62
}
39
63
}
40
- }
64
+ },
65
+ required: [" name" ]
41
66
}
42
67
}
43
- </script >
68
+ function apply () {
69
+ const { isValid , values } = formRef .value .validate ()
70
+ if (! isValid) return false
71
+ // Do stuff
72
+ }
73
+
74
+ // Expose
75
+ defineExpose ({
76
+ apply
77
+ })
78
+ </script >
0 commit comments