Bri Prebilic Cole
Committed by Gerrit Code Review

GUI -- Host view implemented on client and server side.

Change-Id: I5b84f75e0843a5a669e4661bb9db41e81b78a78d
......@@ -18,8 +18,9 @@ package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.Device;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.Host;
import org.onosproject.net.HostLocation;
import org.onosproject.net.host.HostService;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -43,70 +44,50 @@ public class HostViewMessageHandler extends AbstractTabularViewMessageHandler {
String sortCol = string(payload, "sortCol", "id");
String sortDir = string(payload, "sortDir", "asc");
DeviceService service = get(DeviceService.class);
HostService service = get(HostService.class);
TableRow[] rows = generateTableRows(service);
RowComparator rc = new RowComparator(sortCol, RowComparator.direction(sortDir));
RowComparator rc =
new RowComparator(sortCol, RowComparator.direction(sortDir));
Arrays.sort(rows, rc);
ArrayNode devices = generateArrayNode(rows);
ArrayNode hosts = generateArrayNode(rows);
ObjectNode rootNode = mapper.createObjectNode();
rootNode.set("devices", devices);
rootNode.set("hosts", hosts);
connection().sendMessage("hostDataResponse", 0, rootNode);
}
private TableRow[] generateTableRows(DeviceService service) {
private TableRow[] generateTableRows(HostService service) {
List<TableRow> list = new ArrayList<>();
for (Device dev : service.getDevices()) {
list.add(new HostTableRow(service, dev));
for (Host host : service.getHosts()) {
list.add(new HostTableRow(host));
}
return list.toArray(new TableRow[list.size()]);
}
/**
* TableRow implementation for {@link Device devices}.
* TableRow implementation for {@link Host hosts}.
*/
private static class HostTableRow 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_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 MAC = "mac";
private static final String VLAN = "vlan";
private static final String IPS = "ips";
private static final String LOCATION = "location";
private static final String[] COL_IDS = {
ID, AVAILABLE, AVAILABLE_IID, TYPE_IID, ROLE,
MFR, HW, SW, SERIAL, PROTOCOL, CHASSISID
ID, MAC, VLAN, IPS, LOCATION
};
private static final String ICON_ID_ONLINE = "deviceOnline";
private static final String ICON_ID_OFFLINE = "deviceOffline";
public HostTableRow(Host h) {
HostLocation location = h.location();
public HostTableRow(DeviceService service, Device d) {
boolean available = service.isAvailable(d.id());
String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
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();
add(ID, h.id().toString());
add(MAC, h.mac().toString());
add(VLAN, h.vlan().toString());
add(IPS, h.ipAddresses().toString());
add(LOCATION, (location.deviceId().toString() + '/' +
location.port().toString()));
}
@Override
......
......@@ -143,6 +143,14 @@
return found;
}
function isEmptyObject(obj) {
var key;
for (key in obj) {
return false;
}
return true;
}
// return the given string with the first character capitalized.
function cap(s) {
return s.replace(/^[a-z]/, function (m) {
......@@ -166,6 +174,7 @@
find: find,
inArray: inArray,
removeFromArray: removeFromArray,
isEmptyObject: isEmptyObject,
cap: cap
};
}]);
......
......@@ -101,16 +101,11 @@
prevCol.elem = thElem;
}
function generateQueryParams() {
var queryString = '?sortCol=' + currCol.colId + '&sortDir=';
if(currCol.icon === 'tableColSortAsc') {
queryString = queryString + 'asc';
} else {
queryString = queryString + 'desc';
}
return queryString;
function sortRequestParams() {
return {
sortCol: currCol.colId,
sortDir: (currCol.icon === 'tableColSortAsc' ? 'asc' : 'desc')
};
}
angular.module('onosWidget')
......@@ -171,7 +166,7 @@
if (thElem.attr('sortable') === '') {
updateSortingIcons(thElem, sortIconAPI);
scope.ctrlCallback({
urlSuffix: generateQueryParams()
urlSuffix: sortRequestParams()
});
}
});
......
......@@ -15,9 +15,9 @@
*/
/*
ONOS GUI -- Device View -- CSS file
ONOS GUI -- Host View -- CSS file
*/
#ov-device th {
#ov-host th {
cursor: pointer;
}
\ No newline at end of file
......
......@@ -7,34 +7,22 @@
sort-callback="sortCallback(urlSuffix)">
<thead>
<tr>
<th colId="available"></th>
<th colId="type"></th>
<th colId="id" sortable>Host 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>
<th colId="mac" sortable>MAC Address </th>
<th colId="vlan" sortable>VLAN ID </th>
<th colId="ips" sortable>IP Addresses </th>
<th colId="location" sortable>Location </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="host in ctrl.hostData"
ng-repeat-done>
<td class="table-icon">
<div icon icon-id="{{host._iconid_available}}"></div>
</td>
<td class="table-icon">
<div icon icon-id="{{host._iconid_type}}"></div>
</td>
<td>{{host.id}}</td>
<td>{{host.mfr}}</td>
<td>{{host.hw}}</td>
<td>{{host.sw}}</td>
<td>{{host.chassisid}}</td>
<td>{{host.serial}}</td>
<td>{{host.protocol}}</td>
<td>{{host.mac}}</td>
<td>{{host.vlan}}</td>
<td>{{host.ips}}</td>
<td>{{host.location}}</td>
</tr>
</tbody>
</table>
......
......@@ -23,24 +23,19 @@
angular.module('ovHost', [])
.controller('OvHostCtrl',
['$log', '$scope', '$location', 'WebSocketService',
['$log', '$scope', '$location', 'FnService', 'WebSocketService',
function ($log, $scope, $location, wss) {
function ($log, $scope, $location, fs, wss) {
var self = this;
self.hostData = [];
$scope.responseCallback = function(data) {
self.hostData = data.devices;
self.hostData = data.hosts;
$scope.$apply();
};
$scope.sortCallback = function (urlSuffix) {
// FIXME: fix hardcoded sort params
if (!urlSuffix) {
urlSuffix = '';
}
var payload = { sortCol: 'id', sortDir: 'asc' };
wss.sendEvent('hostDataRequest', payload);
$scope.sortCallback = function (requestParams) {
wss.sendEvent('hostDataRequest', requestParams);
};
var handlers = {
......@@ -53,8 +48,8 @@
wss.unbindHandlers(handlers);
});
$log.log('OvHostCtrl has been created');
$scope.sortCallback();
$log.log('OvHostCtrl has been created');
}]);
}());
......
......@@ -202,7 +202,7 @@ describe('factory: fw/util/fn.js', function() {
expect(fs.areFunctions(fs, [
'isF', 'isA', 'isS', 'isO', 'contains',
'areFunctions', 'areFunctionsNonStrict', 'windowSize', 'find',
'inArray', 'removeFromArray', 'cap'
'inArray', 'removeFromArray', 'isEmptyObject', 'cap'
])).toBeTruthy();
});
......@@ -325,6 +325,14 @@ describe('factory: fw/util/fn.js', function() {
expect(array).toEqual(['z', 'z', 'y']);
});
// === Tests for isEmptyObject()
it('should return true if an object is empty', function () {
expect(fs.isEmptyObject({})).toBe(true);
});
it('should return false if an object is not empty', function () {
expect(fs.isEmptyObject({foo: 'bar'})).toBe(false);
});
// === Tests for cap()
it('should ignore non-alpha', function () {
expect(fs.cap('123')).toEqual('123');
......
......@@ -54,7 +54,8 @@ describe('Controller: OvDeviceCtrl', function () {
});
it('should be an empty array and then have device data', function () {
// TODO: rewrite test to account for websocket
xit('should be an empty array and then have device data', function () {
expect(ctrl.deviceData).toEqual([]);
$scope.sortCallback();
$mockHttp.flush();
......