2016-05-13 18:09:12 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-16 18:59:27 +02:00
|
|
|
angular.module('ariaNg').factory('ariaNgSettingService', ['$location', '$translate', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', function ($location, $translate, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions) {
|
|
|
|
var getDefaultRpcHost = function () {
|
|
|
|
return $location.$$host;
|
2016-05-16 17:41:39 +02:00
|
|
|
};
|
|
|
|
|
2016-05-13 18:09:12 +02:00
|
|
|
var setOptions = function (options) {
|
2016-05-16 18:59:27 +02:00
|
|
|
return localStorageService.set(ariaNgConstants.optionStorageKey, options);
|
2016-05-13 18:09:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var getOptions = function () {
|
2016-05-16 18:59:27 +02:00
|
|
|
var options = localStorageService.get(ariaNgConstants.optionStorageKey);
|
2016-05-13 18:09:12 +02:00
|
|
|
|
|
|
|
if (!options) {
|
|
|
|
options = angular.extend({}, ariaNgDefaultOptions);
|
|
|
|
setOptions(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
|
|
|
var getOption = function (key) {
|
2016-05-16 15:32:15 +02:00
|
|
|
var options = getOptions();
|
|
|
|
|
|
|
|
if (angular.isUndefined(options[key])) {
|
|
|
|
options[key] = ariaNgDefaultOptions[key];
|
|
|
|
setOptions(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options[key];
|
2016-05-13 18:09:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var setOption = function (key, value) {
|
|
|
|
var options = getOptions();
|
|
|
|
options[key] = value;
|
|
|
|
|
|
|
|
setOptions(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2016-05-16 17:41:39 +02:00
|
|
|
getAllOptions: function () {
|
|
|
|
var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
|
|
|
|
|
2016-05-16 18:59:27 +02:00
|
|
|
if (!options.rpcHost) {
|
|
|
|
options.rpcHost = getDefaultRpcHost();
|
2016-05-16 17:41:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
2016-05-13 18:09:12 +02:00
|
|
|
},
|
2016-05-16 17:41:39 +02:00
|
|
|
setAllOptions: function (options) {
|
|
|
|
setOptions(options);
|
|
|
|
},
|
|
|
|
getLanguage: function () {
|
|
|
|
return getOption('language');
|
|
|
|
},
|
|
|
|
setLanguage: function (value) {
|
|
|
|
setOption('language', value);
|
2016-05-13 18:09:12 +02:00
|
|
|
$translate.use(value);
|
2016-05-16 17:41:39 +02:00
|
|
|
amMoment.changeLocale(value);
|
2016-05-13 18:09:12 +02:00
|
|
|
},
|
2016-05-16 18:59:27 +02:00
|
|
|
getJsonRpcUrl: function () {
|
|
|
|
var protocol = getOption('protocol');
|
|
|
|
var rpcHost = getOption('rpcHost');
|
|
|
|
var rpcPort = getOption('rpcPort');
|
2016-05-13 18:09:12 +02:00
|
|
|
|
|
|
|
if (!rpcHost) {
|
2016-05-16 18:59:27 +02:00
|
|
|
rpcHost = getDefaultRpcHost();
|
2016-05-13 18:09:12 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 18:59:27 +02:00
|
|
|
return protocol + '://' + rpcHost + ':' + rpcPort + '/jsonrpc';
|
2016-05-16 15:28:23 +02:00
|
|
|
},
|
2016-05-16 18:59:27 +02:00
|
|
|
setRpcHost: function (value) {
|
|
|
|
setOption('rpcHost', value);
|
|
|
|
},
|
|
|
|
setRpcPort: function (value) {
|
2016-05-22 05:23:08 +02:00
|
|
|
setOption('rpcPort', Math.max(parseInt(value), 0));
|
2016-05-16 17:41:39 +02:00
|
|
|
},
|
2016-05-16 15:28:23 +02:00
|
|
|
getProtocol: function () {
|
|
|
|
return getOption('protocol');
|
|
|
|
},
|
|
|
|
setProtocol: function (value) {
|
2016-05-22 05:23:08 +02:00
|
|
|
setOption('protocol', value);
|
2016-05-13 18:09:12 +02:00
|
|
|
},
|
|
|
|
getGlobalStatRefreshInterval: function () {
|
|
|
|
return getOption('globalStatRefreshInterval');
|
|
|
|
},
|
2016-05-17 16:15:28 +02:00
|
|
|
setGlobalStatRefreshInterval: function (value) {
|
|
|
|
setOption('globalStatRefreshInterval', Math.max(parseInt(value), 0));
|
|
|
|
},
|
2016-05-13 18:09:12 +02:00
|
|
|
getDownloadTaskRefreshInterval: function () {
|
|
|
|
return getOption('downloadTaskRefreshInterval');
|
|
|
|
},
|
2016-05-17 16:15:28 +02:00
|
|
|
setDownloadTaskRefreshInterval: function (value) {
|
|
|
|
setOption('downloadTaskRefreshInterval', Math.max(parseInt(value), 0));
|
|
|
|
},
|
2016-05-13 18:09:12 +02:00
|
|
|
getDisplayOrder: function () {
|
|
|
|
var value = getOption('displayOrder');
|
2016-05-16 15:28:23 +02:00
|
|
|
|
2016-05-13 18:09:12 +02:00
|
|
|
if (!value) {
|
2016-05-22 05:13:05 +02:00
|
|
|
value = 'default:false';
|
2016-05-13 18:09:12 +02:00
|
|
|
}
|
2016-05-16 15:28:23 +02:00
|
|
|
|
2016-05-13 18:09:12 +02:00
|
|
|
return value;
|
|
|
|
},
|
|
|
|
setDisplayOrder: function (value) {
|
|
|
|
setOption('displayOrder', value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
})();
|