summaryrefslogtreecommitdiff
path: root/src/client/model
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-07-23 18:14:09 +0300
committerAlon Levy <alon@pobox.com>2015-07-23 18:14:09 +0300
commit78189c857fdf52854fc8b32352f6fa869e0af013 (patch)
tree8a85bd7e7437bb5e5e9ee976cf61b2b74930467e /src/client/model
parent4d0e41af93f8ee35adb9e0b9cc1e0cc7330d9704 (diff)
client/model/graph: linting fixes from emacs js2 mode (jshint probably)
Diffstat (limited to 'src/client/model')
-rw-r--r--src/client/model/graph.js155
1 files changed, 77 insertions, 78 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js
index 46e05030..5beca9e0 100644
--- a/src/client/model/graph.js
+++ b/src/client/model/graph.js
@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-"use strict"
+"use strict";
define(['underscore', 'Bacon', 'consts', 'util', 'model/core', 'model/util', 'model/diff', 'rz_api_backend', 'rz_api_mesh', 'history', 'model/types'],
function (_, Bacon, consts, util, model_core, model_util, model_diff, rz_api_backend, rz_api_mesh, history, model_types) {
@@ -61,13 +61,13 @@ function Graph(spec) {
for (var link_key in id_to_link_map) {
f(id_to_link_map[link_key]);
}
- }
+ };
var nodes_forEach = function (f) {
for (var node_key in id_to_node_map) {
f(id_to_node_map[node_key]);
}
- }
+ };
function key_count(obj) {
return _.keys(obj).length;
@@ -75,7 +75,7 @@ function Graph(spec) {
var degree = function (node) {
return key_count(id_to_link_id_set[node.id]);
- }
+ };
this.degree = degree;
/**
@@ -87,7 +87,7 @@ function Graph(spec) {
if (temporary) {
this.addTempNode = function(spec) {
return this.__addNode(spec);
- }
+ };
}
var nodes_to_touched_links = function (node_id_set) {
@@ -104,7 +104,7 @@ function Graph(spec) {
console.dir(touched_links);
return touched_links.map(function(l){ return l.id; });
- }
+ };
/**
*
@@ -153,7 +153,7 @@ function Graph(spec) {
});
rz_api_backend.commit_diff__topo(topo_diff, __commit_diff_ajax__topo);
- }
+ };
this.commit_and_tx_diff__topo = commit_and_tx_diff__topo;
/**
@@ -166,7 +166,7 @@ function Graph(spec) {
node;
if (undefined == spec.id) {
- existing_node = find_node__by_name(spec.name)
+ existing_node = find_node__by_name(spec.name);
if (existing_node){
return existing_node;
} else {
@@ -200,14 +200,14 @@ function Graph(spec) {
delete id_to_node_map[node_id];
delete id_to_link_id_set[node_id];
invalidate_nodes = true;
- }
+ };
var _node_add_helper = function (node) {
util.assert(node.id, "missing node id");
id_to_node_map[node.id] = node;
id_to_link_id_set[node.id] = [];
invalidate_nodes = true;
- }
+ };
var _link_remove_helper = function (link_id) {
var link = id_to_link_map[link_id],
@@ -221,7 +221,7 @@ function Graph(spec) {
delete id_to_link_map[link_id];
util.assert(id_to_link_map[link_id] === undefined, "delete failed?!");
invalidate_links = true;
- }
+ };
var _link_add_helper = function (link) {
var src_id = link.__src.id,
@@ -238,7 +238,7 @@ function Graph(spec) {
id_to_link_id_set[src_id][dst_id] = 1;
id_to_link_id_set[dst_id][src_id] = 1;
invalidate_links = true;
- }
+ };
var _remove_node_set = function(node_id_set) {
node_id_set.forEach(function (id) {
@@ -249,7 +249,7 @@ function Graph(spec) {
_node_remove_helper(id);
console.log('_remove_node_set: ' + id);
});
- }
+ };
this._remove_node_set = _remove_node_set;
function calc_neighbours() {
@@ -424,7 +424,7 @@ function Graph(spec) {
if (start === undefined) {
console.log('neighbourhood: bug: called with undefined node');
- return;
+ return ret;
}
if (d > 1) {
console.log('neighbourhood: bug: not implemented for d == ' + d);
@@ -489,7 +489,7 @@ function Graph(spec) {
});
});
return ret;
- }
+ };
/* compareSubset:
* state: one of the optional states that defines a subgraph
@@ -559,7 +559,7 @@ function Graph(spec) {
}
}
return {graph_same: true, old_name: changed_nodes.a_b, new_name: changed_nodes.b_a};
- }
+ };
function __addLink(link) {
@@ -585,7 +585,7 @@ function Graph(spec) {
if (temporary) {
this.addTempLink = function (link) {
return __addLink(link);
- }
+ };
}
this.update_link = function(link, new_link_spec, on_success, on_error) {
@@ -600,17 +600,18 @@ function Graph(spec) {
}
var on_ajax_success = function(attr_diff_spec) {
- var attr_diff = model_util.adapt_format_read_diff__attr(attr_diff_spec);
- var id_to_link_map = attr_diff.id_to_link_map
- var l_id = link.id; // original node id
+ var attr_diff = model_util.adapt_format_read_diff__attr(attr_diff_spec),
+ id_to_link_map = attr_diff.id_to_link_map,
+ key,
+ l_id = link.id; // original node id
util.assert(id_to_link_map && id_to_link_map[l_id], "bad return value from ajax");
var ret_link = id_to_link_map[l_id];
- for (var key in ret_link['__attr_write']){
+ for (key in ret_link['__attr_write']){
link[key] = ret_link['__attr_write'][key];
}
- for (var key in ret_link['__attr_remove']){
+ for (key in ret_link['__attr_remove']){
delete link[key];
}
@@ -626,7 +627,7 @@ function Graph(spec) {
};
rz_api_backend.commit_diff__attr(attr_diff, on_ajax_success, on_ajax_error);
- }
+ };
this.update_node = function(node, new_node_spec) {
util.assert(node instanceof model_core.Node);
@@ -641,9 +642,7 @@ function Graph(spec) {
var n_eq_name = find_node__by_name(new_node_spec.name);
if (null !== n_eq_name && n_eq_name !== node) {
if (window.confirm('really merge ' + node.name + ' into ' + n_eq_name.name + '?')) {
- return nodes__merge([n_eq_name.id, node.id]);
- } else {
- return; // do nothing
+ nodes__merge([n_eq_name.id, node.id]);
}
}
@@ -656,17 +655,18 @@ function Graph(spec) {
}
var on_ajax_success = function(attr_diff_spec){
- var attr_diff = model_util.adapt_format_read_diff__attr(attr_diff_spec);
- var id_to_node_map = attr_diff.id_to_node_map
- var n_id = node.id; // original node id
+ var attr_diff = model_util.adapt_format_read_diff__attr(attr_diff_spec),
+ id_to_node_map = attr_diff.id_to_node_map,
+ key,
+ n_id = node.id; // original node id
util.assert(id_to_node_map && id_to_node_map[n_id], "bad return value from ajax");
var ret_node = id_to_node_map[n_id];
- for (var key in ret_node['__attr_write']){
+ for (key in ret_node['__attr_write']){
node[key] = ret_node['__attr_write'][key];
}
- for (var key in ret_node['__attr_remove']){
+ for (key in ret_node['__attr_remove']){
delete node[key];
}
@@ -677,7 +677,7 @@ function Graph(spec) {
console.log('error with commit to server: danger robinson!');
};
rz_api_backend.commit_diff__attr(attr_diff, on_ajax_success, on_ajax_error);
- }
+ };
var update_node = this.update_node;
this.editNameByName = function(old_name, new_name) {
@@ -687,8 +687,8 @@ function Graph(spec) {
console.log('editNameByName: error: cannot find node with name ' + old_name);
return;
}
- return this.editName(node.id, new_name);
- }
+ this.editName(node.id, new_name);
+ };
this.editName = function(id, new_name) {
var n_eq_name = find_node__by_name(new_name);
@@ -705,7 +705,7 @@ function Graph(spec) {
util.assert(n_eq_name === undefined);
n_eq_id.name = new_name;
- }
+ };
/**
* editType:
@@ -714,7 +714,7 @@ function Graph(spec) {
*/
this.editType = function(id, newtype) {
return this._editProperty(id, 'type', newtype);
- }
+ };
function new_attr_diff_prop_value(id, prop, value)
{
@@ -748,17 +748,17 @@ function Graph(spec) {
update_node(n, props);
}
return true;
- }
+ };
this.links__delete = function(link_ids) {
var topo_diff = model_diff.new_topo_diff({link_id_set_rm: link_ids});
this.commit_and_tx_diff__topo(topo_diff);
- }
+ };
this.nodes__delete = function(node_ids) {
var topo_diff = model_diff.new_topo_diff({node_id_set_rm: node_ids});
this.commit_and_tx_diff__topo(topo_diff);
- }
+ };
/**
* links the first node in the list to the rest of the list.
@@ -787,14 +787,14 @@ function Graph(spec) {
.filter(function (src_link) { return src_link.__dst.id !== merge_node_id; })
.map(function (src_link) {
return model_core.create_link__set_random_id(merge_node, src_link.__dst, {
- name: src_link.name,
+ name: src_link.name
});
});
var dst_links = find_link__by_dst_id(node_id)
.filter(function (dst_link) { return dst_link.__src.id !== merge_node_id; })
.map(function (dst_link) {
return model_core.create_link__set_random_id(dst_link.__src, merge_node, {
- name: dst_link.name,
+ name: dst_link.name
});
});
return _.union(src_links, dst_links);
@@ -816,18 +816,18 @@ function Graph(spec) {
_link_remove_helper(id);
console.log('_remove_link_set: ' + id);
});
- }
+ };
this._remove_link_set = _remove_link_set;
this.nodes_rm = function(state) {
var node_ids = get_nodes().filter(function (n) { return n.state == state; })
.map(function (n) { return n.id; }),
topo_diff = model_diff.new_topo_diff({
- node_id_set_rm : node_ids,
+ node_id_set_rm : node_ids
});
this.commit_and_tx_diff__topo(topo_diff);
- }
+ };
var findLink = function(src_id, dst_id, name) {
var link_key, link;
@@ -838,7 +838,8 @@ function Graph(spec) {
return link;
}
}
- }
+ return undefined;
+ };
var find_links__by_nodes = function(nodes) {
var ids = util.set_from_array(_.pluck(nodes, "id"));
@@ -846,7 +847,7 @@ function Graph(spec) {
return get_links().filter(function (link) {
return ids[link.__src.id] && ids[link.__dst.id];
});
- }
+ };
this.find_links__by_nodes = find_links__by_nodes;
var find_links__by_state = function(state) {
@@ -857,7 +858,7 @@ function Graph(spec) {
}
});
return foundLinks;
- }
+ };
var compareNames = function(name1, name2) {
return name1.toLowerCase() === name2.toLowerCase();
@@ -867,7 +868,7 @@ function Graph(spec) {
return get_nodes().filter(function (n) {
return compareNames(n.name, name) && (undefined === state || n.state === state);
}).length > 0;
- }
+ };
this.hasNodeByName = hasNodeByName;
/**
@@ -883,12 +884,12 @@ function Graph(spec) {
}
}
return id_to_node_map[id] || null;
- }
+ };
this.find_node__by_id = find_node__by_id;
var find_nodes__by_id = function(ids, recursive) {
return _.map(ids, function (id) { return find_node__by_id(id, recursive); });
- }
+ };
this.find_nodes__by_id = find_nodes__by_id;
/**
@@ -896,13 +897,13 @@ function Graph(spec) {
*/
var find_nodes__by_filter = function(filter) {
var ret = [];
- nodes.map(function(n){
+ _.values(id_to_node_map).map(function(n) {
if (true == filter(n)){
ret.push(n);
}
});
return ret;
- }
+ };
/**
* @param id unique id of link
@@ -918,7 +919,7 @@ function Graph(spec) {
}
}
return id_to_link_map[id] || null;
- }
+ };
this.find_link__by_id = find_link__by_id;
/**
@@ -928,7 +929,7 @@ function Graph(spec) {
*/
var find_link__by_src_id = function(src_id) {
return _.filter(get_links(), function (link) { return link.__src.id == src_id; });
- }
+ };
this.find_link__by_src_id = find_link__by_src_id;
/**
@@ -938,7 +939,7 @@ function Graph(spec) {
*/
var find_link__by_dst_id = function(dst_id) {
return _.filter(get_links(), function (link) { return link.__dst.id == dst_id; });
- }
+ };
this.find_link__by_dst_id = find_link__by_dst_id;
@@ -957,7 +958,7 @@ function Graph(spec) {
}
}
return null;
- }
+ };
this.find_node__by_name = find_node__by_name;
var find_nodes__by_state = function(state) {
@@ -968,7 +969,7 @@ function Graph(spec) {
}
});
return foundNodes;
- }
+ };
function clear(push_diff) {
push_diff = push_diff === undefined ? true : push_diff;
@@ -997,7 +998,7 @@ function Graph(spec) {
}
rz_api_mesh.broadcast_possible_next_diff_block(diff_set);
- }
+ };
function on_backend__node_add(n_spec) {
n_spec = model_util.adapt_format_read_node(n_spec);
@@ -1115,8 +1116,9 @@ function Graph(spec) {
// process nodes
attr_diff.for_each_node(function(n_id, n_attr_diff) {
+ var attr_key,
+ node = id_to_node_map[n_id];
- var node = id_to_node_map[n_id];
if (undefined == node) {
console.warn('commit_diff__attr: incoming attr diff for non-existing node, discarding');
return;
@@ -1124,7 +1126,7 @@ function Graph(spec) {
// apply attr writes: node
var count_w = 0;
- for (var attr_key in n_attr_diff['__attr_write']) {
+ for (attr_key in n_attr_diff['__attr_write']) {
var attr_value = n_attr_diff['__attr_write'][attr_key];
node[attr_key] = attr_value; // write each new attr update
count_w = count_w + 1;
@@ -1132,7 +1134,7 @@ function Graph(spec) {
// apply attr removals: node
var count_d = 0;
- for (var attr_key in n_attr_diff['__attr_remove']) {
+ for (attr_key in n_attr_diff['__attr_remove']) {
delete node[attr_key]; // apply each attr removal
count_d = count_d + 1;
};
@@ -1142,8 +1144,9 @@ function Graph(spec) {
// process links
attr_diff.for_each_link(function(l_id, n_attr_diff) {
+ var attr_key,
+ link = id_to_link_map[l_id];
- var link = id_to_link_map[l_id];
if (undefined == link) {
console.warn('commit_diff__attr: incoming attr diff for non-existing link, discarding');
return;
@@ -1151,7 +1154,7 @@ function Graph(spec) {
// apply attr writes: link
var count_w = 0;
- for (var attr_key in n_attr_diff['__attr_write']) {
+ for (attr_key in n_attr_diff['__attr_write']) {
var attr_value = n_attr_diff['__attr_write'][attr_key];
link[attr_key] = attr_value; // write each new attr update
count_w = count_w + 1;
@@ -1159,7 +1162,7 @@ function Graph(spec) {
// apply attr removals: link
var count_d = 0;
- for (var attr_key in n_attr_diff['__attr_remove']) {
+ for (attr_key in n_attr_diff['__attr_remove']) {
delete link[attr_key]; // apply each attr removal
count_d = count_d + 1;
};
@@ -1199,7 +1202,7 @@ function Graph(spec) {
name: ext_spec.name ? ext_spec.name : ext_spec.id,
type: ext_spec.type,
x: ext_spec.x,
- y: ext_spec.y,
+ y: ext_spec.y
},
node;
@@ -1222,14 +1225,14 @@ function Graph(spec) {
dst = node_by_id[old_id_to_new_id[link_spec.__dst]],
link = model_core.create_link__set_random_id(src, dst, {
name: link_spec.name,
- state: 'perm', // FIXME: this is meaningless now with graph separation
+ state: 'perm' // FIXME: this is meaningless now with graph separation
});
link.__src_id = src.id;
link.__dst_id = dst.id;
return link;
});
return diff;
- }
+ };
this.new_topo_diff__from_nodes_links = new_topo_diff__from_nodes_links;
this.load_from_json = function(json) {
@@ -1241,7 +1244,7 @@ function Graph(spec) {
}
// FIXME: prompt for replace/merge; now defaulting to merge
commit_and_tx_diff__topo(new_topo_diff__from_nodes_links(data.nodes, data.links));
- }
+ };
this.save_to_json = function() {
var d = {"nodes":[], "links":[]},
@@ -1266,13 +1269,13 @@ function Graph(spec) {
});
}
return JSON.stringify(d);
- }
+ };
this.set_user = function(user) {
var elem = $('svg g.zoom')[0];
this.user = user;
this.history = new history.History(this.user, this, elem);
- }
+ };
function clear_history() {
if (this.history !== undefined) {
@@ -1295,7 +1298,7 @@ function Graph(spec) {
var get_node_ids = function() {
return _.keys(id_to_node_map);
- }
+ };
this.get_node_ids = get_node_ids;
var get_links = function() {
@@ -1316,14 +1319,10 @@ function Graph(spec) {
selected_nodes,
selected_links;
- if (!node_visitor && !link_visitor) {
- return;
- }
-
selected_nodes = node_visitor ? nodes.filter(node_visitor) : [];
selected_links = link_visitor ? links.filter(link_visitor) : [];
return {nodes: selected_nodes, links: selected_links};
- }
+ };
function markRelated(names) {
removeRelated();
@@ -1350,7 +1349,7 @@ function Graph(spec) {
filtered_types = new_filtered_types;
invalidate_links = true;
invalidate_nodes = true;
- }
+ };
}
function is_node(item)
@@ -1366,7 +1365,7 @@ function is_link(item)
return {
Graph: Graph,
is_node: is_node,
- is_link: is_link,
+ is_link: is_link
};
});