完成热门书签的搜索

This commit is contained in:
luchenqun 2017-03-17 23:45:59 +08:00
parent 8ea3763c01
commit a0285cf340
8 changed files with 213 additions and 78 deletions

View File

@ -609,8 +609,6 @@ db.getBookmarksByTag = function(params) {
} }
db.getBookmarksSearch = function(params) { db.getBookmarksSearch = function(params) {
params.currentPage = params.currentPage || 1;
params.perPageItems = params.perPageItems || 20;
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"; 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.dateCreate) { if (params.dateCreate) {
@ -671,6 +669,66 @@ db.getBookmarksSearch = function(params) {
}) })
} }
// CREATE TABLE `hot_bookmarks` (
// `id` int(11) NOT NULL AUTO_INCREMENT, -- id(articleId)
// `date` int(11) NOT NULL DEFAULT 0, -- 日期(自己添加)
// `title` varchar(255) DEFAULT NULL, -- 标题(title)
// `description` varchar(4096) DEFAULT NULL, -- 描述(自己添加)
// `url` varchar(1024) DEFAULT NULL, -- 链接(url)
// `fav_count` smallint DEFAULT 1, -- 总共收藏人数(favCount)
// `created_by` varchar(64) DEFAULT NULL, -- 创建者(sourceName)
// `created_at` bigint DEFAULT 0, -- 创建时间(updatetime)
// `last_click` bigint DEFAULT 0, -- 最后一次点击时间(createtime)
// `snap_url` varchar(1024) DEFAULT NULL, -- 截图链接(imageList[0])
// `favicon_url` varchar(1024) DEFAULT NULL, -- icon链接(sourceLogo)
// `status` tinyint(4) DEFAULT '0', -- 状态
// PRIMARY KEY (`id`)
// );
db.getHotBookmarksSearch = function(params) {
var sql = "SELECT id, title, description, url, fav_count, created_by, created_at, last_click, snap_url, favicon_url FROM `hot_bookmarks` WHERE status=0";
if (params.dateCreate) {
var d = new Date();
d.setDate(d.getDate() - parseInt(params.dateCreate));
sql += " AND `created_at` >= '" + d.getTime() + "'"
} else if (params.dateCreateBegin && params.dateCreateEnd) {
var dateCreateBegin = new Date(params.dateCreateBegin + "T00:00:00");
var dateCreateEnd = new Date(params.dateCreateEnd + "T23:59:59");
sql += " AND `created_at` >= '" + dateCreateBegin.getTime() + "' AND `created_at` <= '" + dateCreateEnd.getTime() + "' "
}
if (params.dateClick) {
var d = new Date();
d.setDate(d.getDate() - parseInt(params.dateClick));
sql += " AND `last_click` >= '" + d.getTime() + "'"
} else if (params.dateClickBegin && params.dateClickEnd) {
var dateClickBegin = new Date(params.dateClickBegin + "T00:00:00");
var dateClickEnd = new Date(params.dateClickEnd + "T23:59:59");
sql += " AND `last_click` >= '" + dateClickBegin.getTime() + "' AND `last_click` <= '" + dateClickEnd.getTime() + "' "
}
if (params.searchWord) {
sql += " AND (`title` LIKE '%" + params.searchWord + "%')"
}
sql += " ORDER BY fav_count DESC";
console.log(sql);
return new Promise(function(resolve, reject) {
client.query(sql, (err, result) => {
if (err) {
reject(err);
} else {
params.currentPage = params.currentPage || 1;
params.perPageItems = params.perPageItems || 20;
var searchData = {
totalItems: result.length,
bookmarks: result.splice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems),
}
resolve(searchData);
}
});
})
}
db.getBookmarksCard = function(user_id) { db.getBookmarksCard = function(user_id) {
return db.getBookmarksTable(user_id); return db.getBookmarksTable(user_id);
} }
@ -790,7 +848,7 @@ db.addHotBookmark = function(bookmark) {
}; };
db.hotBookmarks = function(date) { db.hotBookmarks = function(date) {
var sql = "SELECT * FROM `hot_bookmarks` WHERE `date` = "+ date +" AND `status` = 0" var sql = "SELECT * FROM `hot_bookmarks` WHERE `date` = " + date + " AND `status` = 0"
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
client.query(sql, (err, result) => { client.query(sql, (err, result) => {
if (err) { if (err) {

View File

@ -20,6 +20,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.inputPage = ''; $scope.inputPage = '';
$scope.loading = false; $scope.loading = false;
$scope.waitDelBookmark = {}; $scope.waitDelBookmark = {};
$scope.searchHotBookmarks = false;
$scope.changeCurrentPage = function(currentPage) { $scope.changeCurrentPage = function(currentPage) {
currentPage = parseInt(currentPage) || 0; currentPage = parseInt(currentPage) || 0;
@ -222,6 +223,30 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
function searchBookmarks(params) { function searchBookmarks(params) {
$scope.loading = true; $scope.loading = true;
$('.js-table-search').transition('hide'); $('.js-table-search').transition('hide');
if ($scope.searchHotBookmarks) {
console.log(params);
bookmarkService.searchHotBookmarks(params)
.then((data) => {
$scope.bookmarks = [];
data.bookmarks.forEach((bookmark) => {
bookmark.tags = [{
id: -1,
name: bookmark.created_by, // 给转存用
}]
bookmark.created_at = $filter('date')(new Date(bookmark.created_at), "yyyy-MM-dd HH:mm:ss");
bookmark.last_click = $filter('date')(new Date(bookmark.last_click), "yyyy-MM-dd HH:mm:ss");
$scope.bookmarks.push(bookmark);
})
$scope.bookmarkCount = data.totalItems;
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems);
$scope.loading = false;
transition();
})
.catch((err) => {
console.log('searchHotBookmarks err', err);
$scope.loading = false;
});
} else {
bookmarkService.searchBookmarks(params) bookmarkService.searchBookmarks(params)
.then((data) => { .then((data) => {
$scope.bookmarks = data.bookmarks; $scope.bookmarks = data.bookmarks;
@ -235,6 +260,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.loading = false; $scope.loading = false;
}); });
} }
}
function animation() { function animation() {
var data = ['scale', 'fade', 'fade up', 'fade down', 'fade left', 'fade right', 'horizontal flip', var data = ['scale', 'fade', 'fade up', 'fade down', 'fade left', 'fade right', 'horizontal flip',

View File

@ -81,6 +81,9 @@ app.directive('jsDropdownUserRangeInit', function($compile, $timeout) {
onChange: function(value, text, $choice) { onChange: function(value, text, $choice) {
$timeout(function() { $timeout(function() {
$scope.showTags = (value == '1'); $scope.showTags = (value == '1');
$scope.searchHotBookmarks = (value == '3');
$scope.bookmarks = [];
$scope.totalPages = 0
}) })
}, },
}); });

View File

@ -150,6 +150,20 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
}); });
return def.promise; return def.promise;
}, },
searchHotBookmarks: function(params) {
var def = $q.defer();
$http.get('/api/searchHotBookmarks/', {
params: params
})
.success(function(data) {
def.resolve(data);
})
.error(function(data, status) {
def.reject('searchHotBookmarks error');
});
return def.promise;
},
getBookmark: function(params) { getBookmark: function(params) {
var def = $q.defer(); var def = $q.defer();

View File

@ -13,15 +13,9 @@
<div class="ui vertically divided grid"> <div class="ui vertically divided grid">
<div class="one column row"> <div class="one column row">
<div class="column"> <div class="column">
<img <img class="ui middle aligned mini image" ng-src="{{bookmark.favicon_url}}" style="width:16px;height:16px;padding:0;cursor:pointer;" ng-click="jumpToUrl(bookmark.url, bookmark.id)" favicon-err="./images/favicon/{{bookmark.id}}.ico" title="点击跳转到原页面">
class="ui middle aligned mini image" <span ng-click="jumpToUrl(bookmark.url, bookmark.id)" style="cursor:pointer;" title="点击跳转到原页面">网页地址</span><span title="点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="detailurl{{bookmark.id}}" class="urlSpan">{{bookmark.url}}
ng-src="{{bookmark.favicon_url}}" <span></div>
style="width:16px;height:16px;padding:0;cursor:pointer;"
ng-click="jumpToUrl(bookmark.url, bookmark.id)"
favicon-err="./images/favicon/{{bookmark.id}}.ico"
title="点击跳转到原页面">
<span ng-click="jumpToUrl(bookmark.url, bookmark.id)" style="cursor:pointer;" title="点击跳转到原页面">网页地址</span><span title="点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="detailurl{{bookmark.id}}" class="urlSpan">{{bookmark.url}}<span>
</div>
</div> </div>
<div class="two column row"> <div class="two column row">
<div class="column"> <div class="column">
@ -38,12 +32,15 @@
<div class="column" ng-if="bookmark.fav_count"> <div class="column" ng-if="bookmark.fav_count">
<i class="heart icon"></i>收藏人数:{{bookmark.fav_count}} <i class="heart icon"></i>收藏人数:{{bookmark.fav_count}}
</div> </div>
<div class="column"> <div class="column" ng-if="!bookmark.created_by">
<i class="tags icon"></i>书签分类: <i class="tags icon"></i>书签分类:
<div class="ui label" ng-repeat="tag in bookmark.tags"> <div class="ui label" ng-repeat="tag in bookmark.tags">
{{ tag.name }} {{ tag.name }}
</div> </div>
</div> </div>
<div class="column" ng-if="bookmark.created_by">
<i class="heart icon"></i>来源信息:{{bookmark.created_by}}
</div>
</div> </div>
</div> </div>
</div> </div>
@ -72,4 +69,4 @@
<div class="ui right button" ng-click="jumpToUrl(bookmark.url, bookmark.id)">跳转到原页面</div> <div class="ui right button" ng-click="jumpToUrl(bookmark.url, bookmark.id)">跳转到原页面</div>
<button class="positive ui right button">关闭页面</button> <button class="positive ui right button">关闭页面</button>
</div> </div>
</div> </div>

View File

@ -15,6 +15,7 @@
<div class="menu"> <div class="menu">
<div class="active item" data-value="1">自己书签</div> <div class="active item" data-value="1">自己书签</div>
<div class="item" data-value="2">全站书签</div> <div class="item" data-value="2">全站书签</div>
<div class="item" data-value="3">热门收藏</div>
</div> </div>
</div> </div>
</div> </div>
@ -85,7 +86,7 @@
</div> </div>
</div> </div>
<div class="two wide column" ng-show="showSearch"> <div class="two wide column" ng-show="showSearch">
<div class="ui transparent icon input" ng-show="!showTags"> <div class="ui transparent icon input" ng-show="(!showTags) && (!searchHotBookmarks)">
<input class="prompt" type="text" placeholder="用户账号" ng-model="username" ng-keypress="($event.which === 13)?search(1):0"> <input class="prompt" type="text" placeholder="用户账号" ng-model="username" ng-keypress="($event.which === 13)?search(1):0">
</div> </div>
<div class="ui grid container" style="padding-top: 8px;"> <div class="ui grid container" style="padding-top: 8px;">
@ -120,17 +121,30 @@
<tr> <tr>
<th>标题</th> <th>标题</th>
<th>链接</th> <th>链接</th>
<th style="width:90px;">点击次数</th> <th style="width:90px;">{{ searchHotBookmarks ? '收藏人数' : '点击次数'}}</th>
<th style="width:100px;">创建日期</th> <th style="width:100px;">创建日期</th>
<th style="width:100px;">最后点击</th> <th style="width:100px;">最后点击</th>
<th style="width:150px;">分类</th> <th style="width:150px;">{{ searchHotBookmarks ? '来源信息' : '分类'}}</th>
<th style="width:88px;">操作</th> <th style="width:88px;">操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="bookmark in bookmarks" id="{{ bookmark.id }}"> <tr ng-repeat="bookmark in bookmarks" id="{{ bookmark.id }}">
<td> <td>
<img class="ui ui middle aligned tiny image" src="http://g.soz.im/{{bookmark.url}}/cdn.ico" style="width:16px;height:16px;cursor:pointer;" ng-click="jumpToUrl(bookmark.url, bookmark.id)" favicon-err="./images/favicon/{{bookmark.id}}.ico"> <img
class="ui ui middle aligned mini image"
ng-src="{{ bookmark.favicon_url }}"
style="width:16px;height:16px;cursor:pointer;"
ng-click="jumpToUrl(bookmark.url, bookmark.id)"
favicon-err="./images/favicon/{{bookmark.id}}.ico"
ng-if="searchHotBookmarks">
<img
class="ui ui middle aligned mini image"
ng-src="http://g.soz.im/{{bookmark.url}}/cdn.ico"
style="width:16px;height:16px;cursor:pointer;"
ng-click="jumpToUrl(bookmark.url, bookmark.id)"
favicon-err="./images/favicon/{{bookmark.id}}.ico"
ng-if="!searchHotBookmarks">
<span ng-click="jumpToUrl(bookmark.url, bookmark.id)" title="{{bookmark.title}}" style="cursor:pointer;"> <span ng-click="jumpToUrl(bookmark.url, bookmark.id)" title="{{bookmark.title}}" style="cursor:pointer;">
{{ bookmark.title }} {{ bookmark.title }}
</span> </span>
@ -138,13 +152,22 @@
<td> <td>
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="searchurl{{bookmark.id}}" style="cursor:default;">{{ bookmark.url }}</span> <span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="searchurl{{bookmark.id}}" style="cursor:default;">{{ bookmark.url }}</span>
</td> </td>
<td>{{ bookmark.click_count }}</td> <td>{{ bookmark.click_count || bookmark.fav_count }}</td>
<td>{{ bookmark.created_at }}</td>
<td>{{ bookmark.last_click }}</td>
<td> <td>
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}"> <span title="{{bookmark.created_at}}">{{ bookmark.created_at.substr(0, 10) }}
</span>
</td>
<td>
<span title="{{bookmark.last_click}}">{{ bookmark.last_click.substr(0, 10) }}
</span>
</td>
<td>
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-if="!searchHotBookmarks">
{{ tag.name }} {{ tag.name }}
</div> </div>
<span ng-if="searchHotBookmarks">
{{ bookmark.created_by }}
</span>
</td> </td>
<td> <td>
<span ng-show="bookmark.own"> <span ng-show="bookmark.own">

View File

@ -484,6 +484,20 @@ api.get('/searchBookmarks', function(req, res) {
.catch((err) => console.log('bookmarks table or card err', err)) .catch((err) => console.log('bookmarks table or card err', err))
}); });
api.get('/searchHotBookmarks', function(req, res) {
console.log('hello searchHotBookmarks', JSON.stringify(req.query), req.session.username);
if (!req.session.user) {
res.send(401);
return;
}
var params = req.query;
db.getHotBookmarksSearch(params)
.then((searchData) => {
res.json(searchData);
})
.catch((err) => console.log('getHotBookmarksSearch err', err))
});
api.get('/tags', function(req, res) { api.get('/tags', function(req, res) {
if (!req.session.user) { if (!req.session.user) {
res.send(401); res.send(401);