Simon Hunt
Committed by Gerrit Code Review

GUI -- Log the name of the logged-in user to the Javascript console, at beginning of index.html.

Change-Id: I973023edbb4aa1af3af816fc59895e8ab026192d
...@@ -57,7 +57,7 @@ public class MainIndexResource extends AbstractInjectionResource { ...@@ -57,7 +57,7 @@ public class MainIndexResource extends AbstractInjectionResource {
57 private static final String INJECT_JS_END = "<!-- {INJECTED-JAVASCRIPT-END} -->"; 57 private static final String INJECT_JS_END = "<!-- {INJECTED-JAVASCRIPT-END} -->";
58 58
59 private static final byte[] SCRIPT_START = "\n<script>\n".getBytes(); 59 private static final byte[] SCRIPT_START = "\n<script>\n".getBytes();
60 - private static final byte[] SCRIPT_END = "\n</script>\n\n".getBytes(); 60 + private static final byte[] SCRIPT_END = "</script>\n\n".getBytes();
61 61
62 @Context 62 @Context
63 private SecurityContext ctx; 63 private SecurityContext ctx;
...@@ -90,25 +90,31 @@ public class MainIndexResource extends AbstractInjectionResource { ...@@ -90,25 +90,31 @@ public class MainIndexResource extends AbstractInjectionResource {
90 90
91 StreamEnumeration streams = 91 StreamEnumeration streams =
92 new StreamEnumeration(of(stream(index, 0, p0s), 92 new StreamEnumeration(of(stream(index, 0, p0s),
93 - new ByteArrayInputStream(SCRIPT_START), 93 + new ByteArrayInputStream(SCRIPT_START),
94 - stream(auth, 0, auth.length()), 94 + stream(auth, 0, auth.length()),
95 - userPreferences(userName), 95 + userPreferences(userName),
96 - new ByteArrayInputStream(SCRIPT_END), 96 + userConsoleLog(userName),
97 - stream(index, p0e, p1s), 97 + new ByteArrayInputStream(SCRIPT_END),
98 - includeJs(service), 98 + stream(index, p0e, p1s),
99 - stream(index, p1e, p2s), 99 + includeJs(service),
100 - includeCss(service), 100 + stream(index, p1e, p2s),
101 - stream(index, p2e, p3s))); 101 + includeCss(service),
102 + stream(index, p2e, p3s)));
102 103
103 return Response.ok(new SequenceInputStream(streams)).build(); 104 return Response.ok(new SequenceInputStream(streams)).build();
104 } 105 }
105 106
107 + private InputStream userConsoleLog(String userName) {
108 + String code = "console.log('Logging in as user >" + userName + "<');\n";
109 + return new ByteArrayInputStream(code.getBytes());
110 + }
111 +
106 // Produces an input stream including user preferences. 112 // Produces an input stream including user preferences.
107 private InputStream userPreferences(String userName) { 113 private InputStream userPreferences(String userName) {
108 UiPreferencesService service = get(UiPreferencesService.class); 114 UiPreferencesService service = get(UiPreferencesService.class);
109 ObjectNode prefs = mapper().createObjectNode(); 115 ObjectNode prefs = mapper().createObjectNode();
110 service.getPreferences(userName).forEach(prefs::set); 116 service.getPreferences(userName).forEach(prefs::set);
111 - String string = "var userPrefs = " + prefs.toString() + ";"; 117 + String string = "var userPrefs = " + prefs.toString() + ";\n";
112 return new ByteArrayInputStream(string.getBytes()); 118 return new ByteArrayInputStream(string.getBytes());
113 } 119 }
114 120
......