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

Change-Id: I973023edbb4aa1af3af816fc59895e8ab026192d
This commit is contained in:
Simon Hunt 2016-05-04 14:49:03 -07:00 committed by Gerrit Code Review
parent 673c3e062f
commit 23f21e317e

View File

@ -57,7 +57,7 @@ public class MainIndexResource extends AbstractInjectionResource {
private static final String INJECT_JS_END = "<!-- {INJECTED-JAVASCRIPT-END} -->"; 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_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 @Context
private SecurityContext ctx; private SecurityContext ctx;
@ -90,25 +90,31 @@ public class MainIndexResource extends AbstractInjectionResource {
StreamEnumeration streams = StreamEnumeration streams =
new StreamEnumeration(of(stream(index, 0, p0s), new StreamEnumeration(of(stream(index, 0, p0s),
new ByteArrayInputStream(SCRIPT_START), new ByteArrayInputStream(SCRIPT_START),
stream(auth, 0, auth.length()), stream(auth, 0, auth.length()),
userPreferences(userName), userPreferences(userName),
new ByteArrayInputStream(SCRIPT_END), userConsoleLog(userName),
stream(index, p0e, p1s), new ByteArrayInputStream(SCRIPT_END),
includeJs(service), stream(index, p0e, p1s),
stream(index, p1e, p2s), includeJs(service),
includeCss(service), stream(index, p1e, p2s),
stream(index, p2e, p3s))); includeCss(service),
stream(index, p2e, p3s)));
return Response.ok(new SequenceInputStream(streams)).build(); 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. // Produces an input stream including user preferences.
private InputStream userPreferences(String userName) { private InputStream userPreferences(String userName) {
UiPreferencesService service = get(UiPreferencesService.class); UiPreferencesService service = get(UiPreferencesService.class);
ObjectNode prefs = mapper().createObjectNode(); ObjectNode prefs = mapper().createObjectNode();
service.getPreferences(userName).forEach(prefs::set); service.getPreferences(userName).forEach(prefs::set);
String string = "var userPrefs = " + prefs.toString() + ";"; String string = "var userPrefs = " + prefs.toString() + ";\n";
return new ByteArrayInputStream(string.getBytes()); return new ByteArrayInputStream(string.getBytes());
} }