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 {
private static final String INJECT_JS_END = "<!-- {INJECTED-JAVASCRIPT-END} -->";
private static final byte[] SCRIPT_START = "\n<script>\n".getBytes();
private static final byte[] SCRIPT_END = "\n</script>\n\n".getBytes();
private static final byte[] SCRIPT_END = "</script>\n\n".getBytes();
@Context
private SecurityContext ctx;
......@@ -93,6 +93,7 @@ public class MainIndexResource extends AbstractInjectionResource {
new ByteArrayInputStream(SCRIPT_START),
stream(auth, 0, auth.length()),
userPreferences(userName),
userConsoleLog(userName),
new ByteArrayInputStream(SCRIPT_END),
stream(index, p0e, p1s),
includeJs(service),
......@@ -103,12 +104,17 @@ public class MainIndexResource extends AbstractInjectionResource {
return Response.ok(new SequenceInputStream(streams)).build();
}
private InputStream userConsoleLog(String userName) {
String code = "console.log('Logging in as user >" + userName + "<');\n";
return new ByteArrayInputStream(code.getBytes());
}
// Produces an input stream including user preferences.
private InputStream userPreferences(String userName) {
UiPreferencesService service = get(UiPreferencesService.class);
ObjectNode prefs = mapper().createObjectNode();
service.getPreferences(userName).forEach(prefs::set);
String string = "var userPrefs = " + prefs.toString() + ";";
String string = "var userPrefs = " + prefs.toString() + ";\n";
return new ByteArrayInputStream(string.getBytes());
}
......