Bri Prebilic Cole | 093739a | 2015-01-23 10:22:50 -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 -- Widget -- Table Service |
| 19 | */ |
| 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
| 23 | var $log; |
| 24 | |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 25 | function renderTable(div, config, data) { |
Bri Prebilic Cole | 5c2cab9 | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 26 | var table = div.append('table').attr('fixed-header', ''), |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 27 | colIds = config.colIds, |
| 28 | colText = config.colText, |
| 29 | dataObjects = data[Object.keys(data)[0]], |
| 30 | thead, tbody, tRows; |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 31 | |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 32 | thead = table.append('thead'); |
| 33 | tbody = table.append('tbody'); |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 34 | |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 35 | thead.append('tr').selectAll('th') |
| 36 | .data(colText) |
| 37 | .enter() |
| 38 | .append('th') |
| 39 | .text(function(d) { return d }); |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 40 | |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 41 | tRows = tbody.selectAll('tr') |
| 42 | .data(dataObjects) |
| 43 | .enter() |
| 44 | .append('tr'); |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 45 | |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 46 | tRows.selectAll('td') |
| 47 | .data(function(row) { |
| 48 | return colIds.map(function(headerId) { |
| 49 | return { |
| 50 | column: headerId, value: row[headerId] |
| 51 | }; |
| 52 | }); |
| 53 | }) |
| 54 | .enter() |
| 55 | .append('td') |
| 56 | .html(function(d) { return d.value }); |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 57 | |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 58 | return table; |
Bri Prebilic Cole | aa8d2ed | 2015-01-23 16:53:29 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Bri Prebilic Cole | 093739a | 2015-01-23 10:22:50 -0800 | [diff] [blame] | 61 | angular.module('onosWidget') |
| 62 | .factory('TableService', ['$log', function (_$log_) { |
| 63 | $log = _$log_; |
| 64 | |
| 65 | return { |
Bri Prebilic Cole | 4c89177 | 2015-01-27 11:38:51 -0800 | [diff] [blame^] | 66 | renderTable: renderTable |
Bri Prebilic Cole | 093739a | 2015-01-23 10:22:50 -0800 | [diff] [blame] | 67 | }; |
| 68 | }]); |
| 69 | |
| 70 | }()); |