changed node adding so that it happens directly to the graph
This commit is contained in:
parent
b6260d7015
commit
480a9bcf99
15 changed files with 60 additions and 35 deletions
|
@ -1,4 +1,4 @@
|
|||
var labelType, useGradients, nativeTextSupport, animate, json;
|
||||
var labelType, useGradients, nativeTextSupport, animate, json, fd;
|
||||
|
||||
(function() {
|
||||
var ua = navigator.userAgent,
|
||||
|
@ -67,7 +67,7 @@ function init(){
|
|||
});
|
||||
// end
|
||||
// init ForceDirected
|
||||
var fd = new $jit.ForceDirected({
|
||||
fd = new $jit.ForceDirected({
|
||||
//id of the visualization container
|
||||
injectInto: 'infovis',
|
||||
//Enable zooming and panning
|
||||
|
|
|
@ -19,6 +19,14 @@
|
|||
|
||||
$(document).ready(function() {
|
||||
$('.nodemargin').css('padding-top',$('.focus').css('height'));
|
||||
|
||||
$('#newtopic').click(function(event){
|
||||
obj = $('#new_item');
|
||||
if (obj != null) {
|
||||
$('#new_item').fadeIn('fast');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote,
|
|||
pre, form, fieldset, table, th, td, legend { margin: 0; padding: 0; }
|
||||
img {border:0; padding:0; margin:0; display:block; text-indent:-9999px;}
|
||||
|
||||
html, body, .main, .wrapper, .home { height: 100%; }
|
||||
|
||||
html { }
|
||||
body { background:#031924 url(background2.jpg) repeat 0 0; font-family:Arial, Helvetica, sans-serif; background-attachment:fixed; color:#FFF; }
|
||||
|
||||
|
@ -28,7 +30,10 @@ h2 {display:block; text-align:center; background: #333; font-size:24px;}
|
|||
a {color:#2d6a5d; text-decoration:none;}
|
||||
.clearfloat {clear:both;}
|
||||
|
||||
.new_session, .new_item, .new_synapse, .edit_item, .edit_synapse { display: block; width: 350px; margin: 0 auto; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; }
|
||||
.new_session, .new_synapse, .edit_item, .edit_synapse { display: block; width: 350px; margin: 0 auto; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; }
|
||||
|
||||
.new_item { display: none; position:absolute; left:50%; top:50%; margin:-175px 0 0 -195px; width: 350px; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; border:2px solid #000; }
|
||||
|
||||
|
||||
label, select, input, textarea { display:block; }
|
||||
|
||||
|
@ -41,7 +46,7 @@ input[type="submit"] { margin-top:5px; }
|
|||
.contentarea ul {margin:0 0 0 1em; }
|
||||
.contentarea ol {margin:0 0 0 1.3em; }
|
||||
|
||||
.main { }
|
||||
.main { overflow:hidden; }
|
||||
|
||||
.headertop { display:block; position:fixed; top:0; left:0; z-index:10; height:38px; width:100%; min-width:622px; background: url(topbg2.png) repeat-x top left; }
|
||||
#mainTitle { float: left; }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#center-container {
|
||||
position:relative;
|
||||
height:800px;
|
||||
width:95%;
|
||||
height:100%;
|
||||
width:100%;
|
||||
/* background-color:#031924; */
|
||||
color:#ccc;
|
||||
}
|
||||
|
@ -26,8 +26,8 @@
|
|||
#infovis {
|
||||
position:relative;
|
||||
width:100%;
|
||||
height:800px;
|
||||
margin:0 0 0 50px;
|
||||
height:100%;
|
||||
margin:0;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class ItemsController < ApplicationController
|
|||
@user = current_user
|
||||
@items = Item.all
|
||||
|
||||
respond_with(@items)
|
||||
respond_with(@items,@user)
|
||||
end
|
||||
|
||||
# Get /item/new
|
||||
|
@ -22,12 +22,13 @@ class ItemsController < ApplicationController
|
|||
|
||||
# GET /item/:id
|
||||
def show
|
||||
@user = current_user
|
||||
@item = Item.find(params[:id])
|
||||
|
||||
@relatives = @item.map_as_json.html_safe
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@item) }
|
||||
format.html { respond_with(@item, @user) }
|
||||
format.json { respond_with(@relatives) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,28 +20,14 @@ belongs_to :item_category
|
|||
|
||||
def self_as_json
|
||||
Jbuilder.encode do |json|
|
||||
@single = Array.new
|
||||
@single.push(self)
|
||||
|
||||
json.array!(@single) do |item|
|
||||
json.adjacencies item.synapses2.delete_if{|synapse| not @items.include?(Item.find_by_id(synapse.node1_id))} do |json, synapse|
|
||||
json.nodeTo synapse.node1_id
|
||||
json.nodeFrom synapse.node2_id
|
||||
|
||||
@synapsedata = Hash.new
|
||||
@synapsedata['$desc'] = synapse.desc
|
||||
@synapsedata['$category'] = synapse.category
|
||||
json.data @synapsedata
|
||||
end
|
||||
|
||||
@itemdata = Hash.new
|
||||
@itemdata['$desc'] = item.desc
|
||||
@itemdata['$link'] = item.link
|
||||
@itemdata['$itemcatname'] = item.item_category.name
|
||||
@itemdata['$desc'] = self.desc
|
||||
@itemdata['$link'] = self.link
|
||||
@itemdata['$itemcatname'] = self.item_category.name
|
||||
json.data @itemdata
|
||||
json.id item.id
|
||||
json.name item.name
|
||||
end
|
||||
json.id self.id
|
||||
json.name self.name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%= div_for item do %>
|
||||
<%= link_to 'Delete', item, :class => 'delete', :confirm => 'Delete this topic and all synapses linking to it?', :method => :delete, :remote => true%>
|
||||
<% if @user %><%= link_to 'Delete', item, :class => 'delete', :confirm => 'Delete this topic and all synapses linking to it?', :method => :delete, :remote => true%><% end %>
|
||||
<p class="type"><%= item.item_category.name %></p>
|
||||
<%= image_tag item.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||
<%= link_to item.name, item_url(item), :class => 'title' %>
|
||||
|
|
12
app/views/items/_new.html.erb
Normal file
12
app/views/items/_new.html.erb
Normal file
|
@ -0,0 +1,12 @@
|
|||
<%= form_for Item.new, url: items_path, remote: true do |form| %>
|
||||
<h3>Add Item</h3>
|
||||
<label for="category">Category</label>
|
||||
<%= select_tag "category", options_from_collection_for_select(ItemCategory.all, "id", "name") %>
|
||||
<label for="item_name">Title</label>
|
||||
<%= form.text_field :name %>
|
||||
<label for="item_desc">Description</label>
|
||||
<%= form.text_area :desc, class: "description", :rows => 5 %>
|
||||
<label for="item_link">Link</label>
|
||||
<%= form.text_field :link, class: "link" %>
|
||||
<%= form.submit "Add Item", class: "add" %>
|
||||
<% end %>
|
5
app/views/items/create.js.erb
Normal file
5
app/views/items/create.js.erb
Normal file
|
@ -0,0 +1,5 @@
|
|||
$('#new_item').fadeOut('fast');
|
||||
var newnode = <%= @item.self_as_json.html_safe %>;
|
||||
console.log(newnode);
|
||||
fd.graph.addNode(newnode);
|
||||
fd.plot();
|
|
@ -9,3 +9,5 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<div class="clearfloat"></div>
|
||||
|
||||
<%= render :partial => 'items/new' %>
|
|
@ -5,7 +5,7 @@
|
|||
<%= image_tag @item.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||
</div>
|
||||
<div class="focusmiddle">
|
||||
<h1 class="title"><%= @item.name %> <%= link_to "[edit]", edit_item_path(@item) %></h1>
|
||||
<h1 class="title"><%= @item.name %> <% if @user %><%= link_to "[edit]", edit_item_path(@item) %><% end %></h1>
|
||||
<div class="desc">
|
||||
<p><%= @item.desc %></p>
|
||||
</div>
|
||||
|
@ -32,4 +32,6 @@
|
|||
$(document).ready(function() {
|
||||
init();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<%= render :partial => 'items/new' %>
|
|
@ -26,7 +26,7 @@
|
|||
<li>|</li>
|
||||
<li><%= link_to "Add Synapse", new_synapse_path %></li>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Add Topic", new_item_path %></li>
|
||||
<li><%= link_to "Add Topic", new_item_path, id: "newtopic" %></li>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Topics", items_path %></li>
|
||||
</ul>
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
<div class="clearfloat"></div>
|
||||
<script>
|
||||
json = <%= @alljson %>;
|
||||
console.log(json);
|
||||
$(document).ready(function() {
|
||||
init();
|
||||
});
|
||||
|
@ -18,3 +17,5 @@
|
|||
<% if @item.nil? %>
|
||||
<p><br>Shucks, there is nothing in metamaps.<p>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => 'items/new' %>
|
||||
|
|
|
@ -7,3 +7,5 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<div class="clearfloat"></div>
|
||||
|
||||
<%= render :partial => 'items/new' %>
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
|
||||
<script>
|
||||
json = <%= @synapsesjson %>;
|
||||
console.log(json);
|
||||
$(document).ready(function() {
|
||||
init();
|
||||
});
|
||||
</script>
|
||||
|
||||
<%= render :partial => 'items/new' %>
|
||||
|
|
Loading…
Reference in a new issue