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