diff --git a/database/db.js b/database/db.js index ce434c2..b01bf4c 100644 --- a/database/db.js +++ b/database/db.js @@ -459,12 +459,12 @@ db.getTagsByNames = function(user_id, tags_name) { db.addTags = function(user_id, tags_name) { console.log('addTags', tags_name); - var sql = "INSERT INTO `tags` (`user_id`, `name`) VALUES"; + var sql = "INSERT INTO `tags` (`user_id`, `name`, `sort`) VALUES"; tags_name.forEach((name, i) => { if (i >= 1) { sql += ',' } - sql += "('" + user_id + "', '" + name + "')"; + sql += "('"+ user_id +"', '"+ name +"', '88')"; // sort默认一个比较大的值,默认在后面 }); return new Promise(function(resolve, reject) { if (tags_name.length == 0) { diff --git a/public/images/add-tag.png b/public/images/add-tag.png new file mode 100644 index 0000000..495a160 Binary files /dev/null and b/public/images/add-tag.png differ diff --git a/public/scripts/controllers/edit-controller.js b/public/scripts/controllers/edit-controller.js index 0d83d66..cd9a511 100644 --- a/public/scripts/controllers/edit-controller.js +++ b/public/scripts/controllers/edit-controller.js @@ -42,7 +42,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p }); if (tags.length + $scope.tags.length >= 30) { - toastr.error('标签个数总数不能超过30个!', "提示"); + toastr.error('标签个数总数不能超过30个!不允许再添加新分类,如有需求,请联系管理员。', "提示"); return; } diff --git a/public/scripts/controllers/tags-controller.js b/public/scripts/controllers/tags-controller.js index 3dc5c30..5b8ab55 100644 --- a/public/scripts/controllers/tags-controller.js +++ b/public/scripts/controllers/tags-controller.js @@ -15,6 +15,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim $scope.inputPage = ''; $scope.currentTagId = ($stateParams && $stateParams.tagId) || ''; $scope.edit = false; + $scope.newTag = ''; $scope.waitDelTag = {}; $scope.waitDelBookmark = {}; @@ -202,6 +203,40 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim }); } + $scope.showAddTag = function() { + if ($scope.tags.length < 30) { + console.log('showAddTag..........') + $scope.newTag = ""; + dialog = ngDialog.open({ + template: './views/dialog-add-tag.html', + className: 'ngdialog-theme-default', + scope: $scope + }); + } else { + toastr.error('标签个数总数不能超过30个!不允许再添加新分类,如有需求,请联系管理员。', "提示"); + } + } + + $scope.addTag = function(tag) { + ngDialog.close(dialog); + console.log(tag); + tag = tag.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, ' '); // 去除前后空格,多个空格转为一个空格; + if (tag) { + var tags = []; + tags.push(tag); + bookmarkService.addTags(tags) + .then((data) => { + toastr.success('插入分类成功!将自动更新分类信息', "提示"); + getTags({}); + }) + .catch((err) => { + toastr.warning('插入分类失败:' + JSON.stringify(err), "提示"); + }); + } else { + toastr.warning('您可能没有输入分类或者输入的分类有误', "提示"); + } + } + $scope.backTag = function(tag) { tag.edit = false; tag.name = tag.oldName; diff --git a/public/views/dialog-add-tag.html b/public/views/dialog-add-tag.html new file mode 100644 index 0000000..e7df275 --- /dev/null +++ b/public/views/dialog-add-tag.html @@ -0,0 +1,11 @@ +
+
+