misc small bug-fixes

This commit is contained in:
Curtis SerVaas
2014-08-20 13:23:43 -07:00
parent 411a15d39d
commit ecbdca040d
8 changed files with 302 additions and 301 deletions
+1
View File
@@ -1,3 +1,4 @@
console.log("initializing");
var express = require('express');
var app = express();
var config = require('./config/config.js')
+6 -6
View File
@@ -20,10 +20,10 @@ module.exports = {
var url = require("../config/config.js").DB_URL;
try { mongoose.connect(url); }
catch(err) { console.log("Error: Sign In to MongoLab") }
}
},
createSocket: function(server) {
io = require('socket.io').listen(server);
io = require('socket.io').listen(server, {log: false});
io.sockets.on('connection', function(socket){
socket.AUTHOR = {}; //anonymous.
@@ -31,6 +31,7 @@ module.exports = {
socket.on("logIn", function(data){
socket.AUTHOR = data;
attachLogInListeners(socket);
console.log("logIn + attachLogInListeners")
});
socket.on('nodeRequest', function(data){
@@ -110,7 +111,6 @@ function attachLogInListeners(socket){
socket.on("newNode", function(data){
//data[0] = [parID, newindex] . data[1] = modelJSON
var modelJson = data[1]; //(includes the negative ID to find later);
var parId = data[0][0];
var newIndex = data[0][1];
@@ -122,15 +122,15 @@ function attachLogInListeners(socket){
socket.emit("updateReceived", [modelJson._id ,instance, data[0]]);
socket.broadcast.emit("newNode", [ [parId,newIndex] , instance ]);
//io.sockets.emit("newNode", [data[0], instance])
//I'm going to have to update the parent Model on this as well...
//(and therefore, broadcast the array...)
Node.updateParent(parId, instance._id ,newIndex, now );
}
console.log("newNode");
Node.addNode(modelJson.text, modelJson.children, modelJson.parents, modelJson.author._id ,callback);
});
//need to broadcast parentArray.
socket.on("removeNode", function(data){
var thisId = data[0];
+7 -1
View File
@@ -1,4 +1,5 @@
var mongoose = require('mongoose');
var _ = require("underscore");
var NodeSchema = new mongoose.Schema({
text: {type: String},
@@ -132,7 +133,7 @@ function removeNode(thisId, thisIndex, parId, authorId){
delNode.save();
}
else{ //this is the condition that we'll have to take care of if there are dups.
delNode.parents = _.without(parents, parId);
delNode.parents = _.without(delNode.parents, parId);
delNode.save();
}
})
@@ -150,6 +151,11 @@ function updateText(id, newText, authorId){
});
}
function updateParent(parId, newId ,newIndex,now){
MyNode.findById(parId, null, function(err, parNode){
if(err || parNode == null){
+3 -9
View File
@@ -50,15 +50,11 @@ $(function(){
$("body").on("mouseover", "a.expandCollapse", function(event){
// console.log("bleh");
// debugger;
$(event.target).find("a.expandCollapse").css("opacity", "1");
$(event.target).closest("a.expandCollapse").css("opacity", "1");
// $(event.target).siblings("a.expandCollapse").css("opacity", "1")
});
$("body").on("mouseleave", "a.expandCollapse", function(event){
// console.log("bleh");
// debugger;
$(event.target).find("a.expandCollapse").css("opacity", ".001");
$(event.target).closest("a.expandCollapse").css("opacity", ".001");
// $(event.target).siblings("a.expandCollapse").css("opacity", ".001")
@@ -90,17 +86,13 @@ $(function(){
});
$("body").on("click", ".transclude", function(event){
//alert(vo.thisId);
alert("Transclusion syncing with the server has not been implemented. KnownBugs:\n0.Don't make infinite loops.\n1.");
transclude();
});
// AppRouter.initialize();
myRouter = new AppRouter;
Backbone.history.start();
//console.log("typeOF FUNCTION");
//console.log($.fn.textareaAutoExpand);
//this calls initialize twice.
});
@@ -212,6 +204,7 @@ keydownHandler = function(event){ //the entire body is wrapped in this.
var that = this;
//
if(event.which == undefined){ return; }
if(!CurrentUser){ alert("only logged in users can edit"); return;}//prevent non-logged in users from editing.
voInitializer(that, event);
@@ -240,6 +233,7 @@ keydownHandler = function(event){ //the entire body is wrapped in this.
if(!event.shiftKey){
event.preventDefault();
if(vo.empty){
addNode("");
return;
+132 -132
View File
@@ -1,157 +1,157 @@
voInitializer = function(that, event){
// voInitializer = function(that, event){
vo = {};
vo.hitEnter = (event.which == 13);
vo.hitTab = (event.which ==9);
vo.atEnd = ( $(that).getSelection().end == $(that).val().length);
vo.atBeg = ( $(that).getSelection().start == 0);
//cursor = $(this).getSelection().start;
vo.hitBack = (event.which ==8);
vo.empty = ($(that).val().length ==0);
// vo = {};
// vo.hitEnter = (event.which == 13);
// vo.hitTab = (event.which ==9);
// vo.atEnd = ( $(that).getSelection().end == $(that).val().length);
// vo.atBeg = ( $(that).getSelection().start == 0);
// //cursor = $(this).getSelection().start;
// vo.hitBack = (event.which ==8);
// vo.empty = ($(that).val().length ==0);
vo.rootLevel = $(that).closest("ul").is(".root")
vo.lastBullet = ( $(that).closest("li").is(":first-child") && vo.rootLevel);
vo.thisLI = $(event.target).closest("li");
vo.thisId = vo.thisLI.attr("data-id"); //data-id.
vo.thisIndex = vo.thisLI.index(); //returns -1 if there's no match.
vo.thisModel = nodesCollection.findWhere({_id: vo.thisId});
// vo.rootLevel = $(that).closest("ul").is(".root")
// vo.lastBullet = ( $(that).closest("li").is(":first-child") && vo.rootLevel);
// vo.thisLI = $(event.target).closest("li");
// vo.thisId = vo.thisLI.attr("data-id"); //data-id.
// vo.thisIndex = vo.thisLI.index(); //returns -1 if there's no match.
// vo.thisModel = nodesCollection.findWhere({_id: vo.thisId});
vo.siblingLI = vo.thisLI.prev();
vo.siblingIndex = vo.siblingLI.index();
vo.siblingId = vo.siblingLI.attr("data-id");
vo.siblingModel = nodesCollection.findWhere({_id: vo.siblingId});
// vo.siblingLI = vo.thisLI.prev();
// vo.siblingIndex = vo.siblingLI.index();
// vo.siblingId = vo.siblingLI.attr("data-id");
// vo.siblingModel = nodesCollection.findWhere({_id: vo.siblingId});
console.log(nodesCollection);
console.log(vo.thisModel);
// console.log(nodesCollection);
// console.log(vo.thisModel);
if(vo.rootLevel){
vo.parentLI = undefined;
vo.parentId = (vo.thisLI.closest("ul").attr("data-id"))
vo.grandParentId = undefined; // won't matter since outTab prevents it. //unless programattic.
}
else{ //not root level.
vo.parentLI = vo.thisLI.parent().closest("li");
vo.parentId = (vo.parentLI.attr("data-id"));
if(vo.parentLI.attr("data-depth") == 0){ //could test this another way.
vo.grandParentId = vo.parentLI.closest("ul").attr("data-id");
}
else{
vo.grandParentId = (vo.parentLI.parent().closest("li").attr('data-id'));
}
}
vo.grandParentModel = nodesCollection.findWhere({_id: vo.grandParentId});
vo.parentModel = nodesCollection.findWhere({_id: vo.parentId});
}
// if(vo.rootLevel){
// vo.parentLI = undefined;
// vo.parentId = (vo.thisLI.closest("ul").attr("data-id"))
// vo.grandParentId = undefined; // won't matter since outTab prevents it. //unless programattic.
// }
// else{ //not root level.
// vo.parentLI = vo.thisLI.parent().closest("li");
// vo.parentId = (vo.parentLI.attr("data-id"));
// if(vo.parentLI.attr("data-depth") == 0){ //could test this another way.
// vo.grandParentId = vo.parentLI.closest("ul").attr("data-id");
// }
// else{
// vo.grandParentId = (vo.parentLI.parent().closest("li").attr('data-id'));
// }
// }
// vo.grandParentModel = nodesCollection.findWhere({_id: vo.grandParentId});
// vo.parentModel = nodesCollection.findWhere({_id: vo.parentId});
// }
keydownHandler = function(event){ //the entire body is wrapped in this.
var that = this;
//
if(event.which == undefined){ return; }
// keydownHandler = function(event){ //the entire body is wrapped in this.
// var that = this;
// //
// if(event.which == undefined){ return; }
voInitializer(that, event);
// voInitializer(that, event);
//minor-bug
//event.preventDefault();
//http://stackoverflow.com/questions/20964729/run-keydown-event-handler-after-the-value-of-a-textarea-has-been-changed
//keyupp fixes this, but causes other problems.
if( !(vo.hitTab || vo.hitEnter || (vo.hitBack && vo.empty))){
//The reason this isn't syncing perfectly between bullets is that...
//... the text-area val hasn't updated at this point.
vo.thisModel.set("text", $(that).val());
_.each(vo.thisModel.get("views"), function(view){
view.updateText()
});
}
// //minor-bug
// //event.preventDefault();
// //http://stackoverflow.com/questions/20964729/run-keydown-event-handler-after-the-value-of-a-textarea-has-been-changed
// //keyupp fixes this, but causes other problems.
// if( !(vo.hitTab || vo.hitEnter || (vo.hitBack && vo.empty))){
// //The reason this isn't syncing perfectly between bullets is that...
// //... the text-area val hasn't updated at this point.
// vo.thisModel.set("text", $(that).val());
// _.each(vo.thisModel.get("views"), function(view){
// view.updateText()
// });
// }
if(vo.hitEnter){
event.preventDefault();
// if(vo.hitEnter){
// event.preventDefault();
if(event.shiftKey){
_.each(vo.thisModel.get("views"), function(view){
view.collapse();
});
event.preventDefault();
alert("Temporarily is used for expand/collapse (instead of clicking)")
}
// if(event.shiftKey){
// _.each(vo.thisModel.get("views"), function(view){
// view.collapse();
// });
// event.preventDefault();
// alert("Temporarily is used for expand/collapse (instead of clicking)")
// }
if(!event.shiftKey){
event.preventDefault();
if(vo.empty){
addNode("");
return;
}//if(empty)
else{//!empty
if(vo.atEnd){
//alert("CORRECT!")
addNode("");
return;
}//
if(!vo.atEnd && !vo.atBeg){ //split bullet
var topStr = '';
var botStr = '';
splitText(that, botStr, topStr, addNode);
return;
//addNode(botStr, topStr);
}
if(!vo.atEnd && vo.atBeg){//addNode (before). (equivalent to splitting bullet)
var topStr = '';
var botStr = '';
splitText(that, botStr, topStr, addNode);
return;
//addNode(botStr, topStr);
}
}//!empty
// if(!event.shiftKey){
// event.preventDefault();
// if(vo.empty){
// addNode("");
// return;
// }//if(empty)
// else{//!empty
// if(vo.atEnd){
// //alert("CORRECT!")
// addNode("");
// return;
// }//
// if(!vo.atEnd && !vo.atBeg){ //split bullet
// var topStr = '';
// var botStr = '';
// splitText(that, botStr, topStr, addNode);
// return;
// //addNode(botStr, topStr);
// }
// if(!vo.atEnd && vo.atBeg){//addNode (before). (equivalent to splitting bullet)
// var topStr = '';
// var botStr = '';
// splitText(that, botStr, topStr, addNode);
// return;
// //addNode(botStr, topStr);
// }
// }//!empty
}
} //hitEnter
// }
// } //hitEnter
if(vo.hitBack && vo.empty){
event.preventDefault();
removeNode(vo);
// if(vo.hitBack && vo.empty){
// event.preventDefault();
// removeNode(vo);
}//hitBack.
// }//hitBack.
if((vo.hitTab && !event.shiftKey) || (event.keyCode == 39 && event.shiftKey)){ //INDENT
event.preventDefault();
var hasAboveSibling = (vo.thisIndex != 0);
if(hasAboveSibling){
var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh)
moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true);
}
}
if((vo.hitTab && event.shiftKey) || (event.keyCode == 37 && event.shiftKey)){// OUTDENT!!
if (($(this).parent().parent().parent().hasClass("root"))) {
// do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes.
}
else {
var newSiblingUL = $(this).parent().parent().parent();
var newIndex = newSiblingUL.closest("li").index();
moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true);
setTimeout(function(){ //(MoveNode is asynchronous, so you need to wait a little bit.).
newSiblingUL.parent().next().children().children("textarea").focus();
}, 100);
}//if->else
}//if
// if((vo.hitTab && !event.shiftKey) || (event.keyCode == 39 && event.shiftKey)){ //INDENT
// event.preventDefault();
// var hasAboveSibling = (vo.thisIndex != 0);
// if(hasAboveSibling){
// var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh)
// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true);
// }
// }
// if((vo.hitTab && event.shiftKey) || (event.keyCode == 37 && event.shiftKey)){// OUTDENT!!
// if (($(this).parent().parent().parent().hasClass("root"))) {
// // do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes.
// }
// else {
// var newSiblingUL = $(this).parent().parent().parent();
// var newIndex = newSiblingUL.closest("li").index();
// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true);
// setTimeout(function(){ //(MoveNode is asynchronous, so you need to wait a little bit.).
// newSiblingUL.parent().next().children().children("textarea").focus();
// }, 100);
// }//if->else
// }//if
if(event.keyCode == 38 && event.shiftKey && !vo.thisLI.is(":first-child")) {
moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex-1, true);
return;
}
if(event.keyCode == 40 && event.shiftKey && !vo.thisLI.is(":last-child")) {
moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex+1, true);
return;
}
// if(event.keyCode == 38 && event.shiftKey && !vo.thisLI.is(":first-child")) {
// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex-1, true);
// return;
// }
// if(event.keyCode == 40 && event.shiftKey && !vo.thisLI.is(":last-child")) {
// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex+1, true);
// return;
// }
}//vo-initializer
// }//vo-initializer
Array.prototype.removeOne = function(parId){
var parIndex = this.indexOf(parId);
this.remove(parIndex);
}
// Array.prototype.removeOne = function(parId){
// var parIndex = this.indexOf(parId);
// this.remove(parIndex);
// }
+1 -2
View File
@@ -1,6 +1,5 @@
addNode = function(botStr, topStr){
console.log("ADDNODE (LOGIC)");
console.log(vo);
// debugger;
var randomId = ( -1 * Math.floor( Math.random() * 100000000) )
var modelJSON = {
+148 -151
View File
@@ -11,6 +11,7 @@
initialize: function(){
if(socket){ return; }//prevents double-initialization.
socket = io.connect();
this.setUpSocket();
@@ -91,186 +92,182 @@
},
setUpSocket: function(){
var that = this;
socket.on('nodeData', function(data){
//alert("data");
setUpSocket: function(){
var that = this;
socket.on('nodeData', function(data){
//alert("data");
console.log(data);
nodesCollection = new NodesCollection(data);
var id = nodesCollection.findWhere({text: "0root"}).get("_id");
// if(otherID){
// id = otherID
// }
console.log(data);
nodesCollection = new NodesCollection(data);
var id = nodesCollection.findWhere({text: "0root"}).get("_id");
// if(otherID){
// id = otherID
// }
that.viewRoot(id);
});
that.viewRoot(id);
});
socket.on("commitReceived", function(){
alert("commitReceived");
});
socket.on("commitReceived", function(){
alert("commitReceived");
});
socket.on("revHistory", function(data){
alert("revHistory!!");
console.log("revHistory!!");
snapHash = data[0];
timeHash = data[1];
console.log("snapHash");
console.log(snapHash);
console.log("timeHash");
console.log(timeHash);
socket.on("revHistory", function(data){
alert("revHistory!!");
console.log("revHistory!!");
snapHash = data[0];
timeHash = data[1];
console.log("snapHash");
console.log(snapHash);
console.log("timeHash");
console.log(timeHash);
var list = "";
_.each(Object.keys(timeHash), function(timestamp){
list += "<li><a class='timestamp'>"+timestamp+"</a></li>";
})
$("#revTimestamps").html(list);
var list = "";
_.each(Object.keys(timeHash), function(timestamp){
list += "<li><a class='timestamp'>"+timestamp+"</a></li>";
})
$("#revTimestamps").on("click", "a.timestamp", function(event){
// debugger;
var a = event.target;
var timestamp = parseInt($(a).html());
var subRootId = $(".getRevHistory").attr("data-id");
var snapCollection = renderRevControl(subRootId, timestamp);
console.log("snapCollection")
console.log(snapCollection);
that.viewRoot(subRootId, snapCollection);
});
$("#revTimestamps").html(list);
})
socket.on('edit', function(data){
var id = data[0];
var newText = data[1];
$("#revTimestamps").on("click", "a.timestamp", function(event){
// debugger;
var a = event.target;
var timestamp = parseInt($(a).html());
var subRootId = $(".getRevHistory").attr("data-id");
var snapCollection = renderRevControl(subRootId, timestamp);
console.log("snapCollection")
console.log(snapCollection);
that.viewRoot(subRootId, snapCollection);
});
socket.on('edit', function(data){
var id = data[0];
var newText = data[1];
var curModel = nodesCollection.findWhere({_id: id})
curModel.set("text", newText);
_.each(curModel.get("views"), function(view){
view.updateText(newText);
var curModel = nodesCollection.findWhere({_id: id})
curModel.set("text", newText);
_.each(curModel.get("views"), function(view){
view.updateText(newText);
});
});
socket.on("updateReceived", function(data){
//data[0] is _id. data[1] is instance.
var instance = data[1];
var old_id = data[0];
var parId = data[2][0];
var newIndex = data[2][1];
});
var parentModel = nodesCollection.findWhere({_id: parId});
var new_id = instance._id
var oldModel = nodesCollection.findWhere({ _id: old_id });
oldModel.set("_id", new_id );
_.each(oldModel.get("views"), function(view){
view.updateId(new_id);
});
parentModel.get("children")[newIndex] = instance._id;
})
socket.on("updateReceived", function(data){
//data[0] is _id. data[1] is instance.
var instance = data[1];
var old_id = data[0];
var parId = data[2][0];
var newIndex = data[2][1];
socket.on("newNode", function(data){
//need the instance + the index.
var modelJson = data[1]; //(includes the negative ID to find later);
var parId = data[0][0];
var newIndex = data[0][1];
var newNode = new NodeModel(modelJson);
nodesCollection.add(newNode);
var parentModel = nodesCollection.findWhere({_id: parId});
var parentViews = parentModel.get("views");
_.each(parentViews, function(parentView){
parentView.addNode(newNode, newIndex).lock();
//look at socket.emit("newNode" to see why -1);
});
parentModel.get("children").insert(newIndex, modelJson._id);
var parentModel = nodesCollection.findWhere({_id: parId});
var new_id = instance._id
var oldModel = nodesCollection.findWhere({ _id: old_id });
oldModel.set("_id", new_id );
_.each(oldModel.get("views"), function(view){
view.updateId(new_id);
});
parentModel.get("children")[newIndex] = instance._id;
})
socket.on("editing", function(data){
var id = data[0];
var authorName = data[1];
console.log("EDITING RECEIVED + ID");
console.log(id);
if(id < 0){return;}
var tempViews = nodesCollection.findWhere({_id: id}).get("views");
_.each(tempViews, function(tempView){
tempView.lock();
});
socket.on("newNode", function(data){
//need the instance + the index.
var modelJson = data[1]; //(includes the negative ID to find later);
var parId = data[0][0];
var newIndex = data[0][1];
var newNode = new NodeModel(modelJson);
nodesCollection.add(newNode);
var parentModel = nodesCollection.findWhere({_id: parId});
var parentViews = parentModel.get("views");
_.each(parentViews, function(parentView){
parentView.addNode(newNode, newIndex).lock();
//look at socket.emit("newNode" to see why -1);
});
parentModel.get("children").insert(newIndex, modelJson._id);
});
socket.on("blurred", function(data){
var id = data[0];
var text = data[1];
var author = data[2];
var tempModel = nodesCollection.findWhere({_id: id});
tempModel.set("text", text);
tempModel.set("author", author);
var tempViews = tempModel.get("views");
_.each(tempViews, function(tempView){
tempView.unlock();
tempView.updateText(text);
});
});
socket.on("removeNode", function(data){
var tempVo = {}; //PROTECTING STATE!!
// tempVo.author = data[3]; //(actually, unnecessary...)
tempVo.thisId = data[0];
tempVo.thisIndex = data[1];
tempVo.parentId = data[2];
tempVo.thisModel = nodesCollection.findWhere({_id: tempVo.thisId});
tempVo.parentModel = nodesCollection.findWhere({_id: tempVo.parentId});
removeNode(tempVo, true); //true means came from broadcast.
});
socket.on("movedNode", function(data){
var ids = data[0];
var indices = data[1];
var author = data[2];
var thisModel = nodesCollection.findWhere({_id: ids[0]});
var oldParModel = nodesCollection.findWhere({_id: ids[1]});
var newParModel = nodesCollection.findWhere({_id: ids[2]});
thisModel.set("author", author);
moveNode(thisModel, indices[0], oldParModel, newParModel, indices[1]);
socket.on("editing", function(data){
var id = data[0];
var authorName = data[1];
console.log("EDITING RECEIVED + ID");
console.log(id);
if(id < 0){return;}
var tempViews = nodesCollection.findWhere({_id: id}).get("views");
_.each(tempViews, function(tempView){
tempView.lock();
});
});
socket.on("revControl", function(data){
//(store all of this...).
var timeHash = data[0];
var snapHash = data[1];
var timeStamps = timeHash.keys;
//To be continued...
socket.on("blurred", function(data){
var id = data[0];
var text = data[1];
var author = data[2];
var tempModel = nodesCollection.findWhere({_id: id});
tempModel.set("text", text);
tempModel.set("author", author);
var tempViews = tempModel.get("views");
_.each(tempViews, function(tempView){
tempView.unlock();
tempView.updateText(text);
});
});
socket.emit("nodeRequest");
}
socket.on("removeNode", function(data){
var tempVo = {}; //PROTECTING STATE!!
});
// tempVo.author = data[3]; //(actually, unnecessary...)
tempVo.thisId = data[0];
tempVo.thisIndex = data[1];
tempVo.parentId = data[2];
tempVo.thisModel = nodesCollection.findWhere({_id: tempVo.thisId});
tempVo.parentModel = nodesCollection.findWhere({_id: tempVo.parentId});
removeNode(tempVo, true); //true means came from broadcast.
});
function setUpSocket(){
socket.on("movedNode", function(data){
var ids = data[0];
var indices = data[1];
var author = data[2];
var thisModel = nodesCollection.findWhere({_id: ids[0]});
var oldParModel = nodesCollection.findWhere({_id: ids[1]});
var newParModel = nodesCollection.findWhere({_id: ids[2]});
thisModel.set("author", author);
moveNode(thisModel, indices[0], oldParModel, newParModel, indices[1]);
});
socket.on("revControl", function(data){
//(store all of this...).
var timeHash = data[0];
var snapHash = data[1];
var timeStamps = timeHash.keys;
//To be continued...
});
socket.emit("nodeRequest");
}
});//endAppRouter.
+4
View File
@@ -153,6 +153,10 @@ ul.navbar-right {
border: 1px solid black;
}
.selectedSnap {
border: 2px solid red;
}
#marked-mathjax-input{
border: 2px dotted black;