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
187 lines (154 loc) · 5.98 KB
/
pane.js
File metadata and controls
187 lines (154 loc) · 5.98 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
/*
** Pane for running existing forms for any object
**
*/
var UI = require('solid-ui')
module.exports = {
icon: UI.icons.iconBase + 'noun_122196.svg',
name: 'form',
// Does the subject deserve this pane?
label: function (subject) {
var n = UI.widgets.formsFor(subject).length
UI.log.debug('Form pane: forms for ' + subject + ': ' + n)
if (!n) return null
return '' + n + ' forms'
},
render: function (subject, dom) {
var kb = UI.store
var ns = UI.ns
var mention = function complain (message, style) {
var pre = dom.createElement('p')
pre.setAttribute('style', style || 'color: grey; background-color: white')
box.appendChild(pre).textContent = message
return pre
}
var complain = function complain (message, style) {
mention(message, 'style', style || 'color: grey; background-color: #fdd;')
}
var 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)
}
// The question of where to store this data about subject
// This in general needs a whole lot more thought
// and it connects to the discoverbility through links
// var t = kb.findTypeURIs(subject)
var me = UI.authn.currentUser()
var box = dom.createElement('div')
box.setAttribute('class', 'formPane')
if (!me) {
mention('You are not logged in. If you log in and have ' +
'workspaces then you would be able to select workspace in which ' +
'to put this new information')
} else {
var ws = kb.each(me, ns.ui('workspace'))
if (ws.length === 0) {
mention('You don\'t seem to have any workspaces defined. ' +
'A workspace is a place on the web (http://..) or in ' +
'the file system (file:///) to store application data.\n')
} else {
// @@
}
}
// Render forms using a given store
var renderFormsFor = function (store, subject) {
kb.fetcher.nowOrWhenFetched(store.uri, subject, function (ok, body) {
if (!ok) return complain('Cannot load store ' + store.uri + ': ' + body)
// Render the forms
var forms = UI.widgets.formsFor(subject)
// complain('Form for editing this form:');
for (var i = 0; i < forms.length; i++) {
var form = forms[i]
var heading = dom.createElement('h4')
box.appendChild(heading)
if (form.uri) {
var formStore = $rdf.Util.uri.document(form)
if (formStore.uri !== form.uri) { // The form is a hash-type URI
var e = box.appendChild(UI.widgets.editFormButton(
dom, box, form, formStore, complainIfBad))
e.setAttribute('style', 'float: right;')
}
}
var anchor = dom.createElement('a')
anchor.setAttribute('href', form.uri)
heading.appendChild(anchor)
anchor.textContent = UI.utils.label(form, true)
/* Keep tis as a reminder to let a New one have its URI given by user
mention("Where will this information be stored?")
var ele = dom.createElement('input');
box.appendChild(ele);
ele.setAttribute('type', 'text');
ele.setAttribute('size', '72');
ele.setAttribute('maxlength', '1024');
ele.setAttribute('style', 'font-size: 80%; color:#222;');
ele.value = store.uri
*/
UI.widgets.appendForm(dom, box, {}, subject, form, store, complainIfBad)
}
}) // end: when store loded
} // renderFormsFor
// Figure out what store
// Which places are editable and have stuff about the subject?
var store = null
// 1. The document URI of the subject itself
var docuri = $rdf.Util.uri.docpart(subject.uri)
if (subject.uri !== docuri && kb.updater.editable(docuri, kb)) {
store = subject.doc()
} // an editable data file with hash
store = store || kb.any(kb.sym(docuri), ns.link('annotationStore'))
// 2. where stuff is already stored
if (!store) {
var docs = {}
var docList = []
kb.statementsMatching(subject).map(function (st) { docs[st.why.uri] = 1 })
kb.statementsMatching(undefined, undefined, subject).map(function (st) { docs[st.why.uri] = 2 })
for (var d in docs) docList.push(docs[d], d)
docList.sort()
for (var i = 0; i < docList.length; i++) {
var uri = docList[i][1]
if (uri && kb.updater.editable(uri)) {
store = kb.sym(uri)
break
}
}
}
// 3. In a workspace store
var followeach = function (kb, subject, path) {
if (path.length === 0) return [ subject ]
var oo = kb.each(subject, path[0])
var res = []
for (var i = 0; i < oo.length; i++) {
res = res.concat(followeach(kb, oo[i], path.slice(1)))
}
return res
}
var date = '2014' // @@@@@@@@@@@@ pass as parameter
if (store) {
// mention("@@ Ok, we have a store <" + store.uri + ">.");
renderFormsFor(store, subject)
} else {
complain('No suitable store is known, to edit <' + subject.uri + '>.')
var foobarbaz = UI.authn.selectWorkspace(dom,
function (ws) {
mention('Workspace selected OK: ' + ws)
var activities = kb.each(undefined, ns.space('workspace'), ws)
for (var j = 0; j < activities.length; i++) {
var act = activities[j]
var s = kb.any(ws, ns.space('store'))
var start = kb.any(ws, ns.cal('dtstart')).value()
var end = kb.any(ws, ns.cal('dtend')).value()
if (s && start && end && start <= date && end > date) {
renderFormsFor(s, subject)
break
} else {
complain('Note no suitable annotation store in activity: ' + act)
}
}
})
box.appendChild(foobarbaz)
}
return box
}
}