From d231f59de002c566e6921a6ec3f558b8c6dfd934 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 25 May 2016 23:33:06 +0800 Subject: [PATCH] support sort file list in task detail page --- app/index.html | 1 + app/scripts/controllers/task-detail.js | 40 ++++++++++++++++---- app/scripts/core/utils.js | 1 + app/scripts/filters/fileOrderBy.js | 27 +++++++++++++ app/scripts/services/ariaNgSettingService.js | 12 ++++++ app/views/task-detail.html | 13 ++++--- 6 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 app/scripts/filters/fileOrderBy.js diff --git a/app/index.html b/app/index.html index 322df7e..886dd35 100644 --- a/app/index.html +++ b/app/index.html @@ -240,6 +240,7 @@ + diff --git a/app/scripts/controllers/task-detail.js b/app/scripts/controllers/task-detail.js index e4ea8b4..d4a99c9 100644 --- a/app/scripts/controllers/task-detail.js +++ b/app/scripts/controllers/task-detail.js @@ -5,6 +5,12 @@ var tabOrders = ['overview', 'blocks', 'filelist', 'btpeers']; var downloadTaskRefreshPromise = null; + $scope.context = { + currentTab: 'overview' + }; + + $scope.healthPercent = 0; + var refreshPeers = function (task) { return aria2RpcService.getPeers({ params: [task.gid], @@ -42,13 +48,6 @@ }) }; - $scope.context = { - currentTab: 'overview' - }; - - $scope.healthPercent = 0; - $scope.loadPromise = refreshDownloadTask(); - $rootScope.swipeActions.extentLeftSwipe = function () { 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) { downloadTaskRefreshPromise = $interval(function () { refreshDownloadTask(); diff --git a/app/scripts/core/utils.js b/app/scripts/core/utils.js index 47fced3..98ca0ed 100644 --- a/app/scripts/core/utils.js +++ b/app/scripts/core/utils.js @@ -95,6 +95,7 @@ if (task.files) { for (var i = 0; i < task.files.length; i++) { var file = task.files[i]; + file.fileName = this.getFileNameFromPath(file.path); file.length = parseInt(file.length); file.completedLength = parseInt(file.completedLength); file.completePercent = (file.length > 0 ? file.completedLength / file.length * 100 : 0); diff --git a/app/scripts/filters/fileOrderBy.js b/app/scripts/filters/fileOrderBy.js new file mode 100644 index 0000000..034254c --- /dev/null +++ b/app/scripts/filters/fileOrderBy.js @@ -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; + } + } + }]); +})(); diff --git a/app/scripts/services/ariaNgSettingService.js b/app/scripts/services/ariaNgSettingService.js index acb871d..02ef317 100644 --- a/app/scripts/services/ariaNgSettingService.js +++ b/app/scripts/services/ariaNgSettingService.js @@ -106,6 +106,18 @@ }, setDisplayOrder: function (value) { setOption('displayOrder', value); + }, + getFileListDisplayOrder: function () { + var value = getOption('fileListDisplayOrder'); + + if (!value) { + value = 'default:false'; + } + + return value; + }, + setFileListDisplayOrder: function (value) { + setOption('fileListDisplayOrder', value); } }; }]); diff --git a/app/views/task-detail.html b/app/views/task-detail.html index d5fd52f..e16d826 100644 --- a/app/views/task-detail.html +++ b/app/views/task-detail.html @@ -117,21 +117,24 @@
-
+
- +