diff --git a/node_modules/db.js b/node_modules/db.js index 06580d22..01fcab3e 100644 --- a/node_modules/db.js +++ b/node_modules/db.js @@ -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 }); diff --git a/node_modules/note.js b/node_modules/note.js index b0a13930..2ea7532a 100644 --- a/node_modules/note.js +++ b/node_modules/note.js @@ -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; diff --git a/public/js/app/note.js b/public/js/app/note.js index d6f02ced..c63825b7 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -1208,10 +1208,16 @@ Note.listNoteContentHistories = function() { options.show = true; $("#leanoteDialog").modal(options); - ajaxGet("/noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) { - if(!isArray(re)) {$content.html(getMsg("noHistories")); return} + NoteService.getNoteHistories(Note.curNoteId, function(re) { + // console.log("histories....."); + // console.log(re); + // }); + // ajaxGet("/noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) { + if(!isArray(re)) { + $content.html(getMsg("noHistories")); return; + } // 组装成一个tab - var str = "
" + getMsg("historiesNum") + '