1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
app.controller('HybridPowerStationCMController', function( |
4
|
|
|
$scope, |
5
|
|
|
$rootScope, |
6
|
|
|
$window, |
7
|
|
|
$translate, |
8
|
|
|
$uibModal, |
9
|
|
|
HybridPowerStationService, |
10
|
|
|
HybridPowerStationCMService, |
11
|
|
|
DataSourceService, |
12
|
|
|
PointService, |
13
|
|
|
toaster, |
14
|
|
|
SweetAlert) { |
15
|
|
|
$scope.hybridpowerstations = []; |
16
|
|
|
$scope.hybridpowerstationcms = []; |
17
|
|
|
$scope.points = []; |
18
|
|
|
$scope.currentHybridPowerStation = null; |
19
|
|
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); |
20
|
|
|
$scope.getAllHybridPowerStations = function() { |
21
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
22
|
|
|
HybridPowerStationService.getAllHybridPowerStations(headers, function (response) { |
23
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
24
|
|
|
$scope.hybridpowerstations = response.data; |
25
|
|
|
} else { |
26
|
|
|
$scope.hybridpowerstations = []; |
27
|
|
|
} |
28
|
|
|
}); |
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
$scope.getAllDataSources = function() { |
32
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
33
|
|
|
DataSourceService.getAllDataSources(headers, function (response) { |
34
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
35
|
|
|
$scope.datasources = response.data; |
36
|
|
|
if ($scope.datasources.length > 0) { |
37
|
|
|
$scope.currentDataSource = $scope.datasources[0].id; |
38
|
|
|
$scope.getPointsByDataSourceID($scope.currentDataSource); |
39
|
|
|
} |
40
|
|
|
} else { |
41
|
|
|
$scope.datasources = []; |
42
|
|
|
} |
43
|
|
|
}); |
44
|
|
|
}; |
45
|
|
|
|
46
|
|
|
$scope.getAllPoints = function() { |
47
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
48
|
|
|
PointService.getAllPoints(headers, function (response) { |
49
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
50
|
|
|
$scope.points = response.data; |
51
|
|
|
} else { |
52
|
|
|
$scope.points = []; |
53
|
|
|
} |
54
|
|
|
}); |
55
|
|
|
}; |
56
|
|
|
|
57
|
|
|
$scope.getPointsByDataSourceID = function(id) { |
58
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
59
|
|
|
PointService.getPointsByDataSourceID(id, headers, function (response) { |
60
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
61
|
|
|
$scope.points = response.data; |
62
|
|
|
} else { |
63
|
|
|
$scope.points = []; |
64
|
|
|
} |
65
|
|
|
}); |
66
|
|
|
}; |
67
|
|
|
|
68
|
|
|
$scope.getHybridPowerStationCMsByHybridPowerStationID = function(id) { |
69
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
70
|
|
|
HybridPowerStationCMService.getHybridPowerStationCMsByHybridPowerStationID(id, headers, function (response) { |
71
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
72
|
|
|
$scope.hybridpowerstationcms = response.data; |
73
|
|
|
} else { |
74
|
|
|
$scope.hybridpowerstationcms=[]; |
75
|
|
|
} |
76
|
|
|
}); |
77
|
|
|
}; |
78
|
|
|
|
79
|
|
|
$scope.changeHybridPowerStation=function(item,model){ |
80
|
|
|
$scope.currentHybridPowerStation=item; |
81
|
|
|
$scope.currentHybridPowerStation.selected=model; |
82
|
|
|
$scope.is_show_add_hybridpowerstation_cm = true; |
83
|
|
|
$scope.getHybridPowerStationCMsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
$scope.addHybridPowerStationCM = function() { |
87
|
|
|
|
88
|
|
|
var modalInstance = $uibModal.open({ |
89
|
|
|
templateUrl: 'views/settings/hybridpowerstation/hybridpowerstationcm.model.html', |
90
|
|
|
controller: 'ModalAddHybridPowerStationCMCtrl', |
91
|
|
|
windowClass: "animated fadeIn", |
92
|
|
|
resolve: { |
93
|
|
|
params: function() { |
94
|
|
|
return { |
95
|
|
|
points: angular.copy($scope.points), |
96
|
|
|
}; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
}); |
100
|
|
|
modalInstance.result.then(function(hybridpowerstationcm) { |
101
|
|
|
|
102
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
103
|
|
|
HybridPowerStationCMService.addHybridPowerStationCM($scope.currentHybridPowerStation.id, hybridpowerstationcm, headers, function (response) { |
104
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
105
|
|
|
toaster.pop({ |
106
|
|
|
type: "success", |
107
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
108
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("HYBRID_POWER_STATION.HYBRID_POWER_STATION_CM")}), |
109
|
|
|
showCloseButton: true, |
110
|
|
|
}); |
111
|
|
|
$scope.getHybridPowerStationCMsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
112
|
|
|
$scope.$emit('handleEmitHybridPowerStationCMChanged'); |
113
|
|
|
} else { |
114
|
|
|
toaster.pop({ |
115
|
|
|
type: "error", |
116
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("HYBRID_POWER_STATION.HYBRID_POWER_STATION_CM")}), |
117
|
|
|
body: $translate.instant(response.data.description), |
118
|
|
|
showCloseButton: true, |
119
|
|
|
}); |
120
|
|
|
} |
121
|
|
|
}); |
122
|
|
|
}, function() { |
123
|
|
|
|
124
|
|
|
}); |
125
|
|
|
$rootScope.modalInstance = modalInstance; |
126
|
|
|
}; |
127
|
|
|
|
128
|
|
|
$scope.editHybridPowerStationCM = function(hybridpowerstationcm) { |
129
|
|
|
var modalInstance = $uibModal.open({ |
130
|
|
|
templateUrl: 'views/settings/hybridpowerstation/hybridpowerstationcm.model.html', |
131
|
|
|
controller: 'ModalEditHybridPowerStationCMCtrl', |
132
|
|
|
windowClass: "animated fadeIn", |
133
|
|
|
resolve: { |
134
|
|
|
params: function() { |
135
|
|
|
return { |
136
|
|
|
hybridpowerstationcm: angular.copy(hybridpowerstationcm), |
137
|
|
|
points: angular.copy($scope.points), |
138
|
|
|
}; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
}); |
142
|
|
|
|
143
|
|
|
modalInstance.result.then(function(modifiedHybridPowerStationCM) { |
144
|
|
|
|
145
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
146
|
|
|
HybridPowerStationCMService.editHybridPowerStationCM($scope.currentHybridPowerStation.id, modifiedHybridPowerStationCM, headers, function (response) { |
147
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
148
|
|
|
toaster.pop({ |
149
|
|
|
type: "success", |
150
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
151
|
|
|
body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", {template: $translate.instant("HYBRID_POWER_STATION.HYBRID_POWER_STATION_CM")}), |
152
|
|
|
showCloseButton: true, |
153
|
|
|
}); |
154
|
|
|
$scope.getHybridPowerStationCMsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
155
|
|
|
$scope.$emit('handleEmitHybridPowerStationCMChanged'); |
156
|
|
|
} else { |
157
|
|
|
toaster.pop({ |
158
|
|
|
type: "error", |
159
|
|
|
title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("HYBRID_POWER_STATION.HYBRID_POWER_STATION_CM")}), |
160
|
|
|
body: $translate.instant(response.data.description), |
161
|
|
|
showCloseButton: true, |
162
|
|
|
}); |
163
|
|
|
} |
164
|
|
|
}); |
165
|
|
|
}, function() { |
166
|
|
|
//do nothing; |
167
|
|
|
}); |
168
|
|
|
$rootScope.modalInstance = modalInstance; |
169
|
|
|
}; |
170
|
|
|
$scope.bindHybridPowerStationCMPoint = function(hybridpowerstationcm) { |
171
|
|
|
var modalInstance = $uibModal.open({ |
172
|
|
|
templateUrl: 'views/settings/hybridpowerstation/hybridpowerstationcmpoint.model.html', |
173
|
|
|
controller: 'ModalBindHybridPowerStationCMCtrl', |
174
|
|
|
windowClass: "animated fadeIn", |
175
|
|
|
resolve: { |
176
|
|
|
params: function() { |
177
|
|
|
return { |
178
|
|
|
user_uuid: $scope.cur_user.uuid, |
179
|
|
|
token: $scope.cur_user.token, |
180
|
|
|
hybridpowerstationid: $scope.currentHybridPowerStation.id, |
181
|
|
|
hybridpowerstationcm: angular.copy(hybridpowerstationcm), |
182
|
|
|
meters: angular.copy($scope.meters), |
183
|
|
|
datasources: angular.copy($scope.datasources), |
184
|
|
|
points: angular.copy($scope.points), |
185
|
|
|
}; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
}); |
189
|
|
|
$rootScope.modalInstance = modalInstance; |
190
|
|
|
}; |
191
|
|
|
|
192
|
|
|
$scope.deleteHybridPowerStationCM = function(hybridpowerstationcm) { |
193
|
|
|
SweetAlert.swal({ |
194
|
|
|
title: $translate.instant("SWEET.TITLE"), |
195
|
|
|
text: $translate.instant("SWEET.TEXT"), |
196
|
|
|
type: "warning", |
197
|
|
|
showCancelButton: true, |
198
|
|
|
confirmButtonColor: "#DD6B55", |
199
|
|
|
confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"), |
200
|
|
|
cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"), |
201
|
|
|
closeOnConfirm: true, |
202
|
|
|
closeOnCancel: true |
203
|
|
|
}, |
204
|
|
|
function(isConfirm) { |
205
|
|
|
if (isConfirm) { |
206
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
207
|
|
|
HybridPowerStationCMService.deleteHybridPowerStationCM($scope.currentHybridPowerStation.id, hybridpowerstationcm.id, headers, function (response) { |
208
|
|
|
if (angular.isDefined(response.status) && response.status === 204) { |
209
|
|
|
toaster.pop({ |
210
|
|
|
type: "success", |
211
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
212
|
|
|
body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", {template: $translate.instant("HYBRID_POWER_STATION.HYBRID_POWER_STATION_CM")}), |
213
|
|
|
showCloseButton: true, |
214
|
|
|
}); |
215
|
|
|
$scope.getHybridPowerStationCMsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
216
|
|
|
$scope.$emit('handleEmitHybridPowerStationCMChanged'); |
217
|
|
|
} else { |
218
|
|
|
toaster.pop({ |
219
|
|
|
type: "error", |
220
|
|
|
title: $translate.instant("TOASTER.ERROR_DELETE_BODY", {template: $translate.instant("HYBRID_POWER_STATION.HYBRID_POWER_STATION_CM")}), |
221
|
|
|
body: $translate.instant(response.data.description), |
222
|
|
|
showCloseButton: true, |
223
|
|
|
}); |
224
|
|
|
} |
225
|
|
|
}); |
226
|
|
|
} |
227
|
|
|
}); |
228
|
|
|
}; |
229
|
|
|
|
230
|
|
|
$scope.getAllHybridPowerStations(); |
231
|
|
|
$scope.getAllDataSources(); |
232
|
|
|
$scope.getAllPoints(); |
233
|
|
|
$scope.$on('handleBroadcastHybridPowerStationChanged', function(event) { |
234
|
|
|
$scope.getAllHybridPowerStations(); |
235
|
|
|
}); |
236
|
|
|
|
237
|
|
|
}); |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
app.controller('ModalAddHybridPowerStationCMCtrl', function($scope, $uibModalInstance, params) { |
241
|
|
|
|
242
|
|
|
$scope.operation = "HYBRID_POWER_STATION.ADD_HYBRID_POWER_STATION_CM"; |
243
|
|
|
$scope.points=params.points; |
244
|
|
|
$scope.ok = function() { |
245
|
|
|
$uibModalInstance.close($scope.hybridpowerstationcm); |
246
|
|
|
}; |
247
|
|
|
|
248
|
|
|
$scope.cancel = function() { |
249
|
|
|
$uibModalInstance.dismiss('cancel'); |
250
|
|
|
}; |
251
|
|
|
}); |
252
|
|
|
|
253
|
|
|
app.controller('ModalEditHybridPowerStationCMCtrl', function($scope, $uibModalInstance, params) { |
254
|
|
|
$scope.operation = "HYBRID_POWER_STATION.EDIT_HYBRID_POWER_STATION_CM"; |
255
|
|
|
$scope.hybridpowerstationcm = params.hybridpowerstationcm; |
256
|
|
|
$scope.points=params.points; |
257
|
|
|
$scope.ok = function() { |
258
|
|
|
$uibModalInstance.close($scope.hybridpowerstationcm); |
259
|
|
|
}; |
260
|
|
|
|
261
|
|
|
$scope.cancel = function() { |
262
|
|
|
$uibModalInstance.dismiss('cancel'); |
263
|
|
|
}; |
264
|
|
|
}); |
265
|
|
|
|
266
|
|
|
app.controller('ModalBindHybridPowerStationCMCtrl', function( |
267
|
|
|
$scope, |
268
|
|
|
$uibModalInstance, |
269
|
|
|
toaster, |
270
|
|
|
$translate, |
271
|
|
|
HybridPowerStationCMService, |
272
|
|
|
PointService, |
273
|
|
|
params) { |
274
|
|
|
$scope.operation = "HYBRID_POWER_STATION.EDIT_HYBRID_POWER_STATION_CM"; |
275
|
|
|
$scope.hybridpowerstationid = params.hybridpowerstationid; |
276
|
|
|
$scope.hybridpowerstationcm = params.hybridpowerstationcm; |
277
|
|
|
$scope.datasources=params.datasources; |
278
|
|
|
$scope.boundpoints=params.boundpoints; |
279
|
|
|
|
280
|
|
|
let headers = { "User-UUID": params.user_uuid, "Token": params.token }; |
281
|
|
|
HybridPowerStationCMService.getPointsByCMID($scope.hybridpowerstationid, $scope.hybridpowerstationcm.id, headers, function (response) { |
282
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
283
|
|
|
$scope.boundpoints = response.data; |
284
|
|
|
} else { |
285
|
|
|
$scope.boundpoints = []; |
286
|
|
|
} |
287
|
|
|
}); |
288
|
|
|
|
289
|
|
|
$scope.cancel = function() { |
290
|
|
|
$uibModalInstance.dismiss('cancel'); |
291
|
|
|
}; |
292
|
|
|
|
293
|
|
|
$scope.changeDataSource = function (item, model) { |
294
|
|
|
console.log('changeDataSource'); |
|
|
|
|
295
|
|
|
$scope.currentDataSource = model; |
296
|
|
|
console.log($scope.currentDataSource); |
297
|
|
|
$scope.getPointsByDataSourceID($scope.currentDataSource); |
298
|
|
|
}; |
299
|
|
|
|
300
|
|
|
$scope.getPointsByDataSourceID = function(id) { |
301
|
|
|
console.log('getPointsByDataSourceID'); |
|
|
|
|
302
|
|
|
let headers = { "User-UUID": params.user_uuid, "Token": params.token }; |
303
|
|
|
PointService.getPointsByDataSourceID(id, headers, function (response) { |
304
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
305
|
|
|
$scope.points = response.data; |
306
|
|
|
} else { |
307
|
|
|
$scope.points = []; |
308
|
|
|
} |
309
|
|
|
}); |
310
|
|
|
}; |
311
|
|
|
|
312
|
|
|
$scope.pairPoint = function (dragEl, dropEl) { |
313
|
|
|
var pointid = angular.element('#' + dragEl).scope().point.id; |
314
|
|
|
let headers = { "User-UUID": params.user_uuid, "Token": params.token }; |
315
|
|
|
HybridPowerStationCMService.addPair(params.hybridpowerstationid, params.hybridpowerstationcm.id, pointid, headers, function (response) { |
316
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
317
|
|
|
toaster.pop({ |
318
|
|
|
type: "success", |
319
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
320
|
|
|
body: $translate.instant("TOASTER.BIND_POINT_SUCCESS"), |
321
|
|
|
showCloseButton: true, |
322
|
|
|
}); |
323
|
|
|
let headers = { "User-UUID": params.user_uuid, "Token": params.token }; |
324
|
|
|
HybridPowerStationCMService.getPointsByCMID(params.hybridpowerstationid, params.hybridpowerstationcm.id, headers, function (response) { |
325
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
326
|
|
|
$scope.boundpoints = response.data; |
327
|
|
|
} else { |
328
|
|
|
$scope.boundpoints = []; |
329
|
|
|
} |
330
|
|
|
}); |
331
|
|
|
} else { |
332
|
|
|
toaster.pop({ |
333
|
|
|
type: "error", |
334
|
|
|
title: $translate.instant(response.data.title), |
335
|
|
|
body: $translate.instant(response.data.description), |
336
|
|
|
showCloseButton: true, |
337
|
|
|
}); |
338
|
|
|
} |
339
|
|
|
}); |
340
|
|
|
}; |
341
|
|
|
|
342
|
|
|
$scope.deletePointPair = function (dragEl, dropEl) { |
343
|
|
|
if (angular.element('#' + dragEl).hasClass('source')) { |
344
|
|
|
return; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
var pointid = angular.element('#' + dragEl).scope().boundpoint.id; |
348
|
|
|
let headers = { "User-UUID": params.user_uuid, "Token": params.token }; |
349
|
|
|
HybridPowerStationCMService.deletePair(params.hybridpowerstationid, params.hybridpowerstationcm.id, pointid, headers, function (response) { |
350
|
|
|
if (angular.isDefined(response.status) && response.status === 204) { |
351
|
|
|
toaster.pop({ |
352
|
|
|
type: "success", |
353
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
354
|
|
|
body: $translate.instant("TOASTER.UNBIND_POINT_SUCCESS"), |
355
|
|
|
showCloseButton: true, |
356
|
|
|
}); |
357
|
|
|
let headers = { "User-UUID": params.user_uuid, "Token": params.token }; |
358
|
|
|
HybridPowerStationCMService.getPointsByCMID(params.hybridpowerstationid, params.hybridpowerstationcm.id, headers, function (response) { |
359
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
360
|
|
|
$scope.boundpoints = response.data; |
361
|
|
|
} else { |
362
|
|
|
$scope.boundpoints = []; |
363
|
|
|
} |
364
|
|
|
}); |
365
|
|
|
} else { |
366
|
|
|
toaster.pop({ |
367
|
|
|
type: "error", |
368
|
|
|
title: $translate.instant(response.data.title), |
369
|
|
|
body: $translate.instant(response.data.description), |
370
|
|
|
showCloseButton: true, |
371
|
|
|
}); |
372
|
|
|
} |
373
|
|
|
}); |
374
|
|
|
}; |
375
|
|
|
|
376
|
|
|
}); |
377
|
|
|
|