support set auto refresh interval

This commit is contained in:
MaysWind 2016-05-17 22:15:28 +08:00
parent caf1fda198
commit 3d43450014
7 changed files with 113 additions and 32 deletions

View file

@ -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) {

View file

@ -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);
}
});
}]);
})();

View file

@ -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.'
});
}])

View file

@ -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.': '设置将在页面刷新后生效.'
});
}])
})();

View file

@ -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');

View file

@ -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;

View file

@ -1,10 +1,10 @@
<section class="content no-padding">
<div class="settings-table">
<div class="row">
<div class="setting-key col-md-4">
<div class="setting-key col-sm-4">
<span translate>Language</span>
</div>
<div class="setting-value col-md-8">
<div class="setting-value col-sm-8">
<select class="form-control" style="width: 100%;" ng-model="settings.language" ng-change="settingService.setLanguage(settings.language)">
<option value="en-US" translate translate-language="en-US">English</option>
<option value="zh-CN" translate translate-language="zh-CN">Simplified Chinese</option>
@ -12,11 +12,11 @@
</div>
</div>
<div class="row">
<div class="setting-key col-md-4">
<div class="setting-key col-sm-4">
<span translate>Aria2 RPC Host</span>
<span class="asterisk">*</span>
</div>
<div class="setting-value col-md-8">
<div class="setting-value col-sm-8">
<div class="input-group">
<span class="input-group-addon" ng-bind="settings.protocol + '://'"></span>
<input class="form-control" type="text" ng-model="settings.rpcHost" ng-change="settingService.setRpcHost(settings.rpcHost)"/>
@ -26,26 +26,54 @@
</div>
</div>
<div class="row">
<div class="setting-key col-md-4">
<div class="setting-key col-sm-4">
<span translate>Aria2 RPC Port</span>
<span class="asterisk">*</span>
</div>
<div class="setting-value col-md-8">
<div class="setting-value col-sm-8">
<input class="form-control" type="text" ng-model="settings.rpcPort" ng-change="settingService.setRpcPort(settings.rpcPort)"/>
</div>
</div>
<div class="row">
<div class="setting-key col-md-4">
<div class="setting-key col-sm-4">
<span translate>Aria2 RPC Protocol</span>
<span class="asterisk">*</span>
</div>
<div class="setting-value col-md-8">
<div class="setting-value col-sm-8">
<select class="form-control" style="width: 100%;" ng-model="settings.protocol" ng-change="settingService.setProtocol(settings.protocol)">
<option value="http" translate>Http</option>
<option value="ws" translate>WebSocket</option>
</select>
</div>
</div>
<div class="row">
<div class="setting-key col-sm-4">
<span translate>Global Stat Refresh Interval</span>
<span class="asterisk">*</span>
<span class="description" translate>(0 is disabled)</span>
</div>
<div class="setting-value col-sm-8">
<div class="input-group">
<input class="form-control" type="text" ng-model="settings.globalStatRefreshInterval"
ng-change="settingService.setGlobalStatRefreshInterval(settings.globalStatRefreshInterval)"/>
<span class="input-group-addon" style="border-left: 0" translate>Milliseconds</span>
</div>
</div>
</div>
<div class="row">
<div class="setting-key col-sm-4">
<span translate>Download Task Refresh Interval</span>
<span class="asterisk">*</span>
<span class="description" translate>(0 is disabled)</span>
</div>
<div class="setting-value col-sm-8">
<div class="input-group">
<input class="form-control" type="text" ng-model="settings.downloadTaskRefreshInterval"
ng-change="settingService.setDownloadTaskRefreshInterval(settings.downloadTaskRefreshInterval)"/>
<span class="input-group-addon" style="border-left: 0" translate>Milliseconds</span>
</div>
</div>
</div>
<div class="row tip">
<span class="asterisk">*</span>
<span translate>Changes to the settings take effect after refreshing page.</span>