显示全部的表格可以按照点击次数,增加时间,最后点击排序
This commit is contained in:
parent
45411cd86b
commit
1c22f88085
|
|
@ -52,15 +52,15 @@ Date.prototype.format = function(fmt) { //author: meizz
|
||||||
// update delete 返回影响的行数
|
// update delete 返回影响的行数
|
||||||
var db = {
|
var db = {
|
||||||
|
|
||||||
}
|
}
|
||||||
// var sql = "SELECT * FROM `users` WHERE `username` = 'luchenqun1'";
|
// var sql = "SELECT * FROM `users` WHERE `username` = 'luchenqun1'";
|
||||||
// client.query(sql, (err, result) => {
|
// client.query(sql, (err, result) => {
|
||||||
// if (err) {
|
// if (err) {
|
||||||
// console.log(err);
|
// console.log(err);
|
||||||
// } else {
|
// } else {
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
db.addBookmark = function(user_id, bookmark) {
|
db.addBookmark = function(user_id, bookmark) {
|
||||||
var insertSql = "INSERT INTO `bookmarks` (`user_id`, `title`, `description`, `url`, `public`, `click_count`) VALUES ('" + user_id + "', '" + bookmark.title + "', " + client.escape(bookmark.description) + ", '" + bookmark.url + "', '" + bookmark.public + "', '1')";
|
var insertSql = "INSERT INTO `bookmarks` (`user_id`, `title`, `description`, `url`, `public`, `click_count`) VALUES ('" + user_id + "', '" + bookmark.title + "', " + client.escape(bookmark.description) + ", '" + bookmark.url + "', '" + bookmark.public + "', '1')";
|
||||||
|
|
@ -499,13 +499,13 @@ db.getBookmarksNavigate = function(tags) {
|
||||||
// var sql = "SELECT t.id as tag_id, t.name as tag_name, b.* FROM `tags` as t LEFT OUTER JOIN tags_bookmarks as tb ON t.id = tb.tag_id LEFT OUTER JOIN bookmarks as b ON tb.bookmark_id = b.id WHERE t.user_id='" + user_id + "' ORDER BY t.id ASC, b.click_count DESC";
|
// var sql = "SELECT t.id as tag_id, t.name as tag_name, b.* FROM `tags` as t LEFT OUTER JOIN tags_bookmarks as tb ON t.id = tb.tag_id LEFT OUTER JOIN bookmarks as b ON tb.bookmark_id = b.id WHERE t.user_id='" + user_id + "' ORDER BY t.id ASC, b.click_count DESC";
|
||||||
var sql = "";
|
var sql = "";
|
||||||
tags.forEach((tag, index) => {
|
tags.forEach((tag, index) => {
|
||||||
var t = 't' + tag.id;
|
var t = 't' + tag.id;
|
||||||
if (index >= 1) {
|
if (index >= 1) {
|
||||||
sql += " UNION "
|
sql += " UNION "
|
||||||
}
|
}
|
||||||
sql += "(SELECT * FROM ((SELECT t.id AS tag_id, t.`name` as tag_name, t.sort, b.* FROM `tags` as t, `bookmarks`as b, `tags_bookmarks` as tb WHERE t.id = tb.tag_id AND b.id = tb.bookmark_id AND t.id = " + tag.id + " ORDER BY b.click_count DESC LIMIT 0, 16) UNION (SELECT t.id AS tag_id, t.`name` as tag_name, t.sort, b.* FROM `tags` as t, `bookmarks`as b, `tags_bookmarks` as tb WHERE t.id = tb.tag_id AND b.id = tb.bookmark_id AND t.id = " + tag.id + " ORDER BY b.created_at DESC LIMIT 0, 16)) as " + t + " ORDER BY " + t + ".click_count DESC, " + t + ".created_at DESC)";
|
sql += "(SELECT * FROM ((SELECT t.id AS tag_id, t.`name` as tag_name, t.sort, b.* FROM `tags` as t, `bookmarks`as b, `tags_bookmarks` as tb WHERE t.id = tb.tag_id AND b.id = tb.bookmark_id AND t.id = " + tag.id + " ORDER BY b.click_count DESC LIMIT 0, 16) UNION (SELECT t.id AS tag_id, t.`name` as tag_name, t.sort, b.* FROM `tags` as t, `bookmarks`as b, `tags_bookmarks` as tb WHERE t.id = tb.tag_id AND b.id = tb.bookmark_id AND t.id = " + tag.id + " ORDER BY b.created_at DESC LIMIT 0, 16)) as " + t + " ORDER BY " + t + ".click_count DESC, " + t + ".created_at DESC)";
|
||||||
})
|
})
|
||||||
// console.log('getBookmarksNavigate ', sql);
|
// console.log('getBookmarksNavigate ', sql);
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
client.query(sql, (err, result) => {
|
client.query(sql, (err, result) => {
|
||||||
|
|
@ -523,40 +523,42 @@ db.getBookmarksTable = function(params) {
|
||||||
params.currentPage = params.currentPage || 1;
|
params.currentPage = params.currentPage || 1;
|
||||||
params.perPageItems = params.perPageItems || 20;
|
params.perPageItems = params.perPageItems || 20;
|
||||||
|
|
||||||
var sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, ";
|
var sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') as created_at, DATE_FORMAT(last_click, '%Y-%m-%d %H:%i:%s') as last_click FROM `bookmarks` WHERE 1=1";
|
||||||
if (params.showStyle == 'card') {
|
|
||||||
sql += "'%Y-%m-%d %H:%i:%s'";
|
|
||||||
} else {
|
|
||||||
sql += "'%Y-%m-%d'";
|
|
||||||
}
|
|
||||||
sql += ") as created_at, DATE_FORMAT(last_click, '%Y-%m-%d') as last_click FROM `bookmarks` WHERE 1=1";
|
|
||||||
if (user_id) {
|
if (user_id) {
|
||||||
sql += " AND `user_id` = '" + user_id + "'";
|
sql += " AND `user_id` = '" + user_id + "'";
|
||||||
if (params.showStyle == 'card') {
|
|
||||||
sql += " ORDER BY bookmarks.created_at DESC, bookmarks.click_count DESC";
|
|
||||||
} else {
|
|
||||||
sql += " ORDER BY bookmarks.click_count DESC, bookmarks.created_at DESC";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
sql += " LIMIT " + (params.currentPage - 1) * params.perPageItems + ", " + params.perPageItems;
|
var bookmarksClickCount, bookmarksCreatedAt, bookmarksLatestClick;
|
||||||
var totalItems = result.length;
|
result.sort((a, b) => {
|
||||||
console.log(totalItems, sql);
|
var click1 = parseInt(a.click_count);
|
||||||
client.query(sql, (err, result) => {
|
var click2 = parseInt(b.click_count);
|
||||||
if (err) {
|
if (click1 > click2) {
|
||||||
reject(err);
|
return -1;
|
||||||
|
} else if (click1 == click2) {
|
||||||
|
return a.created_at >= b.created_at ? -1 : 1;
|
||||||
} else {
|
} else {
|
||||||
var bookmarksData = {
|
return 1;
|
||||||
totalItems: totalItems,
|
|
||||||
bookmarks: result,
|
|
||||||
}
|
|
||||||
resolve(bookmarksData);
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
bookmarksClickCount = result.slice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems);
|
||||||
|
|
||||||
|
result.sort((a, b) => a.created_at >= b.created_at ? -1 : 1);
|
||||||
|
bookmarksCreatedAt = result.slice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems);
|
||||||
|
|
||||||
|
result.sort((a, b) => a.last_click >= b.last_click ? -1 : 1);
|
||||||
|
bookmarksLatestClick = result.slice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems);
|
||||||
|
|
||||||
|
var bookmarksData = {
|
||||||
|
totalItems: result.length,
|
||||||
|
bookmarksClickCount: bookmarksClickCount,
|
||||||
|
bookmarksCreatedAt: bookmarksCreatedAt,
|
||||||
|
bookmarksLatestClick: bookmarksLatestClick,
|
||||||
|
}
|
||||||
|
resolve(bookmarksData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
||||||
$scope.inputPage = '';
|
$scope.inputPage = '';
|
||||||
$scope.loadBusy = false;
|
$scope.loadBusy = false;
|
||||||
$scope.waitDelBookmark = {};
|
$scope.waitDelBookmark = {};
|
||||||
|
$scope.order = [false, false, false];
|
||||||
|
$scope.order[($stateParams && $stateParams.orderIndex) || 0] = true;
|
||||||
|
$scope.bookmarkData = {};
|
||||||
|
|
||||||
$scope.changeCurrentPage = function(currentPage) {
|
$scope.changeCurrentPage = function(currentPage) {
|
||||||
currentPage = parseInt(currentPage) || 0;
|
currentPage = parseInt(currentPage) || 0;
|
||||||
|
|
@ -163,6 +166,21 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.changeOrder = function(index) {
|
||||||
|
if (index < 0 || index >= $scope.order.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$scope.order = $scope.order.map(() => false);
|
||||||
|
$scope.order[index] = true;
|
||||||
|
if ($scope.order[0]) {
|
||||||
|
$scope.bookmarks = $scope.bookmarkData.bookmarksClickCount;
|
||||||
|
} else if ($scope.order[1]) {
|
||||||
|
$scope.bookmarks = $scope.bookmarkData.bookmarksCreatedAt;
|
||||||
|
} else {
|
||||||
|
$scope.bookmarks = $scope.bookmarkData.bookmarksLatestClick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pubSubService.subscribe('EditCtr.inserBookmarsSuccess', $scope, function(event, data) {
|
pubSubService.subscribe('EditCtr.inserBookmarsSuccess', $scope, function(event, data) {
|
||||||
console.log('subscribe EditCtr.inserBookmarsSuccess', params);
|
console.log('subscribe EditCtr.inserBookmarsSuccess', params);
|
||||||
|
|
||||||
|
|
@ -183,20 +201,29 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
||||||
params.currentPage = $scope.currentPage;
|
params.currentPage = $scope.currentPage;
|
||||||
params.perPageItems = perPageItems;
|
params.perPageItems = perPageItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sendData = {
|
||||||
|
totalItems: 0,
|
||||||
|
bookmarksClickCount: [],
|
||||||
|
bookmarksCreatedAt: [],
|
||||||
|
bookmarksLatestClick: [],
|
||||||
|
}
|
||||||
|
|
||||||
bookmarkService.getBookmarks(params)
|
bookmarkService.getBookmarks(params)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (params.showStyle != 'navigate') {
|
if (params.showStyle != 'navigate') {
|
||||||
|
$scope.bookmarkData = data;
|
||||||
$scope.totalPages = Math.ceil(data.totalItems / perPageItems);
|
$scope.totalPages = Math.ceil(data.totalItems / perPageItems);
|
||||||
if (data.totalItems == 0) {
|
if (data.totalItems == 0) {
|
||||||
toastr.info('您还没有书签,请点击菜单栏的添加按钮进行添加', "提示");
|
toastr.info('您还没有书签,请点击菜单栏的添加按钮进行添加', "提示");
|
||||||
}
|
}
|
||||||
if (params.showStyle == 'card') {
|
if (params.showStyle == 'card') {
|
||||||
data.bookmarks.forEach(bookmark => {
|
data.bookmarksCreatedAt.forEach(bookmark => {
|
||||||
$scope.bookmarks.push(bookmark);
|
$scope.bookmarks.push(bookmark);
|
||||||
})
|
})
|
||||||
$scope.loadBusy = false;
|
$scope.loadBusy = false;
|
||||||
} else {
|
} else {
|
||||||
$scope.bookmarks = data.bookmarks;
|
$scope.changeOrder($scope.order.indexOf(true));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$scope.bookmarks = data;
|
$scope.bookmarks = data;
|
||||||
|
|
@ -243,7 +270,6 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
||||||
}
|
}
|
||||||
|
|
||||||
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',
|
||||||
'vertical flip', 'drop', 'fly left', 'fly right', 'fly up', 'fly down', 'swing left', 'swing right', 'swing up',
|
'vertical flip', 'drop', 'fly left', 'fly right', 'fly up', 'fly down', 'swing left', 'swing right', 'swing up',
|
||||||
'swing down', 'browse', 'browse right', 'slide down', 'slide up', 'slide left', 'slide right'
|
'swing down', 'browse', 'browse right', 'slide down', 'slide up', 'slide left', 'slide right'
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.changeOrder = function(index) {
|
$scope.changeOrder = function(index) {
|
||||||
|
if (index < 0 || index >= $scope.order.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$scope.order = $scope.order.map(() => false);
|
$scope.order = $scope.order.map(() => false);
|
||||||
$scope.order[index] = true;
|
$scope.order[index] = true;
|
||||||
if ($scope.order[0]) {
|
if ($scope.order[0]) {
|
||||||
|
|
@ -63,13 +66,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
|
||||||
bookmarkService.getBookmarksByTag(params)
|
bookmarkService.getBookmarksByTag(params)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
$scope.bookmarkData = data;
|
$scope.bookmarkData = data;
|
||||||
if ($scope.order[0]) {
|
$scope.changeOrder($scope.order.indexOf(true));
|
||||||
$scope.bookmarks = $scope.bookmarkData.bookmarksClickCount;
|
|
||||||
} else if ($scope.order[1]) {
|
|
||||||
$scope.bookmarks = $scope.bookmarkData.bookmarksCreatedAt;
|
|
||||||
} else {
|
|
||||||
$scope.bookmarks = $scope.bookmarkData.bookmarksLatestClick;
|
|
||||||
}
|
|
||||||
$scope.bookmarkCount = $scope.bookmarkData.totalItems;
|
$scope.bookmarkCount = $scope.bookmarkData.totalItems;
|
||||||
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems);
|
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,13 @@
|
||||||
<table class="ui selectable sortable celled table js-table-bookmarks" ng-if="showStyle === 'table'">
|
<table class="ui selectable sortable celled table js-table-bookmarks" ng-if="showStyle === 'table'">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>标题</th>
|
<th style="cursor:default;">标题</th>
|
||||||
<th>链接</th>
|
<th style="cursor:default;">链接</th>
|
||||||
<th style="width:90px;">点击次数</th>
|
<th style="width:90px;" class="sorted" ng-class="{descending: order[0]}" ng-click="changeOrder(0)">点击次数</th>
|
||||||
<th style="width:100px;">创建日期</th>
|
<th style="width:100px;" class="sorted" ng-class="{descending: order[1]}" ng-click="changeOrder(1)">创建日期</th>
|
||||||
<th style="width:100px;">最后点击</th>
|
<th style="width:100px;" class="sorted" ng-class="{descending: order[2]}" ng-click="changeOrder(2)">最后点击</th>
|
||||||
<th style="width:150px;">分类</th>
|
<th style="width:150px;cursor:default;">分类</th>
|
||||||
<th style="width:88px;">操作</th>
|
<th style="width:88px;cursor:default;">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
@ -71,8 +71,14 @@
|
||||||
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="url{{bookmark.id}}" style="cursor:default;">{{ bookmark.url }}</span>
|
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="url{{bookmark.id}}" style="cursor:default;">{{ bookmark.url }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ bookmark.click_count }}</td>
|
<td>{{ bookmark.click_count }}</td>
|
||||||
<td>{{ bookmark.created_at }}</td>
|
<td>
|
||||||
<td>{{ bookmark.last_click }}</td>
|
<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>
|
<td>
|
||||||
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="jumpToTags(tag.id)">
|
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="jumpToTags(tag.id)">
|
||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th style="cursor:default;">标题</th>
|
<th style="cursor:default;">标题</th>
|
||||||
<th style="cursor:default;">链接</th>
|
<th style="cursor:default;">链接</th>
|
||||||
<th style=" width:90px;" class="sorted" ng-class="{descending: order[0]}" ng-click="changeOrder(0)">点击次数</th>
|
<th style="width:90px;" class="sorted" ng-class="{descending: order[0]}" ng-click="changeOrder(0)">点击次数</th>
|
||||||
<th style="width:100px;" class="sorted" ng-class="{descending: order[1]}" ng-click="changeOrder(1)">创建日期</th>
|
<th style="width:100px;" class="sorted" ng-class="{descending: order[1]}" ng-click="changeOrder(1)">创建日期</th>
|
||||||
<th style="width:100px;" class="sorted" ng-class="{descending: order[2]}" ng-click="changeOrder(2)">最后点击</th>
|
<th style="width:100px;" class="sorted" ng-class="{descending: order[2]}" ng-click="changeOrder(2)">最后点击</th>
|
||||||
<th style="width:150px;cursor:default;">分类</th>
|
<th style="width:150px;cursor:default;">分类</th>
|
||||||
|
|
@ -72,8 +72,14 @@
|
||||||
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="tagurl{{bookmark.id}}" style="cursor:default;">{{ bookmark.url }}</span>
|
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.id, bookmark.url)" id="tagurl{{bookmark.id}}" style="cursor:default;">{{ bookmark.url }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ bookmark.click_count }}</td>
|
<td>{{ bookmark.click_count }}</td>
|
||||||
<td><span title="{{bookmark.created_at}}">{{ bookmark.created_at.substr(0, 10) }} </span></td>
|
<td>
|
||||||
<td><span title="{{bookmark.last_click}}">{{ bookmark.last_click.substr(0, 10) }} </span></td>
|
<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>
|
<td>
|
||||||
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="getBookmarks(tag.id, 1)">
|
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="getBookmarks(tag.id, 1)">
|
||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
|
|
|
||||||
|
|
@ -298,20 +298,22 @@ api.get('/bookmarks', function(req, res) {
|
||||||
})
|
})
|
||||||
.catch((err) => console.log('bookmarks navigate err', err));
|
.catch((err) => console.log('bookmarks navigate err', err));
|
||||||
} else {
|
} else {
|
||||||
var bookmarks = [];
|
|
||||||
var tagsBookmarks = [];
|
var tagsBookmarks = [];
|
||||||
var totalItems = 0;
|
|
||||||
var totalItems = 0;
|
|
||||||
var sendData = {
|
var sendData = {
|
||||||
totalItems: totalItems,
|
totalItems: 0,
|
||||||
bookmarks: []
|
bookmarksClickCount: [],
|
||||||
|
bookmarksCreatedAt: [],
|
||||||
|
bookmarksLatestClick: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
params.userId = userId;
|
params.userId = userId;
|
||||||
db.getBookmarksTable(params)
|
db.getBookmarksTable(params)
|
||||||
.then((bookmarksData) => {
|
.then((bookmarksData) => {
|
||||||
bookmarks = bookmarksData.bookmarks;
|
sendData = bookmarksData;
|
||||||
totalItems = bookmarksData.totalItems;
|
var bookmarkIds = []
|
||||||
var bookmarkIds = bookmarks.map((bookmark) => bookmark.id);
|
.concat(sendData.bookmarksClickCount.map((bookmark) => bookmark.id))
|
||||||
|
.concat(sendData.bookmarksCreatedAt.map((bookmark) => bookmark.id))
|
||||||
|
.concat(sendData.bookmarksLatestClick.map((bookmark) => bookmark.id))
|
||||||
return db.getTagsBookmarks(bookmarkIds);
|
return db.getTagsBookmarks(bookmarkIds);
|
||||||
})
|
})
|
||||||
.then((tbs) => {
|
.then((tbs) => {
|
||||||
|
|
@ -319,24 +321,22 @@ api.get('/bookmarks', function(req, res) {
|
||||||
return db.getTags(userId);
|
return db.getTags(userId);
|
||||||
})
|
})
|
||||||
.then((tags) => {
|
.then((tags) => {
|
||||||
var data = [];
|
var objectName = ['bookmarksClickCount', 'bookmarksCreatedAt', 'bookmarksLatestClick'];
|
||||||
// 获取每个书签的所有分类标签
|
objectName.forEach((name) => {
|
||||||
bookmarks.forEach(function(bookmark) {
|
sendData[name].forEach(function(bookmark, index) {
|
||||||
var bookmarkTags = [];
|
var bookmarkTags = [];
|
||||||
tagsBookmarks.forEach(function(tb) {
|
tagsBookmarks.forEach(function(tb) {
|
||||||
if (tb.bookmark_id == bookmark.id) {
|
if (tb.bookmark_id == bookmark.id) {
|
||||||
tags.forEach(function(tag) {
|
tags.forEach(function(tag) {
|
||||||
if (tb.tag_id == tag.id) {
|
if (tb.tag_id == tag.id) {
|
||||||
bookmarkTags.push(tag)
|
bookmarkTags.push(tag)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bookmark.tags = bookmarkTags;
|
sendData[name][index].tags = bookmarkTags;
|
||||||
data.push(bookmark);
|
})
|
||||||
})
|
})
|
||||||
sendData.totalItems = totalItems;
|
|
||||||
sendData.bookmarks = data;
|
|
||||||
res.json(sendData);
|
res.json(sendData);
|
||||||
})
|
})
|
||||||
.catch((err) => console.log('bookmarks table or card err', err))
|
.catch((err) => console.log('bookmarks table or card err', err))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue