diff --git a/app/assets/javascripts/Jit/ForceDirected/metamap.js b/app/assets/javascripts/Jit/ForceDirected/metamap.js index 7f4043ce..46312229 100644 --- a/app/assets/javascripts/Jit/ForceDirected/metamap.js +++ b/app/assets/javascripts/Jit/ForceDirected/metamap.js @@ -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 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1fa65463..f9a37481 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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; + } + }); }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 9b503211..7f9141cb 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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; } diff --git a/app/assets/stylesheets/base.css b/app/assets/stylesheets/base.css index 9f55e8bd..085fef08 100644 --- a/app/assets/stylesheets/base.css +++ b/app/assets/stylesheets/base.css @@ -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; } diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index ac1bf8bf..cb05033c 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -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 diff --git a/app/models/item.rb b/app/models/item.rb index 70e308a7..06550adc 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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 diff --git a/app/views/items/_item.html.erb b/app/views/items/_item.html.erb index f04abd70..253f9468 100644 --- a/app/views/items/_item.html.erb +++ b/app/views/items/_item.html.erb @@ -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' %> diff --git a/app/views/items/_new.html.erb b/app/views/items/_new.html.erb new file mode 100644 index 00000000..ac764990 --- /dev/null +++ b/app/views/items/_new.html.erb @@ -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 %> \ No newline at end of file diff --git a/app/views/items/create.js.erb b/app/views/items/create.js.erb new file mode 100644 index 00000000..59b9011d --- /dev/null +++ b/app/views/items/create.js.erb @@ -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(); \ No newline at end of file diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb index fa7d4916..0c0797b3 100644 --- a/app/views/items/index.html.erb +++ b/app/views/items/index.html.erb @@ -9,3 +9,5 @@ <% end %> </div> <div class="clearfloat"></div> + +<%= render :partial => 'items/new' %> \ No newline at end of file diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index bb3b714d..ae15e3a7 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -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> \ No newline at end of file +</script> + +<%= render :partial => 'items/new' %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 98476fe1..1ad17f2f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -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> diff --git a/app/views/main/home.html.erb b/app/views/main/home.html.erb index 2d72ab10..09609957 100644 --- a/app/views/main/home.html.erb +++ b/app/views/main/home.html.erb @@ -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' %> diff --git a/app/views/main/userobjects.html.erb b/app/views/main/userobjects.html.erb index cf5bbeb4..c84f308e 100644 --- a/app/views/main/userobjects.html.erb +++ b/app/views/main/userobjects.html.erb @@ -7,3 +7,5 @@ <% end %> </div> <div class="clearfloat"></div> + +<%= render :partial => 'items/new' %> diff --git a/app/views/main/usersynapses.html.erb b/app/views/main/usersynapses.html.erb index a9b343bc..9e72dcbd 100644 --- a/app/views/main/usersynapses.html.erb +++ b/app/views/main/usersynapses.html.erb @@ -9,8 +9,9 @@ <script> json = <%= @synapsesjson %>; - console.log(json); $(document).ready(function() { init(); }); </script> + +<%= render :partial => 'items/new' %>