更新做小的优化
This commit is contained in:
parent
88699ce707
commit
3d39cf95c4
|
|
@ -114,7 +114,7 @@ db.updateBookmark = function(bookmark) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db.getBookmark = function(id) {
|
db.getBookmark = function(id) {
|
||||||
var sql = "SELECT * FROM `bookmarks` WHERE `id` = '" + id + "'";
|
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 `id` = '" + id + "'";
|
||||||
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) {
|
||||||
|
|
@ -140,6 +140,19 @@ db.getBookmarkTags = function(bookmard_id) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.getBookmarkTagsNames = function(bookmard_id) {
|
||||||
|
var sql = "SELECT tags_bookmarks.tag_id as id, tags.name FROM tags_bookmarks LEFT JOIN tags ON tags.id = tags_bookmarks.tag_id WHERE bookmark_id = '"+ bookmard_id +"'";
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
client.query(sql, (err, result) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
db.delBookmarkTags = function(bookmard_id) {
|
db.delBookmarkTags = function(bookmard_id) {
|
||||||
var sql = "DELETE FROM `tags_bookmarks` WHERE (`bookmark_id`='" + bookmard_id + "')";
|
var sql = "DELETE FROM `tags_bookmarks` WHERE (`bookmark_id`='" + bookmard_id + "')";
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
|
|
||||||
|
|
@ -231,17 +231,28 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
||||||
}
|
}
|
||||||
|
|
||||||
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', JSON.stringify(data));
|
||||||
|
|
||||||
var menusScope = $('div[ng-controller="menuCtr"]').scope();
|
var menusScope = $('div[ng-controller="menuCtr"]').scope();
|
||||||
if (menusScope.login && menusScope.selectLoginIndex == 0) {
|
if (menusScope.login && menusScope.selectLoginIndex == 0) {
|
||||||
$scope.showStyle = $scope.showStyle;
|
|
||||||
$scope.forbidTransition = true;
|
$scope.forbidTransition = true;
|
||||||
if ($scope.showStyle == 'card') {
|
if ($scope.showStyle == 'card') {
|
||||||
$scope.currentPage = 1;
|
var find = false;
|
||||||
$scope.bookmarks = [];
|
$scope.bookmarks.forEach((bookmark) => {
|
||||||
|
if (bookmark.id == data.id) {
|
||||||
|
bookmark.title = data.title;
|
||||||
|
bookmark.url = data.url;
|
||||||
|
bookmark.tags = data.tags;
|
||||||
|
bookmark.description = data.description;
|
||||||
|
find = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!find) {
|
||||||
|
$scope.bookmarks.unshift(data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getBookmarks();
|
||||||
}
|
}
|
||||||
getBookmarks();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -302,6 +313,7 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
||||||
index: 0
|
index: 0
|
||||||
});
|
});
|
||||||
if (!($scope.forbidTransition && $scope.forbidTransition == true)) {
|
if (!($scope.forbidTransition && $scope.forbidTransition == true)) {
|
||||||
|
$scope.forbidTransition = false;
|
||||||
transition();
|
transition();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,8 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
|
||||||
currentPage: currentPage,
|
currentPage: currentPage,
|
||||||
perPageItems: perPageItems,
|
perPageItems: perPageItems,
|
||||||
};
|
};
|
||||||
$('.js-tags-table').transition('hide');
|
|
||||||
|
|
||||||
|
$('.js-tags-table').transition('hide');
|
||||||
bookmarkService.getBookmarksByTag(params)
|
bookmarkService.getBookmarksByTag(params)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
$scope.bookmarkData = data;
|
$scope.bookmarkData = data;
|
||||||
|
|
@ -436,10 +436,21 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
|
||||||
|
|
||||||
pubSubService.subscribe('EditCtr.inserBookmarsSuccess', $scope, function(event, data) {
|
pubSubService.subscribe('EditCtr.inserBookmarsSuccess', $scope, function(event, data) {
|
||||||
console.log('subscribe EditCtr.inserBookmarsSuccess', data);
|
console.log('subscribe EditCtr.inserBookmarsSuccess', data);
|
||||||
|
|
||||||
var menusScope = $('div[ng-controller="menuCtr"]').scope();
|
var menusScope = $('div[ng-controller="menuCtr"]').scope();
|
||||||
if (menusScope.login && menusScope.selectLoginIndex == 1) {
|
if (menusScope.login && menusScope.selectLoginIndex == 1) {
|
||||||
getTags({});
|
var find = false;
|
||||||
|
$scope.bookmarkData.bookmarks.forEach((bookmark) => {
|
||||||
|
if (bookmark.id == data.id) {
|
||||||
|
bookmark.title = data.title;
|
||||||
|
bookmark.url = data.url;
|
||||||
|
bookmark.tags = data.tags;
|
||||||
|
bookmark.description = data.description;
|
||||||
|
find = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!find) {
|
||||||
|
getTags({});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -236,16 +236,25 @@ api.post('/updateBookmark', function(req, res) {
|
||||||
res.send(401);
|
res.send(401);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var bookmark = req.body.params;
|
|
||||||
console.log('hello updateBookmark', JSON.stringify(bookmark));
|
|
||||||
var bookmark = req.body.params;
|
var bookmark = req.body.params;
|
||||||
var userId = req.session.user.id;
|
var userId = req.session.user.id;
|
||||||
var tags = bookmark.tags;
|
var tags = bookmark.tags;
|
||||||
|
var ret = {}
|
||||||
|
console.log('hello updateBookmark', JSON.stringify(bookmark));
|
||||||
db.updateBookmark(bookmark) // 更新标签信息
|
db.updateBookmark(bookmark) // 更新标签信息
|
||||||
.then((affectedRows) => db.delBookmarkTags(bookmark.id)) // 将之前所有的书签分类信息删掉
|
.then((affectedRows) => db.delBookmarkTags(bookmark.id)) // 将之前所有的书签分类信息删掉
|
||||||
.then((insertId) => db.addTagsBookmarks(tags, bookmark.id)) // 将新的分类关联起来
|
.then((insertId) => db.addTagsBookmarks(tags, bookmark.id)) // 将新的分类关联起来
|
||||||
.then(() => db.updateLastUseTags(userId, tags)) // 更新最近使用的分类(这个有待考虑)
|
.then(() => db.updateLastUseTags(userId, tags)) // 更新最近使用的分类(这个有待考虑)
|
||||||
.then(() => res.json({})) // 运气不错
|
.then(() => db.getBookmark(bookmark.id)) // 将新的信息返回去
|
||||||
|
.then((bookmark) => {
|
||||||
|
ret = bookmark;
|
||||||
|
return db.getBookmarkTagsNames(bookmark.id);
|
||||||
|
})
|
||||||
|
.then((tags) => {
|
||||||
|
ret.tags = tags;
|
||||||
|
res.json(ret);
|
||||||
|
}) // 运气不错
|
||||||
.catch((err) => console.log('updateBookmark err', err)); // oops!
|
.catch((err) => console.log('updateBookmark err', err)); // oops!
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -726,7 +735,7 @@ api.post('/addBookmark', function(req, res) {
|
||||||
.then(() => db.getBookmark(bookmarkId)) // 获取书签信息,返回去
|
.then(() => db.getBookmark(bookmarkId)) // 获取书签信息,返回去
|
||||||
.then((bookmark) => {
|
.then((bookmark) => {
|
||||||
ret = bookmark;
|
ret = bookmark;
|
||||||
return db.getBookmarkTags(bookmarkId);
|
return db.getBookmarkTagsNames(bookmark.id);
|
||||||
})
|
})
|
||||||
.then((bookmarkTags) => {
|
.then((bookmarkTags) => {
|
||||||
ret.tags = bookmarkTags;
|
ret.tags = bookmarkTags;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue