From ec839b3ecd8757915e5cae91f554c176acc5996e Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 25 Dec 2016 01:07:16 +0800 Subject: [PATCH] code refactor and add option filter in new task page --- src/langs/zh_CN.txt | 2 + src/scripts/config/aria2Options.js | 100 ++++++++++++-------- src/scripts/config/defaultLanguage.js | 2 + src/scripts/controllers/new.js | 7 +- src/scripts/services/aria2SettingService.js | 28 ++++-- src/styles/controls/new-task-table.css | 4 + src/styles/controls/settings-table.css | 10 ++ src/views/new.html | 25 ++++- 8 files changed, 127 insertions(+), 51 deletions(-) diff --git a/src/langs/zh_CN.txt b/src/langs/zh_CN.txt index ba9ac17..802ea9c 100644 --- a/src/langs/zh_CN.txt +++ b/src/langs/zh_CN.txt @@ -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!=请求参数无效 diff --git a/src/scripts/config/aria2Options.js b/src/scripts/config/aria2Options.js index 4fcb0aa..69b8426 100644 --- a/src/scripts/config/aria2Options.js +++ b/src/scripts/config/aria2Options.js @@ -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 + key: 'parameterized-uri', + category: 'global', + canShow: 'new' }, { - key: 'force-save' + key: 'force-save', + category: 'global' } ] }); diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index 946c652..052000c 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -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!', diff --git a/src/scripts/controllers/new.js b/src/scripts/controllers/new.js index 361ada1..7d0143d 100644 --- a/src/scripts/controllers/new.js +++ b/src/scripts/controllers/new.js @@ -13,7 +13,12 @@ return aria2SettingService.getSpecifiedOptions(keys); })(), globalOptions: null, - options: {} + options: {}, + optionFilter: { + global: true, + http: true, + bittorrent: true + } }; $scope.changeTab = function (tabName) { diff --git a/src/scripts/services/aria2SettingService.js b/src/scripts/services/aria2SettingService.js index 093436e..4510456 100644 --- a/src/scripts/services/aria2SettingService.js +++ b/src/scripts/services/aria2SettingService.js @@ -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']; } diff --git a/src/styles/controls/new-task-table.css b/src/styles/controls/new-task-table.css index 06472f4..8a16ee6 100644 --- a/src/styles/controls/new-task-table.css +++ b/src/styles/controls/new-task-table.css @@ -22,3 +22,7 @@ display: block; } } + +.settings-table .new-task-filter-title { + padding-top: 6px; +} diff --git a/src/styles/controls/settings-table.css b/src/styles/controls/settings-table.css index 61a20fd..923d3d0 100644 --- a/src/styles/controls/settings-table.css +++ b/src/styles/controls/settings-table.css @@ -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; diff --git a/src/views/new.html b/src/views/new.html index 4a72b53..65c7a7e 100644 --- a/src/views/new.html +++ b/src/views/new.html @@ -23,7 +23,7 @@ +