将删除做了一下动画

This commit is contained in:
luchenqun 2017-03-02 22:46:25 +08:00
parent 2eaea860c3
commit 7909209042
10 changed files with 241 additions and 55 deletions

View File

@ -679,6 +679,20 @@ db.getTagsBookmarks = function(bookmark_ids) {
});
}
db.getActiveUsers = function() {
var sql = " (SELECT username, DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') as created_at, DATE_FORMAT(last_login, '%Y-%m-%d %H:%i:%s') as last_login, email FROM users ORDER BY last_login DESC LIMIT 0, 5) UNION (SELECT username, DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') as created_at, DATE_FORMAT(last_login, '%Y-%m-%d %H:%i:%s') as last_login, email FROM users ORDER BY created_at DESC LIMIT 0, 5)";
console.log('getActiveUsers', sql);
return new Promise(function(resolve, reject) {
client.query(sql, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
}
db.getBookmarks = function() {
var sql = "SELECT id, snap_state FROM `bookmarks`"; // 如果是空的,那查一个不存在的就行了。
console.log('getBookmarks', sql);

View File

@ -71,7 +71,13 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
ngDialog.close(dialog);
bookmarkService.delBookmark(params)
.then((data) => {
$("#" + bookmarkId).transition({
animation: animation(),
duration: 500,
onComplete: function() {
$("#" + bookmarkId).remove();
}
});
toastr.success($scope.waitDelBookmark.title + ' 书签删除成功!', "提示");
})
.catch((err) => {

View File

@ -101,7 +101,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
$('.ui.modal.js-add-bookmark').modal('hide');
pubSubService.publish('EditCtr.inserBookmarsSuccess', data);
if (data.title) {
toastr.success('[ ' + data.title + ' ] 添加成功', "提示");
toastr.success('[ ' + data.title + ' ] 添加成功,将自动重新更新书签!', "提示");
} else {
toastr.error('[ ' + params.title + ' ] 添加失败', "提示");
}
@ -115,7 +115,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
.then((data) => {
$('.ui.modal.js-add-bookmark').modal('hide');
pubSubService.publish('EditCtr.inserBookmarsSuccess', data);
toastr.success('[ ' + params.title + ' ] 更新成功', "提示");
toastr.success('[ ' + params.title + ' ] 更新成功,将自动重新更新书签!', "提示");
})
.catch((err) => {
console.log('updateBookmark err', err);

View File

@ -85,7 +85,13 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
ngDialog.close(dialog);
bookmarkService.delBookmark(params)
.then((data) => {
$("#" + bookmarkId).transition({
animation: animation(),
duration: 500,
onComplete: function() {
$("#" + bookmarkId).remove();
}
});
toastr.success($scope.waitDelBookmark.title + ' 书签删除成功!', "提示");
})
.catch((err) => {
@ -208,17 +214,21 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
});
}
function transition() {
function animation() {
var data = ['scale', 'fade', 'fade up', 'fade down', 'fade left', 'fade right', 'horizontal flip',
'vertical flip', 'drop', 'fly left', 'fly right', 'fly up', 'fly down', 'swing left', 'swing right', 'swing up',
'swing down', 'browse', 'browse right', 'slide down', 'slide up', 'slide left', 'slide right'
];
var t = data[parseInt(Math.random() * 1000) % data.length];
return t;
}
function transition() {
var className = 'js-table-search';
$('.' + className).transition('hide');
$('.' + className).transition({
animation: t,
animation: animation(),
duration: 500,
});
}

View File

@ -4,12 +4,36 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
$scope.passwordOrgin = "";
$scope.passwordNew1 = "";
$scope.passwordNew2 = "";
$scope.user = {};
$scope.tagCnt = 0;
$scope.bookmarkCnt = 0;
$scope.form[($stateParams && $stateParams.formIndex) || 0] = true;
$scope.changeForm = function(index) {
$scope.form = $scope.form.map(() => false);
$scope.form[index] = true;
if (index == 1) {
bookmarkService.userInfo({})
.then((data) => {
$scope.user = data;
})
.catch((err) => {
toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误");
});
bookmarkService.getTags({})
.then((data) => {
$scope.tagCnt = data.length;
$scope.bookmarkCnt = 0;
data.forEach((tag) => {
$scope.bookmarkCnt += tag.cnt;
})
})
.catch((err) => {
console.log('getTags err', err);
});
}
}
$scope.resetPassword = function() {

View File

@ -91,6 +91,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
$scope.delBookmark = function(bookmark) {
$scope.waitDelBookmark = $.extend(true, {}, bookmark); // 利用jQuery执行深度拷贝
console.log(JSON.stringify(bookmark));
dialog = ngDialog.open({
template: './views/dialog-del-bookmark.html',
className: 'ngdialog-theme-default',
@ -105,7 +106,21 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
ngDialog.close(dialog);
bookmarkService.delBookmark(params)
.then((data) => {
$("#" + bookmarkId).transition({
animation: animation(),
duration: 500,
onComplete: function() {
$("#" + bookmarkId).remove();
}
});
// 更新分类里面含有书签的数量
$scope.tags.forEach((t1) => {
$scope.waitDelBookmark.tags.forEach((t2) => {
if (t1.id == t2.id) {
t1.cnt--;
}
})
})
toastr.success($scope.waitDelBookmark.title + ' 书签删除成功!', "提示");
})
.catch((err) => {
@ -150,7 +165,17 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
if (!$scope.editMode) {
getTags({});
} else {
$('.js-edit').transition('hide'); // 没装完逼之前,不允许切换编辑模式,否则动画模式乱了。
$('.js-tags-table').transition('hide');
$('.stackable.cards .card').transition('hide');
$('.stackable.cards .card').transition({
animation: animation(),
reverse: 'auto', // default setting
interval: 50,
onComplete: function() {
$('.js-edit').transition('show');
}
});
}
updateEditPos();
}
@ -200,7 +225,6 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
}
$scope.confirmDelTag = function(tagId, tagName) {
console.log(tagId);
ngDialog.close(dialog);
var params = {
del: tagName == '未分类' ? false : true,
@ -209,8 +233,25 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
bookmarkService.delTag(params)
.then((data) => {
if (data.retCode == 0) {
toastr.success('[ ' + tagName + ' ]分类删除成功!将自动更新分类信息', "提示");
toastr.success('[ ' + tagName + ' ]分类删除成功!', "提示");
var index = -1;
$scope.tags.forEach((tag, i) => {
if (tag.id == tagId) {
index = i;
}
})
if (index !== -1) {
$("#tag" + tagId).transition({
animation: animation(),
duration: 500,
onComplete: function() {
$("#tag" + tagId).remove();
$scope.tags.splice(index, 1);
}
});
} else {
getTags({});
}
} else {
toastr.error('[ ' + tagName + ' ]分类删除失败!', "提示");
getTags({});
@ -386,17 +427,21 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
}
}
function transition() {
function animation() {
var data = ['scale', 'fade', 'fade up', 'fade down', 'fade left', 'fade right', 'horizontal flip',
'vertical flip', 'drop', 'fly left', 'fly right', 'fly up', 'fly down', 'swing left', 'swing right', 'swing up',
'swing down', 'browse', 'browse right', 'slide down', 'slide up', 'slide left', 'slide right'
];
var t = data[parseInt(Math.random() * 1000) % data.length];
return t;
}
function transition() {
var className = 'js-tags-table';
$('.' + className).transition('hide');
$('.' + className).transition({
animation: t,
animation: animation(),
duration: 500,
});
}

View File

@ -90,6 +90,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
});
return def.promise;
},
userInfo: function(params) {
var def = $q.defer();
$http.get('/api/userInfo/', {
params: params
})
.success(function(data) {
def.resolve(data);
})
.error(function(data) {
def.reject('userInfo error');
});
return def.promise;
},
/**
* @func
* @desc 根据显示页数的索引获取书签的数据

View File

@ -28,9 +28,59 @@
</div>
<button class="ui button" type="submit" ng-click="resetPassword()">重置密码</button>
</form>
<form class="ui form" ng-show="form[1]">
正在开发中...
</form>
<div class="ui four statistics" style="margin-top:30px;" ng-show="form[1]">
<div class="statistic">
<div class="text value">{{user.created_at.substring(0, 4)}}<br>
{{user.created_at.substring(5, 10)}}
</div>
<div class="label">注册时间
</div>
</div>
<div class="statistic">
<div class="text value">{{user.last_login.substring(0, 4)}}<br>
{{user.last_login.substring(5, 10)}}
</div>
<div class="label">最近登陆
</div>
</div>
<div class="statistic">
<div class="value">
<i class="tags icon"></i>
{{ tagCnt }}
</div>
<div class="label">分类数目</div>
</div>
<div class="statistic">
<div class="value">
<i class="bookmark icon"></i>
{{ bookmarkCnt }}
</div>
<div class="label">书签数目</div>
</div>
</div>
<table class="ui celled table" ng-if="form[1]" ng-show="user.activeUsers.length > 0">
<thead>
<tr>
<th colspan="4">
用户活跃度排名
</th>
</tr>
<tr>
<th>用户名</th>
<th>邮箱</th>
<th>注册时间</th>
<th>最后登陆</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="activeUser in user.activeUsers">
<td>{{ activeUser.username }}</td>
<td>{{ activeUser.email }}</td>
<td>{{ activeUser.created_at }}</td>
<td>{{ activeUser.last_login }}</td>
</tr>
</tbody>
</table>
<form class="ui form" ng-show="form[2]">
<div id="fileuploader" style="min-width:100px">点我上传</div>
<h2 class="ui dividing header">注意事项</h2>

View File

@ -1,9 +1,10 @@
<div class="ui segment js-tags">
<div class="ui container" ng-show="!editMode">
<div class="ui grid">
<div class="two wide column" ng-class="" ng-mouseover="" ng-mouseleave="" ng-repeat="tag in tags">
<div class="two wide column js-tag-label" ng-class="" ng-mouseover="" ng-mouseleave="" ng-repeat="tag in tags">
<div class="ui small label" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
{{ tag.name }} ({{ tag.cnt || 0 }})
{{ tag.name }}
({{ tag.cnt || 0 }})
</div>
</div>
</div>
@ -11,7 +12,7 @@
<div class="ui container" ng-show="editMode" ng-mousedown="storeTagIndex()" ng-mouseup="updateTagIndex()">
<p>提示:拖拽分类即可进行排序</p>
<div class="ui six stackable cards" sv-root sv-part="tags">
<div class="card" ng-repeat="tag in tags" sv-element>
<div class="card" ng-repeat="tag in tags" id="tag{{tag.id}}" sv-element>
<div class="content">
<div class="header" ng-if="!tag.edit">{{ tag.name }}</div>
<div class="ui large fluid transparent input" style="height:19px;" ng-if="tag.edit">

View File

@ -76,6 +76,29 @@ api.post('/login', function(req, res) {
.catch((err) => console.log('login error', err));
});
api.get('/userInfo', function(req, res) {
console.log("userInfo");
if (!req.session.user) {
res.send(401);
return;
}
var user = {};
db.getUser(req.session.username)
.then((_user) => {
user = _user
if (req.session.username == 'lcq' && req.session.userId == 1) {
return db.getActiveUsers();
} else {
return Promise.resolve([]);
}
})
.then((_activeUsers) => {
user.activeUsers = _activeUsers;
res.json(user);
})
.catch((err) => console.log('userInfo error', err));
});
api.post('/register', function(req, res) {
var params = req.body.params;
params.password = md5(params.password); // 进行密码加密