refactor code

master
MaysWind 2016-07-03 16:15:47 +08:00
parent 7cd76f5571
commit 7d6b5e2668
3 changed files with 155 additions and 36 deletions

View File

@ -2,7 +2,7 @@
'use strict';
angular.module('ariaNg').constant('aria2AllOptions', {
// EXAMPLE:
// 'option name': {
// 'option key': {
// type: 'string|integer|float|text|boolean|option',
// [suffix: 'Bytes|Milliseconds|Seconds|Minutes|Hours',]
// [defaultValue: '',]
@ -798,11 +798,109 @@
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', 'optimize-concurrent-downloads', 'piece-length', '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', {
activeNormalTaskOptions: ['max-download-limit', 'max-upload-limit', 'force-save'],
activeBtTaskOptions: ['max-download-limit', 'max-upload-limit', 'bt-max-peers', 'bt-request-peer-speed-limit', 'bt-remove-unselected-file', 'force-save'],
inactiveNormalTaskOptions: ['max-download-limit', 'max-upload-limit', 'split', 'min-split-size', 'max-connection-per-server', 'force-save'],
inactiveBtTaskOptions: ['max-download-limit', 'max-upload-limit', 'split', 'min-split-size', 'max-connection-per-server', 'bt-max-peers', 'bt-request-peer-speed-limit', 'bt-remove-unselected-file', 'force-save'],
activeTaskReadonlyOptions: ['split', 'min-split-size', 'max-connection-per-server'],
newTaskOptions: ['dir', 'max-download-limit', 'max-upload-limit', 'split', 'min-split-size', 'max-connection-per-server', 'allow-overwrite', 'conditional-get', 'file-allocation', 'stream-piece-selector', 'parameterized-uri']
taskOptions: [
{
key: 'dir',
newOnly: true
},
{
key: 'allow-overwrite',
newOnly: true
},
{
key: 'max-download-limit'
},
{
key: 'max-upload-limit',
btOnly: true
},
{
key: 'split',
httpOnly: true,
activeReadonly: true
},
{
key: 'min-split-size',
httpOnly: true,
activeReadonly: true
},
{
key: 'max-connection-per-server',
httpOnly: true,
activeReadonly: true
},
{
key: 'lowest-speed-limit',
httpOnly: true,
activeReadonly: true
},
{
key: 'stream-piece-selector',
httpOnly: true,
activeReadonly: true
},
{
key: 'all-proxy',
httpOnly: true,
activeReadonly: true
},
{
key: 'all-proxy-user',
httpOnly: true,
activeReadonly: true
},
{
key: 'all-proxy-passwd',
httpOnly: true,
activeReadonly: true
},
{
key: 'bt-max-peers',
btOnly: true
},
{
key: 'bt-request-peer-speed-limit',
btOnly: true
},
{
key: 'bt-remove-unselected-file',
btOnly: true
},
{
key: 'bt-stop-timeout',
btOnly: true,
activeReadonly: true
},
{
key: 'bt-tracker',
btOnly: true,
activeReadonly: true
},
{
key: 'seed-ratio',
btOnly: true,
activeReadonly: true
},
{
key: 'seed-time',
btOnly: true,
activeReadonly: true
},
{
key: 'conditional-get',
newOnly: true
},
{
key: 'file-allocation',
newOnly: true
},
{
key: 'parameterized-uri ',
newOnly: true
},
{
key: 'force-save'
}
]
});
})();

View File

@ -13,11 +13,7 @@
return;
}
var options = [];
ariaNgCommonService.pushArrayTo(options, aria2SettingService.getSpecifiedOptions(keys.readwrite));
ariaNgCommonService.pushArrayTo(options, aria2SettingService.getSpecifiedOptions(keys.readonly, true));
return options;
return aria2SettingService.getSpecifiedOptions(keys);
};
var refreshBtPeers = function (task, silent) {

View File

@ -39,38 +39,63 @@
}
},
getAvailableTaskOptionKeys: function (status, isBittorrent) {
if (status == 'active' && isBittorrent) {
return {
readwrite: aria2TaskAvailableOptions.activeBtTaskOptions,
readonly: aria2TaskAvailableOptions.activeTaskReadonlyOptions
var allOptions = aria2TaskAvailableOptions.taskOptions;
var availableOptions = [];
for (var i = 0; i < allOptions.length; i++) {
var option = allOptions[i];
var optionKey = {
key: option.key
};
} else if (status == 'active' && !isBittorrent) {
return {
readwrite: aria2TaskAvailableOptions.activeNormalTaskOptions,
readonly: aria2TaskAvailableOptions.activeTaskReadonlyOptions
};
} else if ((status == 'waiting' || status == 'paused') && isBittorrent) {
return {
readwrite: aria2TaskAvailableOptions.inactiveBtTaskOptions,
readonly: []
};
} else if ((status == 'waiting' || status == 'paused') && !isBittorrent) {
return {
readwrite: aria2TaskAvailableOptions.inactiveNormalTaskOptions,
readonly: []
};
} else {
return false;
if (option.newOnly) {
continue;
}
if (option.httpOnly && isBittorrent) {
continue;
} else if (option.btOnly && !isBittorrent) {
continue;
}
if (option.activeReadonly && status == 'active') {
optionKey.readonly = true;
}
availableOptions.push(optionKey);
}
return availableOptions;
},
getNewTaskOptionKeys: function (isBittorrent) {
return aria2TaskAvailableOptions.newTaskOptions;
var allOptions = aria2TaskAvailableOptions.taskOptions;
var availableOptions = [];
for (var i = 0; i < allOptions.length; i++) {
var option = allOptions[i];
var optionKey = {
key: option.key
};
availableOptions.push(optionKey);
}
return availableOptions;
},
getSpecifiedOptions: function (keys, readonly) {
getSpecifiedOptions: function (keys) {
var options = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var readonly = false;
if (angular.isObject(key)) {
var optionKey = key;
key = optionKey.key;
readonly = !!optionKey.readonly;
}
var option = aria2AllOptions[key];
if (!option) {
@ -87,7 +112,7 @@
option.options = ['true', 'false'];
}
if (!!readonly) {
if (readonly) {
option.readonly = true;
}