|
1
|
|
|
'use strict'; |
|
2
|
|
|
|
|
3
|
|
|
app.controller('SpaceHybridPowerStationController', function( |
|
4
|
|
|
$scope, |
|
5
|
|
|
$window, |
|
6
|
|
|
$translate, |
|
7
|
|
|
SpaceService, |
|
8
|
|
|
HybridPowerStationService, |
|
9
|
|
|
SpaceHybridPowerStationService, |
|
10
|
|
|
toaster,SweetAlert) { |
|
11
|
|
|
$scope.spaces = []; |
|
12
|
|
|
$scope.currentSpaceID = 1; |
|
13
|
|
|
$scope.hybridpowerstations = []; |
|
14
|
|
|
$scope.spacehybridpowerstations = []; |
|
15
|
|
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); |
|
16
|
|
|
|
|
17
|
|
|
$scope.getAllSpaces = function() { |
|
18
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
19
|
|
|
SpaceService.getAllSpaces(headers, function (response) { |
|
20
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
21
|
|
|
$scope.spaces = response.data; |
|
22
|
|
|
} else { |
|
23
|
|
|
$scope.spaces = []; |
|
24
|
|
|
} |
|
25
|
|
|
//create space tree |
|
26
|
|
|
var treedata = {'core': {'data': [], "multiple" : false,}, "plugins" : [ "wholerow" ]}; |
|
27
|
|
|
for(var i=0; i < $scope.spaces.length; i++) { |
|
28
|
|
|
if ($scope.spaces[i].id == 1) { |
|
29
|
|
|
var node = {"id": $scope.spaces[i].id.toString(), |
|
30
|
|
|
"parent": '#', |
|
31
|
|
|
"text": $scope.spaces[i].name, |
|
32
|
|
|
"state": { 'opened' : true, 'selected' : false }, |
|
33
|
|
|
}; |
|
34
|
|
|
} else { |
|
35
|
|
|
var node = {"id": $scope.spaces[i].id.toString(), |
|
36
|
|
|
"parent": $scope.spaces[i].parent_space.id.toString(), |
|
37
|
|
|
"text": $scope.spaces[i].name, |
|
38
|
|
|
}; |
|
39
|
|
|
}; |
|
40
|
|
|
treedata['core']['data'].push(node); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
angular.element(spacetreewithhybridpowerstation).jstree(treedata); |
|
44
|
|
|
//space tree selected changed event handler |
|
45
|
|
|
angular.element(spacetreewithhybridpowerstation).on("changed.jstree", function (e, data) { |
|
46
|
|
|
$scope.currentSpaceID = parseInt(data.selected[0]); |
|
47
|
|
|
$scope.getHybridPowerStationsBySpaceID($scope.currentSpaceID); |
|
48
|
|
|
}); |
|
49
|
|
|
}); |
|
50
|
|
|
}; |
|
51
|
|
|
|
|
52
|
|
|
$scope.getHybridPowerStationsBySpaceID = function(id) { |
|
53
|
|
|
$scope.spacehybridpowerstations=[]; |
|
54
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
55
|
|
|
SpaceHybridPowerStationService.getHybridPowerStationsBySpaceID(id, headers, function (response) { |
|
56
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
57
|
|
|
$scope.spacehybridpowerstations = $scope.spacehybridpowerstations.concat(response.data); |
|
58
|
|
|
} else { |
|
59
|
|
|
$scope.spacehybridpowerstations=[]; |
|
60
|
|
|
} |
|
61
|
|
|
}); |
|
62
|
|
|
}; |
|
63
|
|
|
|
|
64
|
|
|
$scope.getAllHybridPowerStations = function() { |
|
65
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
66
|
|
|
HybridPowerStationService.getAllHybridPowerStations(headers, function (response) { |
|
67
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
68
|
|
|
$scope.hybridpowerstations = response.data; |
|
69
|
|
|
} else { |
|
70
|
|
|
$scope.hybridpowerstations = []; |
|
71
|
|
|
} |
|
72
|
|
|
}); |
|
73
|
|
|
}; |
|
74
|
|
|
|
|
75
|
|
|
$scope.pairHybridPowerStation=function(dragEl,dropEl){ |
|
76
|
|
|
var hybridpowerstationid=angular.element('#'+dragEl).scope().hybridpowerstation.id; |
|
77
|
|
|
var spaceid=angular.element(spacetreewithhybridpowerstation).jstree(true).get_top_selected(); |
|
78
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
79
|
|
|
SpaceHybridPowerStationService.addPair(spaceid,hybridpowerstationid, headers, function (response) { |
|
80
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
|
81
|
|
|
toaster.pop({ |
|
82
|
|
|
type: "success", |
|
83
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
|
84
|
|
|
body: $translate.instant("TOASTER.BIND_HYBRID_POWER_STATION_SUCCESS"), |
|
85
|
|
|
showCloseButton: true, |
|
86
|
|
|
}); |
|
87
|
|
|
$scope.getHybridPowerStationsBySpaceID(spaceid); |
|
88
|
|
|
} else { |
|
89
|
|
|
toaster.pop({ |
|
90
|
|
|
type: "error", |
|
91
|
|
|
title: $translate.instant(response.data.title), |
|
92
|
|
|
body: $translate.instant(response.data.description), |
|
93
|
|
|
showCloseButton: true, |
|
94
|
|
|
}); |
|
95
|
|
|
} |
|
96
|
|
|
}); |
|
97
|
|
|
}; |
|
98
|
|
|
|
|
99
|
|
|
$scope.deleteHybridPowerStationPair=function(dragEl,dropEl){ |
|
100
|
|
|
if(angular.element('#'+dragEl).hasClass('source')){ |
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
var spacehybridpowerstationid = angular.element('#' + dragEl).scope().spacehybridpowerstation.id; |
|
104
|
|
|
var spaceid = angular.element(spacetreewithhybridpowerstation).jstree(true).get_top_selected(); |
|
105
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
106
|
|
|
SpaceHybridPowerStationService.deletePair(spaceid, spacehybridpowerstationid, headers, function (response) { |
|
107
|
|
|
if (angular.isDefined(response.status) && response.status === 204) { |
|
108
|
|
|
toaster.pop({ |
|
109
|
|
|
type: "success", |
|
110
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
|
111
|
|
|
body: $translate.instant("TOASTER.UNBIND_HYBRID_POWER_STATION_SUCCESS"), |
|
112
|
|
|
showCloseButton: true, |
|
113
|
|
|
}); |
|
114
|
|
|
$scope.getHybridPowerStationsBySpaceID(spaceid); |
|
115
|
|
|
} else { |
|
116
|
|
|
toaster.pop({ |
|
117
|
|
|
type: "error", |
|
118
|
|
|
title: $translate.instant(response.data.title), |
|
119
|
|
|
body: $translate.instant(response.data.description), |
|
120
|
|
|
showCloseButton: true, |
|
121
|
|
|
}); |
|
122
|
|
|
} |
|
123
|
|
|
}); |
|
124
|
|
|
}; |
|
125
|
|
|
|
|
126
|
|
|
$scope.getAllSpaces(); |
|
127
|
|
|
$scope.getAllHybridPowerStations(); |
|
128
|
|
|
|
|
129
|
|
|
$scope.refreshSpaceTree = function() { |
|
130
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
|
131
|
|
|
SpaceService.getAllSpaces(headers, function (response) { |
|
132
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
|
133
|
|
|
$scope.spaces = response.data; |
|
134
|
|
|
} else { |
|
135
|
|
|
$scope.spaces = []; |
|
136
|
|
|
} |
|
137
|
|
|
//create space tree |
|
138
|
|
|
var treedata = {'core': {'data': [], "multiple" : false,}, "plugins" : [ "wholerow" ]}; |
|
139
|
|
|
for(var i=0; i < $scope.spaces.length; i++) { |
|
140
|
|
|
if ($scope.spaces[i].id == 1) { |
|
141
|
|
|
var node = {"id": $scope.spaces[i].id.toString(), |
|
142
|
|
|
"parent": '#', |
|
143
|
|
|
"text": $scope.spaces[i].name, |
|
144
|
|
|
"state": { 'opened' : true, 'selected' : false }, |
|
145
|
|
|
}; |
|
146
|
|
|
} else { |
|
147
|
|
|
var node = {"id": $scope.spaces[i].id.toString(), |
|
148
|
|
|
"parent": $scope.spaces[i].parent_space.id.toString(), |
|
149
|
|
|
"text": $scope.spaces[i].name, |
|
150
|
|
|
}; |
|
151
|
|
|
}; |
|
152
|
|
|
treedata['core']['data'].push(node); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
angular.element(spacetreewithhybridpowerstation).jstree(true).settings.core.data = treedata['core']['data']; |
|
156
|
|
|
angular.element(spacetreewithhybridpowerstation).jstree(true).refresh(); |
|
157
|
|
|
}); |
|
158
|
|
|
}; |
|
159
|
|
|
|
|
160
|
|
|
$scope.$on('handleBroadcastSpaceChanged', function(event) { |
|
161
|
|
|
$scope.spacehybridpowerstations = []; |
|
162
|
|
|
$scope.refreshSpaceTree(); |
|
163
|
|
|
}); |
|
164
|
|
|
}); |
|
165
|
|
|
|