搜索做了一部分
This commit is contained in:
parent
20b06fce23
commit
cfb24b1a44
|
|
@ -253,9 +253,15 @@ db.getBookmarksTable = function(user_id) {
|
|||
}
|
||||
|
||||
db.getBookmarksSearch = function(params) {
|
||||
var search_word = params.searchWord;
|
||||
var search_word = params.searchWord || 'test';
|
||||
var user_id = '1';
|
||||
var sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(last_click, '%Y-%m-%d') as last_click FROM `bookmarks` WHERE user_id='" + user_id + "' AND (`title` LIKE '%"+ search_word +"%' OR `url` LIKE '%"+ search_word +"%') ORDER BY click_count DESC, created_at DESC LIMIT 0, 50";
|
||||
var sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(last_click, '%Y-%m-%d') as last_click FROM `bookmarks` WHERE 1=1";
|
||||
if (params.userRange == '1') {
|
||||
if (params.userId) {
|
||||
sql += "AND user_id = '"+ params.userId +"'"
|
||||
}
|
||||
}
|
||||
sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(last_click, '%Y-%m-%d') as last_click FROM `bookmarks` WHERE user_id='" + user_id + "' AND (`title` LIKE '%"+ search_word +"%' OR `url` LIKE '%"+ search_word +"%') ORDER BY click_count DESC, created_at DESC LIMIT 0, 50";
|
||||
console.log(sql);
|
||||
return new Promise(function(resolve, reject) {
|
||||
client.query(sql, (err, result) => {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', 'pubSubService',
|
|||
* @desc 点击搜索按钮搜索书签
|
||||
*/
|
||||
$scope.searchBookmarks = function(searchWord) {
|
||||
console.log(searchWord);
|
||||
$state.go('search', {
|
||||
searchWord: searchWord,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -12,12 +12,24 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
$scope.username = '';
|
||||
$scope.userRange = '';
|
||||
$scope.bookmarkCount = 0;
|
||||
$scope.tags = []
|
||||
|
||||
bookmarkService.getTags({
|
||||
user_id: '1',
|
||||
})
|
||||
.then((data) => {
|
||||
$scope.tags = data;
|
||||
})
|
||||
.catch((err) => console.log('getTags err', err));
|
||||
|
||||
var searchParams = {
|
||||
searchWord: $scope.searchWord,
|
||||
}
|
||||
if ($scope.searchWord) {
|
||||
searchBookmarks(searchParams);
|
||||
} else {
|
||||
|
||||
searchBookmarks(searchParams);
|
||||
}
|
||||
|
||||
$scope.delBookmark = function(bookmarkId) {
|
||||
var params = {
|
||||
|
|
@ -40,11 +52,39 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
}
|
||||
|
||||
$scope.search = function() {
|
||||
var params = {
|
||||
searchWord: $scope.searchWord,
|
||||
var params = {}
|
||||
params.userRange = $('.js-user-range').dropdown('get value');
|
||||
if (params.userRange == '1') {
|
||||
var tags = $('.js-search-tags').dropdown('get value')
|
||||
if (tags) {
|
||||
params.tags = tags;
|
||||
}
|
||||
} else if ($scope.username) {
|
||||
params.username = $scope.username
|
||||
}
|
||||
if ($scope.searchWord) {
|
||||
params.searchWord = $scope.searchWord;
|
||||
}
|
||||
|
||||
|
||||
var dateCreate = $('.js-create-date').dropdown('get value') || undefined;
|
||||
if (dateCreate) {
|
||||
params.dateCreate = dateCreate;
|
||||
} else {
|
||||
params.dateCreateBegin = $scope.dateCreateBegin;
|
||||
params.dateCreateEnd = $scope.dateCreateEnd;
|
||||
}
|
||||
|
||||
var dateClick = $('.js-click-date').dropdown('get value') || undefined;
|
||||
if (dateClick) {
|
||||
params.dateClick = dateClick
|
||||
} else {
|
||||
params.dateClickBegin = $scope.dateClickBegin;
|
||||
params.dateClickEnd = $scope.dateClickEnd;
|
||||
}
|
||||
|
||||
searchBookmarks(params)
|
||||
console.log('search..', $scope.searchWord, $scope.dateBegin, $scope.clickCount, $scope.username, $scope.userRange)
|
||||
console.log('search..', params)
|
||||
}
|
||||
$scope.updateCreateDate = function() {
|
||||
console.log($scope.dateCreateBegin, $scope.dateCreateEnd);
|
||||
|
|
@ -64,6 +104,12 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
}
|
||||
}
|
||||
|
||||
$scope.updateTagsSelect = function() {
|
||||
$('.ui.dropdown.js-search-tags .text').removeClass('default');
|
||||
var text = $('.ui.dropdown.js-search-tags .text').text().replace('selected', '个分类已选');
|
||||
$('.ui.dropdown.js-search-tags .text').text(text);
|
||||
}
|
||||
|
||||
function searchBookmarks(params) {
|
||||
bookmarkService.searchBookmarks(params)
|
||||
.then((data) => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ function date(date, settings) {
|
|||
var day = date.getDate();
|
||||
var month = date.getMonth() + 1;
|
||||
var year = date.getFullYear();
|
||||
return year + '/' + month + '/' + day;
|
||||
return year + '-' + month + '-' + day;
|
||||
};
|
||||
|
||||
app.directive('jsDataCreateInit', function($compile) {
|
||||
|
|
@ -67,26 +67,31 @@ app.directive('jsDataClickInit', function($compile) {
|
|||
};
|
||||
});
|
||||
|
||||
app.directive('jsDropdownUserRangeInit', function($compile) {
|
||||
app.directive('jsDropdownUserRangeInit', function($compile, $timeout) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function($scope, $element, $attrs) {
|
||||
$('.ui.dropdown.js-user-range').dropdown({
|
||||
onChange: function(value, text, $choice) {
|
||||
$scope.showTags = (value === '1');
|
||||
console.log(value, text, $choice, $scope.showTags, $scope.username);
|
||||
$scope.$apply();
|
||||
$timeout(function() {
|
||||
$scope.showTags = (value == '1');
|
||||
})
|
||||
},
|
||||
});
|
||||
$('.js-user-range').dropdown('set value', '1');
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
app.directive('jsDropdownInit', function($compile) {
|
||||
app.directive('jsDropdownTagsInit', function($compile) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function($scope, $element, $attrs) {
|
||||
$('.ui.dropdown').dropdown();
|
||||
$('.ui.dropdown.js-search-tags').dropdown({
|
||||
useLabels: false
|
||||
});
|
||||
|
||||
$('.ui.dropdown.js-search-tags .text').removeClass('default');
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ app.factory('httpInterceptor', ['$q', '$injector', function($q, $injector) {
|
|||
},
|
||||
responseError: function(err) {
|
||||
if (401 === err.status) {
|
||||
toastr.warning("您需要先登录才能使用该功能", "警告");
|
||||
// toastr.warning("您需要先登录才能使用该功能", "警告");
|
||||
$injector.get('$state').go('login', {})
|
||||
} else {
|
||||
toastr.error(JSON.stringify(err), "错误");
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
</div>
|
||||
<div class="two wide column" ng-show="showSearch">
|
||||
<div class="ui dropdown js-user-range" js-dropdown-user-range-init>
|
||||
<div class="text" data-value="1">搜索范围</div>
|
||||
<div class="text">搜索范围</div>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<div class="active item" data-value="1">自己书签</div>
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
<div class="text">创建时间不限</div>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<div class="active item" data-value='0'>时间不限</div>
|
||||
<div class="active item" data-value='0'>创建时间不限</div>
|
||||
<div class="item" data-value='7'>一周内</div>
|
||||
<div class="item" data-value='30'>一月内</div>
|
||||
<div class="item" data-value='365'>一年内</div>
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
<div class="text">点击时间不限</div>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<div class="active item" data-value='0'>时间不限</div>
|
||||
<div class="active item" data-value='0'>点击时间不限</div>
|
||||
<div class="item" data-value='7'>一周内</div>
|
||||
<div class="item" data-value='30'>一月内</div>
|
||||
<div class="item" data-value='365'>一年内</div>
|
||||
|
|
@ -86,28 +86,33 @@
|
|||
<div class="ui transparent icon input" ng-show="!showTags">
|
||||
<input class="prompt" type="text" placeholder="用户账号" ng-model="username">
|
||||
</div>
|
||||
<select class="ui fluid search dropdown" multiple="" ng-show="showTags">
|
||||
<option value="">State</option>
|
||||
<option value="AL">Alabama</option>
|
||||
<option value="AK">Alaska</option>
|
||||
<option value="AZ">Arizona</option>
|
||||
<option value="AR">Arkansas</option>
|
||||
<option value="CA">California</option>
|
||||
<option value="CO">Colorado</option>
|
||||
<option value="CT">Connecticut</option>
|
||||
</select>
|
||||
<div class="ui grid container" style="padding-top: 8px;">
|
||||
<div class="ui multiple dropdown js-search-tags" style="padding:0;" ng-show="showTags" js-dropdown-tags-init>
|
||||
<div class="default text">分类选择</div>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu" ng-click="updateTagsSelect()">
|
||||
<div class="item" data-value='{{tag.id}}' ng-repeat="tag in tags">{{tag.name}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="two wide column" ng-show="showSearch">
|
||||
<div class="three wide column" ng-show="showSearch">
|
||||
<div class="ui transparent input">
|
||||
<input type="text" placeholder="标题,链接..." ng-model="searchWord">
|
||||
</div>
|
||||
</div>
|
||||
<div class="left floated right aligned one wide column" ng-show="showSearch">
|
||||
<i class="search icon" title="搜索" ng-click="search()"></i>
|
||||
</div>
|
||||
|
||||
<div class="left floated right aligned two wide column" ng-show="showSearch">
|
||||
<img class="ui ui middle aligned tiny image" ng-src="./images/hide.png" style="width:16px;height:16px" ng-click="showSearch = !showSearch">
|
||||
<span ng-click="showSearch = !showSearch">收起</span>
|
||||
<div class="ui grid">
|
||||
<div class="four wide column">
|
||||
<i class="search icon" title="搜索" ng-click="search()"></i>
|
||||
</div>
|
||||
<div class="twelve wide column">
|
||||
<img class="ui ui middle aligned tiny image" ng-src="./images/hide.png" style="width:16px;height:16px" ng-click="showSearch = !showSearch">
|
||||
<span ng-click="showSearch = !showSearch">收起</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<table class="ui celled table">
|
||||
|
|
|
|||
|
|
@ -210,12 +210,13 @@ api.get('/bookmarks', function(req, res) {
|
|||
});
|
||||
|
||||
api.get('/searchBookmarks', function(req, res) {
|
||||
console.log('hello bookmarks', JSON.stringify(req.query), req.session.username);
|
||||
console.log('hello searchBookmarks', JSON.stringify(req.query), req.session.username);
|
||||
if (!req.session.username) {
|
||||
res.send(401);
|
||||
return;
|
||||
}
|
||||
var params = req.query;
|
||||
params.userId = req.session.userId;
|
||||
var bookmarks = [];
|
||||
var tagsBookmarks = [];
|
||||
var userId = '1';
|
||||
|
|
|
|||
Loading…
Reference in New Issue