-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyShapeEditor.vue
144 lines (126 loc) · 4.88 KB
/
PropertyShapeEditor.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
<template>
<v-row align="start" no-gutters>
<v-col cols="4">
<span>{{ nameOrCURIE(props.property_shape, shapePrefixes, SHACL) }}<span v-if="isRequired" style="color: red;"> *</span>:
<v-tooltip activator="parent" location="right" max-width="400px" max-height="400px">
{{ props.property_shape[SHACL.description.value] }}
</v-tooltip>
</span>
</v-col>
<v-col cols="8">
<v-row no-gutters v-for="(triple, triple_idx) in formData[props.node_uid].at(-1)[my_uid]" :key="props.node_uid + '-' + my_uid + '-' + triple_idx">
<v-col cols="9">
<component
v-model="formData[props.node_uid].at(-1)[my_uid][triple_idx]"
:is="matchedComponent"
:property_shape="props.property_shape"
:node_uid="props.node_uid"
:triple_uid="my_uid"
:triple_idx="triple_idx"
>
</component>
</v-col>
<v-col>
<!-- Remove button -->
<v-btn v-if="allowRemoveTriple(triple_idx)"
rounded="0"
elevation="1"
icon="mdi-delete-outline"
@click="remove_triple(props.node_uid, my_uid, triple_idx)"
density="comfortable"
></v-btn>
<!-- Add button -->
<v-btn v-if="allowAddTriple(triple_idx)"
rounded="0"
elevation="1"
icon="mdi-plus-circle-outline"
@click="add_empty_triple(props.node_uid, my_uid)"
density="comfortable"
></v-btn>
</v-col>
</v-row>
</v-col>
</v-row>
</template>
<script setup>
import { ref, onMounted, onBeforeMount, computed, inject, onBeforeUpdate} from 'vue'
import { SHACL } from '../modules/namespaces'
import { useRules } from '../composables/rules'
import { toCURIE, nameOrCURIE } from '../modules/utils';
// ----- //
// Props //
// ----- //
const props = defineProps({
property_shape: Object,
node_uid: String
})
// ---- //
// Data //
// ---- //
const my_uid = ref('');
const add_empty_triple = inject('add_empty_triple');
const remove_triple = inject('remove_triple');
const shapePrefixes = inject('shapePrefixes');
const editorMatchers = inject('editorMatchers');
const defaultEditor = inject('defaultEditor');
const formData = inject('formData');
const { isRequired } = useRules(props.property_shape)
// ----------------- //
// Lifecycle methods //
// ----------------- //
onMounted(() => {
add_empty_triple(props.node_uid, my_uid.value)
})
onBeforeMount(() => {
console.log("PropertyShapeEditor is about to be mounted")
my_uid.value = props.property_shape[SHACL.path.value]
})
onBeforeUpdate(() => {
console.log(`PropertyShapeEditor is about to be updated: ${my_uid.value}`)
})
// ------------------- //
// Computed properties //
// ------------------- //
const matchedComponent = computed(() => {
for (const key in editorMatchers) {
if (editorMatchers[key].match(props.property_shape)) {
return editorMatchers[key].component;
}
}
return defaultEditor;
});
// --------- //
// Functions //
// --------- //
function allowAddTriple(idx) {
// if there is no maxCount, allowMultiple = true
// if the maxCount is 1, allowMultiple = false
// if the maxCount > 1, allowMultiple = true
if (props.property_shape.hasOwnProperty(SHACL.maxCount)) {
if (props.property_shape[SHACL.maxCount] == 1) {
return false
} else if (props.property_shape[SHACL.maxCount] > 1
&& formData[props.node_uid].at(-1)[my_uid.value].length < props.property_shape[SHACL.maxCount]
&& formData[props.node_uid].at(-1)[my_uid.value].length == idx + 1
) {
return true
} else {
return false
}
} else {
if (formData[props.node_uid].at(-1)[my_uid.value].length == idx + 1) {
return true
} else {
return false
}
}
}
function allowRemoveTriple(idx) {
if (formData[props.node_uid].at(-1)[my_uid.value].length > 1) {
return true
}
return false
}
</script>