/
ConceptTree.vue
187 lines (182 loc) · 4.63 KB
/
ConceptTree.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<template>
<div
class="conceptTree" >
<!-- Minimizer allows the component to get minimized -->
<minimizer text="Concept Tree" />
<!-- Show top concepts -->
<div
ref="conceptTreeItems"
class="conceptTreeItems scrollable" >
<concept-tree-item
v-for="(concept, index) in tree"
:key="index"
:concept="concept"
:depth="0"
:index="index"
:is-left="isLeft" />
</div>
<div
v-if="tree.length == 0 && !loading"
class="fillAndCenter fontWeight-heavy" >
No Concept Tree Available
</div>
<!-- Full screen loading indicator -->
<loading-indicator-full v-if="loading" />
</div>
</template>
<script>
import LoadingIndicatorFull from "./LoadingIndicatorFull"
import ConceptTreeItem from "./ConceptTreeItem"
import Minimizer from "./Minimizer"
import _ from "lodash"
import { scroller } from "vue-scrollto/src/scrollTo"
/**
* Component that represents a (navigatable) concept tree.
*/
export default {
name: "ConceptTree",
components: {
LoadingIndicatorFull, ConceptTreeItem, Minimizer
},
props: {
/**
* Tells the component on which side of the application it is.
*/
isLeft: {
type: Boolean,
default: true
}
},
data () {
return {
tree: [],
loading: false,
currentSelectedConcept: null,
shouldScroll: true,
scrollTo: scroller(),
}
},
computed: {
schemeSelected() {
return this.selected.scheme[this.isLeft]
},
conceptSelected() {
return this.selected.concept[this.isLeft]
}
},
watch: {
/**
* Resets the tree when new vocabulary is chosen.
*/
schemeSelected: function(newValue, oldValue) {
if (oldValue != newValue) {
this.reset()
}
},
conceptSelected: {
handler() {
// TODO: Check
let concept = this.conceptSelected
if (concept != this.currentSelectedConcept) {
this.currentSelectedConcept = concept
this.shouldScroll = true
}
if (this.$jskos.isConcept(concept)) {
// Load concept's narrower
if (!concept.narrower || concept.narrower.includes(null)) {
this.loadNarrower({ object: concept })
}
// Check if concept is fully loaded
if (concept.ancestors && !concept.ancestors.includes(null)) {
let fullyLoaded = true
for (let ancestor of concept.ancestors) {
if (!ancestor.narrower || ancestor.narrower.includes(null)) {
fullyLoaded = false
}
}
if (fullyLoaded && this.shouldScroll) {
this.shouldScroll = false
// Open ancestors
for (let ancestor of this.conceptSelected.ancestors) {
this.open(ancestor, this.isLeft, true)
}
_.delay(() => {
// Don't scroll if concept changed in the meantime
if (this.shouldScroll) return
let el = document.querySelectorAll(`[data-uri='${concept.uri}']`)[0]
// Scroll element
var options = {
container: this.$refs.conceptTreeItems,
easing: "ease-in",
offset: -50,
cancelable: true,
x: false,
y: true
}
if (el) this.scrollTo(el, 200, options)
this.loading = false
}, 100)
} else if (!fullyLoaded) {
this.loading = true
}
} else {
this.loading = true
}
}
},
deep: true
}
},
created() {
// Reset tree if scheme is already chosen
if (this.schemeSelected) {
this.reset()
}
},
methods: {
/**
* Resets the concept tree and loads top concepts for new vocabulary.
*/
reset: function() {
this.tree = []
this.loading = true
this.loadTop({ scheme: this.schemeSelected }).then(() => {
this.tree = _.get(this, "schemeSelected.TOPCONCEPTS", [])
this.loading = false
})
}
}
}
</script>
<style lang="less" scoped>
@import "../style/main.less";
.conceptTree {
position: relative;
overflow-y: hidden;
}
.conceptTreeNotLoading {
padding: 2px 8px 2px 8px;
}
.concept {
list-style-type: none;
padding: 0;
margin-bottom: 10px;
margin-top: 10px;
line-height: 1.2;
}
.concept > li {
margin-left: 20px;
margin-top: 10px;
margin-bottom: 5px;
}
.conceptTreeItems {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.conceptTreeItems {
padding: 2px 0px;
}
</style>