This commit is contained in:
life
2015-02-27 22:29:38 +08:00
parent 3a179380db
commit 6df80d2fed
12 changed files with 45413 additions and 100 deletions

5
node_modules/api.js generated vendored
View File

@@ -466,7 +466,7 @@ var Api = {
// noteId是serverNoteId // noteId是serverNoteId
getNote: function(noteId, callback) { getNote: function(noteId, callback) {
var me = this; var me = this;
needle.get(this.getUrl('note/getNote', {NoteId: noteId}), function(error, response) { needle.get(me.getUrl('note/getNote', {noteId: noteId}), function(error, response) {
me.checkError(error, response); me.checkError(error, response);
if(error) { if(error) {
return callback && callback(false); return callback && callback(false);
@@ -475,7 +475,8 @@ var Api = {
if(Common.isOk(ret)) { if(Common.isOk(ret)) {
callback && callback(ret); callback && callback(ret);
} else { } else {
log(error); console.error(error);
console.log(me.getUrl('note/getNote', {noteId: noteId}));
callback && callback(false); callback && callback(false);
} }
}); });

10
node_modules/db.js generated vendored
View File

@@ -6,8 +6,14 @@ var Evt = require('evt');
// var dbPath = require('nw.gui').App.dataPath + '/nedb'; // var dbPath = require('nw.gui').App.dataPath + '/nedb';
// var dbPath = Evt.getBasePath() + '/Users/life/Library/Application Support/Leanote' + '/nedb'; // var dbPath = Evt.getBasePath() + '/Users/life/Library/Application Support/Leanote' + '/nedb';
var dbPath = Evt.getBasePath() + '/nedb'; var dbPath = Evt.getBasePath() + '/nedb';
console.log(",,,,,,,,,,,,,");
console.log(dbPath); // test
if(dbPath.length < 6) {
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb';
}
// console.log(",,,,,,,,,,,,,");
// console.log(dbPath);
var db = {}; var db = {};
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs', 'noteHistories']; var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs', 'noteHistories'];
for(var i in dbNames) { for(var i in dbNames) {

74
node_modules/note.js generated vendored
View File

@@ -44,7 +44,8 @@ var Note = {
var me = this; 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: ');
console.log(noteOrContent);
var date = new Date(); var date = new Date();
noteOrContent.UpdatedTime = date; noteOrContent.UpdatedTime = date;
@@ -394,7 +395,7 @@ var Note = {
inSyncContent: {}, // 正在同步中的 inSyncContent: {}, // 正在同步中的
getNoteContent: function(noteId, callback) { getNoteContent: function(noteId, callback) {
var me = this; var me = this;
log('getNoteContent------') console.log('getNoteContent------')
// 如果是正在sync的话, 返回 // 如果是正在sync的话, 返回
if(me.inSyncContent[noteId]) { if(me.inSyncContent[noteId]) {
return; return;
@@ -620,10 +621,10 @@ var Note = {
console.log(err); console.log(err);
console.log(cnt); console.log(cnt);
if(err) { if(err) {
console.log(err); console.error(err);
callback && callback(false); callback && callback(false);
} else { } else {
log('强制更新...'); console.log('强制更新...');
callback && callback(note); callback && callback(note);
// 下载内容, 图片, 附件 // 下载内容, 图片, 附件
@@ -875,8 +876,8 @@ var Note = {
var me = this; var me = this;
var conflictNotes = noteSyncInfo.conflicts; var conflictNotes = noteSyncInfo.conflicts;
log('fix note conflicts'); console.log('fix note conflicts');
log(conflictNotes); console.log(conflictNotes);
// 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes // 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes
if(conflictNotes) { if(conflictNotes) {
async.eachSeries(conflictNotes, function(note, cb) { // note是服务器上最新的, note.NoteId, ServerNoteId已转换 async.eachSeries(conflictNotes, function(note, cb) { // note是服务器上最新的, note.NoteId, ServerNoteId已转换
@@ -911,35 +912,43 @@ var Note = {
console.log('changeConflicts'); console.log('changeConflicts');
console.log(changeConflicts); console.log(changeConflicts);
for(var i in changeConflicts) { for(var i in changeConflicts) {
var note = changeConflicts[i]; // note是本地的note (function(i) {
// 复制一份
me.copyNoteForConfict(note.NoteId, function(newNote) { var note = changeConflicts[i]; // note是本地的note
if(newNote) { // 复制一份
// 更新之前的, 要先从服务器上得到服务版的 me.copyNoteForConfict(note.NoteId, function(newNote) {
// 这里的note是本地的, 所以将服务器上的覆盖它 if(newNote) {
if(!Api) { // 更新之前的, 要先从服务器上得到服务版的
Api = require('api'); // 这里的note是本地的, 所以将服务器上的覆盖它
} if(!Api) {
Api.getNote(note.ServerNoteId, function(serverNote) { Api = require('api');
serverNote.ServerNoteId = serverNote.NoteId; }
serverNote.NoteId = note.NoteId; Api.getNote(note.ServerNoteId, function(serverNote) {
me.updateNoteForceForConflict(serverNote, function(note2) { serverNote.ServerNoteId = serverNote.NoteId;
if(!note2) { serverNote.NoteId = note.NoteId;
// 前端来处理, 全量sync时不用前端一个个处理 console.error("changeConflicts -> get note from server");
Web.fixSyncConflict(note2, newNote); console.log(serverNote);
} console.log(note);
me.updateNoteForceForConflict(serverNote, function(note2) {
if(!note2) {
// 前端来处理, 全量sync时不用前端一个个处理
Web.fixSyncConflict(note2, newNote);
}
});
}); });
}); } else {
} else { }
} });
});
})(i);
} }
// 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes // 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes
if(noteSyncInfo.changeNeedAdds) { if(noteSyncInfo.changeNeedAdds) {
var needAddNotes = noteSyncInfo.changeNeedAdds; var needAddNotes = noteSyncInfo.changeNeedAdds;
for(var i in needAddNotes) { for(var i in needAddNotes) {
log('need add '); console.log('need add ');
var note = needAddNotes[i]; var note = needAddNotes[i];
me.setIsNew(note.NoteId); me.setIsNew(note.NoteId);
} }
@@ -947,13 +956,12 @@ var Note = {
// 处理添加的 // 处理添加的
var addNotes = noteSyncInfo.adds; var addNotes = noteSyncInfo.adds;
log('has add...'); console.log('has add...');
log(addNotes); console.log(addNotes);
Web.addSyncNote(addNotes); Web.addSyncNote(addNotes);
log('has updates...'); console.log('has updates...');
log(noteSyncInfo); console.log(noteSyncInfo.updates);
log(noteSyncInfo.updates);
// 处理更新的 // 处理更新的
Web.updateSyncNote(noteSyncInfo.updates); Web.updateSyncNote(noteSyncInfo.updates);

23
node_modules/sync.js generated vendored
View File

@@ -557,7 +557,7 @@ var Sync = {
User.getLastSyncState(function(lastSyncUsn, lastSyncTime) { User.getLastSyncState(function(lastSyncUsn, lastSyncTime) {
// 没有上次同步的时间, 则需要进行一次全量同步, 不可能会发生 // 没有上次同步的时间, 则需要进行一次全量同步, 不可能会发生
if(!lastSyncUsn) { if(!lastSyncUsn) {
console.log('error!!'); console.error('getLastSyncState error!!');
return; return;
} }
@@ -575,7 +575,7 @@ var Sync = {
// 更新上次同步时间 // 更新上次同步时间
me.updateLastSyncState(function() { me.updateLastSyncState(function() {
// send changes // send changes
me.sendChanges(); me.sendChanges(again);
}); });
}); });
} else { } else {
@@ -675,6 +675,8 @@ var Sync = {
if(User.getLastSyncUsn() > usn) { // 添加标签时如果标签已经存在, 则返回的是旧的 if(User.getLastSyncUsn() > usn) { // 添加标签时如果标签已经存在, 则返回的是旧的
return; return;
} }
console.error('---?? checkNeedIncSyncAgain ??------' + usn)
console.trace();
me._needIncrSyncAgain = true; me._needIncrSyncAgain = true;
} }
} }
@@ -707,6 +709,7 @@ var Sync = {
Note.updateNoteForceForSendChange(newNote, true); Note.updateNoteForceForSendChange(newNote, true);
// 这里
me.checkNeedIncSyncAgain(newNote.Usn); me.checkNeedIncSyncAgain(newNote.Usn);
cb(); cb();
@@ -840,10 +843,16 @@ var Sync = {
}); });
}, },
sendChanges: function() { // again, 再一次sync, 不要send changes
sendChanges: function(again) {
var me = this; var me = this;
console.log('send changes before...') console.log('send changes before...')
// 先处理冲突, 可以同时进行 // 先处理冲突, 可以同时进行
if(again) {
console.error('send changes again....');
me.fixConflictsForSendChanges(function(){});
return;
}
me.fixConflicts(function() { me.fixConflicts(function() {
// send changes // send changes
console.log('send changes'); console.log('send changes');
@@ -862,10 +871,14 @@ var Sync = {
// 重新再来一次增量同步 // 重新再来一次增量同步
if(me._needIncrSyncAgain) { if(me._needIncrSyncAgain) {
console.error('-- _needIncrSyncAgain -- ') console.error('-- _needIncrSyncAgain -- ')
me.incrSync(true); console.log('send changes 后解决冲突, 先fix, 再incSync again');
me.fixConflictsForSendChanges(function(){
me.incrSync(true);
});
} else { } else {
console.log('send changes 后解决冲突'); console.log('send changes 后解决冲突');
me.fixConflictsForSendChanges(function(){}); me.fixConflictsForSendChanges(function(){
});
} }
}); });
}); });

4
node_modules/user.js generated vendored
View File

@@ -27,6 +27,7 @@ User = {
LastSyncTime: null, LastSyncTime: null,
// 登录后保存当前 // 登录后保存当前
setCurUser: function(user) { setCurUser: function(user) {
var me = this;
if(user) { if(user) {
this.token = user.Token; this.token = user.Token;
this.userId = user.UserId; this.userId = user.UserId;
@@ -175,9 +176,10 @@ User = {
if(!Api) { if(!Api) {
Api = require('api'); Api = require('api');
} }
log('--updateLastSyncState---')
Api.getLastSyncState(function(state) { Api.getLastSyncState(function(state) {
if(state) { if(state) {
console.error('--updateLastSyncState---')
console.log(state);
me.LastSyncUsn = state.LastSyncUsn; me.LastSyncUsn = state.LastSyncUsn;
me.LastSyncTime = state.LastSyncTime; me.LastSyncTime = state.LastSyncTime;
db.users.update({UserId: me.getCurActiveUserId()}, {$set: state}); db.users.update({UserId: me.getCurActiveUserId()}, {$set: state});

View File

@@ -805,22 +805,29 @@ window.require = undefined;
initPage(); initPage();
</script> </script>
<!-- v2 use require.js, mdeditor -->
<script>
window.require = window.requireNode;
/*
window.baseDir = 'public/dist';
window.require = {
baseUrl: window.baseDir,
};
*/
</script>
<script src="public/tinymce/plugins/leaui_image/public/js/jquery.ui.widget.js"></script> <script src="public/tinymce/plugins/leaui_image/public/js/jquery.ui.widget.js"></script>
<script src="public/tinymce/plugins/leaui_image/public/js/jquery.fileupload.js"></script> <script src="public/tinymce/plugins/leaui_image/public/js/jquery.fileupload.js"></script>
<script src="public/tinymce/plugins/leaui_image/public/js/jquery.iframe-transport.js"></script> <script src="public/tinymce/plugins/leaui_image/public/js/jquery.iframe-transport.js"></script>
<!-- <script src="public/js/app/paste.js"></script> --> <!-- <script src="public/js/app/paste.js"></script> -->
<!-- <script src="public/js/require.js"></script> --> <!-- v2 use require.js, mdeditor -->
<!-- <script src="public/js/main.js"></script> --> <script>
// window.require = undefined;
window.baseDir = 'public/dist';
window.require = {
baseUrl: window.baseDir,
};
</script>
<script src="public/dist/require.js"></script>
<script>
// alert(define);
// alert(require);
</script>
<script src="public/dist/main.js"></script>
<script>
window.require = window.requireNode;
</script>
</body> </body>
</html> </html>

43193
public/dist/main.js vendored

File diff suppressed because one or more lines are too long

21
public/dist/main.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2084
public/dist/require.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -280,8 +280,8 @@ Note.curHasChanged = function(force) {
hasChanged.Abstract = Note.genAbstract(c); hasChanged.Abstract = Note.genAbstract(c);
} }
} else { } else {
log("text相同"); console.log("text相同");
log(cacheNote.Content == content); console.log(cacheNote.Content == content);
} }
hasChanged["UserId"] = cacheNote["UserId"] || ""; hasChanged["UserId"] = cacheNote["UserId"] || "";
@@ -374,21 +374,24 @@ Note.genAbstract = function(content, len) {
var d = document.createElement("div"); var d = document.createElement("div");
d.innerHTML = result d.innerHTML = result
return d.innerHTML; return d.innerHTML;
} };
Note.getImgSrc = function(content) { Note.getImgSrc = function(content) {
if(!content) { if(!content) {
return ""; return "";
} }
var imgs = $(content).find("img"); try {
for(var i in imgs) { var imgs = $(content).find("img");
var src = imgs.eq(i).attr("src"); for(var i in imgs) {
if(src) { var src = imgs.eq(i).attr("src");
return src; if(src) {
return src;
}
} }
} catch(e) {
} }
return ""; return "";
} };
// 如果当前的改变了, 就保存它 // 如果当前的改变了, 就保存它
// 以后要定时调用 // 以后要定时调用
@@ -432,7 +435,7 @@ Note.curChangedSaveIt = function(force, callback) {
me.saveInProcess[hasChanged.NoteId] = true; me.saveInProcess[hasChanged.NoteId] = true;
Service.noteService.updateNoteOrContent(hasChanged, function(ret) { NoteService.updateNoteOrContent(hasChanged, function(ret) {
me.saveInProcess[hasChanged.NoteId] = false; me.saveInProcess[hasChanged.NoteId] = false;
if(hasChanged.IsNew) { if(hasChanged.IsNew) {
// 缓存之, 后台得到其它信息 // 缓存之, 后台得到其它信息
@@ -527,7 +530,7 @@ Note.directToNote = function(noteId) {
// 手机不用slimScroll // 手机不用slimScroll
if(!LEA.isMobile && !Mobile.isMobile()) { if(!LEA.isMobile && !Mobile.isMobile()) {
$("#noteItemList").scrollTop(top); $("#noteItemList").scrollTop(top);
$("#noteItemList").slimScroll({ scrollTo: top + 'px', height: "100%", onlyScrollBar: true}); // $("#noteItemList").slimScroll({ scrollTo: top + 'px', height: "100%", onlyScrollBar: true});
} else { } else {
} }
} }
@@ -672,6 +675,10 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
} }
self.showContentLoading(); self.showContentLoading();
console.error('chage note..........');
console.trace();
Service.noteService.getNoteContent(cacheNote.NoteId, setContent); // ajaxGet(url, param, setContent); Service.noteService.getNoteContent(cacheNote.NoteId, setContent); // ajaxGet(url, param, setContent);
} }
@@ -746,6 +753,7 @@ Note.clearAll = function() {
// render到编辑器 // render到编辑器
// render note // render note
Note.renderNote = function(note) { Note.renderNote = function(note) {
if(!note) { if(!note) {
return; return;
} }
@@ -762,6 +770,8 @@ Note.renderNote = function(note) {
// render content // render content
Note.renderNoteContent = function(content) { Note.renderNoteContent = function(content) {
console.error('---------------- note:' + note.Title);
console.trace();
setEditorContent(content.Content, content.IsMarkdown, content.Preview); setEditorContent(content.Content, content.IsMarkdown, content.Preview);
// 只有在renderNoteContent时才设置curNoteId // 只有在renderNoteContent时才设置curNoteId
@@ -1690,8 +1700,9 @@ Note._initshowConflictInfo = function() {
// console.log(me._curFixNoteTarget); // console.log(me._curFixNoteTarget);
// console.log(target); // console.log(target);
// target.insertBefore(me._curFixNoteTarget); target.insertAfter(me._curFixNoteTarget);
me._curFixNoteTarget.insertBefore(target); // alert(3);
// me._curFixNoteTarget.insertBefore(target);
// 选中与之冲突的笔记 // 选中与之冲突的笔记
me.changeNote(conflictNoteId); me.changeNote(conflictNoteId);
}); });
@@ -2390,20 +2401,18 @@ Note.addSync = function(notes) {
} }
// 更新 // 更新
Note.updateSync = function(notes) { Note.updateSync = function(notes) {
log("??")
if(isEmpty(notes)) { if(isEmpty(notes)) {
return; return;
} }
log("what?")
for(var i in notes) { for(var i in notes) {
var note = notes[i]; var note = notes[i];
note.InitSync = true; // 需要重新获取内容 note.InitSync = true; // 需要重新获取内容
Note.addNoteCache(note); Note.addNoteCache(note);
// 如果当前修改的是本笔记, 那么重新render之 // 如果当前修改的是本笔记, 那么重新render之
log('->>>') console.log('->>>');
log(Note.curNoteId); console.log(Note.curNoteId);
if(Note.curNoteId == note.NoteId) { if(Note.curNoteId == note.NoteId) {
log('yes---'); console.log('yes---');
Note.changeNote(Note.curNoteId); Note.changeNote(Note.curNoteId);
} }
} }

View File

@@ -1303,7 +1303,7 @@ function fullSync(callback) {
// 增量同步 // 增量同步
function incrSync() { function incrSync() {
log('incr sync'); log('incr sync');
SyncService.incrSync(Notebook, Note); SyncService.incrSync();
} }
// note.html调用 // note.html调用

21
test.js
View File

@@ -19,25 +19,30 @@ Api.addNotebook({
// Api.uploadImage(); // Api.uploadImage();
User.userId = '54bdc65599c37b0da9000002'; User.userId = '54bdc65599c37b0da9000002';
User.userId = '54d7620d99c37b030600002c'; User.userId = '54d7620d99c37b030600002c';
User.userId = '54db772899c37b1a6c000135'; User.userId = '54d7620d99c37b030600002c';
/*
User.init(function() { User.init(function() {
Api.getAttach('54d8c8de99c37b02fa000002', function() { Note.getNote('54d76aeec596f27b0b000000', function(note) {
});
Note.getNote('54e16d90c596f238dc000001', function(note) {
console.log(note); console.log(note);
console.log(note.NotebookId); /*
Notebook.getNotebook(note.NotebookId, function(notebook) { Notebook.getNotebook(note.NotebookId, function(notebook) {
console.log(notebook); console.log(notebook);
}); });
}) */
});
}); /*
Note.getDirtyNotes(function(ret) {
// console.log(ret);
});
*/ */
});
/*
Api.auth('e@a.com', 'abc123'); Api.auth('e@a.com', 'abc123');
User.getAllUsers(); User.getAllUsers();
*/
/* /*
Note.hasNotes('54bdc65599c37b0da9000005', function(doc) { Note.hasNotes('54bdc65599c37b0da9000005', function(doc) {