code cleaning

This commit is contained in:
Connor Turland 2014-05-30 11:00:31 -04:00
parent f121661858
commit 1970f794c4
11 changed files with 864 additions and 727 deletions

View file

@ -14,7 +14,7 @@ gem 'formtastic'
gem 'json'
gem 'rails3-jquery-autocomplete'
gem 'best_in_place'
gem 'therubyracer' #optional
#gem 'therubyracer' #optional
#gem 'rb-readline'
# Gems used only for assets and not required

View file

@ -64,7 +64,6 @@ GEM
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.8.1)
libv8 (3.16.14.3)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
@ -112,9 +111,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1)
thread_safe (0.3.3)
tilt (1.4.1)
@ -147,5 +143,4 @@ DEPENDENCIES
rails3-jquery-autocomplete
redis
sass-rails
therubyracer
uglifier (>= 1.0.3)

47
Gemfile~ Normal file
View file

@ -0,0 +1,47 @@
source 'https://rubygems.org'
gem 'rails', '3.2.17'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'devise'
gem 'redis'
gem 'pg'
gem 'cancan'
gem 'formula'
gem 'formtastic'
gem 'json'
gem 'rails3-jquery-autocomplete'
gem 'best_in_place'
gem 'therubyracer' #optional
#gem 'rb-readline'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails', '2.1.2'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
gem 'jbuilder', '0.8.2'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

View file

