-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainForm.vue
159 lines (141 loc) · 4.84 KB
/
MainForm.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
<v-container fluid v-show="page_ready">
<v-row align="start" no-gutters>
<v-col>
<h3>Forms</h3>
<v-select v-if="prefixes_ready" :items="nodeShapeNamesArray" item-title="name" label="Select" density="compact">
<template v-slot:item="{ props, item }">
<v-list-item v-bind="props" :title="toCURIE(nodeShapeNames[item.raw], shapePrefixes)" @click="selectIRI(nodeShapeNames[item.raw])"></v-list-item>
</template>
</v-select>
</v-col>
<v-col cols="6"><v-sheet class="pa-2 ma-2"></v-sheet></v-col>
</v-row>
<v-row align="start" style="flex-wrap: nowrap" no-gutters>
<!-- Display selected form -->
<v-col cols="6">
<span v-if="selectedIRI && prefixes_ready">
<h3>Selected form</h3>
<FormEditor :key="selectedIRI" :shape_iri="selectedIRI"></FormEditor>
</span>
</v-col>
<!-- Display entered form data -->
<v-col class="ml-6">
<span v-if="selectedIRI && prefixes_ready">
<h3>Form data</h3>
<v-sheet class="pa-4" border rounded elevation="2">
<code>
<span v-for="(value, key, index) in shapePrefixes">
@prefix {{ key }}: <{{ value }}> .<br>
</span>
<br>
<span v-for="(item, index) in flatFormData">
_b{{ index }} <br>
a {{ toCURIE(item["node_iri"], shapePrefixes) }}
<!-- value is an array of objects -->
<span v-for="(prop_vals, prop_key, prop_idx) in item['triples']">
<span v-for="pval in prop_vals">
<span v-if="pval">
; <br>
{{ toCURIE(prop_key, shapePrefixes) }} "{{ pval }}"
</span>
</span>
</span> .
<br><br>
</span>
</code>
</v-sheet>
</span>
</v-col>
</v-row>
</v-container>
</template>
<script setup>
import { ref, onMounted, onBeforeMount, provide, inject, computed} from 'vue'
import { useFormData } from '@/composables/formdata';
import { useShapeData } from '@/composables/shapedata';
import { toCURIE } from '@/modules/utils';
import editorMatchers from '@/modules/editors';
import defaultEditor from '@/components/UnknownEditor.vue';
// ---- //
// Data //
// ---- //
var selectedIRI = ref(null)
var selectedShape = ref(null)
var current_instance = ref(null)
var tab = ref(null)
const { formData, add_empty_triple, add_empty_node, remove_triple, save_node } = useFormData()
const shape_file_url = new URL("@/assets/shapesgraph.ttl", import.meta.url).href
const {
shapesDataset,
nodeShapes,
propertyGroups,
nodeShapeNamesArray,
shapePrefixes,
prefixArray,
prefixes_ready,
nodeShapeIRIs,
nodeShapeNames,
page_ready
} = useShapeData(shape_file_url)
const defaultPropertyGroup = {}
defaultPropertyGroup.key = "https://concepts.datalad.org/DefaultPropertyGroup"
defaultPropertyGroup.value = {
"http://www.w3.org/2000/01/rdf-schema#comment": "",
"http://www.w3.org/2000/01/rdf-schema#label": "Default Properties",
"http://www.w3.org/ns/shacl#order": 100,
}
provide('defaultPropertyGroup', defaultPropertyGroup)
provide('formData', formData)
provide('add_empty_triple', add_empty_triple)
provide('add_empty_node', add_empty_node)
provide('remove_triple', remove_triple)
provide('shapePrefixes', shapePrefixes)
provide('editorMatchers', editorMatchers)
provide('defaultEditor', defaultEditor)
provide('nodeShapes', nodeShapes)
provide('propertyGroups', propertyGroups)
provide('shapesDataset', shapesDataset)
provide('prefixArray', prefixArray)
provide('nodeShapeIRIs', nodeShapeIRIs)
// ----------------- //
// Lifecycle methods //
// ----------------- //
onBeforeMount(() => {
console.log(`the root component is about to be mounted.`)
})
onMounted(() => {
console.log(`the root component is now mounted.`)
})
// ------------------- //
// Computed properties //
// ------------------- //
const flatFormData = computed(() => {
var ffdata = []
for (const [key, value] of Object.entries(formData)) {
for (const obj of value) {
ffdata.push(
{
"node_iri": key,
"triples": obj
}
)
}
}
return ffdata
});
// --------- //
// Functions //
// --------- //
function selectIRI(IRI) {
selectedIRI.value = IRI
selectedShape.value = nodeShapes.value[IRI]
add_empty_node(IRI)
}
function saveForm() {
add_empty_node(selectedIRI.value)
// save_node()
}
function resetForm(IRI) {
}
</script>