Simon Hunt | cc035c5 | 2017-02-22 21:12:51 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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 -- YANG Model table view |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
| 24 | // injected refs |
| 25 | var $log, $scope, fs, ps, wss; |
| 26 | |
| 27 | // internal state |
| 28 | var detailsPanel, |
| 29 | ymodel; |
| 30 | |
| 31 | // constants |
| 32 | var pName = 'yang-model-details-panel', |
| 33 | detailsReq = 'yangModelDetailsRequest', |
| 34 | detailsResp = 'yangModelDetailsResponse'; |
| 35 | |
| 36 | // callback invoked when data from a details request returns from server |
| 37 | function respDetailsCb(data) { |
| 38 | $scope.panelData = data.details; |
| 39 | ymodel = data.yangModel; |
| 40 | $scope.$apply(); |
| 41 | // TODO: complete the detail panel directive. |
| 42 | $log.debug('YANG_MODEL>', detailsResp, data); |
| 43 | } |
| 44 | |
| 45 | angular.module('ovYangModel', []) |
| 46 | .controller('OvYangModelCtrl', [ |
| 47 | '$log', '$scope', 'TableBuilderService', 'TableDetailService', |
| 48 | 'FnService', 'PanelService', 'WebSocketService', |
| 49 | |
| 50 | function (_$log_, _$scope_, tbs, tds, _fs_, _ps_, _wss_) { |
| 51 | var handlers = {}; |
| 52 | |
| 53 | $log = _$log_; |
| 54 | $scope = _$scope_; |
| 55 | fs = _fs_; |
| 56 | ps = _ps_; |
| 57 | wss = _wss_; |
| 58 | |
| 59 | $scope.panelData = {}; |
| 60 | |
| 61 | // register response handler |
| 62 | handlers[detailsResp] = respDetailsCb; |
| 63 | wss.bindHandlers(handlers); |
| 64 | |
| 65 | // row selection callback |
| 66 | function selCb($event, row) { |
| 67 | if ($scope.selId) { |
| 68 | wss.sendEvent(detailsReq, { id: row.id }); |
| 69 | } else { |
| 70 | $scope.hidePanel(); |
| 71 | } |
| 72 | $log.debug('Got a click on:', row); |
| 73 | } |
| 74 | |
| 75 | tbs.buildTable({ |
| 76 | scope: $scope, |
| 77 | tag: 'yangModel', |
| 78 | selCb: selCb |
| 79 | }); |
| 80 | |
| 81 | $scope.$on('$destroy', function () { |
| 82 | wss.unbindHandlers(handlers); |
| 83 | }); |
| 84 | |
| 85 | $log.log('OvYangModelCtrl has been created'); |
| 86 | } |
| 87 | ]); |
| 88 | |
| 89 | // .directive('yangModelDetailsPanel', [ |
| 90 | // '$rootScope', '$window', |
| 91 | // function ($rootScope, $window) { |
| 92 | // return function (scope) { |
| 93 | // // TODO: details panel internals (see device.js as example |
| 94 | // } |
| 95 | // } |
| 96 | // ]); |
| 97 | |
| 98 | }()); |