search note by key & tag ok

This commit is contained in:
life
2015-02-11 10:43:58 +08:00
parent 9a6356bd66
commit 225bcd7cf0
9 changed files with 121 additions and 26 deletions

23
node_modules/note.js generated vendored
View File

@@ -145,6 +145,29 @@ var Note = {
});
},
searchNote: function(key, callback) {
var reg = new RegExp(key);
Notes.find({IsTrash: false, LocalIsDelete: false, $or: [{Title: reg}, {Content: reg}]}).sort({'UpdatedTime': -1}).exec(function(err, notes) {
if(!err && notes) {
console.log('search ' + key + ' result: ' + notes.length);
callback(notes);
} else {
callback([]);
}
});
},
searchNoteByTag: function(tag, callback) {
Notes.find({IsTrash: false, LocalIsDelete: false, Tags: {$in: [tag]}}).sort({'UpdatedTime': -1}).exec(function(err, notes) {
if(!err && notes) {
console.log('search by tag: ' + tag + ' result: ' + notes.length);
callback(notes);
} else {
callback([]);
}
});
},
deleteNote: function(noteId, callback) {
Notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) {
if(err || !n) {

View File

@@ -1454,4 +1454,22 @@ top: 4px;
#noteItemList .item-conflict {
border: 2px solid #DBB624;
}
#tagNav {
i, em {
font-style: normal;
}
.tag-delete {
display: none;
font-size: 12px;
}
li:hover {
.tag-delete {
display: inline-block;
}
}
a:hover {
background: none !important;
}
}

View File

@@ -1317,6 +1317,20 @@ h3 {
#noteItemList .item-conflict {
border: 2px solid #DBB624;
}
#tagNav i,
#tagNav em {
font-style: normal;
}
#tagNav .tag-delete {
display: none;
font-size: 12px;
}
#tagNav li:hover .tag-delete {
display: inline-block;
}
#tagNav a:hover {
background: none !important;
}
::selection {
background: #000000;
color: #ffffff;

View File

@@ -1317,6 +1317,20 @@ h3 {
#noteItemList .item-conflict {
border: 2px solid #DBB624;
}
#tagNav i,
#tagNav em {
font-style: normal;
}
#tagNav .tag-delete {
display: none;
font-size: 12px;
}
#tagNav li:hover .tag-delete {
display: inline-block;
}
#tagNav a:hover {
background: none !important;
}
::selection {
background: #000000;
color: #ffffff;

View File

@@ -1317,6 +1317,20 @@ h3 {
#noteItemList .item-conflict {
border: 2px solid #DBB624;
}
#tagNav i,
#tagNav em {
font-style: normal;
}
#tagNav .tag-delete {
display: none;
font-size: 12px;
}
#tagNav li:hover .tag-delete {
display: inline-block;
}
#tagNav a:hover {
background: none !important;
}
@font-face {
font-family: 'Open Sans';
font-style: normal;

View File

@@ -1317,6 +1317,20 @@ h3 {
#noteItemList .item-conflict {
border: 2px solid #DBB624;
}
#tagNav i,
#tagNav em {
font-style: normal;
}
#tagNav .tag-delete {
display: none;
font-size: 12px;
}
#tagNav li:hover .tag-delete {
display: inline-block;
}
#tagNav a:hover {
background: none !important;
}
@font-face {
font-family: 'Open Sans';
font-style: normal;

View File

@@ -1293,6 +1293,8 @@ Note.isSameSearch = function(key) {
return false;
}
// 搜索笔记
Note.searchSeq = 0;
Note.searchNote = function() {
var val = $("#searchNoteInput").val();
if(!val) {
@@ -1304,11 +1306,12 @@ Note.searchNote = function() {
if(Note.isSameSearch(val)) {
return;
}
// 之前有, 还有结束的
if(Note.lastSearch) {
Note.lastSearch.abort();
}
// if(Note.lastSearch) {
// Note.lastSearch.abort();
// }
// 步骤与tag的搜索一样
// 1
@@ -1320,21 +1323,13 @@ Note.searchNote = function() {
// 发送请求之
// 先取消上一个
showLoading();
Note.lastSearch = ajaxPost("/note/searchNote", {key: val}, function(notes) {
Note.searchSeq++;
var t = Note.searchSeq;
NoteService.searchNote(val, function(notes) {
hideLoading();
if(notes) {
// 成功后设为空
Note.lastSearch = null;
// renderNotes只是note列表加载, 右侧笔记详情还没加载
// 这个时候, 定位第一个, 保存之前的,
// 如果: 第一次搜索, renderNotes OK, 还没等到changeNote时
// 第二次搜索来到, Note.curChangedSaveIt();
// 导致没有标题了
// 不是这个原因, 下面的Note.changeNote会导致保存
// 设空, 防止发生上述情况
// Note.curNoteId = "";
if(t == Note.searchSeq && notes) {
Notebook.changeCurNotebookTitle('Search results', false, notes.length);
Note.renderNotes(notes);
if(!isEmpty(notes)) {
Note.changeNote(notes[0].NoteId, false/*, true || Note.isOver2Seconds*/); // isShare, needSaveChanged?, 超过2秒就要保存
@@ -2109,11 +2104,10 @@ $(function() {
//---------------------------
// 搜索, 按enter才搜索
/*
$("#searchNoteInput").on("keyup", function(e) {
Note.searchNote();
});
*/
/*
$("#searchNoteInput").on("keydown", function(e) {
var theEvent = e; // window.event || arguments.callee.caller.arguments[0];
if(theEvent.keyCode == 13 || theEvent.keyCode == 108) {
@@ -2122,6 +2116,7 @@ $(function() {
return false;
}
});
*/
//--------------------
// Note.initContextmenu();

View File

@@ -689,7 +689,7 @@ Notebook.changeNotebook = function(notebookId, callback) {
};
// 改变标签, isStarred是否是星笔记本
Notebook.changeCurNotebookTitle = function(title, isStarred) {
Notebook.changeCurNotebookTitle = function(title, isStarred, subTitle) {
var me = this;
$("#curNotebookForListNote").html(title);
me.isStarred = isStarred;

View File

@@ -261,7 +261,7 @@ Tag.renderTagNav = function(tags) {
}
*/
var classes = Tag.classes[tag] || "label label-default";
$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">? (?)</span> <span class="tag-delete">X</span></li>', tag, classes, text, noteTag.Count));
$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">? <em>(?)</em></span> <i class="tag-delete">X</i></li>', tag, classes, text, noteTag.Count));
}
};
@@ -375,17 +375,20 @@ $(function() {
// 也会把curNoteId清空
Note.clearAll();
$("#tagSearch").html($li.html()).show();
$("#tagSearch .tag-delete").remove();
// $("#tagSearch").html($li.html()).show();
var h = $li.html();
Notebook.changeCurNotebookTitle(h);
$('#curNotebookForListNote').find('i, em').remove();
// $("#tagSearch .tag-delete").remove();
showLoading();
ajaxGet("/note/searchNoteByTags", {tags: [tag]}, function(notes) {
NoteService.searchNoteByTag(tag, function(notes) {
hideLoading();
if(notes) {
// 和note搜索一样
// 设空, 防止发生上述情况
// Note.curNoteId = "";
Note.renderNotes(notes);
if(!isEmpty(notes)) {
Note.changeNote(notes[0].NoteId);