blob: ce3caa1fe69f2bb0c9cb08612314054e343bd857 [file] [log] [blame]
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -07003 *
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 -- Component Settings View Module
19 */
20
21(function () {
22 'use strict';
23
Simon Huntd721f292016-06-22 21:42:23 -070024 // injected refs
25 var $log, $scope, wss, fs, ks, ps, is;
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -070026
Simon Huntd721f292016-06-22 21:42:23 -070027 // internal state
28 var detailsPanel,
29 panelData,
30 top,
31 pStartY,
32 pHeight,
33 wSize = false;
34
35 // constants
36 var pName = 'settings-details-panel',
37 panelWidth = 540,
38 topPdg = 60,
Simon Hunt50e80ea2016-06-23 01:40:30 -070039 propOrder = ['fqComponent', 'prop', 'type', 'value', 'defValue', 'desc'],
Simon Huntd721f292016-06-22 21:42:23 -070040 friendlyProps = [
41 'Component', 'Property', 'Type', 'Value', 'Default Value',
42 'Description'
43 ];
44
45 function createDetailsPanel() {
46 detailsPanel = ps.createPanel(pName, {
47 width: wSize.width,
48 margin: 0,
49 hideMargin: 0
50 });
51
52 detailsPanel.el().style({
53 position: 'absolute',
54 top: pStartY + 'px'
55 });
56
57 detailsPanel.hide();
58 }
59
60 function closePanel() {
61 if (detailsPanel.isVisible()) {
62 $scope.selId = null;
63 panelData = null;
64 detailsPanel.hide();
65 return true;
66 }
67 return false;
68 }
69
70 function addCloseBtn(div) {
71 is.loadEmbeddedIcon(div, 'close', 26);
72 div.on('click', closePanel);
73 }
74
75 function setUpPanel() {
76 var container, closeBtn, div;
77
78 detailsPanel.empty();
79 detailsPanel.width(panelWidth);
80
81 container = detailsPanel.append('div').classed('container', true);
82
83 top = container.append('div').classed('top', true);
84 closeBtn = top.append('div').classed('close-btn', true);
85 addCloseBtn(closeBtn);
86
87 div = top.append('div').classed('top-content', true);
88
89 function ndiv(cls, addTable) {
90 var d = div.append('div').classed(cls, true);
91 if (addTable) {
92 d.append('table');
93 }
94 }
95
Simon Hunt50e80ea2016-06-23 01:40:30 -070096 ndiv('settings-title-1');
97 ndiv('settings-title-2');
Simon Huntd721f292016-06-22 21:42:23 -070098 ndiv('settings-props', true);
99 }
100
101 function addProp(tbody, index, value) {
102 var tr = tbody.append('tr');
103
104 function addCell(cls, txt) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700105 tr.append('td').attr('class', cls).text(txt);
Simon Huntd721f292016-06-22 21:42:23 -0700106 }
107
108 addCell('label', friendlyProps[index] + ':');
109 addCell('value', value);
110 }
111
112 function populateTop(details) {
113 var propsBody = top.select('.settings-props').append('tbody');
114
Simon Hunt50e80ea2016-06-23 01:40:30 -0700115 top.select('.settings-title-1').text(details.component);
116 top.select('.settings-title-2').text(details.prop);
Simon Huntd721f292016-06-22 21:42:23 -0700117
118 propOrder.forEach(function (prop, i) {
119 addProp(propsBody, i, details[prop]);
120 });
121 }
122
123 function populateDetails() {
124 setUpPanel();
125 populateTop(panelData);
126 detailsPanel.height(pHeight);
127 }
128
129 angular.module('ovSettings', [])
130 .controller('OvSettingsCtrl',
131 ['$log', '$scope',
132 'WebSocketService', 'FnService', 'KeyService', 'PanelService',
133 'IconService', 'TableBuilderService',
134
135 function (_$log_, _$scope_, _wss_, _fs_, _ks_, _ps_, _is_, tbs) {
136 $log = _$log_;
137 $scope = _$scope_;
138 wss = _wss_;
139 fs = _fs_;
140 ks = _ks_;
141 ps = _ps_;
142 is = _is_;
143 $scope.panelData = {};
144
145 function selCb($event, row) {
146 if ($scope.selId) {
147 panelData = row;
148 populateDetails();
149 detailsPanel.show();
150 } else {
151 panelData = null;
152 detailsPanel.hide();
153 }
154 }
155
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -0700156 tbs.buildTable({
157 scope: $scope,
Simon Huntd721f292016-06-22 21:42:23 -0700158 tag: 'setting',
159 selCb: selCb
160 });
161
162 ks.keyBindings({
163 esc: [$scope.selectCallback, 'Deselect property'],
164 _helpFormat: ['esc']
165 });
166 ks.gestureNotes([
167 ['click row', 'Select / deselect settings property'],
168 ['scroll down', 'See more settings']
169 ]);
170
171 $scope.$on('$destroy', function () {
172 ks.unbindKeys();
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -0700173 });
174
175 $log.log('OvSettingsCtrl has been created');
Simon Huntd721f292016-06-22 21:42:23 -0700176 }])
177
178 .directive('settingsDetailsPanel',
179 ['$rootScope', '$window', '$timeout', 'KeyService',
180 function ($rootScope, $window, $timeout, ks) {
181 return function (scope) {
182 var unbindWatch;
183
184 function heightCalc() {
185 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
186 + topPdg;
187 wSize = fs.windowSize(pStartY);
188 pHeight = wSize.height;
189 }
190
191 function initPanel() {
192 heightCalc();
193 createDetailsPanel();
194 $log.debug('start to initialize panel!');
195 }
196
197 // Safari has a bug where it renders the fixed-layout table wrong
198 // if you ask for the window's size too early
199 if (scope.onos.browser === 'safari') {
200 $timeout(initPanel);
201 } else {
202 initPanel();
203 }
204 // create key bindings to handle panel
205 ks.keyBindings({
206 esc: [closePanel, 'Close the details panel'],
207 _helpFormat: ['esc']
208 });
209 ks.gestureNotes([
210 ['click', 'Select a row to show property details'],
211 ['scroll down', 'See more properties']
212 ]);
213
214 // if the window size changes
215 unbindWatch = $rootScope.$watchCollection(
216 function () {
217 return {
218 h: $window.innerHeight,
219 w: $window.innerWidth
220 };
221 }, function () {
222 if (panelData) {
223 heightCalc();
224 populateDetails();
225 }
226 }
227 );
228
229 scope.$on('$destroy', function () {
230 panelData = null;
231 unbindWatch();
232 ks.unbindKeys();
233 ps.destroyPanel(pName);
234 });
235 };
236 }]);
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -0700237}());