1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
app.controller('MicrogridGeneratorController', function( |
4
|
|
|
$scope, |
5
|
|
|
$rootScope, |
6
|
|
|
$window, |
7
|
|
|
$translate, |
8
|
|
|
$uibModal, |
9
|
|
|
MicrogridService, |
10
|
|
|
MicrogridGeneratorService, |
11
|
|
|
MicrogridDataSourceService, |
12
|
|
|
PointService, |
13
|
|
|
MeterService, |
14
|
|
|
toaster, |
15
|
|
|
SweetAlert) { |
16
|
|
|
$scope.microgrids = []; |
17
|
|
|
$scope.microgridgenerators = []; |
18
|
|
|
$scope.points = []; |
19
|
|
|
$scope.meters = []; |
20
|
|
|
$scope.currentMicrogrid = null; |
21
|
|
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); |
22
|
|
|
$scope.getAllMicrogrids = function() { |
23
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
24
|
|
|
MicrogridService.getAllMicrogrids(headers, function (response) { |
25
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
26
|
|
|
$scope.microgrids = response.data; |
27
|
|
|
} else { |
28
|
|
|
$scope.microgrids = []; |
29
|
|
|
} |
30
|
|
|
}); |
31
|
|
|
}; |
32
|
|
|
|
33
|
|
|
$scope.getDataSourcesByMicrogridID = function(id) { |
34
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
35
|
|
|
MicrogridDataSourceService.getDataSourcesByMicrogridID(id, headers, function(response) { |
36
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
37
|
|
|
$scope.datasources = response.data; |
38
|
|
|
} else { |
39
|
|
|
$scope.datasources = []; |
40
|
|
|
} |
41
|
|
|
}); |
42
|
|
|
}; |
43
|
|
|
|
44
|
|
|
$scope.getDataSourcePointsByMicrogridID = function(id) { |
45
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
46
|
|
|
MicrogridDataSourceService.getDataSourcePointsByMicrogridID(id, headers, function(response) { |
47
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
48
|
|
|
$scope.points = response.data; |
49
|
|
|
} else { |
50
|
|
|
$scope.points = []; |
51
|
|
|
} |
52
|
|
|
}); |
53
|
|
|
}; |
54
|
|
|
|
55
|
|
|
$scope.getAllMeters = function() { |
56
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
57
|
|
|
MeterService.getAllMeters(headers, function (response) { |
58
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
59
|
|
|
$scope.meters = response.data; |
60
|
|
|
} else { |
61
|
|
|
$scope.meters = []; |
62
|
|
|
} |
63
|
|
|
}); |
64
|
|
|
}; |
65
|
|
|
$scope.getMicrogridGeneratorsByMicrogridID = function(id) { |
66
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
67
|
|
|
MicrogridGeneratorService.getMicrogridGeneratorsByMicrogridID(id, headers, function (response) { |
68
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
69
|
|
|
$scope.microgridgenerators = response.data; |
70
|
|
|
console.log("微电网发电机模块对应内容:", $scope.microgridgenerators); |
|
|
|
|
71
|
|
|
} else { |
72
|
|
|
$scope.microgridgenerators=[]; |
73
|
|
|
} |
74
|
|
|
}); |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
$scope.changeMicrogrid=function(item,model){ |
78
|
|
|
$scope.currentMicrogrid=item; |
79
|
|
|
$scope.currentMicrogrid.selected=model; |
80
|
|
|
$scope.is_show_add_microgrid_generator = true; |
81
|
|
|
$scope.getMicrogridGeneratorsByMicrogridID($scope.currentMicrogrid.id); |
82
|
|
|
$scope.getDataSourcesByMicrogridID($scope.currentMicrogrid.id); |
83
|
|
|
$scope.getDataSourcePointsByMicrogridID($scope.currentMicrogrid.id); |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
$scope.addMicrogridGenerator = function() { |
87
|
|
|
var modalInstance = $uibModal.open({ |
88
|
|
|
templateUrl: 'views/settings/microgrid/microgridgenerator.model.html', |
89
|
|
|
controller: 'ModalAddMicrogridGeneratorCtrl', |
90
|
|
|
windowClass: "animated fadeIn", |
91
|
|
|
resolve: { |
92
|
|
|
params: function() { |
93
|
|
|
return { |
94
|
|
|
meters: angular.copy($scope.meters), |
95
|
|
|
points: angular.copy($scope.points), |
96
|
|
|
}; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
}); |
100
|
|
|
modalInstance.result.then(function(microgridgenerator) { |
101
|
|
|
microgridgenerator.power_point_id = microgridgenerator.power_point.id; |
102
|
|
|
microgridgenerator.meter_id = microgridgenerator.meter.id; |
103
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
104
|
|
|
MicrogridGeneratorService.addMicrogridGenerator($scope.currentMicrogrid.id, microgridgenerator, headers, function (response) { |
105
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
106
|
|
|
toaster.pop({ |
107
|
|
|
type: "success", |
108
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
109
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("MICROGRID.MICROGRID_GENERATOR")}), |
110
|
|
|
showCloseButton: true, |
111
|
|
|
}); |
112
|
|
|
$scope.getMicrogridGeneratorsByMicrogridID($scope.currentMicrogrid.id); |
113
|
|
|
$scope.getDataSourcesByMicrogridID($scope.currentMicrogrid.id); |
114
|
|
|
$scope.getDataSourcePointsByMicrogridID($scope.currentMicrogrid.id); |
115
|
|
|
$scope.$emit('handleEmitMicrogridGeneratorChanged'); |
116
|
|
|
} else { |
117
|
|
|
toaster.pop({ |
118
|
|
|
type: "error", |
119
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("MICROGRID.MICROGRID_GENERATOR")}), |
120
|
|
|
body: $translate.instant(response.data.description), |
121
|
|
|
showCloseButton: true, |
122
|
|
|
}); |
123
|
|
|
} |
124
|
|
|
}); |
125
|
|
|
}, function() { |
126
|
|
|
|
127
|
|
|
}); |
128
|
|
|
$rootScope.modalInstance = modalInstance; |
129
|
|
|
}; |
130
|
|
|
|
131
|
|
|
$scope.editMicrogridGenerator = function(microgridgenerator) { |
132
|
|
|
var modalInstance = $uibModal.open({ |
133
|
|
|
templateUrl: 'views/settings/microgrid/microgridgenerator.model.html', |
134
|
|
|
controller: 'ModalEditMicrogridGeneratorCtrl', |
135
|
|
|
windowClass: "animated fadeIn", |
136
|
|
|
resolve: { |
137
|
|
|
params: function() { |
138
|
|
|
return { |
139
|
|
|
microgridgenerator: angular.copy(microgridgenerator), |
140
|
|
|
meters: angular.copy($scope.meters), |
141
|
|
|
points: angular.copy($scope.points), |
142
|
|
|
}; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
}); |
146
|
|
|
|
147
|
|
|
modalInstance.result.then(function(modifiedMicrogridGenerator) { |
148
|
|
|
modifiedMicrogridGenerator.power_point_id = modifiedMicrogridGenerator.power_point.id; |
149
|
|
|
modifiedMicrogridGenerator.meter_id = modifiedMicrogridGenerator.meter.id; |
150
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
151
|
|
|
MicrogridGeneratorService.editMicrogridGenerator($scope.currentMicrogrid.id, modifiedMicrogridGenerator, headers, function (response) { |
152
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
153
|
|
|
toaster.pop({ |
154
|
|
|
type: "success", |
155
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
156
|
|
|
body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", {template: $translate.instant("MICROGRID.MICROGRID_GENERATOR")}), |
157
|
|
|
showCloseButton: true, |
158
|
|
|
}); |
159
|
|
|
$scope.getMicrogridGeneratorsByMicrogridID($scope.currentMicrogrid.id); |
160
|
|
|
$scope.getDataSourcesByMicrogridID($scope.currentMicrogrid.id); |
161
|
|
|
$scope.getDataSourcePointsByMicrogridID($scope.currentMicrogrid.id); |
162
|
|
|
$scope.$emit('handleEmitMicrogridGeneratorChanged'); |
163
|
|
|
} else { |
164
|
|
|
toaster.pop({ |
165
|
|
|
type: "error", |
166
|
|
|
title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("MICROGRID.MICROGRID_GENERATOR")}), |
167
|
|
|
body: $translate.instant(response.data.description), |
168
|
|
|
showCloseButton: true, |
169
|
|
|
}); |
170
|
|
|
} |
171
|
|
|
}); |
172
|
|
|
}, function() { |
173
|
|
|
//do nothing; |
174
|
|
|
}); |
175
|
|
|
$rootScope.modalInstance = modalInstance; |
176
|
|
|
}; |
177
|
|
|
|
178
|
|
|
$scope.deleteMicrogridGenerator = function(microgridgenerator) { |
179
|
|
|
SweetAlert.swal({ |
180
|
|
|
title: $translate.instant("SWEET.TITLE"), |
181
|
|
|
text: $translate.instant("SWEET.TEXT"), |
182
|
|
|
type: "warning", |
183
|
|
|
showCancelButton: true, |
184
|
|
|
confirmButtonColor: "#DD6B55", |
185
|
|
|
confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"), |
186
|
|
|
cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"), |
187
|
|
|
closeOnConfirm: true, |
188
|
|
|
closeOnCancel: true |
189
|
|
|
}, |
190
|
|
|
function(isConfirm) { |
191
|
|
|
if (isConfirm) { |
192
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
193
|
|
|
MicrogridGeneratorService.deleteMicrogridGenerator($scope.currentMicrogrid.id, microgridgenerator.id, headers, function (response) { |
194
|
|
|
if (angular.isDefined(response.status) && response.status === 204) { |
195
|
|
|
toaster.pop({ |
196
|
|
|
type: "success", |
197
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
198
|
|
|
body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", {template: $translate.instant("MICROGRID.MICROGRID_GENERATOR")}), |
199
|
|
|
showCloseButton: true, |
200
|
|
|
}); |
201
|
|
|
$scope.getMicrogridGeneratorsByMicrogridID($scope.currentMicrogrid.id); |
202
|
|
|
$scope.$emit('handleEmitMicrogridGeneratorChanged'); |
203
|
|
|
} else { |
204
|
|
|
toaster.pop({ |
205
|
|
|
type: "error", |
206
|
|
|
title: $translate.instant("TOASTER.ERROR_DELETE_BODY", {template: $translate.instant("MICROGRID.MICROGRID_GENERATOR")}), |
207
|
|
|
body: $translate.instant(response.data.description), |
208
|
|
|
showCloseButton: true, |
209
|
|
|
}); |
210
|
|
|
} |
211
|
|
|
}); |
212
|
|
|
} |
213
|
|
|
}); |
214
|
|
|
}; |
215
|
|
|
|
216
|
|
|
$scope.bindMicrogridGeneratorPoint = function (generator) { |
217
|
|
|
var modalInstance = $uibModal.open({ |
218
|
|
|
templateUrl: |
219
|
|
|
"views/settings/microgrid/microgridgeneratorpoint.model.html", |
220
|
|
|
controller: "ModalBindMicrogridGeneratorCtrl", |
221
|
|
|
windowClass: "animated fadeIn", |
222
|
|
|
resolve: { |
223
|
|
|
params: function () { |
224
|
|
|
return { |
225
|
|
|
user_uuid: $scope.cur_user.uuid, |
226
|
|
|
token: $scope.cur_user.token, |
227
|
|
|
microgridid: $scope.currentMicrogrid.id, |
228
|
|
|
microgridgenerator: angular.copy(generator), |
229
|
|
|
meters: angular.copy($scope.meters), |
230
|
|
|
datasources: angular.copy($scope.datasources), |
231
|
|
|
points: angular.copy($scope.points), |
232
|
|
|
}; |
233
|
|
|
}, |
234
|
|
|
}, |
235
|
|
|
}); |
236
|
|
|
$rootScope.modalInstance = modalInstance; |
237
|
|
|
}; |
238
|
|
|
|
239
|
|
|
$scope.getAllMicrogrids(); |
240
|
|
|
$scope.getAllMeters(); |
241
|
|
|
$scope.$on('handleBroadcastMicrogridChanged', function(event) { |
242
|
|
|
$scope.getAllMicrogrids(); |
243
|
|
|
}); |
244
|
|
|
|
245
|
|
|
}); |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
app.controller('ModalAddMicrogridGeneratorCtrl', function($scope, $uibModalInstance, params) { |
249
|
|
|
|
250
|
|
|
$scope.operation = "MICROGRID.ADD_MICROGRID_GENERATOR"; |
251
|
|
|
$scope.points=params.points; |
252
|
|
|
$scope.meters=params.meters; |
253
|
|
|
$scope.ok = function() { |
254
|
|
|
$uibModalInstance.close($scope.microgridgenerator); |
255
|
|
|
}; |
256
|
|
|
|
257
|
|
|
$scope.cancel = function() { |
258
|
|
|
$uibModalInstance.dismiss('cancel'); |
259
|
|
|
}; |
260
|
|
|
}); |
261
|
|
|
|
262
|
|
|
app.controller('ModalEditMicrogridGeneratorCtrl', function($scope, $uibModalInstance, params) { |
263
|
|
|
$scope.operation = "MICROGRID.EDIT_MICROGRID_GENERATOR"; |
264
|
|
|
$scope.microgridgenerator = params.microgridgenerator; |
265
|
|
|
$scope.points=params.points; |
266
|
|
|
$scope.meters=params.meters; |
267
|
|
|
$scope.ok = function() { |
268
|
|
|
$uibModalInstance.close($scope.microgridgenerator); |
269
|
|
|
}; |
270
|
|
|
|
271
|
|
|
$scope.cancel = function() { |
272
|
|
|
$uibModalInstance.dismiss('cancel'); |
273
|
|
|
}; |
274
|
|
|
}); |
275
|
|
|
|
276
|
|
|
app.controller( |
277
|
|
|
"ModalBindMicrogridGeneratorCtrl", |
278
|
|
|
function ( |
279
|
|
|
$scope, |
280
|
|
|
$uibModalInstance, |
281
|
|
|
toaster, |
282
|
|
|
$translate, |
283
|
|
|
MicrogridGeneratorService, |
284
|
|
|
PointService, |
285
|
|
|
params |
286
|
|
|
) { |
287
|
|
|
$scope.operation = "MICROGRID.MICROGRID_GENERATOR"; |
288
|
|
|
$scope.microgridid = params.microgridid; |
289
|
|
|
$scope.microgridgenerator = params.microgridgenerator; |
290
|
|
|
$scope.datasources = params.datasources; |
291
|
|
|
$scope.boundpoints = []; |
292
|
|
|
|
293
|
|
|
let headers = { "User-UUID": params.user_uuid, Token: params.token }; |
294
|
|
|
MicrogridGeneratorService.getPointsByGeneratorID( |
295
|
|
|
$scope.microgridid, |
296
|
|
|
$scope.microgridgenerator.id, |
297
|
|
|
headers, |
298
|
|
|
function (response) { |
299
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
300
|
|
|
$scope.boundpoints = response.data; |
301
|
|
|
} else { |
302
|
|
|
$scope.boundpoints = []; |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
); |
306
|
|
|
|
307
|
|
|
$scope.cancel = function () { |
308
|
|
|
$uibModalInstance.dismiss("cancel"); |
309
|
|
|
}; |
310
|
|
|
|
311
|
|
|
$scope.changeDataSource = function (item, model) { |
312
|
|
|
$scope.currentDataSource = model; |
313
|
|
|
$scope.getPointsByDataSourceID($scope.currentDataSource); |
314
|
|
|
}; |
315
|
|
|
|
316
|
|
|
$scope.getPointsByDataSourceID = function (id) { |
317
|
|
|
let headers = { "User-UUID": params.user_uuid, Token: params.token }; |
318
|
|
|
PointService.getPointsByDataSourceID(id, headers, function (response) { |
319
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
320
|
|
|
$scope.points = response.data; |
321
|
|
|
} else { |
322
|
|
|
$scope.points = []; |
323
|
|
|
} |
324
|
|
|
}); |
325
|
|
|
}; |
326
|
|
|
|
327
|
|
|
$scope.pairPoint = function (dragEl, dropEl) { |
328
|
|
|
var pointid = angular.element("#" + dragEl).scope().point.id; |
329
|
|
|
let headers = { "User-UUID": params.user_uuid, Token: params.token }; |
330
|
|
|
MicrogridGeneratorService.addGeneratorPair( |
331
|
|
|
params.microgridid, |
332
|
|
|
params.microgridgenerator.id, |
333
|
|
|
pointid, |
334
|
|
|
headers, |
335
|
|
|
function (response) { |
336
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
337
|
|
|
toaster.pop({ |
338
|
|
|
type: "success", |
339
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
340
|
|
|
body: $translate.instant("TOASTER.BIND_POINT_SUCCESS"), |
341
|
|
|
showCloseButton: true, |
342
|
|
|
}); |
343
|
|
|
let headers = { |
344
|
|
|
"User-UUID": params.user_uuid, |
345
|
|
|
Token: params.token, |
346
|
|
|
}; |
347
|
|
|
MicrogridGeneratorService.getPointsByGeneratorID( |
348
|
|
|
params.microgridid, |
349
|
|
|
params.microgridgenerator.id, |
350
|
|
|
headers, |
351
|
|
|
function (response) { |
352
|
|
|
if ( |
353
|
|
|
angular.isDefined(response.status) && |
354
|
|
|
response.status === 200 |
355
|
|
|
) { |
356
|
|
|
$scope.boundpoints = response.data; |
357
|
|
|
} else { |
358
|
|
|
$scope.boundpoints = []; |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
); |
362
|
|
|
} else { |
363
|
|
|
toaster.pop({ |
364
|
|
|
type: "error", |
365
|
|
|
title: $translate.instant(response.data.title), |
366
|
|
|
body: $translate.instant(response.data.description), |
367
|
|
|
showCloseButton: true, |
368
|
|
|
}); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
); |
372
|
|
|
}; |
373
|
|
|
|
374
|
|
|
$scope.deletePointPair = function (dragEl, dropEl) { |
375
|
|
|
if (angular.element("#" + dragEl).hasClass("source")) { |
376
|
|
|
return; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
var pointid = angular.element("#" + dragEl).scope().boundpoint.id; |
380
|
|
|
let headers = { "User-UUID": params.user_uuid, Token: params.token }; |
381
|
|
|
MicrogridGeneratorService.deleteGeneratorPair( |
382
|
|
|
params.microgridid, |
383
|
|
|
params.microgridgenerator.id, |
384
|
|
|
pointid, |
385
|
|
|
headers, |
386
|
|
|
function (response) { |
387
|
|
|
if (angular.isDefined(response.status) && response.status === 204) { |
388
|
|
|
toaster.pop({ |
389
|
|
|
type: "success", |
390
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
391
|
|
|
body: $translate.instant("TOASTER.UNBIND_POINT_SUCCESS"), |
392
|
|
|
showCloseButton: true, |
393
|
|
|
}); |
394
|
|
|
let headers = { |
395
|
|
|
"User-UUID": params.user_uuid, |
396
|
|
|
Token: params.token, |
397
|
|
|
}; |
398
|
|
|
MicrogridGeneratorService.getPointsByGeneratorID( |
399
|
|
|
params.microgridid, |
400
|
|
|
params.microgridgenerator.id, |
401
|
|
|
headers, |
402
|
|
|
function (response) { |
403
|
|
|
if ( |
404
|
|
|
angular.isDefined(response.status) && |
405
|
|
|
response.status === 200 |
406
|
|
|
) { |
407
|
|
|
$scope.boundpoints = response.data; |
408
|
|
|
} else { |
409
|
|
|
$scope.boundpoints = []; |
410
|
|
|
} |
411
|
|
|
} |
412
|
|
|
); |
413
|
|
|
} else { |
414
|
|
|
toaster.pop({ |
415
|
|
|
type: "error", |
416
|
|
|
title: $translate.instant(response.data.title), |
417
|
|
|
body: $translate.instant(response.data.description), |
418
|
|
|
showCloseButton: true, |
419
|
|
|
}); |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
); |
423
|
|
|
}; |
424
|
|
|
} |
425
|
|
|
); |