add debug mode

This commit is contained in:
MaysWind 2016-11-06 22:41:28 +08:00
parent 530f391392
commit 59518832f3
10 changed files with 71 additions and 4 deletions

View file

@ -334,6 +334,7 @@
<script src="scripts/services/ariaNgMonitorService.js"></script>
<script src="scripts/services/ariaNgNotificationService.js"></script>
<script src="scripts/services/ariaNgSettingService.js"></script>
<script src="scripts/services/ariaNgLogService.js"></script>
<script src="scripts/services/aria2HttpRpcService.js"></script>
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
<script src="scripts/services/aria2RpcService.js"></script>

View file

@ -113,6 +113,7 @@ Download Completed=下载完成
BT Download Completed=BT 下载完成
Download Error=下载出错
Language=语言
Debug Mode=调试模式
Page Title=页面标题
Page Title Refresh Interval=页面标题刷新间隔
Enable Browser Notification=启用浏览器通知

View file

@ -117,6 +117,7 @@
'BT Download Completed': 'BT Download Completed',
'Download Error': 'Download Error',
'Language': 'Language',
'Debug Mode': 'Debug Mode',
'Page Title': 'Page Title',
'Page Title Refresh Interval': 'Page Title Refresh Interval',
'Enable Browser Notification': 'Enable Browser Notification',

View file

@ -1,17 +1,20 @@
(function () {
'use strict';
angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgNotificationService', function ($rootScope, $scope, $timeout, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService, ariaNgNotificationService) {
angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$routeParams', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgNotificationService', function ($rootScope, $scope, $routeParams, $timeout, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService, ariaNgNotificationService) {
var tabOrders = ['global', 'rpc'];
var extendType = $routeParams.extendType;
$scope.context = {
currentTab: 'global',
languages: ariaNgLanguages,
availableTime: ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true),
trueFalseOptions: [{name: 'True', value: true}, {name: 'False', value: false}],
settings: ariaNgSettingService.getAllOptions()
settings: ariaNgSettingService.getAllOptions(),
sessionSettings: ariaNgSettingService.getAllSessionOptions()
};
$scope.context.showDebugMode = $scope.context.sessionSettings.debugMode || extendType === 'debug';
$scope.changeTab = function (tabName) {
$scope.context.currentTab = tabName;

View file

@ -31,6 +31,10 @@
templateUrl: 'views/settings-ariang.html',
controller: 'AriaNgSettingsController'
})
.when('/settings/ariang/:extendType', {
templateUrl: 'views/settings-ariang.html',
controller: 'AriaNgSettingsController'
})
.when('/settings/aria2/basic', {
templateUrl: 'views/settings-aria2.html',
controller: 'Aria2SettingsController'

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgSettingService', function ($http, ariaNgSettingService) {
angular.module('ariaNg').factory('aria2HttpRpcService', ['$http', 'ariaNgSettingService', 'ariaNgLogService', function ($http, ariaNgSettingService, ariaNgLogService) {
var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
return {
@ -16,7 +16,11 @@
data: context.requestBody
};
ariaNgLogService.debug('Http Request Start', requestContext);
return $http(requestContext).success(function (data) {
ariaNgLogService.debug('Http Response Success', data);
if (!data) {
return;
}
@ -25,6 +29,8 @@
context.successCallback(data.id, data.result);
}
}).error(function (data) {
ariaNgLogService.debug('Http Response Error', data);
if (!data) {
data = {
id: '-1',

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('aria2WebSocketRpcService', ['$q', '$websocket', 'ariaNgSettingService', function ($q, $websocket, ariaNgSettingService) {
angular.module('ariaNg').factory('aria2WebSocketRpcService', ['$q', '$websocket', 'ariaNgSettingService', 'ariaNgLogService', function ($q, $websocket, ariaNgSettingService, ariaNgLogService) {
var rpcUrl = ariaNgSettingService.getJsonRpcUrl();
var socketClient = null;
@ -29,10 +29,14 @@
});
if (content.result && context.successCallback) {
ariaNgLogService.debug('WebSocket Response Success', content);
context.successCallback(context.id, content.result);
}
if (content.error && context.errorCallback) {
ariaNgLogService.debug('WebSocket Response Error', content);
context.errorCallback(context.id, content.error);
}
@ -95,6 +99,8 @@
var uniqueId = context.uniqueId;
var requestBody = angular.toJson(context.requestBody);
ariaNgLogService.debug('WebSocket Request Start', context);
var deferred = $q.defer();
sendIdStates[uniqueId] = {

View file

@ -0,0 +1,22 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgLogService', ['$log', 'ariaNgSettingService', function ($log, ariaNgSettingService) {
return {
debug: function (msg, obj) {
if (ariaNgSettingService.isEnableDebugMode()) {
$log.debug('[AriaNg Debug]' + msg, obj);
}
},
info: function (msg, obj) {
$log.info('[AriaNg Info]' + msg, obj);
},
warn: function (msg, obj) {
$log.warn('[AriaNg Warn]' + msg, obj);
},
error: function (msg, obj) {
$log.error('[AriaNg Error]' + msg, obj);
}
};
}]);
}());

View file

@ -3,6 +3,9 @@
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', function ($window, $location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages) {
var onFirstVisitCallbacks = [];
var sessionSettings = {
debugMode: false
};
var fireFirstVisitEvent = function () {
if (!angular.isArray(onFirstVisitCallbacks) || onFirstVisitCallbacks.length < 1) {
@ -91,6 +94,9 @@
return options;
},
getAllSessionOptions: function () {
return angular.copy(sessionSettings);
},
applyLanguage: function (lang) {
if (!ariaNgLanguages[lang]) {
return false;
@ -109,6 +115,12 @@
setOption('language', value);
}
},
isEnableDebugMode: function () {
return sessionSettings.debugMode;
},
setDebugMode: function (value) {
sessionSettings.debugMode = value;
},
getTitle: function () {
return getOption('title');
},

View file

@ -22,6 +22,17 @@
</select>
</div>
</div>
<div class="row" ng-if="context.showDebugMode">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Debug Mode</span>
</div>
<div class="setting-value col-sm-8">
<select class="form-control" style="width: 100%;" ng-model="context.sessionSettings.debugMode"
ng-options="option.value as (option.name | translate) for option in context.trueFalseOptions"
ng-change="settingService.setDebugMode(context.sessionSettings.debugMode)">
</select>
</div>
</div>
<div class="row">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Page Title</span>