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