增加转存共嫩,能将搜索到的书签转为自己的书签

This commit is contained in:
luchenqun 2017-03-01 20:27:49 +08:00
parent cdc35c22cd
commit 7ea24707b9
7 changed files with 35 additions and 8 deletions

View File

@ -505,7 +505,7 @@ db.getBookmarksNavigate = function(tags) {
}
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(sql);
// console.log('getBookmarksNavigate ', sql);
return new Promise(function(resolve, reject) {
client.query(sql, (err, result) => {

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

View File

@ -7,7 +7,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
$timeout(function() {
$scope.urlError = $scope.url == '' && $('.ui.modal.js-add-bookmark').modal('is active');
});
if ($scope.add) {
if ($scope.autoGettitle) {
$scope.title = "";
if (/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test(newUrl)) {
var params = {
@ -149,6 +149,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
console.log('getBookmark ', data);
var bookmark = data.bookmark;
$scope.autoGettitle = false;
$scope.id = (bookmark && bookmark.id) || '';
$scope.url = (bookmark && bookmark.url) || '';
$scope.title = (bookmark && bookmark.title) || '';
@ -169,6 +170,22 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
.catch((err) => console.log('updateBookmark err', err));
});
pubSubService.subscribe('TagCtr.storeBookmark', $scope, function(event, bookmark) {
console.log('TagCtr.storeBookmark', bookmark);
$('.ui.modal.js-add-bookmark').modal({
closable: false,
}).modal('show');
$('.ui.modal.js-add-bookmark .ui.dropdown').dropdown('clear');
$('.ui.modal.js-add-bookmark .ui.dropdown').addClass('loading');
$('.ui.checkbox.js-public').checkbox('set checked');
init();
getTags({});
$scope.autoGettitle = false;
$scope.url = bookmark.url;
$scope.title = bookmark.title;
$scope.newTags = bookmark.tags.map((item) => item.name).toString();
});
function getTags(params) {
bookmarkService.getTags(params)
.then((data) => {
@ -202,6 +219,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
function init() {
$scope.add = true;
$scope.autoGettitle = true;
$scope.id = '';
$scope.url = '';
$scope.title = '';

View File

@ -103,6 +103,11 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
pubSubService.publish('TagCtr.showBookmarkInfo', bookmark);
}
$scope.storeBookmark = function(bookmark) {
var b = $.extend(true, {}, bookmark); // 利用jQuery执行深度拷贝
pubSubService.publish('TagCtr.storeBookmark', b);
}
$scope.search = function(page) {
var params = {}
params.userRange = $('.js-user-range').dropdown('get value');

View File

@ -153,6 +153,9 @@
<span ng-show="bookmark.own">
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/edit-bookmark.png" ng-click="editBookmark(bookmark.id)" title="编辑书签">
</span>
<span ng-show="!bookmark.own">
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/store-bookmark.png" ng-click="storeBookmark(bookmark)" title="转存到我的书签">
</span>
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/detail.png" ng-click="detailBookmark(bookmark)" title="书签详情">
</td>
</tr>

View File

@ -231,6 +231,7 @@ api.get('/bookmarks', function(req, res) {
db.getTags(userId)
.then((tags) => db.getBookmarksNavigate(tags))
.then((result) => {
console.log('ddddddddddddd')
var data = [];
var tag = {
id: result && result[0] && result[0].tag_id,
@ -547,13 +548,13 @@ api.post('/uploadBookmarkFile', upload.single('bookmark'), function(req, res) {
var tags = [];
item.tags.forEach((tag) => {
allTags.forEach((at) => {
if (at.name == tag) {
tags.push(at.id);
}
})
allTags.forEach((at) => {
if (at.name == tag) {
tags.push(at.id);
}
})
// 插入书签
})
// 插入书签
db.addBookmark(userId, bookmark) // 插入书签
.then((bookmark_id) => {
db.delBookmarkTags(bookmark_id); // 不管3721先删掉旧的分类