Passed
Push — master ( 288f92...809e6b )
by
unknown
13:11 queued 13s
created

myems-admin/app/controllers/settings/energystoragecontainer/energystoragecontainerfirecontrol.controller.js   A

Complexity

Total Complexity 35
Complexity/F 1.25

Size

Lines of Code 215
Function Count 28

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 35
eloc 148
dl 0
loc 215
rs 9.6
c 0
b 0
f 0
mnd 7
bc 7
fnc 28
bpm 0.25
cpm 1.25
noi 0
1
'use strict';
2
3
app.controller('EnergyStorageContainerFirecontrolController', function(
4
	$scope,
5
	$rootScope,
6
	$window,
7
	$translate,
8
	$uibModal,
9
	EnergyStorageContainerService,
10
	EnergyStorageContainerFirecontrolService,
11
	PointService,
12
	toaster,
13
	SweetAlert) {
14
      $scope.energystoragecontainers = [];
15
      $scope.energystoragecontainerfirecontrols = [];
16
	  $scope.points = [];
17
      $scope.currentEnergyStorageContainer = null;
18
	  $scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
19
      $scope.getAllEnergyStorageContainers = function() {
20
		let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
21
  		EnergyStorageContainerService.getAllEnergyStorageContainers(headers, function (response) {
22
  			if (angular.isDefined(response.status) && response.status === 200) {
23
  				$scope.energystoragecontainers = response.data;
24
  			} else {
25
  				$scope.energystoragecontainers = [];
26
  			}
27
  		});
28
  	};
29
30
	$scope.getAllPoints = function() {
31
		let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
32
		PointService.getAllPoints(headers, function (response) {
33
			if (angular.isDefined(response.status) && response.status === 200) {
34
				$scope.points = response.data;
35
			} else {
36
				$scope.points = [];
37
			}
38
		});
39
	};
40
41
  	$scope.getEnergyStorageContainerFirecontrolsByEnergyStorageContainerID = function(id) {
42
		let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
43
  		EnergyStorageContainerFirecontrolService.getEnergyStorageContainerFirecontrolsByEnergyStorageContainerID(id, headers, function (response) {
44
			if (angular.isDefined(response.status) && response.status === 200) {
45
				$scope.energystoragecontainerfirecontrols = response.data;
46
			} else {
47
          	$scope.energystoragecontainerfirecontrols=[];
48
        }
49
			});
50
  	};
51
52
  	$scope.changeEnergyStorageContainer=function(item,model){
53
    	$scope.currentEnergyStorageContainer=item;
54
    	$scope.currentEnergyStorageContainer.selected=model;
55
        $scope.is_show_add_energystoragecontainer_firecontrol = true;
56
    	$scope.getEnergyStorageContainerFirecontrolsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
57
  	};
58
59
  	$scope.addEnergyStorageContainerFirecontrol = function() {
60
61
  		var modalInstance = $uibModal.open({
62
  			templateUrl: 'views/settings/energystoragecontainer/energystoragecontainerfirecontrol.model.html',
63
  			controller: 'ModalAddEnergyStorageContainerFirecontrolCtrl',
64
  			windowClass: "animated fadeIn",
65
  			resolve: {
66
  				params: function() {
67
  					return {
68
						points: angular.copy($scope.points),
69
  					};
70
  				}
71
  			}
72
  		});
73
  		modalInstance.result.then(function(energystoragecontainerfirecontrol) {
74
75
			let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
76
  			EnergyStorageContainerFirecontrolService.addEnergyStorageContainerFirecontrol($scope.currentEnergyStorageContainer.id, energystoragecontainerfirecontrol, headers, function (response) {
77
  				if (angular.isDefined(response.status) && response.status === 201) {
78
  					toaster.pop({
79
  						type: "success",
80
  						title: $translate.instant("TOASTER.SUCCESS_TITLE"),
81
  						body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_FIRECONTROL")}),
82
  						showCloseButton: true,
83
  					});
84
  					$scope.getEnergyStorageContainerFirecontrolsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
85
            		$scope.$emit('handleEmitEnergyStorageContainerFirecontrolChanged');
86
  				} else {
87
  					toaster.pop({
88
  						type: "error",
89
  						title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_FIRECONTROL")}),
90
  						body: $translate.instant(response.data.description),
91
  						showCloseButton: true,
92
  					});
93
  				}
94
  			});
95
  		}, function() {
96
97
  		});
98
		$rootScope.modalInstance = modalInstance;
99
  	};
100
101
  	$scope.editEnergyStorageContainerFirecontrol = function(energystoragecontainerfirecontrol) {
102
  		var modalInstance = $uibModal.open({
103
  			templateUrl: 'views/settings/energystoragecontainer/energystoragecontainerfirecontrol.model.html',
104
  			controller: 'ModalEditEnergyStorageContainerFirecontrolCtrl',
105
    		windowClass: "animated fadeIn",
106
  			resolve: {
107
  				params: function() {
108
  					return {
109
  						energystoragecontainerfirecontrol: angular.copy(energystoragecontainerfirecontrol),
110
						points: angular.copy($scope.points),
111
  					};
112
  				}
113
  			}
114
  		});
115
116
  		modalInstance.result.then(function(modifiedEnergyStorageContainerFirecontrol) {
117
118
			let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
119
  			EnergyStorageContainerFirecontrolService.editEnergyStorageContainerFirecontrol($scope.currentEnergyStorageContainer.id, modifiedEnergyStorageContainerFirecontrol, headers, function (response) {
120
  				if (angular.isDefined(response.status) && response.status === 200) {
121
  					toaster.pop({
122
  						type: "success",
123
  						title: $translate.instant("TOASTER.SUCCESS_TITLE"),
124
  						body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_FIRECONTROL")}),
125
  						showCloseButton: true,
126
  					});
127
  					$scope.getEnergyStorageContainerFirecontrolsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
128
            		$scope.$emit('handleEmitEnergyStorageContainerFirecontrolChanged');
129
  				} else {
130
  					toaster.pop({
131
  						type: "error",
132
  						title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_FIRECONTROL")}),
133
  						body: $translate.instant(response.data.description),
134
  						showCloseButton: true,
135
  					});
136
  				}
137
  			});
138
  		}, function() {
139
  			//do nothing;
140
  		});
141
		$rootScope.modalInstance = modalInstance;
142
  	};
143
144
  	$scope.deleteEnergyStorageContainerFirecontrol = function(energystoragecontainerfirecontrol) {
145
  		SweetAlert.swal({
146
  				title: $translate.instant("SWEET.TITLE"),
147
  				text: $translate.instant("SWEET.TEXT"),
148
  				type: "warning",
149
  				showCancelButton: true,
150
  				confirmButtonColor: "#DD6B55",
151
  				confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"),
152
  				cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"),
153
  				closeOnConfirm: true,
154
  				closeOnCancel: true
155
  			},
156
  			function(isConfirm) {
157
  				if (isConfirm) {
158
					let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
159
  					EnergyStorageContainerFirecontrolService.deleteEnergyStorageContainerFirecontrol($scope.currentEnergyStorageContainer.id, energystoragecontainerfirecontrol.id, headers, function (response) {
160
  						if (angular.isDefined(response.status) && response.status === 204) {
161
							toaster.pop({
162
								type: "success",
163
								title: $translate.instant("TOASTER.SUCCESS_TITLE"),
164
								body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_FIRECONTROL")}),
165
								showCloseButton: true,
166
							});
167
							$scope.getEnergyStorageContainerFirecontrolsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
168
							$scope.$emit('handleEmitEnergyStorageContainerFirecontrolChanged');
169
  						} else {
170
							toaster.pop({
171
								type: "error",
172
								title: $translate.instant("TOASTER.ERROR_DELETE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_FIRECONTROL")}),
173
								body: $translate.instant(response.data.description),
174
								showCloseButton: true,
175
							});
176
  				   		}
177
  					});
178
  				}
179
  			});
180
  	};
