blob: 4fbb0df37c654de8952eef65e1f8ba4de13fdaf4 [file] [log] [blame]
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -08003 *
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/*
Bri Prebilic Coleaa0f0882015-02-04 15:27:55 -080018 ONOS GUI -- Device View Module
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080019 */
20
21(function () {
22 'use strict';
23
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070024 // injected refs
Simon Huntd5579252015-10-06 15:09:14 -070025 var $log, $scope, $loc, fs, mast, ps, wss, is, ns, ks;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070026
27 // internal state
Bri Prebilic Colee568ead2015-05-01 09:51:28 -070028 var detailsPanel,
Simon Huntd766c312015-10-06 11:46:32 -070029 pStartY,
30 pHeight,
31 top,
32 bottom,
33 iconDiv,
34 wSize,
Alan Deikman8d858752017-02-14 18:08:29 -080035 editingName = false,
36 device;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070037
38 // constants
Simon Hunt986b92f2016-06-03 15:46:59 -070039 var topPdg = 28,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070040 ctnrPdg = 24,
Bri Prebilic Cole9cf1a8d2015-04-21 13:15:29 -070041 scrollSize = 17,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070042 portsTblPdg = 50,
Yi Tseng1802f552017-08-23 10:14:05 -070043 defaultLabelWidth = 110,
44 defaultValueWidth = 80,
Bri Prebilic Cole45069382015-04-14 15:21:38 -070045
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070046 pName = 'device-details-panel',
47 detailsReq = 'deviceDetailsRequest',
48 detailsResp = 'deviceDetailsResponse',
Simon Huntd5579252015-10-06 15:09:14 -070049 nameChangeReq = 'deviceNameChangeRequest',
50 nameChangeResp = 'deviceNameChangeResponse',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070051 friendlyProps = [
Simon Huntd5579252015-10-06 15:09:14 -070052 'URI', 'Type', 'Master ID', 'Chassis ID',
Steven Burrows1c2a9682017-07-14 16:52:46 +010053 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #',
Yi Tseng1802f552017-08-23 10:14:05 -070054 'Pipeconf',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070055 ],
56 portCols = [
Steven Burrows1c2a9682017-07-14 16:52:46 +010057 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070058 ],
59 friendlyPortCols = [
Steven Burrows1c2a9682017-07-14 16:52:46 +010060 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -070061 ];
62
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -070063 function closePanel() {
64 if (detailsPanel.isVisible()) {
65 $scope.selId = null;
66 detailsPanel.hide();
Simon Huntd766c312015-10-06 11:46:32 -070067 return true;
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -070068 }
Simon Huntd766c312015-10-06 11:46:32 -070069 return false;
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -070070 }
71
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070072 function addCloseBtn(div) {
Simon Hunt986b92f2016-06-03 15:46:59 -070073 is.loadEmbeddedIcon(div, 'close', 20);
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -070074 div.on('click', closePanel);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070075 }
76
Simon Huntd5579252015-10-06 15:09:14 -070077 function exitEditMode(nameH2, name) {
Simon Hunt239f09e2017-05-18 13:10:09 -070078 nameH2.text(name);
Simon Hunt986b92f2016-06-03 15:46:59 -070079 nameH2.classed('editable clickable', true);
Simon Huntd5579252015-10-06 15:09:14 -070080 editingName = false;
81 ks.enableGlobalKeys(true);
Simon Huntd766c312015-10-06 11:46:32 -070082 }
83
84 function editNameSave() {
Simon Huntd5579252015-10-06 15:09:14 -070085 var nameH2 = top.select('h2'),
86 id = $scope.panelData.id,
87 val,
Simon Huntd766c312015-10-06 11:46:32 -070088 newVal;
Simon Huntd5579252015-10-06 15:09:14 -070089
Simon Huntd766c312015-10-06 11:46:32 -070090 if (editingName) {
Simon Huntd5579252015-10-06 15:09:14 -070091 val = nameH2.select('input').property('value').trim();
92 newVal = val || id;
Simon Huntd766c312015-10-06 11:46:32 -070093
Simon Huntd5579252015-10-06 15:09:14 -070094 exitEditMode(nameH2, newVal);
Simon Huntd766c312015-10-06 11:46:32 -070095 $scope.panelData.name = newVal;
Simon Huntd5579252015-10-06 15:09:14 -070096 wss.sendEvent(nameChangeReq, { id: id, name: val });
Simon Huntd766c312015-10-06 11:46:32 -070097 }
98 }
99
100 function editNameCancel() {
Simon Huntd766c312015-10-06 11:46:32 -0700101 if (editingName) {
Simon Huntd5579252015-10-06 15:09:14 -0700102 exitEditMode(top.select('h2'), $scope.panelData.name);
Simon Huntd766c312015-10-06 11:46:32 -0700103 return true;
104 }
105 return false;
106 }
107
108 function editName() {
Simon Huntd5579252015-10-06 15:09:14 -0700109 var nameH2 = top.select('h2'),
110 tf, el;
111
Simon Huntd766c312015-10-06 11:46:32 -0700112 if (!editingName) {
Simon Hunt986b92f2016-06-03 15:46:59 -0700113 nameH2.classed('editable clickable', false);
Simon Hunt239f09e2017-05-18 13:10:09 -0700114 nameH2.text('');
Simon Huntd5579252015-10-06 15:09:14 -0700115 tf = nameH2.append('input').classed('name-input', true)
Simon Huntd766c312015-10-06 11:46:32 -0700116 .attr('type', 'text')
117 .attr('value', $scope.panelData.name);
Simon Huntd5579252015-10-06 15:09:14 -0700118 el = tf[0][0];
119 el.focus();
120 el.select();
121 editingName = true;
122 ks.enableGlobalKeys(false);
Simon Huntd766c312015-10-06 11:46:32 -0700123 }
124 }
125
126 function handleEscape() {
127 return editNameCancel() || closePanel();
128 }
129
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700130 function setUpPanel() {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700131 var container, closeBtn, tblDiv;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700132 detailsPanel.empty();
133
134 container = detailsPanel.append('div').classed('container', true);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700135
136 top = container.append('div').classed('top', true);
137 closeBtn = top.append('div').classed('close-btn', true);
138 addCloseBtn(closeBtn);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700139 iconDiv = top.append('div').classed('dev-icon', true);
Simon Hunt986b92f2016-06-03 15:46:59 -0700140 top.append('h2').classed('editable clickable', true).on('click', editName);
Simon Huntd766c312015-10-06 11:46:32 -0700141
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700142 tblDiv = top.append('div').classed('top-tables', true);
143 tblDiv.append('div').classed('left', true).append('table');
144 tblDiv.append('div').classed('right', true).append('table');
145
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700146 top.append('hr');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700147
148 bottom = container.append('div').classed('bottom', true);
Simon Hunt239f09e2017-05-18 13:10:09 -0700149 bottom.append('h2').classed('ports-title', true).text('Ports');
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700150 bottom.append('table');
151 }
152
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700153 function addProp(tbody, index, value) {
154 var tr = tbody.append('tr');
155
Yi Tseng1802f552017-08-23 10:14:05 -0700156 function addCell(cls, txt, width) {
157 tr.append('td').attr('class', cls).attr('width', width).text(txt);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700158 }
Yi Tseng1802f552017-08-23 10:14:05 -0700159 addCell('label', friendlyProps[index] + ' :', defaultLabelWidth);
160 addCell('value', value, defaultValueWidth);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700161 }
162
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700163 function populateTop(tblDiv, details) {
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700164 var leftTbl = tblDiv.select('.left')
165 .select('table')
166 .append('tbody'),
167 rightTbl = tblDiv.select('.right')
168 .select('table')
169 .append('tbody');
170
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700171 is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40);
Simon Hunt239f09e2017-05-18 13:10:09 -0700172 top.select('h2').text(details.name);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700173
Alan Deikman8d858752017-02-14 18:08:29 -0800174 // === demonstrate use of JsonCodec object see ONOS-5976
Steven Burrows1c2a9682017-07-14 16:52:46 +0100175 addProp(leftTbl, 0, device.id);
176 addProp(leftTbl, 1, device.type);
177 addProp(leftTbl, 2, details['masterid']);
178 addProp(leftTbl, 3, details['chassid']);
Yi Tseng1802f552017-08-23 10:14:05 -0700179 addProp(leftTbl, 4, device.mfr);
Alan Deikman8d858752017-02-14 18:08:29 -0800180 addProp(rightTbl, 5, device.hw);
181 addProp(rightTbl, 6, device.sw);
182 addProp(rightTbl, 7, details['protocol']);
183 addProp(rightTbl, 8, device.serial);
Yi Tseng1802f552017-08-23 10:14:05 -0700184 addProp(rightTbl, 9, details['pipeconf']);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700185 }
186
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700187 function addPortRow(tbody, port) {
188 var tr = tbody.append('tr');
189
190 portCols.forEach(function (col) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700191 tr.append('td').text(port[col]);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700192 });
193 }
194
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700195 function populateBottom(table, ports) {
196 var theader = table.append('thead').append('tr'),
197 tbody = table.append('tbody'),
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700198 tbWidth, tbHeight;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700199
200 friendlyPortCols.forEach(function (col) {
Simon Hunt239f09e2017-05-18 13:10:09 -0700201 theader.append('th').text(col);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700202 });
203 ports.forEach(function (port) {
204 addPortRow(tbody, port);
205 });
206
207 tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize;
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700208 tbHeight = pHeight
209 - (fs.noPxStyle(detailsPanel.el()
210 .select('.top'), 'height')
211 + fs.noPxStyle(detailsPanel.el()
212 .select('.ports-title'), 'height')
213 + portsTblPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700214
215 table.style({
216 height: tbHeight + 'px',
217 width: tbWidth + 'px',
218 overflow: 'auto',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100219 display: 'block',
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700220 });
221
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700222 detailsPanel.width(tbWidth + ctnrPdg);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700223 }
224
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700225 function populateDetails(details) {
Simon Hunta9301bb2016-10-20 11:38:10 -0700226 var topTbs, btmTbl, ports;
227
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700228 setUpPanel();
229
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700230 topTbs = top.select('.top-tables');
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700231 btmTbl = bottom.select('table');
232 ports = details.ports;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700233
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700234 populateTop(topTbs, details);
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700235 populateBottom(btmTbl, ports);
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700236
237 detailsPanel.height(pHeight);
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700238 }
239
240 function respDetailsCb(data) {
Bri Prebilic Colee568ead2015-05-01 09:51:28 -0700241 $scope.panelData = data.details;
Alan Deikman8d858752017-02-14 18:08:29 -0800242 device = data.device;
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700243 $scope.$apply();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700244 }
245
Simon Huntd5579252015-10-06 15:09:14 -0700246 function respNameCb(data) {
247 if (data.warn) {
248 $log.warn(data.warn, data.id);
Simon Hunt239f09e2017-05-18 13:10:09 -0700249 top.select('h2').text(data.id);
Simon Huntd5579252015-10-06 15:09:14 -0700250 }
251 }
252
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700253 function createDetailsPane() {
254 detailsPanel = ps.createPanel(pName, {
255 width: wSize.width,
256 margin: 0,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100257 hideMargin: 0,
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700258 });
259 detailsPanel.el().style({
260 position: 'absolute',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100261 top: pStartY + 'px',
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700262 });
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -0700263 $scope.hidePanel = function () { detailsPanel.hide(); };
Bri Prebilic Cole45069382015-04-14 15:21:38 -0700264 detailsPanel.hide();
265 }
266
Simon Hunt400ebbf2017-01-06 20:07:50 -0800267 // Sample functions for detail panel creation
268 function popTop(div) {
269 $log.debug('populateTop');
270 // TODO: real work
271 // div.append(.....);
272 // div.append(.....);
273 // div.append(.....);
274 }
275
276 function popMid(div) {
277 $log.debug('populateMiddle');
278 // TODO: real work
279 }
280
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800281 angular.module('ovDevice', [])
Simon Hunta89f0f92015-02-26 16:47:12 -0800282 .controller('OvDeviceCtrl',
Simon Hunt400ebbf2017-01-06 20:07:50 -0800283 ['$log', '$scope', '$location', 'TableBuilderService',
284 'TableDetailService', 'FnService',
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700285 'MastService', 'PanelService', 'WebSocketService', 'IconService',
Simon Huntd5579252015-10-06 15:09:14 -0700286 'NavService', 'KeyService',
Simon Hunta89f0f92015-02-26 16:47:12 -0800287
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700288 function (_$log_, _$scope_, _$location_,
Simon Hunt400ebbf2017-01-06 20:07:50 -0800289 tbs, tds, _fs_, _mast_, _ps_, _wss_, _is_, _ns_, _ks_) {
Simon Huntd5579252015-10-06 15:09:14 -0700290 var params,
291 handlers = {};
292
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700293 $log = _$log_;
294 $scope = _$scope_;
Simon Huntd5579252015-10-06 15:09:14 -0700295 $loc = _$location_;
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700296 fs = _fs_;
297 mast = _mast_;
298 ps = _ps_;
299 wss = _wss_;
300 is = _is_;
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -0700301 ns = _ns_;
Simon Huntd5579252015-10-06 15:09:14 -0700302 ks = _ks_;
303
304 params = $loc.search();
305
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -0700306 $scope.panelData = {};
Bri Prebilic Coleeef67ae2015-07-01 16:26:59 -0700307 $scope.flowTip = 'Show flow view for selected device';
308 $scope.portTip = 'Show port view for selected device';
309 $scope.groupTip = 'Show group view for selected device';
Jian Li1f544732015-12-30 23:36:37 -0800310 $scope.meterTip = 'Show meter view for selected device';
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700311
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700312 // details panel handlers
313 handlers[detailsResp] = respDetailsCb;
Simon Huntd5579252015-10-06 15:09:14 -0700314 handlers[nameChangeResp] = respNameCb;
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700315 wss.bindHandlers(handlers);
316
317 // query for if a certain device needs to be highlighted
318 if (params.hasOwnProperty('devId')) {
319 $scope.selId = params['devId'];
320 wss.sendEvent(detailsReq, { id: $scope.selId });
321 }
322
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700323 function selCb($event, row) {
Bri Prebilic Colebfab9c72015-06-01 14:33:18 -0700324 if ($scope.selId) {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700325 wss.sendEvent(detailsReq, { id: row.id });
326 } else {
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -0700327 $scope.hidePanel();
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700328 }
329 $log.debug('Got a click on:', row);
330 }
331
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700332 tbs.buildTable({
Bri Prebilic Cole864cdd62015-04-02 15:46:47 -0700333 scope: $scope,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700334 tag: 'device',
Steven Burrows1c2a9682017-07-14 16:52:46 +0100335 selCb: selCb,
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700336 });
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700337
Simon Hunt400ebbf2017-01-06 20:07:50 -0800338
339 // ==================== for testing for now ===============
340 // TODO: more than just an example
341 tds.buildBasePanel({
342 popTop: popTop,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100343 popMid: popMid,
Simon Hunt400ebbf2017-01-06 20:07:50 -0800344 });
345 // ==================== for testing for now ===============
346
347
Bri Prebilic Cole9b1fb9a2015-07-01 13:57:11 -0700348 $scope.nav = function (path) {
349 if ($scope.selId) {
350 ns.navTo(path, { devId: $scope.selId });
351 }
352 };
353
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700354 $scope.$on('$destroy', function () {
Bri Prebilic Cole0feedc02015-04-09 14:17:37 -0700355 wss.unbindHandlers(handlers);
Simon Hunta89f0f92015-02-26 16:47:12 -0800356 });
357
Bri Prebilic Cole72eb6db2015-03-30 16:58:53 -0700358 $log.log('OvDeviceCtrl has been created');
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700359 }])
360
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700361 .directive('deviceDetailsPanel',
362 ['$rootScope', '$window', '$timeout', 'KeyService',
363 function ($rootScope, $window, $timeout, ks) {
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700364 return function (scope) {
Bri Prebilic Cole0bc4de22015-07-20 17:07:55 -0700365 var unbindWatch;
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700366
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700367 function heightCalc() {
368 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
369 + mast.mastHeight() + topPdg;
370 wSize = fs.windowSize(pStartY);
371 pHeight = wSize.height;
372 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700373
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700374 function initPanel() {
375 heightCalc();
376 createDetailsPane();
377 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700378
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700379 // Safari has a bug where it renders the fixed-layout table wrong
380 // if you ask for the window's size too early
381 if (scope.onos.browser === 'safari') {
382 $timeout(initPanel);
383 } else {
384 initPanel();
385 }
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700386 // create key bindings to handle panel
387 ks.keyBindings({
Simon Huntd766c312015-10-06 11:46:32 -0700388 enter: editNameSave,
389 esc: [handleEscape, 'Close the details panel'],
Steven Burrows1c2a9682017-07-14 16:52:46 +0100390 _helpFormat: ['esc'],
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700391 });
392 ks.gestureNotes([
393 ['click', 'Select a row to show device details'],
Steven Burrows1c2a9682017-07-14 16:52:46 +0100394 ['scroll down', 'See more devices'],
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700395 ]);
396
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700397 // if the panelData changes
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700398 scope.$watch('panelData', function () {
399 if (!fs.isEmptyObject(scope.panelData)) {
400 populateDetails(scope.panelData);
401 detailsPanel.show();
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700402 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700403 });
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700404
Bri Prebilic Cole55ee09b2015-08-04 14:34:07 -0700405 // if the window size changes
Bri Prebilic Cole0bc4de22015-07-20 17:07:55 -0700406 unbindWatch = $rootScope.$watchCollection(
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700407 function () {
408 return {
409 h: $window.innerHeight,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100410 w: $window.innerWidth,
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700411 };
412 }, function () {
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700413 if (!fs.isEmptyObject(scope.panelData)) {
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700414 heightCalc();
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700415 populateDetails(scope.panelData);
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700416 }
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700417 }
418 );
Bri Prebilic Cole54bbfb92015-05-28 16:02:28 -0700419
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700420 scope.$on('$destroy', function () {
Bri Prebilic Cole0bc4de22015-07-20 17:07:55 -0700421 unbindWatch();
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700422 ks.unbindKeys();
Bri Prebilic Cole17c6d0a2015-07-16 14:56:40 -0700423 ps.destroyPanel(pName);
424 });
425 };
426 }]);
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800427}());