code refactor and add option filter in new task page

This commit is contained in:
MaysWind 2016-12-25 01:07:16 +08:00
parent 6323fe2ae8
commit ec839b3ecd
8 changed files with 127 additions and 51 deletions

View file

@ -35,6 +35,7 @@ By Progress=按进度
By Remain Time=按剩余时间
By Download Speed=按下载速度
By Upload Speed=按上传速度
Filters=过滤器
Download=下载
Upload=上传
Downloading=正在下载
@ -165,6 +166,7 @@ WebSocket (Security)=WebSocket (安全)
POST=POST
GET=GET
Disabled=禁用
BitTorrent=BitTorrent
Changes to the settings take effect after refreshing page.=设置将在页面刷新后生效.
Type is illegal!=类型错误!
Parameter is invalid!=请求参数无效

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').constant('aria2AllOptions', {
// EXAMPLE:
// Aria2 Option Defination EXAMPLE:
// 'option key': {
// [since: '',] //This option is supported by this or higher aria2 version
// type: 'string|integer|float|text|boolean|option',
@ -809,6 +809,10 @@
defaultValue: 'true'
}
}).constant('aria2GlobalAvailableOptions', {
// Aria2 Setting Page Defination EXAMPLE:
// 'category key': [
// 'option key 1', 'option key 2', // more options if possible
// ]
basicOptions: [
'dir', 'log', 'max-concurrent-downloads', 'check-integrity', 'continue'
],
@ -858,118 +862,132 @@
'save-session', 'save-session-interval', 'socket-recv-buffer-size', 'stop', 'truncate-console-readout'
]
}).constant('aria2TaskAvailableOptions', {
// Aria2 Task Option Defination EXAMPLE:
// {
// key: 'option key',
// category: 'global|http|bittorrent',
// [canShow: 'new|active|waiting|paused',] // possible to show in specific status, supporting multiple choice. if not set, always show
// [canUpdate: 'new|active|waiting|paused',] // possible to write in specific status, supporting multiple choice. if not set, always writable
// }
taskOptions: [
{
key: 'dir',
newOnly: true
category: 'global',
canUpdate: 'new'
},
{
key: 'out',
httpOnly: true,
newOnly: true
category: 'http',
canUpdate: 'new'
},
{
key: 'allow-overwrite',
newOnly: true
category: 'global',
canShow: 'new'
},
{
key: 'max-download-limit'
key: 'max-download-limit',
category: 'global'
},
{
key: 'max-upload-limit',
btOnly: true
category: 'bittorrent'
},
{
key: 'split',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'min-split-size',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'max-connection-per-server',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'lowest-speed-limit',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'stream-piece-selector',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'all-proxy',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'all-proxy-user',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'all-proxy-passwd',
httpOnly: true,
activeReadonly: true
category: 'http',
canUpdate: 'new|waiting|paused'
},
{
key: 'header',
httpOnly: true,
newOnly: true
category: 'http',
canUpdate: 'new'
},
{
key: 'bt-max-peers',
btOnly: true
category: 'bittorrent'
},
{
key: 'bt-request-peer-speed-limit',
btOnly: true
category: 'bittorrent'
},
{
key: 'bt-remove-unselected-file',
btOnly: true
category: 'bittorrent'
},
{
key: 'bt-stop-timeout',
btOnly: true,
activeReadonly: true
category: 'bittorrent',
canUpdate: 'new|waiting|paused'
},
{
key: 'bt-tracker',
btOnly: true,
activeReadonly: true
category: 'bittorrent',
canUpdate: 'new|waiting|paused'
},
{
key: 'seed-ratio',
btOnly: true,
activeReadonly: true
category: 'bittorrent',
canUpdate: 'new|waiting|paused'
},
{
key: 'seed-time',
btOnly: true,
activeReadonly: true
category: 'bittorrent',
canUpdate: 'new|waiting|paused'
},
{
key: 'conditional-get',
newOnly: true
category: 'global',
canShow: 'new'
},
{
key: 'file-allocation',
newOnly: true
category: 'global',
canShow: 'new'
},
{
key: 'parameterized-uri',
newOnly: true
category: 'global',
canShow: 'new'
},
{
key: 'force-save'
key: 'force-save',
category: 'global'
}
]
});

View file

@ -39,6 +39,7 @@
'By Remain Time': 'By Remain Time',
'By Download Speed': 'By Download Speed',
'By Upload Speed': 'By Upload Speed',
'Filters': 'Filters',
'Download': 'Download',
'Upload': 'Upload',
'Downloading': 'Downloading',
@ -169,6 +170,7 @@
'POST': 'POST',
'GET': 'GET',
'Disabled': 'Disabled',
'BitTorrent': 'BitTorrent',
'Changes to the settings take effect after refreshing page.': 'Changes to the settings take effect after refreshing page.',
'Type is illegal!': 'Type is illegal!',
'Parameter is invalid!': 'Parameter is invalid!',