181
182
  	$scope.getAllEnergyStorageContainers();
183
	$scope.getAllPoints();
184
    $scope.$on('handleBroadcastEnergyStorageContainerChanged', function(event) {
185
      $scope.getAllEnergyStorageContainers();
186
  	});
187
188
  });
189
190
191
  app.controller('ModalAddEnergyStorageContainerFirecontrolCtrl', function($scope, $uibModalInstance, params) {
192
193
  	$scope.operation = "ENERGY_STORAGE_CONTAINER.ADD_ENERGY_STORAGE_CONTAINER_FIRECONTROL";
194
	$scope.points=params.points;
195
  	$scope.ok = function() {
196
  		$uibModalInstance.close($scope.energystoragecontainerfirecontrol);
197
  	};
198
199
  	$scope.cancel = function() {
200
  		$uibModalInstance.dismiss('cancel');
201
  	};
202
  });
203
204
  app.controller('ModalEditEnergyStorageContainerFirecontrolCtrl', function($scope, $uibModalInstance, params) {
205
  	$scope.operation = "ENERGY_STORAGE_CONTAINER.EDIT_ENERGY_STORAGE_CONTAINER_FIRECONTROL";
206
  	$scope.energystoragecontainerfirecontrol = params.energystoragecontainerfirecontrol;
207
	$scope.points=params.points;
208
  	$scope.ok = function() {
209
  		$uibModalInstance.close($scope.energystoragecontainerfirecontrol);
210
  	};
211
212
  	$scope.cancel = function() {
213
  		$uibModalInstance.dismiss('cancel');
214
  	};
215
  });
216