GUI -- Refactored DeviceTableRow to use abstract super class.
- added type and chassis ID to table data
Change-Id: I5758bfb3f9dcd659325265d734ffe9aa7ae1b0ad
diff --git a/web/gui/src/main/java/org/onosproject/gui/AbstractTableRow.java b/web/gui/src/main/java/org/onosproject/gui/AbstractTableRow.java
new file mode 100644
index 0000000..7be7172
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/gui/AbstractTableRow.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.gui;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Provides a partial implementation of {@link TableRow}.
+ */
+public abstract class AbstractTableRow implements TableRow {
+
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ private final Map<String, String> data = new HashMap<>();
+
+ @Override
+ public String get(String key) {
+ return data.get(key);
+ }
+
+ @Override
+ public ObjectNode toJsonNode() {
+ ObjectNode result = MAPPER.createObjectNode();
+ for (String id : columnIds()) {
+ result.put(id, data.get(id));
+ }
+ return result;
+ }
+
+ /**
+ * Subclasses must provide the list of column IDs.
+ *
+ * @return array of column IDs
+ */
+ protected abstract String[] columnIds();
+
+ /**
+ * Add a column ID to value binding.
+ *
+ * @param id the column ID
+ * @param value the cell value
+ */
+ protected void add(String id, String value) {
+ data.put(id, value);
+ }
+}
diff --git a/web/gui/src/main/java/org/onosproject/gui/DeviceGuiResource.java b/web/gui/src/main/java/org/onosproject/gui/DeviceGuiResource.java
index 3128456..403b8c6 100644
--- a/web/gui/src/main/java/org/onosproject/gui/DeviceGuiResource.java
+++ b/web/gui/src/main/java/org/onosproject/gui/DeviceGuiResource.java
@@ -43,7 +43,7 @@
private static final ObjectMapper MAPPER = new ObjectMapper();
- // return list of devices
+ // return the list of devices in appropriate sorted order
@GET
@Produces("application/json")
public Response getDevices(
diff --git a/web/gui/src/main/java/org/onosproject/gui/DeviceTableRow.java b/web/gui/src/main/java/org/onosproject/gui/DeviceTableRow.java
index ab13467..423657a 100644
--- a/web/gui/src/main/java/org/onosproject/gui/DeviceTableRow.java
+++ b/web/gui/src/main/java/org/onosproject/gui/DeviceTableRow.java
@@ -16,68 +16,58 @@
package org.onosproject.gui;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.net.Device;
import org.onosproject.net.device.DeviceService;
-import java.util.HashMap;
-import java.util.Map;
-
-public class DeviceTableRow implements TableRow {
+/**
+ * TableRow implementation for {@link Device devices}.
+ */
+public class DeviceTableRow extends AbstractTableRow {
private static final String ID = "id";
private static final String AVAILABLE = "available";
private static final String AVAILABLE_IID = "_iconid_available";
- private static final String TYPE = "type";
+ private static final String TYPE_IID = "_iconid_type";
+ private static final String DEV_ICON_PREFIX = "devIcon_";
private static final String ROLE = "role";
private static final String MFR = "mfr";
private static final String HW = "hw";
private static final String SW = "sw";
private static final String SERIAL = "serial";
private static final String PROTOCOL = "protocol";
+ private static final String CHASSISID = "chassisid";
+
+ private static final String[] COL_IDS = {
+ ID, AVAILABLE, AVAILABLE_IID, TYPE_IID, ROLE,
+ MFR, HW, SW, SERIAL, PROTOCOL, CHASSISID
+ };
private static final String ICON_ID_ONLINE = "deviceOnline";
private static final String ICON_ID_OFFLINE = "deviceOffline";
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
- private final Map<String, String> data = new HashMap<>();
-
public DeviceTableRow(DeviceService service, Device d) {
boolean available = service.isAvailable(d.id());
String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
- data.put(ID, d.id().toString());
- data.put(AVAILABLE, Boolean.toString(available));
- data.put(AVAILABLE_IID, iconId);
- data.put(TYPE, d.type().toString());
- data.put(ROLE, service.getRole(d.id()).toString());
- data.put(MFR, d.manufacturer());
- data.put(HW, d.hwVersion());
- data.put(SW, d.swVersion());
- data.put(SERIAL, d.serialNumber());
- data.put(PROTOCOL, d.annotations().value(PROTOCOL));
+ add(ID, d.id().toString());
+ add(AVAILABLE, Boolean.toString(available));
+ add(AVAILABLE_IID, iconId);
+ add(TYPE_IID, getTypeIconId(d));
+ add(ROLE, service.getRole(d.id()).toString());
+ add(MFR, d.manufacturer());
+ add(HW, d.hwVersion());
+ add(SW, d.swVersion());
+ add(SERIAL, d.serialNumber());
+ add(PROTOCOL, d.annotations().value(PROTOCOL));
+ add(CHASSISID, d.chassisId().toString());
+ }
+
+ private String getTypeIconId(Device d) {
+ return DEV_ICON_PREFIX + d.type().toString();
}
@Override
- public String get(String key) {
- return data.get(key);
- }
-
- @Override
- public ObjectNode toJsonNode() {
- ObjectNode result = MAPPER.createObjectNode();
- result.put(ID, data.get(ID));
- result.put(AVAILABLE, data.get(AVAILABLE));
- result.put(AVAILABLE_IID, data.get(AVAILABLE_IID));
- result.put(TYPE, data.get(TYPE));
- result.put(ROLE, data.get(ROLE));
- result.put(MFR, data.get(MFR));
- result.put(HW, data.get(HW));
- result.put(SW, data.get(SW));
- result.put(SERIAL, data.get(SERIAL));
- result.put(PROTOCOL, data.get(PROTOCOL));
- return result;
+ protected String[] columnIds() {
+ return COL_IDS;
}
}
diff --git a/web/gui/src/main/java/org/onosproject/gui/RowComparator.java b/web/gui/src/main/java/org/onosproject/gui/RowComparator.java
index f14a660..7c79fc2 100644
--- a/web/gui/src/main/java/org/onosproject/gui/RowComparator.java
+++ b/web/gui/src/main/java/org/onosproject/gui/RowComparator.java
@@ -29,6 +29,13 @@
private final String colId;
private final Direction dir;
+ /**
+ * Constructs a comparator for table rows that uses the given
+ * column ID and direction.
+ *
+ * @param colId the column to sort on
+ * @param dir the direction to sort in
+ */
public RowComparator(String colId, Direction dir) {
if (colId == null || dir == null) {
throw new NullPointerException("Null parameters not allowed");
diff --git a/web/gui/src/main/webapp/app/fw/svg/icon.js b/web/gui/src/main/webapp/app/fw/svg/icon.js
index e3f4bdb..51e47b9 100644
--- a/web/gui/src/main/webapp/app/fw/svg/icon.js
+++ b/web/gui/src/main/webapp/app/fw/svg/icon.js
@@ -31,6 +31,8 @@
var glyphMapping = {
deviceOnline: 'checkMark',
deviceOffline: 'xMark',
+ devIcon_SWITCH: 'switch',
+
tableColSortAsc: 'triangleUp',
tableColSortDesc: 'triangleDown',
tableColSortNone: '-'
diff --git a/web/gui/src/main/webapp/app/fw/widget/table.js b/web/gui/src/main/webapp/app/fw/widget/table.js
index 6477018..3d950b8 100644
--- a/web/gui/src/main/webapp/app/fw/widget/table.js
+++ b/web/gui/src/main/webapp/app/fw/widget/table.js
@@ -83,7 +83,7 @@
// if the header has no text in it,
// then make the column the width of the td element.
// (This looks good for icons)
- if (!(thElement.html().length)) {
+ if (!(thElement.text().length)) {
var tdSize = tdElement.style('width');
thElement.style('width', tdSize + 'px');
tdElement.style('width', tdSize + 'px');
@@ -161,6 +161,7 @@
};
}])
+ // TODO: fix header alignment spacing
.directive('onosFixedHeader', ['$window', '$timeout',
'MastService', 'FnService',
function (_$window_, $timeout, mast, _fs_) {
diff --git a/web/gui/src/main/webapp/app/view/device/device.html b/web/gui/src/main/webapp/app/view/device/device.html
index 2d8dd62..5eb1d32 100644
--- a/web/gui/src/main/webapp/app/view/device/device.html
+++ b/web/gui/src/main/webapp/app/view/device/device.html
@@ -1,6 +1,6 @@
<!-- Device partial HTML -->
<div id="ov-device">
- <h2>Devices</h2>
+ <h2>Devices ({{ctrl.deviceData.length}} total)</h2>
<table class="summary-list"
onos-fixed-header
ng-style="setTableHW()"
@@ -8,13 +8,15 @@
sort-callback="sortCallback(urlSuffix)">
<thead>
<tr>
- <th colId="available"></th>
- <th colId="id" sortable>Device ID</th>
- <th colId="mfr" sortable>Vendor</th>
- <th colId="hw" sortable>Hardware Version</th>
- <th colId="sw" sortable>Software Version</th>
- <th colId="serial" sortable>Serial Number</th>
- <th colId="protocol" sortable>Protocol</th>
+ <th colId="available">.</th>
+ <th colId="type">.</th>
+ <th colId="id" sortable>Device ID </th>
+ <th colId="mfr" sortable>Vendor </th>
+ <th colId="hw" sortable>H/W Version </th>
+ <th colId="sw" sortable>S/W Version </th>
+ <th colId="chassisid" sortable>Chassis ID </th>
+ <th colId="serial" sortable>Serial # </th>
+ <th colId="protocol" sortable>Protocol </th>
</tr>
</thead>
@@ -22,10 +24,12 @@
<tr ng-repeat="dev in ctrl.deviceData"
ng-repeat-done>
<td><div icon icon-id="{{dev._iconid_available}}"></div></td>
+ <td><div icon icon-id="{{dev._iconid_type}}"></div></td>
<td>{{dev.id}}</td>
<td>{{dev.mfr}}</td>
<td>{{dev.hw}}</td>
<td>{{dev.sw}}</td>
+ <td>{{dev.chassisid}}</td>
<td>{{dev.serial}}</td>
<td>{{dev.protocol}}</td>
</tr>