blob: b2b892cef54a7e792455e72fa358580bfb68b2e9 [file] [log] [blame]
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -08001/*
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 Coleaa8d2ed2015-01-23 16:53:29 -080024 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 Colee7399f32015-01-22 16:50:55 -080072 function setColWidth(t) {
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080073 var tHeaders, tdElement, colWidth;
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080074
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080075 tHeaders = t.selectAll('th');
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080076
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 Cole4f0d9772015-01-21 16:45:14 -080087 });
88 }
89
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080090 function setCSS(thead, tbody, height) {
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080091 thead.style('display', 'block');
92 tbody.style({'display': 'block',
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080093 'height': height || '500px',
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -080094 'overflow': 'auto'
95 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -080096 }
97
Bri Prebilic Colee7399f32015-01-22 16:50:55 -080098 function fixTable(t, th, tb, height) {
99 setColWidth(t);
100 setCSS(th, tb, height);
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800101 }
102
103 angular.module('practiceTable', [])
104
105 .directive('fixedHeader', ['$log', '$timeout', function ($log, $timeout) {
106 return {
107 restrict: 'A',
Bri Prebilic Colee7399f32015-01-22 16:50:55 -0800108 scope: {
109 tableHeight: '@'
110 },
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800111
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 Cole4f0d9772015-01-21 16:45:14 -0800122
123 // ensure thead and tbody have no display
124 thead.style('display', null);
125 tbody.style('display', null);
126
127 $timeout(function() {
Bri Prebilic Colee7399f32015-01-22 16:50:55 -0800128 fixTable(table, thead, tbody, scope.tableHeight);
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -0800129 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800130 }
131 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800132 }
133 };
134 }]);
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -0800135}());