|
1
|
|
|
"use strict"; |
|
2
|
|
|
|
|
3
|
|
|
app.controller( |
|
4
|
|
|
"EnergyStorageContainerController", |
|
5
|
|
|
function ( |
|
6
|
|
|
$scope, |
|
7
|
|
|
$rootScope, |
|
8
|
|
|
$window, |
|
9
|
|
|
$translate, |
|
10
|
|
|
$uibModal, |
|
11
|
|
|
CostCenterService, |
|
12
|
|
|
ContactService, |
|
13
|
|
|
EnergyStorageContainerService, |
|
14
|
|
|
PointService, |
|
15
|
|
|
toaster, |
|
16
|
|
|
SweetAlert |
|
17
|
|
|
) { |
|
18
|
|
|
$scope.cur_user = JSON.parse( |
|
19
|
|
|
$window.localStorage.getItem("myems_admin_ui_current_user") |
|
20
|
|
|
); |
|
21
|
|
|
$scope.getAllCostCenters = function () { |
|
22
|
|
|
let headers = { |
|
23
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
24
|
|
|
Token: $scope.cur_user.token, |
|
25
|
|
|
}; |
|
26
|
|
|
CostCenterService.getAllCostCenters(headers, function (response) { |
|
27
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
28
|
|
|
$scope.costcenters = response.data; |
|
29
|
|
|
} else { |
|
30
|
|
|
$scope.costcenters = []; |
|
31
|
|
|
} |
|
32
|
|
|
}); |
|
33
|
|
|
}; |
|
34
|
|
|
|
|
35
|
|
|
$scope.getAllContacts = function () { |
|
36
|
|
|
let headers = { |
|
37
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
38
|
|
|
Token: $scope.cur_user.token, |
|
39
|
|
|
}; |
|
40
|
|
|
ContactService.getAllContacts(headers, function (response) { |
|
41
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
42
|
|
|
$scope.contacts = response.data; |
|
43
|
|
|
} else { |
|
44
|
|
|
$scope.contacts = []; |
|
45
|
|
|
} |
|
46
|
|
|
}); |
|
47
|
|
|
}; |
|
48
|
|
|
|
|
49
|
|
|
$scope.getAllEnergyStorageContainers = function () { |
|
50
|
|
|
let headers = { |
|
51
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
52
|
|
|
Token: $scope.cur_user.token, |
|
53
|
|
|
}; |
|
54
|
|
|
EnergyStorageContainerService.getAllEnergyStorageContainers( |
|
55
|
|
|
headers, |
|
56
|
|
|
function (response) { |
|
57
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
58
|
|
|
$scope.energystoragecontainers = response.data; |
|
59
|
|
|
} else { |
|
60
|
|
|
$scope.energystoragecontainers = []; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
); |
|
64
|
|
|
}; |
|
65
|
|
|
|
|
66
|
|
|
let searchDebounceTimer = null; |
|
67
|
|
|
$scope.searchEnergyStorageContainers = function() { |
|
68
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
69
|
|
|
const rawKeyword = $scope.searchKeyword || ""; |
|
70
|
|
|
const trimmedKeyword = rawKeyword.trim(); |
|
71
|
|
|
if (searchDebounceTimer) { |
|
72
|
|
|
clearTimeout(searchDebounceTimer); |
|
73
|
|
|
} |
|
74
|
|
|
searchDebounceTimer = setTimeout(() => { |
|
75
|
|
|
if (!trimmedKeyword) { |
|
76
|
|
|
$scope.getAllEnergyStorageContainers(); |
|
77
|
|
|
return; |
|
78
|
|
|
} |
|
79
|
|
|
EnergyStorageContainerService.searchEnergyStorageContainers(trimmedKeyword, headers, function (response) { |
|
80
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
81
|
|
|
$scope.energystoragecontainers = response.data; |
|
82
|
|
|
} else { |
|
83
|
|
|
$scope.energystoragecontainers = []; |
|
84
|
|
|
} |
|
85
|
|
|
}); |
|
86
|
|
|
}, 300); |
|
87
|
|
|
}; |
|
88
|
|
|
|
|
89
|
|
|
$scope.exportEnergyStorageContainer = function (container) { |
|
90
|
|
|
let headers = { |
|
91
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
92
|
|
|
"Token": $scope.cur_user.token, |
|
93
|
|
|
}; |
|
94
|
|
|
EnergyStorageContainerService.exportEnergyStorageContainer(container, headers, function (response) { |
|
95
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
96
|
|
|
$scope.exportdata = JSON.stringify(response.data); |
|
97
|
|
|
var modalInstance = $uibModal.open({ |
|
98
|
|
|
windowClass: "animated fadeIn", |
|
99
|
|
|
templateUrl: "views/common/export.html", |
|
100
|
|
|
controller: "ModalExportCtrl", |
|
101
|
|
|
resolve: { |
|
102
|
|
|
params: function () { |
|
103
|
|
|
return { |
|
104
|
|
|
exportdata: angular.copy($scope.exportdata), |
|
105
|
|
|
}; |
|
106
|
|
|
}, |
|
107
|
|
|
}, |
|
108
|
|
|
}); |
|
109
|
|
|
$rootScope.modalInstance = modalInstance; |
|
110
|
|
|
} else { |
|
111
|
|
|
$scope.exportdata = null; |
|
112
|
|
|
} |
|
113
|
|
|
}); |
|
114
|
|
|
}; |
|
115
|
|
|
$scope.importEnergyStorageContainer = function () { |
|
116
|
|
|
var modalInstance = $uibModal.open({ |
|
117
|
|
|
templateUrl: 'views/common/import.html', |
|
118
|
|
|
controller: 'ModalImportCtrl', |
|
119
|
|
|
windowClass: "animated fadeIn", |
|
120
|
|
|
resolve: { |
|
121
|
|
|
params: function () { |
|
122
|
|
|
return {}; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
}); |
|
126
|
|
|
|
|
127
|
|
|
modalInstance.result.then(function (importdata) { |
|
128
|
|
|
let headers = { |
|
129
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
130
|
|
|
"Token": $scope.cur_user.token |
|
131
|
|
|
}; |
|
132
|
|
|
EnergyStorageContainerService.importEnergyStorageContainer(importdata, headers, function (response) { |
|
133
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
|
134
|
|
|
toaster.pop({ |
|
135
|
|
|
type: "success", |
|
136
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
|
137
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", { |
|
138
|
|
|
template: $translate.instant("COMMON.ENERGY_STORAGE_CONTAINER") |
|
139
|
|
|
}), |
|
140
|
|
|
showCloseButton: true, |
|
141
|
|
|
}); |
|
142
|
|
|
$scope.getAllEnergyStorageContainers(); |
|
143
|
|
|
$scope.$emit('handleEmitEnergyStorageContainerChanged'); |
|
144
|
|
|
} else { |
|
145
|
|
|
toaster.pop({ |
|
146
|
|
|
type: "error", |
|
147
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", { |
|
148
|
|
|
template: $translate.instant("COMMON.ENERGY_STORAGE_CONTAINER") |
|
149
|
|
|
}), |
|
150
|
|
|
body: $translate.instant(response.data.description), |
|
151
|
|
|
showCloseButton: true, |
|
152
|
|
|
}); |
|
153
|
|
|
} |
|
154
|
|
|
}); |
|
155
|
|
|
}, function () { |
|
156
|
|
|
// do nothing |
|
157
|
|
|
}); |
|
158
|
|
|
|
|
159
|
|
|
$rootScope.modalInstance = modalInstance; |
|
160
|
|
|
}; |
|
161
|
|
|
|
|
162
|
|
|
$scope.cloneEnergyStorageContainer = function(energystoragecontainer){ |
|
163
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
164
|
|
|
EnergyStorageContainerService.cloneEnergyStorageContainer(energystoragecontainer, headers, function(response) { |
|
165
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
|
166
|
|
|
toaster.pop({ |
|
167
|
|
|
type: "success", |
|
168
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
|
169
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("COMMON.ENERGY_STORAGE_CONTAINER")}), |
|
170
|
|
|
showCloseButton: true, |
|
171
|
|
|
}); |
|
172
|
|
|
$scope.getAllEnergyStorageContainers(); |
|
173
|
|
|
$scope.$emit('handleEmitEnergyStorageContainerChanged'); |
|
174
|
|
|
}else { |
|
175
|
|
|
toaster.pop({ |
|
176
|
|
|
type: "error", |
|
177
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("COMMON.ENERGY_STORAGE_CONTAINER")}), |
|
178
|
|
|
body: $translate.instant(response.data.description), |
|
179
|
|
|
showCloseButton: true, |
|
180
|
|
|
}); |
|
181
|
|
|
} |
|
182
|
|
|
}); |
|
183
|
|
|
}; |
|
184
|
|
|
|
|
185
|
|
|
$scope.addEnergyStorageContainer = function () { |
|
186
|
|
|
var modalInstance = $uibModal.open({ |
|
187
|
|
|
templateUrl: |
|
188
|
|
|
"views/settings/energystoragecontainer/energystoragecontainer.model.html", |
|
189
|
|
|
controller: "ModalAddEnergyStorageContainerCtrl", |
|
190
|
|
|
windowClass: "animated fadeIn", |
|
191
|
|
|
resolve: { |
|
192
|
|
|
params: function () { |
|
193
|
|
|
return { |
|
194
|
|
|
costcenters: angular.copy($scope.costcenters), |
|
195
|
|
|
contacts: angular.copy($scope.contacts), |
|
196
|
|
|
}; |
|
197
|
|
|
}, |
|
198
|
|
|
}, |
|
199
|
|
|
}); |
|
200
|
|
|
modalInstance.result.then( |
|
201
|
|
|
function (energystoragecontainer) { |
|
202
|
|
|
energystoragecontainer.cost_center_id = |
|
203
|
|
|
energystoragecontainer.cost_center.id; |
|
204
|
|
|
energystoragecontainer.contact_id = energystoragecontainer.contact.id; |
|
205
|
|
|
|
|
206
|
|
|
let headers = { |
|
207
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
208
|
|
|
Token: $scope.cur_user.token, |
|
209
|
|
|
}; |
|
210
|
|
|
EnergyStorageContainerService.addEnergyStorageContainer( |
|
211
|
|
|
energystoragecontainer, |
|
212
|
|
|
headers, |
|
213
|
|
|
function (response) { |
|
214
|
|
|
if ( |
|
215
|
|
|
angular.isDefined(response.status) && |
|
216
|
|
|
response.status === 201 |
|
217
|
|
|
) { |
|
218
|
|
|
toaster.pop({ |
|
219
|
|
|
type: "success", |
|
220
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
|
221
|
|
|
body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", { |
|
222
|
|
|
template: $translate.instant( |
|
223
|
|
|
"COMMON.ENERGY_STORAGE_CONTAINER" |
|
224
|
|
|
), |
|
225
|
|
|
}), |
|
226
|
|
|
showCloseButton: true, |
|
227
|
|
|
}); |
|
228
|
|
|
$scope.$emit("handleEmitEnergyStorageContainerChanged"); |
|
229
|
|
|
} else { |
|
230
|
|
|
toaster.pop({ |
|
231
|
|
|
type: "error", |
|
232
|
|
|
title: $translate.instant("TOASTER.ERROR_ADD_BODY", { |
|
233
|
|
|
template: $translate.instant( |
|
234
|
|
|
"COMMON.ENERGY_STORAGE_CONTAINER" |
|
235
|
|
|
), |
|
236
|
|
|
}), |
|
237
|
|
|
body: $translate.instant(response.data.description), |
|
238
|
|
|
showCloseButton: true, |
|
239
|
|
|
}); |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
); |
|
243
|
|
|
}, |
|
244
|
|
|
function () {} |
|
245
|
|
|
); |
|
246
|
|
|
$rootScope.modalInstance = modalInstance; |
|
247
|
|
|
}; |
|
248
|
|
|
|
|
249
|
|
|
$scope.editEnergyStorageContainer = function (energystoragecontainer) { |
|
250
|
|
|
var modalInstance = $uibModal.open({ |
|
251
|
|
|
windowClass: "animated fadeIn", |
|
252
|
|
|
templateUrl: |
|
253
|
|
|
"views/settings/energystoragecontainer/energystoragecontainer.model.html", |
|
254
|
|
|
controller: "ModalEditEnergyStorageContainerCtrl", |
|
255
|
|
|
resolve: { |
|
256
|
|
|
params: function () { |
|
257
|
|
|
return { |
|
258
|
|
|
energystoragecontainer: angular.copy(energystoragecontainer), |
|
259
|
|
|
costcenters: angular.copy($scope.costcenters), |
|
260
|
|
|
contacts: angular.copy($scope.contacts), |
|
261
|
|
|
}; |
|
262
|
|
|
}, |
|
263
|
|
|
}, |
|
264
|
|
|
}); |
|
265
|
|
|
|
|
266
|
|
|
modalInstance.result.then( |
|
267
|
|
|
function (modifiedEnergyStorageContainer) { |
|
268
|
|
|
modifiedEnergyStorageContainer.cost_center_id = |
|
269
|
|
|
modifiedEnergyStorageContainer.cost_center.id; |
|
270
|
|
|
modifiedEnergyStorageContainer.contact_id = |
|
271
|
|
|
modifiedEnergyStorageContainer.contact.id; |
|
272
|
|
|
|
|
273
|
|
|
let headers = { |
|
274
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
275
|
|
|
Token: $scope.cur_user.token, |
|
276
|
|
|
}; |
|
277
|
|
|
EnergyStorageContainerService.editEnergyStorageContainer( |
|
278
|
|
|
modifiedEnergyStorageContainer, |
|
279
|
|
|
headers, |
|
280
|
|
|
function (response) { |
|
281
|
|
|
if ( |
|
282
|
|
|
angular.isDefined(response.status) && |
|
283
|
|
|
response.status === 200 |
|
284
|
|
|
) { |
|
285
|
|
|
toaster.pop({ |
|
286
|
|
|
type: "success", |
|
287
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
|
288
|
|
|
body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", { |
|
289
|
|
|
template: $translate.instant( |
|
290
|
|
|
"COMMON.ENERGY_STORAGE_CONTAINER" |
|
291
|
|
|
), |
|
292
|
|
|
}), |
|
293
|
|
|
showCloseButton: true, |
|
294
|
|
|
}); |
|
295
|
|
|
$scope.$emit("handleEmitEnergyStorageContainerChanged"); |
|
296
|
|
|
} else { |
|
297
|
|
|
toaster.pop({ |
|
298
|
|
|
type: "error", |
|
299
|
|
|
title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", { |
|
300
|
|
|
template: $translate.instant( |
|
301
|
|
|
"COMMON.ENERGY_STORAGE_CONTAINER" |
|
302
|
|
|
), |
|
303
|
|
|
}), |
|
304
|
|
|
body: $translate.instant(response.data.description), |
|
305
|
|
|
showCloseButton: true, |
|
306
|
|
|
}); |
|
307
|
|
|
} |
|
308
|
|
|
} |
|
309
|
|
|
); |
|
310
|
|
|
}, |
|
311
|
|
|
function () { |
|
312
|
|
|
//do nothing; |
|
313
|
|
|
} |
|
314
|
|
|
); |
|
315
|
|
|
$rootScope.modalInstance = modalInstance; |
|
316
|
|
|
}; |
|
317
|
|
|
|
|
318
|
|
|
$scope.deleteEnergyStorageContainer = function (energystoragecontainer) { |
|
319
|
|
|
SweetAlert.swal( |
|
320
|
|
|
{ |
|
321
|
|
|
title: $translate.instant("SWEET.TITLE"), |
|
322
|
|
|
text: $translate.instant("SWEET.TEXT"), |
|
323
|
|
|
type: "warning", |
|
324
|
|
|
showCancelButton: true, |
|
325
|
|
|
confirmButtonColor: "#DD6B55", |
|
326
|
|
|
confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"), |
|
327
|
|
|
cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"), |
|
328
|
|
|
closeOnConfirm: true, |
|
329
|
|
|
closeOnCancel: true, |
|
330
|
|
|
}, |
|
331
|
|
|
function (isConfirm) { |
|
332
|
|
|
if (isConfirm) { |
|
333
|
|
|
let headers = { |
|
334
|
|
|
"User-UUID": $scope.cur_user.uuid, |
|
335
|
|
|
Token: $scope.cur_user.token, |
|
336
|
|
|
}; |
|
337
|
|
|
EnergyStorageContainerService.deleteEnergyStorageContainer( |
|
338
|
|
|
energystoragecontainer, |
|
339
|
|
|
headers, |
|
340
|
|
|
function (response) { |
|
341
|
|
|
if ( |
|
342
|
|
|
angular.isDefined(response.status) && |
|
343
|
|
|
response.status === 204 |
|
344
|
|
|
) { |
|
345
|
|
|
toaster.pop({ |
|
346
|
|
|
type: "success", |
|
347
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
|
348
|
|
|
body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", { |
|
349
|
|
|
template: $translate.instant( |
|
350
|
|
|
"COMMON.ENERGY_STORAGE_CONTAINER" |
|
351
|
|
|
), |
|
352
|
|
|
}), |
|
353
|
|
|
showCloseButton: true, |
|
354
|
|
|
}); |
|
355
|
|
|
$scope.$emit("handleEmitEnergyStorageContainerChanged"); |
|
356
|
|
|
} else { |
|
357
|
|
|
toaster.pop({ |
|
358
|
|
|
type: "error", |
|
359
|
|
|
title: $translate.instant("TOASTER.ERROR_DELETE_BODY", { |
|
360
|
|
|
template: $translate.instant( |
|
361
|
|
|
"COMMON.ENERGY_STORAGE_CONTAINER" |
|
362
|
|
|
), |
|
363
|
|
|
}), |
|
364
|
|
|
body: $translate.instant(response.data.description), |
|
365
|
|
|
showCloseButton: true, |
|
366
|
|
|
}); |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
); |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
); |
|
373
|
|
|
}; |
|
374
|
|
|
$scope.getAllEnergyStorageContainers(); |
|
375
|
|
|
$scope.getAllCostCenters(); |
|
376
|
|
|
$scope.getAllContacts(); |
|
377
|
|
|
$scope.$on( |
|
378
|
|
|
"handleBroadcastEnergyStorageContainerChanged", |
|
379
|
|
|
function (event) { |
|
380
|
|
|
$scope.getAllEnergyStorageContainers(); |
|
381
|
|
|
} |
|
382
|
|
|
); |
|
383
|
|
|
} |
|
384
|
|
|
); |
|
385
|
|
|
|
|
386
|
|
|
app.controller( |
|
387
|
|
|
"ModalAddEnergyStorageContainerCtrl", |
|
388
|
|
|
function ($scope, $uibModalInstance, params) { |
|
389
|
|
|
$scope.operation = "SETTING.ADD_ENERGY_STORAGE_CONTAINER"; |
|
390
|
|
|
$scope.costcenters = params.costcenters; |
|
391
|
|
|
$scope.contacts = params.contacts; |
|
392
|
|
|
$scope.ok = function () { |
|
393
|
|
|
$uibModalInstance.close($scope.energystoragecontainer); |
|
394
|
|
|
}; |
|
395
|
|
|
|
|
396
|
|
|
$scope.cancel = function () { |
|
397
|
|
|
$uibModalInstance.dismiss("cancel"); |
|
398
|
|
|
}; |
|
399
|
|
|
} |
|
400
|
|
|
); |
|
401
|
|
|
|
|
402
|
|
|
app.controller( |
|
403
|
|
|
"ModalEditEnergyStorageContainerCtrl", |
|
404
|
|
|
function ($scope, $uibModalInstance, params) { |
|
405
|
|
|
$scope.operation = "SETTING.EDIT_ENERGY_STORAGE_CONTAINER"; |
|
406
|
|
|
$scope.energystoragecontainer = params.energystoragecontainer; |
|
407
|
|
|
$scope.costcenters = params.costcenters; |
|
408
|
|
|
$scope.contacts = params.contacts; |
|
409
|
|
|
$scope.ok = function () { |
|
410
|
|
|
$uibModalInstance.close($scope.energystoragecontainer); |
|
411
|
|
|
}; |
|
412
|
|
|
|
|
413
|
|
|
$scope.cancel = function () { |
|
414
|
|
|
$uibModalInstance.dismiss("cancel"); |
|
415
|
|
|
}; |
|
416
|
|
|
} |
|
417
|
|
|
); |
|
418
|
|
|
|