Skip to content

Commit 378c0f4

Browse files
authoredOct 23, 2020
first commit
1 parent 77650a9 commit 378c0f4

14 files changed

+27049
-0
lines changed
 

‎backend/all.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var username = neo4j;
2+
var password = 000000;
3+
4+
function allnodesPromise(query) {
5+
return new Promise((resolve, reject) => {
6+
// console.log(resolve);
7+
var neo4j = require('node-neo4j');
8+
db = new neo4j(`http://${username}:${password}@localhost:7474`);
9+
db.cypherQuery(query, function(err, result) {
10+
if (err) {
11+
reject(err);
12+
}
13+
14+
resolve(result);
15+
});
16+
});
17+
}
18+
module.exports.allnodesPromise = allnodesPromise
19+
// module.exports.allnodes=allnodes localhost:7687

‎backend/index.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const Koa = require('koa');
2+
const router = require('koa-router')();
3+
const app = new Koa();
4+
const all = require('./all');
5+
6+
const os = require('os');
7+
8+
var cors = require('koa2-cors'); // CORS是一个W3C标准,全称是"跨域资源共享"
9+
app.use(cors());
10+
11+
var myHost = '';
12+
13+
function getIPAdd() {
14+
var ifaces = os.networkInterfaces();
15+
for (var dev in ifaces) {
16+
//将'WLAN'替换为系统所处网络
17+
if (dev.includes('WLAN')) {
18+
break;
19+
}
20+
}
21+
ifaces[dev].forEach(function(details) {
22+
if (details.family == 'IPv4') {
23+
var adr = details.address
24+
// console.log(adr)
25+
myHost = adr;
26+
return adr;
27+
28+
}
29+
});
30+
}
31+
getIPAdd();
32+
33+
router.get('/all', (ctx, next) => {
34+
// console.log(myHost);
35+
var client_list = new Set();
36+
var clientHost = ctx.req.connection.remoteAddress.slice(7, );
37+
// console.log(ctx.req.connection.remoteAddress.slice(7, ));
38+
39+
// console.log(client_list);
40+
// console.log(ctx.req.headers.origin);
41+
// 从主页访问的情况
42+
if (ctx.req.headers.origin) {
43+
if (client_list.has(clientHost) == false) {
44+
client_list.add(clientHost);
45+
}
46+
query = ctx.query;
47+
// console.log(ctx.query);
48+
}
49+
// 本机访问3000
50+
else if (clientHost.includes(myHost) | clientHost == '::1') {
51+
console.log(clientHost + '正在访问3000端口并请求');
52+
query = ctx.query;
53+
54+
} else {
55+
console.log(clientHost + '正在访问3000端口并请求,已返回空');
56+
query = { query: 'MATCH (n:Error) RETURN n' };
57+
}
58+
59+
// console.log(query);
60+
return all.allnodesPromise(query.query).then(nodes => {
61+
ctx.body = nodes
62+
})
63+
});
64+
app.use(async(ctx, next) => {
65+
try {
66+
await next();
67+
} catch (e) {
68+
console.log(e)
69+
}
70+
});
71+
72+
app.use(router.routes());
73+
app.use(router.allowedMethods());
74+
app.listen(3000, getIPAdd());

‎favicon.ico

4.19 KB
Binary file not shown.

‎gif/drill.gif

3.49 MB
Loading

‎gif/entities.gif

1.03 MB
Loading

‎gif/properties.gif

3.29 MB
Loading

‎gif/relations.gif

3.19 MB
Loading

‎gif/relations_of_entities.gif

2.5 MB
Loading

‎index.html

+526
Large diffs are not rendered by default.

‎js/formattrans.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
function random(l, u) {
2+
return Math.floor(Math.random() * (u - l + 1)) + l
3+
}
4+
5+
function nodesFoldToD3(d) {
6+
let data;
7+
// console.log('nodesFoldToD3_2,data',d.data)
8+
data = d.data;
9+
10+
var nodes = [];
11+
var relationships = [];
12+
var nodeset = new Set();
13+
var relset = new Set();
14+
// console.log(data);
15+
for (let name in data) {
16+
var project = data[name];
17+
console.log(project);
18+
var nodenums = [0, 4, 8]
19+
nodenums.forEach(n => {
20+
if (project[n] == null || nodeset.has(project[n]['_id'])) {} else {
21+
nodeset.add(project[n]['_id']);
22+
// console.log(nodeset)
23+
var node = {};
24+
node['id'] = project[n]['_id'].toString();
25+
project[n + 1] = project[n + 1].filter((x) => x !== '');
26+
// console.log('project[n+1]',project[n+1]);
27+
if (project[n + 1][0] == 'Person')
28+
node['label'] = project[n]['name']
29+
else if (project[n + 1][0] == 'Movie') {
30+
node['label'] = project[n]['title']
31+
}
32+
33+
34+
// console.log(node);
35+
var proper = {};
36+
proper['type'] = project[n + 1][0];
37+
// console.log(proper['type']);
38+
for (let pro in project[n]) {
39+
{
40+
proper[pro] = project[n][pro];
41+
}
42+
43+
node['properties'] = proper;
44+
}
45+
46+
nodes.push(node);
47+
}
48+
})
49+
50+
51+
52+
if (project[2] == null || relset.has(project[2]['_id'])) {} else {
53+
var relation = {}
54+
relset.add(project[2]['_id']);
55+
// relation['id']=project[2]['_id'].toString();
56+
relation['label'] = project[3];
57+
relation['source'] = project[0]['_id'].toString();
58+
relation['target'] = project[4]['_id'].toString();
59+
// relation['linknum']=1;
60+
relationships.push(relation);
61+
};
62+
if (project[6] == null || relset.has(project[6]['_id'])) {
63+
// console.log(relset)
64+
} else {
65+
var relation = {}
66+
relset.add(project[6]['_id']);
67+
// relation['id']=project[6]['_id'].toString();
68+
relation['label'] = project[7];
69+
relation['source'] = project[4]['_id'].toString();
70+
relation['target'] = project[8]['_id'].toString();
71+
// relation['linknum']=1;
72+
relationships.push(relation);
73+
}
74+
}
75+
// console.log('nodes',nodes.length)
76+
if (nodes.length == 0) {
77+
var alert = 1;
78+
return alert;
79+
}
80+
var content = {
81+
82+
'nodes': nodes,
83+
'edges': relationships
84+
85+
}
86+
// console.log(content)
87+
return JSON.stringify(content)
88+
}

‎js/src/axios.min.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/src/g6.min.js

+25,336
Large diffs are not rendered by default.

‎js/src/jquery-1.8.2.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/src/jquery.autocomplete.js

+1,001
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.