1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
app.controller('HybridPowerStationCommandController', function ( |
4
|
|
|
$scope, |
5
|
|
|
$window, |
6
|
|
|
$timeout, |
7
|
|
|
$translate, |
8
|
|
|
HybridPowerStationService, |
9
|
|
|
CommandService, |
10
|
|
|
HybridPowerStationCommandService, |
11
|
|
|
toaster) { |
12
|
|
|
$scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); |
13
|
|
|
$scope.currentHybridPowerStation = {selected:undefined}; |
14
|
|
|
$scope.getAllCommands = function() { |
15
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
16
|
|
|
CommandService.getAllCommands(headers, function (response) { |
17
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
18
|
|
|
$scope.commands = response.data; |
19
|
|
|
} else { |
20
|
|
|
$scope.commands = []; |
21
|
|
|
} |
22
|
|
|
}); |
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
$scope.getCommandsByHybridPowerStationID = function (id) { |
26
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
27
|
|
|
HybridPowerStationCommandService.getCommandsByHybridPowerStationID(id, headers, function (response) { |
28
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
29
|
|
|
$scope.hybridpowerstationcommands = response.data; |
30
|
|
|
} else { |
31
|
|
|
$scope.hybridpowerstationcommands = []; |
32
|
|
|
} |
33
|
|
|
}); |
34
|
|
|
}; |
35
|
|
|
|
36
|
|
|
$scope.changeHybridPowerStation=function(item,model){ |
37
|
|
|
$scope.currentHybridPowerStation=item; |
38
|
|
|
$scope.currentHybridPowerStation.selected=model; |
39
|
|
|
$scope.getCommandsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
40
|
|
|
}; |
41
|
|
|
|
42
|
|
|
$scope.getAllHybridPowerStations = function () { |
43
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
44
|
|
|
HybridPowerStationService.getAllHybridPowerStations(headers, function (response) { |
45
|
|
|
if (angular.isDefined(response.status) && response.status === 200) { |
46
|
|
|
$scope.hybridpowerstations = response.data; |
47
|
|
|
$timeout(function () { |
48
|
|
|
$scope.getCommandsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
49
|
|
|
}, 1000); |
50
|
|
|
} else { |
51
|
|
|
$scope.hybridpowerstations = []; |
52
|
|
|
} |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
}; |
56
|
|
|
|
57
|
|
|
$scope.pairCommand = function (dragEl, dropEl) { |
58
|
|
|
var commandid = angular.element('#' + dragEl).scope().command.id; |
59
|
|
|
var hybridpowerstationid = $scope.currentHybridPowerStation.id; |
60
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
61
|
|
|
HybridPowerStationCommandService.addPair(hybridpowerstationid, commandid, headers, function (response) { |
62
|
|
|
if (angular.isDefined(response.status) && response.status === 201) { |
63
|
|
|
toaster.pop({ |
64
|
|
|
type: "success", |
65
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
66
|
|
|
body: $translate.instant("TOASTER.BIND_COMMAND_SUCCESS"), |
67
|
|
|
showCloseButton: true, |
68
|
|
|
}); |
69
|
|
|
$scope.getCommandsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
70
|
|
|
} else { |
71
|
|
|
toaster.pop({ |
72
|
|
|
type: "error", |
73
|
|
|
title: $translate.instant(response.data.title), |
74
|
|
|
body: $translate.instant(response.data.description), |
75
|
|
|
showCloseButton: true, |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
}); |
79
|
|
|
}; |
80
|
|
|
|
81
|
|
|
$scope.deleteCommandPair = function (dragEl, dropEl) { |
82
|
|
|
if (angular.element('#' + dragEl).hasClass('source')) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
var hybridpowerstationcommandid = angular.element('#' + dragEl).scope().hybridpowerstationcommand.id; |
86
|
|
|
var hybridpowerstationid = $scope.currentHybridPowerStation.id; |
87
|
|
|
let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; |
88
|
|
|
HybridPowerStationCommandService.deletePair(hybridpowerstationid, hybridpowerstationcommandid, headers, function (response) { |
89
|
|
|
if (angular.isDefined(response.status) && response.status === 204) { |
90
|
|
|
toaster.pop({ |
91
|
|
|
type: "success", |
92
|
|
|
title: $translate.instant("TOASTER.SUCCESS_TITLE"), |
93
|
|
|
body: $translate.instant("TOASTER.UNBIND_COMMAND_SUCCESS"), |
94
|
|
|
showCloseButton: true, |
95
|
|
|
}); |
96
|
|
|
$scope.getCommandsByHybridPowerStationID($scope.currentHybridPowerStation.id); |
97
|
|
|
} else { |
98
|
|
|
toaster.pop({ |
99
|
|
|
type: "error", |
100
|
|
|
title: $translate.instant(response.data.title), |
101
|
|
|
body: $translate.instant(response.data.description), |
102
|
|
|
showCloseButton: true, |
103
|
|
|
}); |
104
|
|
|
} |
105
|
|
|
}); |
106
|
|
|
}; |
107
|
|
|
|
108
|
|
|
$scope.getAllCommands(); |
109
|
|
|
$scope.getAllHybridPowerStations(); |
110
|
|
|
|
111
|
|
|
$scope.$on('handleBroadcastHybridPowerStationChanged', function(event) { |
112
|
|
|
$scope.getAllHybridPowerStations(); |
113
|
|
|
}); |
114
|
|
|
}); |
115
|
|
|
|