blob: caca00cbb99f7cbaf87e9b6cdd09f22a9a23f477 [file] [log] [blame]
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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
Steven Burrows1c2a9682017-07-14 16:52:46 +010025 var $log, $scope, 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 = [
Thomas Vachuska6af7f152017-09-12 14:56:44 -070041 'Component', 'Property', 'Type', 'Value', 'Default',
Steven Burrows1c2a9682017-07-14 16:52:46 +010042 'Description',
Simon Huntd721f292016-06-22 21:42:23 -070043 ];
44
45 function createDetailsPanel() {
46 detailsPanel = ps.createPanel(pName, {
47 width: wSize.width,
48 margin: 0,
Steven Burrows1c2a9682017-07-14 16:52:46 +010049 hideMargin: 0,
Simon Huntd721f292016-06-22 21:42:23 -070050 });
51
52 detailsPanel.el().style({
53 position: 'absolute',
Steven Burrows1c2a9682017-07-14 16:52:46 +010054 top: pStartY + 'px',
Simon Huntd721f292016-06-22 21:42:23 -070055 });
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) {
Thomas Vachuskaa4410742017-09-14 09:59:16 -070071 is.loadEmbeddedIcon(div, 'close', 20);
Simon Huntd721f292016-06-22 21:42:23 -070072 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) {
Steven Burrows1c2a9682017-07-14 16:52:46 +010090 var d = div.append('div').classed(cls, true);
Simon Huntd721f292016-06-22 21:42:23 -070091 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) {
Thomas Vachuska6af7f152017-09-12 14:56:44 -0700113 var propsBody = top.select('.settings-props table').append('tbody');
Simon Huntd721f292016-06-22 21:42:23 -0700114
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',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100132 'FnService', 'KeyService', 'PanelService',
Simon Huntd721f292016-06-22 21:42:23 -0700133 'IconService', 'TableBuilderService',
134
Steven Burrows1c2a9682017-07-14 16:52:46 +0100135 function (_$log_, _$scope_, _fs_, _ks_, _ps_, _is_, tbs) {
Simon Huntd721f292016-06-22 21:42:23 -0700136 $log = _$log_;
137 $scope = _$scope_;
Simon Huntd721f292016-06-22 21:42:23 -0700138 fs = _fs_;
139 ks = _ks_;
140 ps = _ps_;
141 is = _is_;
142 $scope.panelData = {};
143
144 function selCb($event, row) {
145 if ($scope.selId) {
146 panelData = row;
147 populateDetails();
148 detailsPanel.show();
149 } else {
150 panelData = null;
151 detailsPanel.hide();
152 }
153 }
154
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -0700155 tbs.buildTable({
156 scope: $scope,
Simon Huntd721f292016-06-22 21:42:23 -0700157 tag: 'setting',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100158 selCb: selCb,
Simon Huntd721f292016-06-22 21:42:23 -0700159 });
160
161 ks.keyBindings({
162 esc: [$scope.selectCallback, 'Deselect property'],
Steven Burrows1c2a9682017-07-14 16:52:46 +0100163 _helpFormat: ['esc'],
Simon Huntd721f292016-06-22 21:42:23 -0700164 });
165 ks.gestureNotes([
166 ['click row', 'Select / deselect settings property'],
Steven Burrows1c2a9682017-07-14 16:52:46 +0100167 ['scroll down', 'See more settings'],
Simon Huntd721f292016-06-22 21:42:23 -0700168 ]);
169
170 $scope.$on('$destroy', function () {
171 ks.unbindKeys();
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -0700172 });
173
174 $log.log('OvSettingsCtrl has been created');
Simon Huntd721f292016-06-22 21:42:23 -0700175 }])
176
177 .directive('settingsDetailsPanel',
178 ['$rootScope', '$window', '$timeout', 'KeyService',
179 function ($rootScope, $window, $timeout, ks) {
180 return function (scope) {
181 var unbindWatch;
182
183 function heightCalc() {
184 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
185 + topPdg;
186 wSize = fs.windowSize(pStartY);
187 pHeight = wSize.height;
188 }
189
190 function initPanel() {
191 heightCalc();
192 createDetailsPanel();
193 $log.debug('start to initialize panel!');
194 }
195
196 // Safari has a bug where it renders the fixed-layout table wrong
197 // if you ask for the window's size too early
198 if (scope.onos.browser === 'safari') {
199 $timeout(initPanel);
200 } else {
201 initPanel();
202 }
203 // create key bindings to handle panel
204 ks.keyBindings({
205 esc: [closePanel, 'Close the details panel'],
Steven Burrows1c2a9682017-07-14 16:52:46 +0100206 _helpFormat: ['esc'],
Simon Huntd721f292016-06-22 21:42:23 -0700207 });
208 ks.gestureNotes([
209 ['click', 'Select a row to show property details'],
Steven Burrows1c2a9682017-07-14 16:52:46 +0100210 ['scroll down', 'See more properties'],
Simon Huntd721f292016-06-22 21:42:23 -0700211 ]);
212
213 // if the window size changes
214 unbindWatch = $rootScope.$watchCollection(
215 function () {
216 return {
217 h: $window.innerHeight,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100218 w: $window.innerWidth,
Simon Huntd721f292016-06-22 21:42:23 -0700219 };
220 }, function () {
221 if (panelData) {
222 heightCalc();
223 populateDetails();
224 }
225 }
226 );
227
228 scope.$on('$destroy', function () {
229 panelData = null;
230 unbindWatch();
231 ks.unbindKeys();
232 ps.destroyPanel(pName);
233 });
234 };
235 }]);
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -0700236}());