-
Notifications
You must be signed in to change notification settings - Fork 42
/
internalPane.js
161 lines (148 loc) · 5.89 KB
/
internalPane.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
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
/* Internal Pane
**
** This outline pane contains the properties which are
** internal to the user's interaction with the web, and are not normally displayed
*/
/* global alert confirm */
const UI = require('solid-ui')
const panes = require('pane-registry')
const ns = UI.ns
module.exports = {
icon: UI.icons.originalIconBase + 'tango/22-emblem-system.png',
name: 'internal',
label: function (subject) {
// if (subject.uri)
return 'under the hood' // There is often a URI even of no statements
},
render: function (subject, dom) {
var $r = UI.rdf
var kb = UI.store
subject = kb.canon(subject)
var types = kb.findTypeURIs(subject)
function filter (pred, inverse) {
if (types['http://www.w3.org/2007/ont/link#ProtocolEvent']) return true // display everything for them
return !!(typeof panes.internal.predicates[pred.uri] !== 'undefined')
}
var div = dom.createElement('div')
div.setAttribute('class', 'internalPane')
div.setAttribute('style', 'background-color: #ddddff; padding: 0.5em; border-radius: 1em;')
function deleteRecursive (kb, folder) {
return new Promise(function (resolve, reject) {
kb.fetcher.load(folder).then(function () {
let promises = kb.each(folder, ns.ldp('contains')).map(file => {
if (kb.holds(file, ns.rdf('type'), ns.ldp('BasicContainer'))) {
return deleteRecursive(kb, file)
} else {
console.log('deleteRecursive leaf file: ' + file)
return kb.fetcher.webOperation('DELETE', file.uri)
}
})
Promise.all(promises).then(res => {
console.log('deleteRecursive empty folder: ' + folder)
kb.fetcher.webOperation('DELETE', folder.uri).then(res => {
console.log('Deleted Ok: ' + folder)
resolve()
}, err => {
var str = 'Unable to delete ' + folder + ': ' + err
console.log(str)
reject(new Error(str))
})
resolve()
}, err => {
alert(err)
reject(err)
})
})
})
}
const isDocument = subject.uri && !subject.uri.includes('#')
if (isDocument) {
const controls = div.appendChild(dom.createElement('table'))
controls.style = 'width: 100%; margin: 1em;'
const controlRow = controls.appendChild(dom.createElement('tr'))
const deleteCell = controlRow.appendChild(dom.createElement('td'))
const isFolder = ((subject.uri && subject.uri.endsWith('/')) ||
kb.holds(subject, ns.rdf('type'), ns.ldp('Container')))
const noun = isFolder ? 'folder' : 'file'
var deleteButton = UI.widgets.deleteButtonWithCheck(dom, deleteCell, noun, function () {
if (!confirm('Are you sure you want to delete ' + subject + '? This cannot be undone.')) return
var promise = isFolder ? deleteRecursive(kb, subject)
: kb.fetcher.webOperation('DELETE', subject.uri)
promise.then(response => {
var str = 'Deleted: ' + subject
console.log(str)
}, err => {
var str = 'Unable to delete ' + subject + ': ' + err
console.log(str)
alert(str)
})
})
deleteButton.style = 'height: 2em;'
deleteButton.class = '' // Remove hover hide
deleteCell.appendChild(deleteButton)
const refreshCell = controlRow.appendChild(dom.createElement('td'))
const refreshButton = UI.widgets.button(dom, UI.icons.iconBase + 'noun_479395.svg', 'refresh')
refreshCell.appendChild(refreshButton)
refreshButton.addEventListener('click', event => {
kb.fetcher.refresh(subject, function (ok, errm, res) {
let str
if (ok) {
str = 'Refreshed OK: ' + subject
} else {
str = 'Error refreshing: ' + subject + ': ' + errm
}
console.log(str)
alert(str)
})
})
}
var plist = kb.statementsMatching(subject)
var docURI = null
if (subject.uri) {
plist.push($r.st(subject,
kb.sym('http://www.w3.org/2007/ont/link#uri'), subject.uri, UI.store.fetcher.appNode))
if (subject.uri.indexOf('#') >= 0) {
docURI = subject.uri.split('#')[0]
plist.push($r.st(subject,
kb.sym('http://www.w3.org/2007/ont/link#documentURI'),
subject.uri.split('#')[0], UI.store.fetcher.appNode))
plist.push($r.st(subject,
kb.sym('http://www.w3.org/2007/ont/link#document'),
kb.sym(subject.uri.split('#')[0]), UI.store.fetcher.appNode))
} else {
docURI = subject.uri
}
}
if (docURI) {
var ed = UI.store.updater.editable(docURI)
if (ed) {
plist.push($r.st(subject,
kb.sym('http://www.w3.org/ns/rww#editable'),
kb.literal(ed), UI.store.fetcher.appNode))
}
}
var outliner = panes.getOutliner(dom)
outliner.appendPropertyTRs(div, plist, false, filter)
plist = kb.statementsMatching(undefined, undefined, subject)
outliner.appendPropertyTRs(div, plist, true, filter)
return div
},
predicates: { // Predicates used for inner workings. Under the hood
'http://www.w3.org/2007/ont/link#request': 1,
'http://www.w3.org/2007/ont/link#requestedBy': 1,
'http://www.w3.org/2007/ont/link#source': 1,
'http://www.w3.org/2007/ont/link#session': 2, // 2= test neg but display
'http://www.w3.org/2007/ont/link#uri': 1,
'http://www.w3.org/2007/ont/link#documentURI': 1,
'http://www.w3.org/2007/ont/link#document': 1,
'http://www.w3.org/2007/ont/link#all': 1, // From userinput.js
'http://www.w3.org/2007/ont/link#Document': 1,
'http://www.w3.org/ns/rww#editable': 1,
'http://www.w3.org/2000/01/rdf-schema#seeAlso': 1,
'http://www.w3.org/2002/07/owl#': 1
},
classes: { // Things which are inherently already undercover
'http://www.w3.org/2007/ont/link#ProtocolEvent': 1
}
}
// ends