完成热门书签的搜索
This commit is contained in:
parent
8ea3763c01
commit
a0285cf340
|
|
@ -609,8 +609,6 @@ db.getBookmarksByTag = 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";
|
||||
|
||||
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) {
|
||||
return db.getBookmarksTable(user_id);
|
||||
}
|
||||
|
|
@ -790,7 +848,7 @@ db.addHotBookmark = function(bookmark) {
|
|||
};
|
||||
|
||||
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) {
|
||||
client.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
|
|
|
|||
|
|
@ -122,10 +122,10 @@ app.controller('hotCtr', ['$scope', '$state', '$stateParams', '$filter', '$windo
|
|||
var login = (menusScope && menusScope.login) || false;
|
||||
if (login) {
|
||||
$scope.random = true;
|
||||
var beginDay = new Date(2016, 7, 15); // 注意日期是从0 ~ 11
|
||||
var beginDay = new Date(2016, 7, 15); // 注意日期是从0 ~ 11
|
||||
var now = new Date();
|
||||
var dayGap = parseInt(Math.abs(now - beginDay) / (1000 * 60 * 60 * 24)) + 1;
|
||||
$scope.curDay = -(parseInt(Math.random() * 1000000) % dayGap);
|
||||
$scope.curDay = -(parseInt(Math.random() * 1000000) % dayGap);
|
||||
$scope.bookmarks = [];
|
||||
getHotBookmarks();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
$scope.inputPage = '';
|
||||
$scope.loading = false;
|
||||
$scope.waitDelBookmark = {};
|
||||
$scope.searchHotBookmarks = false;
|
||||
|
||||
$scope.changeCurrentPage = function(currentPage) {
|
||||
currentPage = parseInt(currentPage) || 0;
|
||||
|
|
@ -222,18 +223,43 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
function searchBookmarks(params) {
|
||||
$scope.loading = true;
|
||||
$('.js-table-search').transition('hide');
|
||||
bookmarkService.searchBookmarks(params)
|
||||
.then((data) => {
|
||||
$scope.bookmarks = data.bookmarks;
|
||||
$scope.bookmarkCount = data.totalItems;
|
||||
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems);
|
||||
$scope.loading = false;
|
||||
transition();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('getBookmarks err', err);
|
||||
$scope.loading = false;
|
||||
});
|
||||
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)
|
||||
.then((data) => {
|
||||
$scope.bookmarks = data.bookmarks;
|
||||
$scope.bookmarkCount = data.totalItems;
|
||||
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems);
|
||||
$scope.loading = false;
|
||||
transition();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('getBookmarks err', err);
|
||||
$scope.loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function animation() {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ app.directive('jsDropdownUserRangeInit', function($compile, $timeout) {
|
|||
onChange: function(value, text, $choice) {
|
||||
$timeout(function() {
|
||||
$scope.showTags = (value == '1');
|
||||
$scope.searchHotBookmarks = (value == '3');
|
||||
$scope.bookmarks = [];
|
||||
$scope.totalPages = 0
|
||||
})
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -150,6 +150,20 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
|
|||
});
|
||||
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) {
|
||||
var def = $q.defer();
|
||||
|
||||
|
|
|
|||
|
|
@ -13,63 +13,60 @@
|
|||
<div class="ui vertically divided grid">
|
||||
<div class="one column row">
|
||||
<div class="column">
|
||||
<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="点击跳转到原页面">
|
||||
<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 class="two column row">
|
||||
<div class="column">
|
||||
<i class="add to calendar icon"></i>创建日期:{{bookmark.created_at}}
|
||||
</div>
|
||||
<div class="column">
|
||||
<i class="calendar icon"></i>最后点击:{{bookmark.last_click}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="two column row">
|
||||
<div class="column" ng-if="bookmark.click_count">
|
||||
<i class="hand pointer icon"></i>点击次数:{{bookmark.click_count}}
|
||||
</div>
|
||||
<div class="column" ng-if="bookmark.fav_count">
|
||||
<i class="heart icon"></i>收藏人数:{{bookmark.fav_count}}
|
||||
</div>
|
||||
<div class="column">
|
||||
<i class="tags icon"></i>书签分类:
|
||||
<div class="ui label" ng-repeat="tag in bookmark.tags">
|
||||
{{ tag.name }}
|
||||
<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="点击跳转到原页面">
|
||||
<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 class="two column row">
|
||||
<div class="column">
|
||||
<i class="add to calendar icon"></i>创建日期:{{bookmark.created_at}}
|
||||
</div>
|
||||
<div class="column">
|
||||
<i class="calendar icon"></i>最后点击:{{bookmark.last_click}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="two column row">
|
||||
<div class="column" ng-if="bookmark.click_count">
|
||||
<i class="hand pointer icon"></i>点击次数:{{bookmark.click_count}}
|
||||
</div>
|
||||
<div class="column" ng-if="bookmark.fav_count">
|
||||
<i class="heart icon"></i>收藏人数:{{bookmark.fav_count}}
|
||||
</div>
|
||||
<div class="column" ng-if="!bookmark.created_by">
|
||||
<i class="tags icon"></i>书签分类:
|
||||
<div class="ui label" ng-repeat="tag in bookmark.tags">
|
||||
{{ tag.name }}
|
||||
</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>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
<div class="content" style="padding:0 0 0 20px">
|
||||
<div class="description">
|
||||
<div class="ui header">
|
||||
描述信息
|
||||
<div class="ui divider"></div>
|
||||
<div class="content" style="padding:0 0 0 20px">
|
||||
<div class="description">
|
||||
<div class="ui header">
|
||||
描述信息
|
||||
</div>
|
||||
<p ng-bind-html="bookmark.description"></p>
|
||||
</div>
|
||||
</div>
|
||||
<p ng-bind-html="bookmark.description"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
<div class="content" style="padding:0 0 0 20px">
|
||||
<div class="description">
|
||||
<div class="ui header">
|
||||
内容摘抄
|
||||
<div class="ui divider"></div>
|
||||
<div class="content" style="padding:0 0 0 20px">
|
||||
<div class="description">
|
||||
<div class="ui header">
|
||||
内容摘抄
|
||||
</div>
|
||||
<p ng-bind-html="content"></p>
|
||||
<img class="ui centered medium image" src="/images/loading.gif" ng-show="loading">
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui right button" ng-click="jumpToUrl(bookmark.url, bookmark.id)">跳转到原页面</div>
|
||||
<button class="positive ui right button">关闭页面</button>
|
||||
</div>
|
||||
<p ng-bind-html="content"></p>
|
||||
<img class="ui centered medium image" src="/images/loading.gif" ng-show="loading">
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui right button" ng-click="jumpToUrl(bookmark.url, bookmark.id)">跳转到原页面</div>
|
||||
<button class="positive ui right button">关闭页面</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
<div class="menu">
|
||||
<div class="active item" data-value="1">自己书签</div>
|
||||
<div class="item" data-value="2">全站书签</div>
|
||||
<div class="item" data-value="3">热门收藏</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -85,7 +86,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<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">
|
||||
</div>
|
||||
<div class="ui grid container" style="padding-top: 8px;">
|
||||
|
|
@ -120,17 +121,30 @@
|
|||
<tr>
|
||||
<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:150px;">分类</th>
|
||||
<th style="width:150px;">{{ searchHotBookmarks ? '来源信息' : '分类'}}</th>
|
||||
<th style="width:88px;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="bookmark in bookmarks" id="{{ bookmark.id }}">
|
||||
<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;">
|
||||
{{ bookmark.title }}
|
||||
</span>
|
||||
|
|
@ -138,13 +152,22 @@
|
|||
<td>
|
||||
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="searchurl{{bookmark.id}}" style="cursor:default;">{{ bookmark.url }}</span>
|
||||
</td>
|
||||
<td>{{ bookmark.click_count }}</td>
|
||||
<td>{{ bookmark.created_at }}</td>
|
||||
<td>{{ bookmark.last_click }}</td>
|
||||
<td>{{ bookmark.click_count || bookmark.fav_count }}</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 }}
|
||||
</div>
|
||||
<span ng-if="searchHotBookmarks">
|
||||
{{ bookmark.created_by }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span ng-show="bookmark.own">
|
||||
|
|
|
|||
|
|
@ -484,6 +484,20 @@ api.get('/searchBookmarks', function(req, res) {
|
|||
.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) {
|
||||
if (!req.session.user) {
|
||||
res.send(401);
|
||||
|
|
@ -1024,7 +1038,7 @@ api.getFaviconByTimer = function() {
|
|||
|
||||
api.getHotBookmarksByTimer = function() {
|
||||
console.log('getHotBookmarks...........');
|
||||
var timeout = 1000 * 60 * 10; // 10分钟更新一遍
|
||||
var timeout = 1000 * 60 * 10; // 10分钟更新一遍
|
||||
var busy = false;
|
||||
setInterval(function() {
|
||||
if (busy) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue