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) { deleteNote: function(noteId, callback) {
Notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) { Notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) {
if(err || !n) { if(err || !n) {

View File

@@ -1454,4 +1454,22 @@ top: 4px;
#noteItemList .item-conflict { #noteItemList .item-conflict {
border: 2px solid #DBB624; 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 { #noteItemList .item-conflict {
border: 2px solid #DBB624; 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 { ::selection {
background: #000000; background: #000000;
color: #ffffff; color: #ffffff;

View File

@@ -1317,6 +1317,20 @@ h3 {
#noteItemList .item-conflict { #noteItemList .item-conflict {
border: 2px solid #DBB624; 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 { ::selection {
background: #000000; background: #000000;
color: #ffffff; color: #ffffff;

View File

@@ -1317,6 +1317,20 @@ h3 {
#noteItemList .item-conflict { #noteItemList .item-conflict {
border: 2px solid #DBB624; 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-face {
font-family: 'Open Sans'; font-family: 'Open Sans';
font-style: normal; font-style: normal;

View File

@@ -1317,6 +1317,20 @@ h3 {
#noteItemList .item-conflict { #noteItemList .item-conflict {
border: 2px solid #DBB624; 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-face {
font-family: 'Open Sans'; font-family: 'Open Sans';
font-style: normal; font-style: normal;

View File

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

View File

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

View File

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