mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: EventDispatchion for edge-creation finished
This commit is contained in:
parent
33abdae1f0
commit
9cb974531b
|
@ -71,14 +71,38 @@ function EventDispatcher(nodeShaper, edgeShaper, config) {
|
||||||
if (eventlib.checkEdgeEditorConfig(config)) {
|
if (eventlib.checkEdgeEditorConfig(config)) {
|
||||||
var insert = new eventlib.InsertEdge(config),
|
var insert = new eventlib.InsertEdge(config),
|
||||||
patch = new eventlib.PatchEdge(config),
|
patch = new eventlib.PatchEdge(config),
|
||||||
del = new eventlib.DeleteEdge(config);
|
del = new eventlib.DeleteEdge(config),
|
||||||
/*
|
edgeStart = null,
|
||||||
self.events.CREATEEDGE = function(callback) {
|
didInsert = false;
|
||||||
return function() {
|
|
||||||
insert(callback);
|
self.events.STARTCREATEEDGE = function(callback) {
|
||||||
|
return function(node) {
|
||||||
|
edgeStart = node;
|
||||||
|
didInsert = false;
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
self.events.CANCELCREATEEDGE = function(callback) {
|
||||||
|
return function() {
|
||||||
|
edgeStart = null;
|
||||||
|
if (callback !== undefined && !didInsert) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
self.events.FINISHCREATEEDGE = function(callback) {
|
||||||
|
return function(node) {
|
||||||
|
if (edgeStart !== null && node !== edgeStart) {
|
||||||
|
insert(edgeStart, node, callback);
|
||||||
|
didInsert = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
self.events.PATCHEDGE = function(edge, getNewData, callback) {
|
self.events.PATCHEDGE = function(edge, getNewData, callback) {
|
||||||
if (!_.isFunction(getNewData)) {
|
if (!_.isFunction(getNewData)) {
|
||||||
throw "Please give a function to extract the new node data";
|
throw "Please give a function to extract the new node data";
|
||||||
|
@ -93,20 +117,6 @@ function EventDispatcher(nodeShaper, edgeShaper, config) {
|
||||||
del(edge, callback);
|
del(edge, callback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
var insert = new eventlib.InsertEdge(config.edgeEditor);
|
|
||||||
self.events.CREATEEDGE = function(callback) {
|
|
||||||
return function() {
|
|
||||||
insert(callback);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
self.events.CREATEEDGE = new eventlib.InsertEdge(config);
|
|
||||||
/*
|
|
||||||
self.events.PATCHEDGE = new eventlib.PatchEdge(config.edgeEditor);
|
|
||||||
self.events.DELETEEDGE = new eventlib.DeleteEdge(config.edgeEditor);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -521,16 +521,44 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to bind the create edge event', function() {
|
it('should be able to bind the events to create an edge', function() {
|
||||||
|
nodes = [{_id: 1}, {_id: 2}, {_id: 3}];
|
||||||
|
edges = [{source: nodes[0], target: nodes[2]}];
|
||||||
|
nodeShaper.drawNodes(nodes);
|
||||||
|
edgeShaper.drawEdges(edges);
|
||||||
|
|
||||||
|
var started = 0,
|
||||||
|
canceled = 0;
|
||||||
|
|
||||||
runs(function() {
|
runs(function() {
|
||||||
dispatcher.bind($("svg"), "click", dispatcher.events.CREATEEDGE(
|
dispatcher.bind("nodes", "mousedown", dispatcher.events.STARTCREATEEDGE(
|
||||||
|
function() {
|
||||||
|
started++;
|
||||||
|
}
|
||||||
|
));
|
||||||
|
dispatcher.bind("nodes", "mouseup", dispatcher.events.FINISHCREATEEDGE(
|
||||||
function() {
|
function() {
|
||||||
// Never reached as the spy stops propagation
|
// Never reached as the spy stops propagation
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
dispatcher.bind($("svg"), "mouseup", dispatcher.events.CANCELCREATEEDGE(
|
||||||
|
function() {
|
||||||
|
return canceled++;
|
||||||
|
}
|
||||||
|
));
|
||||||
|
helper.simulateMouseEvent("mousedown", "1");
|
||||||
|
helper.simulateMouseEvent("mouseup", "svg");
|
||||||
|
|
||||||
|
helper.simulateMouseEvent("mousedown", "1");
|
||||||
|
helper.simulateMouseEvent("mouseup", "1-3");
|
||||||
|
|
||||||
|
helper.simulateMouseEvent("mousedown", "1");
|
||||||
|
helper.simulateMouseEvent("mouseup", "1");
|
||||||
|
|
||||||
|
helper.simulateMouseEvent("mousedown", "1");
|
||||||
|
helper.simulateMouseEvent("mouseup", "2");
|
||||||
|
|
||||||
helper.simulateMouseEvent("click", "svg");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
waitsFor(function() {
|
waitsFor(function() {
|
||||||
|
@ -538,7 +566,13 @@
|
||||||
}, 1000, "The event should have been triggered.");
|
}, 1000, "The event should have been triggered.");
|
||||||
|
|
||||||
runs(function() {
|
runs(function() {
|
||||||
expect(true).toBeTruthy();
|
expect(started).toEqual(4);
|
||||||
|
expect(canceled).toEqual(3);
|
||||||
|
expect(adapter.createEdge.calls.length).toEqual(1);
|
||||||
|
expect(adapter.createEdge).toHaveBeenCalledWith({
|
||||||
|
source: nodes[0],
|
||||||
|
target: nodes[1]
|
||||||
|
}, jasmine.any(Function));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue