blob: 930dc6d7bafc99119040da4c707a7e942de5b16c [file] [log] [blame]
Simon Huntcc035c52017-02-22 21:12:51 -08001/*
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
Simon Hunt7d5e9842017-02-23 11:37:02 -080025 var $log, $scope, fs, mast, ps, wss, is;
26
27 // constants
28 var topPdg = 28,
29 pWidth = 800;
Simon Huntcc035c52017-02-22 21:12:51 -080030
31 // internal state
32 var detailsPanel,
Simon Hunt7d5e9842017-02-23 11:37:02 -080033 ymodel,
34 pStartY,
35 pHeight,
36 wSize,
37 top,
38 iconDiv;
Simon Huntcc035c52017-02-22 21:12:51 -080039
40 // constants
41 var pName = 'yang-model-details-panel',
42 detailsReq = 'yangModelDetailsRequest',
43 detailsResp = 'yangModelDetailsResponse';
44
Simon Hunt7d5e9842017-02-23 11:37:02 -080045
46
47 function createDetailsPanel() {
48 detailsPanel = ps.createPanel(pName, {
49 width: pWidth,
50 margin: 0,
51 hideMargin: 0
52 });
53 $scope.hidePanel = function () { detailsPanel.hide(); };
54 detailsPanel.hide();
55 }
56
57 function populateDetails(details) {
58 var topData;
59
60 setUpPanel();
61 topData = top.select('.top-data');
62 populateTop(topData, details);
63 detailsPanel.height(pHeight);
64 }
65
66 function setUpPanel() {
67 var container, closeBtn, dataDiv;
68 detailsPanel.empty();
69
70 container = detailsPanel.append('div').classed('container', true);
71
72 top = container.append('div').classed('top', true);
73 closeBtn = top.append('div').classed('close-btn', true);
74 addCloseBtn(closeBtn);
75 iconDiv = top.append('div').classed('dev-icon', true);
76 top.append('h2');
77
78 dataDiv = top.append('div').classed('top-data', true);
79 dataDiv.append('p').text('fill out properties here');
80 }
81
82 function populateTop(dataDiv, details) {
83 top.select('h2').html('ID:' + details.id);
84 // TODO: format data from 'details' into the dataDiv
85 dataDiv.append('p').html('type: ' + details.type);
86
87 }
88
89 function closePanel() {
90 if (detailsPanel.isVisible()) {
91 $scope.selId = null;
92 detailsPanel.hide();
93 return true;
94 }
95 return false;
96 }
97
98 function addCloseBtn(div) {
99 is.loadEmbeddedIcon(div, 'close', 20);
100 div.on('click', closePanel);
101 }
102
103
Simon Huntcc035c52017-02-22 21:12:51 -0800104 // callback invoked when data from a details request returns from server
105 function respDetailsCb(data) {
106 $scope.panelData = data.details;
107 ymodel = data.yangModel;
108 $scope.$apply();
109 // TODO: complete the detail panel directive.
110 $log.debug('YANG_MODEL>', detailsResp, data);
111 }
112
Simon Hunt7d5e9842017-02-23 11:37:02 -0800113 function handleEscape() {
114 return closePanel();
115 }
116
117
118 // defines view controller
Simon Huntcc035c52017-02-22 21:12:51 -0800119 angular.module('ovYangModel', [])
Simon Hunt7d5e9842017-02-23 11:37:02 -0800120 .controller('OvYangModelCtrl', [
121 '$log', '$scope', 'TableBuilderService', 'TableDetailService',
122 'FnService', 'MastService', 'PanelService', 'WebSocketService',
123 'IconService',
Simon Huntcc035c52017-02-22 21:12:51 -0800124
Simon Hunt7d5e9842017-02-23 11:37:02 -0800125 function (_$log_, _$scope_, tbs, tds, _fs_, _mast_, _ps_, _wss_, _is_) {
126 var handlers = {};
Simon Huntcc035c52017-02-22 21:12:51 -0800127
Simon Hunt7d5e9842017-02-23 11:37:02 -0800128 $log = _$log_;
129 $scope = _$scope_;
130 fs = _fs_;
131 mast = _mast_;
132 ps = _ps_;
133 wss = _wss_;
134 is = _is_;
Simon Huntcc035c52017-02-22 21:12:51 -0800135
Simon Hunt7d5e9842017-02-23 11:37:02 -0800136 $scope.panelData = {};
Simon Huntcc035c52017-02-22 21:12:51 -0800137
Simon Hunt7d5e9842017-02-23 11:37:02 -0800138 // register response handler
139 handlers[detailsResp] = respDetailsCb;
140 wss.bindHandlers(handlers);
Simon Huntcc035c52017-02-22 21:12:51 -0800141
Simon Hunt7d5e9842017-02-23 11:37:02 -0800142 // row selection callback
143 function selCb($event, row) {
144 if ($scope.selId) {
145 wss.sendEvent(detailsReq, { id: row.id });
146 } else {
147 $scope.hidePanel();
Simon Huntcc035c52017-02-22 21:12:51 -0800148 }
Simon Hunt7d5e9842017-02-23 11:37:02 -0800149 $log.debug('Got a click on:', row);
Simon Huntcc035c52017-02-22 21:12:51 -0800150 }
Simon Huntcc035c52017-02-22 21:12:51 -0800151
Simon Hunt7d5e9842017-02-23 11:37:02 -0800152 tbs.buildTable({
153 scope: $scope,
154 tag: 'yangModel',
155 selCb: selCb
156 });
157
158 $scope.$on('$destroy', function () {
159 wss.unbindHandlers(handlers);
160 });
161
162 $log.log('OvYangModelCtrl has been created');
163 }
164 ])
165
166 .directive('yangModelDetailsPanel', [
167 '$rootScope', '$window', '$timeout', 'KeyService',
168
169 function ($rootScope, $window, $timeout, ks) {
170 return function (scope) {
171 var unbindWatch;
172
173 function heightCalc() {
174 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
175 + mast.mastHeight() + topPdg;
176 wSize = fs.windowSize(pStartY);
177 pHeight = wSize.height;
178 }
179
180 function initPanel() {
181 heightCalc();
182 createDetailsPanel();
183 }
184
185 // Safari has a bug where it renders the fixed-layout table wrong
186 // if you ask for the window's size too early
187 if (scope.onos.browser === 'safari') {
188 $timeout(initPanel);
189 } else {
190 initPanel();
191 }
192
193 // create key bindings to handle panel
194 ks.keyBindings({
195 esc: [handleEscape, 'Close the details panel'],
196 _helpFormat: ['esc']
197 });
198 ks.gestureNotes([
199 ['click', 'Select a row to show YANG model details'],
200 ['scroll down', 'See more models']
201 ]);
202
203 // if the panelData changes
204 scope.$watch('panelData', function () {
205 if (!fs.isEmptyObject(scope.panelData)) {
206 populateDetails(scope.panelData);
207 detailsPanel.show();
208 }
209 });
210
211 // if the window size changes
212 unbindWatch = $rootScope.$watchCollection(
213 function () {
214 return {
215 h: $window.innerHeight,
216 w: $window.innerWidth
217 };
218 }, function () {
219 if (!fs.isEmptyObject(scope.panelData)) {
220 heightCalc();
221 populateDetails(scope.panelData);
222 }
223 }
224 );
225
226 scope.$on('$destroy', function () {
227 unbindWatch();
228 ks.unbindKeys();
229 ps.destroyPanel(pName);
230 });
231 };
232 }]);
Simon Huntcc035c52017-02-22 21:12:51 -0800233
234}());