From 0f881c8e77e1fe6c05a66e44e9e7595ec7cf12d9 Mon Sep 17 00:00:00 2001 From: life Date: Tue, 24 Nov 2015 10:42:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E4=BF=9D=E5=AD=9820=E6=9D=A1=E8=AE=B0?= =?UTF-8?q?=E5=BD=95,=20ctrl+s,=20ctrl+e=E6=97=B6=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95.=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=97=B6=E4=B8=8D=E6=B7=BB=E5=8A=A0=E5=88=B0?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/leanote/desktop-app/issues/70 --- node_modules/note.js | 27 +++++++++++++++++++++------ public/js/app/note.js | 9 ++++----- public/js/dec/history.js | 8 +++++--- public/langs/zh-cn.js | 4 +++- public/langs/zh-hk.js | 4 +++- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/node_modules/note.js b/node_modules/note.js index 7f7218d2..f99cc49c 100644 --- a/node_modules/note.js +++ b/node_modules/note.js @@ -43,7 +43,7 @@ type NoteOrContent struct { // 笔记服务 var Note = { // 更新笔记 - updateNoteOrContent: function(noteOrContent, callback) { + updateNoteOrContent: function(noteOrContent, callback, needAddToHistory) { var me = this; // Web.alertWeb(process.type); // render @@ -153,7 +153,11 @@ var Note = { callback && callback(noteOrContent); if('Content' in updates) { - me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content); + + // 需要添加到历史记录中才加 + if (needAddToHistory) { + me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content); + } } } }); @@ -207,18 +211,29 @@ var Note = { addNoteHistory: function(noteId, content) { var me = this; db.noteHistories.loadDB(function (ok) { + if (!ok) { + return; + } // 先判断是否存在, 不存在则新建之 db.noteHistories.findOne({_id: noteId}, function(err, history) { + var now = new Date(); // 新建之 if(!history) { - db.noteHistories.insert({_id: noteId, Histories: [content], "UpdatedTime": new Date()}); + db.noteHistories.insert({_id: noteId, Histories: [{Content: content, "UpdatedTime": now}], "UpdatedTime": now}); } // 更新之 else { var histories = history.Histories; - histories.push({Content: content, UpdatedTime: new Date()}); + histories.push({Content: content, UpdatedTime: now}); - // 不能多了, 多了有麻烦 + // 不能多了, 多了有麻烦, 20个最多 + var max = 20; + var len = histories.length; + if (len > max) { + for (var i = 0; i < len - max; ++i) { + histories.shift(); + } + } db.noteHistories.update({_id: noteId}, {$set: {Histories: histories}}); } @@ -241,7 +256,7 @@ var Note = { } db.noteHistories.findOne({_id: noteId}, function(err, doc) { if(err || !doc) { - callback(false); + callback([]); } else { var histories = []; diff --git a/public/js/app/note.js b/public/js/app/note.js index 4a048dbf..3df10f1f 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -499,7 +499,7 @@ Note.curChangedSaveIt = function(force, callback) { } callback && callback(ret); - }); + }, force); return hasChanged; @@ -676,7 +676,7 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) { needSaveChanged = true; } if(needSaveChanged) { - Note.curChangedSaveIt(); + Note.curChangedSaveIt(true); } // 2. 设空, 防止在内容得到之前又发生保存 @@ -1095,7 +1095,7 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) { Note.stopInterval(); // 保存当前的笔记 - Note.curChangedSaveIt(); + Note.curChangedSaveIt(true); Note.batch.reset(); @@ -1789,13 +1789,12 @@ Note.toggleReadOnly = function(needSave) { // 保存之 if (needSave) { - Note.curChangedSaveIt(); + Note.curChangedSaveIt(true); } Note.readOnly = true; LEA.readOnly = true; - if(!note.IsMarkdown) { // 里面的pre也设为不可写 $('#editorContent pre').each(function() { diff --git a/public/js/dec/history.js b/public/js/dec/history.js index 19c370fd..ebe16537 100644 --- a/public/js/dec/history.js +++ b/public/js/dec/history.js @@ -115,7 +115,11 @@ define(function() { var note = Note.getCurNote(); me.note = note; NoteService.getNoteHistories(Note.curNoteId, function(re) { - if(!isArray(re)) { + if (re === false) { + alert(getMsg('Load Database Error')); + return; + } + if(!isArray(re) || !re.length) { alert(getMsg('noHistories')); return; } @@ -154,8 +158,6 @@ define(function() { info.unfold = false } }); - - }); }, diff --git a/public/langs/zh-cn.js b/public/langs/zh-cn.js index eed852a9..64ea97b0 100644 --- a/public/langs/zh-cn.js +++ b/public/langs/zh-cn.js @@ -291,5 +291,7 @@ " notes selected": "当前选中了 篇笔记", "Sync error, retry to sync after 3 seconds": "同步失败, 3 秒后自动重新尝试同步", - "Network error!": "网络异常" + "Network error!": "网络异常", + + "Load Database Error": "加载数据库出错, 请尝试在帐户管理中优化数据库" } \ No newline at end of file diff --git a/public/langs/zh-hk.js b/public/langs/zh-hk.js index 486dce54..0fa9ec80 100644 --- a/public/langs/zh-hk.js +++ b/public/langs/zh-hk.js @@ -291,5 +291,7 @@ " notes selected": "當前選中了 篇筆記", "Sync error, retry to sync after 3 seconds": "同步失敗, 3 秒後自動重新嘗試同步", - "Network error!": "網絡異常" + "Network error!": "網絡異常", + + "Load Database Error": "加載數據庫出錯, 請嘗試在帳戶管理中優化數據庫" } \ No newline at end of file