1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

This commit is contained in:
Jan Steemann 2013-04-15 13:05:42 +02:00
commit d6da13b1f9
18 changed files with 573 additions and 128 deletions

View File

@ -34,6 +34,7 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
initialX = {}, initialX = {},
initialY = {}, initialY = {},
api = {}, api = {},
queries = {},
findNode = function(id) { findNode = function(id) {
var res = $.grep(nodes, function(e){ var res = $.grep(nodes, function(e){
@ -156,8 +157,15 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
}, },
sendQuery = function(query, onSuccess) { sendQuery = function(query, bindVars, onSuccess) {
var data = {query: query}; if (query !== queries.connectedEdges) {
bindVars["@nodes"] = nodeCollection;
}
bindVars["@edges"] = edgeCollection;
var data = {
query: query,
bindVars: bindVars
};
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: api.cursor, url: api.cursor,
@ -234,11 +242,9 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
}, },
permanentlyRemoveEdgesOfNode = function (nodeId) { permanentlyRemoveEdgesOfNode = function (nodeId) {
var query = "FOR e IN " + edgeCollection sendQuery(queries.connectedEdges, {
+ " FILTER e._to == " + JSON.stringify(nodeId) id: nodeId
+ " || e._from == " + JSON.stringify(nodeId) }, function(res) {
+ " RETURN e";
sendQuery(query, function(res) {
_.each(res, self.deleteEdge); _.each(res, self.deleteEdge);
}); });
}; };
@ -252,6 +258,50 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
api.node = api.base + "document?collection=" + nodeCollection; api.node = api.base + "document?collection=" + nodeCollection;
api.edge = api.base + "edge?collection=" + edgeCollection; api.edge = api.base + "edge?collection=" + edgeCollection;
queries.nodeById = "FOR n IN @@nodes"
+ " FILTER n._id == @id"
+ " LET links = ("
+ " FOR l IN @@edges"
+ " FILTER n._id == l._from"
+ " FOR t IN @@nodes"
+ " FILTER t._id == l._to"
+ " RETURN t._id"
+ " )"
+ " RETURN MERGE(n, {\"children\" : links})";
queries.traversalById = "RETURN TRAVERSAL("
+ "@@nodes, "
+ "@@edges, "
+ "@id, "
+ "\"outbound\", {"
+ "strategy: \"depthfirst\","
+ "maxDepth: 1,"
+ "paths: true"
+ "})";
queries.traversalByAttribute = function(attr) {
return "FOR n IN @@nodes "
+ " FILTER n." + attr
+ " == @value"
+ " RETURN TRAVERSAL("
+ "@@nodes, "
+ "@@edges, "
+ "n._id, "
+ "\"outbound\", {"
+ "strategy: \"depthfirst\","
+ "maxDepth: 1,"
+ "paths: true"
+ "})";
};
queries.childrenCentrality = "FOR u IN @@nodes"
+ " FILTER u._id == @id"
+ " LET g = ("
+ " FOR l in @@edges"
+ " FILTER l._from == u._id"
+ " RETURN 1 )"
+ " RETURN length(g)";
queries.connectedEdges = "FOR e IN @@edges"
+ " FILTER e._to == @id"
+ " || e._from == @id"
+ " RETURN e";
initialX.range = width / 2; initialX.range = width / 2;
initialX.start = width / 4; initialX.start = width / 4;
@ -266,65 +316,33 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
}; };
self.oldLoadNodeFromTreeById = function(nodeId, callback) { self.oldLoadNodeFromTreeById = function(nodeId, callback) {
var loadNodeQuery = sendQuery(queries.nodeById, {
"FOR n IN " + nodeCollection id: nodeId
+ " FILTER n._id == " + JSON.stringify(nodeId) }, function(res) {
+ " LET links = ("
+ " FOR l IN " + edgeCollection
+ " FILTER n._id == l._from"
+ " FOR t IN " + nodeCollection
+ " FILTER t._id == l._to"
+ " RETURN t._id"
+ " )"
+ " RETURN MERGE(n, {\"children\" : links})";
sendQuery(loadNodeQuery, function(res) {
parseResultOfQuery(res, callback); parseResultOfQuery(res, callback);
}); });
}; };
self.loadNodeFromTreeById = function(nodeId, callback) { self.loadNodeFromTreeById = function(nodeId, callback) {
var traversal = "RETURN TRAVERSAL(" sendQuery(queries.traversalById, {
+ nodeCollection + ", " id: nodeId
+ edgeCollection + ", " }, function(res) {
+ "\"" + nodeId + "\", "
+ "\"outbound\", {"
+ "strategy: \"depthfirst\","
+ "maxDepth: 1,"
+ "paths: true"
+ "})";
sendQuery(traversal, function(res) {
parseResultOfTraversal(res, callback); parseResultOfTraversal(res, callback);
}); });
}; };
self.loadNodeFromTreeByAttributeValue = function(attribute, value, callback) { self.loadNodeFromTreeByAttributeValue = function(attribute, value, callback) {
var traversal = "FOR n in " sendQuery(queries.traversalByAttribute(attribute), {
+ nodeCollection value: value
+ " FILTER n." + attribute }, function(res) {
+ " == " + JSON.stringify(value)
+ " RETURN TRAVERSAL("
+ nodeCollection + ", "
+ edgeCollection + ", "
+ "n._id, "
+ "\"outbound\", {"
+ "strategy: \"depthfirst\","
+ "maxDepth: 1,"
+ "paths: true"
+ "})";
sendQuery(traversal, function(res) {
parseResultOfTraversal(res, callback); parseResultOfTraversal(res, callback);
}); });
}; };
self.requestCentralityChildren = function(nodeId, callback) { self.requestCentralityChildren = function(nodeId, callback) {
var requestChildren = "for u in " + nodeCollection sendQuery(queries.childrenCentrality,{
+ " filter u._id == " + JSON.stringify(nodeId) id: nodeId
+ " let g = (" }, function(res) {
+ " for l in " + edgeCollection
+ " filter l._from == u._id"
+ " return 1 )"
+ " return length(g)";
sendQuery(requestChildren, function(res) {
callback(res[0]); callback(res[0]);
}); });
}; };
@ -447,5 +465,11 @@ function ArangoAdapter(arangodb, nodes, edges, nodeCollection, edgeCollection, w
}); });
}; };
self.changeTo = function (nodesCol, edgesCol ) {
nodeCollection = nodesCol;
edgeCollection = edgesCol;
api.node = api.base + "document?collection=" + nodeCollection;
api.edge = api.base + "edge?collection=" + edgeCollection;
};
} }

