fixed delete map bug. made it so that if the user hasn't saved a layout to a map, it continues to render as forcedirected

This commit is contained in:
Connor Turland 2012-12-03 18:40:14 -05:00
parent cfe7966958
commit 30b5b94037
9 changed files with 49 additions and 20 deletions

View file

@ -320,18 +320,6 @@ function initMAP(){
}); });
$(document).ready(function() { $(document).ready(function() {
var coor = "";
$("#saveLayout").click(function(event) {
event.preventDefault();
coor = "";
map.graph.eachNode(function(n) {
coor = coor + n.data.$mappingid + '/' + n.pos.x + '/' + n.pos.y + ',';
});
coor = coor.slice(0, -1);
$('#map_coordinates').val(coor);
$('#saveMapLayout').submit();
});
map.animate({ map.animate({
modes: ['linear'], modes: ['linear'],
transition: $jit.Trans.Quad.easeInOut, transition: $jit.Trans.Quad.easeInOut,

View file

@ -219,6 +219,26 @@
} }
} }
}); });
// this is to save the layout of maps
var coor = "";
$("#saveLayout").click(function(event) {
event.preventDefault();
coor = "";
if (map != null) {
map.graph.eachNode(function(n) {
coor = coor + n.data.$mappingid + '/' + n.pos.x + '/' + n.pos.y + ',';
});
}
else if (fd != null) {
fd.graph.eachNode(function(n) {
coor = coor + n.data.$mappingid + '/' + n.pos.x + '/' + n.pos.y + ',';
});
}
coor = coor.slice(0, -1);
$('#map_coordinates').val(coor);
$('#saveMapLayout').submit();
});
}); });

View file

@ -47,7 +47,7 @@ class MapsController < ApplicationController
@user = current_user @user = current_user
@map = Map.create(params[:map]) @map = Map.create(params[:map])
@map.user = @user @map.user = @user
@map.arranged = false
@map.save @map.save
respond_to do |format| respond_to do |format|
@ -110,6 +110,8 @@ class MapsController < ApplicationController
@mapping.yloc = item[2] @mapping.yloc = item[2]
@mapping.save @mapping.save
end end
@map.arranged = true
@map.save
end end
end end
@ -127,7 +129,8 @@ class MapsController < ApplicationController
@map.delete @map.delete
respond_with(location: user_maps_path(@user)) do |format| respond_to do |format|
format.js
end end
end end

View file

@ -6,13 +6,18 @@ map2 = document.getElementById('container');
if (map2 != null) { if (map2 != null) {
var newnode = <%= @item.self_as_json.html_safe %>; var newnode = <%= @item.self_as_json.html_safe %>;
console.log(newnode);
if (fd != null) { if (fd != null) {
fd.graph.addNode(newnode); fd.graph.addNode(newnode);
var temp = fd.graph.getNode('<%= @item.id %>'); var temp = fd.graph.getNode('<%= @item.id %>');
temp.setData('dim', 1, 'start'); temp.setData('dim', 1, 'start');
temp.setData('dim', 40, 'end'); temp.setData('dim', 40, 'end');
<% unless (@mapping.nil?) %>
temp.setData('xloc',0);
temp.setData('yloc',0);
temp.setData('mappingid', '<%= @mapping.id %>');
<% end %>
temp.setPos(new $jit.Complex(0, 0), 'current'); temp.setPos(new $jit.Complex(0, 0), 'current');
temp.setPos(new $jit.Complex(0, 0), 'start'); temp.setPos(new $jit.Complex(0, 0), 'start');
temp.setPos(new $jit.Complex(0, 0), 'end'); temp.setPos(new $jit.Complex(0, 0), 'end');
@ -36,7 +41,7 @@ if (map2 != null) {
duration: 400 duration: 400
}); });
} }
if (map != null) { else if (map != null) {
map.graph.addNode(newnode); map.graph.addNode(newnode);
var temp = map.graph.getNode('<%= @item.id %>'); var temp = map.graph.getNode('<%= @item.id %>');
temp.setData('dim', 1, 'start'); temp.setData('dim', 1, 'start');
@ -57,7 +62,8 @@ if (map2 != null) {
json = newnode; json = newnode;
initFD(); initFD();
} }
// add the new node to the synapse select list console.log(temp);
// add the new node to the synapse select lists
$("#node1_id").prepend("<option value='<%= @item.id %>'><%= @item.name %></option>"); $("#node1_id").prepend("<option value='<%= @item.id %>'><%= @item.name %></option>");
$("#node2_id").prepend("<option value='<%= @item.id %>'><%= @item.name %></option>"); $("#node2_id").prepend("<option value='<%= @item.id %>'><%= @item.name %></option>");

View file

@ -1 +1 @@
$('#<%= dom_id(@item) %>').fadeOut('slow'); $('#<%= dom_id(@map) %>').fadeOut('slow');

View file

@ -34,7 +34,11 @@
json = <%= @mapjson %>; json = <%= @mapjson %>;
if (json.length > 0) { if (json.length > 0) {
$(document).ready(function() { $(document).ready(function() {
initMAP(); <% if (@map.arranged) %>
initMAP();
<% else %>
initFD();
<% end %>
}); });
} }
</script> </script>

View file

@ -2,6 +2,7 @@ class CreateMaps < ActiveRecord::Migration
def change def change
create_table :maps do |t| create_table :maps do |t|
t.text :name t.text :name
t.boolean :arranged
t.text :desc t.text :desc
t.text :permission t.text :permission
t.integer :user_id t.integer :user_id

View file

@ -0,0 +1,6 @@
class AddArrangedToMap < ActiveRecord::Migration
def change
add_column :maps, :arranged, :boolean
Map.update_all ["arranged = ?", false]
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121026000731) do ActiveRecord::Schema.define(:version => 20121203225613) do
create_table "item_categories", :force => true do |t| create_table "item_categories", :force => true do |t|
t.text "name" t.text "name"
@ -50,6 +50,7 @@ ActiveRecord::Schema.define(:version => 20121026000731) do
t.integer "user_id" t.integer "user_id"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.boolean "arranged"
end end
create_table "synapses", :force => true do |t| create_table "synapses", :force => true do |t|