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

103 lines
3.2 KiB
JavaScript
Raw Normal View History

2016-05-13 18:09:12 +02:00
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgSettingService', ['$location', '$translate', 'amMoment', 'localStorageService', 'ariaNgDefaultOptions', function ($location, $translate, amMoment, localStorageService, ariaNgDefaultOptions) {
var getDefaultJsonRpcHost = function () {
var rpcHost = $location.$$host + ':6800';
return rpcHost;
};
2016-05-13 18:09:12 +02:00
var setOptions = function (options) {
return localStorageService.set('Options', options);
};
var getOptions = function () {
var options = localStorageService.get('Options');
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());
if (!options.aria2RpcHost) {
options.aria2RpcHost = getDefaultJsonRpcHost();
}
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
},
getJsonRpcUrl: function (protocol) {
2016-05-13 18:09:12 +02:00
var rpcHost = getOption('aria2RpcHost');
if (!rpcHost) {
rpcHost = getDefaultJsonRpcHost();
2016-05-13 18:09:12 +02:00
}
return protocol + '://' + rpcHost + '/jsonrpc';
},
setJsonRpcHost: function (value) {
setOption('aria2RpcHost', value);
},
getProtocol: function () {
return getOption('protocol');
},
setProtocol: function (value) {
setOption('protocol', value);
2016-05-13 18:09:12 +02:00
},
getGlobalStatRefreshInterval: function () {
return getOption('globalStatRefreshInterval');
},
getDownloadTaskRefreshInterval: function () {
return getOption('downloadTaskRefreshInterval');
},
getDisplayOrder: function () {
var value = getOption('displayOrder');
2016-05-13 18:09:12 +02:00
if (!value) {
value = 'default';
}
2016-05-13 18:09:12 +02:00
return value;
},
setDisplayOrder: function (value) {
setOption('displayOrder', value);
}
};
}]);
})();