huge refactor 75% done

This commit is contained in:
Connor Turland 2014-07-27 15:57:35 -04:00
parent eceb1174c3
commit b06f5cae35
28 changed files with 17715 additions and 612 deletions

View file

@ -1,5 +1,5 @@
source 'https://rubygems.org' source 'https://rubygems.org'
ruby '1.9.3' #ruby '1.9.3'
gem 'rails', '3.2.17' gem 'rails', '3.2.17'
@ -35,7 +35,7 @@ group :assets do
end end
group :production do #this is used on heroku group :production do #this is used on heroku
gem 'rmagick' #gem 'rmagick'
end end
gem 'jquery-rails', '2.1.2' gem 'jquery-rails', '2.1.2'

View file

@ -585,47 +585,4 @@ function touchPanZoomHandler(eventInfo, e) {
lastDist = dist; lastDist = dist;
} }
}
function updateSelectedPermissions(permission) {
if ($('.notice.metamaps').length == 0) {
$('body').prepend('<div class="notice metamaps" />');
}
$('.notice.metamaps').hide().html('Working...').fadeIn('fast');
// variables to keep track of how many nodes and synapses you had the ability to change the permission of
var nCount = 0,
sCount = 0;
// change the permission of the selected synapses, if logged in user is the original creator
var l = MetamapsModel.selectedEdges.length;
for (var i = l - 1; i >= 0; i -= 1) {
var edge = MetamapsModel.selectedEdges[i];
if (edge.getData('userid') == userid) {
updateSynapsePermission(edge, permission);
sCount++;
}
}
// change the permission of the selected topics, if logged in user is the original creator
var l = MetamapsModel.selectedNodes.length;
for (var i = l - 1; i >= 0; i -= 1) {
var node = MetamapsModel.selectedNodes[i];
if (node.getData('userid') == userid) {
updateTopicPermission(node, permission);
nCount++;
}
}
var nString = nCount == 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and ');
var sString = sCount == 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses');
$('.notice.metamaps').html(nString + sString + ' you created updated to ' + permission)
setTimeout(function () {
$('.notice.metamaps').fadeOut('fast');
}, 8000);
} }

View file

