Passed
Push — master ( 49640a...288f92 )
by
unknown
11:30 queued 17s
created

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

Complexity

Total Complexity 35
Complexity/F 1.25

Size

Lines of Code 213
Function Count 28

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 35
eloc 148
dl 0
loc 213
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('EnergyStorageContainerHVACController', function(
4
	$scope,
5
	$rootScope,
6
	$window,
7
	$translate,
8
	$uibModal,
9
	EnergyStorageContainerService,
10
	EnergyStorageContainerHVACService,
11
	PointService,
12
	toaster,
13
	SweetAlert) {
14
      $scope.energystoragecontainers = [];
15
      $scope.energystoragecontainerhvacs = [];
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.getEnergyStorageContainerHVACsByEnergyStorageContainerID = function(id) {
42
		let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
43
  		EnergyStorageContainerHVACService.getEnergyStorageContainerHVACsByEnergyStorageContainerID(id, headers, function (response) {
44
			if (angular.isDefined(response.status) && response.status === 200) {
45
				$scope.energystoragecontainerhvacs = response.data;
46
			} else {
47
          	    $scope.energystoragecontainerhvacs=[];
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_hvac = true;
56
    	$scope.getEnergyStorageContainerHVACsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
57
  	};
58
59
  	$scope.addEnergyStorageContainerHVAC = function() {
60
61
  		var modalInstance = $uibModal.open({
62
  			templateUrl: 'views/settings/energystoragecontainer/energystoragecontainerhvac.model.html',
63
  			controller: 'ModalAddEnergyStorageContainerHVACCtrl',
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(energystoragecontainerhvac) {
74
			let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
75
  			EnergyStorageContainerHVACService.addEnergyStorageContainerHVAC($scope.currentEnergyStorageContainer.id, energystoragecontainerhvac, headers, function (response) {
76
  				if (angular.isDefined(response.status) && response.status === 201) {
77
  					toaster.pop({
78
  						type: "success",
79
  						title: $translate.instant("TOASTER.SUCCESS_TITLE"),
80
  						body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_HVAC")}),
81
  						showCloseButton: true,
82
  					});
83
  					$scope.getEnergyStorageContainerHVACsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
84
            		$scope.$emit('handleEmitEnergyStorageContainerHVACChanged');
85
  				} else {
86
  					toaster.pop({
87
  						type: "error",
88
  						title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_HVAC")}),
89
  						body: $translate.instant(response.data.description),
90
  						showCloseButton: true,
91
  					});
92
  				}
93
  			});
94
  		}, function() {
95
96
  		});
97
		$rootScope.modalInstance = modalInstance;
98
  	};
99
100
  	$scope.editEnergyStorageContainerHVAC = function(energystoragecontainerhvac) {
101
  		var modalInstance = $uibModal.open({
102
  			templateUrl: 'views/settings/energystoragecontainer/energystoragecontainerhvac.model.html',
103
  			controller: 'ModalEditEnergyStorageContainerHVACCtrl',
104
    		windowClass: "animated fadeIn",
105
  			resolve: {
106
  				params: function() {
107
  					return {
108
  						energystoragecontainerhvac: angular.copy(energystoragecontainerhvac),
109
						points: angular.copy($scope.points),
110
  					};
111
  				}
112
  			}
113
  		});
114
115
  		modalInstance.result.then(function(modifiedEnergyStorageContainerHVAC) {
116
			let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
117
  			EnergyStorageContainerHVACService.editEnergyStorageContainerHVAC($scope.currentEnergyStorageContainer.id, modifiedEnergyStorageContainerHVAC, headers, function (response) {
118
  				if (angular.isDefined(response.status) && response.status === 200) {
119
  					toaster.pop({
120
  						type: "success",
121
  						title: $translate.instant("TOASTER.SUCCESS_TITLE"),
122
  						body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_HVAC")}),
123
  						showCloseButton: true,
124
  					});
125
  					$scope.getEnergyStorageContainerHVACsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
126
            		$scope.$emit('handleEmitEnergyStorageContainerHVACChanged');
127
  				} else {
128
  					toaster.pop({
129
  						type: "error",
130
  						title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_HVAC")}),
131
  						body: $translate.instant(response.data.description),
132
  						showCloseButton: true,
133
  					});
134
  				}
135
  			});
136
  		}, function() {
137
  			//do nothing;
138
  		});
139
		$rootScope.modalInstance = modalInstance;
140
  	};
141
142
  	$scope.deleteEnergyStorageContainerHVAC = function(energystoragecontainerhvac) {
143
  		SweetAlert.swal({
144
  				title: $translate.instant("SWEET.TITLE"),
145
  				text: $translate.instant("SWEET.TEXT"),
146
  				type: "warning",
147
  				showCancelButton: true,
148
  				confirmButtonColor: "#DD6B55",
149
  				confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"),
150
  				cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"),
151
  				closeOnConfirm: true,
152
  				closeOnCancel: true
153
  			},
154
  			function(isConfirm) {
155
  				if (isConfirm) {
156
					let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
157
  					EnergyStorageContainerHVACService.deleteEnergyStorageContainerHVAC($scope.currentEnergyStorageContainer.id, energystoragecontainerhvac.id, headers, function (response) {
158
  						if (angular.isDefined(response.status) && response.status === 204) {
159
							toaster.pop({
160
								type: "success",
161
								title: $translate.instant("TOASTER.SUCCESS_TITLE"),
162
								body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_HVAC")}),
163
								showCloseButton: true,
164
							});
165
							$scope.getEnergyStorageContainerHVACsByEnergyStorageContainerID($scope.currentEnergyStorageContainer.id);
166
							$scope.$emit('handleEmitEnergyStorageContainerHVACChanged');
167
  						} else {
168
							toaster.pop({
169
								type: "error",
170
								title: $translate.instant("TOASTER.ERROR_DELETE_BODY", {template: $translate.instant("ENERGY_STORAGE_CONTAINER.ENERGY_STORAGE_CONTAINER_HVAC")}),
171
								body: $translate.instant(response.data.description),
172
								showCloseButton: true,
173
							});
174
  				   		}
175
  					});
176
  				}
177
  			});
178
  	};
179
180
  	$scope.getAllEnergyStorageContainers();
181
	$scope.getAllPoints();
182
    $scope.$on('handleBroadcastEnergyStorageContainerChanged', function(event) {
183
      $scope.getAllEnergyStorageContainers();
184
  	});
185
186
  });
187
188
189
  app.controller('ModalAddEnergyStorageContainerHVACCtrl', function($scope, $uibModalInstance, params) {
190
191
  	$scope.operation = "ENERGY_STORAGE_CONTAINER.ADD_ENERGY_STORAGE_CONTAINER_HVAC";
192
	$scope.points=params.points;
193
  	$scope.ok = function() {
194
  		$uibModalInstance.close($scope.energystoragecontainerhvac);
195
  	};
196
197
  	$scope.cancel = function() {
198
  		$uibModalInstance.dismiss('cancel');
199
  	};
200
  });
201
202
  app.controller('ModalEditEnergyStorageContainerHVACCtrl', function($scope, $uibModalInstance, params) {
203
  	$scope.operation = "ENERGY_STORAGE_CONTAINER.EDIT_ENERGY_STORAGE_CONTAINER_HVAC";
204
  	$scope.energystoragecontainerhvac = params.energystoragecontainerhvac;
205
	$scope.points=params.points;
206
  	$scope.ok = function() {
207
  		$uibModalInstance.close($scope.energystoragecontainerhvac);
208
  	};
209
210
  	$scope.cancel = function() {
211
  		$uibModalInstance.dismiss('cancel');
212
  	};
213
  });
214