made it so that only synapses can be created on topic pages, not new topics. Restructured the URL address system
This commit is contained in:
parent
84e9f59b8a
commit
37e41c87bf
21 changed files with 357 additions and 311 deletions
|
@ -221,8 +221,8 @@ function showAll(duration) {
|
|||
|
||||
$('.find_topic_by_name #topic_by_name_input').bind('railsAutocomplete.select', function(event, data){
|
||||
/* Do something here */
|
||||
if (data.item.user_id != undefined && data.item.id != undefined) {
|
||||
window.open("/users/" + data.item.user_id + "/items/" + data.item.id)
|
||||
if (data.item.id != undefined) {
|
||||
window.open("/items/" + data.item.id)
|
||||
}
|
||||
$('.find_topic_by_name #topic_by_name_input').val('');
|
||||
});
|
||||
|
@ -233,8 +233,8 @@ function showAll(duration) {
|
|||
|
||||
$('.find_map_by_name #map_by_name_input').bind('railsAutocomplete.select', function(event, data){
|
||||
/* Do something here */
|
||||
if (data.item.user_id != undefined && data.item.id != undefined) {
|
||||
window.open("/users/" + data.item.user_id + "/maps/" + data.item.id)
|
||||
if (data.item.id != undefined) {
|
||||
window.open("/maps/" + data.item.id)
|
||||
}
|
||||
$('.find_map_by_name #map_by_name_input').val('');
|
||||
});
|
||||
|
|
|
@ -57,54 +57,7 @@ function graphSettings(type) {
|
|||
},
|
||||
//Update node positions when dragged
|
||||
onDragMove: function (node, eventInfo, e) {
|
||||
if (node && !node.nodeFrom) {
|
||||
$('#new_synapse').fadeOut('fast');
|
||||
$('#new_item').fadeOut('fast');
|
||||
var pos = eventInfo.getPos();
|
||||
// if it's a left click, move the node
|
||||
if (e.button == 0) {
|
||||
node.pos.setc(pos.x, pos.y);
|
||||
Mconsole.plot();
|
||||
}
|
||||
// if it's a right click, start synapse creation
|
||||
else if (e.button == 2) {
|
||||
if (tempInit == false) {
|
||||
tempNode = node;
|
||||
tempInit = true;
|
||||
}
|
||||
//
|
||||
temp = eventInfo.getNode();
|
||||
if (temp != false && temp.id != node.id) { // this means a Node has been returned
|
||||
tempNode2 = temp;
|
||||
Mconsole.plot();
|
||||
renderMidArrow({ x: tempNode.pos.x, y: tempNode.pos.y }, { x: temp.pos.x, y: temp.pos.y }, 13, false, Mconsole.canvas);
|
||||
// before making the highlighted one bigger, make sure all the others are regular size
|
||||
Mconsole.graph.eachNode(function (n) {
|
||||
n.setData('dim', 25, 'current');
|
||||
});
|
||||
temp.setData('dim',35,'current');
|
||||
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
|
||||
Mconsole.fx.plotNode(temp, Mconsole.canvas);
|
||||
} else if (!temp) {
|
||||
Mconsole.graph.eachNode(function (n) {
|
||||
n.setData('dim', 25, 'current');
|
||||
});
|
||||
//pop up node creation :)
|
||||
$('#item_grabItem').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_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);
|
||||
Mconsole.plot();
|
||||
renderMidArrow({ x: tempNode.pos.x, y: tempNode.pos.y }, { x: pos.x, y: pos.y }, 13, false, Mconsole.canvas);
|
||||
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
clickDragOnTopicForceDirected(node, eventInfo, e);
|
||||
},
|
||||
onDragEnd: function() {
|
||||
if (tempInit && tempNode2 == null) {
|
||||
|
@ -124,15 +77,13 @@ function graphSettings(type) {
|
|||
}
|
||||
},
|
||||
onDragCancel: function() {
|
||||
if (tempInit && tempNode2 == null) {
|
||||
tempNode = null;
|
||||
tempNode2 = null;
|
||||
tempInit = false;
|
||||
$('#item_addSynapse').val("false");
|
||||
$('#item_item1id').val(0);
|
||||
$('#item_item2id').val(0);
|
||||
Mconsole.plot();
|
||||
}
|
||||
tempNode = null;
|
||||
tempNode2 = null;
|
||||
tempInit = false;
|
||||
$('#item_addSynapse').val("false");
|
||||
$('#item_item1id').val(0);
|
||||
$('#item_item2id').val(0);
|
||||
Mconsole.plot();
|
||||
},
|
||||
//Implement the same handler for touchscreens
|
||||
onTouchMove: function (node, eventInfo, e) {
|
||||
|
@ -162,7 +113,7 @@ function graphSettings(type) {
|
|||
var html =
|
||||
'<div class="CardOnGraph" title="Click to Hide" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p>' +
|
||||
'<img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" />' +
|
||||
'<div class="scroll"><a href="/users/' + node.getData("userid") + '/items/' + node.id + '" class="title">' + node.name + '</a>' +
|
||||
'<div class="scroll"><a href="/items/' + node.id + '" class="title">' + node.name + '</a>' +
|
||||
'<div class="contributor">Added by: <a href="/users/' + node.getData('userid') + '">' + node.getData('username') + '</a></div>' +
|
||||
'<div class="desc"><p>' + node.getData('desc') + '</p></div></div>' +
|
||||
'<a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
||||
|
@ -283,12 +234,32 @@ function graphSettings(type) {
|
|||
},
|
||||
//Update node positions when dragged
|
||||
onDragMove: function (node, eventInfo, e) {
|
||||
if (node && !node.nodeFrom) {
|
||||
var pos = eventInfo.getPos();
|
||||
node.pos.setc(pos.x, pos.y);
|
||||
Mconsole.plot();
|
||||
}
|
||||
clickDragOnTopicRGraph(node, eventInfo, e);
|
||||
},
|
||||
onDragEnd: function() {
|
||||
if (tempInit && tempNode2 != null) {
|
||||
$('#item_addSynapse').val("false");
|
||||
$('#synapse_item1id').val(tempNode.id);
|
||||
$('#synapse_item2id').val(tempNode2.id);
|
||||
$('#new_synapse').fadeIn('fast');
|
||||
$('#synapse_desc').focus();
|
||||
tempNode = null;
|
||||
tempNode2 = null;
|
||||
tempInit = false;
|
||||
}
|
||||
else {
|
||||
tempNode = null;
|
||||
tempNode2 = null;
|
||||
tempInit = false;
|
||||
Mconsole.plot();
|
||||
}
|
||||
},
|
||||
onDragCancel: function() {
|
||||
tempNode = null;
|
||||
tempNode2 = null;
|
||||
tempInit = false;
|
||||
Mconsole.plot();
|
||||
},
|
||||
//Implement the same handler for touchscreens
|
||||
onTouchMove: function (node, eventInfo, e) {
|
||||
$jit.util.event.stop(e); //stop default touchmove event
|
||||
|
@ -307,7 +278,8 @@ function graphSettings(type) {
|
|||
hideLabels: false
|
||||
});
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
canvasDoubleClickHandler(eventInfo.getPos(), e);
|
||||
}//if
|
||||
}//onClick
|
||||
|
@ -322,7 +294,7 @@ function graphSettings(type) {
|
|||
var html =
|
||||
'<div class="CardOnGraph" title="Click to Hide" id="item_' + node.id + '"><p class="type">' + node.getData("itemcatname") + '</p>' +
|
||||
'<img alt="' + node.getData("itemcatname") + '" class="icon" height="50" src="' + imgArray[node.getData("itemcatname")].src + '" width="50" />' +
|
||||
'<div class="scroll"><a href="/users/' + node.getData("userid") + '/items/' + node.id + '" class="title">' + node.name + '</a>' +
|
||||
'<div class="scroll"><a href="/items/' + node.id + '" class="title">' + node.name + '</a>' +
|
||||
'<div class="contributor">Added by: <a href="/users/' + node.getData('userid') + '">' + node.getData('username') + '</a></div>' +
|
||||
'<div class="desc"><p>' + node.getData('desc') + '</p></div></div>' +
|
||||
'<a href="' + node.getData('link') + '" class="link" target="_blank">' + node.getData('link') + '</a></div>';
|
||||
|
@ -520,7 +492,7 @@ function canvasDoubleClickHandler(canvasLoc,e) {
|
|||
var storedTime = canvasDoubleClickHandlerObject.storedTime;
|
||||
var now = Date.now(); //not compatible with IE8 FYI
|
||||
|
||||
if (now - storedTime < TOLERANCE) {
|
||||
if (now - storedTime < TOLERANCE && (gType == "arranged" || gType == "chaotic")) {
|
||||
//pop up node creation :)
|
||||
$('#item_grabItem').val("null");
|
||||
$('#item_addSynapse').val("false");
|
||||
|
@ -532,7 +504,9 @@ function canvasDoubleClickHandler(canvasLoc,e) {
|
|||
$('#item_name').focus();
|
||||
} else {
|
||||
canvasDoubleClickHandlerObject.storedTime = now;
|
||||
$('#new_item').fadeOut('fast');
|
||||
if (gType != "centered") {
|
||||
$('#new_item').fadeOut('fast');
|
||||
}
|
||||
$('#new_synapse').fadeOut('fast');
|
||||
tempInit = false;
|
||||
tempNode = null;
|
||||
|
@ -540,3 +514,102 @@ function canvasDoubleClickHandler(canvasLoc,e) {
|
|||
Mconsole.plot();
|
||||
}
|
||||
}//canvasDoubleClickHandler
|
||||
|
||||
// ForceDirected Mode: for the creation of new topics and synapses through clicking and draggin with right clicks off of topics
|
||||
function clickDragOnTopicForceDirected(node, eventInfo, e) {
|
||||
if (node && !node.nodeFrom) {
|
||||
$('#new_synapse').fadeOut('fast');
|
||||
$('#new_item').fadeOut('fast');
|
||||
var pos = eventInfo.getPos();
|
||||
// if it's a left click, move the node
|
||||
if (e.button == 0) {
|
||||
node.pos.setc(pos.x, pos.y);
|
||||
Mconsole.plot();
|
||||
}
|
||||
// if it's a right click, start synapse creation
|
||||
else if (e.button == 2) {
|
||||
if (tempInit == false) {
|
||||
tempNode = node;
|
||||
tempInit = true;
|
||||
}
|
||||
//
|
||||
temp = eventInfo.getNode();
|
||||
if (temp != false && temp.id != node.id) { // this means a Node has been returned
|
||||
tempNode2 = temp;
|
||||
Mconsole.plot();
|
||||
renderMidArrow({ x: tempNode.pos.x, y: tempNode.pos.y }, { x: temp.pos.x, y: temp.pos.y }, 13, false, Mconsole.canvas);
|
||||
// before making the highlighted one bigger, make sure all the others are regular size
|
||||
Mconsole.graph.eachNode(function (n) {
|
||||
n.setData('dim', 25, 'current');
|
||||
});
|
||||
temp.setData('dim',35,'current');
|
||||
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
|
||||
Mconsole.fx.plotNode(temp, Mconsole.canvas);
|
||||
} else if (!temp) {
|
||||
Mconsole.graph.eachNode(function (n) {
|
||||
n.setData('dim', 25, 'current');
|
||||
});
|
||||
//pop up node creation :)
|
||||
$('#item_grabItem').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_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);
|
||||
Mconsole.plot();
|
||||
renderMidArrow({ x: tempNode.pos.x, y: tempNode.pos.y }, { x: pos.x, y: pos.y }, 13, false, Mconsole.canvas);
|
||||
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RGRAPH MODE: for the creation of synapses through clicking and draggin with right clicks off of topics
|
||||
function clickDragOnTopicRGraph(node, eventInfo, e) {
|
||||
if (node && !node.nodeFrom) {
|
||||
$('#new_synapse').fadeOut('fast');
|
||||
var pos = eventInfo.getPos();
|
||||
|
||||
// if it's a left click, move the node
|
||||
if (e.button == 0) {
|
||||
node.pos.setc(pos.x, pos.y);
|
||||
Mconsole.plot();
|
||||
}
|
||||
// if it's a right click, start synapse creation
|
||||
else if (e.button == 2) {
|
||||
if (tempInit == false) {
|
||||
tempNode = node;
|
||||
tempInit = true;
|
||||
}
|
||||
//
|
||||
temp = eventInfo.getNode();
|
||||
if (temp != false && temp.id != node.id) { // this means a Node has been returned
|
||||
tempNode2 = temp;
|
||||
Mconsole.plot();
|
||||
renderMidArrow({ x: tempNode.pos.getc().x, y: tempNode.pos.getc().y }, { x: temp.pos.getc().x, y: temp.pos.getc().y }, 13, false, Mconsole.canvas);
|
||||
// before making the highlighted one bigger, make sure all the others are regular size
|
||||
Mconsole.graph.eachNode(function (n) {
|
||||
n.setData('dim', 25, 'current');
|
||||
});
|
||||
temp.setData('dim',35,'current');
|
||||
Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
|
||||
Mconsole.fx.plotNode(temp, Mconsole.canvas);
|
||||
} else if (!temp) {
|
||||
tempNode2 = null;
|
||||
Mconsole.graph.eachNode(function (n) {
|
||||
n.setData('dim', 25, 'current');
|
||||
});
|
||||
var myX = e.x - 110;
|
||||
var myY = e.y - 30;
|
||||
document.getElementById('new_synapse').style.left = myX + "px";
|
||||
document.getElementById('new_synapse').style.top = myY + "px";
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,17 +7,22 @@ class ItemsController < ApplicationController
|
|||
autocomplete :item, :name, :full => true, :extra_data => [:user_id]
|
||||
|
||||
|
||||
# GET /users/:user_id/items
|
||||
# GET items
|
||||
# or GET /users/:user_id/items
|
||||
def index
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@items = Item.visibleToUser(@current, @user)
|
||||
|
||||
if params[:user_id]
|
||||
@user = User.find(params[:user_id])
|
||||
@items = Item.visibleToUser(@current, @user)
|
||||
elsif
|
||||
@items = Item.visibleToUser(@current, nil)
|
||||
end
|
||||
|
||||
respond_with(@user,@items)
|
||||
end
|
||||
|
||||
# Get /users/:user_id/items/new
|
||||
# Get items/new
|
||||
def new
|
||||
@item = Item.new
|
||||
@user = current_user
|
||||
|
@ -25,26 +30,24 @@ class ItemsController < ApplicationController
|
|||
respond_with(@item)
|
||||
end
|
||||
|
||||
# GET /users/:user_id/items/:id
|
||||
# GET items/:id
|
||||
def show
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@item = @user.items.find(params[:id]).authorize_to_show(@current)
|
||||
@current = current_user
|
||||
@item = Item.find(params[:id]).authorize_to_show(@current)
|
||||
|
||||
if @item
|
||||
@relatives = @item.network_as_json(@current).html_safe
|
||||
else
|
||||
redirect_to root_url and return
|
||||
end
|
||||
if @item
|
||||
@relatives = @item.network_as_json(@current).html_safe
|
||||
else
|
||||
redirect_to root_url and return
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@item, @user) }
|
||||
format.json { respond_with(@relatives) }
|
||||
end
|
||||
end
|
||||
|
||||
# POST /users/:user_id/items
|
||||
# POST items
|
||||
def create
|
||||
|
||||
@user = current_user
|
||||
|
@ -90,69 +93,63 @@ class ItemsController < ApplicationController
|
|||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: user_item_url(@user, @item)) }
|
||||
format.html { respond_with(@user, location: item_url(@item)) }
|
||||
format.js { respond_with(@item, @mapping, @synapse, @position) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# GET /users/:user_id/items/:id/edit
|
||||
# GET items/:id/edit
|
||||
def edit
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@item = @user.items.find(params[:id]).authorize_to_edit(@current)
|
||||
@current = current_user
|
||||
@item = Item.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
if not @item
|
||||
redirect_to root_url and return
|
||||
end
|
||||
if not @item
|
||||
redirect_to root_url and return
|
||||
end
|
||||
|
||||
respond_with(@item)
|
||||
respond_with(@item)
|
||||
end
|
||||
|
||||
# PUT /users/:user_id/items/:id
|
||||
# PUT items/:id
|
||||
def update
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@item = @user.items.find(params[:id])
|
||||
@current = current_user
|
||||
@item = Item.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
if @item
|
||||
@item.name = params[:item][:name]
|
||||
@item.desc = params[:item][:desc]
|
||||
@item.link = params[:item][:link]
|
||||
@item.permission = params[:item][:permission]
|
||||
@item.item_category = ItemCategory.find(params[:category][:item_category_id])
|
||||
|
||||
@item.save
|
||||
if @item
|
||||
@item.name = params[:item][:name]
|
||||
@item.desc = params[:item][:desc]
|
||||
@item.link = params[:item][:link]
|
||||
@item.permission = params[:item][:permission]
|
||||
@item.item_category = ItemCategory.find(params[:category][:item_category_id])
|
||||
@item.save
|
||||
end
|
||||
|
||||
respond_with(@user, location: user_item_url(@user, @item)) do |format|
|
||||
respond_with(@user, location: item_url(@item)) do |format|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# DELETE /users/:user_id/items/:id
|
||||
# DELETE items/:id
|
||||
def destroy
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@item = @user.items.find(params[:id])
|
||||
|
||||
@synapses = @item.synapses
|
||||
@mappings = @item.mappings
|
||||
|
||||
@synapses.each do |synapse|
|
||||
synapse.delete
|
||||
end
|
||||
|
||||
@mappings.each do |mapping|
|
||||
mapping.delete
|
||||
end
|
||||
|
||||
@item.delete
|
||||
|
||||
respond_to do |format|
|
||||
@current = current_user
|
||||
@item = Item.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
if @item
|
||||
@synapses = @item.synapses
|
||||
@mappings = @item.mappings
|
||||
|
||||
@synapses.each do |synapse|
|
||||
synapse.delete
|
||||
end
|
||||
|
||||
@mappings.each do |mapping|
|
||||
mapping.delete
|
||||
end
|
||||
|
||||
@item.delete
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,17 +6,23 @@ class MapsController < ApplicationController
|
|||
|
||||
autocomplete :map, :name, :full => true, :extra_data => [:user_id]
|
||||
|
||||
# GET /users/:user_id/maps
|
||||
# GET /maps
|
||||
# or GET /users/:user_id/maps
|
||||
def index
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@maps = Map.visibleToUser(@current, @user)
|
||||
|
||||
respond_with(@maps,@user)
|
||||
|
||||
@current = current_user
|
||||
|
||||
if params[:user_id]
|
||||
@user = User.find(params[:user_id])
|
||||
@maps = Map.visibleToUser(@current, @user)
|
||||
elsif
|
||||
@maps = Map.visibleToUser(@current, nil)
|
||||
end
|
||||
|
||||
respond_with(@maps,@user)
|
||||
end
|
||||
|
||||
# GET /users/:user_id/maps/new
|
||||
# GET maps/new
|
||||
def new
|
||||
@map = Map.new
|
||||
@user = current_user
|
||||
|
@ -24,116 +30,104 @@ class MapsController < ApplicationController
|
|||
respond_with(@map)
|
||||
end
|
||||
|
||||
# GET Get /users/:user_id/maps/:id
|
||||
# GET maps/:id
|
||||
def show
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@map = @user.maps.find(params[:id]).authorize_to_show(@current)
|
||||
@current = current_user
|
||||
@map = Map.find(params[:id]).authorize_to_show(@current)
|
||||
|
||||
if not @map
|
||||
redirect_to root_url and return
|
||||
end
|
||||
if not @map
|
||||
redirect_to root_url and return
|
||||
end
|
||||
|
||||
@mapjson = @map.self_as_json(@current).html_safe
|
||||
@mapjson = @map.self_as_json(@current).html_safe
|
||||
|
||||
respond_to do |format|
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@map, @user) }
|
||||
format.json { respond_with(@mapjson) }
|
||||
end
|
||||
end
|
||||
|
||||
# POST /users/:user_id/maps
|
||||
# POST maps
|
||||
def create
|
||||
|
||||
@user = current_user
|
||||
@map = Map.create(params[:map])
|
||||
@map = Map.create(params[:map])
|
||||
@map.user = @user
|
||||
@map.arranged = false
|
||||
@map.save
|
||||
@map.arranged = false
|
||||
@map.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: user_map_path(@user, @map)) }
|
||||
format.html { respond_with(@user, location: map_path(@map)) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# GET /users/:user_id/maps/:id/edit
|
||||
# GET maps/:id/edit
|
||||
def edit
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@map = @user.maps.find(params[:id]).authorize_to_edit(@current)
|
||||
@current = current_user
|
||||
@map = Map.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
if not @map
|
||||
redirect_to root_url and return
|
||||
end
|
||||
if not @map
|
||||
redirect_to root_url and return
|
||||
end
|
||||
|
||||
@outitems = @map.items.order("name ASC").delete_if{|item| not item.authorize_to_view(@current)}
|
||||
@outitems = @map.items.order("name ASC").delete_if{|item| not item.authorize_to_view(@current)}
|
||||
|
||||
respond_with(@user, @map, @outitems)
|
||||
respond_with(@user, @map, @outitems)
|
||||
end
|
||||
|
||||
# PUT /users/:user_id/maps/:id
|
||||
# PUT maps/:id
|
||||
def update
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@map = @user.maps.find(params[:id])
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
@map.attributes = params[:map]
|
||||
@map.save
|
||||
@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
|
||||
@mapping.delete
|
||||
end
|
||||
end
|
||||
if params[:outitems]
|
||||
@outitems = params[:outitems]
|
||||
@outitems.each do |item|
|
||||
@mapping = Mapping.where("map_id = ? AND item_id = ?", @map.id, item).first
|
||||
@mapping.delete
|
||||
end
|
||||
end
|
||||
|
||||
respond_with(@user, location: user_map_path(@user, @map)) do |format|
|
||||
respond_with(@user, location: map_path(@map)) do |format|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# PUT /users/:user_id/maps/:id/savelayout
|
||||
# PUT maps/:id/savelayout
|
||||
def savelayout
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@map = @user.maps.find(params[:id])
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
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]
|
||||
@mapping.save
|
||||
end
|
||||
@map.arranged = true
|
||||
@map.save
|
||||
end
|
||||
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]
|
||||
@mapping.save
|
||||
end
|
||||
@map.arranged = true
|
||||
@map.save
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /users/:user_id/maps/:id
|
||||
def destroy
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@map = @user.maps.find(params[:id])
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
@mappings = @map.mappings
|
||||
@mappings = @map.mappings
|
||||
|
||||
@mappings.each do |mapping|
|
||||
mapping.delete
|
||||
end
|
||||
@mappings.each do |mapping|
|
||||
mapping.delete
|
||||
end
|
||||
|
||||
@map.delete
|
||||
@map.delete
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,13 +7,19 @@ class SynapsesController < ApplicationController
|
|||
|
||||
autocomplete :synapse, :desc, :full => true
|
||||
|
||||
# GET users/:user_id/synapses
|
||||
# GET synapses
|
||||
# or GET users/:user_id/synapses
|
||||
def index
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@synapses = Synapse.visibleToUser(@current, @user)
|
||||
@synapsesjson = synapses_as_json(@current, @synapses).html_safe
|
||||
@current = current_user
|
||||
|
||||
if params[:user_id]
|
||||
@user = User.find(params[:user_id])
|
||||
@synapses = Synapse.visibleToUser(@current, @user)
|
||||
elsif
|
||||
@synapses = Synapse.visibleToUser(@current, nil)
|
||||
end
|
||||
|
||||
@synapsesjson = synapses_as_json(@current, @synapses).html_safe
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
@ -21,7 +27,7 @@ class SynapsesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# Get users/:user_id/synapses/new
|
||||
# Get synapses/new
|
||||
def new
|
||||
@synapse = Synapse.new
|
||||
@user = current_user
|
||||
|
@ -29,28 +35,26 @@ class SynapsesController < ApplicationController
|
|||
respond_with(@synapse)
|
||||
end
|
||||
|
||||
# GET users/:user_id/synapses/:id
|
||||
# GET synapses/:id
|
||||
def show
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@synapse = @user.synapses.find(params[:id]).authorize_to_show(@current)
|
||||
@item1 = @synapse.item1.authorize_to_show(@current)
|
||||
@item2 = @synapse.item2.authorize_to_show(@current)
|
||||
@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)
|
||||
|
||||
if @synapse && @item1 && @item2
|
||||
@synapsejson = @synapse.selfplusnodes_as_json.html_safe
|
||||
else
|
||||
redirect_to root_url and return
|
||||
end
|
||||
if @synapse && @item1 && @item2
|
||||
@synapsejson = @synapse.selfplusnodes_as_json.html_safe
|
||||
else
|
||||
redirect_to root_url and return
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { respond_with(@synapsejson) }
|
||||
end
|
||||
end
|
||||
|
||||
# POST users/:user_id/synapses
|
||||
# POST synapses
|
||||
def create
|
||||
|
||||
@user = current_user
|
||||
|
@ -64,65 +68,59 @@ class SynapsesController < ApplicationController
|
|||
@synapse.user = @user
|
||||
@synapse.save
|
||||
|
||||
if params[:synapse][:map]
|
||||
@mapping = Mapping.new()
|
||||
@mapping.category = "Synapse"
|
||||
@mapping.user = @user
|
||||
@mapping.map = Map.find(params[:synapse][:map])
|
||||
@mapping.synapse = @synapse
|
||||
@mapping.save
|
||||
end
|
||||
if params[:synapse][:map]
|
||||
@mapping = Mapping.new()
|
||||
@mapping.category = "Synapse"
|
||||
@mapping.user = @user
|
||||
@mapping.map = Map.find(params[:synapse][:map])
|
||||
@mapping.synapse = @synapse
|
||||
@mapping.save
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: user_synapse_url(@user, @synapse)) }
|
||||
format.html { respond_with(@user, location: synapse_url(@synapse)) }
|
||||
format.js { respond_with(@synapse) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# GET users/:user_id/synapses/:id/edit
|
||||
# GET synapses/:id/edit
|
||||
def edit
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@current = current_user
|
||||
@synapse = @user.synapses.find(params[:id]).authorize_to_edit(@current)
|
||||
@current = current_user
|
||||
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
if @synapse
|
||||
@items = Item.visibleToUser(@current, nil)
|
||||
elsif not @synapse
|
||||
redirect_to root_url and return
|
||||
end
|
||||
if @synapse
|
||||
@items = Item.visibleToUser(@current, nil)
|
||||
elsif not @synapse
|
||||
redirect_to root_url and return
|
||||
end
|
||||
|
||||
respond_with(@synapse, @items)
|
||||
respond_with(@synapse, @items)
|
||||
end
|
||||
|
||||
# PUT users/:user_id/synapses/:id
|
||||
# PUT synapses/:id
|
||||
def update
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@synapse = @user.synapses.find(params[:id])
|
||||
@current = current_user
|
||||
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
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])
|
||||
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.permission = params[:synapse][:permission]
|
||||
@synapse.save
|
||||
@synapse.save
|
||||
end
|
||||
|
||||
respond_with(@user, location: user_synapse_url(@user, @synapse)) do |format|
|
||||
respond_with(@user, location: synapse_url(@synapse)) do |format|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# DELETE users/:user_id/synapses/:id
|
||||
# DELETE synapses/:id
|
||||
def destroy
|
||||
@user = User.find(params[:user_id])
|
||||
|
||||
@synapse = @user.synapses.find(params[:id])
|
||||
@current = current_user
|
||||
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
@synapse.delete
|
||||
@synapse.delete if @synapse
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<%= div_for item, class: item.item_category.name do %>
|
||||
<% if item.user == user %><%= link_to 'Delete', user_item_path(@user,item), :class => 'delete', :confirm => 'Delete this topic and all synapses linking to it?', :method => :delete, :remote => true%><% end %>
|
||||
<% if item.user == user %><%= link_to 'Delete', item_path(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' %>
|
||||
<div class="scroll">
|
||||
<%= link_to item.name, user_item_path(@user, item), :class => 'title' %>
|
||||
<%= link_to item.name, item_path(item), :class => 'title' %>
|
||||
<div class="desc"><p><%=item.desc %></p></div>
|
||||
</div>
|
||||
<%= link_to item.link, item.link, :class => 'link', :target => '_blank' %>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="anypage">
|
||||
<%= form_for Item.new, url: user_items_url(user), remote: true do |form| %>
|
||||
<%= form_for Item.new, url: items_url, remote: true do |form| %>
|
||||
<%= form.autocomplete_field :name, autocomplete_item_name_items_path, :placeholder => "What is the name of your topic?" %>
|
||||
<%= form.hidden_field :x, :value => 0 %>
|
||||
<%= form.hidden_field :y, :value => 0 %>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_for @item, url: user_item_url do |form| %>
|
||||
<%= form_for @item, url: item_url do |form| %>
|
||||
<h3>Edit Item</h3>
|
||||
<label for="category">Category</label>
|
||||
<%= select "category", "item_category_id", ItemCategory.order("name ASC").all.collect {|p| [ p.name, p.id ] }, { :selected => @item.item_category.id } %>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="nothidden">
|
||||
<%= form_for @item || Item.new, url: user_items_path do |form| %>
|
||||
<%= form_for @item || Item.new, url: items_path do |form| %>
|
||||
<h3>Add Topic</h3>
|
||||
<label for="category">Category</label>
|
||||
<%= select_tag "category", options_from_collection_for_select(ItemCategory.order("name ASC").all, "id", "name") %>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<%= image_tag @item.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||
</div>
|
||||
<div class="focusmiddle">
|
||||
<h1 class="title"><%= @item.name %> <% if (@item.permission == "commons" && authenticated?) || @item.user == user %><%= link_to "[edit]", edit_user_item_path(@user, @item) %><% end %></h1>
|
||||
<h1 class="title"><%= @item.name %> <% if (@item.permission == "commons" && authenticated?) || @item.user == user %><%= link_to "[edit]", edit_item_path(@item) %><% end %></h1>
|
||||
<div class="desc">
|
||||
<p><%= @item.desc %></p>
|
||||
</div>
|
||||
|
@ -32,7 +32,6 @@
|
|||
</script>
|
||||
|
||||
<% if authenticated? %>
|
||||
<%= render :partial => 'items/new' %>
|
||||
<%= render :partial => 'synapses/new' %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<li><%= link_to "Invite", invite_path %></li>
|
||||
<li><%= link_to "Settings", edit_user_url(user) %></li>
|
||||
<% unless Map.first(:conditions => [ "id = ?", 7]).nil? %>
|
||||
<li><%= link_to "Feedback", user_map_path(User.find(555629996), Map.find(7)) %></li>
|
||||
<li><%= link_to "Feedback", map_path(Map.find(7)) %></li>
|
||||
<% end %>
|
||||
<li class="last"><%= link_to "Logout", session_path, method: 'delete', id: "Login" %></li>
|
||||
</ul>
|
||||
|
@ -45,7 +45,7 @@
|
|||
<li class="createWrap">
|
||||
<p id="create">CREATE</p>
|
||||
<ul class="create">
|
||||
<li class="first"><%= link_to "Add Map", new_user_map_path(user), id: "newmap" %></li>
|
||||
<li class="first"><%= link_to "Add Map", new_map_path, id: "newmap" %></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<%= div_for map do %>
|
||||
<% if map.user == user %><%= link_to 'Delete', user_map_path(map.user,map), :class => 'delete', :confirm => 'Delete this map (nodes and synapses will remain)?', :method => :delete, :remote => true %><% end %>
|
||||
<% if map.user == user %><%= link_to 'Delete', map_path(map), :class => 'delete', :confirm => 'Delete this map (nodes and synapses will remain)?', :method => :delete, :remote => true %><% end %>
|
||||
<div class="scroll">
|
||||
<%= link_to map.name, user_map_path(map.user, map), :class => 'title' %>
|
||||
<%= link_to map.name, map_path(map), :class => 'title' %>
|
||||
<div class="desc"><p><%= map.desc %></p><p># of Topics: <%= map.items.count %></p><p># of Synapses: <%= map.synapses.count %></p></div>
|
||||
</div>
|
||||
<div class="link"><p>Permissions:<%= map.permission %></p></div>
|
||||
|
|
|
@ -1,22 +1,8 @@
|
|||
<div class="anypage">
|
||||
<%= form_for Synapse.new, url: user_synapses_url(user), remote: true do |form| %>
|
||||
<button id="closenewsynapse" onclick="$('#new_synapse').fadeOut('fast'); $('#new_synapse')[0].reset(); return false;">close</button>
|
||||
<h3>Add Synapse Between Topics</h3>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node1_id">Choose First Topic</label>
|
||||
<%= select_tag :node1_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="item_category">Directionality of the Connection</label>
|
||||
<%= form.select :category, options_for_select(['none', 'both', 'from-to']) %>
|
||||
<label for="item_desc">Describe The Connection</label>
|
||||
<%= form.text_field :desc, class: "description" %>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node2_id">Choose Second Topic</label>
|
||||
<%= select_tag :node2_id, options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil), "id", "name") %>
|
||||
<% end %>
|
||||
<label for="synapse_permission">Permission</label>
|
||||
<%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %>
|
||||
<%= form.hidden_field :map, :value => @map.id %>
|
||||
<%= form.submit "Add Synapse", class: "add" %>
|
||||
<%= form_for Synapse.new, url: synapses_url, remote: true do |form| %>
|
||||
<%= form.autocomplete_field :desc, autocomplete_synapse_desc_synapses_path, :placeholder => "Describe the connection..." %>
|
||||
<%= form.hidden_field :item1id, :value => 0 %>
|
||||
<%= form.hidden_field :item2id, :value => 0 %>
|
||||
<%= form.hidden_field :map, :value => @map.id %>
|
||||
<% end %>
|
||||
</div>
|
|
@ -1,5 +1,5 @@
|
|||
<div class="anypage">
|
||||
<%= form_for Item.new, url: user_items_url(user), remote: true do |form| %>
|
||||
<%= form_for Item.new, url: items_url, remote: true do |form| %>
|
||||
<%= form.autocomplete_field :name, autocomplete_item_name_items_path, :placeholder => "What is the name of your topic?" %>
|
||||
<%= form.hidden_field :x, :value => 0 %>
|
||||
<%= form.hidden_field :y, :value => 0 %>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_for @map, url: user_map_url(@user, @map) do |form| %>
|
||||
<%= form_for @map, url: map_url(@map) do |form| %>
|
||||
<h3>Edit Map</h3>
|
||||
<label for="map_name">Name</label>
|
||||
<%= form.text_field :name %>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="nothidden">
|
||||
<%= form_for @map || Map.new, url: user_maps_url do |form|%>
|
||||
<%= form_for @map || Map.new, url: maps_url do |form|%>
|
||||
<h3>Add Map</h3>
|
||||
<label for="map_name">Name</label>
|
||||
<%= form.text_field :name %>
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
<p># of Topics: <%= @map.items.count %></p>
|
||||
<p># of Synapses: <%= @map.synapses.count %></p>
|
||||
<% if (@map.permission == "commons" && authenticated?) || @map.user == user %>
|
||||
<%= form_for @map, :url => savelayout_path(@user,@map), :html => { :class => "saveMapLayout", :id => "saveMapLayout"}, remote: true do |form| %>
|
||||
<%= form_for @map, :url => savelayout_path(@map), :html => { :class => "saveMapLayout", :id => "saveMapLayout"}, remote: true do |form| %>
|
||||
<%= form.hidden_field "coordinates", :value => "" %>
|
||||
<%= form.submit "Save Layout", class: "saveLayout", id: "saveLayout" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="focusmiddle">
|
||||
<h1 class="title"><%= @map.name %> <% if (@map.permission == "commons" && authenticated?) || @map.user == user %><%= link_to "[edit]", edit_user_map_path(@user, @map) %><% end %></h1>
|
||||
<h1 class="title"><%= @map.name %> <% if (@map.permission == "commons" && authenticated?) || @map.user == user %><%= link_to "[edit]", edit_map_path(@map) %><% end %></h1>
|
||||
<div class="desc">
|
||||
<p><%= @map.desc %></p>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="anypage">
|
||||
<%= form_for Synapse.new, url: user_synapses_url(user), remote: true do |form| %>
|
||||
<%= form_for Synapse.new, url: synapses_url, remote: true do |form| %>
|
||||
<%= form.autocomplete_field :desc, autocomplete_synapse_desc_synapses_path, :placeholder => "Describe the connection..." %>
|
||||
<%= form.hidden_field :item1id, :value => 0 %>
|
||||
<%= form.hidden_field :item2id, :value => 0 %>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_for @synapse, url: user_synapse_url do |form| %>
|
||||
<%= form_for @synapse, url: synapse_url do |form| %>
|
||||
<h3>Edit Synapse</h3>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node1_id">Choose First Topic</label>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="newsynapses">
|
||||
<%= form_for @synapse, url: user_synapses_url do |form| %>
|
||||
<%= form_for @synapse, url: synapses_url do |form| %>
|
||||
<h3>Add Synapse Between Topics</h3>
|
||||
<% if Item.visibleToUser(user, nil).count > 0 %>
|
||||
<label for="node1_id">Choose First Topic</label>
|
||||
|
|
|
@ -3,11 +3,10 @@ ISSAD::Application.routes.draw do
|
|||
root to: 'main#console', via: :get
|
||||
|
||||
match 'metamap', to: 'main#metamap', via: :get, as: :metamap
|
||||
match 'maps', to: 'main#allmaps', via: :get, as: :allmaps
|
||||
|
||||
match 'invite', to: 'main#invite', via: :get, as: :invite
|
||||
|
||||
match 'users/:user_id/maps/:id/savelayout', to: 'maps#savelayout', via: :put, as: :savelayout
|
||||
match 'maps/:id/savelayout', to: 'maps#savelayout', via: :put, as: :savelayout
|
||||
|
||||
resource :session
|
||||
|
||||
|
@ -25,9 +24,9 @@ ISSAD::Application.routes.draw do
|
|||
|
||||
resources :users do
|
||||
get :autocomplete_user_name, :on => :collection
|
||||
resources :items
|
||||
resources :synapses
|
||||
resources :maps
|
||||
resources :items, :only => [:index]
|
||||
resources :synapses, :only => [:index]
|
||||
resources :maps, :only => [:index]
|
||||
end
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
|
|
Loading…
Reference in a new issue