@ -144,16 +144,7 @@ function graphSettings(type, embed) {
//Number of iterations for the FD algorithm
iterations: 200,
//Edge length
levelDistance: 200,
// Add text to the labels. This method is only triggered
// on label creation and only for DOM labels (not native canvas ones).
//onCreateLabel: function (domElement, node) {
// onCreateLabelHandler(type, domElement, node);
//},
// Change node styles when DOM labels are placed or moved.
//onPlaceLabel: function (domElement, node) {
// onPlaceLabelHandler(domElement, node);
//}
levelDistance: 200
};
if (embed) {
@ -177,24 +168,6 @@ function graphSettings(type, embed) {
//different because we're centred
onDragCancelHandler(node, eventInfo, e, true);
};
/*t.Events.onClick = function(node, eventInfo, e) {
//this is handled mostly differently than in arranged/chaotic
if (e.target.id != "infovis-canvas") return false;
//hide synapse and topic editing dialog
hideCards();
//clicking on an edge, a node, or clicking on blank part of canvas?
if (node.nodeFrom) {
selectEdgeOnClickHandler(node, e);
} else if (node && !node.nodeFrom) {
//node is actually a node :)
selectNodeOnClickHandler(node, e);
} else {
canvasDoubleClickHandler(eventInfo.getPos(), e);
}
};*/
}//if
return t;
@ -258,18 +231,9 @@ var nodeSettings = {
var pos = node.pos.getc(true),
dim = node.getData('dim'),
cat = node.getData('metacode'),
greenCircle = node.getData('greenCircle'),
whiteCircle = node.getData('whiteCircle'),
ctx = canvas.getCtx();
// if the topic is from the Commons draw a green circle around it
if (greenCircle) {
ctx.beginPath();
ctx.arc(pos.x, pos.y, dim+3, 0, 2 * Math.PI, false);
ctx.strokeStyle = '#67be5f'; // green
ctx.lineWidth = 2;
ctx.stroke();
}
// if the topic is on the Canvas draw a white circle around it
if (whiteCircle) {
ctx.beginPath();
@ -591,31 +555,6 @@ function onDragCancelHandler(node, eventInfo, e, centred) {
Mconsole.plot();
}
function onPlaceLabelHandler(domElement, node) {
var style = domElement.style;
var left = parseInt(style.left);
var top = parseInt(style.top);
var w = $('#topic_' + node.id + '_label').width();
style.left = (left - w / 2) + 'px';
style.top = (top+20) + 'px';
style.display = '';
// now position the showcard
if (MetamapsModel.showcardInUse != null) {
top = $('#' + MetamapsModel.showcardInUse).css('top');
left = parseInt($('#' + MetamapsModel.showcardInUse).css('left'));
if (0 != $('#topic_' + MetamapsModel.showcardInUse + '_label').width()) {
MetamapsModel.widthOfLabel = $('#topic_' + MetamapsModel.showcardInUse + '_label').width();
}
w = MetamapsModel.widthOfLabel/2;
left = (left + w) + 'px';
$('#showcard').css('top', top);
$('#showcard').css('left', left);
Mconsole.labels.hideLabel(Mconsole.graph.getNode(MetamapsModel.showcardInUse));
}
}
// thanks to http://stackoverflow.com/questions/4338963/
// convert-html-character-entities-back-to-regular-text-using-javascript
function decodeEntities(desc) {
@ -625,4 +564,3 @@ function decodeEntities(desc) {
temp = null; //delete the element;
return str;
}//decodeEntities

View file

@ -25,7 +25,15 @@
// other options are 'graph'
var viewMode = "list";
var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null, gType, tempNode = null, tempInit = false, tempNode2 = null, metacodeIMGinit = false, goRealtime = false, mapid = null, mapperm = false, touchPos, touchDragNode, mouseIsDown = false;
var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
gType, tempNode = null,
tempInit = false,
tempNode2 = null,
metacodeIMGinit = false,
goRealtime = false,
mapid = null,
mapperm = false,
touchPos, touchDragNode, mouseIsDown = false;
$(document).ready(function () {
@ -107,7 +115,10 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
$('.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField').animate({
width: '200px'
}, 200, function () {
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({padding:'5px 10px', width:'180px'});
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({
padding: '5px 10px',
width: '180px'
});
$('.sidebarSearchField').focus();
sliding1 = false
searchIsOpen = true;
@ -118,7 +129,10 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
lT = setTimeout(function () {
if (!sliding1 && searchIsOpen && $('.sidebarSearchField').val() == '') {
sliding1 = true;
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({padding:'5px 0', width:'200px'});
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({
padding: '5px 0',
width: '200px'
});
$('.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField').animate({
width: '0'
}, 200, function () {
@ -131,7 +145,11 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
}
// bind the hover events
$(".sidebarSearch").hover(function(){ openSearch() }, function() { closeSearch(800) });
$(".sidebarSearch").hover(function () {
openSearch()
}, function () {
closeSearch(800)
});
$('.sidebarSearchIcon').click(function (e) {
$('.sidebarSearchField').focus();
@ -151,7 +169,8 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
openSearch();
}
break;
default: break; //console.log(e.which);
default:
break; //console.log(e.which);
}
});
@ -179,7 +198,7 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
dataset.push({
value: "No results",
label: "No results",
typeImageURL: "/assets/wildcard.png",
typeImageURL: "/assets/icons/wildcard.png",
rtype: "noresult"
});
}
@ -248,11 +267,9 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
var win;
if (dataset == "topics") {
win = window.open('/topics/' + datum.id, '_blank');
}
else if (dataset == "maps") {
} else if (dataset == "maps") {
win = window.open('/maps/' + datum.id, '_blank');
}
else if (dataset == "mappers") {
} else if (dataset == "mappers") {
win = window.open('/maps/mappers/' + datum.id, '_blank');
}
win.focus();
@ -261,7 +278,8 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
});
var checkboxChangeInit = false, minimizeInit = false;
var checkboxChangeInit = false,
minimizeInit = false;
$('.sidebarSearchField').bind('keyup', function () {
@ -271,7 +289,9 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
// set the value of the search equal to itself to retrigger the autocomplete event
searchIsOpen = false;
$('.sidebarSearchField').typeahead('setQuery', $('.sidebarSearchField').val());
setTimeout(function() { searchIsOpen = true; }, 2000);
setTimeout(function () {
searchIsOpen = true;
}, 2000);
});
checkboxChangeInit = true;
}
@ -282,10 +302,16 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
var s = $('.tt-dataset-mappers .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
$('.tt-dataset-mappers .tt-suggestions').css({'height':'auto','overflow':'visible'});
$('.tt-dataset-mappers .tt-suggestions').css({
'height': 'auto',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
$('.tt-dataset-mappers .tt-suggestions').css({'height':'0','overflow':'hidden'});
$('.tt-dataset-mappers .tt-suggestions').css({
'height': '0',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
@ -293,10 +319,18 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
var s = $('.tt-dataset-topics .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
s.css({'height':'auto','border-top':'none','overflow':'visible'});
s.css({
'height': 'auto',
'border-top': 'none',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
s.css({'height':'0','border-top':'1px solid rgb(56, 56, 56)','overflow':'hidden'});
s.css({
'height': '0',
'border-top': '1px solid rgb(56, 56, 56)',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
@ -304,10 +338,18 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
var s = $('.tt-dataset-maps .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
s.css({'height':'auto','border-top':'none','overflow':'visible'});
s.css({
'height': 'auto',
'border-top': 'none',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
s.css({'height':'0','border-top':'1px solid rgb(56, 56, 56)','overflow':'hidden'});
s.css({
'height': '0',
'border-top': '1px solid rgb(56, 56, 56)',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
@ -399,7 +441,8 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
case 13:
$('.new_topic').submit();
break;
default: break;
default:
break;
}
});
@ -442,7 +485,8 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
case 13:
$('.new_synapse').submit();
break;
default: break;
default:
break;
}
});
@ -455,7 +499,11 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
//$(".scroll").mCustomScrollbar();
// initialize scroll bar for filter by metacode, then hide it and position it correctly again
$("#filter_by_metacode").mCustomScrollbar({advanced: { updateOnContentResize: true }});
$("#filter_by_metacode").mCustomScrollbar({
advanced: {
updateOnContentResize: true
}
});
$('.sidebarFilterBox').hide().css({
position: 'absolute',
top: '35px',
@ -510,9 +558,14 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
// 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);
case 13:
enterKeyHandler(e);
break;
case 27:
escKeyHandler();
break;
default:
break; //console.log(e.which);
}
});
@ -569,7 +622,7 @@ function addHoverForSettings() {
else if (permission == "public") el.html("pu");
else if (permission == "private") el.html("pr");
});
}
} // end addHoverForSettings
// this is to save the layout of a map
function saveLayoutAll() {
@ -597,7 +650,8 @@ function saveLayout(id) {
// this is to save your console to a map
function saveToMap() {
var nodes_data = "", synapses_data = "";
var nodes_data = "",
synapses_data = "";
var synapses_array = new Array();
Mconsole.graph.eachNode(function (n) {
//don't add to the map if it was filtered out
@ -654,8 +708,7 @@ function fetchRelatives(node) {
});
});
Mconsole.busy = false;
}
else {
} else {
Mconsole.op.sum(data, {
type: 'nothing',
});
@ -679,7 +732,11 @@ function fetchRelatives(node) {
// @param node = JIT node object
// @param metacode = STRING like "Idea", "Action", etc.
function updateMetacode(node, metacode) {
var mdata = { "topic": { "metacode": metacode } };
var mdata = {
"topic": {
"metacode": metacode
}
};
$.ajax({
type: "PUT",
dataType: 'json',
@ -692,7 +749,10 @@ function updateMetacode(node, metacode) {
Mconsole.plot();
$('.metacodeTitle').removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.metacodeSelect').hide();
setTimeout(function() { $('.metacodeTitle').hide(); $('.showcard .icon').css('z-index','1'); }, 500);
setTimeout(function () {
$('.metacodeTitle').hide();
$('.showcard .icon').css('z-index', '1');
}, 500);
},
error: function () {
alert('failed to update metacode');
@ -701,7 +761,11 @@ function updateMetacode(node, metacode) {
}
function updateTopicPermission(node, permission) {
var mdata = { "topic": { "permission": permission } };
var mdata = {
"topic": {
"permission": permission
}
};
$.ajax({
type: "PUT",
dataType: 'json',
@ -719,7 +783,11 @@ function updateTopicPermission(node, permission) {
}
function updateSynapsePermission(edge, permission) {
var mdata = { "synapse": { "permission": permission } };
var mdata = {
"synapse": {
"permission": permission
}
};
$.ajax({
type: "PUT",
dataType: 'json',
@ -737,7 +805,11 @@ function updateSynapsePermission(edge, permission) {
}
function updateMapPermission(mapid, permission) {
var mdata = { "map": { "permission": permission } };
var mdata = {
"map": {
"permission": permission
}
};
$.ajax({
type: "PUT",
dataType: 'json',

View file

@ -0,0 +1,75 @@
window.realtime = {};
window.realtime.addTopicToMap = function(topic) {
var newPos, tempForT;
Mconsole.graph.addNode(topic);
tempForT = Mconsole.graph.getNode(topic.id);
tempForT.setData('dim', 1, 'start');
tempForT.setData('dim', 25, 'end');
newPos = new $jit.Complex();
newPos.x = tempForT.data.$xloc;
newPos.y = tempForT.data.$yloc;
tempForT.setPos(newPos, 'start');
tempForT.setPos(newPos, 'current');
tempForT.setPos(newPos, 'end');
Mconsole.fx.plotNode(tempForT, Mconsole.canvas);
return Mconsole.labels.plotLabel(Mconsole.canvas, tempForT, Mconsole.config);
};
window.realtime.updateTopicOnMap = function(topic) {
var newPos, tempForT;
tempForT = Mconsole.graph.getNode(topic.id);
tempForT.data = topic.data;
tempForT.name = topic.name;
if (MetamapsModel.showcardInUse === topic.id) {
populateShowCard(tempForT);
}
newPos = new $jit.Complex();
newPos.x = tempForT.data.$xloc;
newPos.y = tempForT.data.$yloc;
tempForT.setPos(newPos, 'start');
tempForT.setPos(newPos, 'current');
tempForT.setPos(newPos, 'end');
return Mconsole.fx.animate({
modes: ['linear', 'node-property:dim', 'edge-property:lineWidth'],
transition: $jit.Trans.Quad.easeInOut,
duration: 500
});
};
window.realtime.addSynapseToMap = function(synapse) {
var Node1, Node2, tempForS;
Node1 = Mconsole.graph.getNode(synapse.data.$direction[0]);
Node2 = Mconsole.graph.getNode(synapse.data.$direction[1]);
Mconsole.graph.addAdjacence(Node1, Node2, {});
tempForS = Mconsole.graph.getAdjacence(Node1.id, Node2.id);
tempForS.setDataset('start', {
lineWidth: 0.4
});
tempForS.setDataset('end', {
lineWidth: 2
});
tempForS.data = synapse.data;
Mconsole.fx.plotLine(tempForS, Mconsole.canvas);
return Mconsole.fx.animate({
modes: ['linear', 'node-property:dim', 'edge-property:lineWidth'],
transition: $jit.Trans.Quad.easeInOut,
duration: 500
});
};
window.realtime.updateSynapseOnMap = function(synapse) {
var k, tempForS, v, wasShowDesc, _ref;
tempForS = Mconsole.graph.getAdjacence(synapse.data.$direction[0], synapse.data.$direction[1]);
wasShowDesc = tempForS.data.$showDesc;
_ref = synapse.data;
for (k in _ref) {
v = _ref[k];
tempForS.data[k] = v;
}
tempForS.data.$showDesc = wasShowDesc;
if (MetamapsModel.edgecardInUse === synapse.data.$id) {
editEdge(tempForS, false);
}
return Mconsole.plot();
};

View file

@ -10,7 +10,7 @@ module TopicsHelper
topic['value'] = t.name
topic['description'] = t.desc.truncate(35) # make this return matched results
topic['type'] = t.metacode.name
topic['typeImageURL'] = '/assets/' + t.metacode.icon
topic['typeImageURL'] = t.metacode.icon
topic['permission'] = t.permission
topic['mapCount'] = t.maps.count
topic['synapseCount'] = t.synapses.count

View file

@ -77,7 +77,7 @@
$(document).ready(function() {
function bindFilterHover() {
var filterIsOpen = false
var filterIsOpen = false;
// controls the sliding hover of the bottom left menu
var sliding1 = false;
@ -121,7 +121,7 @@
function bindInfoHover() {
var infoIsOpen = false
var infoIsOpen = false;
// controls the sliding hover of the bottom left menu
var sliding1 = false;
@ -254,9 +254,9 @@
initialize("chaotic", true);
});
}
window.realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com'); // this is for the heroku staging environment
//window.realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com'); // this is for the heroku staging environment
//window.realtime.socket = io.connect('http://metamaps.cc:5001'); // this is for metamaps.cc
//window.realtime.socket = io.connect('http://localhost:5001'); // this is for localhost development
window.realtime.socket = io.connect('http://localhost:5001'); // this is for localhost development
window.realtime.socket.on('connect', function() {
subscribeToRooms();

View file

@ -5,8 +5,8 @@
#%>
<% content_for :title, @user.name + "'s Settings | Metamaps" %>
<%= formula_form_for @user, url: user_url do |form| %>
<h1 class="index">Your Settings</h1>
<%= formula_form_for @user, url: user_url do |form| %>
<h3>Edit Account</h3>
<%= form.input :name, label: "Name", class: "name" %>
<%= form.input :email, label: "Email", class: "email" %>

View file

@ -0,0 +1,10 @@
development:
min_messages: WARNING
adapter: postgresql
host: 127.0.0.1
port: 5432
encoding: unicode
database: metamap002_development
pool: 5
username: postgres
password: "3112"

View file

@ -10,8 +10,8 @@ Devise.setup do |config|
# config.mailer = "Devise::Mailer"
if Rails.env.development?
#config.secret_key = 'f71c467e526f23d614b3b08866cad4788c502bed869c282f06e73ee6c94675b62fe1f6d52fa7ba8196b33031f0d2f3b67e27ea07693c52ecebccb01700cad614'
if Rails.env.development? # this is for Connors localhost
config.secret_key = 'f71c467e526f23d614b3b08866cad4788c502bed869c282f06e73ee6c94675b62fe1f6d52fa7ba8196b33031f0d2f3b67e27ea07693c52ecebccb01700cad614'
end
if Rails.env.production? # this is for the heroku staging environment
config.secret_key = 'd91ba0da95749174ee2b8922034783cbde4945409ed28b13383e18e72844beb74467f8199e9e216f0687cd2290c6e46bf74da24486d14bba3671d76c5b10c753'