mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-17 16:45:21 +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 = [];
|
||||
|
Reference in New Issue
Block a user