save synapses to map in saveToMap function wasn't working, but it is now

This commit is contained in:
Devin Howard 2013-01-07 23:03:29 -05:00
parent 3f1d9ddda5
commit 1fed4d2f06
2 changed files with 16 additions and 6 deletions

View file

@ -115,14 +115,24 @@ function saveLayout(id) {
// this is to save your console to a map // this is to save your console to a map
function saveToMap() { function saveToMap() {
var nodes_data = "", syapses_data = ""; var nodes_data = "", synapses_data = "";
var synapses_array = new Array();
Mconsole.graph.eachNode(function(n) { Mconsole.graph.eachNode(function(n) {
nodes_data += n.id + '/' + n.pos.x + '/' + n.pos.y + ','; nodes_data += n.id + '/' + n.pos.x + '/' + n.pos.y + ',';
n.eachAdjacency(function(adj) {
synapses_array.push(adj.getData("id"));
});
}); });
Mconsole.graph.eachAdjacence(function(adj) {
synapses_data += adj.id + ','; //get unique values only
} synapses_array = $.grep(synapses_array, function(value, key){
return $.inArray(value, synapses_array) === key;
});
synapses_data = synapses_array.join();
console.log(synapses_data);
nodes_data = nodes_data.slice(0, -1); nodes_data = nodes_data.slice(0, -1);
$('#map_topicsToMap').val(nodes_data); $('#map_topicsToMap').val(nodes_data);
$('#map_synapsesToMap').val(synapses_data); $('#map_synapsesToMap').val(synapses_data);
$('#new_map').fadeIn('fast'); $('#new_map').fadeIn('fast');

View file

@ -78,12 +78,12 @@ class MapsController < ApplicationController
if params[:map][:synapsesToMap] if params[:map][:synapsesToMap]
@synAll = params[:map][:synapsesToMap] @synAll = params[:map][:synapsesToMap]
@synAll = @synAll.split(',') @synAll = @synAll.split(',')
@synAll.each do |synapse| @synAll.each do |synapse_id|
@mapping = Mapping.new() @mapping = Mapping.new()
@mapping.category = "Synapse" @mapping.category = "Synapse"
@mapping.user = @user @mapping.user = @user
@mapping.map = @map @mapping.map = @map
@mapping.synapse = Synapse.find(synapse[0]) @mapping.synapse = Synapse.find(synapse_id)
@mapping.save @mapping.save
end end
end end