From ba5cff823e0529bd5e035a14d3c5dcaa9c697907 Mon Sep 17 00:00:00 2001 From: luchenqun Date: Mon, 27 Feb 2017 11:11:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=88=86=E7=B1=BB=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E5=A2=9E=E5=88=86=E7=B1=BB=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/db.js | 4 +- public/images/add-tag.png | Bin 0 -> 687 bytes public/scripts/controllers/edit-controller.js | 2 +- public/scripts/controllers/tags-controller.js | 35 ++++++++++++++++++ public/views/dialog-add-tag.html | 11 ++++++ public/views/tags.html | 5 +++ routes/api.js | 35 ++++++++++-------- 7 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 public/images/add-tag.png create mode 100644 public/views/dialog-add-tag.html 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 0000000000000000000000000000000000000000..495a16046fad6ec4ecfee1182e461bb1fdc675fe GIT binary patch literal 687 zcmeAS@N?(olHy`uVBq!ia0vp^tAKa`2OE%_^Y;4_AjMc5RtvY3H^?+6GpPSxg z$eq5mA&1F?>#UZ+(w8s&dS^*qoGVm2xp>m4_3@rNXD`2Z+r)Q0qy3%rKU?H|SEz7I zWmz~$Aw;Oft0}-!K#S8!)p5`X#$I^*QR4UCf1gt#onkM1{wZ_)^;Zy^pi}QH%d9&4 z{!f|R{Npc6X646!-e_97|Nil+y>hFsX8rqRdi-&r3}5@tWAbXR?Dxd2&$svfbN;^1 z71q0X+c(~Rd+ceE= 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 @@ +
+

新建分类

+
+
+ 新分类: +
+

+
+ + +
diff --git a/public/views/tags.html b/public/views/tags.html index 3a1832e..61dca52 100644 --- a/public/views/tags.html +++ b/public/views/tags.html @@ -34,6 +34,11 @@ +
+
+ +
+
diff --git a/routes/api.js b/routes/api.js index bfba5da..810545c 100644 --- a/routes/api.js +++ b/routes/api.js @@ -545,13 +545,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,先删掉旧的分类 @@ -747,18 +747,23 @@ api.post('/getArticle', function(req, res) { var url = params.url; var requestId = params.requestId || 0; read(url, function(err, article, meta) { - console.log(article.title || 'Get title failed'); - if (requestId == 0) { + if (err) { res.json({ - title: article.title || '', - }); - } else if (requestId == 1) { - res.json({ - content: article.content, + title: '', + content: false, }); + } else { + if (requestId == 0) { + res.json({ + title: article.title || '', + }); + } else if (requestId == 1) { + res.json({ + content: article.content, + }); + } + article.close(); } - - article.close(); }); })