Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 1 | /* |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 2 | * Copyright 2015-2016 Open Networking Laboratory |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the 'License'); |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 11 | * distributed under the License is distributed on an 'AS IS' BASIS, |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 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 -- App View Module |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 24 | // injected refs |
| 25 | var $log, $scope, $loc, fs, ps, wss, is, ns, ks, is; |
| 26 | |
| 27 | // internal state |
| 28 | var detailsPanel, |
| 29 | pStartY, |
| 30 | pHeight, |
| 31 | top, |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 32 | middle, |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 33 | bottom, |
| 34 | iconDiv, |
| 35 | wSize = false; |
| 36 | |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 37 | // constants |
| 38 | var INSTALLED = 'INSTALLED', |
| 39 | ACTIVE = 'ACTIVE', |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 40 | appMgmtReq = 'appManagementRequest', |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 41 | topPdg = 50, |
| 42 | ctnrPdg = 24, |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 43 | tbWidth = 470, |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 44 | scrollSize = 17, |
| 45 | pName = 'application-details-panel', |
| 46 | detailsReq = 'appDetailsRequest', |
| 47 | detailsResp = 'appDetailsResponse', |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 48 | fileUploadUrl = 'applications/upload', |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 49 | iconUrlPrefix = 'rs/applications/', |
| 50 | iconUrlSuffix = '/icon', |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 51 | dialogId = 'app-dialog', |
| 52 | dialogOpts = { |
| 53 | edge: 'right' |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 54 | }, |
| 55 | strongWarning = { |
| 56 | 'org.onosproject.drivers': true |
| 57 | }, |
| 58 | discouragement = 'Deactivating or uninstalling this component can' + |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 59 | ' have serious negative consequences! Do so at your own risk!!', |
| 60 | propOrder = ['id', 'state', 'category', 'version', 'origin', 'role', 'url'], |
| 61 | friendlyProps = ['App ID', 'State', 'Category', 'Version', 'Origin', 'Role', 'URL']; |
| 62 | |
| 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 Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 86 | function addCloseBtn(div) { |
| 87 | is.loadEmbeddedIcon(div, 'plus', 30); |
| 88 | div.select('g').attr('transform', 'translate(25, 0) rotate(45)'); |
| 89 | div.on('click', closePanel); |
| 90 | } |
| 91 | |
| 92 | function setUpPanel() { |
| 93 | var container, closeBtn, tblDiv; |
| 94 | detailsPanel.empty(); |
| 95 | |
| 96 | container = detailsPanel.append('div').classed('container', true); |
| 97 | |
| 98 | top = container.append('div').classed('top', true); |
| 99 | closeBtn = top.append('div').classed('close-btn', true); |
| 100 | addCloseBtn(closeBtn); |
| 101 | iconDiv = top.append('div').classed('dev-icon', true); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 102 | |
| 103 | tblDiv = top.append('div').classed('top-tables', true); |
| 104 | tblDiv.append('div').classed('left', true).append('table'); |
| 105 | tblDiv.append('div').classed('right', true).append('table'); |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 106 | tblDiv.append('div').classed('description', true).append('table'); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 107 | |
| 108 | top.append('hr'); |
| 109 | |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 110 | middle = container.append('div').classed('middle', true); |
| 111 | tblDiv = middle.append('div').classed('middle-tables', true); |
| 112 | tblDiv.append('div').classed('readme', true).append('table'); |
| 113 | |
| 114 | middle.append('hr'); |
| 115 | |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 116 | bottom = container.append('div').classed('bottom', true); |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 117 | tblDiv = bottom.append('div').classed('bottom-tables', true).append('table'); |
| 118 | tblDiv.append('h2').html('Features'); |
| 119 | tblDiv.append('div').classed('features', true).append('table'); |
| 120 | tblDiv.append('h2').html('Required Apps'); |
| 121 | tblDiv.append('div').classed('required-apps', true).append('table'); |
| 122 | tblDiv.append('h2').html('Permissions'); |
| 123 | tblDiv.append('div').classed('permissions', true).append('table'); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | function addProp(tbody, index, value) { |
| 127 | var tr = tbody.append('tr'); |
| 128 | |
| 129 | function addCell(cls, txt) { |
| 130 | tr.append('td').attr('class', cls).html(txt); |
| 131 | } |
| 132 | addCell('label', friendlyProps[index] + ' :'); |
| 133 | addCell('value', value); |
| 134 | } |
| 135 | |
Simon Hunt | a477b60 | 2016-01-22 12:10:07 -0800 | [diff] [blame^] | 136 | function addUrl(tbody, index, value) { |
| 137 | var href = '<a href="' + value + '" target="_blank">' + value + '</a>'; |
| 138 | addProp(tbody, index, href); |
| 139 | } |
| 140 | |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 141 | function addIcon(tbody, value) { |
| 142 | var tr = tbody.append('tr'); |
| 143 | var td = tr.append('td'); |
| 144 | td.append('img').attr('src', iconUrlPrefix + value + iconUrlSuffix); |
| 145 | } |
| 146 | |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 147 | function addContent(tbody, value) { |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 148 | var tr = tbody.append('tr'); |
| 149 | tr.append('td').html(value); |
| 150 | } |
| 151 | |
| 152 | function populateTop(tblDiv, details) { |
| 153 | var leftTbl = tblDiv.select('.left') |
| 154 | .select('table') |
| 155 | .append('tbody'), |
| 156 | rightTbl = tblDiv.select('.right') |
| 157 | .select('table') |
| 158 | .append('tbody'), |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 159 | descriptionTbl = tblDiv.select('.description') |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 160 | .select('table') |
| 161 | .append('tbody'); |
| 162 | |
| 163 | top.select('h2').html(details.name); |
| 164 | |
| 165 | // place application icon to the left table |
| 166 | addIcon(leftTbl, details.id); |
| 167 | |
| 168 | // place rest of the fields to the right table |
| 169 | propOrder.forEach(function (prop, i) { |
Simon Hunt | a477b60 | 2016-01-22 12:10:07 -0800 | [diff] [blame^] | 170 | var fn = prop === 'url' ? addUrl : addProp; |
| 171 | fn(rightTbl, i, details[prop]); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 172 | }); |
| 173 | |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 174 | // place description field to the description table |
| 175 | addContent(descriptionTbl, details.desc); |
| 176 | } |
| 177 | |
| 178 | function populateMiddle(tblDiv, details) { |
| 179 | var readmeTbl = tblDiv.select('.readme') |
| 180 | .select('table') |
| 181 | .append('tbody'); |
| 182 | |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 183 | // place readme field to the readme table |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 184 | addContent(readmeTbl, details.readme); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | function populateName(div, name) { |
| 188 | var lab = div.select('.label'), |
| 189 | val = div.select('.value'); |
| 190 | lab.html('Friendly Name:'); |
| 191 | val.html(name); |
| 192 | } |
| 193 | |
| 194 | function populateDetails(details) { |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 195 | var nameDiv, topTbs, middleTbs, bottomTbs; |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 196 | setUpPanel(); |
| 197 | |
| 198 | nameDiv = top.select('.name-div'); |
| 199 | topTbs = top.select('.top-tables'); |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 200 | middleTbs = middle.select('.middle-tables'); |
| 201 | bottomTbs = bottom.select('.bottom-tables'); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 202 | |
| 203 | populateName(nameDiv, details.name); |
| 204 | populateTop(topTbs, details); |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 205 | populateMiddle(middleTbs, details); |
| 206 | populateBottom(bottomTbs, details); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 207 | |
| 208 | detailsPanel.height(pHeight); |
| 209 | } |
| 210 | |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 211 | function addItem(tbody, item) { |
| 212 | var tr = tbody.append('tr').attr('width', tbWidth + 'px'); |
| 213 | tr.append('td').attr('width', tbWidth + 'px') |
| 214 | .attr('style', 'text-align:left').html(item); |
| 215 | } |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 216 | |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 217 | function addItems(table, items) { |
| 218 | var tbody = table.append('tbody'); |
| 219 | items.forEach(function (item) { |
| 220 | addItem(tbody, item); |
| 221 | }); |
| 222 | } |
| 223 | |
| 224 | function populateBottom(tblDiv, details) { |
| 225 | var featuresTbl = tblDiv.select('.features') |
| 226 | .select('table'), |
| 227 | permissionsTbl = tblDiv.select('.permissions') |
| 228 | .select('table'), |
| 229 | requiredAppsTbl = tblDiv.select('.required-apps') |
| 230 | .select('table'); |
| 231 | |
| 232 | addItems(featuresTbl, details.features); |
| 233 | addItems(requiredAppsTbl, details._required_apps); |
| 234 | addItems(permissionsTbl, details.permissions); |
| 235 | |
| 236 | featuresTbl.style({ |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 237 | width: tbWidth + 'px', |
| 238 | overflow: 'auto', |
| 239 | display: 'block' |
| 240 | }); |
| 241 | |
Jian Li | da253e0 | 2016-01-21 17:46:17 -0800 | [diff] [blame] | 242 | detailsPanel.width(tbWidth + ctnrPdg); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | function respDetailsCb(data) { |
| 246 | $scope.panelData = data.details; |
| 247 | $scope.$apply(); |
| 248 | } |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 249 | |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 250 | angular.module('ovApp', []) |
| 251 | .controller('OvAppCtrl', |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 252 | ['$log', '$scope', '$http', |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 253 | 'FnService', 'TableBuilderService', 'PanelService', 'WebSocketService', |
| 254 | 'IconService', 'UrlFnService', 'KeyService', 'DialogService', |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 255 | |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 256 | function (_$log_, _$scope_, $http, _fs_, tbs, _ps_, _wss_, _is_, ufs, _ks_, ds) { |
| 257 | $log = _$log_; |
| 258 | $scope = _$scope_; |
| 259 | wss = _wss_; |
| 260 | ks = _ks_; |
| 261 | fs = _fs_; |
| 262 | ps = _ps_; |
| 263 | is = _is_; |
| 264 | $scope.panelData = {}; |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame] | 265 | $scope.ctrlBtnState = {}; |
Bri Prebilic Cole | 6c82ade | 2015-08-05 11:12:30 -0700 | [diff] [blame] | 266 | $scope.uploadTip = 'Upload an application (.oar file)'; |
Bri Prebilic Cole | eef67ae | 2015-07-01 16:26:59 -0700 | [diff] [blame] | 267 | $scope.activateTip = 'Activate selected application'; |
| 268 | $scope.deactivateTip = 'Deactivate selected application'; |
| 269 | $scope.uninstallTip = 'Uninstall selected application'; |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame] | 270 | |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 271 | var handlers = {}; |
| 272 | |
| 273 | // details panel handlers |
| 274 | handlers[detailsResp] = respDetailsCb; |
| 275 | wss.bindHandlers(handlers); |
| 276 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 277 | function selCb($event, row) { |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 278 | // $scope.selId is set by code in tableBuilder |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame] | 279 | $scope.ctrlBtnState.selection = !!$scope.selId; |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 280 | refreshCtrls(); |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 281 | ds.closeDialog(); // don't want dialog from previous selection |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 282 | |
| 283 | if ($scope.selId) { |
| 284 | wss.sendEvent(detailsReq, { id: row.id }); |
| 285 | } else { |
| 286 | $scope.hidePanel(); |
| 287 | } |
| 288 | $log.debug('Got a click on:', row); |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Bri Prebilic Cole | a7f81e5 | 2015-06-23 10:11:08 -0700 | [diff] [blame] | 291 | function refreshCtrls() { |
| 292 | var row, rowIdx; |
| 293 | if ($scope.ctrlBtnState.selection) { |
| 294 | rowIdx = fs.find($scope.selId, $scope.tableData); |
| 295 | row = rowIdx >= 0 ? $scope.tableData[rowIdx] : null; |
| 296 | |
| 297 | $scope.ctrlBtnState.installed = row && row.state === INSTALLED; |
| 298 | $scope.ctrlBtnState.active = row && row.state === ACTIVE; |
| 299 | } else { |
| 300 | $scope.ctrlBtnState.installed = false; |
| 301 | $scope.ctrlBtnState.active = false; |
| 302 | } |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 303 | } |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 304 | |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame] | 305 | tbs.buildTable({ |
| 306 | scope: $scope, |
| 307 | tag: 'app', |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 308 | selCb: selCb, |
Simon Hunt | a678b84 | 2016-01-11 17:14:18 -0800 | [diff] [blame] | 309 | respCb: refreshCtrls, |
| 310 | // pre-populate sort so active apps are at the top of the list |
| 311 | sortParams: { |
Simon Hunt | 051e9fa | 2016-01-19 15:54:22 -0800 | [diff] [blame] | 312 | firstCol: 'state', |
| 313 | firstDir: 'desc', |
| 314 | secondCol: 'id', |
| 315 | secondDir: 'asc' |
Simon Hunt | a678b84 | 2016-01-11 17:14:18 -0800 | [diff] [blame] | 316 | } |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame] | 317 | }); |
| 318 | |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 319 | // TODO: reexamine where keybindings should be - directive or controller? |
| 320 | ks.keyBindings({ |
| 321 | esc: [$scope.selectCallback, 'Deselect app'], |
| 322 | _helpFormat: ['esc'] |
| 323 | }); |
| 324 | ks.gestureNotes([ |
| 325 | ['click row', 'Select / deselect app'], |
| 326 | ['scroll down', 'See more apps'] |
| 327 | ]); |
| 328 | |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 329 | function createConfirmationText(action, itemId) { |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 330 | var content = ds.createDiv(); |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 331 | content.append('p').text(action + ' ' + itemId); |
| 332 | if (strongWarning[itemId]) { |
| 333 | content.append('p').text(discouragement).classed('strong', true); |
| 334 | } |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 335 | return content; |
| 336 | } |
| 337 | |
| 338 | function confirmAction(action) { |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 339 | var itemId = $scope.selId, |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 340 | spar = $scope.sortParams; |
| 341 | |
| 342 | function dOk() { |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 343 | $log.debug('Initiating', action, 'of', itemId); |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 344 | wss.sendEvent(appMgmtReq, { |
| 345 | action: action, |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 346 | name: itemId, |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 347 | sortCol: spar.sortCol, |
| 348 | sortDir: spar.sortDir |
| 349 | }); |
| 350 | } |
| 351 | |
| 352 | function dCancel() { |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 353 | $log.debug('Canceling', action, 'of', itemId); |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | ds.openDialog(dialogId, dialogOpts) |
| 357 | .setTitle('Confirm Action') |
Simon Hunt | 3f92c43 | 2016-01-12 17:34:23 -0800 | [diff] [blame] | 358 | .addContent(createConfirmationText(action, itemId)) |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 359 | .addButton('OK', dOk) |
| 360 | .addButton('Cancel', dCancel); |
| 361 | } |
| 362 | |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 363 | $scope.appAction = function (action) { |
| 364 | if ($scope.ctrlBtnState.selection) { |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 365 | confirmAction(action); |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 366 | } |
Bri Prebilic Cole | bd0bc77 | 2015-05-13 13:02:26 -0700 | [diff] [blame] | 367 | }; |
Thomas Vachuska | 530e52a | 2015-05-06 19:51:32 -0700 | [diff] [blame] | 368 | |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 369 | $scope.$on('FileChanged', function () { |
| 370 | var formData = new FormData(); |
| 371 | if ($scope.appFile) { |
| 372 | formData.append('file', $scope.appFile); |
Simon Hunt | 8d28a55 | 2016-01-11 14:01:02 -0800 | [diff] [blame] | 373 | $http.post(ufs.rsUrl(fileUploadUrl), formData, { |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 374 | transformRequest: angular.identity, |
| 375 | headers: { |
| 376 | 'Content-Type': undefined |
| 377 | } |
| 378 | }) |
Bri Prebilic Cole | a7f81e5 | 2015-06-23 10:11:08 -0700 | [diff] [blame] | 379 | .finally(function () { |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 380 | $scope.sortCallback($scope.sortParams); |
| 381 | document.getElementById('inputFileForm').reset(); |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 382 | }); |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 383 | } |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 384 | }); |
| 385 | |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 386 | $scope.$on('$destroy', function () { |
| 387 | ks.unbindKeys(); |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 388 | wss.unbindHandlers(handlers); |
Bri Prebilic Cole | 9dcaea5 | 2015-07-21 14:39:48 -0700 | [diff] [blame] | 389 | }); |
| 390 | |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 391 | $log.log('OvAppCtrl has been created'); |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 392 | }]) |
| 393 | |
| 394 | // triggers the input form to appear when button is clicked |
| 395 | .directive('triggerForm', function () { |
| 396 | return { |
| 397 | restrict: 'A', |
| 398 | link: function (scope, elem) { |
| 399 | elem.bind('click', function () { |
| 400 | document.getElementById('uploadFile') |
Bri Prebilic Cole | 6c82ade | 2015-08-05 11:12:30 -0700 | [diff] [blame] | 401 | .dispatchEvent(new MouseEvent('click')); |
Bri Prebilic Cole | 522e756 | 2015-06-22 15:56:25 -0700 | [diff] [blame] | 402 | }); |
| 403 | } |
| 404 | }; |
| 405 | }) |
| 406 | |
| 407 | // binds the model file to the scope in scope.appFile |
| 408 | // sends upload request to the server |
| 409 | .directive('fileModel', ['$parse', |
| 410 | function ($parse) { |
| 411 | return { |
| 412 | restrict: 'A', |
| 413 | link: function (scope, elem, attrs) { |
| 414 | var model = $parse(attrs.fileModel), |
| 415 | modelSetter = model.assign; |
| 416 | |
| 417 | elem.bind('change', function () { |
| 418 | scope.$apply(function () { |
| 419 | modelSetter(scope, elem[0].files[0]); |
| 420 | }); |
| 421 | scope.$emit('FileChanged'); |
| 422 | }); |
| 423 | } |
| 424 | }; |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 425 | }]) |
| 426 | |
| 427 | .directive('applicationDetailsPanel', |
| 428 | ['$rootScope', '$window', '$timeout', 'KeyService', |
| 429 | function ($rootScope, $window, $timeout, ks) { |
| 430 | return function (scope) { |
| 431 | var unbindWatch; |
| 432 | |
| 433 | function heightCalc() { |
| 434 | pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height') |
| 435 | + topPdg; |
| 436 | wSize = fs.windowSize(pStartY); |
| 437 | pHeight = wSize.height; |
| 438 | } |
| 439 | |
| 440 | function initPanel() { |
| 441 | heightCalc(); |
| 442 | createDetailsPane(); |
| 443 | $log.debug('start to initialize panel!'); |
| 444 | } |
| 445 | |
| 446 | // Safari has a bug where it renders the fixed-layout table wrong |
| 447 | // if you ask for the window's size too early |
| 448 | if (scope.onos.browser === 'safari') { |
| 449 | $timeout(initPanel); |
| 450 | } else { |
| 451 | initPanel(); |
| 452 | } |
| 453 | // create key bindings to handle panel |
| 454 | ks.keyBindings({ |
Simon Hunt | a477b60 | 2016-01-22 12:10:07 -0800 | [diff] [blame^] | 455 | esc: [closePanel, 'Close the details panel'], |
Jian Li | a54de5a | 2016-01-20 23:10:39 -0800 | [diff] [blame] | 456 | _helpFormat: ['esc'] |
| 457 | }); |
| 458 | ks.gestureNotes([ |
| 459 | ['click', 'Select a row to show application details'], |
| 460 | ['scroll down', 'See more application'] |
| 461 | ]); |
| 462 | |
| 463 | // if the panelData changes |
| 464 | scope.$watch('panelData', function () { |
| 465 | if (!fs.isEmptyObject(scope.panelData)) { |
| 466 | populateDetails(scope.panelData); |
| 467 | detailsPanel.show(); |
| 468 | } |
| 469 | }); |
| 470 | |
| 471 | // if the window size changes |
| 472 | unbindWatch = $rootScope.$watchCollection( |
| 473 | function () { |
| 474 | return { |
| 475 | h: $window.innerHeight, |
| 476 | w: $window.innerWidth |
| 477 | }; |
| 478 | }, function () { |
| 479 | if (!fs.isEmptyObject(scope.panelData)) { |
| 480 | heightCalc(); |
| 481 | populateDetails(scope.panelData); |
| 482 | } |
| 483 | } |
| 484 | ); |
| 485 | |
| 486 | scope.$on('$destroy', function () { |
| 487 | unbindWatch(); |
| 488 | ks.unbindKeys(); |
| 489 | ps.destroyPanel(pName); |
| 490 | }); |
| 491 | }; |
| 492 | }]); |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 493 | }()); |