@ -7238,7 +7238,7 @@ Graph.Label.Native = new Class({
function splitLine(st,n) {var b = ''; var s = st;while (s.length > n) {var c = s.substring(0,n);var d = c.lastIndexOf(' ');var e =c.lastIndexOf('\n');if (e != -1) d = e; if (d == -1) d = n; b += c.substring(0,d) + '\n';s = s.substring(d+1);}return b+s;} function splitLine(st,n) {var b = ''; var s = st;while (s.length > n) {var c = s.substring(0,n);var d = c.lastIndexOf(' ');var e =c.lastIndexOf('\n');if (e != -1) d = e; if (d == -1) d = n; b += c.substring(0,d) + '\n';s = s.substring(d+1);}return b+s;}
var arrayOfLabelLines = splitLine(node.name,30).split('\n'); var arrayOfLabelLines = splitLine(node.name,30).split('\n');
//render background //render background
ctx.fillStyle = 'rgba(24,32,46, 1)'; ctx.fillStyle = 'rgba(24, 32, 46, 1)';
ctx.strokeStyle = node.getData('whiteCircle') ? '#FFF' : 'rgba(24,32,46, 1)'; ctx.strokeStyle = node.getData('whiteCircle') ? '#FFF' : 'rgba(24,32,46, 1)';
ctx.lineWidth = 2; ctx.lineWidth = 2;
var height = 25 * arrayOfLabelLines.length; //font size + margin var height = 25 * arrayOfLabelLines.length; //font size + margin

View file

@ -20,7 +20,17 @@
//= require jquery.roundabout.min //= require jquery.roundabout.min
//= require bip //= require bip
//= require jquery_ujs //= require jquery_ujs
//= require_tree . //= require hogan-2.0.0
//= require socket.io
//= require typeahead
//= require underscore
//= require backbone
//= require_directory ./carousel
// require_directory ./Jit
//= require_directory ./jquery
//= require_directory ./realtime
//= require_directory ./scroll
//= require_directory ./typing
// other options are 'graph' // other options are 'graph'
var viewMode = "list"; var viewMode = "list";
@ -165,70 +175,6 @@ function updateMetacode(node, metacode) {
}); });
} }
function updateTopicPermission(node, permission) {
var mdata = {
"topic": {
"permission": permission
}
};
$.ajax({
type: "PUT",
dataType: 'json',
url: "/topics/" + node.id,
data: mdata,
success: function (data) {
$('.showcard .mapPerm').removeClass('co pu pr minimize').addClass(permission.substring(0, 2));
$('.permissionSelect').remove();
node.setData("permission", permission);
},
error: function () {
alert('failed to update permission');
}
});
}
function updateSynapsePermission(edge, permission) {
var mdata = {
"synapse": {
"permission": permission
}
};
$.ajax({
type: "PUT",
dataType: 'json',
url: "/synapses/" + edge.data.$id,
data: mdata,
success: function (data) {
$('#edit_synapse .mapPerm').removeClass('co pu pr minimize').addClass(permission.substring(0, 2));
$('#edit_synapse .permissionSelect').remove();
edge.setData("permission", permission);
},
error: function () {
alert('failed to update permission');
}
});
}
function updateMapPermission(mapid, permission) {
var mdata = {
"map": {
"permission": permission
}
};
$.ajax({
type: "PUT",
dataType: 'json',
url: "/maps/" + mapid,
data: mdata,
success: function (data) {
$('.mapPermission').removeClass('commons public private minimize').addClass(permission);
$('.mapPermission .permissionSelect').remove();
},
error: function () {
alert('failed to update permission');
}
});
}
function updateMetacodeSet(set, index, custom) { function updateMetacodeSet(set, index, custom) {
@ -330,21 +276,6 @@ function MconsoleReset() {
Mconsole.canvas.scale((1 / mX), (1 / mY)); Mconsole.canvas.scale((1 / mX), (1 / mY));
} }
function openNodeShowcard(node) {
//populate the card that's about to show with the right topics data
populateShowCard(node);
$('.showcard').fadeIn('fast');
var s = $('.showcard').find('.scroll');
s.height(s.height()).mCustomScrollbar({
mouseWheelPixels: 200,
advanced: {
updateOnContentResize: true
}
});
MetamapsModel.showcardInUse = node.id;
}
function openLightbox(which) { function openLightbox(which) {
$('.lightboxContent').hide(); $('.lightboxContent').hide();
$('#' + which).show(); $('#' + which).show();

File diff suppressed because it is too large Load diff

View file

@ -198,7 +198,7 @@ jQuery.browser = browser;
{ {
$(options.titleBox).html( ($(event.target).attr('title') )); $(options.titleBox).html( ($(event.target).attr('title') ));
// METAMAPS CODE // METAMAPS CODE
$('#topic_metacode').val($(event.target).attr('title')); Metamaps.Create.newTopic.metacode = $(event.target).attr('title');
// NOT METAMAPS CODE // NOT METAMAPS CODE
var idx = $(event.target).data('itemIndex'); var idx = $(event.target).data('itemIndex');
var frontIndex = event.data.frontIndex; var frontIndex = event.data.frontIndex;
@ -236,7 +236,7 @@ jQuery.browser = browser;
{ {
if ( items[this.frontIndex] === undefined ) { return; } // Images might not have loaded yet. if ( items[this.frontIndex] === undefined ) { return; } // Images might not have loaded yet.
// METAMAPS CODE // METAMAPS CODE
$('#topic_metacode').val($(items[this.frontIndex].image).attr('title')); Metamaps.Create.newTopic.metacode = $(items[this.frontIndex].image).attr('title');
//$('img.cloudcarousel').css({"background":"none", "width":"","height":""}); //$('img.cloudcarousel').css({"background":"none", "width":"","height":""});
//$(items[this.frontIndex].image).css({"width":"45px","height":"45px"}); //$(items[this.frontIndex].image).css({"width":"45px","height":"45px"});
// NOT METAMAPS CODE // NOT METAMAPS CODE

View file

@ -57,7 +57,7 @@ $(document).ready(function () {
// hide the other two // hide the other two
$('.sidebarAccountBox').hide(); $('.sidebarAccountBox').hide();
$('.sidebarCollaborateBox').hide(); $('.sidebarCollaborateBox').hide();
$('.sidebarAccountIcon').css('background-color', '#0F1519'); //$('.sidebarAccountIcon').css('background-color', '#0F1519');
$('.sidebarCollaborateIcon').css('background-color', '#0F1519'); $('.sidebarCollaborateIcon').css('background-color', '#0F1519');
$('.sidebarFilterIcon').css('background-color', '#000'); $('.sidebarFilterIcon').css('background-color', '#000');

View file

@ -37,7 +37,7 @@ $(document).ready(function () {
$('.sidebarFilterBox').hide(); $('.sidebarFilterBox').hide();
$('.sidebarAccountBox').hide(); $('.sidebarAccountBox').hide();
$('.sidebarFilterIcon').css('background-color', '#0F1519'); $('.sidebarFilterIcon').css('background-color', '#0F1519');
$('.sidebarAccountIcon').css('background-color', '#0F1519'); //$('.sidebarAccountIcon').css('background-color', '#0F1519');
$('.sidebarCollaborateIcon').css('background-color', '#000'); $('.sidebarCollaborateIcon').css('background-color', '#000');
$('.sidebarCollaborateBox').fadeIn(200, function () { $('.sidebarCollaborateBox').fadeIn(200, function () {
@ -58,7 +58,7 @@ $(document).ready(function () {
var openSave = function () { var openSave = function () {
// hide the other three // hide the other three
$('.sidebarFilterBox, .sidebarAccountBox, .sidebarCollaborateBox').hide(); $('.sidebarFilterBox, .sidebarAccountBox, .sidebarCollaborateBox').hide();
$('.sidebarFilterIcon, .sidebarAccountIcon, .sidebarCollaborateIcon').css('background-color', '#0F1519'); $('.sidebarFilterIcon, .sidebarCollaborateIcon').css('background-color', '#0F1519');
} }
// bind the hover events // bind the hover events
$(".sidebarSave").hover(openSave, closeSave); $(".sidebarSave").hover(openSave, closeSave);

View file

@ -17,7 +17,7 @@ $(document).ready(function () {
var openFork = function () { var openFork = function () {
// hide the other three // hide the other three
$('.sidebarFilterBox, .sidebarAccountBox, .sidebarCollaborateBox').hide(); $('.sidebarFilterBox, .sidebarAccountBox, .sidebarCollaborateBox').hide();
$('.sidebarFilterIcon, .sidebarAccountIcon, .sidebarCollaborateIcon').css('background-color', '#0F1519'); $('.sidebarFilterIcon, .sidebarCollaborateIcon').css('background-color', '#0F1519');
} }
// bind the hover events // bind the hover events
$(".sidebarFork").hover(openFork, closeFork); $(".sidebarFork").hover(openFork, closeFork);
@ -25,137 +25,13 @@ $(document).ready(function () {
// bind hover events // bind hover events
bindForkHover(); bindForkHover();
//////
//////
//// TOPIC CREATION
// initialize the autocomplete results for the metacode spinner
$('#topic_name').typeahead([
{
name: 'topic_autocomplete',
limit: 8,
template: $('#topicAutocompleteTemplate').html(),
remote: {
url: '/topics/autocomplete_topic?term=%QUERY'
},
engine: Hogan
}
]);
var topicTypeahead = false;
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
$('#topic_name').bind('typeahead:selected', function (event, datum, dataset) {
$('#topic_grabTopic').val(datum.id);
event.preventDefault();
event.stopPropagation();
$('.new_topic').submit();
topicTypeahead = true;
});
$('#topic_name').bind('typeahead:opened', function () {
topicTypeahead = false;
});
// bind keyboard handlers
$('#topic_name').bind('keyup', function (e) {
switch (e.which) {
case 13:
if (!topicTypeahead) $('.new_topic').submit();
break;
default:
break;
}
});
// initialize metacode spinner and then hide it
$("#metacodeImg").CloudCarousel({
titleBox: $('#metacodeImgTitle'),
yRadius: 40,
xPos: 150,
yPos: 40,
speed: 0.3,
mouseWheel: true,
bringToFront: true
});
$('.new_topic').hide();
//////
//////
//// SYNAPSE CREATION
// initialize the autocomplete results for synapse creation
$('#synapse_desc').typeahead([
{
name: 'synapse_autocomplete',
template: "<div>{{label}}</div>",
remote: {
url: '/search/synapses?term=%QUERY'
},
engine: Hogan
},
{
name: 'existing_synapses',
limit: 50,
template: $('#synapseAutocompleteTemplate').html(),
remote: {
url: '/search/synapses',
replace: function () {
var q = '/search/synapses?topic1id=' + $('#synapse_topic1id').val() + '&topic2id=' + $('#synapse_topic2id').val();
return q;
}
},
engine: Hogan,
header: "<h3>Existing Synapses</h3>"
},
]);
var synapseTypeahead = false;
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
$('#synapse_desc').bind('typeahead:selected', function (event, datum, dataset) {
if (datum.id) { // if they clicked on an existing synapse get it
$('#synapse_grabSynapse').val(datum.id);
}
event.preventDefault();
event.stopPropagation();
$('.new_synapse').submit();
synapseTypeahead = true;
});
$('#synapse_desc').bind('typeahead:opened', function () {
synapseTypeahead = false;
});
// bind keyboard handlers
$('#synapse_desc').bind('keyup', function (e) {
switch (e.which) {
case 13:
if (!synapseTypeahead) $('.new_synapse').submit();
break;
default:
break;
}
});
//////
//////
//// TOPIC AND SYNAPSE CREATION
// when either form submits, don't leave the page
$('.new_topic, .new_synapse').bind('submit', function (event, data) {
event.preventDefault();
});
// disable right click events on the new topic and new synapse input fields
$('#new_topic, #new_synapse').bind('contextmenu', function (e) {
return false;
});
////// //////
////// //////
//// SWITCHING METACODE SETS //// SWITCHING METACODE SETS
$('#metacodeSwitchTabs').tabs({ $('#metacodeSwitchTabs').tabs({
selected: MetamapsModel.selectedMetacodeSetIndex selected: Metamaps.Settings.selectedMetacodeSetIndex
}).addClass("ui-tabs-vertical ui-helper-clearfix"); }).addClass("ui-tabs-vertical ui-helper-clearfix");
$("#metacodeSwitchTabs .ui-tabs-nav li").removeClass("ui-corner-top").addClass("ui-corner-left"); $("#metacodeSwitchTabs .ui-tabs-nav li").removeClass("ui-corner-top").addClass("ui-corner-left");
$('.customMetacodeList li').click(function () { $('.customMetacodeList li').click(function () {

View file

@ -362,7 +362,7 @@ $(document).ready(function () {
lT = setTimeout(function () { lT = setTimeout(function () {
if (!sliding1) { if (!sliding1) {
sliding1 = true; sliding1 = true;
$('.sidebarAccountIcon').css('background-color', '#0F1519'); //$('.sidebarAccountIcon').css('background-color', '#0F1519');
$('.sidebarAccountBox').fadeOut(200, function () { $('.sidebarAccountBox').fadeOut(200, function () {
sliding1 = false; sliding1 = false;
accountIsOpen = false; accountIsOpen = false;
@ -382,7 +382,7 @@ $(document).ready(function () {
$('.sidebarFilterIcon').css('background-color', '#0F1519'); $('.sidebarFilterIcon').css('background-color', '#0F1519');
$('.sidebarCollaborateIcon').css('background-color', '#0F1519'); $('.sidebarCollaborateIcon').css('background-color', '#0F1519');
$('.sidebarAccountIcon').css('background-color', '#000'); //$('.sidebarAccountIcon').css('background-color', '#000');
$('.sidebarAccountBox').fadeIn(200, function () { $('.sidebarAccountBox').fadeIn(200, function () {
sliding1 = false; sliding1 = false;
accountIsOpen = true; accountIsOpen = true;
@ -409,18 +409,4 @@ $(document).ready(function () {
return false; return false;
}); });
// bind keyboard handlers
$('body').bind('keyup', function (e) {
switch (e.which) {
case 13:
enterKeyHandler(e);
break;
case 27:
escKeyHandler();
break;
default:
break; //console.log(e.which);
}
});
}); // end document.ready }); // end document.ready

View file

@ -0,0 +1,14 @@
// This is a manifest file that'll be compiled into map.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require ./metamaps/metamapsJIT
//= require ./metamaps/metamaps

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -569,10 +569,15 @@ label[for="user_remember_me"] {
position: absolute; position: absolute;
width: 35px; width: 35px;
height: 35px; height: 35px;
background: #0F1519 url('MMCCicon_mapper.png') no-repeat center center; /*background: #0F1519 url('MMCCicon_mapper.png') no-repeat center center;*/
background-size: 24px 24px; background-size: 24px 24px;
cursor: pointer; cursor: pointer;
} }
.sidebarAccountIcon img {
border-radius: 17px;
}
.sidebarAccountBox { .sidebarAccountBox {
position: absolute; position: absolute;
display: none; display: none;

View file

@ -1,67 +1,45 @@
class MappingsController < ApplicationController class MappingsController < ApplicationController
respond_to :js, :html
before_filter :require_user, only: [:create, :update, :destroy]
respond_to :json
#skip_before_filter :verify_authenticity_token, :only => [:create]
# GET mappings # GET /mappings/1.json
def index def show
@mapping = Mapping.find(params[:id])
render json: @mapping
end end
# GET mappings/new # POST /mappings.json
def new
@mapping = Mapping.new
@user = current_user
respond_with(@mapping)
end
# POST mappings
def create def create
@user = current_user @mapping = Mapping.new(params[:mapping])
if @user
@mapping = Mapping.new()
@mapping.user = @user if @mapping.save
@mapping.xloc = params[:xloc] if params[:xloc] render json: @mapping, status: :created
@mapping.yloc = params[:yloc] if params[:yloc] else
render json: @mapping.errors, status: :unprocessable_entity
if params[:map]
if params[:map][:id]
@map = Map.find(params[:map][:id])
@map.touch(:updated_at)
@mapping.map = @map
end
end
if params[:topic]
if params[:topic][:id]
@topic = Topic.find(params[:topic][:id])
@mapping.topic = @topic
@mapping.category = "Topic"
end
elsif params[:synapse]
if params[:synapse][:id]
@topic = Synapse.find(params[:synapse][:id])
@mapping.synapse = @synapse
@mapping.category = "Synapse"
end
end
@mapping.save()
#push add to map to realtime viewers of the map
@mapping.message 'create',@user.id
end end
end end
# GET /mappings/:id # PUT /mappings/1.json
def show
end
# GET /mappings/:id/edit
def edit
end
# PUT /mappings/:id
def update def update
@mapping = Mapping.find(params[:id])
if @mapping.update_attributes(params[:mapping])
head :no_content
else
render json: @mapping.errors, status: :unprocessable_entity
end
end end
# DELETE /mappings/:id # DELETE /mappings/1.json
def destroy def destroy
@mapping = Mapping.find(params[:id])
@mapping.destroy
head :no_content
end end
end end

View file

@ -69,12 +69,18 @@ class MapsController < ApplicationController
if not @map if not @map
redirect_to root_url and return redirect_to root_url and return
end end
@mapjson = @map.self_as_json(@current).html_safe @mapjson = @map.self_as_json(@current).html_safe
@alltopics = @map.topics # should limit to topics visible to user
@allsynapses = @map.synapses # should also be limited
@allmappings = @map.mappings
@allmetacodes = Metacode.all
respond_to do |format| respond_to do |format|
format.html { respond_with(@map, @user) } format.html { respond_with(@allmetacodes, @allmappings, @allsynapses, @alltopics, @map, @user) }
format.json { respond_with(@mapjson) } #format.json { respond_with(@mapjson) }
format.json { render json: @topics }
end end
end end

View file

@ -1,14 +1,21 @@
class MetacodesController < ApplicationController class MetacodesController < ApplicationController
before_filter :require_admin before_filter :require_admin, except: [:index]
# GET /metacodes # GET /metacodes
# GET /metacodes.json # GET /metacodes.json
def index def index
@metacodes = Metacode.order("name").all @metacodes = Metacode.order("name").all
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html {
unless authenticated? && user.admin
redirect_to root_url, notice: "You need to be an admin for that."
return false
end
render action: "index"
}
format.json { render json: @metacodes } format.json { render json: @metacodes }
end end
end end

View file

@ -1,9 +1,9 @@
class SynapsesController < ApplicationController class SynapsesController < ApplicationController
include TopicsHelper include TopicsHelper
before_filter :require_user, only: [:create, :update, :removefrommap, :destroy] before_filter :require_user, only: [:create, :update, :destroy]
respond_to :html, :js, :json respond_to :js, :json
# GET synapses/:id/json # GET synapses/:id/json
def json def json
@ -19,108 +19,31 @@ class SynapsesController < ApplicationController
end end
end end
# POST synapses # POST /synapses
# POST /synapses.json
def create def create
@user = current_user @synapse = Synapse.new(params[:synapse])
# if the topic exists grab it and return it
if params[:synapse][:grabSynapse] != "null"
@synapse = Synapse.find(params[:synapse][:grabSynapse])
# if not selecting an existing synapse, create it
else
@synapse = Synapse.new()
@synapse.desc = params[:synapse][:desc]
@synapse.topic1 = Topic.find(params[:synapse][:topic1id])
@synapse.topic2 = Topic.find(params[:synapse][:topic2id])
@synapse.permission = "commons"
@synapse.category = "from-to"
@synapse.weight = 5
@synapse.user = @user
@synapse.save
end
if params[:synapse][:map]
@map = Map.find(params[:synapse][:map])
@map.touch(:updated_at)
@mapping = Mapping.new()
@mapping.category = "Synapse"
@mapping.user = @user
@mapping.map = @map
@mapping.synapse = @synapse
@mapping.save
#push add to map to realtime viewers of the map
@mapping.message 'create',@user.id
# set the permission of the synapse to whatever the permission of the
#map is
@synapse.permission = @map.permission
@synapse.save
end
respond_to do |format| respond_to do |format|
format.html { respond_with(@user, location: synapse_url(@synapse)) } if @synapse.save
format.js { respond_with(@synapse) } format.json { render json: @synapse, status: :created }
else
format.json { render json: @synapse.errors, status: :unprocessable_entity }
end
end end
end end
# PUT synapses/:id # PUT /synapses/1
# PUT /synapses/1.json
def update def update
@current = current_user @synapse = Synapse.find(params[:id])
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
if @synapse
@permissionBefore = @synapse.permission
if params[:synapse]
@synapse.desc = params[:synapse][:desc] if params[:synapse][:desc]
@synapse.category = params[:synapse][:category] if params[:synapse][:category]
@synapse.permission = params[:synapse][:permission] if params[:synapse][:permission]
end
if params[:node1_id] and params[:node1_id][:node1]
@synapse.topic1 = Topic.find(params[:node1_id][:node1])
end
if params[:node2_id] and params[:node2_id][:node2]
@synapse.topic2 = Topic.find(params[:node2_id][:node2])
end
@synapse.save
@permissionAfter = @synapse.permission
#push notify to anyone viewing this synapse on a map in realtime (see mapping.rb to understand the 'message' action)
# if the topic was private and is being switched to PU or CO it is the same as being created for other viewers
if @permissionBefore == "private" and @permissionAfter != "private"
@synapse.message 'create',@current.id
elsif @permissionBefore != "private" and @permissionAfter == "private"
@synapse.message 'destroy',@current.id
else
@synapse.message 'update',@current.id
end
end
respond_to do |format|
format.js
format.json { respond_with(@synapse) }
end
end
# POST synapses/:map_id/:synapse_id/removefrommap
def removefrommap
@user = current_user
@mapping = Mapping.find_by_synapse_id_and_map_id(params[:synapse_id],params[:map_id])
Map.find(params[:map_id]).touch(:updated_at)
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
@mapping.message 'destroy',@user.id
@mapping.delete
respond_to do |format| respond_to do |format|
format.js if @synapse.update_attributes(params[:synapse])
format.json { head :no_content }
else
format.json { render json: @synapse.errors, status: :unprocessable_entity }
end
end end
end end
@ -140,5 +63,9 @@ class SynapsesController < ApplicationController
end end
@synapse.delete if @synapse @synapse.delete if @synapse
respond_to do |format|
format.js { render :json => "success" }
end
end end
end end

View file

@ -1,7 +1,7 @@
class TopicsController < ApplicationController class TopicsController < ApplicationController
include TopicsHelper include TopicsHelper
before_filter :require_user, only: [:create, :update, :removefrommap, :destroy] before_filter :require_user, only: [:create, :update, :destroy]
respond_to :html, :js, :json respond_to :html, :js, :json
@ -34,7 +34,8 @@ class TopicsController < ApplicationController
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) }
format.json { render :json => @topic }
end end
end end
@ -48,140 +49,36 @@ class TopicsController < ApplicationController
end end
respond_to do |format| respond_to do |format|
format.json { render :json => @topic.self_as_json } #format.json { render :json => @topic.self_as_json }
format.json { render :json => @topic.to_json }
end end
end end
# POST topics # POST /topics
# POST /topics.json
def create def create
@topic = Topic.new(params[:topic])
@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
#if being created on a map, set topic by default to whatever permissions the map is
if params[:topic][:map]
@map = Map.find(params[:topic][:map])
@topic.permission = @map.permission
end
@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 = nil
if params[:topic][:map]
@map = Map.find(params[:topic][:map])
@map.touch(:updated_at)
@mapping = Mapping.new()
@mapping.category = "Topic"
@mapping.user = @user
@mapping.map = @map
@mapping.topic = @topic
@mapping.xloc = params[:topic][:x]
@mapping.yloc = params[:topic][:y]
@mapping.save
#push add to map to realtime viewers of the map
@mapping.message 'create',@user.id
end
respond_to do |format| respond_to do |format|
format.html { respond_with(@user, location: topic_url(@topic)) } if @topic.save
format.js { respond_with(@topic, @mapping, @synapse, @position) } format.json { render json: @topic, status: :created }
end
end
# PUT topics/:id
def update
@current = current_user
@topic = Topic.find(params[:id]).authorize_to_edit(@current)
if @topic
if params[:topic]
@permissionBefore = @topic.permission
@topic.name = params[:topic][:name] if params[:topic][:name]
@topic.desc = params[:topic][:desc] if params[:topic][:desc]
@topic.link = params[:topic][:link] if params[:topic][:link]
@topic.permission = params[:topic][:permission] if params[:topic][:permission]
@topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) if params[:topic][:metacode]
@permissionAfter = @topic.permission
end
@topic.save
#push notify to anyone viewing this topic on a map in realtime (see mapping.rb to understand the 'message' action)
# if the topic was private and is being switched to PU or CO it is the same as being created for other viewers
if @permissionBefore == "private" and @permissionAfter != "private"
@topic.message 'create',@current.id
elsif @permissionBefore != "private" and @permissionAfter == "private"
@topic.message 'destroy',@current.id
else
@topic.message 'update',@current.id
end
end
respond_to do |format|
format.js { render :json => @topic.self_as_json }
format.json { render :json => @topic.self_as_json }
end
end
# POST topics/:map_id/:topic_id/removefrommap
def removefrommap
@current = current_user
@mapping = Mapping.find_by_topic_id_and_map_id(params[:topic_id],params[:map_id])
@map = Map.find(params[:map_id])
@map.touch(:updated_at)
@topic = Topic.find(params[:topic_id])
@mappings = @map.mappings.select{|m|
if m.synapse != nil
m.synapse.topic1 == @topic || m.synapse.topic2 == @topic
else else
false format.json { render json: @topic.errors, status: :unprocessable_entity }
end end
}
@mappings.each do |m|
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
m.message 'destroy',@current.id
m.delete
end end
end
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action) # PUT /topics/1
#@mapping.message 'destroy',@current.id # PUT /topics/1.json
def update
@mapping.delete @topic = Topic.find(params[:id])
respond_to do |format| respond_to do |format|
format.js if @topic.update_attributes(params[:topic])
format.json { head :no_content }
else
format.json { render json: @topic.errors, status: :unprocessable_entity }
end
end end
end end
@ -223,8 +120,8 @@ class TopicsController < ApplicationController
@topic.delete @topic.delete
end end
respond_to do |format| respond_to do |format|
format.js format.js { render :json => "success" }
end end
end end
end end

View file

@ -1,9 +1,16 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_filter :require_user, only: [:edit, :update] before_filter :require_user, only: [:edit, :update, :updatemetacodes]
respond_to :html, :json respond_to :html, :json
# GET /users/1.json
def show
@user = User.find(params[:id])
render json: @user
end
# GET /user/edit # GET /user/edit
def edit def edit
@user = current_user @user = current_user

View file

@ -38,8 +38,8 @@ end
#build a json object of a map #build a json object of a map
def self_as_json(current) def self_as_json(current)
Jbuilder.encode do |json| Jbuilder.encode do |json|
@topics = self.topics @topics = self.topics.dup
@synapses = self.synapses @synapses = self.synapses.dup
json.array!(@topics.delete_if{|topic| not topic.authorize_to_view(current)}) do |topic| json.array!(@topics.delete_if{|topic| not topic.authorize_to_view(current)}) do |topic|
@ -57,7 +57,9 @@ end
@synapsedata['$userid'] = synapse.user.id @synapsedata['$userid'] = synapse.user.id
@synapsedata['$username'] = synapse.user.name @synapsedata['$username'] = synapse.user.name
@synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()] @synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
@synapsedata['$permission'] = synapse.permission @synapsedata['$permission'] = synapse.permission
@mapping = Mapping.find_by_synapse_id_and_map_id(synapse.id,self.id)
@synapsedata['$mappingid'] = @mapping.id
json.data @synapsedata json.data @synapsedata
end end
@ -73,19 +75,20 @@ end
@topicdata['$desc'] = topic.desc @topicdata['$desc'] = topic.desc
@topicdata['$link'] = topic.link @topicdata['$link'] = topic.link
@topicdata['$metacode'] = topic.metacode.name @topicdata['$metacode'] = topic.metacode.name
@topicdata['$inmaps'] = @inmaps @topicdata['$inmaps'] = @inmaps
@topicdata['$inmapsString'] = @mapsString @topicdata['$inmapsString'] = @mapsString
@topicdata['$synapseCount'] = topic.synapses.count @topicdata['$synapseCount'] = topic.synapses.count
@topicdata['$userid'] = topic.user.id @topicdata['$userid'] = topic.user.id
@topicdata['$username'] = topic.user.name @topicdata['$username'] = topic.user.name
@mapping = Mapping.find_by_topic_id_and_map_id(topic.id,self.id) @mapping = Mapping.find_by_topic_id_and_map_id(topic.id,self.id)
@topicdata['$xloc'] = @mapping.xloc @topicdata['$xloc'] = @mapping.xloc
@topicdata['$yloc'] = @mapping.yloc @topicdata['$yloc'] = @mapping.yloc
@topicdata['$mappingid'] = @mapping.id @topicdata['$mappingid'] = @mapping.id
@topicdata['$permission'] = topic.permission @topicdata['$permission'] = topic.permission
@topicdata['$date'] = topic.created_at.strftime("%m/%d/%Y") @topicdata['$date'] = topic.created_at.strftime("%m/%d/%Y")
@topicdata['$id'] = topic.id
json.data @topicdata json.data @topicdata
json.id topic.id json.id @mapping.id
json.name topic.name json.name topic.name
end end
end end

View file

@ -14,4 +14,4 @@ class Metacode < ActiveRecord::Base
return false return false
end end
end end

View file

@ -64,6 +64,6 @@
<div class="clearfloat"></div> <div class="clearfloat"></div>
<script> <script>
MetamapsModel.selectedMetacodeSet = "metacodeset-<%= selectedSet %>"; Metamaps.Settings.selectedMetacodeSet = "metacodeset-<%= selectedSet %>";
MetamapsModel.selectedMetacodeSetIndex = <%= index %>; Metamaps.Settings.selectedMetacodeSetIndex = <%= index %>;
</script> </script>

View file

@ -29,11 +29,15 @@
</script> </script>
<%= stylesheet_link_tag "application", :media => "all" %> <%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %> <%= javascript_include_tag "application" %>
<% if controller_name == "maps" && action_name == "show" %>
<%= javascript_include_tag "map" %>
<% end %>
<script type="text/javascript" src="//use.typekit.net/tki2nyo.js"></script> <script type="text/javascript" src="//use.typekit.net/tki2nyo.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script> <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<script type="text/javascript" src="//use.typekit.net/obp7wss.js"></script> <script type="text/javascript" src="//use.typekit.net/obp7wss.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script> <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, user-scalable=no">
</head> </head>
<body class="<%= (action_name == "show") ? "mapBody" : "" %>" > <body class="<%= (action_name == "show") ? "mapBody" : "" %>" >
@ -54,7 +58,9 @@
<%= render :partial => 'layouts/templates' %> <%= render :partial => 'layouts/templates' %>
</div> </div>
<div class="sidebarAccount"> <div class="sidebarAccount">
<div class="sidebarAccountIcon"></div> <div class="sidebarAccountIcon">
<% if user && user.image %><%= image_tag user.image.url(:thumb), :size => "35x35" %><% end %>
</div>
<div class="sidebarAccountBox <%= authenticated? ? 'loggedin' : 'loggedout' %>"> <div class="sidebarAccountBox <%= authenticated? ? 'loggedin' : 'loggedout' %>">
<%= render :partial => 'layouts/account' %> <%= render :partial => 'layouts/account' %>
</div> </div>

View file

@ -92,42 +92,9 @@
<script> <script>
var dragged = 0; Metamaps.Active.Map = <%= @map.to_json.html_safe %>;
mapid = <%= @map.id %>; Metamaps.Metacodes = <%= @allmetacodes.to_json.html_safe %>;
<% if (@map.permission == "commons" && authenticated? ) || @map.user == user %> Metamaps.Topics = <%= @alltopics.to_json.html_safe %>;
mapperm = true; Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>;
<% end %> Metamaps.Mappings = <%= @allmappings.to_json.html_safe %>;
viewMode = "graph";
json = <%= @mapjson %>;
if (json.length > 0) {
$(window).load(function () {
<% if (@map.arranged) %>
initialize("arranged");
<% else %>
initialize("chaotic");
<% end %>
});
} else {
$(window).load(function () {
initialize("chaotic", true);
});
}
<% if authenticated? && (@map.permission == "commons" || @map.user == user) %>
// this is for the heroku staging environment
window.realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com');
// this is for metamaps.cc
//window.realtime.socket = io.connect('http://metamaps.cc:5001');
// this is for localhost development
//window.realtime.socket = io.connect('http://localhost:5001');
window.realtime.socket.on('connect', function () {
console.log('socket connected');
window.realtime.setupSocket();
});
<% end %>
</script> </script>

View file

@ -70,7 +70,7 @@ ISSAD::Application.configure do
# config.action_controller.asset_host = "http://assets.example.com" # config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js ) config.assets.precompile += %w( metamaps.js )
# Disable delivery errors, bad email addresses will be ignored # Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false # config.action_mailer.raise_delivery_errors = false

View file

@ -44,7 +44,7 @@ ISSAD::Application.routes.draw do
end end
match 'user/updatemetacodes', to: 'users#updatemetacodes', via: :post, as: :updatemetacodes match 'user/updatemetacodes', to: 'users#updatemetacodes', via: :post, as: :updatemetacodes
resources :users, except: [:show, :index] resources :users, except: [:index]
resources :mappings resources :mappings