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