|
2 | 2 | <v-autocomplete
|
3 | 3 | density="compact"
|
4 | 4 | variant="outlined"
|
5 |
| - label="(instances select editor)" |
| 5 | + label="select an item" |
6 | 6 | v-model="triple_object"
|
7 | 7 | :items="instanceItems"
|
8 | 8 | validate-on="lazy input"
|
9 | 9 | :rules="rules"
|
10 | 10 | item-value="value"
|
11 | 11 | item-text="title"
|
12 | 12 | return-object
|
| 13 | + ref="fieldRef" |
| 14 | + :id="inputId" |
13 | 15 | >
|
14 | 16 |
|
15 | 17 | <template v-slot:item="data">
|
16 |
| - <v-list-item @click="console.log('add new item')" v-if="data.item.props.isButton"> |
17 |
| - <template v-slot:prepend> |
18 |
| - <v-icon icon="item.icon">mdi-plus-box</v-icon> |
19 |
| - </template> |
20 |
| - <v-list-item-title>{{ data.item.title }}</v-list-item-title> |
21 |
| - </v-list-item> |
22 |
| - <v-list-item @click="selectItem(data.item)" v-else> |
23 |
| - <v-list-item-title>{{ data.item.title }}</v-list-item-title> |
24 |
| - <v-list-item-subtitle>{{ data.item.props.subtitle }}</v-list-item-subtitle> |
25 |
| - </v-list-item> |
| 18 | + <div v-if="data.item.props.isButton"> |
| 19 | + <v-list-item> |
| 20 | + <v-list-item-title> |
| 21 | + <v-menu location="end"> |
| 22 | + <template v-slot:activator="{ props }"> |
| 23 | + <v-btn variant="tonal" v-bind="props">{{ data.item.title }} <v-icon icon="item.icon">mdi-play</v-icon></v-btn> |
| 24 | + </template> |
| 25 | + |
| 26 | + <v-list> |
| 27 | + <v-list-item v-for="item in propClassList" @click="add_empty_node(item.value)"> |
| 28 | + <v-list-item-title>{{ item.title }}</v-list-item-title> |
| 29 | + <v-dialog activator="parent" max-width="700"> |
| 30 | + <template v-slot:default="{ isActive }"> |
| 31 | + <FormEditor :shape_iri="item.value"></FormEditor> |
| 32 | + </template> |
| 33 | + </v-dialog> |
| 34 | + </v-list-item> |
| 35 | + </v-list> |
| 36 | + </v-menu> |
| 37 | + |
| 38 | + </v-list-item-title> |
| 39 | + </v-list-item> |
| 40 | + </div> |
| 41 | + <div v-else> |
| 42 | + <v-list-item @click="selectItem(data.item)"> |
| 43 | + <v-list-item-title>{{ data.item.title }}</v-list-item-title> |
| 44 | + <v-list-item-subtitle>{{ data.item.props.subtitle }}</v-list-item-subtitle> |
| 45 | + </v-list-item> |
| 46 | + </div> |
26 | 47 | </template>
|
27 | 48 | </v-autocomplete>
|
| 49 | + |
| 50 | + |
| 51 | + |
28 | 52 | </template>
|
29 | 53 |
|
30 | 54 | <script setup>
|
|
33 | 57 | import rdf from 'rdf-ext'
|
34 | 58 | import {SHACL, RDF, RDFS, DLTHING, XSD} from '@/modules/namespaces'
|
35 | 59 | import { toCURIE } from '../modules/utils';
|
| 60 | + import { useRegisterRef } from '../composables/refregister'; |
| 61 | +
|
| 62 | +
|
36 | 63 |
|
37 | 64 | // ----- //
|
38 | 65 | // Props //
|
|
50 | 77 | // ---- //
|
51 | 78 |
|
52 | 79 | const formData = inject('formData');
|
| 80 | + const propertyGroups = inject('propertyGroups'); |
| 81 | + const nodeShapes = inject('nodeShapes'); |
53 | 82 | const graphData = inject('graphData');
|
| 83 | + const add_empty_node = inject('add_empty_node'); |
54 | 84 | const graphPrefixes = inject('graphPrefixes');
|
55 | 85 | const shapePrefixes = inject('shapePrefixes');
|
56 | 86 | const classPrefixes = inject('classPrefixes');
|
| 87 | + const allPrefixes = {...shapePrefixes, ...graphPrefixes, ...classPrefixes}; |
57 | 88 | const classData = inject('classData');
|
58 | 89 | const { rules } = useRules(props.property_shape)
|
59 | 90 | var propClass = ref(null)
|
60 |
| - const combinedQuads = reactive([]) |
61 | 91 | const instanceItems = reactive([])
|
62 |
| -
|
| 92 | + const inputId = `input-${Date.now()}`; |
| 93 | + const { fieldRef } = useRegisterRef(inputId, props); |
| 94 | + |
63 | 95 | // ------------------- //
|
64 | 96 | // Computed properties //
|
65 | 97 | // ------------------- //
|
|
85 | 117 | // ---
|
86 | 118 | // TODO: what should the correct default value be here?
|
87 | 119 | propClass.value = props.property_shape[SHACL.class.value] ?? false
|
88 |
| - let allprefixes = {...shapePrefixes, ...graphPrefixes, ...classPrefixes}; |
89 | 120 | // find nodes with predicate rdf:type and object being the property class
|
90 | 121 | var quads = getLiteralAndNamedNodes(
|
91 | 122 | graphData,
|
92 | 123 | rdf.namedNode(RDF.type),
|
93 | 124 | propClass.value,
|
94 |
| - allprefixes |
| 125 | + allPrefixes |
95 | 126 | )
|
96 | 127 | // then find nodes with predicate rdfs:subClassOf and object being the property class
|
97 | 128 | // TODO: here we are only using a named node for the object because this is how the
|
|
105 | 136 | var myArr = []
|
106 | 137 | Array.from(subClasses).forEach(quad => {
|
107 | 138 | const cl = quad.subject.value
|
108 |
| - myArr = myArr.concat(getLiteralAndNamedNodes(graphData, rdf.namedNode(RDF.type), cl, allprefixes)) |
| 139 | + myArr = myArr.concat(getLiteralAndNamedNodes(graphData, rdf.namedNode(RDF.type), cl, allPrefixes)) |
109 | 140 | });
|
110 | 141 | // Then combine all quad arrays
|
111 | 142 | const combinedQuads = quads.concat(myArr);
|
|
126 | 157 | {
|
127 | 158 | title: quad.subject.value + extra,
|
128 | 159 | value: quad.subject.value,
|
129 |
| - props: { subtitle: toCURIE(quad.object.value, allprefixes) }, |
| 160 | + props: { subtitle: toCURIE(quad.object.value, allPrefixes) }, |
130 | 161 | }
|
131 | 162 | )
|
132 | 163 | });
|
133 | 164 | })
|
134 | 165 |
|
| 166 | + const propClassList = computed(() => { |
| 167 | + var items = [] |
| 168 | + // first add main property class |
| 169 | + items.push( |
| 170 | + { |
| 171 | + title: toCURIE(propClass.value, allPrefixes), |
| 172 | + value: propClass.value |
| 173 | + } |
| 174 | + ) |
| 175 | + const subClasses = rdf.grapoi({ dataset: classData }) |
| 176 | + .hasOut(rdf.namedNode(RDFS.subClassOf.value), rdf.namedNode(propClass.value)) |
| 177 | + .quads(); |
| 178 | + |
| 179 | + Array.from(subClasses).forEach(quad => { |
| 180 | + items.push( |
| 181 | + { |
| 182 | + title: toCURIE(quad.subject.value, allPrefixes), |
| 183 | + value: quad.subject.value |
| 184 | + } |
| 185 | + ) |
| 186 | + }); |
| 187 | + return items |
| 188 | + }) |
| 189 | +
|
135 | 190 | // --------- //
|
136 | 191 | // Functions //
|
137 | 192 | // --------- //
|
|
152 | 207 |
|
153 | 208 | function selectItem(item) {
|
154 | 209 | triple_object.value = item.value;
|
| 210 | + fieldRef.value.blur(); |
155 | 211 | }
|
156 | 212 |
|
157 |
| -
|
158 | 213 | </script>
|
159 | 214 |
|
160 | 215 | <!-- Component matching logic -->
|
|
0 commit comments