blob: f244c866debb62ebcbb844b1ef07beb45f54af2f [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',
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -080026 'annotations'],
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080027 colText: ['Availability', 'URI', 'Vendor', 'Hardware Version',
28 'Software Version', 'Serial Number', 'Protocol']
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080029 },
30 deviceData = {
31 "devices": [{
32 "id": "of:0000000000000001",
33 "available": true,
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070034 "_iconid_available": "active",
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080035 "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 Cole5c2cab92015-01-23 16:53:29 -080042 }
43 },
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080044 {
45 "id": "of:0000000000000004",
46 "available": false,
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070047 "_iconid_available": "inactive",
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080048 "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 Coleab582b82015-04-14 15:08:22 -070060 "_iconid_available": "inactive",
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080061 "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 Cole5c2cab92015-01-23 16:53:29 -080069 },
70 {
71 "id": "of:0000000000000092",
72 "available": false,
Bri Prebilic Coleab582b82015-04-14 15:08:22 -070073 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -080074 "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 Coleab582b82015-04-14 15:08:22 -070086 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -080087 "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 Coleab582b82015-04-14 15:08:22 -070099 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800100 "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 Coleab582b82015-04-14 15:08:22 -0700112 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800113 "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 Coleab582b82015-04-14 15:08:22 -0700125 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800126 "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 Coleab582b82015-04-14 15:08:22 -0700138 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800139 "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 Coleab582b82015-04-14 15:08:22 -0700151 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800152 "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 Coleab582b82015-04-14 15:08:22 -0700164 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800165 "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 Coleab582b82015-04-14 15:08:22 -0700177 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800178 "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 Coleab582b82015-04-14 15:08:22 -0700190 "_iconid_available": "inactive",
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800191 "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 Coleaa8d2ed2015-01-23 16:53:29 -0800199 }]
200 };
201
Bri Prebilic Colee7399f32015-01-22 16:50:55 -0800202 function setColWidth(t) {
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -0800203 var tHeaders, tdElement, colWidth;
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800204
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800205 tHeaders = t.selectAll('th');
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -0800206
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 Cole4f0d9772015-01-21 16:45:14 -0800217 });
218 }
219
Bri Prebilic Colee7399f32015-01-22 16:50:55 -0800220 function setCSS(thead, tbody, height) {
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -0800221 thead.style('display', 'block');
222 tbody.style({'display': 'block',
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800223 'height': height || '100px',
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -0800224 'overflow': 'auto'
225 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800226 }
227
Bri Prebilic Colee7399f32015-01-22 16:50:55 -0800228 function fixTable(t, th, tb, height) {
229 setColWidth(t);
230 setCSS(th, tb, height);
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800231 }
232
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800233 angular.module('practiceTable', ['onosWidget'])
234
Bri Prebilic Cole15983012015-01-28 15:17:18 -0800235 .controller('showTableCtrl', ['$log', '$scope', '$rootScope',
236 '$timeout', 'TableService',
237 function ($log, $scope, $rootScope, $timeout, ts) {
Bri Prebilic Cole9ca0f9c2015-01-29 15:44:20 -0800238 var self = this;
Bri Prebilic Cole15983012015-01-28 15:17:18 -0800239 var table = ts.renderTable(d3.select('#tableDiv'), config, deviceData);
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -0800240 }])
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800241
Bri Prebilic Cole15983012015-01-28 15:17:18 -0800242 .directive('fixedHeader', ['$log', '$timeout', '$compile',
243 function ($log, $timeout, $compile) {
244 return {
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800245 restrict: 'A',
Bri Prebilic Colee7399f32015-01-22 16:50:55 -0800246 scope: {
Bri Prebilic Cole15983012015-01-28 15:17:18 -0800247 tHeight: '@'
Bri Prebilic Colee7399f32015-01-22 16:50:55 -0800248 },
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800249
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 Cole15983012015-01-28 15:17:18 -0800258 function(newValue, oldValue) {
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800259 if (newValue === true) {
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800260
261 // ensure thead and tbody have no display
262 thead.style('display', null);
263 tbody.style('display', null);
264
Bri Prebilic Cole15983012015-01-28 15:17:18 -0800265 $timeout(function () {
266 fixTable(table, thead, tbody, scope.tHeight);
Bri Prebilic Coled36a90f2015-01-22 16:19:27 -0800267 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800268 }
269 });
Bri Prebilic Cole4f0d9772015-01-21 16:45:14 -0800270 }
271 };
272 }]);
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -0800273}());