GUI -- Added category to the UiView abstraction.
Change-Id: I55fff4d242e8d6b8d8ce3d25e8f9355dc0ef976a
Showing
8 changed files
with
72 additions
and
20 deletions
| ... | @@ -39,6 +39,7 @@ import java.util.List; | ... | @@ -39,6 +39,7 @@ import java.util.List; |
| 39 | import java.util.Set; | 39 | import java.util.Set; |
| 40 | 40 | ||
| 41 | import static java.util.Collections.synchronizedSet; | 41 | import static java.util.Collections.synchronizedSet; |
| 42 | +import static org.onosproject.ui.UiView.Category.OTHER; | ||
| 42 | 43 | ||
| 43 | /** | 44 | /** |
| 44 | * Mechanism to stream data to the GUI. | 45 | * Mechanism to stream data to the GUI. |
| ... | @@ -52,7 +53,7 @@ public class IntentPerfUi { | ... | @@ -52,7 +53,7 @@ public class IntentPerfUi { |
| 52 | 53 | ||
| 53 | private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>()); | 54 | private final Set<StreamingControl> handlers = synchronizedSet(new HashSet<>()); |
| 54 | 55 | ||
| 55 | - private List<UiView> views = ImmutableList.of(new UiView("intentPerf", "Intent Performance")); | 56 | + private List<UiView> views = ImmutableList.of(new UiView(OTHER, "intentPerf", "Intent Performance")); |
| 56 | private UiExtension uiExtension = new UiExtension(views, this::newHandlers, | 57 | private UiExtension uiExtension = new UiExtension(views, this::newHandlers, |
| 57 | getClass().getClassLoader()); | 58 | getClass().getClassLoader()); |
| 58 | 59 | ... | ... |
| ... | @@ -24,21 +24,68 @@ import java.util.Objects; | ... | @@ -24,21 +24,68 @@ import java.util.Objects; |
| 24 | */ | 24 | */ |
| 25 | public class UiView { | 25 | public class UiView { |
| 26 | 26 | ||
| 27 | + /** | ||
| 28 | + * Designates navigation menu category. | ||
| 29 | + */ | ||
| 30 | + public enum Category { | ||
| 31 | + /** | ||
| 32 | + * Represents platform related views. | ||
| 33 | + */ | ||
| 34 | + PLATFORM("Platform"), | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Represents network-control related views. | ||
| 38 | + */ | ||
| 39 | + NETWORK("Network"), | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Represents miscellaneous views. | ||
| 43 | + */ | ||
| 44 | + OTHER("Other"); | ||
| 45 | + | ||
| 46 | + private final String label; | ||
| 47 | + | ||
| 48 | + Category(String label) { | ||
| 49 | + this.label = label; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Returns display label for the category. | ||
| 54 | + * | ||
| 55 | + * @return display label | ||
| 56 | + */ | ||
| 57 | + public String label() { | ||
| 58 | + return label; | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 27 | private final String id; | 62 | private final String id; |
| 28 | private final String label; | 63 | private final String label; |
| 64 | + private final Category category; | ||
| 29 | 65 | ||
| 30 | /** | 66 | /** |
| 31 | * Creates a new user interface view descriptor. | 67 | * Creates a new user interface view descriptor. |
| 32 | * | 68 | * |
| 33 | - * @param id view identifier | 69 | + * @param category view category |
| 34 | - * @param label view label | 70 | + * @param id view identifier |
| 71 | + * @param label view label | ||
| 35 | */ | 72 | */ |
| 36 | - public UiView(String id, String label) { | 73 | + public UiView(Category category, String id, String label) { |
| 74 | + this.category = category; | ||
| 37 | this.id = id; | 75 | this.id = id; |
| 38 | this.label = label; | 76 | this.label = label; |
| 39 | } | 77 | } |
| 40 | 78 | ||
| 41 | /** | 79 | /** |
| 80 | + * Returns the navigation category. | ||
| 81 | + * | ||
| 82 | + * @return navigation category | ||
| 83 | + */ | ||
| 84 | + public Category category() { | ||
| 85 | + return category; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 42 | * Returns the view identifier. | 89 | * Returns the view identifier. |
| 43 | * | 90 | * |
| 44 | * @return view id | 91 | * @return view id |
| ... | @@ -76,6 +123,7 @@ public class UiView { | ... | @@ -76,6 +123,7 @@ public class UiView { |
| 76 | @Override | 123 | @Override |
| 77 | public String toString() { | 124 | public String toString() { |
| 78 | return MoreObjects.toStringHelper(this) | 125 | return MoreObjects.toStringHelper(this) |
| 126 | + .add("category", category) | ||
| 79 | .add("id", id) | 127 | .add("id", id) |
| 80 | .add("label", label) | 128 | .add("label", label) |
| 81 | .toString(); | 129 | .toString(); | ... | ... |
| ... | @@ -26,10 +26,10 @@ public class UiViewHidden extends UiView { | ... | @@ -26,10 +26,10 @@ public class UiViewHidden extends UiView { |
| 26 | /** | 26 | /** |
| 27 | * Creates a new user interface hidden view descriptor. | 27 | * Creates a new user interface hidden view descriptor. |
| 28 | * | 28 | * |
| 29 | - * @param id view identifier | 29 | + * @param id view identifier |
| 30 | */ | 30 | */ |
| 31 | public UiViewHidden(String id) { | 31 | public UiViewHidden(String id) { |
| 32 | - super(id, null); | 32 | + super(Category.OTHER, id, null); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | @Override | 35 | @Override | ... | ... |
| ... | @@ -22,6 +22,7 @@ import java.io.IOException; | ... | @@ -22,6 +22,7 @@ import java.io.IOException; |
| 22 | 22 | ||
| 23 | import static com.google.common.io.ByteStreams.toByteArray; | 23 | import static com.google.common.io.ByteStreams.toByteArray; |
| 24 | import static org.junit.Assert.*; | 24 | import static org.junit.Assert.*; |
| 25 | +import static org.onosproject.ui.UiView.Category.OTHER; | ||
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| 27 | * Tests the default user interface extension descriptor. | 28 | * Tests the default user interface extension descriptor. |
| ... | @@ -30,26 +31,27 @@ public class UiExtensionTest { | ... | @@ -30,26 +31,27 @@ public class UiExtensionTest { |
| 30 | 31 | ||
| 31 | @Test | 32 | @Test |
| 32 | public void basics() throws IOException { | 33 | public void basics() throws IOException { |
| 33 | - UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")), | 34 | + UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")), |
| 34 | null, | 35 | null, |
| 35 | getClass().getClassLoader()); | 36 | getClass().getClassLoader()); |
| 36 | String css = new String(toByteArray(ext.css())); | 37 | String css = new String(toByteArray(ext.css())); |
| 37 | assertTrue("incorrect css stream", css.contains("foo-css")); | 38 | assertTrue("incorrect css stream", css.contains("foo-css")); |
| 38 | String js = new String(toByteArray(ext.js())); | 39 | String js = new String(toByteArray(ext.js())); |
| 39 | assertTrue("incorrect js stream", js.contains("foo-js")); | 40 | assertTrue("incorrect js stream", js.contains("foo-js")); |
| 40 | - assertEquals("incorrect views stream", "foo", ext.views().get(0).id()); | 41 | + assertEquals("incorrect view id", "foo", ext.views().get(0).id()); |
| 42 | + assertEquals("incorrect view category", OTHER, ext.views().get(0).category()); | ||
| 41 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); | 43 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | @Test | 46 | @Test |
| 45 | public void withPath() throws IOException { | 47 | public void withPath() throws IOException { |
| 46 | - UiExtension ext = new UiExtension(ImmutableList.of(new UiView("foo", "Foo View")), | 48 | + UiExtension ext = new UiExtension(ImmutableList.of(new UiView(OTHER, "foo", "Foo View")), |
| 47 | null, "custom", getClass().getClassLoader()); | 49 | null, "custom", getClass().getClassLoader()); |
| 48 | String css = new String(toByteArray(ext.css())); | 50 | String css = new String(toByteArray(ext.css())); |
| 49 | assertTrue("incorrect css stream", css.contains("custom-css")); | 51 | assertTrue("incorrect css stream", css.contains("custom-css")); |
| 50 | String js = new String(toByteArray(ext.js())); | 52 | String js = new String(toByteArray(ext.js())); |
| 51 | assertTrue("incorrect js stream", js.contains("custom-js")); | 53 | assertTrue("incorrect js stream", js.contains("custom-js")); |
| 52 | - assertEquals("incorrect views stream", "foo", ext.views().get(0).id()); | 54 | + assertEquals("incorrect view id", "foo", ext.views().get(0).id()); |
| 53 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); | 55 | assertNull("incorrect handler factory", ext.messageHandlerFactory()); |
| 54 | } | 56 | } |
| 55 | } | 57 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -4,4 +4,4 @@ export ONOS_NIC=192.168.56.* | ... | @@ -4,4 +4,4 @@ export ONOS_NIC=192.168.56.* |
| 4 | export OC1="192.168.56.11" | 4 | export OC1="192.168.56.11" |
| 5 | export OC2="192.168.56.12" | 5 | export OC2="192.168.56.12" |
| 6 | export OC3="192.168.56.13" | 6 | export OC3="192.168.56.13" |
| 7 | -export OCN="192.168.56.14" | 7 | +export OCN="192.168.56.7" | ... | ... |
| ... | @@ -44,7 +44,6 @@ public class MainNavResource extends AbstractInjectionResource { | ... | @@ -44,7 +44,6 @@ public class MainNavResource extends AbstractInjectionResource { |
| 44 | private static final String INJECT_VIEW_ITEMS_START = "<!-- {INJECTED-VIEW-NAV-START} -->"; | 44 | private static final String INJECT_VIEW_ITEMS_START = "<!-- {INJECTED-VIEW-NAV-START} -->"; |
| 45 | private static final String INJECT_VIEW_ITEMS_END = "<!-- {INJECTED-VIEW-NAV-END} -->"; | 45 | private static final String INJECT_VIEW_ITEMS_END = "<!-- {INJECTED-VIEW-NAV-END} -->"; |
| 46 | 46 | ||
| 47 | - | ||
| 48 | private static final String NAV_FORMAT = | 47 | private static final String NAV_FORMAT = |
| 49 | "<a ng-click=\"navCtrl.hideNav()\" href=\"#/%s\">%s</a>\n"; | 48 | "<a ng-click=\"navCtrl.hideNav()\" href=\"#/%s\">%s</a>\n"; |
| 50 | 49 | ... | ... |
| ... | @@ -38,6 +38,8 @@ import java.util.Set; | ... | @@ -38,6 +38,8 @@ import java.util.Set; |
| 38 | 38 | ||
| 39 | import static com.google.common.collect.ImmutableList.of; | 39 | import static com.google.common.collect.ImmutableList.of; |
| 40 | import static java.util.stream.Collectors.toSet; | 40 | import static java.util.stream.Collectors.toSet; |
| 41 | +import static org.onosproject.ui.UiView.Category.NETWORK; | ||
| 42 | +import static org.onosproject.ui.UiView.Category.PLATFORM; | ||
| 41 | 43 | ||
| 42 | /** | 44 | /** |
| 43 | * Manages the user interface extensions. | 45 | * Manages the user interface extensions. |
| ... | @@ -60,14 +62,14 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { | ... | @@ -60,14 +62,14 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { |
| 60 | 62 | ||
| 61 | // Creates core UI extension | 63 | // Creates core UI extension |
| 62 | private static UiExtension createCoreExtension() { | 64 | private static UiExtension createCoreExtension() { |
| 63 | - List<UiView> coreViews = of(new UiView("topo", "Topology"), | 65 | + List<UiView> coreViews = of(new UiView(PLATFORM, "app", "Applications"), |
| 64 | - new UiView("device", "Devices"), | 66 | + new UiView(PLATFORM, "cluster", "Cluster Nodes"), |
| 67 | + new UiView(NETWORK, "topo", "Topology"), | ||
| 68 | + new UiView(NETWORK, "device", "Devices"), | ||
| 65 | new UiViewHidden("flow"), | 69 | new UiViewHidden("flow"), |
| 66 | - new UiView("link", "Links"), | 70 | + new UiView(NETWORK, "link", "Links"), |
| 67 | - new UiView("host", "Hosts"), | 71 | + new UiView(NETWORK, "host", "Hosts"), |
| 68 | - new UiView("intent", "Intents"), | 72 | + new UiView(NETWORK, "intent", "Intents")); |
| 69 | - new UiView("app", "Applications"), | ||
| 70 | - new UiView("cluster", "Cluster Nodes")); | ||
| 71 | 73 | ||
| 72 | UiMessageHandlerFactory messageHandlerFactory = | 74 | UiMessageHandlerFactory messageHandlerFactory = |
| 73 | () -> ImmutableList.of( | 75 | () -> ImmutableList.of( | ... | ... |
| ... | @@ -106,7 +106,7 @@ | ... | @@ -106,7 +106,7 @@ |
| 106 | // If view ID not provided, route to the first view in the list. | 106 | // If view ID not provided, route to the first view in the list. |
| 107 | $routeProvider | 107 | $routeProvider |
| 108 | .otherwise({ | 108 | .otherwise({ |
| 109 | - redirectTo: '/' + viewIds[0] | 109 | + redirectTo: '/topo' |
| 110 | }); | 110 | }); |
| 111 | 111 | ||
| 112 | function viewCtrlName(vid) { | 112 | function viewCtrlName(vid) { | ... | ... |
-
Please register or login to post a comment