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 () { (function () {
'use strict'; '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 cachedDebugLogs = [];
var createNewCacheLogItem = function (msg, level, obj) { var createNewCacheLogItem = function (msg, level, obj) {
@ -14,7 +15,7 @@
}; };
var pushLogToCache = function (msg, level, obj) { var pushLogToCache = function (msg, level, obj) {
if (!ariaNgSettingService.isEnableDebugMode()) { if (!enableDebugLog) {
return; return;
} }
@ -26,8 +27,11 @@
}; };
return { return {
setEnableDebugLog: function (value) {
enableDebugLog = value;
},
debug: function (msg, obj) { debug: function (msg, obj) {
if (ariaNgSettingService.isEnableDebugMode()) { if (enableDebugLog) {
if (obj) { if (obj) {
$log.debug('[AriaNg Debug]' + msg, obj); $log.debug('[AriaNg Debug]' + msg, obj);
} else { } else {
@ -65,7 +69,7 @@
pushLogToCache(msg, 'ERROR', obj); pushLogToCache(msg, 'ERROR', obj);
}, },
getDebugLogs: function () { getDebugLogs: function () {
if (ariaNgSettingService.isEnableDebugMode()) { if (enableDebugLog) {
return cachedDebugLogs; return cachedDebugLogs;
} else { } else {
return []; return [];

View file

@ -1,7 +1,7 @@
(function () { (function () {
'use strict'; '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 browserFeatures = (function () {
var supportLocalStroage = localStorageService.isSupported; var supportLocalStroage = localStorageService.isSupported;
var supportCookies = $window.navigator.cookieEnabled; var supportCookies = $window.navigator.cookieEnabled;
@ -270,6 +270,7 @@
}, },
setDebugMode: function (value) { setDebugMode: function (value) {
sessionSettings.debugMode = value; sessionSettings.debugMode = value;
ariaNgLogService.setEnableDebugLog(value);
}, },
getTitle: function () { getTitle: function () {
return getOption('title'); return getOption('title');