View File

@ -213,7 +213,8 @@ function EdgeShaper(parent, flags, idfunc) {
.attr("text-anchor", "middle") // Define text-anchor .attr("text-anchor", "middle") // Define text-anchor
.attr("stroke", "black") .attr("stroke", "black")
.text(function(d) { .text(function(d) {
return d[label] !== undefined ? d[label] : ""; // Which value should be used as label // Which value should be used as label
return d._data[label] !== undefined ? d._data[label] : "";
}); });
}; };
} }
@ -274,7 +275,7 @@ function EdgeShaper(parent, flags, idfunc) {
case "attribute": case "attribute":
addColor = function (line, g) { addColor = function (line, g) {
g.attr("stroke", function(e) { g.attr("stroke", function(e) {
return colourMapper.getColour(e[color.key]); return colourMapper.getColour(e._data[color.key]);
}); });
}; };
break; break;

View File

@ -204,7 +204,7 @@ function NodeShaper(parent, flags, idfunc) {
.attr("fill", "black") .attr("fill", "black")
.attr("stroke", "black") .attr("stroke", "black")
.text(function(d) { .text(function(d) {
return d[label] !== undefined ? d[label] : ""; // Which value should be used as label return d._data[label] !== undefined ? d._data[label] : "";
}); });
}; };
} }

View File

