mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-09-09 11:14:22 +08:00
REVISION CONTROL
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
$(function(){
|
||||
//alert("jquery works");
|
||||
|
||||
|
||||
$("#COMMIT").click(function(){
|
||||
socket.emit("COMMIT");
|
||||
});
|
||||
|
||||
$(".getRevHistory").click(function(){
|
||||
socket.emit("revHistoryRequest");
|
||||
});
|
||||
|
||||
$(".toggleSidebar").click(function(){
|
||||
$("#mainPanel").toggleClass("floatRight centering");
|
||||
$("#metaSidebar").toggleClass("hideBar");
|
||||
});
|
||||
|
||||
$("#markdownButton").click(function(){
|
||||
vo.thisView.createMarkDownBullet();
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var nodesCollection = Backbone.Collection.extend({
|
||||
var NodesCollection = Backbone.Collection.extend({
|
||||
|
||||
model: NodeModel
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
renderRevControl = function(rootNode, timeStamp){
|
||||
var finalCollection = [];
|
||||
rootSnap = fetchLTE(rootNode, timeStamp );
|
||||
|
||||
var queue = [rootSnap];
|
||||
while(queue.length > 0){
|
||||
snap = queue.shift();
|
||||
finalCollection.push(snap);
|
||||
childrenSnaps = fetchChildren(snap);
|
||||
_.each(childrenSnaps, function(childSnap){queue.push(childSnap)});
|
||||
}
|
||||
console.log("FINALCOLLECTION");
|
||||
console.log(finalCollection);
|
||||
nodesCollection = new NodesCollection(finalCollection);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//we want the first snap that has a timestamp lessThan or Equal to this.
|
||||
//(if none exists, then this call is made in error!).
|
||||
function fetchLTE(nodeId, timeStamp){
|
||||
var snapList = snapHash[nodeId]; //sorted, [0] is smallest
|
||||
for(var i = snapList.length-1 ; i >= 0; i--){ //start with biggest/mostRecent.
|
||||
if(snapList[i].timestamp <= timeStamp){
|
||||
return snapList[i];
|
||||
}
|
||||
}
|
||||
alert("error!!");
|
||||
}
|
||||
|
||||
function fetchChildren(subRootSnap){
|
||||
childrenSnaps = [];
|
||||
var timeStamp = snap.timestamp;
|
||||
_.each(subRootSnap.children, function(childId){
|
||||
childrenSnaps.push( fetchLTE(childId, timeStamp) );
|
||||
});
|
||||
return childrenSnaps;
|
||||
}
|
||||
+57
-3
@@ -29,7 +29,7 @@
|
||||
socket.on('nodeData', function(data){
|
||||
//alert("data");
|
||||
console.log(data);
|
||||
nodesCollection = new nodesCollection(data);
|
||||
nodesCollection = new NodesCollection(data);
|
||||
var id = nodesCollection.findWhere({text: "0root"}).get("_id");
|
||||
if(otherID){
|
||||
id = otherID
|
||||
@@ -39,6 +39,42 @@
|
||||
that.viewRoot(id);
|
||||
});
|
||||
|
||||
|
||||
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);
|
||||
|
||||
var list = "";
|
||||
_.each(Object.keys(timeHash), function(timestamp){
|
||||
list += "<li><a class='timestamp'>"+timestamp+"</a></li>";
|
||||
})
|
||||
|
||||
$("#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);
|
||||
});
|
||||
|
||||
socket.on('edit', function(data){
|
||||
var id = data[0];
|
||||
var newText = data[1];
|
||||
@@ -130,9 +166,24 @@
|
||||
var thisModel = nodesCollection.findWhere({_id: ids[0]});
|
||||
var oldParModel = nodesCollection.findWhere({_id: ids[1]});
|
||||
var newParModel = nodesCollection.findWhere({_id: ids[2]});
|
||||
debugger;
|
||||
// debugger;
|
||||
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...
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -140,6 +191,9 @@
|
||||
|
||||
viewRoot: function(id){
|
||||
var rootNode = nodesCollection.findWhere({_id: id});
|
||||
if(!rootNode){
|
||||
rootNode = nodesCollection.findWhere({cur_id: id});
|
||||
}
|
||||
// alert("viewNode");
|
||||
console.log("ViewRoot + rootNode");
|
||||
console.log(rootNode);
|
||||
|
||||
@@ -55,6 +55,7 @@ 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 tempView = new showView({
|
||||
|
||||
Reference in New Issue
Block a user