Index: pkg/analysis_server/lib/src/status/pages.dart |
diff --git a/pkg/analysis_server/lib/src/status/pages.dart b/pkg/analysis_server/lib/src/status/pages.dart |
index 5bfb46dd071e85d8b759b1bb282532e41cee0a46..3faf60a603ab867fc83e938aa96a5413c4930534 100644 |
--- a/pkg/analysis_server/lib/src/status/pages.dart |
+++ b/pkg/analysis_server/lib/src/status/pages.dart |
@@ -8,79 +8,15 @@ import 'dart:io'; |
import 'package:intl/intl.dart'; |
-/// Contains a collection of Pages. |
-abstract class Site { |
- final String title; |
- List<Page> pages = []; |
- List<Page> secondaryPages = []; |
- |
- Site(this.title); |
- |
- String get customCss => ''; |
- |
- Future<Null> handleGetRequest(HttpRequest request) async { |
- try { |
- String path = request.uri.path; |
- |
- if (path == '/') { |
- respondRedirect(request, pages.first.path); |
- return; |
- } |
- |
- for (Page page in pages) { |
- if (page.path == path) { |
- HttpResponse response = request.response; |
- response.headers.contentType = ContentType.HTML; |
- response.write(await page.generate(request.uri.queryParameters)); |
- response.close(); |
- return; |
- } |
- } |
- |
- for (Page page in secondaryPages) { |
- if (page.path == path) { |
- HttpResponse response = request.response; |
- response.headers.contentType = ContentType.HTML; |
- response.write(await page.generate(request.uri.queryParameters)); |
- response.close(); |
- return; |
- } |
- } |
- |
- await respond(request, createUnknownPage(path), HttpStatus.NOT_FOUND); |
- } catch (e, st) { |
- try { |
- await respond(request, createExceptionPage('$e', st), |
- HttpStatus.INTERNAL_SERVER_ERROR); |
- } catch (e, st) { |
- HttpResponse response = request.response; |
- response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; |
- response.headers.contentType = ContentType.TEXT; |
- response.write('$e\n\n$st'); |
- response.close(); |
- } |
- } |
- } |
+final NumberFormat numberFormat = new NumberFormat.decimalPattern(); |
- Page createUnknownPage(String unknownPath); |
+String escape(String text) => text == null ? '' : HTML_ESCAPE.convert(text); |
- Page createExceptionPage(String message, StackTrace trace); |
+String printInteger(int value) => numberFormat.format(value); |
- Future<Null> respond(HttpRequest request, Page page, |
- [int code = HttpStatus.OK]) async { |
- HttpResponse response = request.response; |
- response.statusCode = code; |
- response.headers.contentType = ContentType.HTML; |
- response.write(await page.generate(request.uri.queryParameters)); |
- response.close(); |
- } |
+String printMilliseconds(num value) => '${numberFormat.format(value)} ms'; |
- void respondRedirect(HttpRequest request, String pathFragment) { |
- HttpResponse response = request.response; |
- response.statusCode = HttpStatus.MOVED_TEMPORARILY; |
- response.redirect(request.uri.resolve(pathFragment)); |
- } |
-} |
+String printPercentage(num value) => '${(value * 100).toStringAsFixed(1)}%'; |
/// An entity that knows how to serve itself over http. |
abstract class Page { |
@@ -94,6 +30,30 @@ abstract class Page { |
String get path => '/$id'; |
+ Future<Null> asyncDiv(void gen(), {String classes}) async { |
+ if (classes != null) { |
+ buf.writeln('<div class="$classes">'); |
+ } else { |
+ buf.writeln('<div>'); |
+ } |
+ await gen(); |
+ buf.writeln('</div>'); |
+ } |
+ |
+ void blankslate(String str) { |
+ div(() => buf.writeln(str), classes: 'blankslate'); |
+ } |
+ |
+ void div(void gen(), {String classes}) { |
+ if (classes != null) { |
+ buf.writeln('<div class="$classes">'); |
+ } else { |
+ buf.writeln('<div>'); |
+ } |
+ gen(); |
+ buf.writeln('</div>'); |
+ } |
+ |
Future<String> generate(Map<String, String> params) async { |
buf.clear(); |
await generatePage(params); |
@@ -122,16 +82,6 @@ abstract class Page { |
buf.writeln('<h4>${raw ? text : escape(text)}</h4>'); |
} |
- void ul<T>(Iterable<T> items, void gen(T item), {String classes}) { |
- buf.writeln('<ul${classes == null ? '' : ' class=$classes'}>'); |
- for (T item in items) { |
- buf.write('<li>'); |
- gen(item); |
- buf.write('</li>'); |
- } |
- buf.writeln('</ul>'); |
- } |
- |
void inputList<T>(Iterable<T> items, void gen(T item)) { |
buf.writeln('<select size="8" style="width: 100%">'); |
for (T item in items) { |
@@ -142,25 +92,7 @@ abstract class Page { |
buf.writeln('</select>'); |
} |
- Future<Null> asyncDiv(void gen(), {String classes}) async { |
- if (classes != null) { |
- buf.writeln('<div class="$classes">'); |
- } else { |
- buf.writeln('<div>'); |
- } |
- await gen(); |
- buf.writeln('</div>'); |
- } |
- |
- void div(void gen(), {String classes}) { |
- if (classes != null) { |
- buf.writeln('<div class="$classes">'); |
- } else { |
- buf.writeln('<div>'); |
- } |
- gen(); |
- buf.writeln('</div>'); |
- } |
+ bool isCurrentPage(String pathToTest) => path == pathToTest; |
void p(String text, {String style, bool raw: false, String classes}) { |
String c = classes == null ? '' : ' class="$classes"'; |
@@ -182,19 +114,87 @@ abstract class Page { |
buf.writeln('</pre>'); |
} |
- void blankslate(String str) { |
- div(() => buf.writeln(str), classes: 'blankslate'); |
+ void ul<T>(Iterable<T> items, void gen(T item), {String classes}) { |
+ buf.writeln('<ul${classes == null ? '' : ' class=$classes'}>'); |
+ for (T item in items) { |
+ buf.write('<li>'); |
+ gen(item); |
+ buf.write('</li>'); |
+ } |
+ buf.writeln('</ul>'); |
} |
- |
- bool isCurrentPage(String pathToTest) => path == pathToTest; |
} |
-String escape(String text) => text == null ? '' : HTML_ESCAPE.convert(text); |
+/// Contains a collection of Pages. |
+abstract class Site { |
+ final String title; |
+ List<Page> pages = []; |
+ List<Page> secondaryPages = []; |
-final NumberFormat numberFormat = new NumberFormat.decimalPattern(); |
+ Site(this.title); |
-String printInteger(int value) => numberFormat.format(value); |
+ String get customCss => ''; |
-String printMilliseconds(num value) => '${numberFormat.format(value)} ms'; |
+ Page createExceptionPage(String message, StackTrace trace); |
-String printPercentage(num value) => '${(value * 100).toStringAsFixed(1)}%'; |
+ Page createUnknownPage(String unknownPath); |
+ |
+ Future<Null> handleGetRequest(HttpRequest request) async { |
+ try { |
+ String path = request.uri.path; |
+ |
+ if (path == '/') { |
+ respondRedirect(request, pages.first.path); |
+ return; |
+ } |
+ |
+ for (Page page in pages) { |
+ if (page.path == path) { |
+ HttpResponse response = request.response; |
+ response.headers.contentType = ContentType.HTML; |
+ response.write(await page.generate(request.uri.queryParameters)); |
+ response.close(); |
+ return; |
+ } |
+ } |
+ |
+ for (Page page in secondaryPages) { |
+ if (page.path == path) { |
+ HttpResponse response = request.response; |
+ response.headers.contentType = ContentType.HTML; |
+ response.write(await page.generate(request.uri.queryParameters)); |
+ response.close(); |
+ return; |
+ } |
+ } |
+ |
+ await respond(request, createUnknownPage(path), HttpStatus.NOT_FOUND); |
+ } catch (e, st) { |
+ try { |
+ await respond(request, createExceptionPage('$e', st), |
+ HttpStatus.INTERNAL_SERVER_ERROR); |
+ } catch (e, st) { |
+ HttpResponse response = request.response; |
+ response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; |
+ response.headers.contentType = ContentType.TEXT; |
+ response.write('$e\n\n$st'); |
+ response.close(); |
+ } |
+ } |
+ } |
+ |
+ Future<Null> respond(HttpRequest request, Page page, |
+ [int code = HttpStatus.OK]) async { |
+ HttpResponse response = request.response; |
+ response.statusCode = code; |
+ response.headers.contentType = ContentType.HTML; |
+ response.write(await page.generate(request.uri.queryParameters)); |
+ response.close(); |
+ } |
+ |
+ void respondRedirect(HttpRequest request, String pathFragment) { |
+ HttpResponse response = request.response; |
+ response.statusCode = HttpStatus.MOVED_TEMPORARILY; |
+ response.redirect(request.uri.resolve(pathFragment)); |
+ } |
+} |