diff --git a/lib/helperLib.js b/lib/helperLib.js index 2afc871..c36263c 100644 --- a/lib/helperLib.js +++ b/lib/helperLib.js @@ -49,8 +49,8 @@ module.exports = { socket.emit("commitReceived"); }); - socket.on("revHistoryRequest", function(){ - getAndSendRevHistory(null, socket); + socket.on("revHistoryRequest", function(subRootId){ + getAndSendRevHistory(subRootId, socket); }); //socket.emit('news', {hello: "world"}); diff --git a/lib/revAlgorithm.js b/lib/revAlgorithm.js index 559c07a..e0617b7 100644 --- a/lib/revAlgorithm.js +++ b/lib/revAlgorithm.js @@ -3,16 +3,16 @@ var MySnap = require('../models/Snap.js').MySnap module.exports.getAndSendRevHistory = getAndSendRevHistory; -function getAndSendRevHistory(rootId, sock){ +function getAndSendRevHistory(subRootId, sock){ globalList = []; snapHash = {}; timeHash = {}; depth = 0; socket = sock; - var rootId = "53ea3f506dc8d39342bf4f9f"; + // subRootId = "53f10817cb52c1e31cf45d94"; // FetchSelfAndChildrenBack(rootId, asyncLoopGetChildren); - asyncLoopGetChildren([rootId]); + asyncLoopGetChildren([subRootId]); } //This is all the backSnaps for ONE rootId. diff --git a/public/js/app.js b/public/js/app.js index 8f43d92..8d76653 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,13 +1,16 @@ $(function(){ //alert("jquery works"); + var myRouter; $("#COMMIT").click(function(){ socket.emit("COMMIT"); }); - $(".getRevHistory").click(function(){ - socket.emit("revHistoryRequest"); + $(".getRevHistory").click(function(e){ + var rootId = $(".root").attr("data-id") + socket.emit("revHistoryRequest", rootId); + $(e.target).attr("data-id", rootId); }); $(".toggleSidebar").click(function(){ @@ -291,6 +294,9 @@ if((vo.hitTab && !event.shiftKey) || (event.keyCode == 39 && event.shiftKey)){ / 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); + setTimeout(function(){ + + }, 100); } } if((vo.hitTab && event.shiftKey) || (event.keyCode == 37 && event.shiftKey)){// OUTDENT!! diff --git a/public/js/libs/myLib/revControl.js b/public/js/libs/myLib/revControl.js index 9337920..964b99a 100644 --- a/public/js/libs/myLib/revControl.js +++ b/public/js/libs/myLib/revControl.js @@ -11,7 +11,8 @@ renderRevControl = function(rootNode, timeStamp){ } console.log("FINALCOLLECTION"); console.log(finalCollection); - nodesCollection = new NodesCollection(finalCollection); + var snapCollection = new NodesCollection(finalCollection); + return snapCollection; } diff --git a/public/js/router.js b/public/js/router.js index b04d370..4045786 100644 --- a/public/js/router.js +++ b/public/js/router.js @@ -62,17 +62,19 @@ $("#revTimestamps").html(list); }) + $("#revTimestamps").on("click", "a.timestamp", function(event){ // debugger; var a = event.target; var timestamp = parseInt($(a).html()); - renderRevControl("53ea3f506dc8d39342bf4f9f", timestamp); - setTimeout(function(){ - // debugger; - console.log("nodesCollection") - console.log(nodesCollection); - that.viewRoot("53ea3f506dc8d39342bf4f9f") - }, 1000); + 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){ @@ -189,27 +191,28 @@ }, - viewRoot: function(id){ - var rootNode = nodesCollection.findWhere({_id: id}); - if(!rootNode){ - rootNode = nodesCollection.findWhere({cur_id: id}); + viewRoot: function(id, snapCollection){ + + var rootModel; + var metaCollection; + var snapView = 0; + if(snapCollection){ + rootModel = snapCollection.findWhere({cur_id: id}); + metaCollection = snapCollection + snapView = 1; } - // alert("viewNode"); - console.log("ViewRoot + rootNode"); - console.log(rootNode); + else{ + rootModel = nodesCollection.findWhere({_id: id}); + metaCollection = nodesCollection; + } + var rootView = new listView({ viewWindow: ".main1", - model: rootNode, - nodesCollection: nodesCollection //nodesCollection might be global (and this would be redundant) + model: rootModel, + metaCollection: metaCollection, + snapView: snapView }) this.changeView(rootView); - - // var rootView = new listView({ - // viewWindow: ".main2", - // model: rootNode, - // nodesCollection: nodesCollection //nodesCollection might be global (and this would be redundant) - // }) - // this.changeView(rootView); }, changeView: function(view) { diff --git a/public/js/views/listView.js b/public/js/views/listView.js index 7863a02..aa97003 100644 --- a/public/js/views/listView.js +++ b/public/js/views/listView.js @@ -2,6 +2,8 @@ var listView = Backbone.View.extend({ initialize: function(options){ var that = this; + that.metaCollection = options["metaCollection"]; + that.snapView = options["snapView"]; this.viewWindow = $(options["viewWindow"]); that.model = options["model"]; @@ -24,6 +26,15 @@ var listView = Backbone.View.extend({ return that; }, + findModel: function(id){ + if(this.snapView){ + return this.metaCollection.findWhere({cur_id: id}); + } + else{ + return this.metaCollection.findWhere({_id: id}); + } + }, + renderPath: function(){ var that = this; @@ -33,12 +44,12 @@ var listView = Backbone.View.extend({ var parents = that.model.get("parents"); while(parents.length != 0){ ancestry.push(parents); - parents = nodesCollection.findWhere({_id: parents[0] }).get("parents"); + parents = that.findModel(parents[0]).get("parents"); //making the assumption/simplification that it's a tree. Not a graph. } _.each(ancestry.reverse(), function(parent){ - var parentModel = nodesCollection.findWhere({_id: parent[0] }); + var parentModel = that.findModel(parent[0]); pathDiv += "" + parentModel.get("text") + ""; pathDiv += " -- "; }); @@ -54,15 +65,15 @@ var listView = Backbone.View.extend({ var childrenIds = that.model.get("children"); _.each(childrenIds, function(childId, index){ - var childModel = nodesCollection.findWhere({_id: childId}); - if(!childModel){childModel= nodesCollection.findWhere({cur_id: childId});} - console.log("childModelId = " + childId); - console.log(childModel); + var childModel = that.findModel(childId); + var tempView = new showView({ depth: 0, - model: childModel //, - //nodesCollection: that.nodesCollection + model: childModel, + metaCollection: that.metaCollection, + snapView: that.snapView }); + var tempLI = tempView.render().$el; tempLI.children("textarea").textareaAutoExpand(); that.$el.append(tempLI); @@ -76,7 +87,9 @@ var listView = Backbone.View.extend({ var that = this; var newView = new showView({ model: newNode, - depth: 0 + depth: 0, + metaCollection: that.metaCollection, + snapView: that.snapView }); var newLI = newView.render().$el; diff --git a/public/js/views/showView.js b/public/js/views/showView.js index 3ecbf0e..662c245 100644 --- a/public/js/views/showView.js +++ b/public/js/views/showView.js @@ -1,6 +1,8 @@ var showView = Backbone.View.extend({ initialize: function(options){ var that = this; + that.metaCollection = options["metaCollection"]; + that.snapView = options["snapView"]; this.model = options["model"]; this.depth = options["depth"]; @@ -15,6 +17,16 @@ var showView = Backbone.View.extend({ events: {"click .markdown" : "showMarkDownEditor"}, + findModel: function(id){ + if(this.snapView){ + return this.metaCollection.findWhere({cur_id: id}); + } + else{ + return this.metaCollection.findWhere({_id: id}); + } + }, + + //todo = refactor this function. render: function(){ var that = this; @@ -29,6 +41,10 @@ var showView = Backbone.View.extend({ that.$el.attr("data-id", id); that.$el.html(html); + if(that.snapView){ + that.$el.children().children("textarea").prop("disabled", true); + that.$el.addClass("snapLI"); + } console.log("about to render textarea") that.renderChildren(); @@ -40,10 +56,12 @@ var showView = Backbone.View.extend({ var childrenIds = that.model.get("children"); _.each(childrenIds, function(childId, index){ - var childModel = nodesCollection.findWhere({_id: childId}); + var childModel = that.findModel(childId); var tempView = new showView({ - depth: 0, - model: childModel + depth: that.depth + 1, + model: childModel, + metaCollection: that.metaCollection, + snapView: that.snapView }); that.childViews.push(tempView) that.$el.children("ul").append(tempView.render().$el); @@ -115,7 +133,10 @@ var showView = Backbone.View.extend({ console.log("addNodeText" + newNode.get("text")) var newView = new showView({ model: newNode, - depth: that.depth +1 + depth: that.depth +1, + metaCollection: that.metaCollection, + snapView: that.snapView + }); var newLI = newView.render().$el; @@ -130,7 +151,7 @@ var showView = Backbone.View.extend({ that.childViews.insert(index , newView); if(cur){ - newLI.children().children("textarea").focus(); + newLI.children().children("textarea").focus().textareaAutoExpand(); } else{ newView.lock(); @@ -146,7 +167,7 @@ var showView = Backbone.View.extend({ var that = this; this.$el.children().children("textarea").val(that.model.get("text")); }, - lock: function(){ + lock: function(){ //for concurrent editing... this.$el.children().children("textarea").attr("readonly", "readonly"); this.$el.children().children("textarea").val("editing....") }, diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index aaf4674..1713a92 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -148,6 +148,12 @@ ul.navbar-right { /**************** Panel ****************/ /**************** List *****************/ + +.snapLI > span > textarea:hover{ + border: 1px solid black; +} + + #marked-mathjax-input{ border: 2px dotted black; margin-left: 0px;