code refactor

This commit is contained in:
MaysWind 2018-08-12 16:22:59 +08:00
parent 8df955a372
commit a7e1d3a1f0
2 changed files with 10 additions and 5 deletions

View file

@ -1,7 +1,8 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgLogService', ['$log', 'moment', 'ariaNgConstants', 'ariaNgSettingService', function ($log, moment, ariaNgConstants, ariaNgSettingService) {
angular.module('ariaNg').factory('ariaNgLogService', ['$log', 'moment', 'ariaNgConstants', function ($log, moment, ariaNgConstants) {
var enableDebugLog = false;
var cachedDebugLogs = [];
var createNewCacheLogItem = function (msg, level, obj) {
@ -14,7 +15,7 @@
};
var pushLogToCache = function (msg, level, obj) {
if (!ariaNgSettingService.isEnableDebugMode()) {
if (!enableDebugLog) {
return;
}
@ -26,8 +27,11 @@
};
return {
setEnableDebugLog: function (value) {
enableDebugLog = value;
},
debug: function (msg, obj) {
if (ariaNgSettingService.isEnableDebugMode()) {
if (enableDebugLog) {
if (obj) {
$log.debug('[AriaNg Debug]' + msg, obj);
} else {
@ -65,7 +69,7 @@
pushLogToCache(msg, 'ERROR', obj);
},
getDebugLogs: function () {
if (ariaNgSettingService.isEnableDebugMode()) {
if (enableDebugLog) {
return cachedDebugLogs;
} else {
return [];

View file

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', function ($window, $location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService) {
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', function ($window, $location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService) {
var browserFeatures = (function () {
var supportLocalStroage = localStorageService.isSupported;
var supportCookies = $window.navigator.cookieEnabled;
@ -270,6 +270,7 @@
},
setDebugMode: function (value) {
sessionSettings.debugMode = value;
ariaNgLogService.setEnableDebugLog(value);
},
getTitle: function () {
return getOption('title');