feat(dataLogs): show user uploaded/downloaded data history

This commit is contained in:
OldHawk
2018-06-06 02:28:32 +08:00
parent e1d4537164
commit 677f4f9e9b
11 changed files with 135 additions and 15 deletions

View File

@@ -1500,6 +1500,8 @@
DAILY_CHECK_IN: 'Daily check in',
SEED_TIMED: 'Torrent seeding timed increased score <a href=/torrents/{{tid}}>{{tid}}',
SEED_UP_DOWNLOAD: 'Torrent seeding and leeching data transfer score <a href=/torrents/{{tid}}>{{tid}}'
ANNOUNCE_UPLOAD_LOGS: 'Client announce uploaded data',
ANNOUNCE_DOWNLOAD_LOGS: 'Client announce downloaded data'
},
//status pages

View File

@@ -1499,7 +1499,9 @@
ACTIVE_IDLE_ACCOUNT: '重新激活帳戶狀態',
DAILY_CHECK_IN: '每日簽到',
SEED_TIMED: '做種時間獲得的積分 <a href=/torrents/{{tid}}>{{tid}}',
SEED_UP_DOWNLOAD: '上傳或下載數據交換積分 <a href=/torrents/{{tid}}>{{tid}}'
SEED_UP_DOWNLOAD: '上傳或下載數據交換積分 <a href=/torrents/{{tid}}>{{tid}}',
ANNOUNCE_UPLOAD_LOGS: '客戶端上報的上傳數據',
ANNOUNCE_DOWNLOAD_LOGS: '客戶端上報的下載數據'
},
//status pages

View File

@@ -1499,7 +1499,9 @@
ACTIVE_IDLE_ACCOUNT: '重新激活帐户状态',
DAILY_CHECK_IN: '每日签到',
SEED_TIMED: '做种时间获得的积分 <a href=/torrents/{{tid}}>{{tid}}',
SEED_UP_DOWNLOAD: '上传或下载数据交换积分 <a href=/torrents/{{tid}}>{{tid}}'
SEED_UP_DOWNLOAD: '上传或下载数据交换积分 <a href=/torrents/{{tid}}>{{tid}}',
ANNOUNCE_UPLOAD_LOGS: '客户端上报的上传数据',
ANNOUNCE_DOWNLOAD_LOGS: '客户端上报的下载数据'
},
//status pages

View File

@@ -6,10 +6,10 @@
.controller('DataCenterController', DataCenterController);
DataCenterController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', '$window', 'MeanTorrentConfig', 'NotifycationService',
'UserDaysLogsService', 'UserMonthsLogsService', '$rootScope', 'moment', 'DebugConsoleService', '$filter', 'UserScoreLogsService'];
'UserDaysLogsService', 'UserMonthsLogsService', '$rootScope', 'moment', 'DebugConsoleService', '$filter', 'UserScoreLogsService', 'UserAnnounceLogsService'];
function DataCenterController($scope, $state, $translate, $timeout, Authentication, $window, MeanTorrentConfig, NotifycationService,
UserDaysLogsService, UserMonthsLogsService, $rootScope, moment, mtDebug, $filter, UserScoreLogsService) {
UserDaysLogsService, UserMonthsLogsService, $rootScope, moment, mtDebug, $filter, UserScoreLogsService, UserAnnounceLogsService) {
var vm = this;
vm.user = Authentication.user;
vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage;
@@ -216,14 +216,35 @@
UserScoreLogsService.query({
userId: vm.user._id
}, function (items) {
vm.userScoreLogsData = items;
vm.userLogsData = items;
vm.buildPager();
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'DATA_CENTER.GET_USER_LOGS_ERROR');
});
};
/**
* getUserAnnounceHistory
*/
vm.getUserAnnounceHistory = function (status) {
UserAnnounceLogsService.query({
userId: vm.user._id
}, function (items) {
if (status === 'seeding') {
vm.userLogsData = items.filter(function (it) {
return it.write_uploaded > 0;
});
} else {
vm.userLogsData = items.filter(function (it) {
return it.write_downloaded > 0;
});
}
vm.buildPager();
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'DATA_CENTER.GET_USER_LOGS_ERROR');
});
};
/**
* buildLogsPager
@@ -239,14 +260,13 @@
* figureOutItemsToDisplay
*/
vm.figureOutItemsToDisplay = function (callback) {
vm.filteredItems = vm.userScoreLogsData;
vm.filteredItems = vm.userLogsData;
vm.filterLength = vm.filteredItems.length;
var begin = ((vm.currentPage - 1) * vm.itemsPerPage);
var end = begin + vm.itemsPerPage;
vm.pagedItems = vm.filteredItems.slice(begin, end);
$('.use-logs-list-ol').prop('start', begin + 1);
mtDebug.info(vm.pagedItems);
if (callback) callback();
};
@@ -268,6 +288,5 @@
});
});
};
}
}());

View File

