-
Notifications
You must be signed in to change notification settings - Fork 0
/
RdfResource.js
124 lines (104 loc) · 2.99 KB
/
RdfResource.js
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
import { html } from 'lit'
import RdfData from './src/RdfData.js'
import style from './src/style.js'
import termElement from './src/termElement.js'
import toTree from './src/toTree.js'
class RdfResource extends RdfData {
static get properties () {
return {
resource: {
type: Object
},
scrollToSubject: {
type: Boolean,
default: false
}
}
}
static get styles () {
return [style()]
}
constructor () {
super()
this.subjects = null
}
requestUpdate (name, oldValue, options) {
if (name === 'resource') {
this.subjects = toTree({ ...this.resource, processList: true })
}
return super.requestUpdate(name, oldValue, options)
}
render () {
if (!this.subjects) {
return html`<div></div>`
}
return this.subjects.map(subject => this.renderSubject({ subject }))
}
renderObjects ({ predicate, subject }) {
if (predicate.type === 'single') {
const object = predicate.objects[0]
return termElement({
click: () => this.clickObject({ object, predicate, subject }),
label: object.label,
term: object.term
})
}
if (predicate.type === 'orderedList') {
if (predicate.objects.length === 0) {
return html`<p class="fst-italic">empty list</p>`
}
const links = predicate.objects.map(object => {
const link = termElement({
click: () => this.clickObject({ object, predicate, subject }),
label: object.label,
term: object.term
})
return html`<li>${link}</li>`
})
return html`<ol>${links}</ol>`
}
if (predicate.type === 'list') {
const links = predicate.objects.map(object => {
const link = termElement({
click: () => this.clickObject({ object, predicate, subject }),
label: object.label,
term: object.term
})
return html`<li>${link}</li>`
})
return html`<ul>${links}</ul>`
}
}
renderPredicate ({ predicate, subject }) {
return html`
<tr>
<td>
${termElement({ term: predicate.term, click: () => this.clickPredicate({ predicate, subject }) })}
</td>
<td>
${this.renderObjects({ predicate, subject })}
</td>
</tr>
`
}
renderSubject ({ subject }) {
return html`
<table data-subject="${subject.term.toCanonical()}" class="table table-bordered" style="table-layout: fixed;">
<thead>
<tr>
<th>
${termElement({ term: subject.term, label: subject.label, click: () => this.clickSubject({ subject }) })}
</th>
<th>
${subject.types.map(type => termElement({ term: type, click: () => this.clickType({ subject, type }) }))}
</th>
</tr>
</thead>
<tbody>
${subject.predicates.map(predicate => this.renderPredicate({ predicate, subject }))}
</tbody>
</table>
`
}
}
export default RdfResource