This repository has been archived on 2022-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
AriaNg/app/scripts/services/ariaNgSettingService.js

125 lines
4.1 KiB
JavaScript
Raw Normal View History

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-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) {
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 {
getAllOptions: function () {
var options = angular.extend({}, ariaNgDefaultOptions, getOptions());
2016-05-16 18:59:27 +02:00
if (!options.rpcHost) {
options.rpcHost = getDefaultRpcHost();
}
return options;
2016-05-13 18:09:12 +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);
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 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));
},
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-13 18:09:12 +02:00
if (!value) {
value = 'default:false';
2016-05-13 18:09:12 +02:00
}
2016-05-13 18:09:12 +02:00
return value;
},
setDisplayOrder: function (value) {
setOption('displayOrder', value);
},
getFileListDisplayOrder: function () {
var value = getOption('fileListDisplayOrder');
if (!value) {
value = 'default:false';
}
return value;
},
setFileListDisplayOrder: function (value) {
setOption('fileListDisplayOrder', value);
2016-05-13 18:09:12 +02:00
}
};
}]);
})();