forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassInstancePane.js
More file actions
85 lines (82 loc) · 3.08 KB
/
Copy pathclassInstancePane.js
File metadata and controls
85 lines (82 loc) · 3.08 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
/* Class member Pane
**
** This outline pane lists the members of a class
*/
import * as UI from 'solid-ui-jss';
import * as $rdf from 'rdflib';
const ns = UI.ns;
export const classInstancePane = {
icon: UI.icons.originalIconBase + 'tango/22-folder-open.png',
name: 'classInstance',
// Create a new folder in a Solid system,
audience: [ns.solid('PowerUser')],
label: function (subject, context) {
const kb = context.session.store;
const n = kb.each(undefined, ns.rdf('type'), subject).length;
if (n > 0) return 'List (' + n + ')'; // Show how many in hover text
return null; // Suppress pane otherwise
},
render: function (subject, context) {
const dom = context.dom;
const outliner = context.getOutliner(dom);
const kb = context.session.store;
const complain = function complain(message, color) {
const pre = dom.createElement('pre');
pre.setAttribute('style', 'background-color: ' + color || '#eed' + ';');
div.appendChild(pre);
pre.appendChild(dom.createTextNode(message));
};
const div = dom.createElement('div');
div.setAttribute('class', 'instancePane');
div.setAttribute('style', ' border-top: solid 1px #777; border-bottom: solid 1px #777; margin-top: 0.5em; margin-bottom: 0.5em ');
// If this is a class, look for all both explicit and implicit
const sts = kb.statementsMatching(undefined, ns.rdf('type'), subject);
if (sts.length > 0) {
const already = {};
const more = [];
sts.forEach(st => {
already[st.subject.toNT()] = st;
});
for (const nt in kb.findMembersNT(subject)) {
if (!already[nt]) {
more.push($rdf.st(kb.fromNT(nt), ns.rdf('type'), subject)); // @@ no provenance
}
}
if (more.length) {
complain('There are ' + sts.length + ' explicit and ' + more.length + ' implicit members of ' + UI.utils.label(subject));
}
if (subject.sameTerm(ns.rdf('Property'))) {
// / Do not find all properties used as properties .. unless look at kb index
} else if (subject.sameTerm(ns.rdfs('Class'))) {
const uses = kb.statementsMatching(undefined, ns.rdf('type'), undefined);
const usedTypes = {};
uses.forEach(function (st) {
usedTypes[st.object] = st;
}); // Get unique
const used = [];
for (const i in usedTypes) {
used.push($rdf.st($rdf.sym(i), ns.rdf('type'), ns.rdfs('Class')));
}
complain('Total of ' + uses.length + ' type statements and ' + used.length + ' unique types.');
}
if (sts.length > 10) {
const tr = dom.createElement('TR');
tr.appendChild(dom.createTextNode('' + sts.length));
// tr.AJAR_statement=sts[i]
div.appendChild(tr);
}
outliner.appendPropertyTRs(div, sts, true, function (_pred) {
return true;
});
if (more.length) {
complain('Implicit:');
outliner.appendPropertyTRs(div, more, true, function (_pred) {
return true;
});
}
}
return div;
}
};
// ends
//# sourceMappingURL=classInstancePane.js.map