GUI -- Clean up of index.html and onos.js generation.
Change-Id: Icc1cdeb0e36b29bb76cee9d90fb342e131b78644
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
index a30c047..ac1a8bb 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
@@ -62,9 +62,9 @@
InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
String index = new String(toByteArray(indexTemplate));
- int p1s = split(index, 0, INJECT_JS_START);
+ int p1s = split(index, 0, INJECT_JS_START) - INJECT_JS_START.length();
int p1e = split(index, p1s, INJECT_JS_END);
- int p2s = split(index, p1e, INJECT_CSS_START);
+ int p2s = split(index, p1e, INJECT_CSS_START) - INJECT_CSS_START.length();
int p2e = split(index, p2s, INJECT_CSS_END);
int p3s = split(index, p2e, null);
@@ -78,17 +78,23 @@
return Response.ok(new SequenceInputStream(streams)).build();
}
- // Produces an input stream including CSS injections from all extensions.
- private InputStream includeCss(UiExtensionService service) {
- Builder<InputStream> builder = ImmutableList.builder();
- service.getExtensions().forEach(ext -> add(builder, ext.css()));
- return new SequenceInputStream(new StreamEnumeration(builder.build()));
- }
-
// Produces an input stream including JS injections from all extensions.
private InputStream includeJs(UiExtensionService service) {
Builder<InputStream> builder = ImmutableList.builder();
- service.getExtensions().forEach(ext -> add(builder, ext.js()));
+ service.getExtensions().forEach(ext -> {
+ add(builder, ext.js());
+ add(builder, new NewlineInputStream());
+ });
+ return new SequenceInputStream(new StreamEnumeration(builder.build()));
+ }
+
+ // Produces an input stream including CSS injections from all extensions.
+ private InputStream includeCss(UiExtensionService service) {
+ Builder<InputStream> builder = ImmutableList.builder();
+ service.getExtensions().forEach(ext -> {
+ add(builder, ext.css());
+ add(builder, new NewlineInputStream());
+ });
return new SequenceInputStream(new StreamEnumeration(builder.build()));
}
@@ -99,4 +105,19 @@
}
}
+ private static final String NL = String.format("%n");
+ private static final byte[] NL_BYTES = NL.getBytes();
+
+ private static class NewlineInputStream extends InputStream {
+ private int index = 0;
+
+ @Override
+ public int read() throws IOException {
+ if (index == NL_BYTES.length) {
+ return -1;
+ }
+ return NL_BYTES[index++];
+ }
+ }
+
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java
index 42d1dff..92725d9 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java
@@ -43,6 +43,8 @@
private static final String INJECT_VIEW_IDS_START = "// {INJECTED-VIEW-IDS-START}";
private static final String INJECT_VIEW_IDS_END = "// {INJECTED-VIEW-IDS-END}";
+ private static final String PREFIX = " '";
+ private static final String SUFFIX = String.format("',%n");
@GET
@Produces(SCRIPT)
@@ -51,7 +53,7 @@
InputStream jsTemplate = getClass().getClassLoader().getResourceAsStream(MAIN_JS);
String js = new String(toByteArray(jsTemplate));
- int p1s = split(js, 0, INJECT_VIEW_IDS_START);
+ int p1s = split(js, 0, INJECT_VIEW_IDS_START) - INJECT_VIEW_IDS_START.length();
int p1e = split(js, 0, INJECT_VIEW_IDS_END);
int p2s = split(js, p1e, null);
@@ -68,7 +70,7 @@
StringBuilder sb = new StringBuilder("\n");
for (UiExtension extension : service.getExtensions()) {
for (UiView view : extension.views()) {
- sb.append(" '").append(view.id()).append("',");
+ sb.append(PREFIX).append(view.id()).append(SUFFIX);
}
}
return new ByteArrayInputStream(sb.toString().getBytes());
diff --git a/web/gui/src/main/resources/core/css.html b/web/gui/src/main/resources/core/css.html
index 97bee6b..49f4ff6 100644
--- a/web/gui/src/main/resources/core/css.html
+++ b/web/gui/src/main/resources/core/css.html
@@ -1 +1 @@
-<!-- Builtin view stylesheets are in the main index.html -->
+<!-- Builtin view stylesheets defined in index.html template -->
diff --git a/web/gui/src/main/resources/core/js.html b/web/gui/src/main/resources/core/js.html
index 8e2269b..01fb039 100644
--- a/web/gui/src/main/resources/core/js.html
+++ b/web/gui/src/main/resources/core/js.html
@@ -1 +1 @@
-<!-- Builtin view javascript is in the main index.html -->
\ No newline at end of file
+<!-- Builtin view javascript defined in index.html template -->
diff --git a/web/gui/src/main/webapp/app/fw/util/fn.js b/web/gui/src/main/webapp/app/fw/util/fn.js
index defb845..14060b9 100644
--- a/web/gui/src/main/webapp/app/fw/util/fn.js
+++ b/web/gui/src/main/webapp/app/fw/util/fn.js
@@ -223,9 +223,7 @@
// return the given string with the first character capitalized.
function cap(s) {
- return s.toLowerCase().replace(/^[a-z]/, function (m) {
- return m.toUpperCase();
- });
+ return s ? s[0].toUpperCase() + s.slice(1) : s;
}
// return the parameter without a px suffix
diff --git a/web/gui/src/main/webapp/app/view/app/app.js b/web/gui/src/main/webapp/app/view/app/app.js
index 2cca7c0..16c1e72 100644
--- a/web/gui/src/main/webapp/app/view/app/app.js
+++ b/web/gui/src/main/webapp/app/view/app/app.js
@@ -326,13 +326,9 @@
['scroll down', 'See more apps']
]);
- function capitalize(s) {
- return s ? s[0].toUpperCase() + s.slice(1) : s;
- }
-
function createConfirmationText(action, itemId) {
var content = ds.createDiv();
- content.append('p').text(capitalize(action) + ' ' + itemId);
+ content.append('p').text(fs.cap(action) + ' ' + itemId);
if (strongWarning[itemId]) {
content.append('p').text(discouragement).classed('strong', true);
}
diff --git a/web/gui/src/main/webapp/index.html b/web/gui/src/main/webapp/index.html
index adead69..3d22c9a 100644
--- a/web/gui/src/main/webapp/index.html
+++ b/web/gui/src/main/webapp/index.html
@@ -130,7 +130,7 @@
<script src="app/view/processor/processor.js"></script>
<script src="app/view/tunnel/tunnel.js"></script>
- <!-- This is where contributed javascript will get injected -->
+ <!-- Contributed javascript injected here -->
<!-- {INJECTED-JAVASCRIPT-START} -->
<!-- {INJECTED-JAVASCRIPT-END} -->
@@ -150,7 +150,7 @@
<link rel="stylesheet" href="app/view/processor/processor.css">
<link rel="stylesheet" href="app/view/tunnel/tunnel.css">
- <!-- This is where contributed stylesheets will get injected -->
+ <!-- Contributed stylesheets injected here -->
<!-- {INJECTED-STYLESHEETS-START} -->
<!-- {INJECTED-STYLESHEETS-END} -->
diff --git a/web/gui/src/main/webapp/onos.js b/web/gui/src/main/webapp/onos.js
index fcb9310..2fffb24 100644
--- a/web/gui/src/main/webapp/onos.js
+++ b/web/gui/src/main/webapp/onos.js
@@ -33,38 +33,27 @@
'onosWidget'
];
- // view IDs.. note the first view listed is loaded at startup
+ // view IDs.. injected via the servlet
var viewIds = [
// {INJECTED-VIEW-IDS-START}
- 'topo',
- 'device',
- 'flow',
- 'port',
- 'group',
- 'meter',
- 'host',
- 'app',
- 'intent',
- 'cluster',
- 'link',
// {INJECTED-VIEW-IDS-END}
-
// dummy entry
''
];
- var viewDependencies = [];
+ var defaultView = 'topo',
+ viewDependencies = [];
viewIds.forEach(function (id) {
if (id) {
- viewDependencies.push('ov' + capitalize(id));
+ viewDependencies.push('ov' + cap(id));
}
});
var moduleDependencies = coreDependencies.concat(viewDependencies);
- function capitalize(word) {
- return word ? word[0].toUpperCase() + word.slice(1) : word;
+ function cap(s) {
+ return s ? s[0].toUpperCase() + s.slice(1) : s;
}
angular.module('onosApp', moduleDependencies)
@@ -97,8 +86,6 @@
flash.initFlash();
qhs.initQuickHelp();
- // TODO: register handler for user settings, etc.
-
wss.createWebSocket({
wsport: $location.search().wsport
});
@@ -111,14 +98,14 @@
}])
.config(['$routeProvider', function ($routeProvider) {
- // If view ID not provided, route to the first view in the list.
+ // If view ID not provided, route to the default view
$routeProvider
.otherwise({
- redirectTo: '/topo'
+ redirectTo: '/' + defaultView
});
function viewCtrlName(vid) {
- return 'Ov' + capitalize(vid) + 'Ctrl';
+ return 'Ov' + cap(vid) + 'Ctrl';
}
function viewTemplateUrl(vid) {