added ability to add synapses
This commit is contained in:
parent
1144c4c145
commit
4d09fb6fc8
17 changed files with 275 additions and 18 deletions
3
app/assets/javascripts/synapses.js.coffee
Normal file
3
app/assets/javascripts/synapses.js.coffee
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
3
app/assets/stylesheets/synapses.css.scss
Normal file
3
app/assets/stylesheets/synapses.css.scss
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the synapses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -46,7 +46,7 @@ class GroupsController < ApplicationController
|
|||
@group.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: restore(default: group_url(@group))) }
|
||||
format.html { respond_with(@user, location: group_url(@group)) }
|
||||
format.js { respond_with(@group) }
|
||||
end
|
||||
|
||||
|
@ -121,7 +121,7 @@ class GroupsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
respond_with(@user, location: restore(default: group_url(@group))) do |format|
|
||||
respond_with(@user, location: group_url(@group)) do |format|
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class ItemsController < ApplicationController
|
|||
@item.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: restore(default: item_url(@item))) }
|
||||
format.html { respond_with(@user, location: item_url(@item)) }
|
||||
format.js { respond_with(@item) }
|
||||
end
|
||||
|
||||
|
@ -180,12 +180,12 @@ class ItemsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
respond_with(@user, location: restore(default: item_url(@item))) do |format|
|
||||
respond_with(@user, location: item_url(@item)) do |format|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# DELETE /actions/:id
|
||||
# DELETE /items/:id
|
||||
def destroy
|
||||
@item = Item.find_by_id(params[:id])
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class PeopleController < ApplicationController
|
|||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: restore(default: person_url(@person))) }
|
||||
format.html { respond_with(@user, location: person_url(@person)) }
|
||||
format.js { respond_with(@person) }
|
||||
end
|
||||
|
||||
|
@ -105,7 +105,7 @@ class PeopleController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
respond_with(@user, location: restore(default: person_url(@person))) do |format|
|
||||
respond_with(@user, location: person_url(@person)) do |format|
|
||||
end
|
||||
end
|
||||
|
||||
|
|
145
app/controllers/synapses_controller.rb
Normal file
145
app/controllers/synapses_controller.rb
Normal file
|
@ -0,0 +1,145 @@
|
|||
class SynapsesController < ApplicationController
|
||||
|
||||
before_filter :require_user, only: [:new, :create, :edit, :update]
|
||||
|
||||
respond_to :html, :js, :json
|
||||
|
||||
# GET /synapses
|
||||
def index
|
||||
@user = current_user
|
||||
@synapses = Synapse.all
|
||||
|
||||
respond_with(@synapses)
|
||||
end
|
||||
|
||||
# Get /synapse/new
|
||||
def new
|
||||
@synapse1 = Synapse.new
|
||||
@synapse1.category = "Group"
|
||||
@synapse2 = Synapse.new
|
||||
@synapse2.category = "Person"
|
||||
@synapse3 = Synapse.new
|
||||
@synapse3.category = "Item"
|
||||
@user = current_user
|
||||
@allgroups = Group.all
|
||||
@allpeople = Person.all
|
||||
@allitems = Item.all
|
||||
|
||||
respond_with(@synapse1, @synapse2, @synapse3, @allgroups, @allpeople, @allitems)
|
||||
end
|
||||
|
||||
# GET /synapse/:id
|
||||
def show
|
||||
@synapse = Synapse.find(params[:id])
|
||||
|
||||
@node1 = nil
|
||||
@node2 = nil
|
||||
|
||||
if @synapse
|
||||
if (@synapse.category == "Group")
|
||||
@node1 = @synapse.group1
|
||||
@node2 = @synapse.group2
|
||||
end
|
||||
if (@synapse.category == "Person")
|
||||
@node1 = @synapse.person1
|
||||
@node2 = @synapse.person2
|
||||
end
|
||||
if (@synapse.category == "Item")
|
||||
@node1 = @synapse.item1
|
||||
@node2 = @synapse.item2
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@synapse, @node1, @node2) }
|
||||
# format.json { respond_with(@relatives) }
|
||||
end
|
||||
end
|
||||
|
||||
# POST /synapses
|
||||
def create
|
||||
|
||||
@user = current_user
|
||||
@synapse = Synapse.new()
|
||||
@synapse.desc = params[:synapse][:desc]
|
||||
@synapse.category = params[:category]
|
||||
if ( @synapse.category == "Group" )
|
||||
@synapse.group1 = Group.find(params[:node1_id])
|
||||
@synapse.group2 = Group.find(params[:node2_id])
|
||||
end
|
||||
if ( @synapse.category == "Person" )
|
||||
@synapse.person1 = Person.find(params[:node1_id])
|
||||
@synapse.person2 = Person.find(params[:node2_id])
|
||||
end
|
||||
if ( @synapse.category == "Item" )
|
||||
@synapse.item1 = Item.find(params[:node1_id])
|
||||
@synapse.item2 = Item.find(params[:node2_id])
|
||||
end
|
||||
@synapse.user = @user
|
||||
|
||||
@synapse.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: synapse_url(@synapse)) }
|
||||
format.js { respond_with(@synapse) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# GET /synapses/:id/edit
|
||||
def edit
|
||||
@synapse = Synapse.find_by_id(params[:id])
|
||||
|
||||
@collection1 = nil
|
||||
@collection2 = nil
|
||||
|
||||
if @synapse
|
||||
if (@synapse.category == "Group")
|
||||
@collection = Group.all
|
||||
end
|
||||
if (@synapse.category == "Person")
|
||||
@collection = Person.all
|
||||
end
|
||||
if (@synapse.category == "Item")
|
||||
@collection = Item.all
|
||||
end
|
||||
end
|
||||
|
||||
respond_with(@synapse, @collection)
|
||||
end
|
||||
|
||||
# PUT /actions/:id
|
||||
def update
|
||||
@synapse = Synapse.find_by_id(params[:id])
|
||||
|
||||
if @synapse
|
||||
@synapse.desc = params[:synapse][:desc]
|
||||
if ( @synapse.category == "Group" )
|
||||
@synapse.group1 = Group.find(params[:node1_id][:node1])
|
||||
@synapse.group2 = Group.find(params[:node2_id][:node2])
|
||||
end
|
||||
if ( @synapse.category == "Person" )
|
||||
@synapse.person1 = Person.find(params[:node1_id][:node1])
|
||||
@synapse.person2 = Person.find(params[:node2_id][:node2])
|
||||
end
|
||||
if ( @synapse.category == "Item" )
|
||||
@synapse.item1 = Item.find(params[:node1_id][:node1])
|
||||
@synapse.item2 = Item.find(params[:node2_id][:node2])
|
||||
end
|
||||
|
||||
@synapse.save
|
||||
end
|
||||
|
||||
respond_with(@user, location: synapse_url(@synapse)) do |format|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# DELETE /synapses/:id
|
||||
def destroy
|
||||
@synapse = Synapse.find_by_id(params[:id])
|
||||
|
||||
@synapse.delete
|
||||
end
|
||||
|
||||
end
|
2
app/helpers/synapses_helper.rb
Normal file
2
app/helpers/synapses_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module SynapsesHelper
|
||||
end
|
|
@ -36,10 +36,10 @@ has_many :items, :through => :groupitems
|
|||
@groups = @single + self.relatives
|
||||
|
||||
json.array!(@groups) do |group|
|
||||
json.adjacencies group.synapses2 do |json, synapse|
|
||||
json.nodeTo synapse.node1_id
|
||||
json.nodeFrom synapse.node2_id
|
||||
json.data @data1
|
||||
json.adjacencies group.synapses2.delete_if{|synapse| not @groups.include?(Group.find_by_id(synapse.node1_id))} do |json, synapse|
|
||||
json.nodeTo synapse.node1_id
|
||||
json.nodeFrom synapse.node2_id
|
||||
json.data @data1
|
||||
end
|
||||
|
||||
json.data @data2
|
||||
|
|
|
@ -38,10 +38,10 @@ has_many :parent_items, :through => :itemitem_p, :source => :parent_item
|
|||
@items = @single + self.relatives
|
||||
|
||||
json.array!(@items) do |item|
|
||||
json.adjacencies item.synapses2 do |json, synapse|
|
||||
json.nodeTo synapse.node1_id
|
||||
json.nodeFrom synapse.node2_id
|
||||
json.data @data1
|
||||
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
|
||||
json.data @data1
|
||||
end
|
||||
|
||||
json.data @data2
|
||||
|
|
|
@ -30,7 +30,7 @@ has_many :people2, :through => :synapses1, :source => :person2
|
|||
@people = @single + self.relatives
|
||||
|
||||
json.array!(@people) do |person|
|
||||
json.adjacencies person.synapses2 do |json, synapse|
|
||||
json.adjacencies person.synapses2.delete_if{|synapse| not @people.include?(Person.find_by_id(synapse.node1_id))} do |json, synapse|
|
||||
json.nodeTo synapse.node1_id
|
||||
json.nodeFrom synapse.node2_id
|
||||
json.data @data1
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
<% if authenticated? %>
|
||||
<ul>
|
||||
<li><%= link_to "Logout", session_path, method: 'delete', id: "Login" %></li>
|
||||
<li><%= link_to "My Objects", userobjects_path %></li>
|
||||
<li><%= link_to "My Cards", userobjects_path %></li>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Add Synapse", new_synapse_path %></li>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Add Item", new_item_path %></li>
|
||||
<li><%= link_to "Add Person", new_person_path %></li>
|
||||
|
|
14
app/views/synapses/edit.html.erb
Normal file
14
app/views/synapses/edit.html.erb
Normal file
|
@ -0,0 +1,14 @@
|
|||
<%= form_for @synapse, url: synapse_url do |form| %>
|
||||
<h3>Edit Synapse</h3>
|
||||
<% if @collection.count > 0 %>
|
||||
<label for="node1_id">Choose First <%= @synapse.category %></label>
|
||||
<%= select "node1_id", "node1", @collection.map {|p| [ p.name, p.id ] }, { :selected => @synapse.node1_id } %>
|
||||
<% end %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if @collection.count > 0 %>
|
||||
<label for="node2_id">Choose Second <%= @synapse.category %></label>
|
||||
<%= select "node2_id", "node2", @collection.map {|p| [ p.name, p.id ] }, { :selected => @synapse.node2_id } %>
|
||||
<% end %>
|
||||
<%= form.submit "Update", class: "update" %>
|
||||
<% end %>
|
45
app/views/synapses/new.html.erb
Normal file
45
app/views/synapses/new.html.erb
Normal file
|
@ -0,0 +1,45 @@
|
|||
<%= form_for @synapse1, url: synapses_url do |form| %>
|
||||
<h3>Add Synapse Between Groups</h3>
|
||||
<%= hidden_field_tag(:category, "Group") %>
|
||||
<% if @allgroups.count > 0 %>
|
||||
<label for="node1_id">Choose First Group</label>
|
||||
<%= select_tag :node1_id, options_from_collection_for_select(@allgroups, "id", "name") %>
|
||||
<% end %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if @allgroups.count > 0 %>
|
||||
<label for="node2_id">Choose Second Group</label>
|
||||
<%= select_tag :node2_id, options_from_collection_for_select(@allgroups, "id", "name") %>
|
||||
<% end %>
|
||||
<%= form.submit "Add Synapse", class: "add" %>
|
||||
<% end %>
|
||||
<%= form_for @synapse2, url: synapses_url do |form| %>
|
||||
<h3>Add Synapse Between People</h3>
|
||||
<%= hidden_field_tag(:category, "Person") %>
|
||||
<% if @allpeople.count > 0 %>
|
||||
<label for="node1_id">Choose First Person</label>
|
||||
<%= select_tag :node1_id, options_from_collection_for_select(@allpeople, "id", "name") %>
|
||||
<% end %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if @allpeople.count > 0 %>
|
||||
<label for="node2_id">Choose Second Person</label>
|
||||
<%= select_tag :node2_id, options_from_collection_for_select(@allpeople, "id", "name") %>
|
||||
<% end %>
|
||||
<%= form.submit "Add Synapse", class: "add" %>
|
||||
<% end %>
|
||||
<%= form_for @synapse3, url: synapses_url do |form| %>
|
||||
<h3>Add Synapse Between Items</h3>
|
||||
<%= hidden_field_tag(:category, "Item") %>
|
||||
<% if @allitems.count > 0 %>
|
||||
<label for="node1_id">Choose First Item</label>
|
||||
<%= select_tag :node1_id, options_from_collection_for_select(@allitems, "id", "name") %>
|
||||
<% end %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if @allitems.count > 0 %>
|
||||
<label for="node2_id">Choose Second Item</label>
|
||||
<%= select_tag :node2_id, options_from_collection_for_select(@allitems, "id", "name") %>
|
||||
<% end %>
|
||||
<%= form.submit "Add Synapse", class: "add" %>
|
||||
<% end %>
|
31
app/views/synapses/show.html.erb
Normal file
31
app/views/synapses/show.html.erb
Normal file
|
@ -0,0 +1,31 @@
|
|||
<div class="focus">
|
||||
<div class="focusleft">
|
||||
<p><%= @node1.name %></p>
|
||||
<% if (@node1.class == Group) %>
|
||||
<%= image_tag "group.png", :class => 'icon', :size => '50x50' %>
|
||||
<% elsif (@node1.class == Person) %>
|
||||
<%= image_tag "person.png", :class => 'icon', :size => '50x50' %>
|
||||
<% elsif (@node1.class == Item) %>
|
||||
<%= image_tag @node1.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||
<% end %>
|
||||
<p><%= @node1.desc %></p>
|
||||
</div>
|
||||
<div class="focusmiddle">
|
||||
<h1 class="title">Synapse <%= link_to "[edit]", edit_synapse_path(@synapse) %></h1>
|
||||
<div class="desc">
|
||||
<p><%= @synapse.desc %></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="focusright">
|
||||
<p><%= @node2.name %></p>
|
||||
<% if (@node2.class == Group) %>
|
||||
<%= image_tag "group.png", :class => 'icon', :size => '50x50' %>
|
||||
<% elsif (@node2.class == Person) %>
|
||||
<%= image_tag "person.png", :class => 'icon', :size => '50x50' %>
|
||||
<% elsif (@node2.class == Item) %>
|
||||
<%= image_tag @node2.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||
<% end %>
|
||||
<p><%= @node2.desc %></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfloat nodemargin"></div>
|
|
@ -2,7 +2,7 @@ ISSAD::Application.routes.draw do
|
|||
|
||||
root to: 'main#home', via: :get
|
||||
|
||||
match 'my-objects', to: 'main#userobjects', via: :get, as: :userobjects
|
||||
match 'my-cards', to: 'main#userobjects', via: :get, as: :userobjects
|
||||
|
||||
resource :user
|
||||
resource :session
|
||||
|
@ -10,6 +10,7 @@ ISSAD::Application.routes.draw do
|
|||
resources :items
|
||||
resources :people
|
||||
resources :groups
|
||||
resources :synapses
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
|
7
test/functional/synapses_controller_test.rb
Normal file
7
test/functional/synapses_controller_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class SynapsesControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
4
test/unit/helpers/synapses_helper_test.rb
Normal file
4
test/unit/helpers/synapses_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class SynapsesHelperTest < ActionView::TestCase
|
||||
end
|
Loading…
Reference in a new issue