Beispiel #1
0
				db.users.update({_id: everUserId}, {$set: data}, function(err, cnt) {

					if(err || cnt == 0) {
						console.log('用户信息更新失败', err);

					} else {
						Evt.setHost(me.host);
						console.log('用户信息更新成功');

						db.notes.update({UserId: everUserId}, {$set: {UserId: me.userId, IsDirty: true, ServerNoteId: '', LocalIsNew: true}}, {multi: true}, function () {
							console.log('notes 数据更新成功');
						});

						db.notebooks.update({UserId: everUserId}, {$set: {UserId: me.userId, IsDirty: true, ServerNotebookId: '', LocalIsNew: true}}, {multi: true}, function () {
							console.log('notebooks 数据更新成功');
						});
						db.tags.update({UserId: everUserId}, {$set: {UserId: me.userId, IsDirty: true}}, {multi: true}, function () {
							console.log('tags 数据更新成功');
						});

						db.attachs.update({UserId: everUserId}, {$set: {UserId: me.userId, ServerFileId: '', IsDirty: true}}, {multi: true}, function () {
							console.log('attachs 数据更新成功');
						});

						dbClient.images.update({UserId: everUserId}, {$set: {UserId: me.userId, ServerFileId: '', IsDirty: true}}, {multi: true}, function () {
							console.log('images 数据更新成功');
						});
					}
				});
Beispiel #2
0
	updateNotebookTitle: function(notebookId, title, callback) {
		db.notebooks.update({NotebookId: notebookId}, 
			{$set: 
				{Title: title, IsDirty: true, UpdatedTime: new Date()}
			}, function(err, n) {
			callback(true);
		});
	},
Beispiel #3
0
			}, function(err, count) {
			if(err) {
				log(err);
				return;
			}
			Web.updateNotebookNumberNotes(notebookId, count);
			db.notebooks.update({NotebookId: notebookId}, {$set: {NumberNotes: count}}, {})
		});
Beispiel #4
0
		Note.hasNotes(notebookId, function(has) {
			if(has) {
				callback(false, 'This notebook has notes, please delete notes firstly.');
			} else {
				db.notebooks.update({NotebookId: notebookId}, {$set: {LocalIsDelete: true, IsDirty: true, UpdatedTime: new Date()}}, function(err, n) {
					callback(true);
				});
			}
		});
Beispiel #5
0
	deleteNotebookForce: function(notebookId, callback) {
		var me = this;
		db.notebooks.remove({ServerNotebookId: notebookId}, function(err, n) {
			if(err) { 
				callback && callback(false);
			} else {
				callback && callback(true);
			}
		});
	},
Beispiel #6
0
	getServerNotebookIdByNotebookId: function(notebookId, callback) {
		if(!notebookId) {
			return callback(false);
		}
		db.notebooks.findOne({NotebookId: notebookId}, function(err, notebook) {
			if(err || !notebook) {
				return callback(false);
			}
			callback(notebook.ServerNotebookId);
		});
	},
Beispiel #7
0
	getNotebookIdByServerNotebookId: function(serverNotebookId, callback) {
		if(!serverNotebookId) {
			return callback(false);
		}
		db.notebooks.findOne({ServerNotebookId: serverNotebookId}, function(err, notebook) {
			if(err || !notebook) {
				return callback(false);
			}
			callback(notebook.NotebookId);
		});
	},
Beispiel #8
0
	getNotebookByServerNotebookId: function(notebookId, callback) {
		var me = this;
		db.notebooks.findOne({ServerNotebookId: notebookId}, function(err, doc) {
			if(err || !doc) {
				log('不存在');
				callback && callback(false);
			} else {
				callback && callback(doc);
			}
		});
	},
Beispiel #9
0
	getNotebooks: function(callback) {
		var me = this;
		var userId = User.getCurActiveUserId();
		db.notebooks.find({UserId: userId, $or: [{LocalIsDelete : { $exists : false }}, {LocalIsDelete: false}] }, function(err, notebooks) {
			if(err) {
				log(err);
				return callback && callback(false);
			}
			
			callback && callback(me._mapNotebooks(notebooks));
		});
	},
Beispiel #10
0
		me.getNotebookIdByServerNotebookId(notebook.ParentNotebookId, function(parentNotebookId) {
			notebook.ParentNotebookId = parentNotebookId;
			notebook.ServerNotebookId = notebook.NotebookId;
			notebook.NotebookId = notebookLocal.NotebookId;
			db.notebooks.update({ServerNotebookId: serverNotebookId}, {$set: notebook}, {}, function (err, updates) {   // Callback is optional
				if(err) {
					console.log(err);
					callback && callback(false);
				} else {
					callback && callback(notebook);
				}
			});
		});
