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/controllers/main.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-05-13 18:09:12 +02:00
(function () {
'use strict';
angular.module('ariaNg').controller('MainController', ['$scope', '$interval', 'aria2RpcService', 'ariaNgSettingService', function ($scope, $interval, aria2RpcService, ariaNgSettingService) {
2016-05-17 16:15:28 +02:00
var globalStatRefreshPromise = null;
2016-05-13 18:09:12 +02:00
var processStatResult = function (stat) {
var activeCount = parseInt(stat.numActive);
var waitingCount = parseInt(stat.numWaiting);
var totalRunningCount = activeCount + waitingCount;
stat.totalRunningCount = totalRunningCount;
};
2016-05-17 16:15:28 +02:00
var refreshGlobalStat = function () {
2016-05-13 18:09:12 +02:00
aria2RpcService.getGlobalStat({
callback: function (result) {
if (result) {
processStatResult(result);
}
$scope.globalStat = result;
}
});
2016-05-17 16:15:28 +02:00
};
refreshGlobalStat();
$scope.changeDisplayOrder = function (type) {
ariaNgSettingService.setDisplayOrder(type);
};
$scope.isSetDisplayOrder = function (type) {
return ariaNgSettingService.getDisplayOrder() === type;
};
if (ariaNgSettingService.getGlobalStatRefreshInterval() > 0) {
globalStatRefreshPromise = $interval(function () {
refreshGlobalStat();
}, ariaNgSettingService.getGlobalStatRefreshInterval());
}
$scope.$on('$destroy', function () {
if (globalStatRefreshPromise) {
$interval.cancel(globalStatRefreshPromise);
}
});
2016-05-13 18:09:12 +02:00
}]);
})();