Bri Prebilic Cole

GUI -- Refactored DeviceTableRow to use abstract super class.

- added type and chassis ID to table data

Change-Id: I5758bfb3f9dcd659325265d734ffe9aa7ae1b0ad
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 +package org.onosproject.gui;
18 +
19 +import com.fasterxml.jackson.databind.ObjectMapper;
20 +import com.fasterxml.jackson.databind.node.ObjectNode;
21 +
22 +import java.util.HashMap;
23 +import java.util.Map;
24 +
25 +
26 +/**
27 + * Provides a partial implementation of {@link TableRow}.
28 + */
29 +public abstract class AbstractTableRow implements TableRow {
30 +
31 + private static final ObjectMapper MAPPER = new ObjectMapper();
32 +
33 + private final Map<String, String> data = new HashMap<>();
34 +
35 + @Override
36 + public String get(String key) {
37 + return data.get(key);
38 + }
39 +
40 + @Override
41 + public ObjectNode toJsonNode() {
42 + ObjectNode result = MAPPER.createObjectNode();
43 + for (String id : columnIds()) {
44 + result.put(id, data.get(id));
45 + }
46 + return result;
47 + }
48 +
49 + /**
50 + * Subclasses must provide the list of column IDs.
51 + *
52 + * @return array of column IDs
53 + */
54 + protected abstract String[] columnIds();
55 +
56 + /**
57 + * Add a column ID to value binding.
58 + *
59 + * @param id the column ID
60 + * @param value the cell value
61 + */
62 + protected void add(String id, String value) {
63 + data.put(id, value);
64 + }
65 +}
...@@ -43,7 +43,7 @@ public class DeviceGuiResource extends BaseResource { ...@@ -43,7 +43,7 @@ public class DeviceGuiResource extends BaseResource {
43 private static final ObjectMapper MAPPER = new ObjectMapper(); 43 private static final ObjectMapper MAPPER = new ObjectMapper();
44 44
45 45
46 - // return list of devices 46 + // return the list of devices in appropriate sorted order
47 @GET 47 @GET
48 @Produces("application/json") 48 @Produces("application/json")
49 public Response getDevices( 49 public Response getDevices(
......
...@@ -16,68 +16,58 @@ ...@@ -16,68 +16,58 @@
16 16
17 package org.onosproject.gui; 17 package org.onosproject.gui;
18 18
19 -import com.fasterxml.jackson.databind.ObjectMapper;
20 -import com.fasterxml.jackson.databind.node.ObjectNode;
21 import org.onosproject.net.Device; 19 import org.onosproject.net.Device;
22 import org.onosproject.net.device.DeviceService; 20 import org.onosproject.net.device.DeviceService;
23 21
24 -import java.util.HashMap; 22 +/**
25 -import java.util.Map; 23 + * TableRow implementation for {@link Device devices}.
26 - 24 + */
27 -public class DeviceTableRow implements TableRow { 25 +public class DeviceTableRow extends AbstractTableRow {
28 26
29 private static final String ID = "id"; 27 private static final String ID = "id";
30 private static final String AVAILABLE = "available"; 28 private static final String AVAILABLE = "available";
31 private static final String AVAILABLE_IID = "_iconid_available"; 29 private static final String AVAILABLE_IID = "_iconid_available";
32 - private static final String TYPE = "type"; 30 + private static final String TYPE_IID = "_iconid_type";
31 + private static final String DEV_ICON_PREFIX = "devIcon_";
33 private static final String ROLE = "role"; 32 private static final String ROLE = "role";
34 private static final String MFR = "mfr"; 33 private static final String MFR = "mfr";
35 private static final String HW = "hw"; 34 private static final String HW = "hw";
36 private static final String SW = "sw"; 35 private static final String SW = "sw";
37 private static final String SERIAL = "serial"; 36 private static final String SERIAL = "serial";
38 private static final String PROTOCOL = "protocol"; 37 private static final String PROTOCOL = "protocol";
38 + private static final String CHASSISID = "chassisid";
39 +
40 + private static final String[] COL_IDS = {
41 + ID, AVAILABLE, AVAILABLE_IID, TYPE_IID, ROLE,
42 + MFR, HW, SW, SERIAL, PROTOCOL, CHASSISID
43 + };
39 44
40 private static final String ICON_ID_ONLINE = "deviceOnline"; 45 private static final String ICON_ID_ONLINE = "deviceOnline";
41 private static final String ICON_ID_OFFLINE = "deviceOffline"; 46 private static final String ICON_ID_OFFLINE = "deviceOffline";
42 47
43 - private static final ObjectMapper MAPPER = new ObjectMapper();
44 -
45 - private final Map<String, String> data = new HashMap<>();
46 -
47 public DeviceTableRow(DeviceService service, Device d) { 48 public DeviceTableRow(DeviceService service, Device d) {
48 boolean available = service.isAvailable(d.id()); 49 boolean available = service.isAvailable(d.id());
49 String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE; 50 String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
50 51
51 - data.put(ID, d.id().toString()); 52 + add(ID, d.id().toString());
52 - data.put(AVAILABLE, Boolean.toString(available)); 53 + add(AVAILABLE, Boolean.toString(available));
53 - data.put(AVAILABLE_IID, iconId); 54 + add(AVAILABLE_IID, iconId);
54 - data.put(TYPE, d.type().toString()); 55 + add(TYPE_IID, getTypeIconId(d));
55 - data.put(ROLE, service.getRole(d.id()).toString()); 56 + add(ROLE, service.getRole(d.id()).toString());
56 - data.put(MFR, d.manufacturer()); 57 + add(MFR, d.manufacturer());
57 - data.put(HW, d.hwVersion()); 58 + add(HW, d.hwVersion());
58 - data.put(SW, d.swVersion()); 59 + add(SW, d.swVersion());
59 - data.put(SERIAL, d.serialNumber()); 60 + add(SERIAL, d.serialNumber());
60 - data.put(PROTOCOL, d.annotations().value(PROTOCOL)); 61 + add(PROTOCOL, d.annotations().value(PROTOCOL));
62 + add(CHASSISID, d.chassisId().toString());
61 } 63 }
62 64
63 - @Override 65 + private String getTypeIconId(Device d) {
64 - public String get(String key) { 66 + return DEV_ICON_PREFIX + d.type().toString();
65 - return data.get(key);
66 } 67 }
67 68
68 @Override 69 @Override
69 - public ObjectNode toJsonNode() { 70 + protected String[] columnIds() {
70 - ObjectNode result = MAPPER.createObjectNode(); 71 + return COL_IDS;
71 - result.put(ID, data.get(ID));
72 - result.put(AVAILABLE, data.get(AVAILABLE));
73 - result.put(AVAILABLE_IID, data.get(AVAILABLE_IID));
74 - result.put(TYPE, data.get(TYPE));
75 - result.put(ROLE, data.get(ROLE));
76 - result.put(MFR, data.get(MFR));
77 - result.put(HW, data.get(HW));
78 - result.put(SW, data.get(SW));
79 - result.put(SERIAL, data.get(SERIAL));
80 - result.put(PROTOCOL, data.get(PROTOCOL));
81 - return result;
82 } 72 }
83 } 73 }
......
...@@ -29,6 +29,13 @@ public class RowComparator implements Comparator<TableRow> { ...@@ -29,6 +29,13 @@ public class RowComparator implements Comparator<TableRow> {
29 private final String colId; 29 private final String colId;
30 private final Direction dir; 30 private final Direction dir;
31 31
32 + /**
33 + * Constructs a comparator for table rows that uses the given
34 + * column ID and direction.
35 + *
36 + * @param colId the column to sort on
37 + * @param dir the direction to sort in
38 + */
32 public RowComparator(String colId, Direction dir) { 39 public RowComparator(String colId, Direction dir) {
33 if (colId == null || dir == null) { 40 if (colId == null || dir == null) {
34 throw new NullPointerException("Null parameters not allowed"); 41 throw new NullPointerException("Null parameters not allowed");
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
31 var glyphMapping = { 31 var glyphMapping = {
32 deviceOnline: 'checkMark', 32 deviceOnline: 'checkMark',
33 deviceOffline: 'xMark', 33 deviceOffline: 'xMark',
34 + devIcon_SWITCH: 'switch',
35 +
34 tableColSortAsc: 'triangleUp', 36 tableColSortAsc: 'triangleUp',
35 tableColSortDesc: 'triangleDown', 37 tableColSortDesc: 'triangleDown',
36 tableColSortNone: '-' 38 tableColSortNone: '-'
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
83 // if the header has no text in it, 83 // if the header has no text in it,
84 // then make the column the width of the td element. 84 // then make the column the width of the td element.
85 // (This looks good for icons) 85 // (This looks good for icons)
86 - if (!(thElement.html().length)) { 86 + if (!(thElement.text().length)) {
87 var tdSize = tdElement.style('width'); 87 var tdSize = tdElement.style('width');
88 thElement.style('width', tdSize + 'px'); 88 thElement.style('width', tdSize + 'px');
89 tdElement.style('width', tdSize + 'px'); 89 tdElement.style('width', tdSize + 'px');
...@@ -161,6 +161,7 @@ ...@@ -161,6 +161,7 @@
161 }; 161 };
162 }]) 162 }])
163 163
164 + // TODO: fix header alignment spacing
164 .directive('onosFixedHeader', ['$window', '$timeout', 165 .directive('onosFixedHeader', ['$window', '$timeout',
165 'MastService', 'FnService', 166 'MastService', 'FnService',
166 function (_$window_, $timeout, mast, _fs_) { 167 function (_$window_, $timeout, mast, _fs_) {
......
1 <!-- Device partial HTML --> 1 <!-- Device partial HTML -->
2 <div id="ov-device"> 2 <div id="ov-device">
3 - <h2>Devices</h2> 3 + <h2>Devices ({{ctrl.deviceData.length}} total)</h2>
4 <table class="summary-list" 4 <table class="summary-list"
5 onos-fixed-header 5 onos-fixed-header
6 ng-style="setTableHW()" 6 ng-style="setTableHW()"
...@@ -8,13 +8,15 @@ ...@@ -8,13 +8,15 @@
8 sort-callback="sortCallback(urlSuffix)"> 8 sort-callback="sortCallback(urlSuffix)">
9 <thead> 9 <thead>
10 <tr> 10 <tr>
11 - <th colId="available"></th> 11 + <th colId="available">.</th>
12 - <th colId="id" sortable>Device ID</th> 12 + <th colId="type">.</th>
13 - <th colId="mfr" sortable>Vendor</th> 13 + <th colId="id" sortable>Device ID </th>
14 - <th colId="hw" sortable>Hardware Version</th> 14 + <th colId="mfr" sortable>Vendor </th>
15 - <th colId="sw" sortable>Software Version</th> 15 + <th colId="hw" sortable>H/W Version </th>
16 - <th colId="serial" sortable>Serial Number</th> 16 + <th colId="sw" sortable>S/W Version </th>
17 - <th colId="protocol" sortable>Protocol</th> 17 + <th colId="chassisid" sortable>Chassis ID </th>
18 + <th colId="serial" sortable>Serial # </th>
19 + <th colId="protocol" sortable>Protocol </th>
18 </tr> 20 </tr>
19 </thead> 21 </thead>
20 22
...@@ -22,10 +24,12 @@ ...@@ -22,10 +24,12 @@
22 <tr ng-repeat="dev in ctrl.deviceData" 24 <tr ng-repeat="dev in ctrl.deviceData"
23 ng-repeat-done> 25 ng-repeat-done>
24 <td><div icon icon-id="{{dev._iconid_available}}"></div></td> 26 <td><div icon icon-id="{{dev._iconid_available}}"></div></td>
27 + <td><div icon icon-id="{{dev._iconid_type}}"></div></td>
25 <td>{{dev.id}}</td> 28 <td>{{dev.id}}</td>
26 <td>{{dev.mfr}}</td> 29 <td>{{dev.mfr}}</td>
27 <td>{{dev.hw}}</td> 30 <td>{{dev.hw}}</td>
28 <td>{{dev.sw}}</td> 31 <td>{{dev.sw}}</td>
32 + <td>{{dev.chassisid}}</td>
29 <td>{{dev.serial}}</td> 33 <td>{{dev.serial}}</td>
30 <td>{{dev.protocol}}</td> 34 <td>{{dev.protocol}}</td>
31 </tr> 35 </tr>
......