sampleCustom.js
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// js for patch panel app custom view
(function () {
'use strict';
// injected refs
var $log, $scope, wss, ks;
// constants
var dataReq = 'sampleCustomDataRequest',
dataResp = 'sampleCustomDataResponse';
var dataReq2 = 'sampleCustomDataRequest2',
dataResp2 = 'sampleCustomDataResponse2';
var dataReq3 = 'sampleCustomDataRequest3',
dataResp3 = 'sampleCustomDataResponse3';
function addKeyBindings() {
var map = {space: [getData, 'Fetch data from server'], _helpFormat: [['space']]};
ks.keyBindings(map);
}
function getData() {
wss.sendEvent(dataReq);
}
function used() {
wss.sendEvent(dataReq3);
}
function loadPorts(){
$scope.ports = [];
var i;
var index;
for(i = 0; i < $scope.cps.length ; i++){
if($scope.cps[i] == $scope.myDev){
index = i;
}
}
var j = index+1;
while( $scope.data.cps[j].indexOf("o") != 0){
var tempi = {name : $scope.data.cps[j]};
$scope.ports.push(tempi);
j++;
}
}
function done(){
var temp = [$scope.myDev.name, $scope.myPort1.name, $scope.myPort2.name];
var temp1 = {result : temp};
wss.sendEvent(dataReq2, temp1);
}
function respDataCb(data) {
$scope.data = data;
$scope.cps = [];
$scope.devices = [];
var i;
for(i = 0; i < $scope.data.cps.length; i++){
$scope.cps.push(temp);
if($scope.data.cps[i].indexOf("o") == 0){
var temp = {name : $scope.data.cps[i]};
$scope.devices.push(temp);
}
}
$scope.$apply();
}
function respDataCb2(data) {
$scope.data = data;
$scope.$apply();
}
function respDataCb3(data) {
$scope.data = data;
$scope.$apply();
}
var app = angular.module('ovSampleCustom', [])
.controller('OvSampleCustomCtrl',
['$log', '$scope', 'WebSocketService', 'KeyService',
function (_$log_, _$scope_, _wss_, _ks_) {
$log = _$log_;
$scope = _$scope_;
wss = _wss_;
ks = _ks_;
$scope.cps = [];
$scope.devices = [];
$scope.ports = [];
$scope.myDev = $scope.devices[0];
$scope.myPort1 = $scope.ports[0];
$scope.myPort2 = $scope.ports[0];
var handlers = {};
$scope.data = {};
// data response handler
handlers[dataResp] = respDataCb;
handlers[dataResp2] = respDataCb2;
handlers[dataResp3] = respDataCb3;
wss.bindHandlers(handlers);
addKeyBindings();
// custom click handler
$scope.getData = getData;
$scope.loadPorts = loadPorts;
$scope.used = used;
$scope.done = done;
// cleanup
$scope.$on('$destroy', function () {
wss.unbindHandlers(handlers);
ks.unbindKeys();
$log.log('OvSampleCustomCtrl has been destroyed');
});
$log.log('OvSampleCustomCtrl has been created');
}]);
}());