blob: be72230deefcd163e3e1f805660a9040ec48290d [file] [log] [blame]
Thomas Vachuska0fa583c2015-03-30 23:07:41 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska0fa583c2015-03-30 23:07:41 -07003 *
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -07004 * Licensed under the Apache License, Version 2.0 (the 'License');
Thomas Vachuska0fa583c2015-03-30 23:07:41 -07005 * 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
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070011 * distributed under the License is distributed on an 'AS IS' BASIS,
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070012 * 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 -- App View Module
19 */
20
21(function () {
22 'use strict';
23
Jian Lia54de5a2016-01-20 23:10:39 -080024 // injected refs
Simon Hunt31642932016-01-22 20:34:00 -080025 var $log, $scope, wss, fs, ks, ps, is;
Jian Lia54de5a2016-01-20 23:10:39 -080026
27 // internal state
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -080028 var detailsPanel,
29 pStartY,
30 pHeight,
31 top,
32 middle,
33 bottom,
34 wSize = false,
35 activateImmediately;
Jian Lia54de5a2016-01-20 23:10:39 -080036
Bri Prebilic Cole522e7562015-06-22 15:56:25 -070037 // constants
38 var INSTALLED = 'INSTALLED',
39 ACTIVE = 'ACTIVE',
Simon Hunt8d28a552016-01-11 14:01:02 -080040 appMgmtReq = 'appManagementRequest',
Simon Hunt047f4052016-06-06 16:51:11 -070041 topPdg = 60,
42 panelWidth = 540,
Jian Lia54de5a2016-01-20 23:10:39 -080043 pName = 'application-details-panel',
44 detailsReq = 'appDetailsRequest',
45 detailsResp = 'appDetailsResponse',
Simon Hunt8d28a552016-01-11 14:01:02 -080046 fileUploadUrl = 'applications/upload',
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -080047 activateOption = '?activate=true',
Jian Lia54de5a2016-01-20 23:10:39 -080048 iconUrlPrefix = 'rs/applications/',
49 iconUrlSuffix = '/icon',
Simon Hunt8d28a552016-01-11 14:01:02 -080050 dialogId = 'app-dialog',
51 dialogOpts = {
52 edge: 'right'
Simon Hunt3f92c432016-01-12 17:34:23 -080053 },
54 strongWarning = {
55 'org.onosproject.drivers': true
56 },
57 discouragement = 'Deactivating or uninstalling this component can' +
Jian Lia54de5a2016-01-20 23:10:39 -080058 ' have serious negative consequences! Do so at your own risk!!',
Simon Hunt31642932016-01-22 20:34:00 -080059 propOrder = ['id', 'state', 'category', 'version', 'origin', 'role'],
60 friendlyProps = ['App ID', 'State', 'Category', 'Version', 'Origin', 'Role'];
61 // note: url is handled separately
Jian Lia54de5a2016-01-20 23:10:39 -080062
63 function createDetailsPane() {
64 detailsPanel = ps.createPanel(pName, {
65 width: wSize.width,
66 margin: 0,
67 hideMargin: 0
68 });
69 detailsPanel.el().style({
70 position: 'absolute',
71 top: pStartY + 'px'
72 });
73 $scope.hidePanel = function () { detailsPanel.hide(); };
74 detailsPanel.hide();
75 }
76
77 function closePanel() {
78 if (detailsPanel.isVisible()) {
79 $scope.selId = null;
80 detailsPanel.hide();
81 return true;
82 }
83 return false;
84 }
85
Jian Lia54de5a2016-01-20 23:10:39 -080086 function addCloseBtn(div) {
Simon Hunte6e09842016-06-07 11:11:26 -070087 is.loadEmbeddedIcon(div, 'close', 26);
Jian Lia54de5a2016-01-20 23:10:39 -080088 div.on('click', closePanel);
89 }
90
91 function setUpPanel() {
Simon Hunt31642932016-01-22 20:34:00 -080092 var container, closeBtn, div;
93
Jian Lia54de5a2016-01-20 23:10:39 -080094 detailsPanel.empty();
Simon Hunt31642932016-01-22 20:34:00 -080095 detailsPanel.width(panelWidth);
Jian Lia54de5a2016-01-20 23:10:39 -080096
97 container = detailsPanel.append('div').classed('container', true);
98
99 top = container.append('div').classed('top', true);
100 closeBtn = top.append('div').classed('close-btn', true);
101 addCloseBtn(closeBtn);
Jian Lia54de5a2016-01-20 23:10:39 -0800102
Simon Hunt31642932016-01-22 20:34:00 -0800103 div = top.append('div').classed('top-content', true);
Jian Lia54de5a2016-01-20 23:10:39 -0800104
Simon Hunt31642932016-01-22 20:34:00 -0800105 function ndiv(cls, tcls) {
106 var d = div.append('div').classed(cls, true);
107 if (tcls) {
108 d.append('table').classed(tcls, true);
109 }
110 }
111
Simon Hunt877ee982016-03-09 10:53:16 -0800112 ndiv('app-title');
Simon Hunt31642932016-01-22 20:34:00 -0800113 ndiv('left app-icon');
114 ndiv('right', 'app-props');
115 ndiv('app-url');
116
117 container.append('hr');
Jian Lia54de5a2016-01-20 23:10:39 -0800118
Jian Lida253e02016-01-21 17:46:17 -0800119 middle = container.append('div').classed('middle', true);
Simon Hunt31642932016-01-22 20:34:00 -0800120 middle.append('div').classed('app-readme', true);
Jian Lida253e02016-01-21 17:46:17 -0800121
Simon Hunt31642932016-01-22 20:34:00 -0800122 container.append('hr');
Jian Lida253e02016-01-21 17:46:17 -0800123
Simon Hunt31642932016-01-22 20:34:00 -0800124 // TODO: make bottom container scrollable
Jian Lia54de5a2016-01-20 23:10:39 -0800125 bottom = container.append('div').classed('bottom', true);
Simon Hunt31642932016-01-22 20:34:00 -0800126
127 function nTable(hdr, cls) {
128 bottom.append('h2').html(hdr);
129 bottom.append('div').classed(cls, true).append('table');
130 }
131
132 nTable('Features', 'features');
133 nTable('Required Apps', 'required-apps');
134 nTable('Permissions', 'permissions');
Jian Lia54de5a2016-01-20 23:10:39 -0800135 }
136
137 function addProp(tbody, index, value) {
Simon Hunt811d8572016-06-02 13:40:14 -0700138 var tr = tbody.append('tr');
Jian Lia54de5a2016-01-20 23:10:39 -0800139
140 function addCell(cls, txt) {
141 tr.append('td').attr('class', cls).html(txt);
142 }
Simon Hunt31642932016-01-22 20:34:00 -0800143
144 addCell('label', friendlyProps[index] + ':');
Simon Hunt811d8572016-06-02 13:40:14 -0700145 addCell('value', value);
Jian Lia54de5a2016-01-20 23:10:39 -0800146 }
147
Simon Hunt31642932016-01-22 20:34:00 -0800148 function urlize(u) {
Simon Hunt811d8572016-06-02 13:40:14 -0700149 return 'Url:<br/> <a href="' + u + '" target="_blank">' + u + '</a>';
Simon Hunta477b602016-01-22 12:10:07 -0800150 }
151
Simon Hunt31642932016-01-22 20:34:00 -0800152 function addIcon(elem, value) {
153 elem.append('img').attr('src', iconUrlPrefix + value + iconUrlSuffix);
Jian Lia54de5a2016-01-20 23:10:39 -0800154 }
155
Simon Hunt31642932016-01-22 20:34:00 -0800156 function populateTop(details) {
157 var propsBody = top.select('.app-props').append('tbody'),
158 url = details.url;
Jian Lia54de5a2016-01-20 23:10:39 -0800159
Simon Hunt877ee982016-03-09 10:53:16 -0800160 top.select('.app-title').text(details.title);
161
Simon Hunt31642932016-01-22 20:34:00 -0800162 addIcon(top.select('.app-icon'), details.id);
Jian Lia54de5a2016-01-20 23:10:39 -0800163
Jian Lia54de5a2016-01-20 23:10:39 -0800164 propOrder.forEach(function (prop, i) {
Simon Hunt31642932016-01-22 20:34:00 -0800165 addProp(propsBody, i, details[prop]);
Jian Lia54de5a2016-01-20 23:10:39 -0800166 });
167
Simon Hunt31642932016-01-22 20:34:00 -0800168 if (url) {
169 top.select('.app-url').html(urlize(url));
170 }
Jian Lida253e02016-01-21 17:46:17 -0800171 }
172
Simon Hunt31642932016-01-22 20:34:00 -0800173 function populateMiddle(details) {
174 middle.select('.app-readme').text(details.readme);
Jian Lia54de5a2016-01-20 23:10:39 -0800175 }
176
Simon Hunt31642932016-01-22 20:34:00 -0800177 function populateBottom(details) {
178
179 function addItems(cls, items) {
180 var table = bottom.select('.' + cls).select('table'),
181 tbody = table.append('tbody');
182
183 items.forEach(function (item) {
184 tbody.append('tr').append('td').html(item);
185 });
186 }
187
188 addItems('features', details.features);
189 addItems('required-apps', details.required_apps);
190 addItems('permissions', details.permissions);
Jian Lia54de5a2016-01-20 23:10:39 -0800191 }
192
193 function populateDetails(details) {
Jian Lia54de5a2016-01-20 23:10:39 -0800194 setUpPanel();
Simon Hunt31642932016-01-22 20:34:00 -0800195 populateTop(details);
196 populateMiddle(details);
197 populateBottom(details);
Jian Lia54de5a2016-01-20 23:10:39 -0800198 detailsPanel.height(pHeight);
199 }
200
Jian Lia54de5a2016-01-20 23:10:39 -0800201 function respDetailsCb(data) {
202 $scope.panelData = data.details;
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800203 $scope.selId = data.details.id;
204 $scope.ctrlBtnState.selection = data.details.id;
Jian Lia54de5a2016-01-20 23:10:39 -0800205 $scope.$apply();
206 }
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700207
Thomas Vachuska0fa583c2015-03-30 23:07:41 -0700208 angular.module('ovApp', [])
209 .controller('OvAppCtrl',
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800210 ['$log', '$scope', '$http', '$timeout',
Simon Hunt31642932016-01-22 20:34:00 -0800211 'WebSocketService', 'FnService', 'KeyService', 'PanelService',
212 'IconService', 'UrlFnService', 'DialogService', 'TableBuilderService',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -0700213
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800214 function (_$log_, _$scope_, $http, $timeout, _wss_, _fs_, _ks_, _ps_, _is_, ufs, ds, tbs) {
Jian Lia54de5a2016-01-20 23:10:39 -0800215 $log = _$log_;
216 $scope = _$scope_;
217 wss = _wss_;
Jian Lia54de5a2016-01-20 23:10:39 -0800218 fs = _fs_;
Simon Hunt31642932016-01-22 20:34:00 -0800219 ks = _ks_;
Jian Lia54de5a2016-01-20 23:10:39 -0800220 ps = _ps_;
221 is = _is_;
222 $scope.panelData = {};
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -0700223 $scope.ctrlBtnState = {};
Bri Prebilic Cole6c82ade2015-08-05 11:12:30 -0700224 $scope.uploadTip = 'Upload an application (.oar file)';
Bri Prebilic Coleeef67ae2015-07-01 16:26:59 -0700225 $scope.activateTip = 'Activate selected application';
226 $scope.deactivateTip = 'Deactivate selected application';
227 $scope.uninstallTip = 'Uninstall selected application';
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -0700228
Jian Lia54de5a2016-01-20 23:10:39 -0800229 var handlers = {};
230
231 // details panel handlers
232 handlers[detailsResp] = respDetailsCb;
233 wss.bindHandlers(handlers);
234
Bri Prebilic Coleb699a162015-04-13 12:01:39 -0700235 function selCb($event, row) {
Simon Hunt3f92c432016-01-12 17:34:23 -0800236 // $scope.selId is set by code in tableBuilder
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -0700237 $scope.ctrlBtnState.selection = !!$scope.selId;
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700238 refreshCtrls();
Simon Hunt3f92c432016-01-12 17:34:23 -0800239 ds.closeDialog(); // don't want dialog from previous selection
Jian Lia54de5a2016-01-20 23:10:39 -0800240
241 if ($scope.selId) {
242 wss.sendEvent(detailsReq, { id: row.id });
243 } else {
244 $scope.hidePanel();
245 }
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700246 }
247
Bri Prebilic Colea7f81e52015-06-23 10:11:08 -0700248 function refreshCtrls() {
249 var row, rowIdx;
250 if ($scope.ctrlBtnState.selection) {
251 rowIdx = fs.find($scope.selId, $scope.tableData);
252 row = rowIdx >= 0 ? $scope.tableData[rowIdx] : null;
253
254 $scope.ctrlBtnState.installed = row && row.state === INSTALLED;
255 $scope.ctrlBtnState.active = row && row.state === ACTIVE;
256 } else {
257 $scope.ctrlBtnState.installed = false;
258 $scope.ctrlBtnState.active = false;
259 }
Thomas Vachuska619c5382015-04-02 13:41:47 -0700260 }
Thomas Vachuska0fa583c2015-03-30 23:07:41 -0700261
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -0700262 tbs.buildTable({
263 scope: $scope,
264 tag: 'app',
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700265 selCb: selCb,
Simon Hunta678b842016-01-11 17:14:18 -0800266 respCb: refreshCtrls,
267 // pre-populate sort so active apps are at the top of the list
268 sortParams: {
Simon Hunt051e9fa2016-01-19 15:54:22 -0800269 firstCol: 'state',
270 firstDir: 'desc',
Simon Hunt877ee982016-03-09 10:53:16 -0800271 secondCol: 'title',
Simon Hunt051e9fa2016-01-19 15:54:22 -0800272 secondDir: 'asc'
Simon Hunta678b842016-01-11 17:14:18 -0800273 }
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -0700274 });
275
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700276 // TODO: reexamine where keybindings should be - directive or controller?
277 ks.keyBindings({
Simon Hunt31642932016-01-22 20:34:00 -0800278 esc: [$scope.selectCallback, 'Deselect application'],
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700279 _helpFormat: ['esc']
280 });
281 ks.gestureNotes([
Simon Hunt31642932016-01-22 20:34:00 -0800282 ['click row', 'Select / deselect application'],
283 ['scroll down', 'See more applications']
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700284 ]);
285
Simon Hunt3f92c432016-01-12 17:34:23 -0800286 function createConfirmationText(action, itemId) {
Simon Hunt8d28a552016-01-11 14:01:02 -0800287 var content = ds.createDiv();
Simon Hunt40927332016-01-22 15:29:47 -0800288 content.append('p').text(fs.cap(action) + ' ' + itemId);
Simon Hunt3f92c432016-01-12 17:34:23 -0800289 if (strongWarning[itemId]) {
290 content.append('p').text(discouragement).classed('strong', true);
291 }
Simon Hunt8d28a552016-01-11 14:01:02 -0800292 return content;
293 }
294
295 function confirmAction(action) {
Simon Hunt3f92c432016-01-12 17:34:23 -0800296 var itemId = $scope.selId,
Simon Hunt8d28a552016-01-11 14:01:02 -0800297 spar = $scope.sortParams;
298
299 function dOk() {
Simon Hunt3f92c432016-01-12 17:34:23 -0800300 $log.debug('Initiating', action, 'of', itemId);
Simon Hunt8d28a552016-01-11 14:01:02 -0800301 wss.sendEvent(appMgmtReq, {
302 action: action,
Simon Hunt3f92c432016-01-12 17:34:23 -0800303 name: itemId,
Simon Hunt8d28a552016-01-11 14:01:02 -0800304 sortCol: spar.sortCol,
305 sortDir: spar.sortDir
306 });
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800307 if (action == 'uninstall') {
308 detailsPanel.hide();
309 } else {
310 wss.sendEvent(detailsReq, {id: itemId});
311 }
Simon Hunt8d28a552016-01-11 14:01:02 -0800312 }
313
314 function dCancel() {
Simon Hunt3f92c432016-01-12 17:34:23 -0800315 $log.debug('Canceling', action, 'of', itemId);
Simon Hunt8d28a552016-01-11 14:01:02 -0800316 }
317
318 ds.openDialog(dialogId, dialogOpts)
319 .setTitle('Confirm Action')
Simon Hunt3f92c432016-01-12 17:34:23 -0800320 .addContent(createConfirmationText(action, itemId))
Simon Hunt5198f082016-02-04 13:41:17 -0800321 .addOk(dOk)
322 .addCancel(dCancel)
323 .bindKeys();
Simon Hunt8d28a552016-01-11 14:01:02 -0800324 }
325
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700326 $scope.appAction = function (action) {
327 if ($scope.ctrlBtnState.selection) {
Simon Hunt8d28a552016-01-11 14:01:02 -0800328 confirmAction(action);
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700329 }
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -0700330 };
Thomas Vachuska530e52a2015-05-06 19:51:32 -0700331
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700332 $scope.$on('FileChanged', function () {
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800333 var formData = new FormData(),
334 url;
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700335 if ($scope.appFile) {
336 formData.append('file', $scope.appFile);
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800337 url = fileUploadUrl + (activateImmediately || '');
338 $http.post(ufs.rsUrl(url), formData, {
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700339 transformRequest: angular.identity,
340 headers: {
341 'Content-Type': undefined
342 }
343 })
Bri Prebilic Colea7f81e52015-06-23 10:11:08 -0700344 .finally(function () {
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800345 activateImmediately = null;
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700346 $scope.sortCallback($scope.sortParams);
347 document.getElementById('inputFileForm').reset();
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800348 $timeout(function () { wss.sendEvent(detailsReq); }, 250);
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700349 });
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -0700350 }
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -0700351 });
352
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800353 $scope.appDropped = function() {
354 activateImmediately = activateOption;
355 $scope.$emit('FileChanged');
356 $scope.appFile = null;
357 };
358
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700359 $scope.$on('$destroy', function () {
360 ks.unbindKeys();
Jian Lia54de5a2016-01-20 23:10:39 -0800361 wss.unbindHandlers(handlers);
Bri Prebilic Cole9dcaea52015-07-21 14:39:48 -0700362 });
363
Thomas Vachuska619c5382015-04-02 13:41:47 -0700364 $log.log('OvAppCtrl has been created');
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700365 }])
366
367 // triggers the input form to appear when button is clicked
368 .directive('triggerForm', function () {
369 return {
370 restrict: 'A',
371 link: function (scope, elem) {
372 elem.bind('click', function () {
373 document.getElementById('uploadFile')
Bri Prebilic Cole6c82ade2015-08-05 11:12:30 -0700374 .dispatchEvent(new MouseEvent('click'));
Bri Prebilic Cole522e7562015-06-22 15:56:25 -0700375 });
376 }
377 };
378 })
379
380 // binds the model file to the scope in scope.appFile
381 // sends upload request to the server
382 .directive('fileModel', ['$parse',
383 function ($parse) {
384 return {
385 restrict: 'A',
386 link: function (scope, elem, attrs) {
387 var model = $parse(attrs.fileModel),
388 modelSetter = model.assign;
389
390 elem.bind('change', function () {
391 scope.$apply(function () {
392 modelSetter(scope, elem[0].files[0]);
393 });
394 scope.$emit('FileChanged');
395 });
396 }
397 };
Jian Lia54de5a2016-01-20 23:10:39 -0800398 }])
399
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800400 .directive("filedrop", function ($parse, $document) {
401 return {
402 restrict: "A",
403 link: function (scope, element, attrs) {
404 var onAppDrop = $parse(attrs.onFileDrop);
405
406 // When an item is dragged over the document
407 var onDragOver = function (e) {
Thomas Vachuskaebf3be02016-04-11 09:52:06 -0700408 d3.select('#frame').classed('dropping', true);
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800409 e.preventDefault();
410 };
411
412 // When the user leaves the window, cancels the drag or drops the item
413 var onDragEnd = function (e) {
Thomas Vachuskaebf3be02016-04-11 09:52:06 -0700414 d3.select('#frame').classed('dropping', false);
Thomas Vachuskaa42ce0b2016-03-09 09:02:49 -0800415 e.preventDefault();
416 };
417
418 // When a file is dropped
419 var loadFile = function (file) {
420 scope.appFile = file;
421 scope.$apply(onAppDrop(scope));
422 };
423
424 // Dragging begins on the document
425 $document.bind("dragover", onDragOver);
426
427 // Dragging ends on the overlay, which takes the whole window
428 element.bind("dragleave", onDragEnd)
429 .bind("drop", function (e) {
430 $log.info('Drag leave', e);
431 loadFile(e.dataTransfer.files[0]);
432 onDragEnd(e);
433 });
434 }
435 };
436 })
437
Jian Lia54de5a2016-01-20 23:10:39 -0800438 .directive('applicationDetailsPanel',
439 ['$rootScope', '$window', '$timeout', 'KeyService',
440 function ($rootScope, $window, $timeout, ks) {
441 return function (scope) {
442 var unbindWatch;
443
444 function heightCalc() {
445 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
446 + topPdg;
447 wSize = fs.windowSize(pStartY);
448 pHeight = wSize.height;
449 }
450
451 function initPanel() {
452 heightCalc();
453 createDetailsPane();
454 $log.debug('start to initialize panel!');
455 }
456
457 // Safari has a bug where it renders the fixed-layout table wrong
458 // if you ask for the window's size too early
459 if (scope.onos.browser === 'safari') {
460 $timeout(initPanel);
461 } else {
462 initPanel();
463 }
464 // create key bindings to handle panel
465 ks.keyBindings({
Simon Hunta477b602016-01-22 12:10:07 -0800466 esc: [closePanel, 'Close the details panel'],
Jian Lia54de5a2016-01-20 23:10:39 -0800467 _helpFormat: ['esc']
468 });
469 ks.gestureNotes([
470 ['click', 'Select a row to show application details'],
471 ['scroll down', 'See more application']
472 ]);
473
474 // if the panelData changes
475 scope.$watch('panelData', function () {
476 if (!fs.isEmptyObject(scope.panelData)) {
477 populateDetails(scope.panelData);
478 detailsPanel.show();
479 }
480 });
481
482 // if the window size changes
483 unbindWatch = $rootScope.$watchCollection(
484 function () {
485 return {
486 h: $window.innerHeight,
487 w: $window.innerWidth
488 };
489 }, function () {
490 if (!fs.isEmptyObject(scope.panelData)) {
491 heightCalc();
492 populateDetails(scope.panelData);
493 }
494 }
495 );
496
497 scope.$on('$destroy', function () {
498 unbindWatch();
499 ks.unbindKeys();
500 ps.destroyPanel(pName);
501 });
502 };
503 }]);
Thomas Vachuska0fa583c2015-03-30 23:07:41 -0700504}());