' + node.name + '' +
+ '
';
var showCard = document.createElement('div');
- showCard.className = 'showcard item_' + node.id;
+ showCard.className = 'showcard topic_' + node.id;
showCard.innerHTML = html;
showCard.style.display = "none";
domElement.appendChild(showCard);
@@ -322,7 +322,7 @@ function graphSettings(type) {
modes: ['edge-property:lineWidth:color'],
duration: 500
});
- $('.showcard.item_' + node.id).fadeOut('fast', function(){
+ $('.showcard.topic_' + node.id).fadeOut('fast', function(){
$('.name').css('display','block');
Mconsole.plot();
});
@@ -333,7 +333,7 @@ function graphSettings(type) {
// to the main node label
var nameContainer = document.createElement('span'),
style = nameContainer.style;
- nameContainer.className = 'name item_' + node.id;
+ nameContainer.className = 'name topic_' + node.id;
nameContainer.innerHTML = '
' + node.name + '
';
domElement.appendChild(nameContainer);
style.fontSize = "0.9em";
@@ -410,7 +410,7 @@ var nodeSettings = {
'render': function (node, canvas) {
var pos = node.pos.getc(true),
dim = node.getData('dim'),
- cat = node.getData('itemcatname'),
+ cat = node.getData('metacode'),
inCommons = node.getData('inCommons'),
onCanvas = node.getData('onCanvas'),
ctx = canvas.getCtx();
@@ -502,8 +502,8 @@ function selectNodeOnClickHandler(node) {
$('.showcard').css('display','none');
$('.name').css('display','block');
- $('.name.item_' + node.id).css('display','none');
- $('.showcard.item_' + node.id).fadeIn('fast');
+ $('.name.topic_' + node.id).css('display','none');
+ $('.showcard.topic_' + node.id).fadeIn('fast');
//set final styles
Mconsole.graph.eachNode(function (n) {
@@ -552,18 +552,18 @@ function canvasDoubleClickHandler(canvasLoc,e) {
if (now - storedTime < TOLERANCE) {
//pop up node creation :)
- $('#item_grabItem').val("null");
- $('#item_addSynapse').val("false");
- document.getElementById('new_item').style.left = e.x + "px";
- document.getElementById('new_item').style.top = e.y + "px";
- $('#item_x').val(canvasLoc.x);
- $('#item_y').val(canvasLoc.y);
- $('#new_item').fadeIn('fast');
+ $('#topic_grabTopic').val("null");
+ $('#topic_addSynapse').val("false");
+ document.getElementById('new_topic').style.left = e.x + "px";
+ document.getElementById('new_topic').style.top = e.y + "px";
+ $('#topic_x').val(canvasLoc.x);
+ $('#topic_y').val(canvasLoc.y);
+ $('#new_topic').fadeIn('fast');
addMetacode();
- $('#item_name').focus();
+ $('#topic_name').focus();
} else {
canvasDoubleClickHandlerObject.storedTime = now;
- $('#new_item').fadeOut('fast');
+ $('#new_topic').fadeOut('fast');
$('#new_synapse').fadeOut('fast');
tempInit = false;
tempNode = null;
@@ -576,7 +576,7 @@ function canvasDoubleClickHandler(canvasLoc,e) {
function clickDragOnTopic(node, eventInfo, e) {
if (node && !node.nodeFrom) {
$('#new_synapse').fadeOut('fast');
- $('#new_item').fadeOut('fast');
+ $('#new_topic').fadeOut('fast');
var pos = eventInfo.getPos();
// if it's a left click, move the node
if (e.button == 0 && !e.altKey ) {
@@ -608,15 +608,15 @@ function clickDragOnTopic(node, eventInfo, e) {
n.setData('dim', 25, 'current');
});
//pop up node creation :)
- $('#item_grabItem').val("null");
+ $('#topic_grabTopic').val("null");
var myX = e.x - 110;
var myY = e.y - 30;
- document.getElementById('new_item').style.left = myX + "px";
- document.getElementById('new_item').style.top = myY + "px";
+ document.getElementById('new_topic').style.left = myX + "px";
+ document.getElementById('new_topic').style.top = myY + "px";
document.getElementById('new_synapse').style.left = myX + "px";
document.getElementById('new_synapse').style.top = myY + "px";
- $('#item_x').val(eventInfo.getPos().x);
- $('#item_y').val(eventInfo.getPos().y);
+ $('#topic_x').val(eventInfo.getPos().x);
+ $('#topic_y').val(eventInfo.getPos().y);
Mconsole.plot();
renderMidArrow({ x: tempNode.pos.getc().x, y: tempNode.pos.getc().y }, { x: pos.x, y: pos.y }, 13, false, Mconsole.canvas);
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 6069ec05..c38362e5 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -25,14 +25,14 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
$(document).ready(function() {
- $('#new_item, #new_synapse').bind('contextmenu', function(e){
+ $('#new_topic, #new_synapse').bind('contextmenu', function(e){
return false;
});
/// this is for the topic creation autocomplete field
- $('#item_name').bind('railsAutocomplete.select', function(event, data){
+ $('#topic_name').bind('railsAutocomplete.select', function(event, data){
if (data.item.id != undefined) {
- $('#item_grabItem').val(data.item.id);
+ $('#topic_grabTopic').val(data.item.id);
}
});
diff --git a/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js b/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js
index 1b33702e..0dd961af 100644
--- a/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js
+++ b/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js
@@ -187,7 +187,7 @@
if ( items[this.frontIndex] === undefined ) { return; } // Images might not have loaded yet.
$(options.titleBox).html( $(items[this.frontIndex].image).attr('title'));
// METAMAPS CODE
- $('#item_metacode').val( $(items[this.frontIndex].image).attr('title'));
+ $('#topic_metacode').val( $(items[this.frontIndex].image).attr('title'));
// NOT METAMAPS CODE
$(options.altBox).html( $(items[this.frontIndex].image).attr('alt'));
};
diff --git a/app/assets/javascripts/topics.js.coffee b/app/assets/javascripts/topics.js.coffee
new file mode 100644
index 00000000..52b1d028
--- /dev/null
+++ b/app/assets/javascripts/topics.js.coffee
@@ -0,0 +1,6 @@
+# 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/
+
+jQuery ->
+ $('.best_in_place').best_in_place()
\ No newline at end of file
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index fc1f50e7..3b7ef952 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -93,7 +93,7 @@ a {
.new_user,
.new_map,
.edit_user,
-.edit_item,
+.edit_topic,
.edit_synapse,
.edit_map,
.invite {
@@ -135,18 +135,18 @@ a {
right:3px;
}
-.anypage .new_item {
+.anypage .new_topic {
width:300px;
margin:-40px 0 0 -50px;
}
-.anypage .new_item,
+.anypage .new_topic,
.anypage .new_synapse {
display: block;
position: absolute;
}
-.anypage #item_name {
+.anypage #topic_name {
width:200px;
position:absolute;
top:40px;
diff --git a/app/assets/stylesheets/jquery-ui.css b/app/assets/stylesheets/jquery-ui.css
index ac0b1b7c..4d2c8534 100644
--- a/app/assets/stylesheets/jquery-ui.css
+++ b/app/assets/stylesheets/jquery-ui.css
@@ -152,18 +152,18 @@ button.ui-button::-moz-focus-inner { border: 0; padding: 0; } /* reset extra pad
.ui-menu { list-style:none; padding: 2px; margin: 0; display:block; outline: none; }
.ui-menu .ui-menu { margin-top: -3px; position: absolute; }
-.ui-menu .ui-menu-item { margin: 0; padding: 0; zoom: 1; width: 100%; }
+.ui-menu .ui-menu-topic { margin: 0; padding: 0; zoom: 1; width: 100%; }
.ui-menu .ui-menu-divider { margin: 5px -2px 5px -2px; height: 0; font-size: 0; line-height: 0; border-width: 1px 0 0 0; }
-.ui-menu .ui-menu-item a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; }
-.ui-menu .ui-menu-item a.ui-state-focus,
-.ui-menu .ui-menu-item a.ui-state-active { font-weight: normal; margin: -1px; }
+.ui-menu .ui-menu-topic a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; }
+.ui-menu .ui-menu-topic a.ui-state-focus,
+.ui-menu .ui-menu-topic a.ui-state-active { font-weight: normal; margin: -1px; }
.ui-menu .ui-state-disabled { font-weight: normal; margin: .4em 0 .2em; line-height: 1.5; }
.ui-menu .ui-state-disabled a { cursor: default; }
/* icon support */
.ui-menu-icons { position: relative; }
-.ui-menu-icons .ui-menu-item a { position: relative; padding-left: 2em; }
+.ui-menu-icons .ui-menu-topic a { position: relative; padding-left: 2em; }
/* left-aligned */
.ui-menu .ui-icon { position: absolute; top: .2em; left: .2em; }
diff --git a/app/assets/stylesheets/maps.css.scss b/app/assets/stylesheets/maps.css.scss
index 3fdbcb09..3b527c51 100644
--- a/app/assets/stylesheets/maps.css.scss
+++ b/app/assets/stylesheets/maps.css.scss
@@ -46,4 +46,4 @@ line-height: 24px;}
// add topic on maps pages
.selecttype { border:1px solid #000; margin-top: 20px; border-radius:15px; }
-.mapspages .new_item h3 { padding: 10px 26px; display: block; cursor: pointer; color: #2d6a5d; float:left; }
\ No newline at end of file
+.mapspages .new_topic h3 { padding: 10px 26px; display: block; cursor: pointer; color: #2d6a5d; float:left; }
\ No newline at end of file
diff --git a/app/assets/stylesheets/topics.css.scss b/app/assets/stylesheets/topics.css.scss
new file mode 100644
index 00000000..7fbc6738
--- /dev/null
+++ b/app/assets/stylesheets/topics.css.scss
@@ -0,0 +1,37 @@
+// Place all the styles related to the Topics controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+.topic { display:block; float:left; position:relative; width:175px; height:300px; padding:10px 5px 10px 35px; background: url('bg.png'); border-radius:15px; margin:30px 0 30px 50px; color:#000; }
+
+.topic .delete {position: absolute;
+top: -14px;
+left: 0px;
+background: none;
+border: 0;
+color: white;
+border: none;
+font-size: 14px;
+margin: 0;
+padding: 0;
+cursor:pointer;
+}
+
+.topic .scroll { display:block; height:283px; }
+
+.topic .type {position: absolute;
+color: white;
+top: -22px;
+right: 0;
+font-weight: bold;
+font-size: 20px;
+line-height: 24px;}
+
+.topic .icon { position:absolute; top:135px; left:-25px; }
+
+.topic .title { font-size:22px; line-height:25px; display:block; border-bottom:2px solid #000; padding-bottom:5px; }
+
+.topic .desc { font-size:15px; font-family:Arial, Helvetica, sans-serif; }
+.topic .desc h3 { font-style:normal; margin-top:5px; }
+
+.topic .link { position:absolute; width:170px; top:295px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
\ No newline at end of file
diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb
index b7949c25..7b8e7e3a 100644
--- a/app/controllers/main_controller.rb
+++ b/app/controllers/main_controller.rb
@@ -1,5 +1,5 @@
class MainController < ApplicationController
- include ItemsHelper
+ include TopicsHelper
before_filter :require_user, only: [:invite]
@@ -11,16 +11,16 @@ class MainController < ApplicationController
def search
@current = current_user
- @items = Array.new()
+ @topics = Array.new()
if params[:topics_by_user_id] != ""
@user = User.find(params[:topics_by_user_id])
- @items = Item.visibleToUser(@current, @user)
+ @topics = Topic.visibleToUser(@current, @user)
elsif params[:topics_by_map_id] != ""
@map = Map.find(params[:topics_by_map_id])
- @items = @map.items.delete_if{|item| not item.authorize_to_view(@current)}
+ @topics = @map.topics.delete_if{|topic| not topic.authorize_to_view(@current)}
end
respond_to do |format|
- format.js { respond_with(@items) }
+ format.js { respond_with(@topics) }
end
end
diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb
index 4487abba..1e93a7c3 100644
--- a/app/controllers/maps_controller.rb
+++ b/app/controllers/maps_controller.rb
@@ -63,15 +63,15 @@ class MapsController < ApplicationController
if params[:map][:topicsToMap]
@all = params[:map][:topicsToMap]
@all = @all.split(',')
- @all.each do |item|
- item = item.split('/')
+ @all.each do |topic|
+ topic = topic.split('/')
@mapping = Mapping.new()
- @mapping.category = "Item"
+ @mapping.category = "Topic"
@mapping.user = @user
@mapping.map = @map
- @mapping.item = Item.find(item[0])
- @mapping.xloc = item[1]
- @mapping.yloc = item[2]
+ @mapping.topic = Topic.find(topic[0])
+ @mapping.xloc = topic[1]
+ @mapping.yloc = topic[2]
@mapping.save
end
@map.arranged = true
@@ -95,9 +95,9 @@ class MapsController < ApplicationController
redirect_to root_url and return
end
- @outitems = @map.items.order("name ASC").delete_if{|item| not item.authorize_to_view(@current)}
+ @outtopics = @map.topics.order("name ASC").delete_if{|topic| not topic.authorize_to_view(@current)}
- respond_with(@user, @map, @outitems)
+ respond_with(@user, @map, @outtopics)
end
# PUT maps/:id
@@ -107,10 +107,10 @@ class MapsController < ApplicationController
@map.attributes = params[:map]
@map.save
- if params[:outitems]
- @outitems = params[:outitems]
- @outitems.each do |item|
- @mapping = Mapping.where("map_id = ? AND item_id = ?", @map.id, item).first
+ if params[:outtopics]
+ @outtopics = params[:outtopics]
+ @outtopics.each do |topic|
+ @mapping = Mapping.where("map_id = ? AND topic_id = ?", @map.id, topic).first
@mapping.delete
end
end
@@ -126,11 +126,11 @@ class MapsController < ApplicationController
if params[:map][:coordinates]
@all = params[:map][:coordinates]
@all = @all.split(',')
- @all.each do |item|
- item = item.split('/')
- @mapping = Mapping.find(item[0])
- @mapping.xloc = item[1]
- @mapping.yloc = item[2]
+ @all.each do |topic|
+ topic = topic.split('/')
+ @mapping = Mapping.find(topic[0])
+ @mapping.xloc = topic[1]
+ @mapping.yloc = topic[2]
@mapping.save
end
@map.arranged = true
diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb
index 75a0a9ff..8e23c638 100644
--- a/app/controllers/synapses_controller.rb
+++ b/app/controllers/synapses_controller.rb
@@ -1,5 +1,5 @@
class SynapsesController < ApplicationController
- include ItemsHelper
+ include TopicsHelper
before_filter :require_user, only: [:new, :create, :edit, :update]
@@ -39,10 +39,10 @@ class SynapsesController < ApplicationController
def show
@current = current_user
@synapse = Synapse.find(params[:id]).authorize_to_show(@current)
- @item1 = @synapse.item1.authorize_to_show(@current)
- @item2 = @synapse.item2.authorize_to_show(@current)
+ @topic1 = @synapse.topic1.authorize_to_show(@current)
+ @topic2 = @synapse.topic2.authorize_to_show(@current)
- if @synapse && @item1 && @item2
+ if @synapse && @topic1 && @topic2
@synapsejson = @synapse.selfplusnodes_as_json.html_safe
else
redirect_to root_url and return
@@ -60,8 +60,8 @@ class SynapsesController < ApplicationController
@user = current_user
@synapse = Synapse.new()
@synapse.desc = params[:synapse][:desc]
- @synapse.item1 = Item.find(params[:synapse][:item1id])
- @synapse.item2 = Item.find(params[:synapse][:item2id])
+ @synapse.topic1 = Topic.find(params[:synapse][:topic1id])
+ @synapse.topic2 = Topic.find(params[:synapse][:topic2id])
@synapse.permission = "commons"
@synapse.category = "from-to"
@synapse.weight = 5
@@ -90,12 +90,12 @@ class SynapsesController < ApplicationController
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
if @synapse
- @items = Item.visibleToUser(@current, nil)
+ @topics = Topic.visibleToUser(@current, nil)
elsif not @synapse
redirect_to root_url and return
end
- respond_with(@synapse, @items)
+ respond_with(@synapse, @topics)
end
# PUT synapses/:id
@@ -106,8 +106,8 @@ class SynapsesController < ApplicationController
if @synapse
@synapse.desc = params[:synapse][:desc]
@synapse.category = params[:synapse][:category]
- @synapse.item1 = Item.find(params[:node1_id][:node1])
- @synapse.item2 = Item.find(params[:node2_id][:node2])
+ @synapse.topic1 = Topic.find(params[:node1_id][:node1])
+ @synapse.topic2 = Topic.find(params[:node2_id][:node2])
@synapse.permission = params[:synapse][:permission]
@synapse.save
end
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
new file mode 100644
index 00000000..eef727a7
--- /dev/null
+++ b/app/controllers/topics_controller.rb
@@ -0,0 +1,163 @@
+class TopicsController < ApplicationController
+ before_filter :require_user, only: [:new, :create, :edit, :update]
+
+ respond_to :html, :js, :json
+
+ autocomplete :topic, :name, :full => true, :extra_data => [:user_id]
+
+
+ # GET topics
+ # or GET /users/:user_id/topics
+ def index
+ @current = current_user
+
+ if params[:user_id]
+ @user = User.find(params[:user_id])
+ @topics = Topic.order("name ASC").visibleToUser(@current, @user)
+ elsif
+ @topics = Topic.order("name ASC").visibleToUser(@current, nil)
+ end
+
+ respond_with(@user,@topics)
+ end
+
+ # Get topics/new
+ def new
+ @topic = Topic.new
+ @user = current_user
+
+ respond_with(@topic)
+ end
+
+ # GET topics/:id
+ def show
+ @current = current_user
+ @topic = Topic.find(params[:id]).authorize_to_show(@current)
+
+ if @topic
+ @relatives = @topic.network_as_json(@current).html_safe
+ else
+ redirect_to root_url and return
+ end
+
+ respond_to do |format|
+ format.html { respond_with(@topic, @user) }
+ format.json { respond_with(@relatives) }
+ end
+ end
+
+ # GET showcard/:id
+ def showcard
+ @user = current_user
+ @topic = Topic.find(params[:id]).authorize_to_show(@user)
+
+ respond_to do |format|
+ format.html { respond_with(@topic, @user) }
+ end
+ end
+
+ # POST topics
+ def create
+
+ @user = current_user
+
+ # if the topic exists grab it and return it
+ if params[:topic][:grabTopic] != "null"
+ @topic = Topic.find(params[:topic][:grabTopic])
+ # if the topic doesn't exist yet, create it
+ else
+ @topic = Topic.new()
+ @topic.name = params[:topic][:name]
+ @topic.desc = ""
+ @topic.link = ""
+ @topic.permission = 'commons'
+ @topic.metacode = Metacode.find_by_name(params[:topic][:metacode])
+ @topic.user = @user
+
+ @topic.save
+ end
+
+ # pass on to the topic create js whether it's being created with a synapse
+ @synapse = "false"
+ if params[:topic][:addSynapse] == "true"
+ @synapse = "true"
+ end
+
+ # also create an object to return the position to the canvas
+ @position = Hash.new()
+ @position['x'] = params[:topic][:x]
+ @position['y'] = params[:topic][:y]
+
+ # set this for the case where the topic is being created on a map.
+ @mapping = Mapping.new()
+ if params[:topic][:map]
+ @mapping.category = "Topic"
+ @mapping.user = @user
+ @mapping.map = Map.find(params[:topic][:map])
+ @mapping.topic = @topic
+ @mapping.xloc = params[:topic][:x]
+ @mapping.yloc = params[:topic][:y]
+ @mapping.save
+ end
+
+ respond_to do |format|
+ format.html { respond_with(@user, location: topic_url(@topic)) }
+ format.js { respond_with(@topic, @mapping, @synapse, @position) }
+ end
+ end
+
+ # GET topics/:id/edit
+ def edit
+ @current = current_user
+ @topic = Topic.find(params[:id]).authorize_to_edit(@current)
+
+ if not @topic
+ redirect_to root_url and return
+ end
+
+ respond_with(@topic)
+ end
+
+ # PUT topics/:id
+ def update
+ @current = current_user
+ @topic = Topic.find(params[:id]).authorize_to_edit(@current)
+
+ if @topic
+ @topic.name = params[:topic][:name]
+ @topic.desc = params[:topic][:desc]
+ @topic.link = params[:topic][:link]
+ @topic.permission = params[:topic][:permission]
+ @topic.metacode = Metacode.find(params[:category][:metacode_id])
+ @topic.save
+ end
+
+ respond_with(@user, location: topic_url(@topic)) do |format|
+ end
+ end
+
+ # DELETE topics/:id
+ def destroy
+ @current = current_user
+ @topic = Topic.find(params[:id]).authorize_to_edit(@current)
+
+ if @topic
+ @synapses = @topic.synapses
+ @mappings = @topic.mappings
+
+ @synapses.each do |synapse|
+ synapse.delete
+ end
+
+ @mappings.each do |mapping|
+ mapping.delete
+ end
+
+ @topic.delete
+ end
+
+ respond_to do |format|
+ format.js
+ end
+ end
+end
diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb
new file mode 100644
index 00000000..d9c8358e
--- /dev/null
+++ b/app/helpers/topics_helper.rb
@@ -0,0 +1,128 @@
+module TopicsHelper
+
+#find all nodes in any given nodes network
+ def network(node, array, count)
+ # recurse starting with a node to find all connected nodes and return an array of topics that constitutes the starting nodes network
+
+ # if the array of nodes is empty initialize it
+ if array.nil?
+ array = Array.new
+ end
+
+ # add the node to the array
+ array.push(node)
+
+ if count == 0
+ return array
+ end
+
+ count = count - 1
+
+ # check if each relative is already in the array and if not, call the network function again
+ if not node.relatives.empty?
+ if (node.relatives-array).empty?
+ return array
+ else
+ (node.relatives-array).each do |relative|
+ array = (array | network(relative, array, count))
+ end
+ return array
+ end
+
+ elsif node.relatives.empty?
+ return array
+ end
+ end
+
+ #return a json object containing all of a users added synapses
+ def synapses_as_json(current, synapses)
+ Jbuilder.encode do |json|
+ @topics = Array.new
+
+ synapses.each do |synapse|
+ @topics.push(synapse.topic1) if (not @topics.include?(synapse.topic1)) && synapse.topic1.authorize_to_view(current)
+ @topics.push(synapse.topic2) if (not @topics.include?(synapse.topic2)) && synapse.topic2.authorize_to_view(current)
+ end
+
+ json.array!(@topics) do |topic|
+ json.adjacencies topic.synapses2.delete_if{|synapse| not @topics.include?(Topic.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['$showDesc'] = false
+ @synapsedata['$category'] = synapse.category
+ @synapsedata['$id'] = synapse.id
+ @synapsedata['$userid'] = synapse.user.id
+ @synapsedata['$username'] = synapse.user.name
+ @synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
+ json.data @synapsedata
+ end
+
+ @inmaps = Array.new
+ topic.maps.each do |map|
+ @inmaps.push(map.id)
+ end
+
+ @topicdata = Hash.new
+ @topicdata['$desc'] = topic.desc
+ @topicdata['$link'] = topic.link
+ @topicdata['$metacode'] = topic.metacode.name
+ @topicdata['$inmaps'] = @inmaps
+ @topicdata['$userid'] = topic.user.id
+ @topicdata['$username'] = topic.user.name
+ json.data @topicdata
+ json.id topic.id
+ json.name topic.name
+ end
+ end
+ end
+
+ def all_as_json(current, user)
+
+ # current is current user
+
+ Jbuilder.encode do |json|
+ if user.nil?
+ @topics = Topic.visibleToUser(current, nil)
+ @synapses = Synapse.visibleToUser(current, nil)
+ else
+ @topics = Topic.visibleToUser(current, user)
+ @synapses = Synapse.visibleToUser(current, user)
+ end
+
+ json.array!(@topics) do |topic|
+ json.adjacencies topic.synapses2.delete_if{|synapse| (not @topics.include?(Topic.find_by_id(synapse.node1_id))) || (not @synapses.include?(synapse))} do |json, synapse|
+ json.nodeTo synapse.node1_id
+ json.nodeFrom synapse.node2_id
+
+ @synapsedata = Hash.new
+ @synapsedata['$desc'] = synapse.desc
+ @synapsedata['$category'] = synapse.category
+ @synapsedata['$userid'] = synapse.user.id
+ @synapsedata['$username'] = synapse.user.name
+ json.data @synapsedata
+ end
+
+ @inmaps = Array.new
+ topic.maps.each do |map|
+ @inmaps.push(map.id)
+ end
+
+ @topicdata = Hash.new
+ @topicdata['$desc'] = topic.desc
+ @topicdata['$link'] = topic.link
+ @topicdata['$metacode'] = topic.metacode.name
+ @topicdata['$inmaps'] = @inmaps
+ @topicdata['$userid'] = topic.user.id
+ @topicdata['$username'] = topic.user.name
+
+ json.data @topicdata
+ json.id topic.id
+ json.name topic.name
+ end
+ end
+ end
+
+end
diff --git a/app/models/map.rb b/app/models/map.rb
index 2c538a52..4793c40c 100644
--- a/app/models/map.rb
+++ b/app/models/map.rb
@@ -2,14 +2,14 @@ class Map < ActiveRecord::Base
belongs_to :user
-has_many :itemmappings, :class_name => 'Mapping', :conditions => {:category => 'Item'}
+has_many :topicmappings, :class_name => 'Mapping', :conditions => {:category => 'Topic'}
has_many :synapsemappings, :class_name => 'Mapping', :conditions => {:category => 'Synapse'}
-has_many :items, :through => :itemmappings
+has_many :topics, :through => :topicmappings
has_many :synapses, :through => :synapsemappings
def mappings
- itemmappings + synapsemappings
+ topicmappings + synapsemappings
end
@@ -17,14 +17,14 @@ end
#build a json object of a map
def self_as_json(current)
Jbuilder.encode do |json|
- @items = self.items
+ @topics = self.topics
@synapses = self.synapses
- json.array!(@items.delete_if{|item| not item.authorize_to_view(current)}) do |item|
+ json.array!(@topics.delete_if{|topic| not topic.authorize_to_view(current)}) do |topic|
- #json.adjacencies item.synapses2.delete_if{|synapse| (not @items.include?(synapse.item1)) || (not @synapses.include?(synapse)) || (not synapse.authorize_to_view(current)) || (not synapse.item1.authorize_to_view(current)) } do |json, synapse|
+ #json.adjacencies topic.synapses2.delete_if{|synapse| (not @topics.include?(synapse.topic1)) || (not @synapses.include?(synapse)) || (not synapse.authorize_to_view(current)) || (not synapse.topic1.authorize_to_view(current)) } do |json, synapse|
- json.adjacencies item.synapses1.delete_if{|synapse| (not @items.include?(synapse.item2)) || (not synapse.authorize_to_view(current)) || (not synapse.item2.authorize_to_view(current)) } do |json, synapse|
+ json.adjacencies topic.synapses1.delete_if{|synapse| (not @topics.include?(synapse.topic2)) || (not synapse.authorize_to_view(current)) || (not synapse.topic2.authorize_to_view(current)) } do |json, synapse|
json.nodeTo synapse.node2_id
json.nodeFrom synapse.node1_id
@@ -40,24 +40,24 @@ end
end
@inmaps = Array.new
- item.maps.each do |map|
+ topic.maps.each do |map|
@inmaps.push(map.id)
end
- @itemdata = Hash.new
- @itemdata['$desc'] = item.desc
- @itemdata['$link'] = item.link
- @itemdata['$itemcatname'] = item.item_category.name
- @itemdata['$inmaps'] = @inmaps
- @itemdata['$userid'] = item.user.id
- @itemdata['$username'] = item.user.name
- @mapping = Mapping.find_by_item_id_and_map_id(item.id,self.id)
- @itemdata['$xloc'] = @mapping.xloc
- @itemdata['$yloc'] = @mapping.yloc
- @itemdata['$mappingid'] = @mapping.id
- json.data @itemdata
- json.id item.id
- json.name item.name
+ @topicdata = Hash.new
+ @topicdata['$desc'] = topic.desc
+ @topicdata['$link'] = topic.link
+ @topicdata['$metacode'] = topic.metacode.name
+ @topicdata['$inmaps'] = @inmaps
+ @topicdata['$userid'] = topic.user.id
+ @topicdata['$username'] = topic.user.name
+ @mapping = Mapping.find_by_topic_id_and_map_id(topic.id,self.id)
+ @topicdata['$xloc'] = @mapping.xloc
+ @topicdata['$yloc'] = @mapping.yloc
+ @topicdata['$mappingid'] = @mapping.id
+ json.data @topicdata
+ json.id topic.id
+ json.name topic.name
end
end
end
diff --git a/app/models/mapping.rb b/app/models/mapping.rb
index b36fee81..434c19ff 100644
--- a/app/models/mapping.rb
+++ b/app/models/mapping.rb
@@ -1,6 +1,6 @@
class Mapping < ActiveRecord::Base
-belongs_to :item, :class_name => "Item", :foreign_key => "item_id"
+belongs_to :topic, :class_name => "Topic", :foreign_key => "topic_id"
belongs_to :synapse, :class_name => "Synapse", :foreign_key => "synapse_id"
belongs_to :map, :class_name => "Map", :foreign_key => "map_id"
diff --git a/app/models/metacode.rb b/app/models/metacode.rb
new file mode 100644
index 00000000..c181a19f
--- /dev/null
+++ b/app/models/metacode.rb
@@ -0,0 +1,5 @@
+class Metacode < ActiveRecord::Base
+
+has_many :topics
+
+end
diff --git a/app/models/synapse.rb b/app/models/synapse.rb
index 6324f236..c7fe44e1 100644
--- a/app/models/synapse.rb
+++ b/app/models/synapse.rb
@@ -2,8 +2,8 @@ class Synapse < ActiveRecord::Base
belongs_to :user
-belongs_to :item1, :class_name => "Item", :foreign_key => "node1_id"
-belongs_to :item2, :class_name => "Item", :foreign_key => "node2_id"
+belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id"
+belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
has_many :mappings
has_many :maps, :through => :mappings
@@ -26,12 +26,12 @@ has_many :maps, :through => :mappings
def selfplusnodes_as_json
Jbuilder.encode do |json|
- @items = Array.new
- @items.push(self.item1)
- @items.push(self.item2)
+ @topics = Array.new
+ @topics.push(self.topic1)
+ @topics.push(self.topic2)
- json.array!(@items) do |item|
- json.adjacencies item.synapses1.delete_if{|synapse| not @items.include?(Item.find_by_id(synapse.node2_id))} do |json, synapse|
+ json.array!(@topics) do |topic|
+ json.adjacencies topic.synapses1.delete_if{|synapse| not @topics.include?(Topic.find_by_id(synapse.node2_id))} do |json, synapse|
json.nodeTo synapse.node2_id
json.nodeFrom synapse.node1_id
@@ -47,20 +47,20 @@ has_many :maps, :through => :mappings
end
@inmaps = Array.new
- item.maps.each do |map|
+ topic.maps.each do |map|
@inmaps.push(map.id)
end
- @itemdata = Hash.new
- @itemdata['$desc'] = item.desc
- @itemdata['$link'] = item.link
- @itemdata['$itemcatname'] = item.item_category.name
- @itemdata['$inmaps'] = @inmaps
- @itemdata['$userid'] = item.user.id
- @itemdata['$username'] = item.user.name
- json.data @itemdata
- json.id item.id
- json.name item.name
+ @topicdata = Hash.new
+ @topicdata['$desc'] = topic.desc
+ @topicdata['$link'] = topic.link
+ @topicdata['$metacode'] = topic.metacode.name
+ @topicdata['$inmaps'] = @inmaps
+ @topicdata['$userid'] = topic.user.id
+ @topicdata['$username'] = topic.user.name
+ json.data @topicdata
+ json.id topic.id
+ json.name topic.name
end
end
end
diff --git a/app/models/topic.rb b/app/models/topic.rb
new file mode 100644
index 00000000..bb4199a1
--- /dev/null
+++ b/app/models/topic.rb
@@ -0,0 +1,171 @@
+class Topic < ActiveRecord::Base
+
+include TopicsHelper
+
+belongs_to :user
+
+has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id'
+has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id'
+has_many :topics1, :through => :synapses2, :source => :topic1
+has_many :topics2, :through => :synapses1, :source => :topic2
+
+has_many :mappings
+has_many :maps, :through => :mappings
+
+ def synapses
+ synapses1 + synapses2
+ end
+
+ def relatives
+ topics1 + topics2
+ end
+
+belongs_to :metacode
+
+ # has no viewable synapses helper function
+ def has_viewable_synapses(current)
+ result = false
+ self.synapses.each do |synapse|
+ if synapse.authorize_to_view(current)
+ result = true
+ end
+ end
+ return result
+ end
+
+ ###### JSON ######
+
+ def self_as_json
+ Jbuilder.encode do |json|
+ @inmaps = Array.new
+ self.maps.each do |map|
+ @inmaps.push(map.id)
+ end
+
+ @topicdata = Hash.new
+ @topicdata['$desc'] = self.desc
+ @topicdata['$link'] = self.link
+ @topicdata['$metacode'] = self.metacode.name
+ @topicdata['$inmaps'] = @inmaps
+ @topicdata['$userid'] = self.user.id
+ @topicdata['$username'] = self.user.name
+ json.data @topicdata
+ json.id self.id
+ json.name self.name
+ end
+ end
+
+ #build a json object of everything connected to a specified node
+ def network_as_json(current)
+ Jbuilder.encode do |json|
+ @topics = network(self,nil,4)
+
+ if @topics.count > 1
+ json.array!(@topics.delete_if{|topic| (not topic.authorize_to_view(current)) || (not topic.has_viewable_synapses(current))}) do |topic|
+
+ json.adjacencies topic.synapses1.delete_if{|synapse| (not @topics.include?(synapse.topic2)) || (not synapse.authorize_to_view(current)) || (not synapse.topic2.authorize_to_view(current)) } do |json, synapse|
+ json.nodeTo synapse.node2_id
+ json.nodeFrom synapse.node1_id
+
+ @synapsedata = Hash.new
+ @synapsedata['$desc'] = synapse.desc
+ @synapsedata['$showDesc'] = false
+ @synapsedata['$category'] = synapse.category
+ @synapsedata['$id'] = synapse.id
+ @synapsedata['$userid'] = synapse.user.id
+ @synapsedata['$username'] = synapse.user.name
+ @synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
+ json.data @synapsedata
+ end
+
+ @inmaps = Array.new
+ topic.maps.each do |map|
+ @inmaps.push(map.id)
+ end
+
+ @topicdata = Hash.new
+ @topicdata['$desc'] = topic.desc
+ @topicdata['$link'] = topic.link
+ @topicdata['$metacode'] = topic.metacode.name
+ @topicdata['$inmaps'] = @inmaps
+ @topicdata['$userid'] = topic.user.id
+ @topicdata['$username'] = topic.user.name
+ json.data @topicdata
+ json.id topic.id
+ json.name topic.name
+ end
+ elsif @topics.count == 1
+ json.array!(@topics) do |topic|
+ @inmaps = Array.new
+ topic.maps.each do |map|
+ @inmaps.push(map.id)
+ end
+
+ @topicdata = Hash.new
+ @topicdata['$desc'] = topic.desc
+ @topicdata['$link'] = topic.link
+ @topicdata['$metacode'] = topic.metacode.name
+ @topicdata['$inmaps'] = @inmaps
+ @topicdata['$userid'] = topic.user.id
+ @topicdata['$username'] = topic.user.name
+ json.data @topicdata
+ json.id topic.id
+ json.name topic.name
+ end
+ end
+ end
+ end
+
+ ##### PERMISSIONS ######
+
+ scope :visibleToUser, lambda { |current, user|
+ if user != nil
+ if user != current
+ Topic.find_all_by_user_id_and_permission(user.id, "commons") | Topic.find_all_by_user_id_and_permission(user.id, "public")
+ elsif user == current
+ Topic.find_all_by_user_id_and_permission(user.id, "commons") | Topic.find_all_by_user_id_and_permission(user.id, "public") | current.topics.where(:permission => "private")
+ end
+ elsif (current != nil && user == nil)
+ Topic.find_all_by_permission("commons") | Topic.find_all_by_permission("public") | current.topics.where(:permission => "private")
+ elsif (current == nil)
+ Topic.find_all_by_permission("commons") | Topic.find_all_by_permission("public")
+ end
+ }
+
+ # returns false if user not allowed to 'show' Topic, Synapse, or Map
+ def authorize_to_show(user)
+ if (self.permission == "private" && self.user != user)
+ return false
+ end
+ return self
+ end
+
+ # returns false if user not allowed to 'edit' Topic, Synapse, or Map
+ def authorize_to_edit(user)
+ if (self.permission == "private" && self.user != user)
+ return false
+ elsif (self.permission == "public" && self.user != user)
+ return false
+ end
+ return self
+ end
+
+ # returns Boolean if user allowed to view Topic, Synapse, or Map
+ def authorize_to_view(user)
+ if (self.permission == "private" && self.user != user)
+ return false
+ end
+ return true
+ end
+
+ # returns Boolean based on whether user has permissions to edit or not
+ def authorize_linkto_edit(user)
+ if (self.user == user)
+ return true
+ elsif (self.permission == "commons")
+ return true
+ end
+ return false
+ end
+
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 1aaa3c3a..1e4f824c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -2,7 +2,7 @@ require 'open-uri'
class User < ActiveRecord::Base
-has_many :items
+has_many :topics
has_many :synapses
has_many :maps
has_many :mappings
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 2c28686a..f1703bd5 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -33,7 +33,7 @@
<% unless authenticated? %>
<% if authenticated? %>
- <%= render :partial => 'items/new' %>
+ <%= render :partial => 'topics/new' %>
<%= render :partial => 'synapses/new' %>
<%= render :partial => 'maps/new' %>
<% end %>
@@ -43,8 +43,8 @@
- <%= form_for Item.new, :html => { :class => "find_topic_by_name find find_topic", :id => "find_topic_by_name" } do |f| %>
- <%= f.autocomplete_field :name, autocomplete_item_name_items_path, :id => "topic_by_name_input", :placeholder => "Search for topics..." %>
+ <%= form_for Topic.new, :html => { :class => "find_topic_by_name find find_topic", :id => "find_topic_by_name" } do |f| %>
+ <%= f.autocomplete_field :name, autocomplete_topic_name_topics_path, :id => "topic_by_name_input", :placeholder => "Search for topics..." %>
<% end %>
<%= form_for Map.new, :html => { :class => "find_map_by_name find", :id => "find_map_by_name" } do |f| %>
<%= f.autocomplete_field :name, autocomplete_map_name_maps_path, :id => "map_by_name_input", :placeholder => "Search for maps..." %>
diff --git a/app/views/main/metamap.html.erb b/app/views/main/metamap.html.erb
index f0977cac..23191a42 100644
--- a/app/views/main/metamap.html.erb
+++ b/app/views/main/metamap.html.erb
@@ -1,4 +1,4 @@
-<% unless @item.nil? %>
+<% unless @topic.nil? %>