disabled awkward panning and zooming bugs by editing jit code
This commit is contained in:
parent
8260fdf7e0
commit
e5076533c0
|
@ -57,7 +57,7 @@ function graphSettings(type) {
|
||||||
},
|
},
|
||||||
//Update node positions when dragged
|
//Update node positions when dragged
|
||||||
onDragMove: function (node, eventInfo, e) {
|
onDragMove: function (node, eventInfo, e) {
|
||||||
clickDragOnTopic(node, eventInfo, e);
|
clickDragOnTopic(node, eventInfo, e);
|
||||||
},
|
},
|
||||||
onDragEnd: function() {
|
onDragEnd: function() {
|
||||||
if (tempInit && tempNode2 == null) {
|
if (tempInit && tempNode2 == null) {
|
||||||
|
@ -196,7 +196,7 @@ function graphSettings(type) {
|
||||||
},
|
},
|
||||||
//Update node positions when dragged
|
//Update node positions when dragged
|
||||||
onDragMove: function (node, eventInfo, e) {
|
onDragMove: function (node, eventInfo, e) {
|
||||||
clickDragOnTopic(node, eventInfo, e);
|
clickDragOnTopic(node, eventInfo, e);
|
||||||
},
|
},
|
||||||
onDragEnd: function() {
|
onDragEnd: function() {
|
||||||
if (tempInit && tempNode2 == null) {
|
if (tempInit && tempNode2 == null) {
|
||||||
|
@ -557,7 +557,6 @@ function onCreateLabelHandler(domElement, node) {
|
||||||
height="50" \
|
height="50" \
|
||||||
width="50" \
|
width="50" \
|
||||||
src="$_imgsrc_$" /> \
|
src="$_imgsrc_$" /> \
|
||||||
<div class="scroll"> \
|
|
||||||
<span class="title"> \
|
<span class="title"> \
|
||||||
<span class="best_in_place best_in_place_name" \
|
<span class="best_in_place best_in_place_name" \
|
||||||
data-url="/topics/$_id_$" \
|
data-url="/topics/$_id_$" \
|
||||||
|
@ -575,6 +574,7 @@ function onCreateLabelHandler(domElement, node) {
|
||||||
Added by: <a href="/users/$_userid_$" target="_blank">$_username_$ \
|
Added by: <a href="/users/$_userid_$" target="_blank">$_username_$ \
|
||||||
</a> \
|
</a> \
|
||||||
</div> \
|
</div> \
|
||||||
|
<div class="scroll"> \
|
||||||
<div class="desc"> \
|
<div class="desc"> \
|
||||||
<span class="best_in_place best_in_place_desc" \
|
<span class="best_in_place best_in_place_desc" \
|
||||||
data-url="/topics/$_id_$" \
|
data-url="/topics/$_id_$" \
|
||||||
|
@ -593,6 +593,7 @@ function onCreateLabelHandler(domElement, node) {
|
||||||
data-object="topic" \
|
data-object="topic" \
|
||||||
data-attribute="link" \
|
data-attribute="link" \
|
||||||
data-type="input">$_link_$</span>$_close_a_tag_$ \
|
data-type="input">$_link_$</span>$_close_a_tag_$ \
|
||||||
|
<div class="clearfloat"></div> \
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
//link is rendered differently if user is logged out or in
|
//link is rendered differently if user is logged out or in
|
||||||
|
|
|
@ -2585,6 +2585,9 @@ Extras.Classes.Navigation = new Class({
|
||||||
|
|
||||||
onMouseWheel: function(e, win, scroll) {
|
onMouseWheel: function(e, win, scroll) {
|
||||||
if(!this.config.zooming) return;
|
if(!this.config.zooming) return;
|
||||||
|
// START METAMAPS CODE
|
||||||
|
if (e.target.id != 'infovis-canvas') return;
|
||||||
|
// END METAMAPS CODE
|
||||||
$.event.stop($.event.get(e, win));
|
$.event.stop($.event.get(e, win));
|
||||||
var val = this.config.zooming / 1000,
|
var val = this.config.zooming / 1000,
|
||||||
ans = 1 + scroll * val;
|
ans = 1 + scroll * val;
|
||||||
|
@ -2611,6 +2614,12 @@ Extras.Classes.Navigation = new Class({
|
||||||
if(!this.config.panning) return;
|
if(!this.config.panning) return;
|
||||||
if(!this.pressed) return;
|
if(!this.pressed) return;
|
||||||
if(this.config.panning == 'avoid nodes' && eventInfo.getNode()) return;
|
if(this.config.panning == 'avoid nodes' && eventInfo.getNode()) return;
|
||||||
|
// START METAMAPS CODE
|
||||||
|
if (e.target.id != 'infovis-canvas') {
|
||||||
|
this.pressed = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// END METAMAPS CODE
|
||||||
var thispos = this.pos,
|
var thispos = this.pos,
|
||||||
currentPos = eventInfo.getPos(),
|
currentPos = eventInfo.getPos(),
|
||||||
canvas = this.canvas,
|
canvas = this.canvas,
|
||||||
|
|
|
@ -33,6 +33,7 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
|
||||||
$('#topic_name').bind('railsAutocomplete.select', function(event, data){
|
$('#topic_name').bind('railsAutocomplete.select', function(event, data){
|
||||||
if (data.item.id != undefined) {
|
if (data.item.id != undefined) {
|
||||||
$('#topic_grabTopic').val(data.item.id);
|
$('#topic_grabTopic').val(data.item.id);
|
||||||
|
$('.new_topic').submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -127,27 +127,19 @@
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add code that makes up and down arrows scroll through.
|
// Add code that makes tab and shift+tab scroll through metacodes
|
||||||
$('.new_topic').bind('keydown keypress',this,function(event) {
|
$('.new_topic').bind('keydown',this,function(event){
|
||||||
//console.log(event)
|
if (event.keyCode == 9 || (event.keyCode == 9 && event.shiftKey)) {
|
||||||
if (event.keyCode == 38 || event.keyCode == 40)
|
event.preventDefault();
|
||||||
{
|
|
||||||
//e.preventDefault();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('.new_topic').bind('keyup',this,function(event){
|
$('.new_topic').bind('keyup',this,function(event){
|
||||||
console.log(event);
|
//console.log(event);
|
||||||
/*key navigation through elements*/
|
/*key navigation through elements*/
|
||||||
if (event.keyCode == 38 || event.keyCode == 40) {
|
if (event.keyCode == 9 && event.shiftKey) {
|
||||||
switch ( event.keyCode ) {
|
event.data.rotate(-1);
|
||||||
case 38: // Up
|
} else if (event.keyCode == 9) {
|
||||||
event.data.rotate(-1);
|
event.data.rotate(1);
|
||||||
break;
|
|
||||||
case 40: // Down
|
|
||||||
event.data.rotate(1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
.CardOnGraph .scroll {
|
.CardOnGraph .scroll {
|
||||||
display:block;
|
display:block;
|
||||||
height:283px;
|
height:232px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.CardOnGraph .type {
|
.CardOnGraph .type {
|
||||||
|
@ -71,6 +71,15 @@
|
||||||
padding-bottom:5px;
|
padding-bottom:5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.CardOnGraph .best_in_place_name {
|
||||||
|
max-width:130px;
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CardOnGraph .best_in_place_name input{
|
||||||
|
max-width:130px;
|
||||||
|
}
|
||||||
|
|
||||||
.CardOnGraph .desc {
|
.CardOnGraph .desc {
|
||||||
font-size:15px;
|
font-size:15px;
|
||||||
font-family:Arial, Helvetica, sans-serif;
|
font-family:Arial, Helvetica, sans-serif;
|
||||||
|
@ -81,28 +90,47 @@
|
||||||
margin-top:5px;
|
margin-top:5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.CardOnGraph .link {
|
|
||||||
position:absolute;
|
|
||||||
width:170px;
|
|
||||||
top:295px;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CardOnGraph .best_in_place_desc {
|
|
||||||
width:160px;
|
|
||||||
height:180px;
|
|
||||||
display:block;
|
|
||||||
margin-top:2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CardOnGraph .best_in_place_desc input {
|
.CardOnGraph .best_in_place_desc input {
|
||||||
float: right;
|
float: right;
|
||||||
margin: 2px 0px 0px 2px;
|
margin: 2px 0px 0px 2px;
|
||||||
padding: 1px 5px;
|
padding: 1px 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.CardOnGraph .best_in_place_desc {
|
||||||
|
width:140px;
|
||||||
|
display:block;
|
||||||
|
margin-top:2px;
|
||||||
|
}
|
||||||
|
|
||||||
.CardOnGraph .best_in_place_desc input[value="Save"] {
|
.CardOnGraph .best_in_place_desc input[value="Save"] {
|
||||||
margin-right: -8px;
|
margin-right: -8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.CardOnGraph .link {
|
||||||
|
position:absolute;
|
||||||
|
width:170px;
|
||||||
|
top:293px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CardOnGraph .best_in_place_link {
|
||||||
|
width: 135px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
display: block;
|
||||||
|
float: left;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-top:2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CardOnGraph .best_in_place_link input {
|
||||||
|
width:130px;
|
||||||
|
margin-top:-2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CardOnGraph .go-link {
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
|
|
|
@ -75,16 +75,7 @@ line-height: 24px;}
|
||||||
.topic .desc { font-size:15px; font-family:Arial, Helvetica, sans-serif; }
|
.topic .desc { font-size:15px; font-family:Arial, Helvetica, sans-serif; }
|
||||||
.topic .desc h3 { font-style:normal; margin-top:5px; }
|
.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; }
|
.topic .link { position:absolute; width:140px; top:295px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
|
|
||||||
.best_in_place_name {
|
|
||||||
max-width:130px;
|
|
||||||
float:left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.best_in_place_name input{
|
|
||||||
max-width:130px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topic-go-arrow {
|
.topic-go-arrow {
|
||||||
width: 25px;
|
width: 25px;
|
||||||
|
|
|
@ -1,182 +1,182 @@
|
||||||
class TopicsController < ApplicationController
|
class TopicsController < ApplicationController
|
||||||
before_filter :require_user, only: [:new, :create, :edit, :update]
|
before_filter :require_user, only: [:new, :create, :edit, :update]
|
||||||
|
|
||||||
respond_to :html, :js, :json
|
respond_to :html, :js, :json
|
||||||
|
|
||||||
autocomplete :topic, :name, :full => true, :extra_data => [:user_id]
|
autocomplete :topic, :name, :full => true, :extra_data => [:user_id], :display_value => :topic_autocomplete_method
|
||||||
|
|
||||||
|
|
||||||
# GET topics
|
# GET topics
|
||||||
# or GET /users/:user_id/topics
|
# or GET /users/:user_id/topics
|
||||||
def index
|
def index
|
||||||
@current = current_user
|
@current = current_user
|
||||||
|
|
||||||
if params[:user_id]
|
if params[:user_id]
|
||||||
@user = User.find(params[:user_id])
|
@user = User.find(params[:user_id])
|
||||||
@topics = Topic.order("name ASC").visibleToUser(@current, @user)
|
@topics = Topic.order("name ASC").visibleToUser(@current, @user)
|
||||||
elsif
|
elsif
|
||||||
@topics = Topic.order("name ASC").visibleToUser(@current, nil)
|
@topics = Topic.order("name ASC").visibleToUser(@current, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with(@user,@topics)
|
respond_with(@user,@topics)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get topics/new
|
# Get topics/new
|
||||||
def new
|
def new
|
||||||
@topic = Topic.new
|
@topic = Topic.new
|
||||||
@user = current_user
|
@user = current_user
|
||||||
|
|
||||||
respond_with(@topic)
|
respond_with(@topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET topics/:id
|
# GET topics/:id
|
||||||
def show
|
def show
|
||||||
@current = current_user
|
@current = current_user
|
||||||
@topic = Topic.find(params[:id]).authorize_to_show(@current)
|
@topic = Topic.find(params[:id]).authorize_to_show(@current)
|
||||||
|
|
||||||
if @topic
|
if @topic
|
||||||
@relatives = @topic.network_as_json(@current).html_safe
|
@relatives = @topic.network_as_json(@current).html_safe
|
||||||
else
|
else
|
||||||
redirect_to root_url and return
|
redirect_to root_url and return
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@topic, @user) }
|
format.html { respond_with(@topic, @user) }
|
||||||
format.json { respond_with(@relatives) }
|
format.json { respond_with(@relatives) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST topics
|
# POST topics
|
||||||
def create
|
def create
|
||||||
|
|
||||||
@user = current_user
|
@user = current_user
|
||||||
|
|
||||||
# if the topic exists grab it and return it
|
# if the topic exists grab it and return it
|
||||||
if params[:topic][:grabTopic] != "null"
|
if params[:topic][:grabTopic] != "null"
|
||||||
@topic = Topic.find(params[:topic][:grabTopic])
|
@topic = Topic.find(params[:topic][:grabTopic])
|
||||||
# if the topic doesn't exist yet, create it
|
# if the topic doesn't exist yet, create it
|
||||||
else
|
else
|
||||||
@topic = Topic.new()
|
@topic = Topic.new()
|
||||||
@topic.name = params[:topic][:name]
|
@topic.name = params[:topic][:name]
|
||||||
@topic.desc = ""
|
@topic.desc = ""
|
||||||
@topic.link = ""
|
@topic.link = ""
|
||||||
@topic.permission = 'commons'
|
@topic.permission = 'commons'
|
||||||
@topic.metacode = Metacode.find_by_name(params[:topic][:metacode])
|
@topic.metacode = Metacode.find_by_name(params[:topic][:metacode])
|
||||||
@topic.user = @user
|
@topic.user = @user
|
||||||
|
|
||||||
@topic.save
|
@topic.save
|
||||||
end
|
end
|
||||||
|
|
||||||
# pass on to the topic create js whether it's being created with a synapse
|
# pass on to the topic create js whether it's being created with a synapse
|
||||||
@synapse = "false"
|
@synapse = "false"
|
||||||
if params[:topic][:addSynapse] == "true"
|
if params[:topic][:addSynapse] == "true"
|
||||||
@synapse = "true"
|
@synapse = "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
# also create an object to return the position to the canvas
|
# also create an object to return the position to the canvas
|
||||||
@position = Hash.new()
|
@position = Hash.new()
|
||||||
@position['x'] = params[:topic][:x]
|
@position['x'] = params[:topic][:x]
|
||||||
@position['y'] = params[:topic][:y]
|
@position['y'] = params[:topic][:y]
|
||||||
|
|
||||||
# set this for the case where the topic is being created on a map.
|
# set this for the case where the topic is being created on a map.
|
||||||
@mapping = Mapping.new()
|
@mapping = Mapping.new()
|
||||||
if params[:topic][:map]
|
if params[:topic][:map]
|
||||||
@mapping.category = "Topic"
|
@mapping.category = "Topic"
|
||||||
@mapping.user = @user
|
@mapping.user = @user
|
||||||
@mapping.map = Map.find(params[:topic][:map])
|
@mapping.map = Map.find(params[:topic][:map])
|
||||||
@mapping.topic = @topic
|
@mapping.topic = @topic
|
||||||
@mapping.xloc = params[:topic][:x]
|
@mapping.xloc = params[:topic][:x]
|
||||||
@mapping.yloc = params[:topic][:y]
|
@mapping.yloc = params[:topic][:y]
|
||||||
@mapping.save
|
@mapping.save
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@user, location: topic_url(@topic)) }
|
format.html { respond_with(@user, location: topic_url(@topic)) }
|
||||||
format.js { respond_with(@topic, @mapping, @synapse, @position) }
|
format.js { respond_with(@topic, @mapping, @synapse, @position) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET topics/:id/edit
|
# GET topics/:id/edit
|
||||||
def edit
|
def edit
|
||||||
@current = current_user
|
@current = current_user
|
||||||
@topic = Topic.find(params[:id]).authorize_to_edit(@current)
|
@topic = Topic.find(params[:id]).authorize_to_edit(@current)
|
||||||
|
|
||||||
if not @topic
|
if not @topic
|
||||||
redirect_to root_url and return
|
redirect_to root_url and return
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with(@topic)
|
respond_with(@topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT topics/:id
|
# PUT topics/:id
|
||||||
def update
|
def update
|
||||||
@current = current_user
|
@current = current_user
|
||||||
@topic = Topic.find(params[:id]).authorize_to_edit(@current)
|
@topic = Topic.find(params[:id]).authorize_to_edit(@current)
|
||||||
|
|
||||||
if @topic
|
if @topic
|
||||||
if params[:topic]
|
if params[:topic]
|
||||||
@topic.name = params[:topic][:name] if params[:topic][:name]
|
@topic.name = params[:topic][:name] if params[:topic][:name]
|
||||||
@topic.desc = params[:topic][:desc] if params[:topic][:desc]
|
@topic.desc = params[:topic][:desc] if params[:topic][:desc]
|
||||||
@topic.link = params[:topic][:link] if params[:topic][:link]
|
@topic.link = params[:topic][:link] if params[:topic][:link]
|
||||||
@topic.permission = params[:topic][:permission] if params[:topic][:permission]
|
@topic.permission = params[:topic][:permission] if params[:topic][:permission]
|
||||||
@topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) if params[:topic][:metacode]
|
@topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) if params[:topic][:metacode]
|
||||||
end
|
end
|
||||||
@topic.save
|
@topic.save
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with @topic
|
respond_with @topic
|
||||||
|
|
||||||
# respond_with(@user, location: topic_url(@topic)) do |format|
|
# respond_with(@user, location: topic_url(@topic)) do |format|
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET mappings/:map_id/:topic_id/removefrommap
|
# GET mappings/:map_id/:topic_id/removefrommap
|
||||||
def removefrommap
|
def removefrommap
|
||||||
@current = current_user
|
@current = current_user
|
||||||
@mapping = Mapping.find_by_topic_id_and_map_id(params[:topic_id],params[:map_id])
|
@mapping = Mapping.find_by_topic_id_and_map_id(params[:topic_id],params[:map_id])
|
||||||
|
|
||||||
@map = Map.find(params[:map_id])
|
@map = Map.find(params[:map_id])
|
||||||
@topic = Topic.find(params[:topic_id])
|
@topic = Topic.find(params[:topic_id])
|
||||||
@mappings = @map.mappings.select{|m|
|
@mappings = @map.mappings.select{|m|
|
||||||
if m.synapse != nil
|
if m.synapse != nil
|
||||||
m.synapse.topic1 == @topic || m.synapse.topic2 == @topic
|
m.synapse.topic1 == @topic || m.synapse.topic2 == @topic
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@mappings.each do |m|
|
@mappings.each do |m|
|
||||||
m.delete
|
m.delete
|
||||||
end
|
end
|
||||||
|
|
||||||
@mapping.delete
|
@mapping.delete
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE topics/:id
|
# DELETE topics/:id
|
||||||
def destroy
|
def destroy
|
||||||
@current = current_user
|
@current = current_user
|
||||||
@topic = Topic.find(params[:id]).authorize_to_edit(@current)
|
@topic = Topic.find(params[:id]).authorize_to_edit(@current)
|
||||||
|
|
||||||
if @topic
|
if @topic
|
||||||
@synapses = @topic.synapses
|
@synapses = @topic.synapses
|
||||||
@mappings = @topic.mappings
|
@mappings = @topic.mappings
|
||||||
|
|
||||||
@synapses.each do |synapse|
|
@synapses.each do |synapse|
|
||||||
synapse.delete
|
synapse.delete
|
||||||
end
|
end
|
||||||
|
|
||||||
@mappings.each do |mapping|
|
@mappings.each do |mapping|
|
||||||
mapping.delete
|
mapping.delete
|
||||||
end
|
end
|
||||||
|
|
||||||
@topic.delete
|
@topic.delete
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,195 +1,199 @@
|
||||||
class Topic < ActiveRecord::Base
|
class Topic < ActiveRecord::Base
|
||||||
|
|
||||||
include TopicsHelper
|
include TopicsHelper
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id'
|
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id'
|
||||||
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id'
|
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id'
|
||||||
has_many :topics1, :through => :synapses2, :source => :topic1
|
has_many :topics1, :through => :synapses2, :source => :topic1
|
||||||
has_many :topics2, :through => :synapses1, :source => :topic2
|
has_many :topics2, :through => :synapses1, :source => :topic2
|
||||||
|
|
||||||
has_many :mappings
|
has_many :mappings
|
||||||
has_many :maps, :through => :mappings
|
has_many :maps, :through => :mappings
|
||||||
|
|
||||||
def synapses
|
def synapses
|
||||||
synapses1 + synapses2
|
synapses1 + synapses2
|
||||||
end
|
end
|
||||||
|
|
||||||
def relatives
|
def relatives
|
||||||
topics1 + topics2
|
topics1 + topics2
|
||||||
end
|
end
|
||||||
|
|
||||||
belongs_to :metacode
|
belongs_to :metacode
|
||||||
|
|
||||||
# has no viewable synapses helper function
|
def topic_autocomplete_method
|
||||||
def has_viewable_synapses(current)
|
"Get: #{self.name}"
|
||||||
result = false
|
end
|
||||||
self.synapses.each do |synapse|
|
|
||||||
if synapse.authorize_to_view(current)
|
# has no viewable synapses helper function
|
||||||
result = true
|
def has_viewable_synapses(current)
|
||||||
end
|
result = false
|
||||||
end
|
self.synapses.each do |synapse|
|
||||||
return result
|
if synapse.authorize_to_view(current)
|
||||||
end
|
result = true
|
||||||
|
end
|
||||||
###### JSON ######
|
end
|
||||||
|
return result
|
||||||
def self_as_json
|
end
|
||||||
Jbuilder.encode do |json|
|
|
||||||
@inmaps = Array.new
|
###### JSON ######
|
||||||
self.maps.each do |map|
|
|
||||||
@inmaps.push(map.id)
|
def self_as_json
|
||||||
end
|
Jbuilder.encode do |json|
|
||||||
|
@inmaps = Array.new
|
||||||
@topicdata = Hash.new
|
self.maps.each do |map|
|
||||||
@topicdata['$desc'] = self.desc
|
@inmaps.push(map.id)
|
||||||
@topicdata['$link'] = self.link
|
end
|
||||||
@topicdata['$metacode'] = self.metacode.name
|
|
||||||
@topicdata['$inmaps'] = @inmaps
|
@topicdata = Hash.new
|
||||||
@topicdata['$userid'] = self.user.id
|
@topicdata['$desc'] = self.desc
|
||||||
@topicdata['$username'] = self.user.name
|
@topicdata['$link'] = self.link
|
||||||
json.data @topicdata
|
@topicdata['$metacode'] = self.metacode.name
|
||||||
json.id self.id
|
@topicdata['$inmaps'] = @inmaps
|
||||||
json.name self.name
|
@topicdata['$userid'] = self.user.id
|
||||||
end
|
@topicdata['$username'] = self.user.name
|
||||||
end
|
json.data @topicdata
|
||||||
|
json.id self.id
|
||||||
def selfonmap_as_json(mapid)
|
json.name self.name
|
||||||
Jbuilder.encode do |json|
|
end
|
||||||
@inmaps = Array.new
|
end
|
||||||
self.maps.each do |map|
|
|
||||||
@inmaps.push(map.id)
|
def selfonmap_as_json(mapid)
|
||||||
end
|
Jbuilder.encode do |json|
|
||||||
|
@inmaps = Array.new
|
||||||
@topicdata = Hash.new
|
self.maps.each do |map|
|
||||||
@topicdata['$desc'] = self.desc
|
@inmaps.push(map.id)
|
||||||
@topicdata['$link'] = self.link
|
end
|
||||||
@topicdata['$metacode'] = self.metacode.name
|
|
||||||
@topicdata['$inmaps'] = @inmaps
|
@topicdata = Hash.new
|
||||||
@topicdata['$userid'] = self.user.id
|
@topicdata['$desc'] = self.desc
|
||||||
@topicdata['$username'] = self.user.name
|
@topicdata['$link'] = self.link
|
||||||
@mapping = Mapping.find_by_topic_id_and_map_id(self.id,mapid)
|
@topicdata['$metacode'] = self.metacode.name
|
||||||
@topicdata['$xloc'] = @mapping.xloc
|
@topicdata['$inmaps'] = @inmaps
|
||||||
@topicdata['$yloc'] = @mapping.yloc
|
@topicdata['$userid'] = self.user.id
|
||||||
@topicdata['$mappingid'] = @mapping.id
|
@topicdata['$username'] = self.user.name
|
||||||
json.data @topicdata
|
@mapping = Mapping.find_by_topic_id_and_map_id(self.id,mapid)
|
||||||
json.id self.id
|
@topicdata['$xloc'] = @mapping.xloc
|
||||||
json.name self.name
|
@topicdata['$yloc'] = @mapping.yloc
|
||||||
end
|
@topicdata['$mappingid'] = @mapping.id
|
||||||
end
|
json.data @topicdata
|
||||||
|
json.id self.id
|
||||||
#build a json object of everything connected to a specified node
|
json.name self.name
|
||||||
def network_as_json(current)
|
end
|
||||||
Jbuilder.encode do |json|
|
end
|
||||||
@topics = network(self,nil,4)
|
|
||||||
|
#build a json object of everything connected to a specified node
|
||||||
if @topics.count > 1
|
def network_as_json(current)
|
||||||
json.array!(@topics.delete_if{|topic| (not topic.authorize_to_view(current)) || (not topic.has_viewable_synapses(current))}) do |topic|
|
Jbuilder.encode do |json|
|
||||||
|
@topics = network(self,nil,4)
|
||||||
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
|
if @topics.count > 1
|
||||||
json.nodeFrom synapse.node1_id
|
json.array!(@topics.delete_if{|topic| (not topic.authorize_to_view(current)) || (not topic.has_viewable_synapses(current))}) do |topic|
|
||||||
|
|
||||||
@synapsedata = Hash.new
|
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|
|
||||||
@synapsedata['$desc'] = synapse.desc
|
json.nodeTo synapse.node2_id
|
||||||
@synapsedata['$showDesc'] = false
|
json.nodeFrom synapse.node1_id
|
||||||
@synapsedata['$category'] = synapse.category
|
|
||||||
@synapsedata['$id'] = synapse.id
|
@synapsedata = Hash.new
|
||||||
@synapsedata['$userid'] = synapse.user.id
|
@synapsedata['$desc'] = synapse.desc
|
||||||
@synapsedata['$username'] = synapse.user.name
|
@synapsedata['$showDesc'] = false
|
||||||
@synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
|
@synapsedata['$category'] = synapse.category
|
||||||
json.data @synapsedata
|
@synapsedata['$id'] = synapse.id
|
||||||
end
|
@synapsedata['$userid'] = synapse.user.id
|
||||||
|
@synapsedata['$username'] = synapse.user.name
|
||||||
@inmaps = Array.new
|
@synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
|
||||||
topic.maps.each do |map|
|
json.data @synapsedata
|
||||||
@inmaps.push(map.id)
|
end
|
||||||
end
|
|
||||||
|
@inmaps = Array.new
|
||||||
@topicdata = Hash.new
|
topic.maps.each do |map|
|
||||||
@topicdata['$desc'] = topic.desc
|
@inmaps.push(map.id)
|
||||||
@topicdata['$link'] = topic.link
|
end
|
||||||
@topicdata['$metacode'] = topic.metacode.name
|
|
||||||
@topicdata['$inmaps'] = @inmaps
|
@topicdata = Hash.new
|
||||||
@topicdata['$userid'] = topic.user.id
|
@topicdata['$desc'] = topic.desc
|
||||||
@topicdata['$username'] = topic.user.name
|
@topicdata['$link'] = topic.link
|
||||||
json.data @topicdata
|
@topicdata['$metacode'] = topic.metacode.name
|
||||||
json.id topic.id
|
@topicdata['$inmaps'] = @inmaps
|
||||||
json.name topic.name
|
@topicdata['$userid'] = topic.user.id
|
||||||
end
|
@topicdata['$username'] = topic.user.name
|
||||||
elsif @topics.count == 1
|
json.data @topicdata
|
||||||
json.array!(@topics) do |topic|
|
json.id topic.id
|
||||||
@inmaps = Array.new
|
json.name topic.name
|
||||||
topic.maps.each do |map|
|
end
|
||||||
@inmaps.push(map.id)
|
elsif @topics.count == 1
|
||||||
end
|
json.array!(@topics) do |topic|
|
||||||
|
@inmaps = Array.new
|
||||||
@topicdata = Hash.new
|
topic.maps.each do |map|
|
||||||
@topicdata['$desc'] = topic.desc
|
@inmaps.push(map.id)
|
||||||
@topicdata['$link'] = topic.link
|
end
|
||||||
@topicdata['$metacode'] = topic.metacode.name
|
|
||||||
@topicdata['$inmaps'] = @inmaps
|
@topicdata = Hash.new
|
||||||
@topicdata['$userid'] = topic.user.id
|
@topicdata['$desc'] = topic.desc
|
||||||
@topicdata['$username'] = topic.user.name
|
@topicdata['$link'] = topic.link
|
||||||
json.data @topicdata
|
@topicdata['$metacode'] = topic.metacode.name
|
||||||
json.id topic.id
|
@topicdata['$inmaps'] = @inmaps
|
||||||
json.name topic.name
|
@topicdata['$userid'] = topic.user.id
|
||||||
end
|
@topicdata['$username'] = topic.user.name
|
||||||
end
|
json.data @topicdata
|
||||||
end
|
json.id topic.id
|
||||||
end
|
json.name topic.name
|
||||||
|
end
|
||||||
##### PERMISSIONS ######
|
end
|
||||||
|
end
|
||||||
scope :visibleToUser, lambda { |current, user|
|
end
|
||||||
if user != nil
|
|
||||||
if user != current
|
##### PERMISSIONS ######
|
||||||
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
|
scope :visibleToUser, lambda { |current, user|
|
||||||
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")
|
if user != nil
|
||||||
end
|
if user != current
|
||||||
elsif (current != nil && user == nil)
|
Topic.find_all_by_user_id_and_permission(user.id, "commons") | Topic.find_all_by_user_id_and_permission(user.id, "public")
|
||||||
Topic.find_all_by_permission("commons") | Topic.find_all_by_permission("public") | current.topics.where(:permission => "private")
|
elsif user == current
|
||||||
elsif (current == nil)
|
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")
|
||||||
Topic.find_all_by_permission("commons") | Topic.find_all_by_permission("public")
|
end
|
||||||
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)
|
||||||
# returns false if user not allowed to 'show' Topic, Synapse, or Map
|
Topic.find_all_by_permission("commons") | Topic.find_all_by_permission("public")
|
||||||
def authorize_to_show(user)
|
end
|
||||||
if (self.permission == "private" && self.user != user)
|
}
|
||||||
return false
|
|
||||||
end
|
# returns false if user not allowed to 'show' Topic, Synapse, or Map
|
||||||
return self
|
def authorize_to_show(user)
|
||||||
end
|
if (self.permission == "private" && self.user != user)
|
||||||
|
return false
|
||||||
# returns false if user not allowed to 'edit' Topic, Synapse, or Map
|
end
|
||||||
def authorize_to_edit(user)
|
return self
|
||||||
if (self.permission == "private" && self.user != user)
|
end
|
||||||
return false
|
|
||||||
elsif (self.permission == "public" && self.user != user)
|
# returns false if user not allowed to 'edit' Topic, Synapse, or Map
|
||||||
return false
|
def authorize_to_edit(user)
|
||||||
end
|
if (self.permission == "private" && self.user != user)
|
||||||
return self
|
return false
|
||||||
end
|
elsif (self.permission == "public" && self.user != user)
|
||||||
|
return false
|
||||||
# returns Boolean if user allowed to view Topic, Synapse, or Map
|
end
|
||||||
def authorize_to_view(user)
|
return self
|
||||||
if (self.permission == "private" && self.user != user)
|
end
|
||||||
return false
|
|
||||||
end
|
# returns Boolean if user allowed to view Topic, Synapse, or Map
|
||||||
return true
|
def authorize_to_view(user)
|
||||||
end
|
if (self.permission == "private" && self.user != user)
|
||||||
|
return false
|
||||||
# returns Boolean based on whether user has permissions to edit or not
|
end
|
||||||
def authorize_linkto_edit(user)
|
return true
|
||||||
if (self.user == user)
|
end
|
||||||
return true
|
|
||||||
elsif (self.permission == "commons")
|
# returns Boolean based on whether user has permissions to edit or not
|
||||||
return true
|
def authorize_linkto_edit(user)
|
||||||
end
|
if (self.user == user)
|
||||||
return false
|
return true
|
||||||
end
|
elsif (self.permission == "commons")
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue