From 3d43450014cb91da2be40fe8b6e2c49403863ab3 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Tue, 17 May 2016 22:15:28 +0800 Subject: [PATCH] support set auto refresh interval --- app/scripts/controllers/list.js | 33 +++++++++------ app/scripts/controllers/main.js | 36 +++++++++++----- app/scripts/langs/en-US.js | 5 +++ app/scripts/langs/zh-CN.js | 7 +++- app/scripts/services/ariaNgSettingService.js | 8 +++- app/styles/aria-ng.css | 12 ++++++ app/views/settings-ariang.html | 44 ++++++++++++++++---- 7 files changed, 113 insertions(+), 32 deletions(-) diff --git a/app/scripts/controllers/list.js b/app/scripts/controllers/list.js index 99898bc..fea14d7 100644 --- a/app/scripts/controllers/list.js +++ b/app/scripts/controllers/list.js @@ -3,6 +3,7 @@ angular.module('ariaNg').controller('DownloadListController', ['$scope', '$window', '$location', '$interval', 'translateFilter', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($scope, $window, $location, $interval, translateFilter, aria2RpcService, ariaNgSettingService, utils) { var location = $location.path().substring(1); + var downloadTaskRefreshPromise = null; var getTitleWidth = function () { var titleColumn = angular.element('.task-table > .row > .col-md-8:first-child'); @@ -47,17 +48,7 @@ task.remainTime = calculateDownloadRemainTime(remainLength, task.downloadSpeed); }; - $scope.titleWidth = getTitleWidth(); - - angular.element($window).bind('resize', function () { - $scope.titleWidth = getTitleWidth(); - }); - - $scope.getOrderType = function () { - return ariaNgSettingService.getDisplayOrder(); - }; - - var downloadTaskRefreshPromise = $interval(function () { + var refreshDownloadTask = function () { var invokeMethod = null; var params = []; @@ -87,7 +78,25 @@ } }); } - }, ariaNgSettingService.getDownloadTaskRefreshInterval()); + }; + + refreshDownloadTask(); + + angular.element($window).bind('resize', function () { + $scope.titleWidth = getTitleWidth(); + }); + + $scope.titleWidth = getTitleWidth(); + + $scope.getOrderType = function () { + return ariaNgSettingService.getDisplayOrder(); + }; + + if (ariaNgSettingService.getDownloadTaskRefreshInterval() > 0) { + downloadTaskRefreshPromise = $interval(function () { + refreshDownloadTask(); + }, ariaNgSettingService.getDownloadTaskRefreshInterval()); + } $scope.$on('$destroy', function () { if (downloadTaskRefreshPromise) { diff --git a/app/scripts/controllers/main.js b/app/scripts/controllers/main.js index 0b64041..7104bbd 100644 --- a/app/scripts/controllers/main.js +++ b/app/scripts/controllers/main.js @@ -2,6 +2,8 @@ 'use strict'; angular.module('ariaNg').controller('MainController', ['$scope', '$interval', 'aria2RpcService', 'ariaNgSettingService', function ($scope, $interval, aria2RpcService, ariaNgSettingService) { + var globalStatRefreshPromise = null; + var processStatResult = function (stat) { var activeCount = parseInt(stat.numActive); var waitingCount = parseInt(stat.numWaiting); @@ -10,15 +12,7 @@ stat.totalRunningCount = totalRunningCount; }; - $scope.changeDisplayOrder = function (type) { - ariaNgSettingService.setDisplayOrder(type); - }; - - $scope.isSetDisplayOrder = function (type) { - return ariaNgSettingService.getDisplayOrder() === type; - }; - - $interval(function () { + var refreshGlobalStat = function () { aria2RpcService.getGlobalStat({ callback: function (result) { if (result) { @@ -28,6 +22,28 @@ $scope.globalStat = result; } }); - }, ariaNgSettingService.getGlobalStatRefreshInterval()); + }; + + refreshGlobalStat(); + + $scope.changeDisplayOrder = function (type) { + ariaNgSettingService.setDisplayOrder(type); + }; + + $scope.isSetDisplayOrder = function (type) { + return ariaNgSettingService.getDisplayOrder() === type; + }; + + if (ariaNgSettingService.getGlobalStatRefreshInterval() > 0) { + globalStatRefreshPromise = $interval(function () { + refreshGlobalStat(); + }, ariaNgSettingService.getGlobalStatRefreshInterval()); + } + + $scope.$on('$destroy', function () { + if (globalStatRefreshPromise) { + $interval.cancel(globalStatRefreshPromise); + } + }); }]); })(); diff --git a/app/scripts/langs/en-US.js b/app/scripts/langs/en-US.js index a5d5ab3..6657581 100644 --- a/app/scripts/langs/en-US.js +++ b/app/scripts/langs/en-US.js @@ -24,10 +24,15 @@ 'Aria2 RPC Host': 'Aria2 RPC Host', 'Aria2 RPC Port': 'Aria2 RPC Port', 'Aria2 RPC Protocol': 'Aria2 RPC Protocol', + 'Global Stat Refresh Interval': 'Global Stat Refresh Interval', + 'Download Task Refresh Interval': 'Download Task Refresh Interval', 'Toggle Navigation': 'Toggle Navigation', 'Loading': 'Loading...', 'More Than One Day': 'More than 1 day', 'Unknown': 'Unknown', + 'Seconds': 'Seconds', + 'Milliseconds': 'Milliseconds', + '(0 is disabled)': '(0 is disabled)', 'Changes to the settings take effect after refreshing page.': 'Changes to the settings take effect after refreshing page.' }); }]) diff --git a/app/scripts/langs/zh-CN.js b/app/scripts/langs/zh-CN.js index 1ead168..84ac313 100644 --- a/app/scripts/langs/zh-CN.js +++ b/app/scripts/langs/zh-CN.js @@ -24,11 +24,16 @@ 'Aria2 RPC Host': 'Aria2 RPC 主机', 'Aria2 RPC Port': 'Aria2 RPC 端口', 'Aria2 RPC Protocol': 'Aria2 RPC 协议', + 'Global Stat Refresh Interval': '全局状态刷新间隔', + 'Download Task Refresh Interval': '下载任务刷新间隔', 'Toggle Navigation': '切换导航', 'Loading': '正在加载...', 'More Than One Day': '超过1天', 'Unknown': '未知', - 'Changes to the settings take effect after refreshing page.': '设置将在刷新页面后生效.' + 'Seconds': '秒', + 'Milliseconds': '毫秒', + '(0 is disabled)': '(0为禁用)', + 'Changes to the settings take effect after refreshing page.': '设置将在页面刷新后生效.' }); }]) })(); diff --git a/app/scripts/services/ariaNgSettingService.js b/app/scripts/services/ariaNgSettingService.js index 1576cb9..2bc7ef4 100644 --- a/app/scripts/services/ariaNgSettingService.js +++ b/app/scripts/services/ariaNgSettingService.js @@ -81,14 +81,20 @@ return getOption('protocol'); }, setProtocol: function (value) { - setOption('protocol', value); + setOption('protocol', Math.max(parseInt(value), 0)); }, getGlobalStatRefreshInterval: function () { return getOption('globalStatRefreshInterval'); }, + setGlobalStatRefreshInterval: function (value) { + setOption('globalStatRefreshInterval', Math.max(parseInt(value), 0)); + }, getDownloadTaskRefreshInterval: function () { return getOption('downloadTaskRefreshInterval'); }, + setDownloadTaskRefreshInterval: function (value) { + setOption('downloadTaskRefreshInterval', Math.max(parseInt(value), 0)); + }, getDisplayOrder: function () { var value = getOption('displayOrder'); diff --git a/app/styles/aria-ng.css b/app/styles/aria-ng.css index ee986d2..5705270 100644 --- a/app/styles/aria-ng.css +++ b/app/styles/aria-ng.css @@ -320,6 +320,12 @@ td { color: red; } +.settings-table .description { + color: #888; + font-size: 12px; + display: block; +} + .settings-table .tip { background-color: #fff !important; font-size: 12px; @@ -329,6 +335,12 @@ td { background-color: #fff !important; } +@media (max-width: 767px) { + .settings-table .description { + display: inline-block; + } +} + /* miscellaneous */ span.realtime-upload, span.realtime-download { padding: 0 15px 0 15px; diff --git a/app/views/settings-ariang.html b/app/views/settings-ariang.html index c2d490e..544452a 100644 --- a/app/views/settings-ariang.html +++ b/app/views/settings-ariang.html @@ -1,10 +1,10 @@
-
+
Language
-
+
@@ -26,26 +26,54 @@
-
+
Aria2 RPC Port *
-
+
-
+
Aria2 RPC Protocol *
-
+
+
+
+ Global Stat Refresh Interval + * + (0 is disabled) +
+
+
+ + Milliseconds +
+
+
+
+
+ Download Task Refresh Interval + * + (0 is disabled) +
+
+
+ + Milliseconds +
+
+
* Changes to the settings take effect after refreshing page.