code refactor
This commit is contained in:
parent
150d1923f7
commit
12d4149104
|
@ -386,15 +386,16 @@
|
|||
<script src="scripts/filters/taskOrderBy.js"></script>
|
||||
<script src="scripts/filters/taskStatus.js"></script>
|
||||
<script src="scripts/filters/volume.js"></script>
|
||||
<script src="scripts/services/ariaNgCommonService.js"></script>
|
||||
<script src="scripts/services/ariaNgFileService.js"></script>
|
||||
<script src="scripts/services/ariaNgLanguageLoader.js"></script>
|
||||
<script src="scripts/services/ariaNgMonitorService.js"></script>
|
||||
<script src="scripts/services/ariaNgCommonService.js"></script>
|
||||
<script src="scripts/services/ariaNgNotificationService.js"></script>
|
||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||
<script src="scripts/services/ariaNgTitleService.js"></script>
|
||||
<script src="scripts/services/ariaNgLogService.js"></script>
|
||||
<script src="scripts/services/ariaNgLocalizationService.js"></script>
|
||||
<script src="scripts/services/ariaNgLogService.js"></script>
|
||||
<script src="scripts/services/ariaNgStorageService.js"></script>
|
||||
<script src="scripts/services/ariaNgFileService.js"></script>
|
||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||
<script src="scripts/services/ariaNgMonitorService.js"></script>
|
||||
<script src="scripts/services/ariaNgTitleService.js"></script>
|
||||
<script src="scripts/services/aria2HttpRpcService.js"></script>
|
||||
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
|
||||
<script src="scripts/services/aria2RpcService.js"></script>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('aria2SettingService', ['localStorageService', 'ariaNgConstants', 'aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2QuickSettingsAvailableOptions', 'aria2TaskAvailableOptions', 'aria2RpcService', 'ariaNgLogService', function (localStorageService, ariaNgConstants, aria2AllOptions, aria2GlobalAvailableOptions, aria2QuickSettingsAvailableOptions, aria2TaskAvailableOptions, aria2RpcService, ariaNgLogService) {
|
||||
angular.module('ariaNg').factory('aria2SettingService', ['ariaNgConstants', 'aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2QuickSettingsAvailableOptions', 'aria2TaskAvailableOptions', 'aria2RpcService', 'ariaNgLogService', 'ariaNgStorageService', function (ariaNgConstants, aria2AllOptions, aria2GlobalAvailableOptions, aria2QuickSettingsAvailableOptions, aria2TaskAvailableOptions, aria2RpcService, ariaNgLogService, ariaNgStorageService) {
|
||||
var processStatResult = function (stat) {
|
||||
if (!stat) {
|
||||
return stat;
|
||||
|
@ -20,10 +20,6 @@
|
|||
return ariaNgConstants.settingHistoryKeyPrefix + '.' + key;
|
||||
};
|
||||
|
||||
var isSettingHistoryKey = function (key) {
|
||||
return key.indexOf(ariaNgConstants.settingHistoryKeyPrefix + '.') === 0;
|
||||
};
|
||||
|
||||
return {
|
||||
isOptionKeyValid: function (key) {
|
||||
var option = aria2AllOptions[key];
|
||||
|
@ -191,7 +187,7 @@
|
|||
}
|
||||
|
||||
var storageKey = getSettingHistoryKey(key);
|
||||
var history = localStorageService.get(storageKey) || [];
|
||||
var history = ariaNgStorageService.get(storageKey) || [];
|
||||
var newHistory = [];
|
||||
|
||||
for (var i = 0; i < Math.min(history.length, ariaNgConstants.historyMaxStoreCount); i++) {
|
||||
|
@ -206,7 +202,7 @@
|
|||
}
|
||||
|
||||
var storageKey = getSettingHistoryKey(key);
|
||||
var history = localStorageService.get(storageKey) || [];
|
||||
var history = ariaNgStorageService.get(storageKey) || [];
|
||||
var newHistory = [];
|
||||
newHistory.push(value);
|
||||
|
||||
|
@ -216,17 +212,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
localStorageService.set(storageKey, newHistory);
|
||||
ariaNgStorageService.set(storageKey, newHistory);
|
||||
|
||||
return newHistory;
|
||||
},
|
||||
clearSettingsHistorys: function () {
|
||||
var keys = localStorageService.keys();
|
||||
var keys = ariaNgStorageService.keys(ariaNgConstants.settingHistoryKeyPrefix + '.');
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (isSettingHistoryKey(keys[i])) {
|
||||
localStorageService.remove(keys[i]);
|
||||
}
|
||||
ariaNgStorageService.remove(keys[i]);
|
||||
}
|
||||
},
|
||||
getGlobalOption: function (callback, silent) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgLanguageLoader', ['$http', '$q', 'localStorageService', 'ariaNgConstants', 'ariaNgLanguages', 'ariaNgNotificationService', 'ariaNgLogService', function ($http, $q, localStorageService, ariaNgConstants, ariaNgLanguages, ariaNgNotificationService, ariaNgLogService) {
|
||||
angular.module('ariaNg').factory('ariaNgLanguageLoader', ['$http', '$q', 'ariaNgConstants', 'ariaNgLanguages', 'ariaNgNotificationService', 'ariaNgLogService', 'ariaNgStorageService', function ($http, $q, ariaNgConstants, ariaNgLanguages, ariaNgNotificationService, ariaNgLogService, ariaNgStorageService) {
|
||||
var getKeyValuePair = function (line) {
|
||||
for (var i = 0; i < line.length; i++) {
|
||||
if (i > 0 && line.charAt(i - 1) !== '\\' && line.charAt(i) === '=') {
|
||||
|
@ -90,7 +90,7 @@
|
|||
}
|
||||
|
||||
var languageKey = ariaNgConstants.languageStorageKeyPrefix + '.' + options.key;
|
||||
var languageResource = localStorageService.get(languageKey);
|
||||
var languageResource = ariaNgStorageService.get(languageKey);
|
||||
|
||||
if (languageResource) {
|
||||
deferred.resolve(languageResource);
|
||||
|
@ -103,7 +103,7 @@
|
|||
method: 'GET'
|
||||
}).then(function onSuccess(response) {
|
||||
var languageObject = getLanguageObject(response.data);
|
||||
localStorageService.set(languageKey, languageObject);
|
||||
ariaNgStorageService.set(languageKey, languageObject);
|
||||
return deferred.resolve(languageObject);
|
||||
}).catch(function onError(response) {
|
||||
ariaNgLogService.warn('[ariaNgLanguageLoader] cannot get language resource');
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', function ($window, $location, $filter, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService) {
|
||||
angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgLogService', 'ariaNgStorageService', function ($window, $location, $filter, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages, ariaNgCommonService, ariaNgLogService, ariaNgStorageService) {
|
||||
var browserFeatures = (function () {
|
||||
var supportLocalStroage = localStorageService.isSupported;
|
||||
var supportCookies = $window.navigator.cookieEnabled;
|
||||
var supportLocalStroage = ariaNgStorageService.isLocalStorageSupported();
|
||||
var supportCookies = ariaNgStorageService.isCookiesSupported();
|
||||
|
||||
return {
|
||||
localStroage: supportLocalStroage,
|
||||
|
@ -110,11 +110,11 @@
|
|||
};
|
||||
|
||||
var setOptions = function (options) {
|
||||
return localStorageService.set(ariaNgConstants.optionStorageKey, options);
|
||||
return ariaNgStorageService.set(ariaNgConstants.optionStorageKey, options);
|
||||
};
|
||||
|
||||
var getOptions = function () {
|
||||
var options = localStorageService.get(ariaNgConstants.optionStorageKey);
|
||||
var options = ariaNgStorageService.get(ariaNgConstants.optionStorageKey);
|
||||
|
||||
if (options && !ariaNgLanguages[options.language]) {
|
||||
options.language = getLanguageNameFromAliasOrDefaultLanguage(options.language);
|
||||
|
@ -146,7 +146,7 @@
|
|||
};
|
||||
|
||||
var clearAll = function () {
|
||||
return localStorageService.clearAll();
|
||||
return ariaNgStorageService.clearAll();
|
||||
};
|
||||
|
||||
var getOption = function (key) {
|
||||
|
|
43
src/scripts/services/ariaNgStorageService.js
Normal file
43
src/scripts/services/ariaNgStorageService.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgStorageService', ['$window', 'localStorageService', function ($window, localStorageService) {
|
||||
return {
|
||||
isLocalStorageSupported: function () {
|
||||
return localStorageService.isSupported;
|
||||
},
|
||||
isCookiesSupported: function () {
|
||||
return localStorageService.cookie.isSupported;
|
||||
},
|
||||
get: function (key) {
|
||||
return localStorageService.get(key);
|
||||
},
|
||||
set: function (key, value) {
|
||||
return localStorageService.set(key, value);
|
||||
},
|
||||
remove: function (key) {
|
||||
return localStorageService.remove(key);
|
||||
},
|
||||
clearAll: function () {
|
||||
return localStorageService.clearAll();
|
||||
},
|
||||
keys: function (prefix) {
|
||||
var allKeys = localStorageService.keys();
|
||||
|
||||
if (!allKeys || !allKeys.length || !prefix) {
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
var result = [];
|
||||
|
||||
for (var i = 0; i < allKeys.length; i++) {
|
||||
if (allKeys[i].indexOf(prefix) >= 0) {
|
||||
result.push(allKeys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}());
|
Reference in a new issue