@@ -9,7 +9,9 @@
}
.use-logs-list {
padding: 0 20px;
.score-value {
.score-value,
.upload-value,
.download-value {
min-width: 80px;
text-align: center;
display: inline-block;
@@ -33,6 +35,10 @@
color: @brand-danger;
}
}
.upload-value,
.download-value {
min-width: 100px;
}
.use-logs-list-ol {
line-height: 2.2;
li {

View File

@@ -0,0 +1,34 @@
(function () {
'use strict';
// Users service used for communicating with the users REST endpoint
angular
.module('dataLogs.services')
.factory('UserAnnounceLogsService', UserAnnounceLogsService);
UserAnnounceLogsService.$inject = ['$resource', 'CacheFactory'];
function UserAnnounceLogsService($resource, CacheFactory) {
var userDataLogsCache = CacheFactory.get('userDataLogsCache') || CacheFactory.createCache('userDataLogsCache');
var removeCache = function (res) {
userDataLogsCache.removeAll();
return res.resource;
};
var logs = $resource('/api/userAnnounceLogs/:userId', {
userId: '@userId'
}, {
get: {
method: 'GET',
cache: userDataLogsCache
},
query: {
method: 'GET',
isArray: true,
cache: userDataLogsCache
}
});
return logs;
}
}());

View File

@@ -1,5 +1,5 @@
<section class="data-center" ng-controller="DataCenterController as vm">
<div class="panel panel-default" ng-init="vm.getUserScoreHistory()">
<div class="panel panel-default" ng-init="vm.getUserAnnounceHistory('leeching')">
<div class="panel-heading">
<i class="fa fa-line-chart text-mt"></i>&emsp;
<span translate="DATA_CENTER.LAST_DAYS_DATA_DOWNLOADED_HISTORY" translate-values="{days: vm.announceConfig.announceLogDays}"></span>
@@ -8,8 +8,26 @@
<!--<p>...</p>-->
</div>
<div class="chart-logs">
<div class="use-logs-list" id="top_of_logs_list">
<ol class="use-logs-list-ol">
<li ng-repeat="l in vm.pagedItems">
<span>&emsp;{{l.createdAt | date: 'yyyy-MM-dd HH:mm:ss'}}</span>
<span> - </span>
<span class="download-value" ng-class="{'subtract': l.write_downloaded<0}">{{l.write_downloaded | byteFmt: 2}}</span>
<span> - </span>
<span translate="SCORE_LOG.ANNOUNCE_DOWNLOAD_LOGS"></span>
</li>
</ol>
<div class="pagination-div-bottom">
<ul uib-pagination boundary-links="true" max-size="8" items-per-page="vm.itemsPerPage"
total-items="vm.filterLength"
ng-model="vm.currentPage"
ng-change="vm.pageChanged()"
first-text="{{ 'PAGE_TEXT_FIRST' | translate}}" previous-text="{{ 'PAGE_TEXT_PREVIOUS' | translate}}"
next-text="{{ 'PAGE_TEXT_NEXT' | translate}}" last-text="{{ 'PAGE_TEXT_LAST' | translate}}">
</ul>
</div>
</div>
</div>
</section>

View File

@@ -1,5 +1,5 @@
<section class="data-center" ng-controller="DataCenterController as vm">
<div class="panel panel-default" ng-init="vm.getUserScoreHistory()">
<div class="panel panel-default" ng-init="vm.getUserAnnounceHistory('seeding')">
<div class="panel-heading">
<i class="fa fa-line-chart text-mt"></i>&emsp;
<span translate="DATA_CENTER.LAST_DAYS_DATA_UPLOADED_HISTORY" translate-values="{days: vm.announceConfig.announceLogDays}"></span>
@@ -8,8 +8,26 @@
<!--<p>...</p>-->
</div>
<div class="chart-logs">
<div class="use-logs-list" id="top_of_logs_list">
<ol class="use-logs-list-ol">
<li ng-repeat="l in vm.pagedItems">
<span>&emsp;{{l.createdAt | date: 'yyyy-MM-dd HH:mm:ss'}}</span>
<span> - </span>
<span class="upload-value" ng-class="{'subtract': l.write_uploaded<0}">{{l.write_uploaded | byteFmt: 2}}</span>
<span> - </span>
<span translate="SCORE_LOG.ANNOUNCE_UPLOAD_LOGS"></span>
</li>
</ol>
<div class="pagination-div-bottom">
<ul uib-pagination boundary-links="true" max-size="8" items-per-page="vm.itemsPerPage"
total-items="vm.filterLength"
ng-model="vm.currentPage"
ng-change="vm.pageChanged()"
first-text="{{ 'PAGE_TEXT_FIRST' | translate}}" previous-text="{{ 'PAGE_TEXT_PREVIOUS' | translate}}"
next-text="{{ 'PAGE_TEXT_NEXT' | translate}}" last-text="{{ 'PAGE_TEXT_LAST' | translate}}">
</ul>
</div>
</div>
</div>
</section>

View File

@@ -10,6 +10,7 @@ var path = require('path'),
UserDaysLog = mongoose.model('UserDaysLog'),
UserMonthsLog = mongoose.model('UserMonthsLog'),
ScoreLog = mongoose.model('ScoreLog'),
AnnounceLog = mongoose.model('AnnounceLog'),
objectId = require('mongodb').ObjectId,
async = require('async');
@@ -49,3 +50,17 @@ exports.getUserScoreLogs = function (req, res) {
res.json(logs);
});
};
/**
* getUserAnnounceLogs
* @param req
* @param res
*/
exports.getUserAnnounceLogs = function (req, res) {
AnnounceLog.find({
user: objectId(req.params.userId)
}).sort('-createdAt')
.exec(function (err, logs) {
res.json(logs);
});
};

View File

@@ -19,7 +19,8 @@ exports.invokeRolesPolicies = function () {
allows: [
{resources: '/api/userDaysLogs/:userId', permissions: ['get']},
{resources: '/api/userMonthsLogs/:userId', permissions: ['get']},
{resources: '/api/userScoreLogs/:userId', permissions: ['get']}
{resources: '/api/userScoreLogs/:userId', permissions: ['get']},
{resources: '/api/userAnnounceLogs/:userId', permissions: ['get']}
]
}
]

View File

@@ -16,4 +16,7 @@ module.exports = function (app) {
app.route('/api/userScoreLogs/:userId').all(dataLogsPolicy.isAllowed)
.get(dataLogs.getUserScoreLogs);
app.route('/api/userAnnounceLogs/:userId').all(dataLogsPolicy.isAllowed)
.get(dataLogs.getUserAnnounceLogs);
};