增加一键收藏功能
This commit is contained in:
parent
7909209042
commit
a32a1893cb
|
|
@ -307,7 +307,7 @@ db.register = function(user) {
|
||||||
};
|
};
|
||||||
|
|
||||||
db.insertDefaultBookmarks = function(userId) {
|
db.insertDefaultBookmarks = function(userId) {
|
||||||
var tags_name = ["常用", "未分类"];
|
var tags_name = ["常用", "未分类", "收藏"];
|
||||||
|
|
||||||
db.addTags(userId, tags_name)
|
db.addTags(userId, tags_name)
|
||||||
.then((insertId) => {
|
.then((insertId) => {
|
||||||
|
|
@ -315,27 +315,27 @@ db.insertDefaultBookmarks = function(userId) {
|
||||||
title: "谷歌",
|
title: "谷歌",
|
||||||
description: "要翻墙的搜索网站",
|
description: "要翻墙的搜索网站",
|
||||||
url: "https://www.google.com.hk/",
|
url: "https://www.google.com.hk/",
|
||||||
public: "1"
|
public: "0"
|
||||||
}, {
|
}, {
|
||||||
title: "百度",
|
title: "百度",
|
||||||
description: "A:百度一下你会死啊?B:会!",
|
description: "A:百度一下你会死啊?B:会!",
|
||||||
url: "https://www.baidu.com/",
|
url: "https://www.baidu.com/",
|
||||||
public: "1"
|
public: "0"
|
||||||
}, {
|
}, {
|
||||||
title: "微博",
|
title: "微博",
|
||||||
description: "随时随地发现新鲜事",
|
description: "随时随地发现新鲜事",
|
||||||
url: "http://weibo.com/",
|
url: "http://weibo.com/",
|
||||||
public: "1"
|
public: "0"
|
||||||
}, {
|
}, {
|
||||||
title: "天猫",
|
title: "天猫",
|
||||||
description: "上天猫,就够了!",
|
description: "上天猫,就够了!",
|
||||||
url: "https://www.tmall.com/",
|
url: "https://www.tmall.com/",
|
||||||
public: "1"
|
public: "0"
|
||||||
}, {
|
}, {
|
||||||
title: "优酷",
|
title: "优酷",
|
||||||
description: "视频网站",
|
description: "视频网站",
|
||||||
url: "http://www.youku.com/",
|
url: "http://www.youku.com/",
|
||||||
public: "1"
|
public: "0"
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var tags = [insertId];
|
var tags = [insertId];
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 529 B |
Binary file not shown.
|
After Width: | Height: | Size: 438 B |
|
|
@ -94,7 +94,10 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
|
||||||
toastr.error('检撤到您的书签链接非法,是否忘记加http或者https了?建议直接从打开浏览器地址栏复制出来直接粘贴到输入框。', "错误");
|
toastr.error('检撤到您的书签链接非法,是否忘记加http或者https了?建议直接从打开浏览器地址栏复制出来直接粘贴到输入框。', "错误");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (selectedTags.length < 1) {
|
||||||
|
toastr.error('您至少要选择一个分类!如果暂时没想到放到哪个分类,可以先选择未分类', "错误");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ($scope.add) {
|
if ($scope.add) {
|
||||||
bookmarkService.addBookmark(params)
|
bookmarkService.addBookmark(params)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,29 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
pubSubService.publish('TagCtr.storeBookmark', b);
|
pubSubService.publish('TagCtr.storeBookmark', b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.favoriteBookmark = function(b) {
|
||||||
|
var bookmark = {}
|
||||||
|
bookmark.description = '';
|
||||||
|
bookmark.title = b.title;
|
||||||
|
bookmark.url = b.url;
|
||||||
|
bookmark.public = 1;
|
||||||
|
bookmark.click_count = 1;
|
||||||
|
|
||||||
|
bookmarkService.favoriteBookmark(bookmark)
|
||||||
|
.then((data) => {
|
||||||
|
pubSubService.publish('EditCtr.inserBookmarsSuccess', data);
|
||||||
|
if (data.title) {
|
||||||
|
toastr.success('[ ' + data.title + ' ] 收藏成功,将自动重新更新书签!', "提示");
|
||||||
|
} else {
|
||||||
|
toastr.error('[ ' + bookmark.title + ' ] 收藏失败', "提示");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log('favoriteBookmark err', err);
|
||||||
|
toastr.error('[ ' + bookmark.title + ' ] 收藏失败' + JSON.stringify(err), "提示");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$scope.copy = function(id, url) {
|
$scope.copy = function(id, url) {
|
||||||
var clipboard = new Clipboard('#searchurl' + id, {
|
var clipboard = new Clipboard('#searchurl' + id, {
|
||||||
text: function() {
|
text: function() {
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
|
||||||
});
|
});
|
||||||
return def.promise;
|
return def.promise;
|
||||||
},
|
},
|
||||||
|
favoriteBookmark: function(params) {
|
||||||
|
var def = $q.defer();
|
||||||
|
$http.post('/api/favoriteBookmark/', {
|
||||||
|
params: params
|
||||||
|
})
|
||||||
|
.success(function(data) {
|
||||||
|
def.resolve(data);
|
||||||
|
})
|
||||||
|
.error(function(data) {
|
||||||
|
def.reject('favorite error');
|
||||||
|
});
|
||||||
|
return def.promise;
|
||||||
|
},
|
||||||
updateBookmark: function(params) {
|
updateBookmark: function(params) {
|
||||||
var def = $q.defer();
|
var def = $q.defer();
|
||||||
$http.post('/api/updateBookmark/', {
|
$http.post('/api/updateBookmark/', {
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<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 }}</td>
|
||||||
<td>{{ bookmark.created_at }}</td>
|
<td>{{ bookmark.created_at }}</td>
|
||||||
|
|
@ -153,6 +153,9 @@
|
||||||
<span ng-show="bookmark.own">
|
<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="编辑书签">
|
<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>
|
||||||
|
<span ng-show="!bookmark.own">
|
||||||
|
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/favorite.png" ng-click="favoriteBookmark(bookmark)" title="一键收藏">
|
||||||
|
</span>
|
||||||
<span ng-show="!bookmark.own">
|
<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="转存到我的书签">
|
<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>
|
</span>
|
||||||
|
|
|
||||||
|
|
@ -463,7 +463,6 @@ api.get('/searchBookmarks', function(req, res) {
|
||||||
})
|
})
|
||||||
sendData.totalItems = totalItems;
|
sendData.totalItems = totalItems;
|
||||||
sendData.bookmarks = data;
|
sendData.bookmarks = data;
|
||||||
console.log(JSON.stringify(sendData))
|
|
||||||
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))
|
||||||
|
|
@ -475,7 +474,30 @@ api.get('/tags', function(req, res) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
db.getTags(req.session.user.id)
|
db.getTags(req.session.user.id)
|
||||||
.then((tags) => res.json(tags))
|
.then((tags) => {
|
||||||
|
// 每获取一次标签,就检查一下系统默认的两个分类是不是存在
|
||||||
|
var defaultTags = [];
|
||||||
|
var find1 = false;
|
||||||
|
var find2 = false;
|
||||||
|
tags.forEach((tag) => {
|
||||||
|
if (tag.name == "未分类") {
|
||||||
|
find1 = true;
|
||||||
|
}
|
||||||
|
if (tag.name == "收藏") {
|
||||||
|
find2 = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!find1) {
|
||||||
|
defaultTags.push("未分类")
|
||||||
|
}
|
||||||
|
if (!find2) {
|
||||||
|
defaultTags.push("收藏")
|
||||||
|
}
|
||||||
|
if (defaultTags.length > 0) {
|
||||||
|
db.addTags(req.session.user.id, defaultTags)
|
||||||
|
}
|
||||||
|
res.json(tags);
|
||||||
|
})
|
||||||
.catch((err) => console.log('tags', err));
|
.catch((err) => console.log('tags', err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -631,6 +653,50 @@ api.post('/addBookmark', function(req, res) {
|
||||||
.catch((err) => console.log('addBookmark err', err)); // oops!
|
.catch((err) => console.log('addBookmark err', err)); // oops!
|
||||||
});
|
});
|
||||||
|
|
||||||
|
api.post('/favoriteBookmark', function(req, res) {
|
||||||
|
console.log('hello favoriteBookmark', JSON.stringify(req.body));
|
||||||
|
if (!req.session.user) {
|
||||||
|
res.send(401);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var bookmark = req.body.params;
|
||||||
|
var userId = req.session.user.id;
|
||||||
|
var bookmarkId = -1;
|
||||||
|
var ret = {};
|
||||||
|
|
||||||
|
db.addBookmark(userId, bookmark) // 插入书签
|
||||||
|
.then((bookmark_id) => {
|
||||||
|
db.delBookmarkTags(bookmark_id); // 不管3721,先删掉旧的分类
|
||||||
|
bookmarkId = bookmark_id;
|
||||||
|
return bookmark_id;
|
||||||
|
}) // 将之前所有的书签分类信息删掉
|
||||||
|
.then((bookmark_id) => db.getTags(userId)) // 插入分类
|
||||||
|
.then((tags) => {
|
||||||
|
var tagFavorite = [];
|
||||||
|
tags.forEach((tag) => {
|
||||||
|
if (tag.name == '收藏') {
|
||||||
|
tagFavorite.push(tag.id);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (tagFavorite.length >= 1) {
|
||||||
|
return db.addTagsBookmarks(tagFavorite, bookmarkId)
|
||||||
|
} else {
|
||||||
|
db.addTags(req.session.user.id, ['收藏'])
|
||||||
|
return Promise.reject("没有收藏的分类");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => db.getBookmark(bookmarkId)) // 获取书签信息,返回去
|
||||||
|
.then((bookmark) => {
|
||||||
|
ret = bookmark;
|
||||||
|
return db.getBookmarkTags(bookmarkId);
|
||||||
|
})
|
||||||
|
.then((bookmarkTags) => {
|
||||||
|
ret.tags = bookmarkTags;
|
||||||
|
res.json(ret)
|
||||||
|
})
|
||||||
|
.catch((err) => console.log('addBookmark err', err)); // oops!
|
||||||
|
});
|
||||||
|
|
||||||
api.post('/addTags', function(req, res) {
|
api.post('/addTags', function(req, res) {
|
||||||
console.log('hello addTags', JSON.stringify(req.query), JSON.stringify(req.body));
|
console.log('hello addTags', JSON.stringify(req.query), JSON.stringify(req.body));
|
||||||
if (!req.session.user) {
|
if (!req.session.user) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue