mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-14 15:11:24 +00:00
move & copy note [ok]
This commit is contained in:
89
node_modules/note.js
generated
vendored
89
node_modules/note.js
generated
vendored
@@ -186,6 +186,27 @@ var Note = {
|
||||
});
|
||||
},
|
||||
|
||||
// 移动note
|
||||
// 重新统计另一个notebookId的笔记数
|
||||
moveNote: function(noteId, notebookId, callback) {
|
||||
var me = this;
|
||||
me.getNote(noteId, function(note) {
|
||||
if(note) {
|
||||
var to = !note.Star;
|
||||
var preNotebookId = note.NotebookId;
|
||||
note.NotebookId = notebookId;
|
||||
Notes.update({_id: note._id}, {$set: {NotebookId: notebookId, IsTrash: false, LocalIsDelete: false, UpdatedTime: new Date()}}, function(err, n) {
|
||||
// 重新统计
|
||||
Notebook.reCountNotebookNumberNotes(preNotebookId);
|
||||
Notebook.reCountNotebookNumberNotes(notebookId);
|
||||
callback(note);
|
||||
});
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 加星或取消
|
||||
star: function(noteId, callback) {
|
||||
var me = this;
|
||||
@@ -637,6 +658,7 @@ var Note = {
|
||||
note.IsDirty = true;
|
||||
note.LocalIsNew = true; // 新增加的
|
||||
note.InitSync = false; // 都是本地的, 相当于新建的笔记
|
||||
note.LocalIsDelete = false;
|
||||
|
||||
// 只复制有path的
|
||||
var attachs = note.Attachs || [];
|
||||
@@ -677,8 +699,75 @@ var Note = {
|
||||
Notes.insert(note, function(err, newNote) {
|
||||
if(err) {
|
||||
callback(false);
|
||||
|
||||
} else {
|
||||
callback(newNote);
|
||||
// 重新统计笔记本的笔记数量
|
||||
Notebook.reCountNotebookNumberNotes(newNote.NotebookId);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 复制笔记到某笔记本下, 本地使用
|
||||
copyNote: function(noteId, notebookId, callback) {
|
||||
var me = this;
|
||||
me.getNote(noteId, function(note) {
|
||||
if(!note) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
// 新Id
|
||||
delete note['_id'];
|
||||
delete note['ServerNoteId'];
|
||||
note.NoteId = Common.objectId();
|
||||
note.IsDirty = true;
|
||||
note.LocalIsNew = true; // 新增加的
|
||||
note.InitSync = false; // 都是本地的, 相当于新建的笔记
|
||||
note.LocalIsDelete = false;
|
||||
note.IsTrash = false;
|
||||
note.NotebookId = notebookId;
|
||||
|
||||
// 只复制有path的
|
||||
var attachs = note.Attachs || [];
|
||||
var newAttachs = [];
|
||||
async.eachSeries(attachs, function(attach, cb) {
|
||||
if(!attach.Path) {
|
||||
return cb();
|
||||
}
|
||||
// 新路径
|
||||
var filePathAttr = Common.splitFile(attach.Path);
|
||||
filePathAttr.nameNotExt += '_cp_' + attach.FileId; // 另一个
|
||||
var newPath = filePathAttr.getFullPath();
|
||||
// 复制之
|
||||
// try {
|
||||
Common.copyFile(attach.Path, newPath, function(ret) {
|
||||
if(ret) {
|
||||
attach.FileId = Common.objectId();
|
||||
attach.IsDirty = true;
|
||||
attach.Path = newPath;
|
||||
delete attach['ServerFileId'];
|
||||
newAttachs.push(attach);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
/*
|
||||
} catch(e) {
|
||||
cb();
|
||||
}
|
||||
*/
|
||||
}, function() {
|
||||
note.Attachs = newAttachs;
|
||||
console.log('conflict 复制后的');
|
||||
console.log(note.Attachs);
|
||||
Notes.insert(note, function(err, newNote) {
|
||||
if(err) {
|
||||
callback(false);
|
||||
} else {
|
||||
callback(newNote);
|
||||
// 重新统计下
|
||||
Notebook.reCountNotebookNumberNotes(newNote.NotebookId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
2
node_modules/notebook.js
generated
vendored
2
node_modules/notebook.js
generated
vendored
@@ -185,7 +185,7 @@ var Notebook = {
|
||||
|
||||
// 重新统计笔记本的笔记数据
|
||||
reCountNotebookNumberNotes: function(notebookId) {
|
||||
db.notes.count({NotebookId: notebookId, IsTrash: false}, function(err, count) {
|
||||
db.notes.count({NotebookId: notebookId, IsTrash: false, LocalIsDelete: false}, function(err, count) {
|
||||
if(err) {
|
||||
log(err);
|
||||
return;
|
||||
|
@@ -1407,8 +1407,10 @@ Note.moveNote = function(target, data) {
|
||||
if(!note.IsTrash) {
|
||||
Notebook.minusNotebookNumberNotes(note.NotebookId);
|
||||
}
|
||||
|
||||
ajaxGet("/note/moveNote", {noteId: noteId, notebookId: notebookId}, function(ret) {
|
||||
|
||||
NoteService.moveNote(noteId, notebookId, function(ret) {
|
||||
// });
|
||||
// ajaxGet("/note/moveNote", {noteId: noteId, notebookId: notebookId}, function(ret) {
|
||||
if(ret && ret.NoteId) {
|
||||
if(note.IsTrash) {
|
||||
Note.changeToNext(target);
|
||||
@@ -1452,24 +1454,29 @@ Note.copyNote = function(target, data, isShared) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
var url = "/note/copyNote";
|
||||
var data = {noteId: noteId, notebookId: notebookId};
|
||||
if(isShared) {
|
||||
url = "/note/copySharedNote";
|
||||
data.fromUserId = note.UserId;
|
||||
}
|
||||
*/
|
||||
|
||||
ajaxGet(url, data, function(ret) {
|
||||
if(ret && ret.NoteId) {
|
||||
NoteService.copyNote(noteId, notebookId, function(newNote) {
|
||||
if(newNote && newNote.NoteId) {
|
||||
// 重新清空cache 之后的
|
||||
Note.clearCacheByNotebookId(notebookId);
|
||||
// 改变缓存, 添加之
|
||||
Note.setNoteCache(ret)
|
||||
Note.setNoteCache(newNote)
|
||||
|
||||
// 增加数量
|
||||
Notebook.incrNotebookNumberNotes(notebookId)
|
||||
} else {
|
||||
alert('error');
|
||||
}
|
||||
});
|
||||
|
||||
// 增加数量
|
||||
Notebook.incrNotebookNumberNotes(notebookId)
|
||||
};
|
||||
|
||||
|
||||
@@ -1633,21 +1640,21 @@ Note.initContextmenu = function() {
|
||||
var noteListMenu = {
|
||||
width: 180,
|
||||
items: [
|
||||
{ text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo},
|
||||
{ type: "splitLine" },
|
||||
{ text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Note.setNote2Blog },
|
||||
{ text: getMsg("cancelPublic"), alias: 'unset2Blog', faIcon: "fa-undo", action: Note.setNote2Blog },
|
||||
// { text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Note.listNoteShareUserInfo},
|
||||
// { type: "splitLine" },
|
||||
// { text: getMsg("publicAsBlog"), alias: 'set2Blog', faIcon: "fa-bold", action: Note.setNote2Blog },
|
||||
// { text: getMsg("cancelPublic"), alias: 'unset2Blog', faIcon: "fa-undo", action: Note.setNote2Blog },
|
||||
// { type: "splitLine" },
|
||||
// { text: "分享到社区", alias: 'html2Image', icon: "", action: Note.html2Image},
|
||||
// { text: "导出PDF", alias: 'exportPDF', icon: "", action: Note.exportPDF},
|
||||
{ type: "splitLine" },
|
||||
{ text: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
|
||||
{ text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right",
|
||||
// { type: "splitLine" },
|
||||
{text: getMsg("delete"), icon: "", faIcon: "fa-trash-o", action: Note.deleteNote },
|
||||
{text: getMsg("move"), alias: "move", faIcon: "fa-arrow-right",
|
||||
type: "group",
|
||||
width: 180,
|
||||
items: notebooksMove
|
||||
},
|
||||
{ text: getMsg("copy"), alias: "copy", icon:"", faIcon: "fa-copy",
|
||||
{text: getMsg("copy"), alias: "copy", icon:"", faIcon: "fa-copy",
|
||||
type: "group",
|
||||
width: 180,
|
||||
items: notebooksCopy
|
||||
|
@@ -26,7 +26,7 @@
|
||||
}
|
||||
.b-m-idisable
|
||||
{
|
||||
color:#808080;
|
||||
color:#ccc;
|
||||
}
|
||||
.b-m-ibody, .b-m-arrow {
|
||||
overflow: hidden;
|
||||
|
Reference in New Issue
Block a user