sync, 当前笔记冲突问题

sync当前笔记时,
1) 把服务器上的content->本地
2) changeNote此时会触发saveContent, 此时拿之前的content与新的content对比, 所以导致isDirty
This commit is contained in:
life
2015-03-14 14:17:02 +08:00
parent 3a78cca916
commit 2b809fd377
17 changed files with 189 additions and 81 deletions

5
node_modules/evt.js generated vendored
View File

@@ -16,8 +16,9 @@ if(!fs.existsSync(dataBasePath)) {
// dataBasePath = ''; // dataBasePath = '';
var Evt = { var Evt = {
leanoteUrl: 'http://leanote.com', // leanoteUrl: 'http://leanote.com',
// leanoteUrl: 'http://127.0.0.1:9000', leanoteUrl: 'http://localhost:9000',
port: 8008, port: 8008,
localUrl: 'http://127.0.0.1:8008', localUrl: 'http://127.0.0.1:8008',
dataBasePath: '', dataBasePath: '',

5
node_modules/note.js generated vendored
View File

@@ -117,6 +117,11 @@ var Note = {
console.error(isDirty); console.error(isDirty);
updates['IsDirty'] = isDirty; updates['IsDirty'] = isDirty;
if(isDirty) {
console.error("NONO----------");
Web.alertWeb("NONO");
}
updates['LocalIsDelete'] = false; updates['LocalIsDelete'] = false;
updates.UpdatedTime = date; updates.UpdatedTime = date;

View File

@@ -19,7 +19,7 @@
<!-- theme --> <!-- theme -->
<link rel="stylesheet" href="public/css/theme/simple.css" type="text/css"/> <link rel="stylesheet" href="public/css/theme/simple.css" type="text/css"/>
<link rel="stylesheet" href="public/css/theme/ok.css" type="text/css" id="theme"/> <link rel="stylesheet" href="" type="text/css" id="theme"/>
<link rel="stylesheet" href="public/css/theme/presentation.css" type="text/css" disabled id="themePresentation"/> <link rel="stylesheet" href="public/css/theme/presentation.css" type="text/css" disabled id="themePresentation"/>
<link rel="stylesheet" href="public/css/theme/writting.css" type="text/css" disabled id="themeWritting"/> <link rel="stylesheet" href="public/css/theme/writting.css" type="text/css" disabled id="themeWritting"/>

View File

@@ -5,9 +5,9 @@
"main": "note.html", "main": "note.html",
"window": { "window": {
"icon": "public/images/logo/leanote_icon_blue.png", "icon": "public/images/logo/leanote_icon_blue.png",
"toolbar": false, "toolbar": true,
"frame": false, "frame": true,
"transparent": true, "transparent": true,
"min_width": 258, "min_width": 258,

View File

@@ -19,8 +19,13 @@
width: 100px; width: 100px;
padding: 20px; padding: 20px;
} }
&.loading { &.loading {
animation: rond 2s infinite; animation: rond 2s infinite;
-webkit-animation: rond 2s infinite; -webkit-animation: rond 2s infinite;
} }
} }
.loading-spin {
animation: rond 2s infinite;
-webkit-animation: rond 2s infinite;
}

View File

@@ -30,6 +30,10 @@
animation: rond 2s infinite; animation: rond 2s infinite;
-webkit-animation: rond 2s infinite; -webkit-animation: rond 2s infinite;
} }
.loading-spin {
animation: rond 2s infinite;
-webkit-animation: rond 2s infinite;
}
@font-face { @font-face {
font-family: 'Open Sans'; font-family: 'Open Sans';
font-style: normal; font-style: normal;

View File

@@ -1,6 +1,6 @@
#leftNotebook { #leftNotebook {
background: none !important; background: none !important;
background-color: rgba(37, 49, 62, 0.9) !important; background-color: rgba(37, 49, 62, 0.96) !important;
} }
.folderHeader .fa-left, .folderHeader .fa-left,
.folderHeader span { .folderHeader span {
@@ -12,6 +12,10 @@
#notebookList { #notebookList {
border-top: none; border-top: none;
} }
#notebookList input {
background: transparent;
color: #fff;
}
.folderBody a:hover { .folderBody a:hover {
background-color: transparent !important; background-color: transparent !important;
font-weight: bold; font-weight: bold;

View File

@@ -1,6 +1,6 @@
#leftNotebook { #leftNotebook {
background: none !important; background: none !important;
background-color: rgba(37,49,62, 0.9) !important; background-color: rgba(37,49,62, 0.96) !important;
// background: url(images/mohu.png) !important; // background: url(images/mohu.png) !important;
// background-repeat: repeat; // background-repeat: repeat;
} }
@@ -13,6 +13,12 @@
} }
#notebookList { #notebookList {
border-top: none; border-top: none;
// 添加笔记本框
input {
background: transparent;
color: #fff;
}
} }
.folderBody a:hover { .folderBody a:hover {
background-color: transparent !important; background-color: transparent !important;

View File

@@ -1,6 +1,6 @@
#leftNotebook { #leftNotebook {
background: none !important; background: none !important;
background-color: rgba(40, 167, 233, 0.9) !important; background-color: rgba(40, 167, 233, 0.96) !important;
} }
.folderHeader .fa-left, .folderHeader .fa-left,
.folderHeader span { .folderHeader span {
@@ -12,6 +12,10 @@
#notebookList { #notebookList {
border-top: none; border-top: none;
} }
#notebookList input {
background: transparent;
color: #fff;
}
.folderBody a:hover { .folderBody a:hover {
background-color: transparent !important; background-color: transparent !important;
font-weight: bold; font-weight: bold;

View File

@@ -1,6 +1,6 @@
#leftNotebook { #leftNotebook {
background: none !important; background: none !important;
background-color: rgba(40,167,233, 0.9) !important; background-color: rgba(40,167,233, 0.96) !important;
// background: url(images/mohu.png) !important; // background: url(images/mohu.png) !important;
// background-repeat: repeat; // background-repeat: repeat;
} }
@@ -13,6 +13,11 @@
} }
#notebookList { #notebookList {
border-top: none; border-top: none;
// 添加笔记本框
input {
background: transparent;
color: #fff;
}
} }
.folderBody a:hover { .folderBody a:hover {
background-color: transparent !important; background-color: transparent !important;

View File

@@ -29,6 +29,9 @@ body {
#presentation svg { #presentation svg {
border-radius: 5px; border-radius: 5px;
} }
#presentation a {
color: #2a6496;
}
#presentation.writting, #presentation.writting,
#presentation.black { #presentation.black {
background-color: #F9F9F5; background-color: #F9F9F5;

