mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-16 16:04:56 +00:00
note history
This commit is contained in:
2
node_modules/db.js
generated
vendored
2
node_modules/db.js
generated
vendored
@@ -5,7 +5,7 @@ var path = require('path');
|
|||||||
// var dbPath = require('nw.gui').App.dataPath + '/nedb'
|
// var dbPath = require('nw.gui').App.dataPath + '/nedb'
|
||||||
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb';
|
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb';
|
||||||
var db = {};
|
var db = {};
|
||||||
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs'];
|
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs', 'noteHistories'];
|
||||||
for(var i in dbNames) {
|
for(var i in dbNames) {
|
||||||
var name = dbNames[i];
|
var name = dbNames[i];
|
||||||
db[name] = new Datastore({ filename: path.join(dbPath, name + '.db'), autoload: true });
|
db[name] = new Datastore({ filename: path.join(dbPath, name + '.db'), autoload: true });
|
||||||
|
84
node_modules/note.js
generated
vendored
84
node_modules/note.js
generated
vendored
@@ -19,27 +19,29 @@ function log(o) {
|
|||||||
console.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 = {
|
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) {
|
updateNoteOrContent: function(noteOrContent, callback) {
|
||||||
|
var me = this;
|
||||||
var userId = User.getCurActiveUserId();
|
var userId = User.getCurActiveUserId();
|
||||||
noteOrContent['UserId'] = userId;
|
noteOrContent['UserId'] = userId;
|
||||||
console.log('updateNoteOrContent: ' + noteOrContent.NoteId);
|
console.log('updateNoteOrContent: ' + noteOrContent.NoteId);
|
||||||
@@ -66,6 +68,9 @@ var Note = {
|
|||||||
|
|
||||||
// 重新统计笔记本的笔记数量
|
// 重新统计笔记本的笔记数量
|
||||||
Notebook.reCountNotebookNumberNotes(noteOrContent.NotebookId);
|
Notebook.reCountNotebookNumberNotes(noteOrContent.NotebookId);
|
||||||
|
|
||||||
|
me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// 标签
|
// 标签
|
||||||
if(noteOrContent.Tags && noteOrContent.Tags.length > 0) {
|
if(noteOrContent.Tags && noteOrContent.Tags.length > 0) {
|
||||||
@@ -100,12 +105,57 @@ var Note = {
|
|||||||
callback && callback(false);
|
callback && callback(false);
|
||||||
} else {
|
} else {
|
||||||
callback && callback(noteOrContent);
|
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) {
|
getNotes: function(notebookId, callback) {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
@@ -1208,10 +1208,16 @@ Note.listNoteContentHistories = function() {
|
|||||||
options.show = true;
|
options.show = true;
|
||||||
$("#leanoteDialog").modal(options);
|
$("#leanoteDialog").modal(options);
|
||||||
|
|
||||||
ajaxGet("/noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) {
|
NoteService.getNoteHistories(Note.curNoteId, function(re) {
|
||||||
if(!isArray(re)) {$content.html(getMsg("noHistories")); return}
|
// console.log("histories.....");
|
||||||
|
// console.log(re);
|
||||||
|
// });
|
||||||
|
// ajaxGet("/noteContentHistory/listHistories", {noteId: Note.curNoteId}, function(re) {
|
||||||
|
if(!isArray(re)) {
|
||||||
|
$content.html(getMsg("noHistories")); return;
|
||||||
|
}
|
||||||
// 组装成一个tab
|
// 组装成一个tab
|
||||||
var str = "<p>" + getMsg("historiesNum") + '</p><div id="historyList"><table class="table table-hover">';
|
var str = /*"<p>" + getMsg("historiesNum") + '</p>' + */'<div id="historyList"><table class="table table-hover">';
|
||||||
note = Note.cache[Note.curNoteId];
|
note = Note.cache[Note.curNoteId];
|
||||||
var s = "div"
|
var s = "div"
|
||||||
if(note.IsMarkdown) {
|
if(note.IsMarkdown) {
|
||||||
|
Reference in New Issue
Block a user