Simon Hunt

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

Change-Id: Icc1cdeb0e36b29bb76cee9d90fb342e131b78644
...@@ -62,9 +62,9 @@ public class MainIndexResource extends AbstractInjectionResource { ...@@ -62,9 +62,9 @@ public class MainIndexResource extends AbstractInjectionResource {
62 InputStream indexTemplate = classLoader.getResourceAsStream(INDEX); 62 InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
63 String index = new String(toByteArray(indexTemplate)); 63 String index = new String(toByteArray(indexTemplate));
64 64
65 - int p1s = split(index, 0, INJECT_JS_START); 65 + int p1s = split(index, 0, INJECT_JS_START) - INJECT_JS_START.length();
66 int p1e = split(index, p1s, INJECT_JS_END); 66 int p1e = split(index, p1s, INJECT_JS_END);
67 - int p2s = split(index, p1e, INJECT_CSS_START); 67 + int p2s = split(index, p1e, INJECT_CSS_START) - INJECT_CSS_START.length();
68 int p2e = split(index, p2s, INJECT_CSS_END); 68 int p2e = split(index, p2s, INJECT_CSS_END);
69 int p3s = split(index, p2e, null); 69 int p3s = split(index, p2e, null);
70 70
...@@ -78,17 +78,23 @@ public class MainIndexResource extends AbstractInjectionResource { ...@@ -78,17 +78,23 @@ public class MainIndexResource extends AbstractInjectionResource {
78 return Response.ok(new SequenceInputStream(streams)).build(); 78 return Response.ok(new SequenceInputStream(streams)).build();
79 } 79 }
80 80
81 - // Produces an input stream including CSS injections from all extensions. 81 + // Produces an input stream including JS injections from all extensions.
82 - private InputStream includeCss(UiExtensionService service) { 82 + private InputStream includeJs(UiExtensionService service) {
83 Builder<InputStream> builder = ImmutableList.builder(); 83 Builder<InputStream> builder = ImmutableList.builder();
84 - service.getExtensions().forEach(ext -> add(builder, ext.css())); 84 + service.getExtensions().forEach(ext -> {
85 + add(builder, ext.js());
86 + add(builder, new NewlineInputStream());
87 + });
85 return new SequenceInputStream(new StreamEnumeration(builder.build())); 88 return new SequenceInputStream(new StreamEnumeration(builder.build()));
86 } 89 }
87 90
88 - // Produces an input stream including JS injections from all extensions. 91 + // Produces an input stream including CSS injections from all extensions.
89 - private InputStream includeJs(UiExtensionService service) { 92 + private InputStream includeCss(UiExtensionService service) {
90 Builder<InputStream> builder = ImmutableList.builder(); 93 Builder<InputStream> builder = ImmutableList.builder();
91 - service.getExtensions().forEach(ext -> add(builder, ext.js())); 94 + service.getExtensions().forEach(ext -> {
95 + add(builder, ext.css());
96 + add(builder, new NewlineInputStream());
97 + });
92 return new SequenceInputStream(new StreamEnumeration(builder.build())); 98 return new SequenceInputStream(new StreamEnumeration(builder.build()));
93 } 99 }
94 100
...@@ -99,4 +105,19 @@ public class MainIndexResource extends AbstractInjectionResource { ...@@ -99,4 +105,19 @@ public class MainIndexResource extends AbstractInjectionResource {
99 } 105 }
100 } 106 }
101 107
108 + private static final String NL = String.format("%n");
109 + private static final byte[] NL_BYTES = NL.getBytes();
110 +
111 + private static class NewlineInputStream extends InputStream {
112 + private int index = 0;
113 +
114 + @Override
115 + public int read() throws IOException {
116 + if (index == NL_BYTES.length) {
117 + return -1;
118 + }
119 + return NL_BYTES[index++];
120 + }
121 + }
122 +
102 } 123 }
......
...@@ -43,6 +43,8 @@ public class MainModuleResource extends AbstractInjectionResource { ...@@ -43,6 +43,8 @@ public class MainModuleResource extends AbstractInjectionResource {
43 43
44 private static final String INJECT_VIEW_IDS_START = "// {INJECTED-VIEW-IDS-START}"; 44 private static final String INJECT_VIEW_IDS_START = "// {INJECTED-VIEW-IDS-START}";
45 private static final String INJECT_VIEW_IDS_END = "// {INJECTED-VIEW-IDS-END}"; 45 private static final String INJECT_VIEW_IDS_END = "// {INJECTED-VIEW-IDS-END}";
46 + private static final String PREFIX = " '";
47 + private static final String SUFFIX = String.format("',%n");
46 48
47 @GET 49 @GET
48 @Produces(SCRIPT) 50 @Produces(SCRIPT)
...@@ -51,7 +53,7 @@ public class MainModuleResource extends AbstractInjectionResource { ...@@ -51,7 +53,7 @@ public class MainModuleResource extends AbstractInjectionResource {
51 InputStream jsTemplate = getClass().getClassLoader().getResourceAsStream(MAIN_JS); 53 InputStream jsTemplate = getClass().getClassLoader().getResourceAsStream(MAIN_JS);
52 String js = new String(toByteArray(jsTemplate)); 54 String js = new String(toByteArray(jsTemplate));
53 55
54 - int p1s = split(js, 0, INJECT_VIEW_IDS_START); 56 + int p1s = split(js, 0, INJECT_VIEW_IDS_START) - INJECT_VIEW_IDS_START.length();
55 int p1e = split(js, 0, INJECT_VIEW_IDS_END); 57 int p1e = split(js, 0, INJECT_VIEW_IDS_END);
56 int p2s = split(js, p1e, null); 58 int p2s = split(js, p1e, null);
57 59
...@@ -68,7 +70,7 @@ public class MainModuleResource extends AbstractInjectionResource { ...@@ -68,7 +70,7 @@ public class MainModuleResource extends AbstractInjectionResource {
68 StringBuilder sb = new StringBuilder("\n"); 70 StringBuilder sb = new StringBuilder("\n");
69 for (UiExtension extension : service.getExtensions()) { 71 for (UiExtension extension : service.getExtensions()) {
70 for (UiView view : extension.views()) { 72 for (UiView view : extension.views()) {
71 - sb.append(" '").append(view.id()).append("',"); 73 + sb.append(PREFIX).append(view.id()).append(SUFFIX);
72 } 74 }
73 } 75 }
74 return new ByteArrayInputStream(sb.toString().getBytes()); 76 return new ByteArrayInputStream(sb.toString().getBytes());
......
1 -<!-- Builtin view stylesheets are in the main index.html --> 1 +<!-- Builtin view stylesheets defined in index.html template -->
......
1 -<!-- Builtin view javascript is in the main index.html -->
...\ No newline at end of file ...\ No newline at end of file
1 +<!-- Builtin view javascript defined in index.html template -->
......
...@@ -223,9 +223,7 @@ ...@@ -223,9 +223,7 @@
223 223
224 // return the given string with the first character capitalized. 224 // return the given string with the first character capitalized.
225 function cap(s) { 225 function cap(s) {
226 - return s.toLowerCase().replace(/^[a-z]/, function (m) { 226 + return s ? s[0].toUpperCase() + s.slice(1) : s;
227 - return m.toUpperCase();
228 - });
229 } 227 }
230 228
231 // return the parameter without a px suffix 229 // return the parameter without a px suffix
......
...@@ -326,13 +326,9 @@ ...@@ -326,13 +326,9 @@
326 ['scroll down', 'See more apps'] 326 ['scroll down', 'See more apps']
327 ]); 327 ]);
328 328
329 - function capitalize(s) {
330 - return s ? s[0].toUpperCase() + s.slice(1) : s;
331 - }
332 -
333 function createConfirmationText(action, itemId) { 329 function createConfirmationText(action, itemId) {
334 var content = ds.createDiv(); 330 var content = ds.createDiv();
335 - content.append('p').text(capitalize(action) + ' ' + itemId); 331 + content.append('p').text(fs.cap(action) + ' ' + itemId);
336 if (strongWarning[itemId]) { 332 if (strongWarning[itemId]) {
337 content.append('p').text(discouragement).classed('strong', true); 333 content.append('p').text(discouragement).classed('strong', true);
338 } 334 }
......
...@@ -130,7 +130,7 @@ ...@@ -130,7 +130,7 @@
130 <script src="app/view/processor/processor.js"></script> 130 <script src="app/view/processor/processor.js"></script>
131 <script src="app/view/tunnel/tunnel.js"></script> 131 <script src="app/view/tunnel/tunnel.js"></script>
132 132
133 - <!-- This is where contributed javascript will get injected --> 133 + <!-- Contributed javascript injected here -->
134 <!-- {INJECTED-JAVASCRIPT-START} --> 134 <!-- {INJECTED-JAVASCRIPT-START} -->
135 <!-- {INJECTED-JAVASCRIPT-END} --> 135 <!-- {INJECTED-JAVASCRIPT-END} -->
136 136
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
150 <link rel="stylesheet" href="app/view/processor/processor.css"> 150 <link rel="stylesheet" href="app/view/processor/processor.css">
151 <link rel="stylesheet" href="app/view/tunnel/tunnel.css"> 151 <link rel="stylesheet" href="app/view/tunnel/tunnel.css">
152 152
153 - <!-- This is where contributed stylesheets will get injected --> 153 + <!-- Contributed stylesheets injected here -->
154 <!-- {INJECTED-STYLESHEETS-START} --> 154 <!-- {INJECTED-STYLESHEETS-START} -->
155 <!-- {INJECTED-STYLESHEETS-END} --> 155 <!-- {INJECTED-STYLESHEETS-END} -->
156 156
......
...@@ -33,38 +33,27 @@ ...@@ -33,38 +33,27 @@
33 'onosWidget' 33 'onosWidget'
34 ]; 34 ];
35 35
36 - // view IDs.. note the first view listed is loaded at startup 36 + // view IDs.. injected via the servlet
37 var viewIds = [ 37 var viewIds = [
38 // {INJECTED-VIEW-IDS-START} 38 // {INJECTED-VIEW-IDS-START}
39 - 'topo',
40 - 'device',
41 - 'flow',
42 - 'port',
43 - 'group',
44 - 'meter',
45 - 'host',
46 - 'app',
47 - 'intent',
48 - 'cluster',
49 - 'link',
50 // {INJECTED-VIEW-IDS-END} 39 // {INJECTED-VIEW-IDS-END}
51 -
52 // dummy entry 40 // dummy entry
53 '' 41 ''
54 ]; 42 ];
55 43
56 - var viewDependencies = []; 44 + var defaultView = 'topo',
45 + viewDependencies = [];
57 46
58 viewIds.forEach(function (id) { 47 viewIds.forEach(function (id) {
59 if (id) { 48 if (id) {
60 - viewDependencies.push('ov' + capitalize(id)); 49 + viewDependencies.push('ov' + cap(id));
61 } 50 }
62 }); 51 });
63 52
64 var moduleDependencies = coreDependencies.concat(viewDependencies); 53 var moduleDependencies = coreDependencies.concat(viewDependencies);
65 54
66 - function capitalize(word) { 55 + function cap(s) {
67 - return word ? word[0].toUpperCase() + word.slice(1) : word; 56 + return s ? s[0].toUpperCase() + s.slice(1) : s;
68 } 57 }
69 58
70 angular.module('onosApp', moduleDependencies) 59 angular.module('onosApp', moduleDependencies)
...@@ -97,8 +86,6 @@ ...@@ -97,8 +86,6 @@
97 flash.initFlash(); 86 flash.initFlash();
98 qhs.initQuickHelp(); 87 qhs.initQuickHelp();
99 88
100 - // TODO: register handler for user settings, etc.
101 -
102 wss.createWebSocket({ 89 wss.createWebSocket({
103 wsport: $location.search().wsport 90 wsport: $location.search().wsport
104 }); 91 });
...@@ -111,14 +98,14 @@ ...@@ -111,14 +98,14 @@
111 }]) 98 }])
112 99
113 .config(['$routeProvider', function ($routeProvider) { 100 .config(['$routeProvider', function ($routeProvider) {
114 - // If view ID not provided, route to the first view in the list. 101 + // If view ID not provided, route to the default view
115 $routeProvider 102 $routeProvider
116 .otherwise({ 103 .otherwise({
117 - redirectTo: '/topo' 104 + redirectTo: '/' + defaultView
118 }); 105 });
119 106
120 function viewCtrlName(vid) { 107 function viewCtrlName(vid) {
121 - return 'Ov' + capitalize(vid) + 'Ctrl'; 108 + return 'Ov' + cap(vid) + 'Ctrl';
122 } 109 }
123 110
124 function viewTemplateUrl(vid) { 111 function viewTemplateUrl(vid) {
......