View File

@@ -34,6 +34,10 @@ body {
border-radius: 5px; border-radius: 5px;
} }
a {
color: #2a6496;
}
&.writting, &.black { &.writting, &.black {
background-color: #F9F9F5; background-color: #F9F9F5;
@@ -73,6 +77,7 @@ body {
&.black { &.black {
background-color: #000; background-color: #000;
color: #fff; color: #fff;
blockquote { blockquote {
background-color: rgba(192, 182, 182, 0.5); background-color: rgba(192, 182, 182, 0.5);
border-left-color: #988F8F; border-left-color: #988F8F;

View File

@@ -1622,6 +1622,10 @@ body.init #pageInner {
animation: rond 2s infinite; animation: rond 2s infinite;
-webkit-animation: rond 2s infinite; -webkit-animation: rond 2s infinite;
} }
.loading-spin {
animation: rond 2s infinite;
-webkit-animation: rond 2s infinite;
}
::selection { ::selection {
background: #000000; background: #000000;
color: #ffffff; color: #ffffff;

View File

@@ -27,11 +27,11 @@ body.writting #note #mdEditor {
bottom: 0; bottom: 0;
} }
body.writting #note #editor { body.writting #note #editor {
background-color: #fbfcf7; background-color: #f2f2f2;
} }
body.writting #note #editorContentWrap { body.writting #note #editorContentWrap {
position: absolute; position: absolute;
padding: 5px 0; padding: 10px 0;
top: 40px; top: 40px;
left: 0; left: 0;
right: 0; right: 0;
@@ -44,10 +44,11 @@ body.writting #note #editorContent {
margin: auto; margin: auto;
background-color: #fff; background-color: #fff;
top: 0 !important; top: 0 !important;
border-radius: 5px; border-radius: 0px;
min-height: 100%; min-height: 100%;
box-shadow: 0 1px 10px #ccc; box-shadow: 0 1px 10px #ccc;
font-size: 16px; font-size: 16px;
padding: 50px;
} }
body.writting #note #editorContent p { body.writting #note #editorContent p {
margin: 10px 0; margin: 10px 0;
@@ -101,6 +102,10 @@ body.writting #editor.all-tool #editorContentWrap {
} }
.mce-btn { .mce-btn {
background-color: #fbfcf7 !important; background-color: #fbfcf7 !important;
overflow: hidden;
}
.mce-btn button span {
overflow: hidden;
} }
.mce-menubtn.mce-btn-small span { .mce-menubtn.mce-btn-small span {
line-height: 20px !important; line-height: 20px !important;
@@ -140,3 +145,6 @@ body.writting #editor.all-tool #editorContentWrap {
font-size: 16px; font-size: 16px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
} }
.pren-tool {
right: 6px;
}

