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/aria2SettingService.js

97 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-05-31 16:51:12 +02:00
(function () {
'use strict';
angular.module('ariaNg').factory('aria2SettingService', ['aria2AllOptions', 'aria2GlobalAvailableOptions', 'aria2RpcService', function (aria2AllOptions, aria2GlobalAvailableOptions, aria2RpcService) {
var processStatResult = function (stat) {
if (!stat) {
return stat;
}
var activeCount = parseInt(stat.numActive);
var waitingCount = parseInt(stat.numWaiting);
var totalRunningCount = activeCount + waitingCount;
stat.totalRunningCount = totalRunningCount;
return stat;
};
return {
getAvailableOptionsKeys: function (type) {
if (type == 'basic') {
return aria2GlobalAvailableOptions.basicOptions;
} else if (type == 'http-ftp-sftp') {
return aria2GlobalAvailableOptions.httpFtpSFtpOptions;
} else if (type == 'http') {
return aria2GlobalAvailableOptions.httpOptions;
} else if (type == 'ftp-sftp') {
return aria2GlobalAvailableOptions.ftpSFtpOptions;
} else if (type == 'bt') {
return aria2GlobalAvailableOptions.btOptions;
} else if (type == 'metalink') {
return aria2GlobalAvailableOptions.metalinkOptions;
} else if (type == 'rpc') {
return aria2GlobalAvailableOptions.rpcOptions;
} else if (type == 'advanced') {
return aria2GlobalAvailableOptions.advancedOptions;
} else {
return false;
}
},
getSpecifiedOptions: function (keys) {
var options = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var option = aria2AllOptions[key];
if (!option) {
continue;
}
option = angular.extend({
key: key,
nameKey: 'options.' + key + '.name',
descriptionKey: 'options.' + key + '.description'
}, option);
options.push(option);
}
return options;
},
getGlobalOption: function (callback) {
return aria2RpcService.getGlobalOption({
callback: callback
});
},
setGlobalOption: function (key, value, callback) {
var data = {};
data[key] = value;
return aria2RpcService.changeGlobalOption({
options: data,
callback: callback
});
},
getServerStatus: function (callback) {
return aria2RpcService.getVersion({
callback: callback
})
},
getGlobalStat: function (callback) {
return aria2RpcService.getGlobalStat({
callback: function (result) {
if (!callback) {
return;
}
var stat = processStatResult(result);
callback(stat);
}
});
}
};
}]);
})();