mirror of
https://github.com/yldio/copilot.git
synced 2024-12-05 01:20:08 +02:00
8295bd6882
this shall be a progressive process
1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
(function(a){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.neo4j"),sigma.utils.pkg("sigma.utils"),sigma.neo4j.send=function(a,b,c,d,e){var f,g,h,i=sigma.utils.xhr();if(f=a,"object"==typeof a&&(f=a.url,g=a.user,h=a.password),!i)throw"XMLHttpRequest not supported, cannot load the file.";f+=b,i.open(c,f,!0),g&&h&&i.setRequestHeader("Authorization","Basic "+btoa(g+":"+h)),i.setRequestHeader("Accept","application/json"),i.setRequestHeader("Content-type","application/json; charset=utf-8"),i.onreadystatechange=function(){4===i.readyState&&e(JSON.parse(i.responseText))},i.send(d)},sigma.neo4j.cypher_parse=function(a){var b,c={nodes:[],edges:[]},d={},e={};a.results[0].data.forEach(function(a){a.graph.nodes.forEach(function(a){var b={id:a.id,label:a.id,x:Math.random(),y:Math.random(),size:1,color:"#000000",neo4j_labels:a.labels,neo4j_data:a.properties};b.id in d||(d[b.id]=b)}),a.graph.relationships.forEach(function(a){var b={id:a.id,label:a.type,source:a.startNode,target:a.endNode,color:"#7D7C8E",neo4j_type:a.type,neo4j_data:a.properties};b.id in e||(e[b.id]=b)})});for(b in d)c.nodes.push(d[b]);for(b in e)c.edges.push(e[b]);return c},sigma.neo4j.cypher=function(a,b,c,d){var e,f,g="/db/data/transaction/commit";e=JSON.stringify({statements:[{statement:b,resultDataContents:["graph"],includeStats:!1}]}),f=function(a){return function(b){var d={nodes:[],edges:[]};d=sigma.neo4j.cypher_parse(b),c instanceof sigma?(c.graph.clear(),c.graph.read(d)):"object"==typeof c?(c=new sigma(c),c.graph.read(d),c.refresh()):"function"==typeof c&&(a=c,c=null),a&&a(c||d)}},sigma.neo4j.send(a,g,"POST",e,f(d))},sigma.neo4j.getLabels=function(a,b){sigma.neo4j.send(a,"/db/data/labels","GET",null,b)},sigma.neo4j.getTypes=function(a,b){sigma.neo4j.send(a,"/db/data/relationship/types","GET",null,b)}}).call(this); |