Jian Li | 10a2070 | 2016-02-01 16:39:51 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jian Li | 10a2070 | 2016-02-01 16:39:51 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Control Plane Manager View Module |
| 19 | */ |
| 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
| 23 | // injected refs |
| 24 | var $log, $scope, wss, ks; |
| 25 | |
| 26 | // constants |
| 27 | var dataReq = 'cpmanDataRequest', |
| 28 | dataResp = 'cpmanDataResponse'; |
| 29 | |
| 30 | function addKeyBindings() { |
| 31 | var map = { |
| 32 | space: [getData, 'Fetch data from server'], |
| 33 | |
| 34 | _helpFormat: [ |
| 35 | ['space'] |
| 36 | ] |
| 37 | }; |
| 38 | |
| 39 | ks.keyBindings(map); |
| 40 | } |
| 41 | |
| 42 | function getData() { |
| 43 | wss.sendEvent(dataReq); |
| 44 | } |
| 45 | |
| 46 | function respDataCb(data) { |
| 47 | $scope.data = data; |
| 48 | $scope.$apply(); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | angular.module('ovCpman', []) |
| 53 | .controller('OvCpmanCtrl', |
| 54 | ['$log', '$scope', 'WebSocketService', 'KeyService', |
| 55 | |
| 56 | function (_$log_, _$scope_, _wss_, _ks_) { |
| 57 | $log = _$log_; |
| 58 | $scope = _$scope_; |
| 59 | wss = _wss_; |
| 60 | ks = _ks_; |
| 61 | |
| 62 | var handlers = {}; |
| 63 | $scope.data = {}; |
| 64 | |
| 65 | // data response handler |
| 66 | handlers[dataResp] = respDataCb; |
| 67 | wss.bindHandlers(handlers); |
| 68 | |
| 69 | addKeyBindings(); |
| 70 | |
| 71 | // custom click handler |
| 72 | $scope.getData = getData; |
| 73 | |
| 74 | // get data the first time... |
| 75 | getData(); |
| 76 | |
| 77 | // cleanup |
| 78 | $scope.$on('$destroy', function () { |
| 79 | wss.unbindHandlers(handlers); |
| 80 | ks.unbindKeys(); |
| 81 | $log.log('OvCpmanCtrl has been destroyed'); |
| 82 | }); |
| 83 | |
| 84 | $log.log('OvCpmanCtrl has been created'); |
| 85 | }]); |
| 86 | |
| 87 | }()); |