Thomas Vachuska

GUI -- Added category to the UiView abstraction.

Change-Id: I55fff4d242e8d6b8d8ce3d25e8f9355dc0ef976a
......@@ -39,6 +39,7 @@ import java.util.List;
import java.util.Set;
import static java.util.Collections.synchronizedSet;
import static org.onosproject.ui.UiView.Category.OTHER;
/**
* Mechanism to stream data to the GUI.
......@@ -52,7 +53,7 @@ public class IntentPerfUi {
private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>());
private List<UiView> views = ImmutableList.of(new UiView("intentPerf", "Intent Performance"));
private List<UiView> views = ImmutableList.of(new UiView(OTHER, "intentPerf", "Intent Performance"));
private UiExtension uiExtension = new UiExtension(views, this::newHandlers,
getClass().getClassLoader());
......
......@@ -24,21 +24,68 @@ import java.util.Objects;
*/
public class UiView {
/**
* Designates navigation menu category.
*/
public enum Category {
/**
* Represents platform related views.
*/
PLATFORM("Platform"),
/**
* Represents network-control related views.
*/
NETWORK("Network"),
/**
* Represents miscellaneous views.
*/
OTHER("Other");
private final String label;
Category(String label) {
this.label = label;
}
/**
* Returns display label for the category.
*
* @return display label
*/
public String label() {
return label;
}
}
private final String id;
private final String label;
private final Category category;
/**
* Creates a new user interface view descriptor.
*
* @param id view identifier
* @param label view label
* @param category view category
* @param id view identifier
* @param label view label
*/
public UiView(String id, String label) {
public UiView(Category category, String id, String label) {
this.category = category;
this.id = id;
this.label = label;
}
/**
* Returns the navigation category.
*
* @return navigation category
*/
public Category category() {
return category;
}
/**
* Returns the view identifier.
*
* @return view id
......@@ -76,6 +123,7 @@ public class UiView {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("category", category)
.add("id", id)
.add("label", label)
.toString();
......
......@@ -26,10 +26,10 @@ public class UiViewHidden extends UiView {
/**
* Creates a new user interface hidden view descriptor.
*
* @param id view identifier
* @param id view identifier
*/
public UiViewHidden(String id) {
super(id, null);
super(Category.OTHER, id, null);
}
@Override
......
......@@ -22,6 +22,7 @@ import java.io.IOException;
import static com.google.common.io.ByteStreams.toByteArray;
import static org.junit.Assert.*;
import static org.onosproject.ui.UiView.Category.OTHER;
/**
* Tests the default user interface extension descriptor.
......@@ -30,26 +31,27 @@ public class UiExtensionTest {
@Test
public void basics() throws IOException {
UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")),
UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")),
null,
getClass().getClassLoader());
String css = new String(toByteArray(ext.css()));
assertTrue("incorrect css stream", css.contains("foo-css"));
String js = new String(toByteArray(ext.js()));
assertTrue("incorrect js stream", js.contains("foo-js"));
assertEquals("incorrect views stream", "foo", ext.views().get(0).id());
assertEquals("incorrect view id", "foo", ext.views().get(0).id());
assertEquals("incorrect view category", OTHER, ext.views().get(0).category());
assertNull("incorrect handler factory", ext.messageHandlerFactory());
}
@Test
public void withPath() throws IOException {
UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")),
UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")),
null, "custom", getClass().getClassLoader());
String css = new String(toByteArray(ext.css()));
assertTrue("incorrect css stream", css.contains("custom-css"));
String js = new String(toByteArray(ext.js()));
assertTrue("incorrect js stream", js.contains("custom-js"));
assertEquals("incorrect views stream", "foo", ext.views().get(0).id());
assertEquals("incorrect view id", "foo", ext.views().get(0).id());
assertNull("incorrect handler factory", ext.messageHandlerFactory());
}
}
\ No newline at end of file
......
......@@ -4,4 +4,4 @@ export ONOS_NIC=192.168.56.*
export OC1="192.168.56.11"
export OC2="192.168.56.12"
export OC3="192.168.56.13"
export OCN="192.168.56.14"
export OCN="192.168.56.7"
......
......@@ -44,7 +44,6 @@ public class MainNavResource extends AbstractInjectionResource {
private static final String INJECT_VIEW_ITEMS_START = "<!-- {INJECTED-VIEW-NAV-START} -->";
private static final String INJECT_VIEW_ITEMS_END = "<!-- {INJECTED-VIEW-NAV-END} -->";
private static final String NAV_FORMAT =
"<a ng-click=\"navCtrl.hideNav()\" href=\"#/%s\">%s</a>\n";
......
......@@ -38,6 +38,8 @@ import java.util.Set;
import static com.google.common.collect.ImmutableList.of;
import static java.util.stream.Collectors.toSet;
import static org.onosproject.ui.UiView.Category.NETWORK;
import static org.onosproject.ui.UiView.Category.PLATFORM;
/**
* Manages the user interface extensions.
......@@ -60,14 +62,14 @@ public class UiExtensionManager implements UiExtensionService, SpriteService {
// Creates core UI extension
private static UiExtension createCoreExtension() {
List<UiView> coreViews = of(new UiView("topo", "Topology"),
new UiView("device", "Devices"),
List<UiView> coreViews = of(new UiView(PLATFORM, "app", "Applications"),
new UiView(PLATFORM, "cluster", "Cluster Nodes"),
new UiView(NETWORK, "topo", "Topology"),
new UiView(NETWORK, "device", "Devices"),
new UiViewHidden("flow"),
new UiView("link", "Links"),
new UiView("host", "Hosts"),
new UiView("intent", "Intents"),
new UiView("app", "Applications"),
new UiView("cluster", "Cluster Nodes"));
new UiView(NETWORK, "link", "Links"),
new UiView(NETWORK, "host", "Hosts"),
new UiView(NETWORK, "intent", "Intents"));
UiMessageHandlerFactory messageHandlerFactory =
() -> ImmutableList.of(
......
......@@ -106,7 +106,7 @@
// If view ID not provided, route to the first view in the list.
$routeProvider
.otherwise({
redirectTo: '/' + viewIds[0]
redirectTo: '/topo'
});
function viewCtrlName(vid) {
......