This commit is contained in:
life
2017-01-19 11:35:51 +08:00
parent 097e4486a0
commit 2f615069c2
11 changed files with 341 additions and 183 deletions

48
node_modules/api.js generated vendored
View File

@@ -45,6 +45,9 @@ var Api = {
if(!ret['Ok'] && ret['Msg'] == 'NOTLOGIN') { if(!ret['Ok'] && ret['Msg'] == 'NOTLOGIN') {
Web.notLogin(); Web.notLogin();
} }
if(!ret['Ok'] && ret['Msg'] == 'NEED-UPGRADE-ACCOUNT') {
Web.needUpgradeAccount();
}
} else { } else {
// 出现问题 // 出现问题
Web.unConnected(); Web.unConnected();
@@ -133,8 +136,8 @@ var Api = {
return callback && callback(false); return callback && callback(false);
} }
var ret = response.body; var ret = response.body;
console.log(ret); // console.log(ret);
console.log(response); // console.log(response);
if(Common.isOk(ret)) { if(Common.isOk(ret)) {
callback && callback(ret); callback && callback(ret);
} else { } else {
@@ -184,7 +187,7 @@ var Api = {
getLastSyncState: function(callback) { getLastSyncState: function(callback) {
var me = this; var me = this;
var url = this.getUrl('user/getSyncState'); var url = this.getUrl('user/getSyncState');
console.log(url); // console.log(url);
needle.get(url, {timeout: 10000}, function(error, response) { needle.get(url, {timeout: 10000}, function(error, response) {
// console.log('user/getSyncState ret'); // console.log('user/getSyncState ret');
me.checkError(error, response); me.checkError(error, response);
@@ -192,7 +195,7 @@ var Api = {
return callback && callback(false); return callback && callback(false);
} }
var ret = response.body; var ret = response.body;
console.log('--getSyncState--ret---') // console.log('1. getSyncStateRet:')
if(Common.isOk(ret)) { if(Common.isOk(ret)) {
callback && callback(ret); callback && callback(ret);
} else { } else {
@@ -204,7 +207,8 @@ var Api = {
getNoteContent: function(noteId, callback) { getNoteContent: function(noteId, callback) {
var me = this; var me = this;
var url = this.getUrl('note/getNoteContent', {noteId: noteId}); var url = this.getUrl('note/getNoteContent', {noteId: noteId});
console.log(url); console.log(' get note content from server...', noteId);
// console.log(url);
needle.get(url, function(error, response) { needle.get(url, function(error, response) {
me.checkError(error, response); me.checkError(error, response);
if(error) { if(error) {
@@ -476,9 +480,7 @@ var Api = {
// note.NotebookId是本的, 要得到远程的 // note.NotebookId是本的, 要得到远程的
Notebook.getServerNotebookIdByNotebookId(note.NotebookId, function(serverNotebookId) { Notebook.getServerNotebookIdByNotebookId(note.NotebookId, function(serverNotebookId) {
if(!serverNotebookId) { if(!serverNotebookId) {
console.error('No serverNotebookId'); callback && callback('No serverNotebookId');
// console.log(note);
callback && callback(false);
return; return;
} }
var data = { var data = {
@@ -494,8 +496,6 @@ var Api = {
CreatedTime: Common.formatDatetime(note.CreatedTime), CreatedTime: Common.formatDatetime(note.CreatedTime),
UpdatedTime: Common.formatDatetime(note.UpdatedTime) UpdatedTime: Common.formatDatetime(note.UpdatedTime)
} }
// log('add note');
// log(data);
// files处理 // files处理
var needMultiple = false; var needMultiple = false;
@@ -505,8 +505,7 @@ var Api = {
} }
// 最终传递的数据 // 最终传递的数据
console.log('end transfer data'); console.log(' end transfer data', data);
console.log(data);
try { try {
needle.post(me.getUrl('note/addNote'), data, needle.post(me.getUrl('note/addNote'), data,
@@ -516,24 +515,19 @@ var Api = {
function(err, resp) { function(err, resp) {
me.checkError(err, resp); me.checkError(err, resp);
if(err) { if(err) {
console.error('add note error!!-------'); return callback(err);
console.error(err);
return callback(false);
} }
var ret = resp.body; var ret = resp.body;
console.log('add note ret'); console.log(' add note ret', ret);
console.log(ret);
console.log('add note ret<-');
if(Common.isOk(ret)) { if(Common.isOk(ret)) {
// 将serverId保存 // 将serverId保存
callback(ret); callback(null, ret);
} else { } else {
callback(false); callback(ret);
} }
}); });
} catch(e) { } catch(e) {
console.log('add note needle error'); console.log(' add note needle error', e);
console.log(e);
}; };
}); });
}, },
@@ -568,7 +562,7 @@ var Api = {
} }
} }
console.log('update note :'); // console.log('update note :');
// files处理 // files处理
var needMultiple = false; var needMultiple = false;
@@ -581,9 +575,9 @@ var Api = {
// console.log('update note ret------------------'); // console.log('update note ret------------------');
me.checkError(err, resp); me.checkError(err, resp);
if(err) { if(err) {
console.error('err'); // console.error('err');
console.log(err); // console.log(err);
return callback(false); return callback(err);
} }
var ret = resp.body; var ret = resp.body;
// console.log('update note ret:'); // console.log('update note ret:');
@@ -591,7 +585,7 @@ var Api = {
// console.log(ret.Files); // console.log(ret.Files);
// 没有传IsMarkdown, 后台会传过来总为false // 没有传IsMarkdown, 后台会传过来总为false
delete ret['IsMarkdown']; delete ret['IsMarkdown'];
callback(ret); callback(null, ret);
/* /*
if(Common.isOk(ret)) { if(Common.isOk(ret)) {
} else { } else {

63
node_modules/note.js generated vendored
View File

@@ -881,6 +881,8 @@ var Note = {
needReloadContent = true; needReloadContent = true;
} }
// console.log('...', JSON.stringify(note))
note.IsDirty = false; note.IsDirty = false;
note.InitSync = needReloadContent; note.InitSync = needReloadContent;
note.LocalIsNew = false; note.LocalIsNew = false;
@@ -939,6 +941,7 @@ var Note = {
allAttachs.push(everAttachsMap[serverFileId]); allAttachs.push(everAttachsMap[serverFileId]);
} }
} }
// console.log('allAttachs', allAttachs);
note.Attachs = allAttachs; note.Attachs = allAttachs;
note.ServerNoteId = note.NoteId; note.ServerNoteId = note.NoteId;
@@ -964,14 +967,15 @@ var Note = {
delete note['CreatedTime']; delete note['CreatedTime'];
db.notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional db.notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional
console.log('re:'); // console.log('re:');
console.log(err); // console.log(err);
console.log(cnt); // console.log(cnt);
if(err) { if(err) {
console.error(err); console.error(err);
callback && callback(false); callback && callback(false);
} else { } else {
console.log('强制更新...'); console.log(' 强制更新本地笔记...', note.Title);
callback && callback(note); callback && callback(note);
/* /*
@@ -985,6 +989,8 @@ var Note = {
Notebook.reCountNotebookNumberNotes(note.NotebookId); Notebook.reCountNotebookNumberNotes(note.NotebookId);
// 下载内容, 图片, 附件 // 下载内容, 图片, 附件
// console.log('..', note)
// console.log(JSON.stringify(note), note.Attachs)
me.syncContentAndImagesAndAttachs(note); me.syncContentAndImagesAndAttachs(note);
} }
}); });
@@ -1004,8 +1010,7 @@ var Note = {
// note.LocalIsDelete = false; // note.LocalIsDelete = false;
// note.UserId = User.getCurActiveUserId(); // note.UserId = User.getCurActiveUserId();
// //
console.log("updateNoteForceForSendChange"); // console.log(" updateNoteForceForSendChange", note);
console.log(note);
// 如果是添加的, 因为不会传内容 // 如果是添加的, 因为不会传内容
// if(isAdd) { // if(isAdd) {
@@ -1014,9 +1019,9 @@ var Note = {
delete note['NotebookId']; // 不要设置notebookId, 2/16 fixed delete note['NotebookId']; // 不要设置notebookId, 2/16 fixed
console.log('server data from::::'); // console.log('server data from::::');
console.log(note.NoteId); // console.log(note.NoteId);
console.log(note.Files); // console.log(note.Files);
// 修改Imags的LocalFileId <=> FileId的映射 // 修改Imags的LocalFileId <=> FileId的映射
File.updateImageForce(note.Files); File.updateImageForce(note.Files);
@@ -1033,7 +1038,7 @@ var Note = {
// 之前也是有attachs的, 得到之前的attachs, 进行个merge // 之前也是有attachs的, 得到之前的attachs, 进行个merge
me.getNote(note.NoteId, function(everNote) { me.getNote(note.NoteId, function(everNote) {
if(!everNote) { if(!everNote) {
console.log('我靠, 没有?' + note.NoteId); console.log(' 没有?' + note.NoteId);
return; return;
} }
var everAttachs = everNote.Attachs || []; var everAttachs = everNote.Attachs || [];
@@ -1045,8 +1050,7 @@ var Note = {
} }
} }
note.Attachs = everAttachs; note.Attachs = everAttachs;
console.log('fix after'); console.log(' fix after', everAttachs);
console.log(everAttachs);
delete note['Files']; delete note['Files'];
delete note['UpdatedTime']; delete note['UpdatedTime'];
@@ -1055,8 +1059,7 @@ var Note = {
// multi: true, 避免有历史的笔记有问题 // multi: true, 避免有历史的笔记有问题
db.notes.update({NoteId: note.NoteId}, {$set: note}, {multi: true}, function(err, n) { db.notes.update({NoteId: note.NoteId}, {$set: note}, {multi: true}, function(err, n) {
if(err || !n) { if(err || !n) {
log('updateNoteForceForSendChange err'); console.log(' updateNoteForceForSendChange err', err);
log(err);
return callback && callback(false); return callback && callback(false);
} }
return callback && callback(true); return callback && callback(true);
@@ -1118,8 +1121,8 @@ var Note = {
// 只复制有path的 // 只复制有path的
var attachs = note.Attachs || []; var attachs = note.Attachs || [];
var newAttachs = []; var newAttachs = [];
console.log('不会吧.............') // console.log('不会吧.............')
console.log(attachs); // console.log(attachs);
async.eachSeries(attachs, function(attach, cb) { async.eachSeries(attachs, function(attach, cb) {
if(!attach.Path) { if(!attach.Path) {
return cb(); return cb();
@@ -1128,8 +1131,7 @@ var Note = {
var filePathAttr = Common.splitFile(attach.Path); var filePathAttr = Common.splitFile(attach.Path);
filePathAttr.nameNotExt += '_cp_' + attach.FileId; // 另一个 filePathAttr.nameNotExt += '_cp_' + attach.FileId; // 另一个
var newPath = filePathAttr.getFullPath(); var newPath = filePathAttr.getFullPath();
console.log('复制文件'); console.log(' 复制文件', attach);
console.log(attach);
// 复制之 // 复制之
// try { // try {
Common.copyFile(attach.Path, newPath, function(ret) { Common.copyFile(attach.Path, newPath, function(ret) {
@@ -1149,8 +1151,7 @@ var Note = {
*/ */
}, function() { }, function() {
note.Attachs = newAttachs; note.Attachs = newAttachs;
console.log('conflict 复制后的'); console.log(' conflict 复制后的', note);
console.log(note);
db.notes.insert(note, function(err, newNote) { db.notes.insert(note, function(err, newNote) {
if(err) { if(err) {
callback(false); callback(false);
@@ -1256,8 +1257,9 @@ var Note = {
var me = this; var me = this;
var conflictNotes = noteSyncInfo.conflicts; var conflictNotes = noteSyncInfo.conflicts;
console.log('fix note conflicts'); if (!isEmpty(conflictNotes)) {
console.log(conflictNotes); console.log(' fix note conflicts', conflictNotes);
}
// 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes // 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes
conflictNotes || (conflictNotes = []); conflictNotes || (conflictNotes = []);
if(!Api) { if(!Api) {
@@ -1327,8 +1329,15 @@ var Note = {
// 因为在处理冲突的时候有些成为更新了, 所以必须在此之后调用 // 因为在处理冲突的时候有些成为更新了, 所以必须在此之后调用
// console.log('has updates...'); // console.log('has updates...');
// console.log(noteSyncInfo.updates); // console.log(noteSyncInfo.updates);
// 处理更新的 // 处理更新的
if (!Common.isEmpty(noteSyncInfo.updates)) {
Web.updateSyncNote(noteSyncInfo.updates); Web.updateSyncNote(noteSyncInfo.updates);
}
if (!Common.isEmpty(noteSyncInfo.changeUpdates)) {
Web.updateChangeUpdates(noteSyncInfo.changeUpdates);
}
}); });
// 发送改变的冲突 // 发送改变的冲突
@@ -1373,7 +1382,7 @@ var Note = {
if(noteSyncInfo.changeNeedAdds) { if(noteSyncInfo.changeNeedAdds) {
var needAddNotes = noteSyncInfo.changeNeedAdds; var needAddNotes = noteSyncInfo.changeNeedAdds;
for(var i in needAddNotes) { for(var i in needAddNotes) {
console.log('need add '); console.log(' need add note');
var note = needAddNotes[i]; var note = needAddNotes[i];
me.setIsNew(note.NoteId); me.setIsNew(note.NoteId);
} }
@@ -1381,9 +1390,10 @@ var Note = {
// 处理添加的 // 处理添加的
var addNotes = noteSyncInfo.adds; var addNotes = noteSyncInfo.adds;
console.log('has add...'); if (!isEmpty(addNotes)) {
console.log(addNotes); console.log(' has add note...', addNotes);
Web.addSyncNote(addNotes); Web.addSyncNote(addNotes);
}
// 处理删除的 // 处理删除的
Web.deleteSyncNote(noteSyncInfo.deletes); Web.deleteSyncNote(noteSyncInfo.deletes);
@@ -1467,7 +1477,6 @@ var Note = {
}); });
}); });
}, function() { }, function() {
console.log(notes);
callback(notes); callback(notes);
}); });
} }
@@ -1659,7 +1668,7 @@ var Note = {
// 附件 // 附件
var attachs = note.Attachs || []; var attachs = note.Attachs || [];
for(var i in attachs) { for(var i = 0; i < attachs.length; ++i) {
var attach = attachs[i]; var attach = attachs[i];
me.downloadAttachFromServer(note.NoteId, attach.ServerFileId, attach.FileId); me.downloadAttachFromServer(note.NoteId, attach.ServerFileId, attach.FileId);
} }

67
node_modules/notebook.js generated vendored
View File

@@ -433,9 +433,45 @@ var Notebook = {
fixConflicts: function(notebookSyncInfo, callback) { fixConflicts: function(notebookSyncInfo, callback) {
var me = this; var me = this;
// 服务器没有, 但是是发送更新的, 所以需要作为添加
if(notebookSyncInfo.changeNeedAdds) {
var needAddNotebooks = notebookSyncInfo.changeNeedAdds;
for(var i in needAddNotebooks) {
var notebook = needAddNotebooks[i];
me.setIsNew(notebook.NotebookId);
}
}
// 处理添加的
var adds = notebookSyncInfo.adds;
if (!isEmpty(adds)) {
console.log(' has add notebook');
console.log(adds);
Web.addSyncNotebook(adds);
}
if (!isEmpty(notebookSyncInfo.changeAdds)) {
console.log(' has changeAdds notebook')
console.log(notebookSyncInfo.changeAdds)
Web.addChangeNotebook(notebookSyncInfo.changeAdds);
}
if (!isEmpty(notebookSyncInfo.updates)) {
console.log(' has updates notebook');
console.log(notebookSyncInfo.updates);
// 处理更新的
Web.updateSyncNotebook(notebookSyncInfo.updates);
}
if (!isEmpty(notebookSyncInfo.deletes)) {
// 处理删除的
Web.deleteSyncNotebook(notebookSyncInfo.deletes);
}
// 没有冲突的, 因为notebook不处理冲突
// 处理冲突 // 处理冲突
var conflictNotebooks = notebookSyncInfo.conflicts || []; var conflictNotebooks = notebookSyncInfo.conflicts || [];
console.log('fix notebook conflicts'); conflictNotebooks.length && console.log(' fix notebook conflicts');
async.eachSeries(conflictNotebooks, function(notebook, cb) { async.eachSeries(conflictNotebooks, function(notebook, cb) {
/* /*
var noteId = note.NoteId; var noteId = note.NoteId;
@@ -458,35 +494,6 @@ var Notebook = {
// 最后调用 // 最后调用
callback && callback(); callback && callback();
}); });
// 服务器没有, 但是是发送更新的, 所以需要作为添加
if(notebookSyncInfo.changeNeedAdds) {
var needAddNotebooks = notebookSyncInfo.changeNeedAdds;
for(var i in needAddNotebooks) {
var notebook = needAddNotebooks[i];
me.setIsNew(notebook.NotebookId);
}
}
// 处理添加的
var adds = notebookSyncInfo.adds;
log('has add...');
log(adds);
Web.addSyncNotebook(adds);
log('has changeAdds')
log(notebookSyncInfo.changeAdds)
Web.addChangeNotebook(notebookSyncInfo.changeAdds);
log('has updates...');
log(notebookSyncInfo);
log(notebookSyncInfo.updates);
// 处理更新的
Web.updateSyncNotebook(notebookSyncInfo.updates);
// 处理删除的
Web.deleteSyncNotebook(notebookSyncInfo.deletes);
}, },
// 在send delete笔记时成功 // 在send delete笔记时成功

177
node_modules/sync.js generated vendored
View File

@@ -33,7 +33,7 @@ var Sync = {
// 同步的信息, 返回给调用者 // 同步的信息, 返回给调用者
_syncInfo: { _syncInfo: {
notebook: {changeAdds: [], changeConflicts: [], adds: [], deletes: [], updates: []}, notebook: {changeAdds: [], changeConflicts: [], adds: [], deletes: [], updates: []},
note: {changeAdds: [], changeConflicts: [], adds: [], deletes: [], updates: [], conflicts: []}, note: {changeAdds: [], changeConflicts: [], adds: [], deletes: [], updates: [], conflicts: [], errors: []},
tag: {} tag: {}
}, },
/* /*
@@ -85,7 +85,7 @@ var Sync = {
// 同步信息 // 同步信息
me._syncInfo = { me._syncInfo = {
notebook: {ok: false, changeAdds: [], changeConflicts: [], changeNeedAdds: [], adds: [], deletes: [], updates: []}, notebook: {ok: false, changeAdds: [], changeConflicts: [], changeNeedAdds: [], adds: [], deletes: [], updates: []},
note: {ok: false, adds: [], changeAdds: [], changeConflicts: [], changeUpdates:[], changeNeedAdds: [], deletes: [], updates: [], conflicts: []}, note: {ok: false, adds: [], changeAdds: [], changeConflicts: [], changeUpdates:[], changeNeedAdds: [], deletes: [], updates: [], conflicts: [], errors: []},
tag: {ok: false, adds: [], changeAdds: [], changeConflicts: [], changeNeedAdds: [], deletes: [], updates: [], conflicts: []}, tag: {ok: false, adds: [], changeAdds: [], changeConflicts: [], changeNeedAdds: [], deletes: [], updates: [], conflicts: []},
}; };
@@ -175,7 +175,8 @@ var Sync = {
// console.log(notebook); // console.log(notebook);
Notebook.getNotebookIdByServerNotebookId(notebookId, function(localNotebookId) { Notebook.getNotebookIdByServerNotebookId(notebookId, function(localNotebookId) {
Notebook.deleteNotebookForce(notebookId, function() { Notebook.deleteNotebookForce(notebookId, function() {
me._syncInfo.notebook.deletes.push(localNotebookId); // me._syncInfo.notebook.deletes.push(localNotebookId);
me.fixSynced('notebook', 'deletes', localNotebookId);
canCall(); canCall();
}) })
}); });
@@ -188,7 +189,8 @@ var Sync = {
console.log('add addNotebookForce...') console.log('add addNotebookForce...')
// TODO // TODO
Notebook.addNotebookForce(notebook, function(notebook) { Notebook.addNotebookForce(notebook, function(notebook) {
me._syncInfo.notebook.adds.push(notebook); // me._syncInfo.notebook.adds.push(notebook);
me.fixSynced('notebook', 'adds', notebook);
canCall(); canCall();
}); });
} else { } else {
@@ -207,7 +209,8 @@ var Sync = {
// 这里都是用服务器端的数据, 不处理冲突 // 这里都是用服务器端的数据, 不处理冲突
Notebook.updateNotebookForce(notebook, notebookLocal, function(notebook) { Notebook.updateNotebookForce(notebook, notebookLocal, function(notebook) {
if(notebook) { if(notebook) {
me._syncInfo.notebook.updates.push(notebook); // me._syncInfo.notebook.updates.push(notebook);
me.fixSynced('notebook', 'updates', notebook);
} }
canCall(); canCall();
}) })
@@ -223,7 +226,7 @@ var Sync = {
return; return;
} }
Api.getSyncNotebooks(afterUsn, me._notebookMaxEntry, function(notebooks) { Api.getSyncNotebooks(afterUsn, me._notebookMaxEntry, function(notebooks) {
console.log('syncNotebook') console.log(' syncNotebook')
// console.log(notebooks); // console.log(notebooks);
if(Common.isOk(notebooks)) { if(Common.isOk(notebooks)) {
me._totalSyncNotebookNum += notebooks.length; me._totalSyncNotebookNum += notebooks.length;
@@ -237,7 +240,7 @@ var Sync = {
me.updateSyncUsn('NotebookUsn', last.Usn); me.updateSyncUsn('NotebookUsn', last.Usn);
} else { } else {
console.log('no more'); console.log(' no more notebooks');
me._syncNotebookIsLastChunk = true; me._syncNotebookIsLastChunk = true;
me._syncNotebookToLocal(notebooks, callback); me._syncNotebookToLocal(notebooks, callback);
@@ -255,7 +258,6 @@ var Sync = {
}); });
}, },
//------------- //-------------
// note // note
//------------- //-------------
@@ -313,11 +315,11 @@ var Sync = {
// 1) 服务器端删除了, 本地肯定删除 // 1) 服务器端删除了, 本地肯定删除
if(note.IsDeleted) { if(note.IsDeleted) {
log('delete: '); console.log(' delete: ', note);
log(note);
Note.getNoteIdByServerNoteId(noteId, function(localNoteId) { Note.getNoteIdByServerNoteId(noteId, function(localNoteId) {
Note.deleteNoteForce(noteId, function() { Note.deleteNoteForce(noteId, function() {
me._syncInfo.note.deletes.push(localNoteId); // me._syncInfo.note.deletes.push(localNoteId);
me.fixSynced('note', 'deletes', localNoteId);
canCall(); canCall();
}); });
}); });
@@ -327,15 +329,16 @@ var Sync = {
Note.getNoteByServerNoteId(noteId, function(noteLocal) { Note.getNoteByServerNoteId(noteId, function(noteLocal) {
// 2.1 本地没有, 表示是新建 // 2.1 本地没有, 表示是新建
if(!noteLocal) { if(!noteLocal) {
console.log('add: ...'); console.log(' add note', note);
Note.addNoteForce(note, function(note) { Note.addNoteForce(note, function(note) {
me._syncInfo.note.adds.push(note); // me._syncInfo.note.adds.push(note);
me.fixSynced('note', 'adds', note);
return canCall(); return canCall();
}); });
} else { } else {
// 如果Usn一样, 表示服务器端并没有修改 // 如果Usn一样, 表示服务器端并没有修改
if(noteLocal.Usn === note.Usn) { if(noteLocal.Usn === note.Usn) {
console.log('note 如果Usn一样, 表示服务器端并没有修改'); console.log(' note 如果Usn一样, 表示服务器端并没有修改');
return canCall(); return canCall();
} }
@@ -343,7 +346,7 @@ var Sync = {
// 冲突, 将本地修改的笔记复制一份(设置冲突字段, ConflictNoteId), 远程的覆盖本地的 // 冲突, 将本地修改的笔记复制一份(设置冲突字段, ConflictNoteId), 远程的覆盖本地的
// 新方法: 冲突后, 得到最新内容, 看是否与本地内容一致, 如果一致, 则不冲突, 其它数据用服务器上的 // 新方法: 冲突后, 得到最新内容, 看是否与本地内容一致, 如果一致, 则不冲突, 其它数据用服务器上的
if(noteLocal.IsDirty) { if(noteLocal.IsDirty) {
console.log('note 冲突.... serverNoteId: ' + noteId); console.log(' note 冲突 serverNoteId: ' + noteId, note.Title);
// console.log(noteLocal.NoteId); // console.log(noteLocal.NoteId);
// console.log(noteLocal.IsDirty); // console.log(noteLocal.IsDirty);
// console.log(noteLocal); // console.log(noteLocal);
@@ -354,7 +357,8 @@ var Sync = {
// 表示没有获取到content, 则只能标志为冲突了 // 表示没有获取到content, 则只能标志为冲突了
// 内容不一样, 也标为冲突 // 内容不一样, 也标为冲突
if (content === false || content != noteLocal.Content) { if (content === false || content != noteLocal.Content) {
me._syncInfo.note.conflicts.push({server: note, local: noteLocal}); // me._syncInfo.note.conflicts.push({server: note, local: noteLocal});
me.fixSynced('note', 'conflicts', {server: note, local: noteLocal});
} }
// 否则, 内容一样, 标为不冲突, 需要更新 // 否则, 内容一样, 标为不冲突, 需要更新
else { else {
@@ -363,7 +367,8 @@ var Sync = {
// 服务器是最新的, 本地没动过, 则覆盖之 // 服务器是最新的, 本地没动过, 则覆盖之
Note.updateNoteForce(note, function(note) { Note.updateNoteForce(note, function(note) {
if(note) { if(note) {
me._syncInfo.note.updates.push(note); // me._syncInfo.note.updates.push(note);
me.fixSynced('note', 'updates', note);
} }
canCall(); canCall();
}, false); }, false);
@@ -377,7 +382,8 @@ var Sync = {
// 服务器是最新的, 本地没动过, 则覆盖之 // 服务器是最新的, 本地没动过, 则覆盖之
Note.updateNoteForce(note, function(note) { Note.updateNoteForce(note, function(note) {
if(note) { if(note) {
me._syncInfo.note.updates.push(note); // me._syncInfo.note.updates.push(note);
me.fixSynced('note', 'updates', note);
} }
canCall(); canCall();
}); });
@@ -394,9 +400,10 @@ var Sync = {
return; return;
} }
console.log(' pull notes from server...');
Api.getSyncNotes(afterUsn, me._noteMaxEntry, function(notes) { Api.getSyncNotes(afterUsn, me._noteMaxEntry, function(notes) {
// console.log('syncNote---'); // console.log('syncNote---');
// console.log(notes); console.log(' notes:', notes);
if(Common.isOk(notes)) { if(Common.isOk(notes)) {
me._totalSyncNoteNum += notes.length; me._totalSyncNoteNum += notes.length;
// 证明可能还有要同步的 // 证明可能还有要同步的
@@ -413,7 +420,7 @@ var Sync = {
me.updateSyncUsn('NoteUsn', last.Usn); me.updateSyncUsn('NoteUsn', last.Usn);
} else { } else {
log('no more'); console.log(' no more notes');
me._syncNoteIsLastChunk = true; me._syncNoteIsLastChunk = true;
me._syncNoteToLocal(notes, callback); me._syncNoteToLocal(notes, callback);
@@ -426,8 +433,7 @@ var Sync = {
// 同步失败 // 同步失败
me._syncInfo.note.ok = false; me._syncInfo.note.ok = false;
me._syncInfo.note.msg = "cann't get all chunks"; me._syncInfo.note.msg = "cann't get all chunks";
console.error('eeeeeeeeeeeeeeeeeerrror') console.error(' pull notes error', notes)
console.error(notes);
callback && callback(false); callback && callback(false);
} }
}); });
@@ -492,7 +498,8 @@ var Sync = {
log('delete tag: '); log('delete tag: ');
log(tag); log(tag);
Tag.deleteTag(tag.Tag, function() { Tag.deleteTag(tag.Tag, function() {
me._syncInfo.tag.deletes.push(tag.Tag); // me._syncInfo.tag.deletes.push(tag.Tag);
me.fixSynced('tag', 'deletes', tag.Tag);
canCall(); canCall();
}, true); }, true);
return; return;
@@ -503,7 +510,8 @@ var Sync = {
if(!tagLocal) { if(!tagLocal) {
log('add tag: ...') log('add tag: ...')
Tag.addOrUpdateTag(tag.Tag, function(tagAdded) { Tag.addOrUpdateTag(tag.Tag, function(tagAdded) {
me._syncInfo.tag.adds.push(tagAdded); // me._syncInfo.tag.adds.push(tagAdded);
me.fixSynced('tag', 'adds', tagAdded);
return canCall(); return canCall();
}, true, usn); }, true, usn);
} else { } else {
@@ -547,7 +555,7 @@ var Sync = {
// 同步失败 // 同步失败
me._syncInfo.tag.ok = false; me._syncInfo.tag.ok = false;
me._syncInfo.tag.msg = "cann't get all chunks"; me._syncInfo.tag.msg = "cann't get all chunks";
console.error('tags eeeeeeeeeeeeeeeeeerrror') console.error(' sync tags error...')
// console.log(tags); // console.log(tags);
callback && callback(false); callback && callback(false);
} }
@@ -636,8 +644,25 @@ var Sync = {
}); });
}, },
_notebookWeb: null, // 处理同步好的之后的
_noteWeb: null, // mainType == notebook, note, tag
// type = changeAdds, changeConflicts, adds, deletes, updates, conflicts, errors,
fixSynced: function (mainType, type, data) {
var o = {};
if (!Common.isArray(data)) {
data = [data];
}
o[type] = data;
if (mainType == 'notebook') {
Notebook.fixConflicts(o);
} else if (mainType == 'note') {
console.error('........');
Note.fixConflicts(o);
} else {
Web.addOrDeleteTagFromSync(o);
}
},
// 处理冲突 // 处理冲突
fixConflicts: function(callback) { fixConflicts: function(callback) {
var me = this; var me = this;
@@ -648,6 +673,7 @@ var Sync = {
var tag = me._syncInfo.tag; var tag = me._syncInfo.tag;
// 如果是incSync, 则要前端处理 // 如果是incSync, 则要前端处理
// 不是fullSync
if(me.incrSyncStart) { if(me.incrSyncStart) {
Notebook.fixConflicts(me._syncInfo.notebook); Notebook.fixConflicts(me._syncInfo.notebook);
@@ -656,7 +682,7 @@ var Sync = {
// 避免无限循环, 别send changes了 // 避免无限循环, 别send changes了
if(!me._needIncrSyncAgain) { if(!me._needIncrSyncAgain) {
// alert("?") // alert("?")
console.log(">>>>>>>> not needIncrSyncAgain>>>>>>>>>>>>>>>>> ") console.log(" not needIncrSyncAgain")
// send changes // send changes
callback && callback(); callback && callback();
} else { } else {
@@ -672,6 +698,7 @@ var Sync = {
Web.addOrDeleteTagFromSync(tag); Web.addOrDeleteTagFromSync(tag);
} }
}, },
fixConflictsForSendChanges: function(callback) { fixConflictsForSendChanges: function(callback) {
var me = this; var me = this;
me.fixConflicts(function() { me.fixConflicts(function() {
@@ -724,39 +751,39 @@ var Sync = {
// 得到当前LastSyncUsn // 得到当前LastSyncUsn
User.getLastSyncState(function(lastSyncUsn, lastSyncTime) { User.getLastSyncState(function(lastSyncUsn, lastSyncTime) {
console.log('%cstep1 getLastSyncState', 'color: #68bc7a')
// 没有上次同步的时间, 则需要进行一次全量同步, 不可能会发生 // 没有上次同步的时间, 则需要进行一次全量同步, 不可能会发生
if(!lastSyncUsn) { if(!lastSyncUsn) {
console.error('getLastSyncState error!!'); console.error(' getLastSyncState error!!');
me.setSyncFinished(); me.setSyncFinished();
return; return;
} }
// 先从服务器上得到usn, 与本地的判断, 是否需要pull // 先从服务器上得到usn, 与本地的判断, 是否需要pull
console.log('先从服务器上得到usn, 与本地的判断, 是否需要pull');
Api.getLastSyncState(function(serverState) { Api.getLastSyncState(function(serverState) {
if(!serverState) { if(!serverState) {
console.error('get Server LastSyncState error!!'); console.error(' get Server LastSyncState error!!');
me.setSyncFinished(); me.setSyncFinished();
return; return;
} }
console.log(serverState.LastSyncUsn + ' ' + lastSyncUsn); console.log(' get Server LastSyncState ret', serverState.LastSyncUsn + ' ' + lastSyncUsn);
if(serverState.LastSyncUsn > lastSyncUsn) { if(serverState.LastSyncUsn > lastSyncUsn) {
// 需要同步笔记本 // 需要同步笔记本
console.log('需要pull'); console.log('%cstep2 pull', 'color: #68bc7a')
// 同步笔记本 // 同步笔记本
me.syncNotebook(lastSyncUsn, function(ok) { me.syncNotebook(lastSyncUsn, function(ok) {
if(ok) { if(ok) {
console.log('-------incr notebook ok-----------' + lastSyncUsn); console.log(' incr notebook ok', lastSyncUsn);
me.addSyncProcessStatus(10); me.addSyncProcessStatus(10);
console.log(' incr note start');
// 同步笔记 // 同步笔记
me.syncNote(lastSyncUsn, function(ok) { me.syncNote(lastSyncUsn, function(ok) {
if(ok) { if(ok) {
console.log('-------incr note ok-----------' + lastSyncUsn); console.log(' incr note ok', lastSyncUsn);
me.addSyncProcessStatus(30); me.addSyncProcessStatus(30);
// 同步标签 // 同步标签
me.syncTag(lastSyncUsn, function() { me.syncTag(lastSyncUsn, function() {
console.log('-------incr tag ok-----------' + lastSyncUsn); console.log(' incr tag ok', lastSyncUsn);
me.addSyncProcessStatus(10); me.addSyncProcessStatus(10);
// 更新上次同步时间 // 更新上次同步时间
me.updateLastSyncState(function() { me.updateLastSyncState(function() {
@@ -765,7 +792,7 @@ var Sync = {
}); });
}); });
} else { } else {
console.log('-------incr note not ok-----------') console.log(' incr note not ok')
me.fixConflicts(); me.fixConflicts();
} }
}); });
@@ -775,7 +802,7 @@ var Sync = {
}); });
} else { } else {
console.log('不需要pull'); console.log('%cstep2 不需要pull, skip', 'color: #68bc7a')
me.addSyncProcessStatus(50); me.addSyncProcessStatus(50);
me.sendChanges(again); me.sendChanges(again);
} }
@@ -790,10 +817,14 @@ var Sync = {
// 发送笔记本的更改 // 发送笔记本的更改
sendNotebookChanges: function(callback) { sendNotebookChanges: function(callback) {
var me = this; var me = this;
console.log(' 3.1: sendNotebookChanges')
// 获取所有笔记本的更改 // 获取所有笔记本的更改
Notebook.getDirtyNotebooks(function(notebooks) { Notebook.getDirtyNotebooks(function(notebooks) {
console.log('dirty notebooks'); if (!Common.isEmpty(notebooks)) {
console.log(notebooks); console.log(' dirty notebooks:', notebooks);
} else {
console.log(' no dirty notebooks');
}
if(!notebooks) { if(!notebooks) {
callback && callback(); callback && callback();
} else { } else {
@@ -805,7 +836,7 @@ var Sync = {
// 本地既是新的, 又是删除的, 删除本地的, 不要同步 // 本地既是新的, 又是删除的, 删除本地的, 不要同步
// 5/4 // 5/4
if(notebook.LocalIsNew && notebook.LocalIsDelete) { if(notebook.LocalIsNew && notebook.LocalIsDelete) {
console.log('笔记本既是新的, 又是删除的, 不同步, 直接删除本地的'); console.log(' 笔记本既是新的, 又是删除的, 不同步, 直接删除本地的');
Notebook.deleteLocalNotebook(notebook.NotebookId); Notebook.deleteLocalNotebook(notebook.NotebookId);
return cb(); return cb();
} }
@@ -896,10 +927,14 @@ var Sync = {
// 发送笔记本的更改 // 发送笔记本的更改
sendNoteChanges: function(callback) { sendNoteChanges: function(callback) {
var me = this; var me = this;
console.log(' 3.2: sendNoteChanges');
// 获取所有笔记本的更改 // 获取所有笔记本的更改
Note.getDirtyNotes(function(notes) { Note.getDirtyNotes(function(notes) {
console.error('>>>>>>>>>>>> dirty notes <<<<<<<<<<<<<<< '); if (!Common.isEmpty(notes)) {
console.log(notes); console.log(' dirty notes:', notes);
} else {
console.log(' no dirty notes');
}
if(!notes) { if(!notes) {
callback && callback(); callback && callback();
} else { } else {
@@ -908,7 +943,12 @@ var Sync = {
async.eachSeries(notes, function(note, cb) { async.eachSeries(notes, function(note, cb) {
if (note.InitSync) { if (note.InitSync) {
console.error('InitSync is Dirty'); console.log(' InitSync is Dirty', note);
return cb();
}
if (note.ConflictNoteId && !note.ConflictFixed) {
console.log(' 未解决的冲突不同步', note.Title);
return cb(); return cb();
} }
@@ -916,10 +956,13 @@ var Sync = {
// 是新的, 且不是trash和删除的 // 是新的, 且不是trash和删除的
if(!note.IsTrash && !note.LocalIsDelete) { if(!note.IsTrash && !note.LocalIsDelete) {
// 添加, newNote的返回不会很多值(server端) // 添加, newNote的返回不会很多值(server端)
Api.addNote(note, function(newNote) { Api.addNote(note, function(err, newNote) {
if(!Common.isOk(newNote)) { if(err || !Common.isOk(newNote)) {
console.log(' 添加笔记失败!', err, newNote);
me._syncInfo.note.errors.push({err: err, ret: newNote, note: note});
return cb(); return cb();
} }
console.log(' 添加笔记成功!', note.Title);
newNote.ServerNoteId = newNote.NoteId; newNote.ServerNoteId = newNote.NoteId;
newNote.NoteId = note.NoteId; newNote.NoteId = note.NoteId;
@@ -938,13 +981,13 @@ var Sync = {
// 5/4 // 5/4
// 本地已经删除了, 则彻底删除之 // 本地已经删除了, 则彻底删除之
else if(note.LocalIsDelete) { else if(note.LocalIsDelete) {
console.log('既是新的, 又是删除的, 则删除笔记的'); console.log(' 既是新的, 又是删除的, 则删除笔记的');
Note.deleteLocalNote(note.NoteId); Note.deleteLocalNote(note.NoteId);
return cb(); return cb();
} }
// isTrash, 不同步, 不删除 // isTrash, 不同步, 不删除
else { else {
console.log('既是新的, 又是trash的, 不要同步'); console.log(' 既是新的, 又是trash的, 不要同步');
return cb(); return cb();
} }
} }
@@ -960,13 +1003,12 @@ var Sync = {
} }
else { else {
// 更新 // 更新
Api.updateNote(note, function(ret) { Api.updateNote(note, function(err, ret) {
if(!Common.isOk(ret)) { if(err || !Common.isOk(ret)) {
console.log('updateNote eeeeeeeeeeror'); console.log(' update error:' + note.Title, ret);
console.log(ret);
if(typeof ret == 'object') { if(typeof ret == 'object') {
if(ret.Msg == 'conflict') { if(ret.Msg == 'conflict') {
console.error('updateNote 冲突-----------'); console.error(' updateNote 冲突');
// 这种情况有很少见, 原因是先pull, 肯定会pull过来 // 这种情况有很少见, 原因是先pull, 肯定会pull过来
// 处理方法和pull一样, 看内容是否一样 // 处理方法和pull一样, 看内容是否一样
@@ -999,16 +1041,21 @@ var Sync = {
} }
// 其它错误, 不加, notImage 导致不能终止 // 其它错误, 不加, notImage 导致不能终止
else { else {
console.error(' updateNote error', err);
me._syncInfo.note.errors.push({err: err, ret: ret, note: note});
cb(); cb();
} }
} }
// 更新失败了, 服务器返回异常 // 更新失败了, 服务器返回异常
else { else {
console.error(' updateNote error', err);
me._syncInfo.note.errors.push({err: err, ret: ret, note: note});
cb(); cb();
} }
} }
// 更新成功 // 更新成功
else { else {
console.log(' 更新成功: ', note.Title);
ret.ServerNoteId = ret.NoteId; ret.ServerNoteId = ret.NoteId;
ret.NoteId = note.NoteId; ret.NoteId = note.NoteId;
Note.updateNoteForceForSendChange(ret, false); Note.updateNoteForceForSendChange(ret, false);
@@ -1028,12 +1075,15 @@ var Sync = {
}, },
// 发送标签改变 // 发送标签改变
sendTagChanges: function(callback) { sendTagChanges: function(callback) {
log('send note changes'); console.log(' 3.3: sendTagChanges');
var me = this; var me = this;
// 获取所有笔记本的更改 // 获取所有笔记本的更改
Tag.getDirtyTags(function(tags) { Tag.getDirtyTags(function(tags) {
console.log('dirty tags'); if (!Common.isEmpty(tags)) {
console.log(tags); console.log(' dirty tags:', tags);
} else {
console.log(' no dirty tags');
}
if(!tags) { if(!tags) {
callback && callback(); callback && callback();
} else { } else {
@@ -1075,16 +1125,16 @@ var Sync = {
// again, 再一次sync, 不要send changes // again, 再一次sync, 不要send changes
sendChanges: function(again) { sendChanges: function(again) {
var me = this; var me = this;
console.log('send changes before...') console.log('%cstep3 send changes', 'color: #68bc7a')
// 先处理冲突, 可以同时进行 // 先处理冲突, 可以同时进行
if(again) { if(again) {
console.error('send changes again....'); console.log(' send changes again....');
me.fixConflictsForSendChanges(function(){}); me.fixConflictsForSendChanges(function(){});
return; return;
} }
me.fixConflicts(function() { me.fixConflicts(function() {
// send changes // send changes
console.log('send changes'); console.log(' send changes');
me._initSyncInfo(); // 重新初始化[] me._initSyncInfo(); // 重新初始化[]
async.series([ async.series([
function(cb) { function(cb) {
@@ -1103,13 +1153,12 @@ var Sync = {
// 重新再来一次增量同步 // 重新再来一次增量同步
if(me._needIncrSyncAgain) { if(me._needIncrSyncAgain) {
console.error('-- _needIncrSyncAgain -- ') console.error(' needIncrSyncAgain')
console.log('send changes 后解决冲突, 先fix, 再incSync again');
me.fixConflictsForSendChanges(function() { me.fixConflictsForSendChanges(function() {
me.incrSync(true); me.incrSync(true);
}); });
} else { } else {
console.log('send changes 后解决冲突'); console.log(' send changes 后解决冲突');
me.fixConflictsForSendChanges(function() { me.fixConflictsForSendChanges(function() {
}); });
} }

9
node_modules/web.js generated vendored
View File

@@ -20,6 +20,11 @@ var Web = {
me.Note && me.Note.notLogin(); me.Note && me.Note.notLogin();
}, },
needUpgradeAccount: function () {
var me = this;
me.Note && me.Note.needUpgradeAccount();
},
alertWeb: function(msg) { alertWeb: function(msg) {
var me = this; var me = this;
me.Note && me.Note.alertWeb(msg); me.Note && me.Note.alertWeb(msg);
@@ -66,6 +71,10 @@ var Web = {
var me = this; var me = this;
me.Note.updateSync(notes); me.Note.updateSync(notes);
}, },
updateChangeUpdates: function (notes) {
var me = this;
me.Note.updateChangeUpdates(notes);
},
deleteSyncNote: function(notes) { deleteSyncNote: function(notes) {
var me = this; var me = this;
me.Note.deleteSync(notes); me.Note.deleteSync(notes);

View File

@@ -21,7 +21,7 @@ Note.notebookIds = {}; // notebookId => true
// 初始化模版字符串 // 初始化模版字符串
// blog, star, settings // blog, star, settings
var itemIsBlog = '<div class="item-blog"><i class="fa fa-bold" title="' + getMsg('Blog') + '"></i></div><div class="item-conflict-info"><i class="fa fa-bug" title="' + getMsg('Conflict') + '!!"></i></div><div class="item-star"><i class="fa fa-star-o" title="' + getMsg('Star') + '"></i></div><div class="item-setting"><i class="fa fa-cog" title="' + getMsg('Setting') + '"></i></div>'; var itemIsBlog = '<div class="item-blog"><i class="fa fa-bold" title="' + getMsg('Blog') + '"></i></div><div class="item-conflict-info"><i class="fa fa-bug" title="' + getMsg('Conflict') + '!!"></i></div><div class="item-star"><i class="fa fa-star-o" title="' + getMsg('Star') + '"></i></div><div class="item-setting"><i class="fa fa-cog" title="' + getMsg('Setting') + '"></i></div><span class="dirty-bg"></span>';
Note.itemTplNoImg = '<li href="#" class="item ?" data-seq="?" noteId="?">'; Note.itemTplNoImg = '<li href="#" class="item ?" data-seq="?" noteId="?">';
Note.itemTplNoImg += itemIsBlog + '<div class="item-desc"><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>'; Note.itemTplNoImg += itemIsBlog + '<div class="item-desc"><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';
Note.itemTpl = '<li href="#" class="item ? item-image" data-seq="?" noteId="?"><div class="item-thumb" style=""><img src="?"/></div>'; Note.itemTpl = '<li href="#" class="item ? item-image" data-seq="?" noteId="?"><div class="item-thumb" style=""><img src="?"/></div>';
@@ -445,6 +445,10 @@ Note.getImgSrc = function(content) {
return ""; return "";
}; };
Note.setNoteDirty = function (noteId) {
var $leftNoteNav = $(tt('[noteId="?"]', noteId));
$leftNoteNav.addClass('item-dirty');
};
// 如果当前的改变了, 就保存它 // 如果当前的改变了, 就保存它
// 以后要定时调用 // 以后要定时调用
@@ -506,6 +510,8 @@ Note.curChangedSaveIt = function(force, callback) {
Pjax.changeNote(ret); Pjax.changeNote(ret);
} }
me.setNoteDirty(hasChanged.NoteId);
callback && callback(ret); callback && callback(ret);
}, force); }, force);
@@ -799,9 +805,13 @@ Note.renderChangedNote = function(changedNote) {
// 如果标题改了, 如果也在star列表中, 那也要改star的标题啊 // 如果标题改了, 如果也在star列表中, 那也要改star的标题啊
Note.changeStarNoteTitle(changedNote.NoteId, trimTitle(changedNote.Title)); Note.changeStarNoteTitle(changedNote.NoteId, trimTitle(changedNote.Title));
} }
// $leftNoteNav.addClass('item-dirty');
if($leftNoteNav.hasClass("list-item")) { if($leftNoteNav.hasClass("list-item")) {
return; //list view只需要更新title return; //list view只需要更新title
} }
if(changedNote.Desc) { if(changedNote.Desc) {
$leftNoteNav.find(".desc").html(trimTitle(changedNote.Desc)); $leftNoteNav.find(".desc").html(trimTitle(changedNote.Desc));
} }
@@ -986,9 +996,6 @@ Note.renderNotes = function(notes, forNewNote, isShared) {
Note._getNoteHtmlObjct = function(note, isShared) { Note._getNoteHtmlObjct = function(note, isShared) {
var baseClasses = "item-my"; var baseClasses = "item-my";
if(isShared) {
baseClasses = "item-shared";
}
var classes = baseClasses; var classes = baseClasses;
if (note.IsDeleted) { if (note.IsDeleted) {
console.error('_getNoteHtmlObjct note.IsDeleted'); console.error('_getNoteHtmlObjct note.IsDeleted');
@@ -1015,19 +1022,20 @@ Note._getNoteHtmlObjct = function(note, isShared) {
}, },
Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟 Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟
var baseClasses = "item-my"; var baseClasses = "item-my";
if(isShared) {
baseClasses = "item-shared";
}
var len = notes.length; var len = notes.length;
for(var i = (tang-1)*20; i < len && i < tang*20; ++i) { for(var i = (tang-1)*20; i < len && i < tang*20; ++i) {
var classes = baseClasses; var classes = baseClasses;
if(!forNewNote && i == 0) { if(!forNewNote && i == 0) {
classes += " item-active"; classes += " item-active";
} }
var note = notes[i]; var note = notes[i];
note.Title = trimTitle(note.Title); note.Title = trimTitle(note.Title);
if (note.IsDirty) {
classes += " item-dirty";
}
if (note.IsDeleted) { if (note.IsDeleted) {
console.error('note.IsDeleted'); console.error('note.IsDeleted');
continue; continue;
@@ -1123,9 +1131,6 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
var newItem = ""; var newItem = "";
var baseClasses = "item-my item-active"; var baseClasses = "item-my item-active";
if(isShare) {
baseClasses = "item-shared";
}
var notebook = Notebook.getNotebook(notebookId); var notebook = Notebook.getNotebook(notebookId);
var notebookTitle = notebook ? notebook.Title : ""; var notebookTitle = notebook ? notebook.Title : "";
@@ -1177,12 +1182,14 @@ Note.showSpin = function() {
me._syncRefreshE.addClass('fa-spin'); me._syncRefreshE.addClass('fa-spin');
// 如果超过30秒还在转, 证明有问题了 // 如果超过30秒还在转, 证明有问题了
/*
setTimeout(function() { setTimeout(function() {
if(me._syncRefreshE.hasClass('fa-spin')) { if(me._syncRefreshE.hasClass('fa-spin')) {
me._syncRefreshE.removeClass('fa-spin'); me._syncRefreshE.removeClass('fa-spin');
Note.hideSyncProgress(); Note.hideSyncProgress();
} }
}, 30 * 1000); }, 30 * 1000);
*/
// 禁止自动保存 // 禁止自动保存
me.stopInterval(true); me.stopInterval(true);
@@ -1243,17 +1250,33 @@ Note.notLogin = function() {
me.hideSpin(); me.hideSpin();
SyncService.setSyncFinished(); SyncService.setSyncFinished();
me._syncWarningE.data('reason', 'notLogin'); me._syncWarningE.data('reason', 'notLogin');
me._syncWarningE.attr('title', 'You need sign in leanote'); me._syncWarningE.attr('title', getMsg('You need to sign in Leanote'));
};
Note.needUpgradeAccount = function () {
var me = this;
me._syncWarningE.show();
me.hideSpin();
SyncService.setSyncFinished();
me._syncWarningE.data('reason', 'NEED-UPGRADE-ACCOUNT');
me._syncWarningE.attr('title', getMsg('You need to upgrade Leanote account'));
}; };
// 点击感叹号, 处理错误 // 点击感叹号, 处理错误
Note.fixNetOrAuthError = function() { Note.fixNetOrAuthError = function() {
var me = this; var me = this;
var reason = me._syncWarningE.data('reason'); var reason = me._syncWarningE.data('reason');
if(reason == 'unConnected') {
alert('Network error, please check out your network.'); if (reason == 'unConnected') {
alert(getMsg('Network error, please check out your network.'));
} else if(reason == 'notLogin') { } else if(reason == 'notLogin') {
alert(getMsg('You need to sign in Leanote'));
// 弹出登录框登录之, 重新弹出 // 弹出登录框登录之, 重新弹出
window.open('login.html?ref=needLogin'); window.open('login.html?ref=needLogin');
// 需要升级Leanote
} else if (reason == 'NEED-UPGRADE-ACCOUNT') {
alert(getMsg('You need to upgrade Leanote account'));
openExternal('https://leanote.com/pricing#buy');
} }
}; };
@@ -3426,7 +3449,7 @@ Note.updateSync = function(notes) {
var curNotebookIsTrash = Notebook.curNotebookIsTrash(); var curNotebookIsTrash = Notebook.curNotebookIsTrash();
for(var i in notes) { for(var i = 0; i < notes.length; ++i) {
var note = notes[i]; var note = notes[i];
note.InitSync = true; // 需要重新获取内容 note.InitSync = true; // 需要重新获取内容
Note.addNoteCache(note); Note.addNoteCache(note);
@@ -3442,13 +3465,17 @@ Note.updateSync = function(notes) {
Note.reRenderNote(Note.curNoteId); Note.reRenderNote(Note.curNoteId);
} }
var target = $(tt('[noteId="?"]', note.NoteId));
if(target.length) {
target.removeClass('item-dirty');
}
// 设置当前是否是博客 // 设置当前是否是博客
// alert(note.NoteId + " " + note.IsBlog); // alert(note.NoteId + " " + note.IsBlog);
Note.setNoteBlogVisible(note.NoteId, note.IsBlog); Note.setNoteBlogVisible(note.NoteId, note.IsBlog);
// 如果是trash, 且当前不在trash目录下, 且有该笔记, 则删除之 // 如果是trash, 且当前不在trash目录下, 且有该笔记, 则删除之
if(!curNotebookIsTrash && note.IsTrash) { if(!curNotebookIsTrash && note.IsTrash) {
var target = $(tt('[noteId="?"]', note.NoteId));
// 前端缓存也要删除!! // 前端缓存也要删除!!
// 先删除, 不然changeToNext()之前会先保存现在的, 导致僵尸note // 先删除, 不然changeToNext()之前会先保存现在的, 导致僵尸note
Note.deleteCache(note.NoteId) Note.deleteCache(note.NoteId)
@@ -3512,4 +3539,18 @@ Note.deleteSync = function(notes) {
// 前端缓存也要删除!! // 前端缓存也要删除!!
Note.deleteCache(noteId); Note.deleteCache(noteId);
} }
} };
// 发送改变成功了的
Note.updateChangeUpdates = function (notes) {
if(isEmpty(notes)) {
return;
}
for(var i in notes) {
var note = notes[i];
var target = $(tt('[noteId="?"]', note.NoteId));
if(target.length) {
target.removeClass('item-dirty');
}
}
};

View File

@@ -2153,6 +2153,13 @@ function userMenu(allUsers) {
} }
}); });
this.debug = new gui.MenuItem({
label: getMsg('Toggle DevTools'),
click: function(e) {
gui.win.toggleDevTools();
}
});
this.menu.append(this.email); this.menu.append(this.email);
if (!UserInfo.IsLocal) {//hide sync menu for local account if (!UserInfo.IsLocal) {//hide sync menu for local account
this.blog = new gui.MenuItem({ this.blog = new gui.MenuItem({
@@ -2231,6 +2238,11 @@ function userMenu(allUsers) {
} }
} }
// debug
mores.append(new gui.MenuItem({ type: 'separator' }));
mores.append(this.debug);
// 更多 // 更多
this.more = new gui.MenuItem({ this.more = new gui.MenuItem({
label: getMsg('More...'), label: getMsg('More...'),

View File

@@ -317,5 +317,10 @@
"Close": "关闭", "Close": "关闭",
"Snippet view": "摘要视图", "Snippet view": "摘要视图",
"List view": "列表视图" "List view": "列表视图",
"Network error, please check out your network.": "网络异常, 请检查网络或稍后再试",
"You need to sign in Leanote": "您需要重新登录Leanote",
"You need to upgrade Leanote account": "同步失败, 帐户已到期或流量已用完, 您需要升级Leanote帐户"
} }

View File

@@ -524,6 +524,33 @@ h3 {
} }
} }
.item-dirty {
.dirty-bg {
position: absolute;
right: 0;
bottom: 0;
z-index: 1;
width: 0;
height: 0;
border-top: 29px solid transparent;
border-right: 23px solid #040421;
}
&::after {
content: "\f093";
position: absolute;
right: 1px;
bottom: 1px;
z-index: 2;
color: #FFF;
/* font-size: 5px; */
font: normal normal normal 14px/1 FontAwesome;
/* font-size: inherit; */
text-rendering: auto;
-webkit-font-smoothing: antialiased;
}
}
#noteItemList { #noteItemList {
user-select: none; user-select: none;
-webkit-user-select: none; -webkit-user-select: none;
@@ -560,6 +587,7 @@ h3 {
.item-setting { .item-setting {
bottom: 0; bottom: 0;
display: none; display: none;
z-index: 3;
} }
.item-star { .item-star {
bottom: 0; bottom: 0;

View File

@@ -557,7 +557,7 @@ a.raw:hover {
display: none; display: none;
padding: 0; padding: 0;
border: none; border: none;
background-color: @bgColor; background: none;
&:focus { &:focus {
outline: none; outline: none;
} }

View File

@@ -482,3 +482,7 @@ textarea#wmd-input {
background-color: rgb(101, 189, 119, 0.9); background-color: rgb(101, 189, 119, 0.9);
} }
} }
#tagInput {
color: #fff;
}