note history

This commit is contained in:
life
2015-02-21 22:24:58 +08:00
parent a59c2fcadd
commit 4adb336b93
3 changed files with 77 additions and 21 deletions

2
node_modules/db.js generated vendored
View File

@@ -5,7 +5,7 @@ var path = require('path');
// var dbPath = require('nw.gui').App.dataPath + '/nedb'
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb';
var db = {};
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs'];
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs', 'noteHistories'];
for(var i in dbNames) {
var name = dbNames[i];
db[name] = new Datastore({ filename: path.join(dbPath, name + '.db'), autoload: true });

84
node_modules/note.js generated vendored
View File

@@ -19,27 +19,29 @@ function log(o) {
console.log(o);
}
/*
type NoteOrContent struct {
NotebookId string
NoteId string
UserId string
Title string
Desc string
ImgSrc string
Tags []string
Content string
Abstract string
IsNew bool
IsMarkdown bool
FromUserId string // 为共享而新建
IsBlog bool // 是否是blog, 更新note不需要修改, 添加note时才有可能用到, 此时需要判断notebook是否设为Blog
}
*/
// 笔记服务
var Note = {
/*
type NoteOrContent struct {
NotebookId string
NoteId string
UserId string
Title string
Desc string
ImgSrc string
Tags []string
Content string
Abstract string
IsNew bool
IsMarkdown bool
FromUserId string // 为共享而新建
IsBlog bool // 是否是blog, 更新note不需要修改, 添加note时才有可能用到, 此时需要判断notebook是否设为Blog
}
*/
// 更新笔记
updateNoteOrContent: function(noteOrContent, callback) {
var me = this;
var userId = User.getCurActiveUserId();
noteOrContent['UserId'] = userId;
console.log('updateNoteOrContent: ' + noteOrContent.NoteId);
@@ -66,6 +68,9 @@ var Note = {
// 重新统计笔记本的笔记数量
Notebook.reCountNotebookNumberNotes(noteOrContent.NotebookId);
me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content);
/*
// 标签
if(noteOrContent.Tags && noteOrContent.Tags.length > 0) {
@@ -100,12 +105,57 @@ var Note = {
callback && callback(false);
} else {
callback && callback(noteOrContent);
if('Content' in updates) {
me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content);
}
}
});
}
}
},
// 添加笔记历史
/*
type NoteContentHistory struct {
NoteId bson.ObjectId `bson:"_id,omitempty"`
UserId bson.ObjectId `bson:"UserId"` // 所属者
Histories []EachHistory `Histories`
}
*/
addNoteHistory: function(noteId, content) {
var me = this;
// 先判断是否存在, 不存在则新建之
db.noteHistories.findOne({_id: noteId}, function(err, history) {
// 新建之
if(!history) {
db.noteHistories.insert({_id: noteId, Histories: [content]});
}
// 更新之
else {
var histories = history.Histories;
histories.push(content);
db.noteHistories.update({_id: noteId}, {$set: {Histories: histories}});
}
});
},
// 获取笔记历史记录
getNoteHistories: function(noteId, callback) {
var me = this;
db.noteHistories.findOne({_id: noteId}, function(err, doc) {
if(err || !doc) {
callback(false);
}
else {
var histories = [];
for(var i = doc.Histories.length - 1; i >= 0; --i) {
histories.push({Content: doc.Histories[i]});
}
callback(histories);
}
});
},
// 获取笔记列表
getNotes: function(notebookId, callback) {
var me = this;