Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 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 |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 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 | /* |
Bri Prebilic Cole | aa0f088 | 2015-02-04 15:27:55 -0800 | [diff] [blame] | 18 | ONOS GUI -- Device View Module |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 24 | // injected refs |
| 25 | var $log, $scope, fs, mast, ps, wss, is; |
| 26 | |
| 27 | // internal state |
| 28 | var self, |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 29 | detailsPanel, |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 30 | pStartY, pHeight, |
| 31 | top, bottom, iconDiv, |
| 32 | wSize, selRow; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 33 | |
| 34 | // constants |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 35 | var topPdg = 13, |
| 36 | ctnrPdg = 24, |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 37 | scrollSize = 17, |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 38 | portsTblPdg = 50, |
| 39 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 40 | pName = 'device-details-panel', |
| 41 | detailsReq = 'deviceDetailsRequest', |
| 42 | detailsResp = 'deviceDetailsResponse', |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 43 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 44 | propOrder = [ |
| 45 | 'type', 'masterid', 'chassisid', |
| 46 | 'mfr', 'hw', 'sw', 'protocol', 'serial' |
| 47 | ], |
| 48 | friendlyProps = [ |
| 49 | 'Type', 'Master ID', 'Chassis ID', |
| 50 | 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #' |
| 51 | ], |
| 52 | portCols = [ |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 53 | 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name' |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 54 | ], |
| 55 | friendlyPortCols = [ |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 56 | 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name' |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 57 | ]; |
| 58 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 59 | function addCloseBtn(div) { |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 60 | is.loadEmbeddedIcon(div, 'plus', 30); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 61 | div.select('g').attr('transform', 'translate(25, 0) rotate(45)'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 62 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 63 | div.on('click', function () { |
| 64 | detailsPanel.hide(); |
| 65 | selRow.removeClass('selected'); |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | function setUpPanel() { |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 70 | var container, closeBtn; |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 71 | detailsPanel.empty(); |
| 72 | |
| 73 | container = detailsPanel.append('div').classed('container', true); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 74 | |
| 75 | top = container.append('div').classed('top', true); |
| 76 | closeBtn = top.append('div').classed('close-btn', true); |
| 77 | addCloseBtn(closeBtn); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 78 | iconDiv = top.append('div').classed('dev-icon', true); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 79 | top.append('h2'); |
| 80 | top.append('table'); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 81 | top.append('hr'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 82 | |
| 83 | bottom = container.append('div').classed('bottom', true); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 84 | bottom.append('h2').classed('ports-title', true).html('Ports'); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 85 | bottom.append('table'); |
| 86 | } |
| 87 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 88 | function addProp(tbody, index, value) { |
| 89 | var tr = tbody.append('tr'); |
| 90 | |
| 91 | function addCell(cls, txt) { |
| 92 | tr.append('td').attr('class', cls).html(txt); |
| 93 | } |
| 94 | addCell('label', friendlyProps[index] + ' :'); |
| 95 | addCell('value', value); |
| 96 | } |
| 97 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 98 | function populateTop(tbody, details) { |
| 99 | is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 100 | top.select('h2').html(details.id); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 101 | |
| 102 | propOrder.forEach(function (prop, i) { |
| 103 | addProp(tbody, i, details[prop]); |
| 104 | }); |
| 105 | } |
| 106 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 107 | function addPortRow(tbody, port) { |
| 108 | var tr = tbody.append('tr'); |
| 109 | |
| 110 | portCols.forEach(function (col) { |
| 111 | if (col === 'type' || col === 'id') { |
| 112 | port[col] = fs.cap(port[col]); |
| 113 | } |
| 114 | tr.append('td').html(port[col]); |
| 115 | }); |
| 116 | } |
| 117 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 118 | function populateBottom(table, ports) { |
| 119 | var theader = table.append('thead').append('tr'), |
| 120 | tbody = table.append('tbody'), |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 121 | tbWidth, tbHeight; |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 122 | |
| 123 | friendlyPortCols.forEach(function (col) { |
| 124 | theader.append('th').html(col); |
| 125 | }); |
| 126 | ports.forEach(function (port) { |
| 127 | addPortRow(tbody, port); |
| 128 | }); |
| 129 | |
| 130 | tbWidth = fs.noPxStyle(tbody, 'width') + scrollSize; |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 131 | tbHeight = pHeight |
| 132 | - (fs.noPxStyle(detailsPanel.el() |
| 133 | .select('.top'), 'height') |
| 134 | + fs.noPxStyle(detailsPanel.el() |
| 135 | .select('.ports-title'), 'height') |
| 136 | + portsTblPdg); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 137 | |
| 138 | table.style({ |
| 139 | height: tbHeight + 'px', |
| 140 | width: tbWidth + 'px', |
| 141 | overflow: 'auto', |
| 142 | display: 'block' |
| 143 | }); |
| 144 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 145 | detailsPanel.width(tbWidth + ctnrPdg); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 148 | function populateDetails(details) { |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 149 | var topTb, btmTbl, ports; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 150 | setUpPanel(); |
| 151 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 152 | topTb = top.select('table').append('tbody'); |
| 153 | btmTbl = bottom.select('table'); |
| 154 | ports = details.ports; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 155 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 156 | populateTop(topTb, details); |
| 157 | populateBottom(btmTbl, ports); |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 158 | |
| 159 | detailsPanel.height(pHeight); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | function respDetailsCb(data) { |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 163 | self.panelData = data.details; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 164 | populateDetails(self.panelData); |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 165 | detailsPanel.show(); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 168 | function createDetailsPane() { |
| 169 | detailsPanel = ps.createPanel(pName, { |
| 170 | width: wSize.width, |
| 171 | margin: 0, |
| 172 | hideMargin: 0 |
| 173 | }); |
| 174 | detailsPanel.el().style({ |
| 175 | position: 'absolute', |
| 176 | top: pStartY + 'px' |
| 177 | }); |
| 178 | detailsPanel.hide(); |
| 179 | } |
| 180 | |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 181 | angular.module('ovDevice', []) |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 182 | .controller('OvDeviceCtrl', |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 183 | ['$log', '$scope', 'TableBuilderService', 'FnService', |
| 184 | 'MastService', 'PanelService', 'WebSocketService', 'IconService', |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 185 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 186 | function (_$log_, _$scope_, tbs, _fs_, _mast_, _ps_, _wss_, _is_) { |
| 187 | $log = _$log_; |
| 188 | $scope = _$scope_; |
| 189 | fs = _fs_; |
| 190 | mast = _mast_; |
| 191 | ps = _ps_; |
| 192 | wss = _wss_; |
| 193 | is = _is_; |
| 194 | self = this; |
| 195 | var handlers = {}; |
| 196 | self.panelData = []; |
Bri Prebilic Cole | 4506938 | 2015-04-14 15:21:38 -0700 | [diff] [blame] | 197 | pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height') |
| 198 | + mast.mastHeight() + topPdg; |
| 199 | wSize = fs.windowSize(pStartY); |
| 200 | pHeight = wSize.height; |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 201 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 202 | function selCb($event, row) { |
| 203 | selRow = angular.element($event.currentTarget); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 204 | if ($scope.sel) { |
| 205 | wss.sendEvent(detailsReq, { id: row.id }); |
| 206 | } else { |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 207 | detailsPanel.hide(); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 208 | } |
| 209 | $log.debug('Got a click on:', row); |
| 210 | } |
| 211 | |
Bri Prebilic Cole | 864cdd6 | 2015-04-02 15:46:47 -0700 | [diff] [blame] | 212 | tbs.buildTable({ |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 213 | self: self, |
Bri Prebilic Cole | 864cdd6 | 2015-04-02 15:46:47 -0700 | [diff] [blame] | 214 | scope: $scope, |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 215 | tag: 'device', |
| 216 | selCb: selCb |
| 217 | }); |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 218 | createDetailsPane(); |
| 219 | |
Bri Prebilic Cole | 0feedc0 | 2015-04-09 14:17:37 -0700 | [diff] [blame] | 220 | handlers[detailsResp] = respDetailsCb; |
| 221 | wss.bindHandlers(handlers); |
| 222 | |
| 223 | $scope.$on('$destroy', function () { |
| 224 | ps.destroyPanel(pName); |
| 225 | wss.unbindHandlers(handlers); |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 226 | }); |
| 227 | |
Bri Prebilic Cole | 72eb6db | 2015-03-30 16:58:53 -0700 | [diff] [blame] | 228 | $log.log('OvDeviceCtrl has been created'); |
Bri Prebilic Cole | 7c92a3d | 2015-01-09 16:50:03 -0800 | [diff] [blame] | 229 | }]); |
| 230 | }()); |