View file

@ -13,7 +13,12 @@
return aria2SettingService.getSpecifiedOptions(keys);
})(),
globalOptions: null,
options: {}
options: {},
optionFilter: {
global: true,
http: true,
bittorrent: true
}
};
$scope.changeTab = function (tabName) {

View file

@ -45,20 +45,21 @@
for (var i = 0; i < allOptions.length; i++) {
var option = allOptions[i];
var optionKey = {
key: option.key
key: option.key,
category: option.category
};
if (option.newOnly) {
if (option.canShow && option.canShow.indexOf(status) < 0) {
continue;
}
if (option.httpOnly && isBittorrent) {
if (option.category === 'http' && isBittorrent) {
continue;
} else if (option.btOnly && !isBittorrent) {
} else if (option.category === 'bittorrent' && !isBittorrent) {
continue;
}
if (option.activeReadonly && status === 'active') {
if (option.canUpdate && option.canUpdate.indexOf(status) < 0) {
optionKey.readonly = true;
}
@ -74,9 +75,18 @@
for (var i = 0; i < allOptions.length; i++) {
var option = allOptions[i];
var optionKey = {
key: option.key
key: option.key,
category: option.category
};
if (option.canShow && option.canShow.indexOf('new') < 0) {
continue;
}
if (option.canUpdate && option.canUpdate.indexOf('new') < 0) {
optionKey.readonly = true;
}
availableOptions.push(optionKey);
}
@ -88,12 +98,14 @@
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var readonly = false;
var category = null;
if (angular.isObject(key)) {
var optionKey = key;
key = optionKey.key;
readonly = !!optionKey.readonly;
category = optionKey.category;
}
var option = aria2AllOptions[key];
@ -108,6 +120,10 @@
descriptionKey: 'options.' + key + '.description'
}, option);
if (category) {
option.category = category;
}
if (option.type === 'boolean') {
option.options = ['true', 'false'];
}

View file

@ -22,3 +22,7 @@
display: block;
}
}
.settings-table .new-task-filter-title {
padding-top: 6px;
}

View file

@ -4,6 +4,16 @@
margin-right: 15px;
}
.settings-table .settings-table-title {
font-size: 12px;
padding-top: 4px;
padding-bottom: 4px;
}
.settings-table .settings-table-title a {
color: #000;
}
.settings-table > div.row {
padding-top: 8px;
padding-bottom: 8px;

View file

@ -23,7 +23,7 @@
<button type="submit" class="btn btn-sm"
ng-class="{'btn-default': newTaskForm.$invalid, 'btn-success': !newTaskForm.$invalid}"
ng-disabled="newTaskForm.$invalid" translate>Start Download
</button>
</button>&nbsp;
<button type="button" class="btn btn-sm dropdown-toggle"
ng-class="{'btn-default': newTaskForm.$invalid, 'btn-success': !newTaskForm.$invalid}"
ng-disabled="newTaskForm.$invalid" data-toggle="dropdown">
@ -57,8 +57,27 @@
</div>
<div class="tab-pane" ng-class="{'active': context.currentTab == 'options'}">
<div class="settings-table striped hoverable">
<ng-setting ng-repeat="option in context.availableOptions" option="option" lazy-save-timeout="0"
default-value="context.globalOptions[option.key]"
<div class="settings-table-title new-task-filter-title">
<div class="row">
<div class="col-sm-12">
<span translate>Filters</span><span>:</span>
<div class="checkbox checkbox-inline checkbox-primary">
<input id="optionFilterGlobal" type="checkbox" ng-model="context.optionFilter['global']"/>
<label for="optionFilterGlobal" translate>Global</label>
</div>
<div class="checkbox checkbox-inline checkbox-primary">
<input id="optionFilterHttp" type="checkbox" ng-model="context.optionFilter['http']"/>
<label for="optionFilterHttp" translate>Http</label>
</div>
<div class="checkbox checkbox-inline checkbox-primary">
<input id="optionFilterBittorrent" type="checkbox" ng-model="context.optionFilter['bittorrent']"/>
<label for="optionFilterBittorrent" translate>BitTorrent</label>
</div>
</div>
</div>
</div>
<ng-setting ng-repeat="option in context.availableOptions" ng-if="context.optionFilter[option.category]"
option="option" lazy-save-timeout="0" default-value="context.globalOptions[option.key]"
on-change-value="setOption(key, value, optionStatus)"></ng-setting>
</div>
</div>