@ -6,6 +6,7 @@
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png"> <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css"> <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
<link rel="stylesheet" type="text/css" href="../style/bootstrap.min.css">
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script> <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script> <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jslint.js"></script> <script type="text/javascript" src="lib/jslint.js"></script>
@ -14,16 +15,21 @@
<script type="text/javascript" src="../../lib/d3.v3.min.js"></script> <script type="text/javascript" src="../../lib/d3.v3.min.js"></script>
<script type="text/javascript" src="../../lib/underscore.js"></script> <script type="text/javascript" src="../../lib/underscore.js"></script>
<script type="text/javascript" src="../../lib/jquery-1.8.3.js"></script> <script type="text/javascript" src="../../lib/jquery-1.8.3.js"></script>
<script type="text/javascript" src="../../lib/bootstrap.js"></script>
<script type="text/javascript" src="../../lib/jquery.livequery.js"></script> <script type="text/javascript" src="../../lib/jquery.livequery.js"></script>
<script type="text/javascript" src="helper/eventHelper.js"></script> <script type="text/javascript" src="helper/eventHelper.js"></script>
<script type="text/javascript" src="../graph/arangoAdapter.js"></script> <script type="text/javascript" src="../graph/arangoAdapter.js"></script>
<script type="text/javascript" src="../ui/uiComponentsHelper.js"></script>
<script type="text/javascript" src="../ui/modalDialogHelper.js"></script>
<script type="text/javascript" src="../ui/arangoAdapterControls.js"></script>
<!-- include spec files here... --> <!-- include spec files here... -->
<script type="text/javascript" src="specAdapter/interfaceSpec.js"></script> <script type="text/javascript" src="specAdapter/interfaceSpec.js"></script>
<script type="text/javascript" src="specAdapter/arangoAdapterSpec.js"></script> <script type="text/javascript" src="specAdapter/arangoAdapterSpec.js"></script>
<script type="text/javascript" src="specAdapter/arangoAdapterUISpec.js"></script>
<!-- run JSLINT --> <!-- run JSLINT -->
<script type="text/javascript" src="specJSLint/jsLintSpec.js"></script> <script type="text/javascript" src="specJSLint/jsLintSpec.js"></script>

View File

