分类可隐藏或者显示

This commit is contained in:
HelloWorld 2019-11-30 12:37:07 +08:00
parent 2f705a687e
commit 9f516d0c4e
6 changed files with 96 additions and 5 deletions

View File

@ -414,7 +414,7 @@ db.getUser = function(username) {
}; };
db.getTags = function(user_id) { db.getTags = function(user_id) {
var sql = "SELECT t.id, t.user_id, t.name, DATE_FORMAT(t.last_use, '%Y-%m-%d %H:%i:%s') as last_use, t.sort, tb.cnt, tg.ncnt FROM `tags` as t LEFT OUTER JOIN ( SELECT `tag_id`, COUNT(tag_id) as cnt FROM tags_bookmarks GROUP BY tag_id ) tb ON t.id = tb.tag_id LEFT OUTER JOIN ( SELECT `tag_id`, COUNT(tag_id) as ncnt FROM notes GROUP BY tag_id ) tg ON t.id = tg.tag_id "; var sql = "SELECT t.id, t.user_id, t.name, DATE_FORMAT(t.last_use, '%Y-%m-%d %H:%i:%s') as last_use, t.sort, t.show, tb.cnt, tg.ncnt FROM `tags` as t LEFT OUTER JOIN ( SELECT `tag_id`, COUNT(tag_id) as cnt FROM tags_bookmarks GROUP BY tag_id ) tb ON t.id = tb.tag_id LEFT OUTER JOIN ( SELECT `tag_id`, COUNT(tag_id) as ncnt FROM notes GROUP BY tag_id ) tg ON t.id = tg.tag_id ";
if (user_id) { if (user_id) {
sql += "WHERE t.user_id = '" + user_id + "' "; sql += "WHERE t.user_id = '" + user_id + "' ";
} }
@ -446,6 +446,21 @@ db.updateTagName = function(tag) {
}); });
}; };
db.updateTagShow = function(tag) {
console.log('updateTagShow');
var sql = "UPDATE `tags` SET `show`='" + tag.show + "' WHERE (`id`='" + tag.id + "')";
console.log(sql);
return new Promise(function(resolve, reject) {
client.query(sql, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result.affectedRows);
}
});
});
};
db.updateTagsIndex = function(tagsIndex) { db.updateTagsIndex = function(tagsIndex) {
console.log('updateTagsIndex'); console.log('updateTagsIndex');
var sql = "UPDATE tags SET sort = CASE id "; var sql = "UPDATE tags SET sort = CASE id ";

View File

@ -273,6 +273,26 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
tag.oldName = tag.name; tag.oldName = tag.name;
tag.edit = true; tag.edit = true;
} }
$scope.updateTagShow = function (tag, show) {
var params = {
id: tag.id,
show: show,
}
bookmarkService.updateTagShow(params)
.then((data) => {
if (data.retCode == 0) {
toastr.success(tag.name + ' 更新成功!', "提示");
tag.show = show;
} else {
toastr.error(tag.name + ' 更新失败!错误提示:' + data.msg, "提示");
}
})
.catch((err) => {
toastr.error(tag.name + ' 更新失败!错误提示:' + err, "提示");
});
}
$scope.updateTag = function (tag) { $scope.updateTag = function (tag) {
if (tag.name == tag.oldName) { if (tag.name == tag.oldName) {
toastr.warning('您没有编辑分类', "警告"); toastr.warning('您没有编辑分类', "警告");

View File

@ -300,6 +300,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
}); });
return def.promise; return def.promise;
}, },
updateTagShow: function(params) {
var def = $q.defer();
$http.post('/api/updateTagShow/', {
params: params
})
.success(function(data) {
def.resolve(data);
})
.error(function(data) {
def.reject(data);
});
return def.promise;
},
updateTagsIndex: function(params) { updateTagsIndex: function(params) {
var def = $q.defer(); var def = $q.defer();
$http.post('/api/updateTagsIndex/', { $http.post('/api/updateTagsIndex/', {

View File

@ -3,7 +3,7 @@
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomTag.bookmarkClicked}" ng-click="getBookmarks(-1, 1)"> <div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomTag.bookmarkClicked}" ng-click="getBookmarks(-1, 1)">
{{ costomTag.name }} ({{ costomTag.cnt || 0 }}) {{ costomTag.name }} ({{ costomTag.cnt || 0 }})
</div> </div>
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-if="tag.cnt" ng-repeat="tag in tags" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)"> <div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-if="tag.cnt && tag.show" ng-repeat="tag in tags" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
{{ tag.name }} ({{ tag.cnt || 0 }}) {{ tag.name }} ({{ tag.cnt || 0 }})
</div> </div>
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomAllUsersTag.bookmarkClicked}" ng-click="getBookmarks(-2, 1)"> <div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomAllUsersTag.bookmarkClicked}" ng-click="getBookmarks(-2, 1)">
@ -51,6 +51,8 @@
<img class="ui mini spaced image right floated" style="width:16px;height:16px;margin:0 5px" ng-src="./images/edit-bookmark.png" <img class="ui mini spaced image right floated" style="width:16px;height:16px;margin:0 5px" ng-src="./images/edit-bookmark.png"
ng-click="editTag(tag)" title="编辑分类"> ng-click="editTag(tag)" title="编辑分类">
</label> </label>
<i class="eye black icon right floated" style="cursor:pointer;" ng-if="tag.show" ng-click="updateTagShow(tag, 0)" title="点击隐藏分类"></i>
<i class="eye black slash icon right floated" style="cursor:pointer;" ng-if="!tag.show" ng-click="updateTagShow(tag, 1)" title="点击显示分类"></i>
</div> </div>
</div> </div>
</div> </div>

View File

@ -538,10 +538,7 @@ api.get('/bookmarksByTag', function(req, res) {
var userId = req.session.user.id; var userId = req.session.user.id;
var params = req.query; var params = req.query;
var bookmarks = [];
var tagsBookmarks = []; var tagsBookmarks = [];
var totalItems = 0;
var totalItems = 0;
var sendData = { var sendData = {
totalItems: 0, totalItems: 0,
bookmarks: [], bookmarks: [],
@ -997,6 +994,49 @@ api.post('/updateTagName', function(req, res) {
}); });
}); });
api.post('/updateTagShow', function(req, res) {
console.log("updateTagShow username = ", req.session.username);
if (!req.session.user) {
res.send(401);
return;
}
var tag = req.body.params;
var userId = req.session.user.id;
db.getTags(userId)
.then((tags) => {
for (var i = 0; i < tags.length; i++) {
if (tags[i].id != tag.id && tags[i].name == tag.name) {
return Promise.resolve(-1);
}
}
return db.updateTagShow(tag);
})
.then((affectedRows) => {
var msg = "";
if (affectedRows == -1) {
msg += " 您已经有这个分类了,不允许更新";
} else if (affectedRows == 0) {
msg += " 更新失败";
} else if (affectedRows == 1) {
msg = " 更新成功";
} else {
msg += " 更新失败";
}
res.json({
retCode: (affectedRows == 1) ? 0 : 1,
msg: msg,
})
})
.catch((err) => {
console.log('updateTagShow err', err);
res.json({
retCode: 1,
msg: tag.name + " 更新失败: " + JSON.stringify(err),
})
});
});
api.post('/updateTagsIndex', function(req, res) { api.post('/updateTagsIndex', function(req, res) {
console.log("updateTagsIndex username = ", req.session.username); console.log("updateTagsIndex username = ", req.session.username);
if (!req.session.user) { if (!req.session.user) {

View File

@ -41,6 +41,7 @@ CREATE TABLE `tags` (
`name` varchar(32) NOT NULL, -- 标签 `name` varchar(32) NOT NULL, -- 标签
`last_use` datetime DEFAULT now(), -- 最后使用标签的时间 `last_use` datetime DEFAULT now(), -- 最后使用标签的时间
`sort` tinyint(8) DEFAULT 0, -- 书签排序 `sort` tinyint(8) DEFAULT 0, -- 书签排序
`show` tinyint(8) DEFAULT 1, -- 书签是否显示
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `userIdIdx` (`user_id`) KEY `userIdIdx` (`user_id`)
); );