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