add rpc server port setting

This commit is contained in:
MaysWind 2016-05-17 00:59:27 +08:00
parent f8195b600c
commit 048507bb8e
8 changed files with 47 additions and 20 deletions

View file

@ -3,9 +3,12 @@
angular.module('ariaNg').constant('ariaNgConstants', { angular.module('ariaNg').constant('ariaNgConstants', {
title: 'Aria Ng', title: 'Aria Ng',
appPrefix: 'AriaNg' appPrefix: 'AriaNg',
optionStorageKey: 'Options'
}).constant('ariaNgDefaultOptions', { }).constant('ariaNgDefaultOptions', {
language: 'en-US', language: 'en-US',
rpcHost: '',
rpcPort: '6800',
protocol: 'http', protocol: 'http',
globalStatRefreshInterval: 1000, globalStatRefreshInterval: 1000,
downloadTaskRefreshInterval: 1000 downloadTaskRefreshInterval: 1000

View file

@ -22,6 +22,7 @@
'AriaNg Settings': 'AriaNg Settings', 'AriaNg Settings': 'AriaNg Settings',
'Language': 'Language', 'Language': 'Language',
'Aria2 RPC Host': 'Aria2 RPC Host', 'Aria2 RPC Host': 'Aria2 RPC Host',
'Aria2 RPC Port': 'Aria2 RPC Port',
'Aria2 RPC Protocol': 'Aria2 RPC Protocol', 'Aria2 RPC Protocol': 'Aria2 RPC Protocol',
'Toggle Navigation': 'Toggle Navigation', 'Toggle Navigation': 'Toggle Navigation',
'Loading': 'Loading...', 'Loading': 'Loading...',

View file

@ -22,6 +22,7 @@
'AriaNg Settings': 'AriaNg 设置', 'AriaNg Settings': 'AriaNg 设置',
'Language': '语言', 'Language': '语言',
'Aria2 RPC Host': 'Aria2 RPC 主机', 'Aria2 RPC Host': 'Aria2 RPC 主机',
'Aria2 RPC Port': 'Aria2 RPC 端口',
'Aria2 RPC Protocol': 'Aria2 RPC 协议', 'Aria2 RPC Protocol': 'Aria2 RPC 协议',
'Toggle Navigation': '切换导航', 'Toggle Navigation': '切换导航',
'Loading': '正在加载...', 'Loading': '正在加载...',

View file

@ -2,7 +2,7 @@
'use strict'; 'use strict';
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgSettingService', function ($http, ariaNgSettingService) { angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgSettingService', function ($http, ariaNgSettingService) {
var rpcUrl = ariaNgSettingService.getJsonRpcUrl('http'); var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
return { return {
request: function (context) { request: function (context) {

View file

@ -2,7 +2,7 @@
'use strict'; 'use strict';
angular.module('ariaNg').factory('aria2WebSocketRpcService', ['$websocket', 'ariaNgSettingService', function ($websocket, ariaNgSettingService) { angular.module('ariaNg').factory('aria2WebSocketRpcService', ['$websocket', 'ariaNgSettingService', function ($websocket, ariaNgSettingService) {
var rpcUrl = ariaNgSettingService.getJsonRpcUrl('ws'); var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
var socketClient = null; var socketClient = null;
var sendIdMapping = {}; var sendIdMapping = {};

View file

@ -1,18 +1,17 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('ariaNg').factory('ariaNgSettingService', ['$location', '$translate', 'amMoment', 'localStorageService', 'ariaNgDefaultOptions', function ($location, $translate, amMoment, localStorageService, ariaNgDefaultOptions) { angular.module('ariaNg').factory('ariaNgSettingService', ['$location', '$translate', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', function ($location, $translate, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions) {
var getDefaultJsonRpcHost = function () { var getDefaultRpcHost = function () {
var rpcHost = $location.$$host + ':6800'; return $location.$$host;
return rpcHost;
}; };
var setOptions = function (options) { var setOptions = function (options) {
return localStorageService.set('Options', options); return localStorageService.set(ariaNgConstants.optionStorageKey, options);
}; };
var getOptions = function () { var getOptions = function () {
var options = localStorageService.get('Options'); var options = localStorageService.get(ariaNgConstants.optionStorageKey);
if (!options) { if (!options) {
options = angular.extend({}, ariaNgDefaultOptions); options = angular.extend({}, ariaNgDefaultOptions);
@ -44,8 +43,8 @@
getAllOptions: function () { getAllOptions: function () {
var options = angular.extend({}, ariaNgDefaultOptions, getOptions()); var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
if (!options.aria2RpcHost) { if (!options.rpcHost) {
options.aria2RpcHost = getDefaultJsonRpcHost(); options.rpcHost = getDefaultRpcHost();
} }
return options; return options;
@ -61,17 +60,22 @@
$translate.use(value); $translate.use(value);
amMoment.changeLocale(value); amMoment.changeLocale(value);
}, },
getJsonRpcUrl: function (protocol) { getJsonRpcUrl: function () {
var rpcHost = getOption('aria2RpcHost'); var protocol = getOption('protocol');
var rpcHost = getOption('rpcHost');
var rpcPort = getOption('rpcPort');
if (!rpcHost) { if (!rpcHost) {
rpcHost = getDefaultJsonRpcHost(); rpcHost = getDefaultRpcHost();
} }
return protocol + '://' + rpcHost + '/jsonrpc'; return protocol + '://' + rpcHost + ':' + rpcPort + '/jsonrpc';
}, },
setJsonRpcHost: function (value) { setRpcHost: function (value) {
setOption('aria2RpcHost', value); setOption('rpcHost', value);
},
setRpcPort: function (value) {
setOption('rpcPort', value);
}, },
getProtocol: function () { getProtocol: function () {
return getOption('protocol'); return getOption('protocol');

View file

@ -308,6 +308,10 @@ td {
background-color: #f5f5f5; background-color: #f5f5f5;
} }
.settings-table .input-group-addon {
background-color: #eee;
}
.settings-table .setting-key { .settings-table .setting-key {
padding-top: 6px; padding-top: 6px;
} }
@ -317,7 +321,7 @@ td {
} }
.settings-table .tip { .settings-table .tip {
background-color: #fff; background-color: #fff !important;
font-size: 12px; font-size: 12px;
padding: 4px; padding: 4px;
} }

View file

@ -16,8 +16,22 @@
<span translate>Aria2 RPC Host</span> <span translate>Aria2 RPC Host</span>
<span class="asterisk">*</span> <span class="asterisk">*</span>
</div> </div>
<div class="setting-value col-md-8" translate> <div class="setting-value col-md-8">
<input class="form-control" ng-model="settings.aria2RpcHost" ng-change="settingService.setJsonRpcHost(settings.aria2RpcHost)" /> <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)"/>
<span class="input-group-addon" style="border-left: 0">:</span>
<span class="input-group-addon" style="border-left: 0" ng-bind="settings.rpcPort"></span>
</div>
</div>
</div>
<div class="row">
<div class="setting-key col-md-4">
<span translate>Aria2 RPC Port</span>
<span class="asterisk">*</span>
</div>
<div class="setting-value col-md-8">
<input class="form-control" type="text" ng-model="settings.rpcPort" ng-change="settingService.setRpcPort(settings.rpcPort)"/>
</div> </div>
</div> </div>
<div class="row"> <div class="row">