mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-14 15:11:24 +00:00
仅保存20条记录, ctrl+s, ctrl+e时保存历史记录. 自动保存时不添加到历史记录中
https://github.com/leanote/desktop-app/issues/70
This commit is contained in:
27
node_modules/note.js
generated
vendored
27
node_modules/note.js
generated
vendored
@@ -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 = [];
|
||||
|
@@ -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() {
|
||||
|
@@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
|
@@ -291,5 +291,7 @@
|
||||
"<span></span> notes selected": "当前选中了 <span></span> 篇笔记",
|
||||
|
||||
"Sync error, retry to sync after 3 seconds": "同步失败, 3 秒后自动重新尝试同步",
|
||||
"Network error!": "网络异常"
|
||||
"Network error!": "网络异常",
|
||||
|
||||
"Load Database Error": "加载数据库出错, 请尝试在帐户管理中优化数据库"
|
||||
}
|
@@ -291,5 +291,7 @@
|
||||
"<span></span> notes selected": "當前選中了 <span></span> 篇筆記",
|
||||
|
||||
"Sync error, retry to sync after 3 seconds": "同步失敗, 3 秒後自動重新嘗試同步",
|
||||
"Network error!": "網絡異常"
|
||||
"Network error!": "網絡異常",
|
||||
|
||||
"Load Database Error": "加載數據庫出錯, 請嘗試在帳戶管理中優化數據庫"
|
||||
}
|
Reference in New Issue
Block a user