Simon Hunt

GUI -- Clean up of index.html and onos.js generation.

Change-Id: Icc1cdeb0e36b29bb76cee9d90fb342e131b78644
......@@ -62,9 +62,9 @@ public class MainIndexResource extends AbstractInjectionResource {
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 @@ public class MainIndexResource extends AbstractInjectionResource {
return Response.ok(new SequenceInputStream(streams)).build();
}
// Produces an input stream including CSS injections from all extensions.
private InputStream includeCss(UiExtensionService service) {
// 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.css()));
service.getExtensions().forEach(ext -> {
add(builder, ext.js());
add(builder, new NewlineInputStream());
});
return new SequenceInputStream(new StreamEnumeration(builder.build()));
}
// Produces an input stream including JS injections from all extensions.
private InputStream includeJs(UiExtensionService service) {
// 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.js()));
service.getExtensions().forEach(ext -> {
add(builder, ext.css());
add(builder, new NewlineInputStream());
});
return new SequenceInputStream(new StreamEnumeration(builder.build()));
}
......@@ -99,4 +105,19 @@ public class MainIndexResource extends AbstractInjectionResource {
}
}
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++];
}
}
}
......
......@@ -43,6 +43,8 @@ public class MainModuleResource extends AbstractInjectionResource {
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 @@ public class MainModuleResource extends AbstractInjectionResource {
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 @@ public class MainModuleResource extends AbstractInjectionResource {
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());
......
<!-- Builtin view stylesheets are in the main index.html -->
<!-- Builtin view stylesheets defined in index.html template -->
......
<!-- Builtin view javascript is in the main index.html -->
\ No newline at end of file
<!-- Builtin view javascript defined in index.html template -->
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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} -->
......
......@@ -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) {
......