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', |
| 26 | 'annotations.protocol'], |
| 27 | colText: ['', 'URI', 'Vendor', 'Hardware Version', 'Software Version', |
| 28 | 'Serial Number', 'Protocol'] |
| 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" |
| 42 | } |
| 43 | }, |
| 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 | } |
| 69 | }] |
| 70 | }; |
| 71 | |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 72 | function setColWidth(t) { |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 73 | var tHeaders, tdElement, colWidth; |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 74 | |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 75 | tHeaders = t.selectAll('th'); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 76 | |
| 77 | // select each td in the first row and set the header's width to the |
| 78 | // corresponding td's width, if td is larger than header's width |
| 79 | tHeaders.each(function(thElement, index){ |
| 80 | thElement = d3.select(this); |
| 81 | |
| 82 | tdElement = t.select('td:nth-of-type(' + (index + 1) + ')'); |
| 83 | colWidth = tdElement.style('width'); |
| 84 | |
| 85 | thElement.style('width', colWidth); |
| 86 | tdElement.style('width', colWidth); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 87 | }); |
| 88 | } |
| 89 | |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 90 | function setCSS(thead, tbody, height) { |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 91 | thead.style('display', 'block'); |
| 92 | tbody.style({'display': 'block', |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 93 | 'height': height || '500px', |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 94 | 'overflow': 'auto' |
| 95 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 98 | function fixTable(t, th, tb, height) { |
| 99 | setColWidth(t); |
| 100 | setCSS(th, tb, height); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | angular.module('practiceTable', []) |
| 104 | |
| 105 | .directive('fixedHeader', ['$log', '$timeout', function ($log, $timeout) { |
| 106 | return { |
| 107 | restrict: 'A', |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 108 | scope: { |
| 109 | tableHeight: '@' |
| 110 | }, |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 111 | |
| 112 | link: function (scope, element, attrs) { |
| 113 | var table = d3.select(element[0]), |
| 114 | thead = table.select('thead'), |
| 115 | tbody = table.select('tbody'); |
| 116 | |
| 117 | // wait until the table is visible |
| 118 | scope.$watch( |
| 119 | function () { return (!(table.offsetParent === null)); }, |
| 120 | function (newValue, oldValue) { |
| 121 | if (newValue === true) { |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 122 | |
| 123 | // ensure thead and tbody have no display |
| 124 | thead.style('display', null); |
| 125 | tbody.style('display', null); |
| 126 | |
| 127 | $timeout(function() { |
Bri Prebilic Cole | e7399f3 | 2015-01-22 16:50:55 -0800 | [diff] [blame] | 128 | fixTable(table, thead, tbody, scope.tableHeight); |
Bri Prebilic Cole | d36a90f | 2015-01-22 16:19:27 -0800 | [diff] [blame] | 129 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 130 | } |
| 131 | }); |
Bri Prebilic Cole | 4f0d977 | 2015-01-21 16:45:14 -0800 | [diff] [blame] | 132 | } |
| 133 | }; |
| 134 | }]); |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 135 | }()); |