-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (72 loc) · 3.46 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A Simple Graph App</title>
</head>
<body>
<div id="main">Hello Graph 🌍️ !</div>
<div>
<span><b>Labels in the Active Graph</b></span>
<ul id="labels">
</ul>
</div>
</body>
<script src="https://unpkg.com/neo4j-driver"></script>
<script>
if (window.neo4jDesktopApi) {
let mainDiv = document.getElementById("main");
neo4jDesktopApi.getContext()
.then((context) => {
for (let project of context.projects) {
const projectEl = document.createElement('div');
projectEl.style.cssText = "font-weight: bold";
projectEl.appendChild(document.createTextNode(project.name));
mainDiv.appendChild(projectEl);
const listEl = document.createElement('ul');
for (let graph of project.graphs) {
const listItemFragment = document.createDocumentFragment();
const text = document.createTextNode(graph.name + ' (' + graph.description +') ');
const listItem = document.createElement('li');
listItem.appendChild(text);
listItemFragment.appendChild(listItem);
listEl.appendChild(listItemFragment);
}
mainDiv.appendChild(listEl);
}
}
);
//query the active graph
neo4jDesktopApi.getContext()
.then((context) => {
for (let project of context.projects) {
for (let graph of project.graphs) {
if (graph.status === 'ACTIVE') {
//obtain the bolt protocol which has all the connection details
let boltProtocol = graph.connection.configuration.protocols.bolt;
let driver = neo4j.v1.driver(boltProtocol.url, neo4j.v1.auth.basic(boltProtocol.username, boltProtocol.password));
//Create a session and execute a query
let session = driver.session();
session.run("CALL db.labels() YIELD label RETURN label ORDER BY label")
.then(result => {
if (result.records && result.records.length>0) {
let labelsList = document.getElementById("labels");
for (var i = 0; i < result.records.length; i++) {
const r = result.records[i]
const labelItem = document.createElement('li');
labelItem.appendChild(document.createTextNode(r.get('label')));
labelsList.appendChild(labelItem);
}
}
})
.catch(function(error) {
console.log(error);
});
}
}
}
});
}
</script>
<footer><small>Icons from https://www.iconfinder.com/iconsets/spring-2-1</small></footer>
</html>