在分类界面添加新增分类功能

This commit is contained in:
luchenqun 2017-02-27 11:11:36 +08:00
parent 1eb1266d8b
commit ba5cff823e
7 changed files with 74 additions and 18 deletions

View File

@ -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) {

BIN
public/images/add-tag.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

View File

@ -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;
}

View File

@ -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;

View File

@ -0,0 +1,11 @@
<div class="ngdialog-message">
<h3>新建分类</h3>
</div>
<div class="dialog-contents">
新分类:<input type="text" ng-model="newTag">
</div>
<p></p>
<div class="ngdialog-buttons">
<button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="addTag(newTag)">确定</button>
<button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="closeThisDialog('button')">取消</button>
</div>

View File

@ -34,6 +34,11 @@
</label>
</div>
</div>
<div class="card" ng-click="showAddTag()">
<div class="image">
<img src="./images/add-tag.png">
</div>
</div>
</div>
</div>
<div style="width:22px;height:22px;" class="js-edit" ng-click="toggleMode()" title="{{edit ? '退出编辑模式' : '点我进入编辑模式'}}"><img class="ui ui middle aligned tiny image" ng-src="./images/{{ edit ? 'back' : 'edit'}}.png"></div>

View File

@ -747,7 +747,12 @@ 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 (err) {
res.json({
title: '',
content: false,
});
} else {
if (requestId == 0) {
res.json({
title: article.title || '',
@ -757,8 +762,8 @@ api.post('/getArticle', function(req, res) {
content: article.content,
});
}
article.close();
}
});
})