Project

General

Profile

1
var module = angular.module('shutdownUI', []);
2

    
3
module.controller('shutdownCtrl', function ($scope, $http) {
4
	$scope.stoppables = [];
5
	
6
	$scope.stopLaunched = false;
7
	$scope.stopEnded = false;
8
	
9
	initSpinner();
10
	
11
	$scope.loadStoppables = function() {
12
		showSpinner();
13
		$scope.stoppables = [];
14
		$http.get('shutdown/listStoppableDetails.json').success(function(data) {
15
			hideSpinner();
16
			$scope.stoppables = data;
17
			$scope.calculateStatus();
18
		}).error(function() {
19
			show_notification("error","An error occurred while fetching stoppable modules");
20
			hideSpinner();
21
		});
22
	}
23
	
24
	$scope.calculateStatus = function() {
25
		var lauched = true;
26
		var ended = true;
27
		angular.forEach($scope.stoppables, function(value, key) {
28
			if (value.status == 'RUNNING') {
29
				lauched = false;
30
			}
31
			if (value.status != 'STOPPED') {
32
				ended = false;
33
			}
34
		});
35
		$scope.stopLaunched = lauched;
36
		$scope.stopEnded = ended;
37
	}
38
		
39
	$scope.prepareShutdown = function() {
40
		if (confirm("Are you sure ?")) {
41
			showSpinner();
42
			$scope.stoppables = [];
43
			$http.get('shutdown/stopAll.do').success(function(data) {
44
				hideSpinner();
45
				$scope.stopLaunched = true;
46
				show_notification("info", "You will be able to stop the web application soon");
47
				$scope.loadStoppables();
48
			}).error(function() {
49
				show_notification("error","An error occurred while fetching stoppable modules");
50
				hideSpinner();
51
			});
52
		}
53
	}
54
	
55
	$scope.resumeShutdown = function() {
56
		if (confirm("Are you sure ?")) {
57
			showSpinner();
58
			$scope.stoppables = [];
59
			$http.get('shutdown/resumeAll.do').success(function(data) {
60
				hideSpinner();
61
				$scope.stopLaunched = false;
62
				show_notification("info", "Resuming stopped modules");
63
				$scope.loadStoppables();
64
			}).error(function() {
65
				show_notification("error","An error occurred while fetching stoppable modules");
66
				hideSpinner();
67
			});
68
		}
69
	}
70
	
71
	$scope.loadStoppables();
72

    
73
});
    (1-1/1)