数据列分开, 显示数据大小

This commit is contained in:
life
2015-11-21 14:56:41 +08:00
parent 8c11aad97b
commit c29f6fc27e
3 changed files with 102 additions and 9 deletions

25
node_modules/common.js generated vendored
View File

@@ -291,5 +291,30 @@ var Common = {
fs.rmdirSync(path);
}
},
/**
* 得到目录下的文件大小
* @param {string} path 路径
* @param {boolean} isRecursive 是否递归子目录
* @return {number} 大小, 以KB为单位
*/
getFolderSize: function (path, isRecursive) {
var me = this;
var size = 0;
var fies;
if ( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file, index) {
var curPath = path + '/' + file;
var stat = fs.statSync(curPath);
if(stat.isDirectory() && isRecursive) {
size += me.getFolderSize(curPath, isRecursive);
} else {
size += stat.size / 1000;
}
});
}
return size;
}
};
module.exports = Common;

25
node_modules/user.js generated vendored
View File

@@ -255,10 +255,10 @@ User = {
return Evt.getBasePath() + '/data/' + userId;
},
getUserImagesPath: function(userId) {
return this.getUserImagesAndAttachBasePath() + '/images';
return this.getUserImagesAndAttachBasePath(userId) + '/images';
},
getUserAttachsPath: function(userId) {
return this.getUserImagesAndAttachBasePath() + '/attachs';
return this.getUserImagesAndAttachBasePath(userId) + '/attachs';
},
getUserDBPath: function (userId) {
@@ -306,6 +306,27 @@ User = {
});
},
/**
* 得到用户的数据统计
* @param {User} user 用户
* @return {Object} {db: 1232, image: 3232, attach: 3232} // 以KB为单位
*/
getUserDataStats: function (user) {
var me = this;
var userId = user.UserId;
var dbPath = user.HasDB ? me.getUserDBPath(userId) : Evt.getDBPath();
var dbSize = Common.getFolderSize(dbPath);
var imageSize = Common.getFolderSize(me.getUserImagesPath(userId));
var attachSize = Common.getFolderSize(me.getUserAttachsPath(userId));
return {
db: dbSize,
image: imageSize,
attach: attachSize
};
},
setUserDataPath: function(userId) {
var me = this;
// 判断是否存在, 不存在则创建dir

View File

@@ -24,8 +24,11 @@ define(function() {
"Options": "操作",
"Current": "当前",
"Data": "数据",
"Open Dir": "打开目录",
"Error": "错误",
"No such account": "无该帐户"
"No such account": "无该帐户",
},
'zh-hk': {
'Accounts': '帐户管理',
@@ -49,6 +52,19 @@ define(function() {
#accountsDialog .modal-dialog {
width: 750px ;
}
#accountsDialog .user-data {
margin: 0;
padding: 0;
list-style: none;
}
#accountsDialog .user-data a {
color: #428bca;
display: inline-block;
margin: 0 3px;
}
#accountsDialog .user-data a:hover {
text-decoration: underline !important;
}
</style>
<div class="modal fade bs-modal-sm" id="accountsDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog">
@@ -63,6 +79,7 @@ define(function() {
<tr>
<th class="lang">Username</th>
<th class="lang">Is Local</th>
<th class="lang">Data</th>
<th class="lang">Options</th>
</tr>
</thead>
@@ -113,8 +130,11 @@ define(function() {
Api.gui.Shell.showItemInFolder(path);
});
},
'open-files-dir': function (userId) {
Api.gui.Shell.showItemInFolder(Api.userService.getUserImagesAndAttachBasePath(userId));
'open-attach-dir': function (userId) {
Api.gui.Shell.showItemInFolder(Api.userService.getUserAttachsPath(userId));
},
'open-image-dir': function (userId) {
Api.gui.Shell.showItemInFolder(Api.userService.getUserImagesPath(userId));
},
'delete': function (userId, $targetBtn) {
me.deleteUser(userId);
@@ -124,7 +144,7 @@ define(function() {
};
// 事件
me.tbody.on('click', 'button', function () {
me.tbody.on('click', 'a', function () {
var $this = $(this);
var userId = $this.closest('tr').data('id');
var option = $this.data('op');
@@ -136,6 +156,15 @@ define(function() {
});
},
fixSize: function (size) {
var unit = 'KB'
if (size > 1000) {
size = size / 1000;
unit = 'MB';
}
return size.toFixed(2) + unit;
},
renderUser: function(user) {
var me = this;
var username = user.Username;
@@ -150,10 +179,28 @@ define(function() {
var disabled = user.IsActive ? 'disabled="disabled"' : '';
// 得到用户的数据统计
var userStats = Api.userService.getUserDataStats(user);
var dataTd = '<ul class="user-data">';
dataTd += '<li>数据库 '
+ me.fixSize(userStats.db)
+ '<a data-op="open-db-dir">' + me.getMsg('Open Dir') + '</a>'
+ '<a data-op="db">' + me.getMsg('DB Optimization') + '</a>'
+ ' </li>'
dataTd += '<li>图片 '
+ me.fixSize(userStats.image)
+ '<a data-op="open-image-dir">' + me.getMsg('Open Dir') + '</a>'
+ ' </li>'
dataTd += '<li>附件 '
+ me.fixSize(userStats.attach)
+ '<a data-op="open-attach-dir">' + me.getMsg('Open Dir') + '</a>'
+ ' </li>'
dataTd += '</ul>';
tr += '<td>' + dataTd + '</td>';
var options = '<div class="btn-group" role="group">'
+ '<button class="btn btn-default" data-op="db">' + me.getMsg('DB Optimization') + '</button>'
+ '<button class="btn btn-default" data-op="open-db-dir">' + me.getMsg('Open DB Dir') + '</button>'
+ '<button class="btn btn-default" data-op="open-files-dir">' + me.getMsg('Open Images/Attachs Dir') + '</button>'
+ '<button class="btn btn-danger" ' + disabled + ' data-op="delete">' + me.getMsg('Delete') + '</button>'
+ '</div>';
tr += '<td>' + options + '</td></tr>';