Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -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 | /* |
| 18 | ONOS GUI -- Showing Icons Test Module |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 24 | var config = { |
| 25 | colIds: ['_iconid_available', 'id', 'mfr', 'hw', 'sw', 'serial', |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 26 | 'annotations'], |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame] | 27 | colText: ['Availability', 'URI', 'Vendor', 'Hardware Version', |
| 28 | 'Software Version', 'Serial Number', 'Protocol'] |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 29 | }, |
| 30 | deviceData = { |
| 31 | "devices": [{ |
| 32 | "id": "of:0000000000000001", |
| 33 | "available": true, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 34 | "_iconid_available": "active", |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 35 | "role": "MASTER", |
| 36 | "mfr": "Nicira, Inc.", |
| 37 | "hw": "Open vSwitch", |
| 38 | "sw": "2.0.1", |
| 39 | "serial": "None", |
| 40 | "annotations": { |
| 41 | "protocol": "OF_10" |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 42 | } |
| 43 | }, |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 44 | { |
| 45 | "id": "of:0000000000000004", |
| 46 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 47 | "_iconid_available": "inactive", |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 48 | "role": "MASTER", |
| 49 | "mfr": "Nicira, Inc.", |
| 50 | "hw": "Open vSwitch", |
| 51 | "sw": "2.0.1", |
| 52 | "serial": "None", |
| 53 | "annotations": { |
| 54 | "protocol": "OF_10" |
| 55 | } |
| 56 | }, |
| 57 | { |
| 58 | "id": "of:0000000000000092", |
| 59 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 60 | "_iconid_available": "inactive", |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 61 | "role": "MASTER", |
| 62 | "mfr": "Nicira, Inc.", |
| 63 | "hw": "Open vSwitch", |
| 64 | "sw": "2.0.1", |
| 65 | "serial": "None", |
| 66 | "annotations": { |
| 67 | "protocol": "OF_10" |
| 68 | } |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 69 | }, |
| 70 | { |
| 71 | "id": "of:0000000000000092", |
| 72 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 73 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 74 | "role": "MASTER", |
| 75 | "mfr": "Nicira, Inc.", |
| 76 | "hw": "Open vSwitch", |
| 77 | "sw": "2.0.1", |
| 78 | "serial": "None", |
| 79 | "annotations": { |
| 80 | "protocol": "OF_10" |
| 81 | } |
| 82 | }, |
| 83 | { |
| 84 | "id": "of:0000000000000092", |
| 85 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 86 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 87 | "role": "MASTER", |
| 88 | "mfr": "Nicira, Inc.", |
| 89 | "hw": "Open vSwitch", |
| 90 | "sw": "2.0.1", |
| 91 | "serial": "None", |
| 92 | "annotations": { |
| 93 | "protocol": "OF_10" |
| 94 | } |
| 95 | }, |
| 96 | { |
| 97 | "id": "of:0000000000000092", |
| 98 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 99 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 100 | "role": "MASTER", |
| 101 | "mfr": "Nicira, Inc.", |
| 102 | "hw": "Open vSwitch", |
| 103 | "sw": "2.0.1", |
| 104 | "serial": "None", |
| 105 | "annotations": { |
| 106 | "protocol": "OF_10" |
| 107 | } |
| 108 | }, |
| 109 | { |
| 110 | "id": "of:0000000000000092", |
| 111 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 112 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 113 | "role": "MASTER", |
| 114 | "mfr": "Nicira, Inc.", |
| 115 | "hw": "Open vSwitch", |
| 116 | "sw": "2.0.1", |
| 117 | "serial": "None", |
| 118 | "annotations": { |
| 119 | "protocol": "OF_10" |
| 120 | } |
| 121 | }, |
| 122 | { |
| 123 | "id": "of:0000000000000092", |
| 124 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 125 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 126 | "role": "MASTER", |
| 127 | "mfr": "Nicira, Inc.", |
| 128 | "hw": "Open vSwitch", |
| 129 | "sw": "2.0.1", |
| 130 | "serial": "None", |
| 131 | "annotations": { |
| 132 | "protocol": "OF_10" |
| 133 | } |
| 134 | }, |
| 135 | { |
| 136 | "id": "of:0000000000000092", |
| 137 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 138 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 139 | "role": "MASTER", |
| 140 | "mfr": "Nicira, Inc.", |
| 141 | "hw": "Open vSwitch", |
| 142 | "sw": "2.0.1", |
| 143 | "serial": "None", |
| 144 | "annotations": { |
| 145 | "protocol": "OF_10" |
| 146 | } |
| 147 | }, |
| 148 | { |
| 149 | "id": "of:0000000000000092", |
| 150 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 151 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 152 | "role": "MASTER", |
| 153 | "mfr": "Nicira, Inc.", |
| 154 | "hw": "Open vSwitch", |
| 155 | "sw": "2.0.1", |
| 156 | "serial": "None", |
| 157 | "annotations": { |
| 158 | "protocol": "OF_10" |
| 159 | } |
| 160 | }, |
| 161 | { |
| 162 | "id": "of:0000000000000092", |
| 163 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 164 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 165 | "role": "MASTER", |
| 166 | "mfr": "Nicira, Inc.", |
| 167 | "hw": "Open vSwitch", |
| 168 | "sw": "2.0.1", |
| 169 | "serial": "None", |
| 170 | "annotations": { |
| 171 | "protocol": "OF_10" |
| 172 | } |
| 173 | }, |
| 174 | { |
| 175 | "id": "of:0000000000000092", |
| 176 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 177 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 178 | "role": "MASTER", |
| 179 | "mfr": "Nicira, Inc.", |
| 180 | "hw": "Open vSwitch", |
| 181 | "sw": "2.0.1", |
| 182 | "serial": "None", |
| 183 | "annotations": { |
| 184 | "protocol": "OF_10" |
| 185 | } |
| 186 | }, |
| 187 | { |
| 188 | "id": "of:0000000000000092", |
| 189 | "available": false, |
Bri Prebilic Cole | ab582b8 | 2015-04-14 15:08:22 -0700 | [diff] [blame] | 190 | "_iconid_available": "inactive", |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 191 | "role": "MASTER", |
| 192 | "mfr": "Nicira, Inc.", |
| 193 | "hw": "Open vSwitch", |
| 194 | "sw": "2.0.1", |
| 195 | "serial": "None", |
| 196 | "annotations": { |
| 197 | "protocol": "OF_10" |
| 198 | } |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 199 | }] |
| 200 | }; |
| 201 | |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 202 | function setColWidth(t) { |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 203 | var tHeaders, tdElement, colWidth; |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 204 | |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 205 | tHeaders = t.selectAll('th'); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 206 | |
| 207 | // select each td in the first row and set the header's width to the |
| 208 | // corresponding td's width, if td is larger than header's width |
| 209 | tHeaders.each(function(thElement, index){ |
| 210 | thElement = d3.select(this); |
| 211 | |
| 212 | tdElement = t.select('td:nth-of-type(' + (index + 1) + ')'); |
| 213 | colWidth = tdElement.style('width'); |
| 214 | |
| 215 | thElement.style('width', colWidth); |
| 216 | tdElement.style('width', colWidth); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 217 | }); |
| 218 | } |
| 219 | |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 220 | function setCSS(thead, tbody, height) { |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 221 | thead.style('display', 'block'); |
| 222 | tbody.style({'display': 'block', |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 223 | 'height': height || '100px', |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 224 | 'overflow': 'auto' |
| 225 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 228 | function fixTable(t, th, tb, height) { |
| 229 | setColWidth(t); |
| 230 | setCSS(th, tb, height); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 233 | angular.module('practiceTable', ['onosWidget']) |
| 234 | |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame] | 235 | .controller('showTableCtrl', ['$log', '$scope', '$rootScope', |
| 236 | '$timeout', 'TableService', |
| 237 | function ($log, $scope, $rootScope, $timeout, ts) { |
Bri Prebilic Cole | 9ca0f9c | 2015-01-29 15:44:20 -0800 | [diff] [blame] | 238 | var self = this; |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame] | 239 | var table = ts.renderTable(d3.select('#tableDiv'), config, deviceData); |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 240 | }]) |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 241 | |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame] | 242 | .directive('fixedHeader', ['$log', '$timeout', '$compile', |
| 243 | function ($log, $timeout, $compile) { |
| 244 | return { |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 245 | restrict: 'A', |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 246 | scope: { |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame] | 247 | tHeight: '@' |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 248 | }, |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 249 | |
| 250 | link: function (scope, element, attrs) { |
| 251 | var table = d3.select(element[0]), |
| 252 | thead = table.select('thead'), |
| 253 | tbody = table.select('tbody'); |
| 254 | |
| 255 | // wait until the table is visible |
| 256 | scope.$watch( |
| 257 | function () { return (!(table.offsetParent === null)); }, |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame] | 258 | function(newValue, oldValue) { |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 259 | if (newValue === true) { |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 260 | |
| 261 | // ensure thead and tbody have no display |
| 262 | thead.style('display', null); |
| 263 | tbody.style('display', null); |
| 264 | |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame] | 265 | $timeout(function () { |
| 266 | fixTable(table, thead, tbody, scope.tHeight); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 267 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 268 | } |
| 269 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 270 | } |
| 271 | }; |
| 272 | }]); |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 273 | }()); |