status.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function () {
  2. 'use strict';
  3. angular.module('ariaNg').controller('Aria2StatusController', ['$rootScope', '$scope', '$timeout', 'ariaNgCommonService', 'ariaNgSettingService', 'aria2SettingService', function ($rootScope, $scope, $timeout, ariaNgCommonService, ariaNgSettingService, aria2SettingService) {
  4. $scope.context = {
  5. host: ariaNgSettingService.getCurrentRpcUrl(),
  6. serverStatus: null,
  7. isSupportReconnect: aria2SettingService.canReconnect()
  8. };
  9. $scope.reconnect = function () {
  10. if (!$scope.context.isSupportReconnect || ($rootScope.taskContext.rpcStatus !== 'Disconnected' && $rootScope.taskContext.rpcStatus !== 'Waiting to reconnect')) {
  11. return;
  12. }
  13. aria2SettingService.reconnect();
  14. };
  15. $scope.saveSession = function () {
  16. return aria2SettingService.saveSession(function (response) {
  17. if (response.success && response.data === 'OK') {
  18. ariaNgCommonService.showOperationSucceeded('Session has been saved successfully.');
  19. }
  20. });
  21. };
  22. $scope.shutdown = function () {
  23. ariaNgCommonService.confirm('Confirm Shutdown', 'Are you sure you want to shutdown aria2?', 'warning', function (status) {
  24. return aria2SettingService.shutdown(function (response) {
  25. if (response.success && response.data === 'OK') {
  26. ariaNgCommonService.showOperationSucceeded('Aria2 has been shutdown successfully.');
  27. }
  28. });
  29. }, true);
  30. };
  31. $rootScope.$watch('taskContext.rpcStatus', function (value) {
  32. if (value === 'Connected') {
  33. aria2SettingService.getAria2Status(function (response) {
  34. if (response.success) {
  35. $scope.context.serverStatus = response.data;
  36. }
  37. });
  38. } else {
  39. $scope.context.serverStatus = null;
  40. }
  41. });
  42. $rootScope.loadPromise = $timeout(function () {}, 100);
  43. }]);
  44. }());