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/taskOrderBy.js"></script>
|
||||||
<script src="scripts/filters/taskStatus.js"></script>
|
<script src="scripts/filters/taskStatus.js"></script>
|
||||||
<script src="scripts/filters/volume.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/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/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/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/aria2HttpRpcService.js"></script>
|
||||||
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
|
<script src="scripts/services/aria2WebSocketRpcService.js"></script>
|
||||||
<script src="scripts/services/aria2RpcService.js"></script>
|
<script src="scripts/services/aria2RpcService.js"></script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'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) {
|
var processStatResult = function (stat) {
|
||||||
if (!stat) {
|
if (!stat) {
|
||||||
return stat;
|
return stat;
|
||||||
|
@ -20,10 +20,6 @@
|
||||||
return ariaNgConstants.settingHistoryKeyPrefix + '.' + key;
|
return ariaNgConstants.settingHistoryKeyPrefix + '.' + key;
|
||||||
};
|
};
|
||||||
|
|
||||||
var isSettingHistoryKey = function (key) {
|
|
||||||
return key.indexOf(ariaNgConstants.settingHistoryKeyPrefix + '.') === 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isOptionKeyValid: function (key) {
|
isOptionKeyValid: function (key) {
|
||||||
var option = aria2AllOptions[key];
|
var option = aria2AllOptions[key];
|
||||||
|
@ -191,7 +187,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var storageKey = getSettingHistoryKey(key);
|
var storageKey = getSettingHistoryKey(key);
|
||||||
var history = localStorageService.get(storageKey) || [];
|
var history = ariaNgStorageService.get(storageKey) || [];
|
||||||
var newHistory = [];
|
var newHistory = [];
|
||||||
|
|
||||||
for (var i = 0; i < Math.min(history.length, ariaNgConstants.historyMaxStoreCount); i++) {
|
for (var i = 0; i < Math.min(history.length, ariaNgConstants.historyMaxStoreCount); i++) {
|
||||||
|
@ -206,7 +202,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var storageKey = getSettingHistoryKey(key);
|
var storageKey = getSettingHistoryKey(key);
|
||||||
var history = localStorageService.get(storageKey) || [];
|
var history = ariaNgStorageService.get(storageKey) || [];
|
||||||
var newHistory = [];
|
var newHistory = [];
|
||||||
newHistory.push(value);
|
newHistory.push(value);
|
||||||
|
|
||||||
|
@ -216,17 +212,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorageService.set(storageKey, newHistory);
|
ariaNgStorageService.set(storageKey, newHistory);
|
||||||
|
|
||||||
return newHistory;
|
return newHistory;
|
||||||
},
|
},
|
||||||
clearSettingsHistorys: function () {
|
clearSettingsHistorys: function () {
|
||||||
var keys = localStorageService.keys();
|
var keys = ariaNgStorageService.keys(ariaNgConstants.settingHistoryKeyPrefix + '.');
|
||||||
|
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
if (isSettingHistoryKey(keys[i])) {
|
ariaNgStorageService.remove(keys[i]);
|
||||||
localStorageService.remove(keys[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getGlobalOption: function (callback, silent) {
|
getGlobalOption: function (callback, silent) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'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) {
|
var getKeyValuePair = function (line) {
|
||||||
for (var i = 0; i < line.length; i++) {
|
for (var i = 0; i < line.length; i++) {
|
||||||
if (i > 0 && line.charAt(i - 1) !== '\\' && line.charAt(i) === '=') {
|
if (i > 0 && line.charAt(i - 1) !== '\\' && line.charAt(i) === '=') {
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var languageKey = ariaNgConstants.languageStorageKeyPrefix + '.' + options.key;
|
var languageKey = ariaNgConstants.languageStorageKeyPrefix + '.' + options.key;
|
||||||
var languageResource = localStorageService.get(languageKey);
|
var languageResource = ariaNgStorageService.get(languageKey);
|
||||||
|
|
||||||
if (languageResource) {
|
if (languageResource) {
|
||||||
deferred.resolve(languageResource);
|
deferred.resolve(languageResource);
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then(function onSuccess(response) {
|
}).then(function onSuccess(response) {
|
||||||
var languageObject = getLanguageObject(response.data);
|
var languageObject = getLanguageObject(response.data);
|
||||||
localStorageService.set(languageKey, languageObject);
|
ariaNgStorageService.set(languageKey, languageObject);
|
||||||
return deferred.resolve(languageObject);
|
return deferred.resolve(languageObject);
|
||||||
}).catch(function onError(response) {
|
}).catch(function onError(response) {
|
||||||
ariaNgLogService.warn('[ariaNgLanguageLoader] cannot get language resource');
|
ariaNgLogService.warn('[ariaNgLanguageLoader] cannot get language resource');
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'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 browserFeatures = (function () {
|
||||||
var supportLocalStroage = localStorageService.isSupported;
|
var supportLocalStroage = ariaNgStorageService.isLocalStorageSupported();
|
||||||
var supportCookies = $window.navigator.cookieEnabled;
|
var supportCookies = ariaNgStorageService.isCookiesSupported();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
localStroage: supportLocalStroage,
|
localStroage: supportLocalStroage,
|
||||||
|
@ -110,11 +110,11 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var setOptions = function (options) {
|
var setOptions = function (options) {
|
||||||
return localStorageService.set(ariaNgConstants.optionStorageKey, options);
|
return ariaNgStorageService.set(ariaNgConstants.optionStorageKey, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
var getOptions = function () {
|
var getOptions = function () {
|
||||||
var options = localStorageService.get(ariaNgConstants.optionStorageKey);
|
var options = ariaNgStorageService.get(ariaNgConstants.optionStorageKey);
|
||||||
|
|
||||||
if (options && !ariaNgLanguages[options.language]) {
|
if (options && !ariaNgLanguages[options.language]) {
|
||||||
options.language = getLanguageNameFromAliasOrDefaultLanguage(options.language);
|
options.language = getLanguageNameFromAliasOrDefaultLanguage(options.language);
|
||||||
|
@ -146,7 +146,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var clearAll = function () {
|
var clearAll = function () {
|
||||||
return localStorageService.clearAll();
|
return ariaNgStorageService.clearAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
var getOption = function (key) {
|
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