save/recover state

This commit is contained in:
life
2015-03-04 21:50:20 +08:00
parent 5546fbf0fb
commit 918d8c2e40
13 changed files with 315 additions and 43 deletions

17
node_modules/common.js generated vendored
View File

@@ -124,6 +124,23 @@ var Common = {
ret.nameNotExt = ret.name;
}
return ret;
},
// 2014-01-06T18:29:48.802+08:00
goNowToDate: function (goNow) {
if(!goNow) {
return new Date();
}
// new Date();
if(typeof goNow == 'object') {
alert(3);
return date;
}
var str = goNow.substr(0, 10) + " " + goNow.substr(11, 8);
try {
return new Date(str);
} catch(e) {
return new Date();
}
}
};
module.exports = Common;

7
node_modules/evt.js generated vendored
View File

@@ -26,6 +26,9 @@ var Evt = {
getAttachLocalUrl: function(fileId) {
return this.localUrl + '/api/file/getAttach?fileId=' + fileId;
},
getAllAttachLocalUrl: function(noteId) {
return this.localUrl + '/api/file/getAllAttachs?noteId=' + noteId;
},
// 项目绝对地址
getBasePath: function() {
var me = this;
@@ -39,8 +42,8 @@ var Evt = {
},
setDataBasePath: function(dataBasePath) {
var me = this;
console.log('...........')
console.log(dataBasePath);
// console.log('...........')
// console.log(dataBasePath);
me.dataBasePath = dataBasePath;
}
};

23
node_modules/note.js generated vendored
View File

@@ -365,8 +365,9 @@ var Note = {
var reg2 = new RegExp(Evt.leanoteUrl + '/api/file/getAttach', 'g');
content = content.replace(reg2, Evt.localUrl + '/api/file/getAttach');
var reg3 = new RegExp(Evt.leanoteUrl + '/api/file/getAllAttach', 'g');
content = content.replace(reg3, Evt.localUrl + '/api/file/getAllAttach');
// api/file/getAllAttachs?noteId=xxxxxxxxx, 这里的noteId是服务器上的noteId啊
var reg3 = new RegExp(Evt.leanoteUrl + '/api/file/getAllAttachs', 'g');
content = content.replace(reg3, Evt.localUrl + '/api/file/getAllAttachs');
return content;
},
@@ -384,8 +385,8 @@ var Note = {
var reg2 = new RegExp(Evt.localUrl + '/api/file/getAttach', 'g');
content = content.replace(reg2, Evt.leanoteUrl + '/api/file/getAttach');
var reg3 = new RegExp(Evt.localUrl + '/api/file/getAllAttach', 'g');
content = content.replace(reg3, Evt.leanoteUrl + '/api/file/getAllAttach');
var reg3 = new RegExp(Evt.localUrl + '/api/file/getAllAttachs', 'g');
content = content.replace(reg3, Evt.leanoteUrl + '/api/file/getAllAttachs');
return content;
},
@@ -546,6 +547,10 @@ var Note = {
note.NoteId = Common.objectId();
note.LocalIsDelete = false;
console.error('add note' + note.Title + Common.goNowToDate(note.CreatedTime));
note.CreatedTime = Common.goNowToDate(note.CreatedTime);
note.UpdatedTime = Common.goNowToDate(note.UpdatedTime);
// 附件操作
var files = note.Files || [];
var attachs = [];
@@ -567,6 +572,9 @@ var Note = {
console.log(err);
callback && callback(false);
} else {
// console.log("?????????")
// console.log(note);
// console.log(note.CreatedTime);
callback && callback(newDoc);
// 下载内容, 图片, 附件
@@ -660,6 +668,10 @@ var Note = {
console.log(everNote.NoteId);
console.log(everNote);
// 不要服务器上的
delete note['UpdatedTime'];
delete note['CreatedTime'];
Notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional
console.log('re:');
console.log(err);
@@ -740,6 +752,8 @@ var Note = {
console.log(everAttachs);
delete note['Files'];
delete note['UpdatedTime'];
delete note['CreatedTime'];
Notes.update({NoteId: note.NoteId}, {$set: note}, function(err, n) {
if(err || !n) {
@@ -991,7 +1005,6 @@ var Note = {
});
})(i);
}
// 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes

4
node_modules/notebook.js generated vendored
View File

@@ -278,6 +278,10 @@ var Notebook = {
} else {
// 否则, 就用服务器上的
}
notebook.CreatedTime = Common.goNowToDate(notebook.CreatedTime);
notebook.UpdatedTime = Common.goNowToDate(notebook.UpdatedTime);
NB.insert(notebook, function (err, newDoc) { // Callback is optional
if(err) {
console.log(err);

20
node_modules/user.js generated vendored
View File

@@ -227,6 +227,26 @@ User = {
db.g.update({_id: '1'}, {$set: data}, {upsert: true}, function() {
callback && callback();
});
},
/**
* [saveCurState description]
* @param {[type]} state [description]
* @return {[type]} [description]
User.saveCurState({
StarredOpened: StarredOpened,
NotebookOpened: NotebookOpened,
TagOpened: TagOpened,
CurNoteId: CurNoteId,
CurIsStarred: CurIsStarred,
CurNotebookId: CurNotebookId,
CurTag: CurTag
}, callback);
*/
saveCurState: function(state, callback) {
state = state || {};
db.g.update({_id: '1'}, {$set: state}, {upsert: true}, function() {
callback && callback();
});
}
};