From 68a598b19e1f6da60c4ea0becbd6fcace2e71f4c Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 14 May 2017 22:45:35 +0800 Subject: [PATCH] add quick setting in footer toolbar --- src/index.html | 18 +++++- src/langs/zh_CN.txt | 2 + src/scripts/config/aria2Options.js | 4 ++ src/scripts/config/defaultLanguage.js | 2 + src/scripts/controllers/main.js | 9 +++ src/scripts/directives/settingDialog.js | 69 +++++++++++++++++++++ src/scripts/services/aria2SettingService.js | 9 ++- src/styles/core/core.css | 4 ++ src/styles/theme/default.css | 4 +- src/views/setting-dialog.html | 23 +++++++ 10 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 src/scripts/directives/settingDialog.js create mode 100644 src/views/setting-dialog.html diff --git a/src/index.html b/src/index.html index 0d037f5..b297cee 100644 --- a/src/index.html +++ b/src/index.html @@ -244,7 +244,20 @@ + + @@ -333,6 +348,7 @@ + diff --git a/src/langs/zh_CN.txt b/src/langs/zh_CN.txt index d6721c9..513898a 100644 --- a/src/langs/zh_CN.txt +++ b/src/langs/zh_CN.txt @@ -164,6 +164,8 @@ Are you sure you want to shutdown aria2?=您是否要关闭 aria2? Session has been saved successfully.=会话已经成功保存. Aria2 has been shutdown successfully.=Aria2 已经成功关闭. Toggle Navigation=切换导航 +Quick Setting=快捷设置 +Global Speed Limit=全局速度限制 Loading=正在加载... More Than One Day=超过1天 Unknown=未知 diff --git a/src/scripts/config/aria2Options.js b/src/scripts/config/aria2Options.js index 69b8426..49ea9a0 100644 --- a/src/scripts/config/aria2Options.js +++ b/src/scripts/config/aria2Options.js @@ -861,6 +861,10 @@ '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('aria2QuickSettingsAvailableOptions', { + globalSpeedLimitOptions: [ + 'max-download-limit', 'max-upload-limit' + ] }).constant('aria2TaskAvailableOptions', { // Aria2 Task Option Defination EXAMPLE: // { diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index 518a9bc..d218a8c 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -168,6 +168,8 @@ 'Session has been saved successfully.': 'Session has been saved successfully.', 'Aria2 has been shutdown successfully.': 'Aria2 has been shutdown successfully.', 'Toggle Navigation': 'Toggle Navigation', + 'Quick Setting': 'Quick Setting', + 'Global Speed Limit': 'Global Speed Limit', 'Loading': 'Loading...', 'More Than One Day': 'More than 1 day', 'Unknown': 'Unknown', diff --git a/src/scripts/controllers/main.js b/src/scripts/controllers/main.js index 1d668b9..2babb41 100644 --- a/src/scripts/controllers/main.js +++ b/src/scripts/controllers/main.js @@ -36,6 +36,8 @@ data: ariaNgMonitorService.getGlobalStatsData() }; + $scope.quickSettingContext = null; + $scope.rpcSettings = ariaNgSettingService.getAllRpcSettings(); $scope.isTaskSelected = function () { @@ -213,6 +215,13 @@ return orderType.equals(targetType); }; + $scope.showQuickSettingDialog = function (type, title) { + $scope.quickSettingContext = { + type: type, + title: title + }; + }; + $scope.switchRpcSetting = function (setting) { if (setting.isDefault) { return; diff --git a/src/scripts/directives/settingDialog.js b/src/scripts/directives/settingDialog.js new file mode 100644 index 0000000..43e2dd0 --- /dev/null +++ b/src/scripts/directives/settingDialog.js @@ -0,0 +1,69 @@ +(function () { + 'use strict'; + + angular.module('ariaNg').directive('ngSettingDialog', ['ariaNgCommonService', 'aria2SettingService', function (ariaNgCommonService, aria2SettingService) { + return { + restrict: 'E', + templateUrl: 'views/setting-dialog.html', + replace: true, + scope: { + setting: '=' + }, + link: function (scope, element, attrs) { + scope.context = { + isLoading: false, + availableOptions: [], + globalOptions: [] + }; + + scope.setGlobalOption = function (key, value, optionStatus) { + return aria2SettingService.setGlobalOption(key, value, function (response) { + if (response.success && response.data === 'OK') { + optionStatus.setSuccess(); + } else { + optionStatus.setFailed(response.data.message); + } + }, true); + }; + + var loadOptions = function (type) { + var keys = aria2SettingService.getaria2QuickSettingsAvailableOptions(type); + + if (!keys) { + ariaNgCommonService.showError('Type is illegal!'); + return; + } + + scope.context.availableOptions = aria2SettingService.getSpecifiedOptions(keys); + }; + + var loadAria2OptionsValue = function () { + scope.context.isLoading = true; + + return aria2SettingService.getGlobalOption(function (response) { + scope.context.isLoading = false; + + if (response.success) { + scope.context.globalOptions = response.data; + } + }); + }; + + $('#quickSettingModal').on('hidden.bs.modal', function () { + scope.setting = null; + scope.context.availableOptions = []; + scope.context.globalOptions = []; + }); + + scope.$watch('setting', function (setting) { + if (setting) { + loadOptions(setting.type); + loadAria2OptionsValue(); + + $('#quickSettingModal').modal('show'); + } + }, true); + } + }; + }]); +}()); diff --git a/src/scripts/services/aria2SettingService.js b/src/scripts/services/aria2SettingService.js index 6bad2d4..20cefe3 100644 --- a/src/scripts/services/aria2SettingService.js +++ b/src/scripts/services/aria2SettingService.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - angular.module('ariaNg').factory('aria2SettingService', ['aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2TaskAvailableOptions', 'aria2RpcService', 'ariaNgLogService', function (aria2AllOptions, aria2GlobalAvailableOptions, aria2TaskAvailableOptions, aria2RpcService, ariaNgLogService) { + angular.module('ariaNg').factory('aria2SettingService', ['aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2QuickSettingsAvailableOptions', 'aria2TaskAvailableOptions', 'aria2RpcService', 'ariaNgLogService', function (aria2AllOptions, aria2GlobalAvailableOptions, aria2QuickSettingsAvailableOptions, aria2TaskAvailableOptions, aria2RpcService, ariaNgLogService) { var processStatResult = function (stat) { if (!stat) { return stat; @@ -38,6 +38,13 @@ return false; } }, + getaria2QuickSettingsAvailableOptions: function (type) { + if (type === 'globalSpeedLimit') { + return aria2QuickSettingsAvailableOptions.globalSpeedLimitOptions; + } else { + return false; + } + }, getAvailableTaskOptionKeys: function (status, isBittorrent) { var allOptions = aria2TaskAvailableOptions.taskOptions; var availableOptions = []; diff --git a/src/styles/core/core.css b/src/styles/core/core.css index 3af2492..5aa8d7a 100644 --- a/src/styles/core/core.css +++ b/src/styles/core/core.css @@ -69,6 +69,10 @@ td { overflow-y: scroll; } +.main-footer .toolbar { + display: inline-block; +} + .dropdown-menu.right-align { left: inherit; right: 0; diff --git a/src/styles/theme/default.css b/src/styles/theme/default.css index 2bdaf20..1c92afe 100644 --- a/src/styles/theme/default.css +++ b/src/styles/theme/default.css @@ -40,11 +40,11 @@ top: 15px; } -.skin-aria-ng .main-header .navbar .sidebar-toggle, .skin-aria-ng .main-footer .sidebar-toggle { +.skin-aria-ng .main-header .navbar .sidebar-toggle, .skin-aria-ng .main-footer .sidebar-toggle, .skin-aria-ng .main-footer .toolbar > a { color: #707070; } -.skin-aria-ng .main-header .navbar .sidebar-toggle:hover, .skin-aria-ng .main-footer .sidebar-toggle:hover { +.skin-aria-ng .main-header .navbar .sidebar-toggle:hover, .skin-aria-ng .main-footer .sidebar-toggle:hover, .skin-aria-ng .main-footer .toolbar > a:hover, .skin-aria-ng .main-footer .toolbar.open > a { color: #0080ff; } diff --git a/src/views/setting-dialog.html b/src/views/setting-dialog.html new file mode 100644 index 0000000..9b0b315 --- /dev/null +++ b/src/views/setting-dialog.html @@ -0,0 +1,23 @@ +