mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-07-17 01:30:32 +08:00
Real-time editing works (as far as I can tell)
This commit is contained in:
@@ -11,7 +11,7 @@ require('./config/passport')(passport); // pass passport for configuration
|
||||
require("./models/Node.js");
|
||||
//This isn't used in this file, but calling it before helper lib avoids circularDependencies.
|
||||
var helperLib = require('./lib/helperLib.js');
|
||||
console.log(helperLib);
|
||||
console.log("appJS,HelperLib", helperLib);
|
||||
helperLib.safeConnectToDB();
|
||||
|
||||
|
||||
|
||||
+6
-3
@@ -8,18 +8,21 @@ var mongoose = require('mongoose');
|
||||
var User = mongoose.model('User');
|
||||
var Node = require('../models/Node.js');
|
||||
|
||||
var io;
|
||||
var io = "uninitialized...";
|
||||
var online = [];
|
||||
var lastExchangeData = {};
|
||||
var makeCommit = require("./makeCommit.js").makeCommit;
|
||||
var getAndSendRevHistory = require("./revAlgorithm.js").getAndSendRevHistory;
|
||||
|
||||
var MessageQueue =require("./MessageQueue.js");
|
||||
console.log("MessageQueue");
|
||||
console.log(MessageQueue);
|
||||
console.log("MessageQueue", MessageQueue);
|
||||
|
||||
module.exports = {
|
||||
|
||||
validateParArr: function(parId, parArr){
|
||||
io.sockets.emit("VALIDATE", [parId, parArr]);
|
||||
},
|
||||
|
||||
iterateQueue: MessageQueue.iterateQueue,
|
||||
|
||||
safeConnectToDB: function(){
|
||||
|
||||
+11
-5
@@ -111,6 +111,7 @@ function moveNode(ids, arrays, authorId){
|
||||
MyNode.findById(oldParId, null, function(err, node){
|
||||
node.timestamp = now;
|
||||
node.children = arrays[1];
|
||||
helperLib.validateParArr(oldParId, node.children);
|
||||
node.save(parallelExecutionHelper);
|
||||
});
|
||||
|
||||
@@ -118,6 +119,7 @@ function moveNode(ids, arrays, authorId){
|
||||
MyNode.findById(newParId, null, function(err, node){
|
||||
node.timestamp = now;
|
||||
node.children = arrays[2];
|
||||
helperLib.validateParArr(newParId, node.children);
|
||||
node.save(parallelExecutionHelper);
|
||||
});
|
||||
|
||||
@@ -139,11 +141,13 @@ function removeNode(thisId, thisIndex, parId, authorId){
|
||||
if(err || parNode == null){
|
||||
return;
|
||||
}
|
||||
var temp = parNode.children;
|
||||
temp.splice(thisIndex, 1); //remove thisIndex.
|
||||
parNode.children = temp;
|
||||
// var temp = parNode.children;
|
||||
// temp.splice(thisIndex, 1); //remove thisIndex.
|
||||
// parNode.children = temp;
|
||||
parNode.children.splice(thisIndex,1);
|
||||
parNode.timestamp = now;
|
||||
|
||||
helperLib.validateParArr(parId, parNode.children);
|
||||
parNode.save(function(){helperLib.iterateQueue()});
|
||||
});
|
||||
|
||||
@@ -179,7 +183,9 @@ function updateParent(parId, newId ,newIndex,now){
|
||||
return;
|
||||
}
|
||||
parNode.children.insert(newIndex, newId);
|
||||
parNode.timestamp = Date.now();
|
||||
parNode.timestamp = now;
|
||||
|
||||
helperLib.validateParArr(parId, parNode.children);
|
||||
parNode.save();
|
||||
})
|
||||
}
|
||||
@@ -200,7 +206,7 @@ function addNode(text, children, parents, authorId, callback){
|
||||
}
|
||||
else {
|
||||
helperLib.iterateQueue();
|
||||
callback(null, instance);
|
||||
callback(null, instance, instance.timestamp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -265,12 +265,19 @@ socket.on("revControl", function(data){
|
||||
var timeStamps = timeHash.keys;
|
||||
|
||||
//To be continued...
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
socket.on("VALIDATE", function(data){
|
||||
var parId = data[0];
|
||||
var parArr = data[1];
|
||||
var thisParArr = nodesCollection.findWhere({_id: parId}).get("children");
|
||||
if(!_.isEqual(thisParArr, parArr)){
|
||||
alert("syncing error.Edits no longer synced. Please refresh browser");
|
||||
socket = null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
socket.emit("nodeRequest");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user