support sort file list in task detail page

This commit is contained in:
MaysWind 2016-05-25 23:33:06 +08:00
parent bb88dd8be3
commit d231f59de0
6 changed files with 82 additions and 12 deletions

View file

@ -240,6 +240,7 @@
<script src="scripts/controllers/task-detail.js"></script> <script src="scripts/controllers/task-detail.js"></script>
<script src="scripts/filters/dateDuration.js"></script> <script src="scripts/filters/dateDuration.js"></script>
<script src="scripts/filters/filename.js"></script> <script src="scripts/filters/filename.js"></script>
<script src="scripts/filters/fileOrderBy.js"></script>
<script src="scripts/filters/percent.js"></script> <script src="scripts/filters/percent.js"></script>
<script src="scripts/filters/substring.js"></script> <script src="scripts/filters/substring.js"></script>
<script src="scripts/filters/taskOrderBy.js"></script> <script src="scripts/filters/taskOrderBy.js"></script>

View file

@ -5,6 +5,12 @@
var tabOrders = ['overview', 'blocks', 'filelist', 'btpeers']; var tabOrders = ['overview', 'blocks', 'filelist', 'btpeers'];
var downloadTaskRefreshPromise = null; var downloadTaskRefreshPromise = null;
$scope.context = {
currentTab: 'overview'
};
$scope.healthPercent = 0;
var refreshPeers = function (task) { var refreshPeers = function (task) {
return aria2RpcService.getPeers({ return aria2RpcService.getPeers({
params: [task.gid], params: [task.gid],
@ -42,13 +48,6 @@
}) })
}; };
$scope.context = {
currentTab: 'overview'
};
$scope.healthPercent = 0;
$scope.loadPromise = refreshDownloadTask();
$rootScope.swipeActions.extentLeftSwipe = function () { $rootScope.swipeActions.extentLeftSwipe = function () {
var tabIndex = tabOrders.indexOf($scope.context.currentTab); var tabIndex = tabOrders.indexOf($scope.context.currentTab);
@ -71,6 +70,33 @@
} }
}; };
$scope.changeFileListDisplayOrder = function (type, autoSetReverse) {
var oldType = utils.parseOrderType(ariaNgSettingService.getFileListDisplayOrder());
var newType = utils.parseOrderType(type);
if (autoSetReverse && newType.type == oldType.type) {
newType.reverse = !oldType.reverse;
}
ariaNgSettingService.setFileListDisplayOrder(newType.getValue());
};
$scope.isSetFileListDisplayOrder = function (type, reverse) {
var orderType = utils.parseOrderType(ariaNgSettingService.getFileListDisplayOrder());
if (angular.isUndefined(reverse)) {
return orderType.type === type;
} else {
return orderType.type === type && orderType.reverse === reverse;
}
};
$scope.getFileListOrderType = function () {
return ariaNgSettingService.getFileListDisplayOrder();
};
$scope.loadPromise = refreshDownloadTask();
if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) { if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) {
downloadTaskRefreshPromise = $interval(function () { downloadTaskRefreshPromise = $interval(function () {
refreshDownloadTask(); refreshDownloadTask();

View file

@ -95,6 +95,7 @@
if (task.files) { if (task.files) {
for (var i = 0; i < task.files.length; i++) { for (var i = 0; i < task.files.length; i++) {
var file = task.files[i]; var file = task.files[i];
file.fileName = this.getFileNameFromPath(file.path);
file.length = parseInt(file.length); file.length = parseInt(file.length);
file.completedLength = parseInt(file.completedLength); file.completedLength = parseInt(file.completedLength);
file.completePercent = (file.length > 0 ? file.completedLength / file.length * 100 : 0); file.completePercent = (file.length > 0 ? file.completedLength / file.length * 100 : 0);

View file

@ -0,0 +1,27 @@
(function () {
'use strict';
angular.module("ariaNg").filter('fileOrderBy', ['orderByFilter', 'utils', function (orderByFilter, utils) {
return function (array, type) {
if (!angular.isArray(array)) {
return array;
}
var orderType = utils.parseOrderType(type);
if (orderType == null) {
return array;
}
if (orderType.type == 'name') {
return orderByFilter(array, ['fileName'], orderType.reverse);
} else if (orderType.type == 'size') {
return orderByFilter(array, ['length'], orderType.reverse);
} else if (orderType.type == 'percent') {
return orderByFilter(array, ['completePercent'], orderType.reverse);
} else {
return array;
}
}
}]);
})();

View file

@ -106,6 +106,18 @@
}, },
setDisplayOrder: function (value) { setDisplayOrder: function (value) {
setOption('displayOrder', value); setOption('displayOrder', value);
},
getFileListDisplayOrder: function () {
var value = getOption('fileListDisplayOrder');
if (!value) {
value = 'default:false';
}
return value;
},
setFileListDisplayOrder: function (value) {
setOption('fileListDisplayOrder', value);
} }
}; };
}]); }]);

View file

@ -117,21 +117,24 @@
<div class="task-table-title hidden-xs"> <div class="task-table-title hidden-xs">
<div class="row"> <div class="row">
<div class="col-sm-8"> <div class="col-sm-8">
<span translate>File Name</span> <a ng-click="changeFileListDisplayOrder('name:false', true)" translate>File Name</a>
<i class="fa" ng-class="{'fa-sort-asc': isSetFileListDisplayOrder('name', false), 'fa-sort-desc': isSetFileListDisplayOrder('name', true)}"></i>
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<span translate>Completed Percent</span> <a ng-click="changeFileListDisplayOrder('percent:true', true)" translate>Completed Percent</a>
<i class="fa" ng-class="{'fa-sort-asc': isSetFileListDisplayOrder('percent', false), 'fa-sort-desc': isSetFileListDisplayOrder('percent', true)}"></i>
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<span translate>File Size</span> <a ng-click="changeFileListDisplayOrder('size:false', true)" translate>File Size</a>
<i class="fa" ng-class="{'fa-sort-asc': isSetFileListDisplayOrder('size', false), 'fa-sort-desc': isSetFileListDisplayOrder('size', true)}"></i>
</div> </div>
</div> </div>
</div> </div>
<div class="task-table-body"> <div class="task-table-body">
<div class="row" ng-repeat="file in task.files"> <div class="row" ng-repeat="file in task.files | fileOrderBy: getFileListOrderType()">
<div class="col-sm-8"> <div class="col-sm-8">
<input type="checkbox" ng-checked="file.selected == 'true'" disabled="disabled"/> <input type="checkbox" ng-checked="file.selected == 'true'" disabled="disabled"/>
<span ng-bind="file.path | filename"></span> <span ng-bind="file.fileName"></span>
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
<div class="progress"> <div class="progress">