@ -48,8 +48,12 @@
arangodb, arangodb,
nodesCollection, nodesCollection,
nodesCollId, nodesCollId,
altNodesCollection,
altNodesCollId,
edgesCollection, edgesCollection,
edgesCollId, edgesCollId,
altEdgesCollection,
altEdgesCollId,
callbackCheck, callbackCheck,
checkCallbackFunction = function() { checkCallbackFunction = function() {
callbackCheck = true; callbackCheck = true;
@ -182,6 +186,8 @@
try { try {
dropCollection(nodesCollection); dropCollection(nodesCollection);
dropCollection(edgesCollection); dropCollection(edgesCollection);
dropCollection(altNodesCollection);
dropCollection(altEdgesCollection);
}catch(e){ }catch(e){
} }
@ -190,11 +196,17 @@
setupArangoContent = function() { setupArangoContent = function() {
nodesCollection = "TestNodes321"; nodesCollection = "TestNodes321";
edgesCollection = "TestEdges321"; edgesCollection = "TestEdges321";
altNodesCollection = "TestNodes654";
altEdgesCollection = "TestEdges654";
deleteArangoContent(); deleteArangoContent();
createCollection(nodesCollection, "Document", function(id) {nodesCollId = id;}); createCollection(nodesCollection, "Document", function(id) {nodesCollId = id;});
createCollection(edgesCollection, "Edge", function(id) {edgesCollId = id;}); createCollection(edgesCollection, "Edge", function(id) {edgesCollId = id;});
createCollection(altNodesCollection, "Document", function(id) {altNodesCollId = id;});
createCollection(altEdgesCollection, "Edge", function(id) {altEdgesCollId = id;});
}; };
beforeEach(function() { beforeEach(function() {
@ -247,6 +259,37 @@
}); });
}); });
it('should be able to load a tree node from ArangoDB'
+ ' by internal attribute and value', function() {
var c0, c1, c2, c3, c4;
runs(function() {
c0 = insertNode(nodesCollection, 0);
c1 = insertNode(nodesCollection, 1);
c2 = insertNode(nodesCollection, 2);
c3 = insertNode(nodesCollection, 3);
c4 = insertNode(nodesCollection, 4);
insertEdge(edgesCollection, c0, c1);
insertEdge(edgesCollection, c0, c2);
insertEdge(edgesCollection, c0, c3);
insertEdge(edgesCollection, c0, c4);
callbackCheck = false;
adapter.loadNodeFromTreeByAttributeValue("id", 0, checkCallbackFunction);
});
waitsFor(function() {
return callbackCheck;
});
runs(function() {
existNodes([c0, c1, c2, c3, c4]);
expect(nodes.length).toEqual(5);
});
});
it('should be able to request the number of children centrality', function() { it('should be able to request the number of children centrality', function() {
var c0, c1 ,c2 ,c3 ,c4, var c0, c1 ,c2 ,c3 ,c4,
children; children;
@ -324,6 +367,73 @@
}); });
it('should be able to switch to different collections', function() {
var c0, c1, e1_2, insertedId;
runs(function() {
c0 = insertNode(altNodesCollection, 0);
c1 = insertNode(altNodesCollection, 1);
e1_2 = insertEdge(altEdgesCollection, c0, c1);
adapter.changeTo(altNodesCollection, altEdgesCollection);
callbackCheck = false;
adapter.loadNodeFromTreeById(c0, checkCallbackFunction);
});
waitsFor(function() {
return callbackCheck;
});
runs(function() {
existNodes([c0, c1]);
expect(nodes.length).toEqual(2);
callbackCheck = false;
adapter.createNode({}, function(node) {
insertedId = node._id;
callbackCheck = true;
});
this.addMatchers({
toBeStoredPermanently: function() {
var id = this.actual,
res = false;
$.ajax({
type: "GET",
url: arangodb + "/_api/document/" + id,
contentType: "application/json",
processData: false,
async: false,
success: function(data) {
res = true;
},
error: function(data) {
try {
var temp = JSON.parse(data);
throw "[" + temp.errorNum + "] " + temp.errorMessage;
}
catch (e) {
throw "Undefined ERROR";
}
}
});
return res;
}
});
});
waitsFor(function() {
return callbackCheck;
});
runs(function() {
expect(insertedId).toBeStoredPermanently();
existNode(insertedId);
});
});
describe('that has already loaded one graph', function() { describe('that has already loaded one graph', function() {
var c0, c1, c2, c3, c4, c5, c6, c7; var c0, c1, c2, c3, c4, c5, c6, c7;

View File

@ -0,0 +1,115 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
/*global beforeEach, afterEach */
/*global describe, it, expect*/
/*global runs, waitsFor, spyOn */
/*global window, eb, loadFixtures, document */
/*global $, _, d3*/
/*global helper*/
/*global ArangoAdapterControls */
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph functionality
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Michael Hackstein
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
(function () {
"use strict";
describe('Arango Adapter UI', function () {
var adapter, adapterUI, list;
beforeEach(function () {
adapter = {
changeTo: function(){}
};
list = document.createElement("ul");
document.body.appendChild(list);
list.id = "control_list";
adapterUI = new ArangoAdapterControls(list, adapter);
spyOn(adapter, 'changeTo');
this.addMatchers({
toBeTag: function(name) {
var el = this.actual;
this.message = function() {
return "Expected " + el.tagName.toLowerCase() + " to be a " + name;
};
return el.tagName.toLowerCase() === name;
},
toConformToListCSS: function() {
var li = this.actual,
a = li.firstChild,
lbl = a.firstChild;
expect(li).toBeTag("li");
expect(a).toBeTag("a");
expect(lbl).toBeTag("label");
return true;
}
});
});
afterEach(function () {
document.body.removeChild(list);
});
it('should throw errors if not setup correctly', function() {
expect(function() {
var e = new ArangoAdapterControls();
}).toThrow("A list element has to be given.");
expect(function() {
var e = new ArangoAdapterControls(list);
}).toThrow("The ArangoAdapter has to be given.");
});
it('should be able to add a change collections control to the list', function() {
runs(function() {
adapterUI.addControlChangeCollections();
expect($("#control_list #control_collections").length).toEqual(1);
expect($("#control_list #control_collections")[0]).toConformToListCSS();
helper.simulateMouseEvent("click", "control_collections");
expect($("#control_collections_modal").length).toEqual(1);
$("#control_collections_nodecollection").attr("value", "newNodes");
$("#control_collections_edgecollection").attr("value", "newEdges");
helper.simulateMouseEvent("click", "control_collections_submit");
expect(adapter.changeTo).toHaveBeenCalledWith(
"newNodes",
"newEdges"
);
});
});
it('should be able to add all controls to the list', function() {
adapterUI.addAll();
expect($("#control_list #control_collections").length).toEqual(1);
});
});
}());

View File

@ -355,19 +355,27 @@
edges = [{ edges = [{
source: n1, source: n1,
target: n2, target: n2,
_data: {
label: "lbl1" label: "lbl1"
}
},{ },{
source: n2, source: n2,
target: n3, target: n3,
_data: {
label: "lbl2" label: "lbl2"
}
},{ },{
source: n3, source: n3,
target: n4, target: n4,
_data: {
label: "lbl3" label: "lbl3"
}
},{ },{
source: n4, source: n4,
target: n1, target: n1,
_data: {
label: "lbl1" label: "lbl1"
}
}], }],
shaper = new EdgeShaper(d3.select("svg"), shaper = new EdgeShaper(d3.select("svg"),
{ {
@ -586,22 +594,30 @@
{ {
"source": nodes[0], "source": nodes[0],
"target": nodes[1], "target": nodes[1],
"label": "first" _data: {
label: "first"
}
}, },
{ {
"source": nodes[1], "source": nodes[1],
"target": nodes[2], "target": nodes[2],
"label": "second" _data: {
label: "second"
}
}, },
{ {
"source": nodes[2], "source": nodes[2],
"target": nodes[3], "target": nodes[3],
"label": "third" _data: {
label: "third"
}
}, },
{ {
"source": nodes[3], "source": nodes[3],
"target": nodes[0], "target": nodes[0],
"label": "fourth" _data: {
label: "fourth"
}
} }
]; ];
shaper.drawEdges(edges); shaper.drawEdges(edges);
@ -637,8 +653,10 @@
{ {
"source": nodes[0], "source": nodes[0],
"target": nodes[1], "target": nodes[1],
_data: {
"label": "first" "label": "first"
} }
}
]; ];
shaper.drawEdges(edges); shaper.drawEdges(edges);
@ -651,23 +669,30 @@
{ {
"source": nodes[0], "source": nodes[0],
"target": nodes[1], "target": nodes[1],
_data: {
"label": "correct" "label": "correct"
}
}, },
{ {
"source": nodes[1], "source": nodes[1],
"target": nodes[2], "target": nodes[2],
_data: {
"alt": "incorrect" "alt": "incorrect"
}
}, },
{ {
"source": nodes[2], "source": nodes[2],
"target": nodes[3] "target": nodes[3],
_data: {}
}, },
{ {
"source": nodes[3], "source": nodes[3],
"target": nodes[0], "target": nodes[0],
_data: {
"label": "correct", "label": "correct",
"alt": "incorrect" "alt": "incorrect"
} }
}
]; ];
shaper.drawEdges(edges); shaper.drawEdges(edges);
@ -684,13 +709,17 @@
{ {
"source": nodes[0], "source": nodes[0],
"target": nodes[1], "target": nodes[1],
_data: {
"label": "old" "label": "old"
}
}, },
{ {
"source": nodes[1], "source": nodes[1],
"target": nodes[0], "target": nodes[0],
_data: {
"new": "new" "new": "new"
} }
}
]; ];
shaper.drawEdges(edges); shaper.drawEdges(edges);