Beispiel #11
0
		me.getNotebookIdByServerNotebookId(notebook.ParentNotebookId, function(parentNotebookId) {
			notebook.ParentNotebookId = parentNotebookId;
			// console.log(notebook2);
			// notebook2.Title  += " H-";
			// multi, 因为历史原因, 导致大量重复notebookId的元素
			db.notebooks.update({NotebookId: notebookId}, {$set: notebook}, {multi: true}, function (err, n) {
				// console.log('updateNotebookForceForSendChange end' + notebookId + ' ' + n);
				if(err) {
					console.log(err);
					callback && callback(false);
				} else {
					callback && callback(notebook);
				}
			});
		});
Beispiel #12
0
	getDirtyNotebooks: function(callback) {
		var me = this;
		db.notebooks.find({UserId: User.getCurActiveUserId(), IsDirty: true}, function(err, notebooks) {
			if(err) {
				log(err);
				return callback && callback(false);
			} else {
				var mapNotebooks = me._mapNotebooks(notebooks);
				// 深度优先一个序列
				me._deepTraversal = [];
				me._visited = {};
				me.deep({Subs: mapNotebooks});
				// 返回之
				callback(me._deepTraversal);
			}
		});
	},
Beispiel #13
0
	addNotebookTest: function() {
		var doc = {
			// _id: "xxxxx",
			hello: 'world'
		   , n: 5
		   , today: new Date()
		   , nedbIsAwesome: true
		   , notthere: null
		   , notToBeSaved: undefined  // Will not be saved
		   , fruits: [ 'apple', 'orange', 'pear' ]
		   , infos: { name: 'nedb' }
		   };
		console.log("save before")
		db.notebooks.insert(doc, function (err, newDoc) {   // Callback is optional
		  // newDoc is the newly inserted document, including its _id
		  // newDoc has no key called notToBeSaved since its value was undefined
		  // console.log(err);
		  // console.log(newDoc);
		});
	},
Beispiel #14
0
		me.getNotebook(curNotebookId, function(notebook) {
			if(!notebook) {
				console.log('not fount');
				return;
			}
			// 先更新之
			// db.notebooks.update({NotebookId: notebookId}, {$set: {ParentNotebookId: parentNotebookId, IsDirty: true, UpdatedTime: new Date()}}, function(err, n) {
			// });
			siblingNotebookIds = siblingNotebookIds || [];
			// 再更新所有子孩子的seq
			for(var i = 0; i < siblingNotebookIds.length; ++i) {
				var siblingNotebookId = siblingNotebookIds[i];
				console.log('siblingNotebookId: ' + siblingNotebookId);
				db.notebooks.update({NotebookId: siblingNotebookId}, 
					{$set: 
						{ParentNotebookId: parentNotebookId, Seq: i, IsDirty: true, UpdatedTime: new Date()}
					}
				);
			}
		});
Beispiel #15
0
	addNotebook: function(notebookId, title, parentNotebookId, callback) {
		var notebook = {
			Title: title,
			Seq: -1,
			UserId: User.getCurActiveUserId(),
			ParentNotebookId: parentNotebookId,
			LocalIsNew: true,
			IsDirty: true, // 必须, 同步后才为非dirty状态
			// TODO UrlTitle
		}
		if(notebookId) {
			notebook['NotebookId'] = notebookId;
		}
		db.notebooks.insert(notebook, function (err, newDoc) {   // Callback is optional
			if(err) {
				console.log(err);
				callback && callback(false);
			} else {
				callback && callback(newDoc);
			}
		});
	},
Beispiel #16
0
		me.getNotebookIdByServerNotebookId(notebook.ParentNotebookId, function(parentNotebookId) {
			// 如果是第一次添加可能会有问题, 数据库还没有数据, 那么还找不到
			if(parentNotebookId) {
				notebook.ParentNotebookId = parentNotebookId;
			} else {
				// 否则, 就用服务器上的
			}

			notebook.CreatedTime = Common.goNowToDate(notebook.CreatedTime);
			notebook.UpdatedTime = Common.goNowToDate(notebook.UpdatedTime);

			notebook.IsDirty = false;
			notebook.LocalIsNew = false;
			notebook.LocalIsDelete = false;

			db.notebooks.insert(notebook, function (err, newDoc) {   // Callback is optional
				if(err) {
					console.log(err);
					callback && callback(false);
				} else {
					callback && callback(newDoc);
				}
			});
		});
Beispiel #17
0
	setIsNew: function(notebookId) {
		db.notebooks.update({NotebookId: notebookId}, {$set:{LocalIsNew: true, IsDirty: true}})
	}
Beispiel #18
0
	setNotDirtyNotDelete: function(notebookId) {
		db.notebooks.update({NotebookId: notebookId}, {$set:{IsDirty: false, LocalIsDelete: false}})
	},
Beispiel #19
0
	deleteLocalNotebook: function(notebookId, callback) {
		db.notebooks.remove({NotebookId: notebookId}, function(err, n) {
			callback && callback();
		});
	},