From 6ec1d0586cdf84aa28a845862b8336554541e02a Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 2 Jun 2016 00:02:10 +0800 Subject: [PATCH] support set task option --- app/scripts/config/aria2options.js | 3 ++ app/scripts/controllers/settings-aria2.js | 2 +- app/scripts/controllers/task-detail.js | 51 ++++++++++++++++----- app/scripts/core/root.js | 6 ++- app/scripts/directives/setting.js | 6 +-- app/scripts/services/aria2SettingService.js | 23 ++++++++-- app/scripts/services/aria2TaskService.js | 12 ++++- app/views/settings-aria2.html | 2 +- app/views/task-detail.html | 13 ++++-- 9 files changed, 89 insertions(+), 29 deletions(-) diff --git a/app/scripts/config/aria2options.js b/app/scripts/config/aria2options.js index 83e14c0..aae38fa 100644 --- a/app/scripts/config/aria2options.js +++ b/app/scripts/config/aria2options.js @@ -551,5 +551,8 @@ metalinkOptions: ['follow-metalink', 'metalink-base-uri', 'metalink-language', 'metalink-location', 'metalink-os', 'metalink-version', 'metalink-preferred-protocol', 'metalink-enable-unique-protocol'], rpcOptions: ['enable-rpc', 'pause-metadata', 'rpc-allow-origin-all', 'rpc-listen-all', 'rpc-listen-port', 'rpc-max-request-size', 'rpc-save-upload-metadata', 'rpc-secure'], advancedOptions: ['allow-overwrite', 'allow-piece-length-change', 'always-resume', 'async-dns', 'auto-file-renaming', 'auto-save-interval', 'conditional-get', 'conf-path', 'console-log-level', 'daemon', 'deferred-input', 'disable-ipv6', 'disk-cache', 'download-result', 'dscp', 'rlimit-nofile', 'enable-color', 'enable-mmap', 'event-poll', 'file-allocation', 'force-save', 'hash-check-only', 'human-readable', 'max-download-result', 'max-mmap-limit', 'max-resume-failure-tries', 'min-tls-version', 'log-level', 'piece-length', 'optimize-concurrent-downloads', 'show-console-readout', 'summary-interval', 'max-overall-download-limit', 'max-download-limit', 'no-conf', 'no-file-allocation-limit', 'parameterized-uri', 'quiet', 'realtime-chunk-checksum', 'remove-control-file', 'save-session', 'save-session-interval', 'socket-recv-buffer-size', 'stop', 'truncate-console-readout'] + }).constant('aria2TaskAvailableOptions', { + activeBtOptions: ['max-download-limit', 'max-upload-limit', 'bt-max-peers', 'bt-request-peer-speed-limit', 'bt-remove-unselected-file', 'force-save'], + activeOtherOptions: ['max-download-limit', 'max-upload-limit', 'force-save'] }); })(); diff --git a/app/scripts/controllers/settings-aria2.js b/app/scripts/controllers/settings-aria2.js index 08966ef..c7ebbe3 100644 --- a/app/scripts/controllers/settings-aria2.js +++ b/app/scripts/controllers/settings-aria2.js @@ -5,7 +5,7 @@ var location = $location.path().substring($location.path().lastIndexOf('/') + 1); var getAvailableOptions = function (type) { - var keys = aria2SettingService.getAvailableOptionsKeys(type); + var keys = aria2SettingService.getAvailableGlobalOptionsKeys(type); if (!keys) { ariaNgCommonService.alert('Type is illegal!'); diff --git a/app/scripts/controllers/task-detail.js b/app/scripts/controllers/task-detail.js index 8f3faf6..1c5736b 100644 --- a/app/scripts/controllers/task-detail.js +++ b/app/scripts/controllers/task-detail.js @@ -1,15 +1,20 @@ (function () { 'use strict'; - angular.module('ariaNg').controller('TaskDetailController', ['$rootScope', '$scope', '$routeParams', '$interval', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $scope, $routeParams, $interval, ariaNgCommonService, ariaNgSettingService, aria2TaskService) { + angular.module('ariaNg').controller('TaskDetailController', ['$rootScope', '$scope', '$routeParams', '$interval', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $routeParams, $interval, ariaNgCommonService, ariaNgSettingService, aria2TaskService, aria2SettingService) { var tabOrders = ['overview', 'blocks', 'filelist', 'btpeers']; var downloadTaskRefreshPromise = null; - $scope.context = { - currentTab: 'overview' - }; + var getAvailableOptions = function (status, isBittorrent) { + var keys = aria2SettingService.getAvailableTaskOptionKeys(status, isBittorrent); - $scope.healthPercent = 0; + if (!keys) { + ariaNgCommonService.alert('Type is illegal!'); + return; + } + + return aria2SettingService.getSpecifiedOptions(keys); + }; var refreshBtPeers = function (task) { return aria2TaskService.getBtTaskPeers(task.gid, function (result) { @@ -31,6 +36,10 @@ } } + if (!$scope.task || $scope.task.status != result.status) { + $scope.availableOptions = getAvailableOptions(result.status, !!result.bittorrent); + } + $scope.task = ariaNgCommonService.copyObjectTo(result, $scope.task); $rootScope.taskContext.list = [$scope.task]; @@ -39,6 +48,14 @@ }); }; + $scope.context = { + currentTab: 'overview' + }; + + $scope.healthPercent = 0; + $scope.optionStatus = {}; + $scope.availableOptions = []; + $rootScope.swipeActions.extentLeftSwipe = function () { var tabIndex = tabOrders.indexOf($scope.context.currentTab); @@ -61,12 +78,6 @@ } }; - $scope.loadTaskOption = function (task) { - $rootScope.loadPromise = aria2TaskService.getTaskOption(task.gid, function (result) { - $scope.options = result; - }); - }; - $scope.changeFileListDisplayOrder = function (type, autoSetReverse) { var oldType = ariaNgCommonService.parseOrderType(ariaNgSettingService.getFileListDisplayOrder()); var newType = ariaNgCommonService.parseOrderType(type); @@ -89,6 +100,24 @@ return ariaNgSettingService.getFileListDisplayOrder(); }; + $scope.loadTaskOption = function (task) { + $rootScope.loadPromise = aria2TaskService.getTaskOptions(task.gid, function (result) { + $scope.options = result; + }); + }; + + $scope.pendingOption = function (key, value) { + $scope.optionStatus[key] = 'pending'; + }; + + $scope.setOption = function (key, value) { + $scope.optionStatus[key] = 'saving'; + + return aria2TaskService.setTaskOption($scope.task.gid, key, value, function (result) { + $scope.optionStatus[key] = 'saved'; + }); + }; + if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) { downloadTaskRefreshPromise = $interval(function () { refreshDownloadTask(); diff --git a/app/scripts/core/root.js b/app/scripts/core/root.js index 52c9822..7fc7c47 100644 --- a/app/scripts/core/root.js +++ b/app/scripts/core/root.js @@ -139,6 +139,10 @@ }; $rootScope.$on('$locationChangeStart', function (event) { + SweetAlert.close(); + + $rootScope.loadPromise = null; + delete $rootScope.swipeActions.extentLeftSwipe; delete $rootScope.swipeActions.extentRightSwipe; @@ -151,8 +155,6 @@ } $rootScope.taskContext.enableSelectAll = false; - - SweetAlert.close(); }); $rootScope.$on('$routeChangeStart', function (event, next, current) { diff --git a/app/scripts/directives/setting.js b/app/scripts/directives/setting.js index 25b74bb..fd7d9f2 100644 --- a/app/scripts/directives/setting.js +++ b/app/scripts/directives/setting.js @@ -11,7 +11,7 @@ option: '=', ngModel: '=', status: '=', - beforeChangeValue: '&', + onPendingChangeValue: '&', onChangeValue: '&' }, link: function (scope, element, attrs, ngModel) { @@ -42,8 +42,8 @@ value: optionValue }; - if (scope.beforeChangeValue) { - scope.beforeChangeValue(data); + if (scope.onPendingChangeValue) { + scope.onPendingChangeValue(data); } if (pendingSaveRequest) { diff --git a/app/scripts/services/aria2SettingService.js b/app/scripts/services/aria2SettingService.js index 1fb0441..32d4ac7 100644 --- a/app/scripts/services/aria2SettingService.js +++ b/app/scripts/services/aria2SettingService.js @@ -1,23 +1,23 @@ (function () { 'use strict'; - angular.module('ariaNg').factory('aria2SettingService', ['aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2RpcService', function (aria2AllOptions, aria2GlobalAvailableOptions, aria2RpcService) { + angular.module('ariaNg').factory('aria2SettingService', ['aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2TaskAvailableOptions', 'aria2RpcService', function (aria2AllOptions, aria2GlobalAvailableOptions, aria2TaskAvailableOptions, aria2RpcService) { var processStatResult = function (stat) { if (!stat) { return stat; } - + var activeCount = parseInt(stat.numActive); var waitingCount = parseInt(stat.numWaiting); var totalRunningCount = activeCount + waitingCount; stat.totalRunningCount = totalRunningCount; - + return stat; }; - + return { - getAvailableOptionsKeys: function (type) { + getAvailableGlobalOptionsKeys: function (type) { if (type == 'basic') { return aria2GlobalAvailableOptions.basicOptions; } else if (type == 'http-ftp-sftp') { @@ -38,6 +38,19 @@ return false; } }, + getAvailableTaskOptionKeys: function (status, isBittorrent) { + if (status == 'active' && isBittorrent) { + return aria2TaskAvailableOptions.activeBtOptions; + } else if (status == 'active' && !isBittorrent) { + return aria2TaskAvailableOptions.activeOtherOptions; + } else if ((status == 'waiting' || status == 'paused') && isBittorrent) { + return aria2TaskAvailableOptions.activeBtOptions; + } else if ((status == 'waiting' || status == 'paused') && !isBittorrent) { + return aria2TaskAvailableOptions.activeOtherOptions; + } else { + return false; + } + }, getSpecifiedOptions: function (keys) { var options = []; diff --git a/app/scripts/services/aria2TaskService.js b/app/scripts/services/aria2TaskService.js index 1fd1d2d..6a08eea 100644 --- a/app/scripts/services/aria2TaskService.js +++ b/app/scripts/services/aria2TaskService.js @@ -132,12 +132,22 @@ } }); }, - getTaskOption: function (gid, callback) { + getTaskOptions: function (gid, callback) { return aria2RpcService.getOption({ gid: gid, callback: callback }); }, + setTaskOption: function (gid, key, value, callback) { + var data = {}; + data[key] = value; + + return aria2RpcService.changeOption({ + gid: gid, + options: data, + callback: callback + }); + }, getBtTaskPeers: function (gid, callback) { return aria2RpcService.getPeers({ gid: gid, diff --git a/app/views/settings-aria2.html b/app/views/settings-aria2.html index 954b4b7..fbc726e 100644 --- a/app/views/settings-aria2.html +++ b/app/views/settings-aria2.html @@ -1,6 +1,6 @@
+ on-pending-change-value="pendingOption(key, value)" on-change-value="setGlobalOption(key, value)">
diff --git a/app/views/task-detail.html b/app/views/task-detail.html index c1f6894..21e5b13 100644 --- a/app/views/task-detail.html +++ b/app/views/task-detail.html @@ -10,10 +10,10 @@
  • File List
  • -
  • +
  • Peers
  • -
  • +
  • @@ -160,7 +160,7 @@ -
    +
    -
    +
    - +