View File

@ -235,7 +235,22 @@
shaper; shaper;
beforeEach(function() { beforeEach(function() {
nodes = [{_id: 1}, {_id: 2}, {_id: 3}]; nodes = [{
_id: 1,
_data: {
}
}, {
_id: 2,
_data: {
}
}, {
_id: 3,
_data: {
}
}];
clicked = []; clicked = [];
shaper = new NodeShaper(d3.select("svg")); shaper = new NodeShaper(d3.select("svg"));
shaper.drawNodes(nodes); shaper.drawNodes(nodes);
@ -305,9 +320,9 @@
it('should be able to reshape a single node only', function() { it('should be able to reshape a single node only', function() {
shaper.changeTo({label: "label"}); shaper.changeTo({label: "label"});
nodes[0].label = "false"; nodes[0]._data.label = "false";
nodes[1].label = "true"; nodes[1]._data.label = "true";
nodes[2].label = "false_again"; nodes[2]._data.label = "false_again";
expect($("#1 text").length).toEqual(1); expect($("#1 text").length).toEqual(1);
expect($("#2 text").length).toEqual(1); expect($("#2 text").length).toEqual(1);
expect($("#3 text").length).toEqual(1); expect($("#3 text").length).toEqual(1);
@ -326,8 +341,6 @@
}); });
}); });
describe('configured for circle', function () { describe('configured for circle', function () {
var shaper; var shaper;
@ -522,8 +535,6 @@
}); });
}); });
describe('configured for label', function () { describe('configured for label', function () {
var shaper; var shaper;
@ -534,7 +545,12 @@
}); });
it('should add a text element', function () { it('should add a text element', function () {
var node = [{_id: 1, "label": "MyLabel"}]; var node = [{
_id: 1,
_data: {
"label": "MyLabel"
}
}];
shaper.drawNodes(node); shaper.drawNodes(node);
expect($("svg .node")[0]).toBeDefined(); expect($("svg .node")[0]).toBeDefined();
expect($("svg .node").length).toEqual(1); expect($("svg .node").length).toEqual(1);
@ -550,10 +566,31 @@
it('should ignore other attributes', function () { it('should ignore other attributes', function () {
var nodes = [ var nodes = [
{_id: 1, "label": "correct"}, {
{_id: 2, "alt": "incorrect"}, _id: 1,
{_id: 3, "alt": "incorrect"}, _data: {
{_id: 4, "label": "correct", "alt": "incorrect"}]; "label": "correct"
}
},
{
_id: 2,
_data: {
"alt": "incorrect"
}
},
{
_id: 3,
_data: {
"alt": "incorrect"
}
},
{
_id: 4,
_data: {
"label": "correct",
"alt": "incorrect"
}
}];
shaper.drawNodes(nodes); shaper.drawNodes(nodes);
expect($("svg #1 text")[0].textContent).toEqual("correct"); expect($("svg #1 text")[0].textContent).toEqual("correct");
expect($("svg #2 text")[0].textContent).toEqual(""); expect($("svg #2 text")[0].textContent).toEqual("");
@ -562,7 +599,12 @@
}); });
it('should also print "0" as a label', function() { it('should also print "0" as a label', function() {
var node = [{_id: 1, "label": 0}]; var node = [{
_id: 1,
_data: {
"label": 0
}
}];
shaper.drawNodes(node); shaper.drawNodes(node);
expect($("svg .node text")[0]).toBeDefined(); expect($("svg .node text")[0]).toBeDefined();
expect($("svg .node text").length).toEqual(1); expect($("svg .node text").length).toEqual(1);
@ -572,8 +614,10 @@
it('should be able to switch to another label during runtime', function() { it('should be able to switch to another label during runtime', function() {
var node = [{ var node = [{
_id: 1, _id: 1,
_data: {
label: "before", label: "before",
switched: "after" switched: "after"
}
}]; }];
shaper.drawNodes(node); shaper.drawNodes(node);
expect($("svg .node text")[0].textContent).toEqual("before"); expect($("svg .node text")[0].textContent).toEqual("before");
@ -592,11 +636,11 @@
if (node._id === 4) { if (node._id === 4) {
return "correct"; return "correct";
} }
if (node.label) { if (node._data.label) {
return node.label; return node._data.label;
} }
if (node.alt) { if (node._data.alt) {
return node.alt; return node._data.alt;
} }
return "default"; return "default";
}; };
@ -609,11 +653,36 @@
it('should display the correct labels according to the function', function () { it('should display the correct labels according to the function', function () {
var nodes = [ var nodes = [
{_id: 1, "label": "correct"}, {
{_id: 2, "alt": "correct"}, _id: 1,
{_id: 3, "label": "correct", "alt": "incorrect"}, _data: {
{_id: 4, "label": "incorrect", "alt": "incorrect"}, "label": "correct"
{_id: 5} }
},
{
_id: 2,
_data: {
"alt": "correct"
}
},
{
_id: 3,
_data: {
"label": "correct",
"alt": "incorrect"
}
},
{
_id: 4,
_data: {
"label": "incorrect",
"alt": "incorrect"
}
},
{
_id: 5,
_data: {}
}
]; ];
shaper.drawNodes(nodes); shaper.drawNodes(nodes);
expect($("text").length).toEqual(5); expect($("text").length).toEqual(5);
@ -712,7 +781,9 @@
it('should draw circle elements', function () { it('should draw circle elements', function () {
var node = [{ var node = [{
_id: 1, _id: 1,
_data: {
"label": "correct" "label": "correct"
}
}]; }];
shaper.drawNodes(node); shaper.drawNodes(node);
expect($("svg .node").length).toEqual(1); expect($("svg .node").length).toEqual(1);

View File

@ -0,0 +1,66 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */
/*global $, _, d3*/
/*global document*/
/*global modalDialogHelper, uiComponentsHelper*/
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph functionality
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Michael Hackstein
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
function ArangoAdapterControls(list, adapter) {
"use strict";
if (list === undefined) {
throw "A list element has to be given.";
}
if (adapter === undefined) {
throw "The ArangoAdapter has to be given.";
}
var self = this,
baseClass = "adapter";
this.addControlChangeCollections = function() {
var prefix = "control_collections",
idprefix = prefix + "_";
uiComponentsHelper.createButton(baseClass, list, "Collections", prefix, function() {
modalDialogHelper.createModalDialog("Switch Collections",
idprefix, [{
type: "text",
id: "nodecollection"
},{
type: "text",
id: "edgecollection"
}], function () {
var nodes = $("#" + idprefix + "nodecollection").attr("value"),
edges = $("#" + idprefix + "edgecollection").attr("value");
adapter.changeTo(nodes, edges);
}
);
});
};
this.addAll = function() {
this.addControlChangeCollections();
};
}

View File

@ -18,7 +18,7 @@ $(document).ready(function() {
"application/available/:key" : "applicationInstall", "application/available/:key" : "applicationInstall",
"applications/installed" : "applicationsInstalled", "applications/installed" : "applicationsInstalled",
"applications/available" : "applicationsAvailable", "applications/available" : "applicationsAvailable",
"applications/documentation" : "applicationsDocumentation", "application/documentation/:key" : "appDocumentation",
"graph" : "graph" "graph" : "graph"
}, },
@ -223,12 +223,9 @@ $(document).ready(function() {
}, },
appDocumentation: function(key) {
applicationsDocumentation: function() { var docuView = new window.AppDocumentationView({key: key});
if (this.appDocuView === undefined) { docuView.render();
this.appDocuView = new window.AppDocumentationView();
}
this.appDocuView.render();
this.naviView.selectMenuItem('applications-menu'); this.naviView.selectMenuItem('applications-menu');
} }

View File

@ -14,7 +14,6 @@
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#applications/installed">Installed</a></li> <li><a href="#applications/installed">Installed</a></li>
<li><a href="#applications/available">Available</a></li> <li><a href="#applications/available">Available</a></li>
<li><a href="#applications/documentation">Documentation</a></li>
</ul> </ul>
<li class="collections-menu"><a href="#">Collections</a></li> <li class="collections-menu"><a href="#">Collections</a></li>
<li class="query-menu"><a href="#query">AQL Editor</a></li> <li class="query-menu"><a href="#query">AQL Editor</a></li>

View File

@ -5,25 +5,23 @@ window.AppDocumentationView = Backbone.View.extend({
initialize: function() { initialize: function() {
this.swaggerUi = new SwaggerUi({ this.swaggerUi = new SwaggerUi({
discoveryUrl:"../aardvark/docus", discoveryUrl:"../aardvark/docu/" + this.options.key,
apiKey: false, apiKey: false,
dom_id:"swagger-ui-container", dom_id:"swagger-ui-container",
supportHeaderParams: true, supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch', 'head'], supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch', 'head'],
onComplete: function(swaggerApi, swaggerUi){ onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)}); $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
}, },
onFailure: function(data) { onFailure: function(data) {
if(console) { var div = document.createElement("div"),
console.log("Unable to Load SwaggerUI"); strong = document.createElement("strong");
console.log(data); strong.appendChild(document.createTextNode("Sorry the code is not documented properly"));
} div.appendChild(strong);
div.appendChild(document.createElement("br"));
div.appendChild(document.createTextNode(JSON.stringify(data)));
$("#swagger-ui-container").append(div);
}, },
docExpansion: "none" docExpansion: "none"
}); });

View File

@ -18,7 +18,6 @@ var FoxxActiveListView = Backbone.View.extend({
self.render(); self.render();
}, },
error: function() { error: function() {
console.log("Erroreoror!!");
} }
}); });
this.render(); this.render();

View File

@ -4,7 +4,8 @@ window.FoxxActiveView = Backbone.View.extend({
template: new EJS({url: 'js/templates/foxxActiveView.ejs'}), template: new EJS({url: 'js/templates/foxxActiveView.ejs'}),
events: { events: {
'click .icon-edit': 'editFoxx' 'click .icon-edit': 'editFoxx',
'click' : 'showDocu'
}, },
initialize: function(){ initialize: function(){
@ -16,6 +17,11 @@ window.FoxxActiveView = Backbone.View.extend({
window.App.navigate("application/installed/" + encodeURIComponent(this.model.get("_key")), {trigger: true}); window.App.navigate("application/installed/" + encodeURIComponent(this.model.get("_key")), {trigger: true});
}, },
showDocu: function(event) {
event.stopPropagation();
window.App.navigate("application/documentation/" + encodeURIComponent(this.model.get("_key")), {trigger: true});
},
render: function(){ render: function(){
$(this.el).html(this.template.render(this.model)); $(this.el).html(this.template.render(this.model));
return $(this.el); return $(this.el);

View File

@ -93,7 +93,14 @@
app.get("/foxxes/thumbnail/:app", function (req, res) { app.get("/foxxes/thumbnail/:app", function (req, res) {
res.transformations = [ "base64decode" ]; res.transformations = [ "base64decode" ];
res.body = repositories.foxxes.thumbnail(req.params("app")); res.body = repositories.foxxes.thumbnail(req.params("app"));
}); }).pathParam("app", {
description: "The appname which is used to identify the foxx in the list of available foxxes.",
dataType: "string",
required: true,
allowMultiple: false
}).nickname("thumbnails")
.summary("Get the thumbnail of a foxx.")
.notes("Used to request the thumbnail of the given Foxx in order to display it on the screen.");
app.get('/foxxes', function (req, res) { app.get('/foxxes', function (req, res) {
@ -109,13 +116,22 @@
.notes("This function simply returns the list of all running" .notes("This function simply returns the list of all running"
+ " foxxes and supplies the paths for the swagger documentation"); + " foxxes and supplies the paths for the swagger documentation");
app.get('/docus/*', function(req, res) { app.get("/docu/:key",function (req, res) {
var subPath = req.path.substr(0,req.path.lastIndexOf("[")-1),
key = req.params("key"),
path = "http://" + req.headers.host + subPath + "/" + key + "/";
res.json(repositories.docus.listOne(path, key));
}).nickname("swaggers")
.summary("List documentation of all foxxes.")
.notes("This function simply returns one specific"
+ " foxx and supplies the paths for the swagger documentation");
app.get('/docu/:key/*', function(req, res) {
var mountPoint = ""; var mountPoint = "";
require("underscore").each(req.suffix, function(part) { require("underscore").each(req.suffix, function(part) {
mountPoint += "/" + part; mountPoint += "/" + part;
}); });
//require("console").log(JSON.stringify(req));
res.json(repositories.docus.show(mountPoint)) res.json(repositories.docus.show(mountPoint))
}).pathParam("appname", { }).pathParam("appname", {
description: "The mount point of the App the documentation should be requested for", description: "The mount point of the App the documentation should be requested for",

View File

@ -4,5 +4,6 @@
"apps": { "apps": {
"/": "aardvark.js" "/": "aardvark.js"
} },
"lib": "."
} }

View File

@ -67,17 +67,12 @@
}, },
install: function (name, mount, version) { install: function (name, mount, version) {
require("console").log(name);
require("console").log(mount);
require("console").log(version);
return foxxmanager.installApp(name, mount, version); return foxxmanager.installApp(name, mount, version);
}, },
// Define the functionality to uninstall an installed foxx // Define the functionality to uninstall an installed foxx
uninstall: function (key) { uninstall: function (key) {
return Foxx.uninstallApp(key); return foxxmanager.uninstallApp(key);
}, },
// Define the functionality to deactivate an installed foxx. // Define the functionality to deactivate an installed foxx.

View File

@ -62,8 +62,20 @@
return result; return result;
}, },
listOne: function(basePath, key) {
var result = {},
res = db._collection("_aal").document(key);
result.swaggerVersion = "1.1";
result.basePath = basePath;
result.apis = [
{path: res.mount}
];
return result;
},
// Get details of one specific installed foxx. // Get details of one specific installed foxx.
show: function(appname) { show: function(appname) {
require("console").log(appname);
var result = {}, var result = {},
apis = [], apis = [],
pathes, pathes,