mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: The ArangoAdapter can now be configured to load a graph by its name. UI for it is to be written
This commit is contained in:
parent
459b906f2c
commit
7cfddc42db
|
@ -40,12 +40,15 @@ function ArangoAdapter(nodes, edges, config) {
|
||||||
if (config === undefined) {
|
if (config === undefined) {
|
||||||
throw "A configuration with node- and edgeCollection has to be given.";
|
throw "A configuration with node- and edgeCollection has to be given.";
|
||||||
}
|
}
|
||||||
if (config.nodeCollection === undefined) {
|
if (config.graph === undefined) {
|
||||||
throw "The nodeCollection has to be given.";
|
if (config.nodeCollection === undefined) {
|
||||||
}
|
throw "The nodeCollection or a graphname has to be given.";
|
||||||
if (config.edgeCollection === undefined) {
|
}
|
||||||
throw "The edgeCollection has to be given.";
|
if (config.edgeCollection === undefined) {
|
||||||
|
throw "The edgeCollection or a graphname has to be given.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var self = this,
|
var self = this,
|
||||||
absAdapter,
|
absAdapter,
|
||||||
|
@ -57,9 +60,31 @@ function ArangoAdapter(nodes, edges, config) {
|
||||||
arangodb,
|
arangodb,
|
||||||
direction,
|
direction,
|
||||||
|
|
||||||
|
setNodeCollection = function(name) {
|
||||||
|
nodeCollection = name;
|
||||||
|
api.node = api.base + "document?collection=" + nodeCollection;
|
||||||
|
},
|
||||||
|
|
||||||
|
setEdgeCollection = function(name) {
|
||||||
|
edgeCollection = name;
|
||||||
|
api.edge = api.base + "edge?collection=" + edgeCollection;
|
||||||
|
},
|
||||||
|
|
||||||
|
getCollectionsFromGraph = function(name) {
|
||||||
|
$.ajax({
|
||||||
|
cache: false,
|
||||||
|
type: 'GET',
|
||||||
|
async: false,
|
||||||
|
url: api.graph + "/" + name,
|
||||||
|
contentType: "application/json",
|
||||||
|
success: function(data) {
|
||||||
|
setNodeCollection(data.graph.vertices);
|
||||||
|
setEdgeCollection(data.graph.edges);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
parseConfig = function(config) {
|
parseConfig = function(config) {
|
||||||
nodeCollection = config.nodeCollection;
|
|
||||||
edgeCollection = config.edgeCollection;
|
|
||||||
if (config.host === undefined) {
|
if (config.host === undefined) {
|
||||||
arangodb = "http://" + document.location.host;
|
arangodb = "http://" + document.location.host;
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,6 +105,20 @@ function ArangoAdapter(nodes, edges, config) {
|
||||||
} else {
|
} else {
|
||||||
direction = "outbound";
|
direction = "outbound";
|
||||||
}
|
}
|
||||||
|
api.base = arangodb.lastIndexOf("http://", 0) === 0
|
||||||
|
? arangodb + "/_api/"
|
||||||
|
: "http://" + arangodb + "/_api/";
|
||||||
|
api.cursor = api.base + "cursor";
|
||||||
|
api.graph = api.base + "graph";
|
||||||
|
api.collection = api.base + "collection/";
|
||||||
|
api.document = api.base + "document/";
|
||||||
|
api.any = api.base + "simple/any";
|
||||||
|
if (config.graph) {
|
||||||
|
getCollectionsFromGraph(config.graph);
|
||||||
|
} else {
|
||||||
|
setNodeCollection(config.nodeCollection);
|
||||||
|
setEdgeCollection(config.edgeCollection);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sendQuery = function(query, bindVars, onSuccess) {
|
sendQuery = function(query, bindVars, onSuccess) {
|
||||||
|
@ -231,18 +270,8 @@ function ArangoAdapter(nodes, edges, config) {
|
||||||
absConfig.prioList = config.prioList;
|
absConfig.prioList = config.prioList;
|
||||||
}
|
}
|
||||||
absAdapter = new AbstractAdapter(nodes, edges, this, absConfig);
|
absAdapter = new AbstractAdapter(nodes, edges, this, absConfig);
|
||||||
|
|
||||||
parseConfig(config);
|
|
||||||
|
|
||||||
api.base = arangodb.lastIndexOf("http://", 0) === 0
|
parseConfig(config);
|
||||||
? arangodb + "/_api/"
|
|
||||||
: "http://" + arangodb + "/_api/";
|
|
||||||
api.cursor = api.base + "cursor";
|
|
||||||
api.collection = api.base + "collection/";
|
|
||||||
api.document = api.base + "document/";
|
|
||||||
api.any = api.base + "simple/any";
|
|
||||||
api.node = api.base + "document?collection=" + nodeCollection;
|
|
||||||
api.edge = api.base + "edge?collection=" + edgeCollection;
|
|
||||||
|
|
||||||
queries.randomDocuments = "FOR u IN @@nodes"
|
queries.randomDocuments = "FOR u IN @@nodes"
|
||||||
+ " sort rand()"
|
+ " sort rand()"
|
||||||
|
@ -472,8 +501,8 @@ function ArangoAdapter(nodes, edges, config) {
|
||||||
|
|
||||||
self.changeToCollections = function (nodesCol, edgesCol, dir) {
|
self.changeToCollections = function (nodesCol, edgesCol, dir) {
|
||||||
absAdapter.cleanUp();
|
absAdapter.cleanUp();
|
||||||
nodeCollection = nodesCol;
|
setNodeCollection(nodesCol);
|
||||||
edgeCollection = edgesCol;
|
setEdgeCollection(edgesCol);
|
||||||
if (dir !== undefined) {
|
if (dir !== undefined) {
|
||||||
if (dir === true) {
|
if (dir === true) {
|
||||||
direction = "any";
|
direction = "any";
|
||||||
|
@ -481,8 +510,6 @@ function ArangoAdapter(nodes, edges, config) {
|
||||||
direction = "outbound";
|
direction = "outbound";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
api.node = api.base + "document?collection=" + nodeCollection;
|
|
||||||
api.edge = api.base + "edge?collection=" + edgeCollection;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.setNodeLimit = function (pLimit, callback) {
|
self.setNodeLimit = function (pLimit, callback) {
|
||||||
|
|
Loading…
Reference in New Issue