View File

@@ -43,11 +43,12 @@ body.writting {
} }
#editor { #editor {
background-color: @bgColor; // background-color: @bgColor;
background-color: rgba(242,242,242,1);
} }
#editorContentWrap { #editorContentWrap {
position: absolute; position: absolute;
padding: 5px 0; padding: 10px 0;
top: 40px; top: 40px;
left: 0; left: 0;
right: 0; right: 0;
@@ -61,10 +62,11 @@ body.writting {
background-color: #fff; background-color: #fff;
top: 0 !important; top: 0 !important;
// margin-top: 5px; // margin-top: 5px;
border-radius: 5px; border-radius: 0px;
min-height: 100%; min-height: 100%;
box-shadow: 0 1px 10px #ccc; box-shadow: 0 1px 10px #ccc;
font-size: 16px; font-size: 16px;
padding: 50px;
p { p {
margin: 10px 0; margin: 10px 0;
} }
@@ -129,7 +131,15 @@ body.writting {
} }
.mce-btn { .mce-btn {
background-color: @bgColor !important; background-color: @bgColor !important;
overflow: hidden;
button {
span {
// windows, linux下有滚动
overflow: hidden;
} }
}
}
.mce-menubtn.mce-btn-small span { .mce-menubtn.mce-btn-small span {
line-height: 20px !important; line-height: 20px !important;
} }
@@ -166,3 +176,8 @@ body.writting {
font-size: 16px; font-size: 16px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
} }
// 为了滚动条能拖动
.pren-tool {
right: 6px;
}

View File

