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