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;
...@@ -93,6 +93,7 @@ public class MainIndexResource extends AbstractInjectionResource { ...@@ -93,6 +93,7 @@ public class MainIndexResource extends AbstractInjectionResource {
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 + userConsoleLog(userName),
96 new ByteArrayInputStream(SCRIPT_END), 97 new ByteArrayInputStream(SCRIPT_END),
97 stream(index, p0e, p1s), 98 stream(index, p0e, p1s),
98 includeJs(service), 99 includeJs(service),
...@@ -103,12 +104,17 @@ public class MainIndexResource extends AbstractInjectionResource { ...@@ -103,12 +104,17 @@ public class MainIndexResource extends AbstractInjectionResource {
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
......