forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpane.js
More file actions
226 lines (199 loc) · 6.75 KB
/
pane.js
File metadata and controls
226 lines (199 loc) · 6.75 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* Form building/editing Pane
**
*/
import * as UI from 'solid-ui'
import * as $rdf from 'rdflib'
const ns = UI.ns
export default {
// noun_170702.svg' builder noun_122196.svg form
icon: UI.icons.iconBase + 'noun_170702.svg',
name: 'ui',
audience: [ns.solid('PowerUser')],
// Does the subject deserve this pane?
label: function (subject, context) {
const ns = UI.ns
const kb = context.session.store
const t = kb.findTypeURIs(subject)
if (t[ns.rdfs('Class').uri]) return 'creation forms'
// if (t[ns.rdf('Property').uri]) return "user interface";
if (t[ns.ui('Form').uri]) return 'edit form'
return null // No under other circumstances (while testing at least!)
},
render: function (subject, context) {
const dom = context.dom
const kb = context.session.store
const ns = UI.ns
const box = dom.createElement('div')
box.setAttribute('class', 'formPane') // Share styles
const label = UI.utils.label(subject)
const mention = function complain (message, style) {
const pre = dom.createElement('p')
pre.setAttribute('style', style || 'color: grey; background-color: white')
box.appendChild(pre).textContent = message
return pre
}
const complain = function complain (message, style) {
mention(message, 'style', style || 'color: grey; background-color: #fdd')
}
const complainIfBad = function (ok, body) {
if (ok) {
// setModifiedDate(store, kb, store);
// rerender(box); // Deleted forms at the moment
} else complain('Sorry, failed to save your change:\n' + body)
}
// //////////////////////////////////////////////////////////////////////////////
const t = kb.findTypeURIs(subject)
let store = null
let docuri
if (subject.uri) {
docuri = $rdf.Util.uri.docpart(subject.uri)
if (subject.uri !== docuri && kb.updater.editable(docuri)) {
store = kb.sym($rdf.Util.uri.docpart(subject.uri))
} // an editable ontology with hash
}
if (!store) store = kb.any(kb.sym(docuri), ns.link('annotationStore'))
if (!store) store = UI.widgets.defaultAnnotationStore(subject)
if (!store) {
store = kb.sym(
'https://formsregistry.solid.community/public/formRegistry/'
) // fallback
}
// if (!store) store = kb.sym('http://tabulator.org/wiki/ontologyAnnotation/common') // fallback
// A fallback which gives a different store page for each ontology would be good @@
let pred
if (t[ns.rdfs('Class').uri]) {
// Stuff we can do before we load the store
}
const wait = mention('(Loading data from: ' + store + ')')
kb.fetcher.nowOrWhenFetched(store.uri, subject, function (ok, body) {
if (!ok) {
complain('Cannot load store ' + store + ' :' + body)
return
}
box.removeChild(wait)
// Render a Class -- the forms associated with it
if (t[ns.rdfs('Class').uri]) {
// For each creation form, allow one to create a new object with it, and also to edit the form.
const displayFormsForRelation = function displayFormsForRelation (
pred,
allowCreation
) {
const sts = kb.statementsMatching(subject, pred)
const outliner = context.getOutliner(dom)
if (sts.length) {
for (let i = 0; i < sts.length; i++) {
outliner.appendPropertyTRs(box, [sts[i]])
const form = sts[i].object
const cell = dom.createElement('td')
box.lastChild.appendChild(cell)
if (allowCreation) {
cell.appendChild(
UI.widgets.newButton(
dom,
kb,
null,
null,
subject,
form,
store,
function (ok, body) {
if (ok) {
// dom.outlineManager.GotoSubject(newThing@@, true, undefined, true, undefined);
// rerender(box); // Deleted forms at the moment
} else {
complain('Sorry, failed to save your change:\n' + body)
}
}
)
)
}
let formdef = kb.statementsMatching(form, ns.rdf('type'))
if (!formdef.length) formdef = kb.statementsMatching(form)
if (!formdef.length) complain('No data about form')
else {
UI.widgets.editFormButton(
dom,
box,
form,
formdef[0].why,
complainIfBad
)
}
}
box.appendChild(dom.createElement('hr'))
} else {
mention(
'There are currently no known forms to make a ' + label + '.'
)
}
}
pred = ns.ui('creationForm')
box.appendChild(dom.createElement('h2')).textContent = UI.utils.label(
pred
)
mention(
'Creation forms allow you to add information about a new thing,' +
' in this case a new ' +
label +
'.'
)
displayFormsForRelation(pred, true)
box.appendChild(dom.createElement('hr'))
mention('You can make a new creation form:')
box.appendChild(
UI.widgets.newButton(
dom,
kb,
subject,
pred,
ns.ui('Form'),
null,
store,
complainIfBad
)
)
box.appendChild(dom.createElement('hr'))
pred = ns.ui('annotationForm')
box.appendChild(dom.createElement('h2')).textContent = UI.utils.label(
pred
)
mention(
'Annotaion forms allow you to add extra information about a ,' +
label +
' we already know about.'
)
displayFormsForRelation(pred, false)
box.appendChild(dom.createElement('hr'))
mention('You can make a new annotation form:')
box.appendChild(
UI.widgets.newButton(
dom,
kb,
subject,
pred,
ns.ui('Form'),
null,
store,
complainIfBad
)
)
mention('(Storing new forms in: ' + store + ')')
// Render a Form
} else if (t[ns.ui('Form').uri]) {
UI.widgets.appendForm(
dom,
box,
kb,
subject,
ns.ui('FormForm'),
store,
complainIfBad
)
} else {
complain('ui/pane internal error -- Eh?')
}
}) // end: when store loded
return box
}
}
// ends