From 567a548cff85f4ca5aae5a5ee8230c7b08359126 Mon Sep 17 00:00:00 2001 From: Lucas Dohmen Date: Fri, 7 Jun 2013 14:55:34 +0200 Subject: [PATCH] Tearing appart Graph#addEdge and fixing the build even harder --- js/client/modules/org/arangodb/graph.js | 17 +----- .../modules/org/arangodb/graph-common.js | 54 +++++++++++++++++++ js/server/modules/org/arangodb/graph.js | 47 +--------------- 3 files changed, 57 insertions(+), 61 deletions(-) diff --git a/js/client/modules/org/arangodb/graph.js b/js/client/modules/org/arangodb/graph.js index fa6fbc6869..9652ed2b1f 100644 --- a/js/client/modules/org/arangodb/graph.js +++ b/js/client/modules/org/arangodb/graph.js @@ -424,25 +424,10 @@ Graph.prototype.drop = function () { /// @brief adds an edge to the graph //////////////////////////////////////////////////////////////////////////////// -Graph.prototype.addEdge = function (out_vertex, in_vertex, id, label, data) { - var requestResult; - var params; - var key; - - if (data === null || typeof data !== "object") { - params = {}; - } else { - params = data._shallowCopy || {}; - } - +Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, params) { params._key = id; params._from = out_vertex._properties._key; params._to = in_vertex._properties._key; - params.$label = label; - - if (is.notExisty(params.$label) && is.existy(data) && is.existy(data.$label)) { - params.$label = data.$label; - } requestResult = this._connection.POST("/_api/graph/" + encodeURIComponent(this._properties._key) + "/edge", diff --git a/js/common/modules/org/arangodb/graph-common.js b/js/common/modules/org/arangodb/graph-common.js index 40b3078cba..c3247b2cf4 100644 --- a/js/common/modules/org/arangodb/graph-common.js +++ b/js/common/modules/org/arangodb/graph-common.js @@ -29,6 +29,7 @@ //////////////////////////////////////////////////////////////////////////////// var arangodb = require("org/arangodb"), + is = require("org/arangodb/is"), Edge, Graph, Vertex, @@ -568,6 +569,59 @@ Graph.prototype.getOrAddVertex = function (id) { return v; }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief adds an edge to the graph +/// +/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id})} +/// +/// Creates a new edge from @FA{out} to @FA{in} and returns the edge object. The +/// identifier @FA{id} must be a unique identifier or null. +/// +/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{label})} +/// +/// Creates a new edge from @FA{out} to @FA{in} with @FA{label} and returns the +/// edge object. +/// +/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{data})} +/// +/// Creates a new edge and returns the edge object. The edge contains the +/// properties defined in @FA{data}. +/// +/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{label}, @FA{data})} +/// +/// Creates a new edge and returns the edge object. The edge has the +/// label @FA{label} and contains the properties defined in @FA{data}. +/// +/// @EXAMPLES +/// +/// @verbinclude graph-graph-add-edge +/// +/// @verbinclude graph-graph-add-edge2 +//////////////////////////////////////////////////////////////////////////////// + +Graph.prototype.addEdge = function (out_vertex, in_vertex, id, label, data, waitForSync) { + var params; + + if (is.notExisty(data) && typeof label === 'object') { + data = label; + label = null; + } + + if (is.notExisty(label) && is.existy(data) && is.existy(data.$label)) { + label = data.$label; + } + + if (data === null || typeof data !== "object") { + params = {}; + } else { + params = data._shallowCopy || {}; + } + + params.$label = label; + + return this._saveEdge(id, out_vertex, in_vertex, params, waitForSync); +}; + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/js/server/modules/org/arangodb/graph.js b/js/server/modules/org/arangodb/graph.js index 25f84614e0..cd13cedcaa 100644 --- a/js/server/modules/org/arangodb/graph.js +++ b/js/server/modules/org/arangodb/graph.js @@ -639,60 +639,17 @@ Graph.prototype.drop = function (waitForSync) { //////////////////////////////////////////////////////////////////////////////// /// @brief adds an edge to the graph -/// -/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id})} -/// -/// Creates a new edge from @FA{out} to @FA{in} and returns the edge object. The -/// identifier @FA{id} must be a unique identifier or null. -/// -/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{label})} -/// -/// Creates a new edge from @FA{out} to @FA{in} with @FA{label} and returns the -/// edge object. -/// -/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{data})} -/// -/// Creates a new edge and returns the edge object. The edge contains the -/// properties defined in @FA{data}. -/// -/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{label}, @FA{data})} -/// -/// Creates a new edge and returns the edge object. The edge has the -/// label @FA{label} and contains the properties defined in @FA{data}. -/// -/// @EXAMPLES -/// -/// @verbinclude graph-graph-add-edge -/// -/// @verbinclude graph-graph-add-edge2 //////////////////////////////////////////////////////////////////////////////// -Graph.prototype.addEdge = function (out_vertex, in_vertex, id, label, data, waitForSync) { - var ref; - var shallow; - +Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, shallow, waitForSync) { this.emptyCachedPredecessors(); - if (data === null || typeof data !== "object") { - shallow = {}; - } - else { - shallow = data._shallowCopy || {}; - } - if (id !== undefined && id !== null) { shallow._key = String(id); } - shallow.$label = label; - - if (is.notExisty(shallow.$label) && is.existy(data) && is.existy(data.$label)) { - shallow.$label = data.$label; - } - - ref = this._edges.save(out_vertex._properties._id, + ref = this._edges.save(out_vertex._properties._id, in_vertex._properties._id, shallow, waitForSync); - return this.constructEdge(ref._id); };