blob: be2ee774c7c4aa7769ca15c6186daa7098ee5cfd [file] [log] [blame]
Bri Prebilic Cole093739a2015-01-23 10:22:50 -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 -- Widget -- Table Service
19 */
20(function () {
21 'use strict';
22
23 var $log;
24
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080025 function renderTable(div, config, data) {
Bri Prebilic Cole5c2cab92015-01-23 16:53:29 -080026 var table = div.append('table').attr('fixed-header', ''),
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080027 colIds = config.colIds,
28 colText = config.colText,
29 dataObjects = data[Object.keys(data)[0]],
30 thead, tbody, tRows;
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080031
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080032 thead = table.append('thead');
33 tbody = table.append('tbody');
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080034
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080035 thead.append('tr').selectAll('th')
36 .data(colText)
37 .enter()
38 .append('th')
39 .text(function(d) { return d });
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080040
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080041 tRows = tbody.selectAll('tr')
42 .data(dataObjects)
43 .enter()
44 .append('tr');
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080045
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080046 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 Coleaa8d2ed2015-01-23 16:53:29 -080057
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080058 return table;
Bri Prebilic Coleaa8d2ed2015-01-23 16:53:29 -080059 }
60
Bri Prebilic Cole093739a2015-01-23 10:22:50 -080061 angular.module('onosWidget')
62 .factory('TableService', ['$log', function (_$log_) {
63 $log = _$log_;
64
65 return {
Bri Prebilic Cole4c891772015-01-27 11:38:51 -080066 renderTable: renderTable
Bri Prebilic Cole093739a2015-01-23 10:22:50 -080067 };
68 }]);
69
70}());