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, |
| 34 | "_iconid_available": "deviceOnline", |
| 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, |
| 47 | "_iconid_available": "deviceOffline", |
| 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, |
| 60 | "_iconid_available": "deviceOffline", |
| 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, |
| 73 | "_iconid_available": "deviceOffline", |
| 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, |
| 86 | "_iconid_available": "deviceOffline", |
| 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, |
| 99 | "_iconid_available": "deviceOffline", |
| 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, |
| 112 | "_iconid_available": "deviceOffline", |
| 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, |
| 125 | "_iconid_available": "deviceOffline", |
| 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, |
| 138 | "_iconid_available": "deviceOffline", |
| 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, |
| 151 | "_iconid_available": "deviceOffline", |
| 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, |
| 164 | "_iconid_available": "deviceOffline", |
| 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, |
| 177 | "_iconid_available": "deviceOffline", |
| 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, |
| 190 | "_iconid_available": "deviceOffline", |
| 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) { |
| 238 | var table = ts.renderTable(d3.select('#tableDiv'), config, deviceData); |
| 239 | |
| 240 | // --- commented out code below were various attempts at $apply --- |
| 241 | // will delete unneeded dependencies once we have figured out which ones we need |
| 242 | |
| 243 | //$timeout(function () { |
| 244 | // $log.log('inside timeout'); |
| 245 | // //$scope.$watch('table', function (newVal, oldVal) { |
| 246 | // $scope.$apply(); |
| 247 | // //}); |
| 248 | // }, 1000); |
| 249 | |
| 250 | //$scope.$applyAsync(); |
| 251 | |
| 252 | //$scope.$apply(function () { |
| 253 | // ts.renderTable(d3.select('#tableDiv'), config, deviceData); |
| 254 | //}); |
| 255 | |
| 256 | //$log.log($scope); |
| 257 | |
| 258 | //$scope.$watch('table', function(newVal, oldVal) { |
| 259 | // //if (newVal === oldVal) { $log.log('hello'); return; } |
| 260 | // $scope.$apply(); |
| 261 | //}); |
| 262 | // |
| 263 | //$timeout(function () { |
| 264 | // $log.log("in timeout in controller"); |
| 265 | // $rootScope.$watch(function () { |
| 266 | // return (table); |
| 267 | // }, |
| 268 | // function(newValue, oldValue) { |
| 269 | // if(newValue) { |
| 270 | // $log.log('hello??'); |
| 271 | // //$rootScope.$apply(); |
| 272 | // } |
| 273 | // } |
| 274 | // ); |
| 275 | // //$scope.$apply(table); |
| 276 | // $log.log("after scope.apply")}); |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 277 | }]) |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 278 | |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame^] | 279 | .directive('fixedHeader', ['$log', '$timeout', '$compile', |
| 280 | function ($log, $timeout, $compile) { |
| 281 | return { |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 282 | restrict: 'A', |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 283 | scope: { |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame^] | 284 | tHeight: '@' |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 285 | }, |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 286 | |
| 287 | link: function (scope, element, attrs) { |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame^] | 288 | $log.log("in directive"); |
| 289 | |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 290 | var table = d3.select(element[0]), |
| 291 | thead = table.select('thead'), |
| 292 | tbody = table.select('tbody'); |
| 293 | |
| 294 | // wait until the table is visible |
| 295 | scope.$watch( |
| 296 | function () { return (!(table.offsetParent === null)); }, |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame^] | 297 | function(newValue, oldValue) { |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 298 | if (newValue === true) { |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 299 | |
| 300 | // ensure thead and tbody have no display |
| 301 | thead.style('display', null); |
| 302 | tbody.style('display', null); |
| 303 | |
Bri Prebilic Cole | 1598301 | 2015-01-28 15:17:18 -0800 | [diff] [blame^] | 304 | $timeout(function () { |
| 305 | fixTable(table, thead, tbody, scope.tHeight); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 306 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 307 | } |
| 308 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 309 | } |
| 310 | }; |
| 311 | }]); |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 312 | }()); |