@@ -280,13 +280,16 @@ Note.curHasChanged = function(force) {
if(hasChanged.IsNew) { if(hasChanged.IsNew) {
$.extend(hasChanged, cacheNote); $.extend(hasChanged, cacheNote);
} else { } else {
/*
if(!cacheNote.isDirty) { // 不是dirty if(!cacheNote.isDirty) { // 不是dirty
// dirty操作在后台控制吧, 因为有些命令如添加链接不会触发keydown的
console.log("no dirty"); console.log("no dirty");
hasChanged.hasChanged = false; hasChanged.hasChanged = false;
return hasChanged; return hasChanged;
} else { } else {
console.log("is dirty"); // console.log("is dirty");
} }
*/
} }
if(cacheNote.Title != title) { if(cacheNote.Title != title) {
@@ -474,6 +477,10 @@ Note.curChangedSaveIt = function(force, callback) {
me.saveInProcess[hasChanged.NoteId] = true; me.saveInProcess[hasChanged.NoteId] = true;
// console.error('保存当前的笔记: ' + hasChanged.NoteId); // console.error('保存当前的笔记: ' + hasChanged.NoteId);
//
console.error("why====================");
console.trace("why");
NoteService.updateNoteOrContent(hasChanged, function(ret) { NoteService.updateNoteOrContent(hasChanged, function(ret) {
me.saveInProcess[hasChanged.NoteId] = false; me.saveInProcess[hasChanged.NoteId] = false;
@@ -728,7 +735,23 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
// console.trace(); // console.trace();
Service.noteService.getNoteContent(cacheNote.NoteId, setContent); // ajaxGet(url, param, setContent); Service.noteService.getNoteContent(cacheNote.NoteId, setContent); // ajaxGet(url, param, setContent);
};
// 重新渲染笔记, 因为sync更新了
Note.reRenderNote = function(noteId) {
var me = this;
me.showContentLoading();
var note = Note.getNote(noteId);
Note.renderNote(note);
NoteService.getNoteContent(noteId, function(noteContent) {
if(noteContent) {
Note.setNoteCache(noteContent, false);
Attach.renderNoteAttachNum(noteId, true);
Note.renderNoteContent(noteContent);
} }
me.hideContentLoading();
});
};
// 渲染 // 渲染
@@ -1194,7 +1217,6 @@ Note.saveNote = function(e) {
} else { } else {
} }
// copy, paste // copy, paste
if(e.ctrlKey || e.metaKey) { if(e.ctrlKey || e.metaKey) {
if(num == 67) { // ctrl + c if(num == 67) { // ctrl + c
@@ -1932,7 +1954,7 @@ Note.contentSynced = function(noteId, content) {
if(me.curNoteId == noteId || me.inChangeNoteId == noteId) { if(me.curNoteId == noteId || me.inChangeNoteId == noteId) {
// alert(note.Title); // alert(note.Title);
// 重新渲染 // 重新渲染
Note.changeNote(noteId); Note.reRenderNote(noteId);
} else { } else {
// 生成desc // 生成desc
me.renderNoteDesc(note); me.renderNoteDesc(note);
@@ -2716,8 +2738,8 @@ Note.updateSync = function(notes) {
console.log('->>>'); console.log('->>>');
console.log(Note.curNoteId); console.log(Note.curNoteId);
if(Note.curNoteId == note.NoteId) { if(Note.curNoteId == note.NoteId) {
console.log('yes---'); // 这里, 如果当前就是更新的, 则重新render, 有个问题, server新内容已经在服务器上了
Note.changeNote(Note.curNoteId); Note.reRenderNote(Note.curNoteId);
} }
} }
} }

View File

@@ -699,12 +699,16 @@ LeaAce = {
return "leanote_ace_" + (new Date()).getTime() + "_" + this._aceId; return "leanote_ace_" + (new Date()).getTime() + "_" + this._aceId;
}, },
initAce: function(id, val, force) { initAce: function(id, val, force) {
try {
var me = this; var me = this;
if(!force && !me.canAndIsAce()) { if(!force && !me.canAndIsAce()) {
return; return;
} }
me.disableAddHistory(); me.disableAddHistory();
var $pre = $('#' + id); var $pre = $('#' + id);
if($pre.length == 0) {
return;
}
$pre.find('.toggle-raw').remove(); $pre.find('.toggle-raw').remove();
var preHtml = $pre.html(); var preHtml = $pre.html();
@@ -758,6 +762,9 @@ LeaAce = {
me.resetAddHistory(); me.resetAddHistory();
return aceEditor; return aceEditor;
} catch(e) {
}
}, },
clearIntervalForInitAce: null, clearIntervalForInitAce: null,
initAceFromContent: function(editor) { initAceFromContent: function(editor) {
@@ -1485,8 +1492,10 @@ function userMenu() {
// ---------- // ----------
// 全局菜单 // 全局菜单
Pren.init();
var mode = new gui.Menu(); var mode = new gui.Menu();
Pren.init();
mode.append(Pren.pren); mode.append(Pren.pren);
mode.append(Pren.fullScreen); mode.append(Pren.fullScreen);
var modes = new gui.MenuItem({ label: 'Mode', submenu: mode}); var modes = new gui.MenuItem({ label: 'Mode', submenu: mode});
@@ -1568,8 +1577,16 @@ function userMenu() {
var height = 130; var height = 130;
if(!isMac()) { if(!isMac()) {
this.menu.append(new gui.MenuItem({ type: 'separator' })); this.menu.append(new gui.MenuItem({ type: 'separator' }));
this.menu.append(Pren.pren); this.menu.append(Pren.pren);
this.menu.append(Pren.fullScreen); this.menu.append(Pren.fullScreen);
/*
this.menu.append(new gui.MenuItem(
{label: 'Toggle Presentation', click: function() {
// me.togglePren();
}
}));
*/
height = 220; height = 220;
} }