Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library error_view_element; | 5 library error_view_element; |
| 6 | 6 |
| 7 import 'observatory_element.dart'; | 7 import 'dart:html'; |
| 8 import 'package:polymer/polymer.dart'; | 8 import 'dart:async'; |
| 9 import 'package:observatory/service.dart'; | 9 import 'package:observatory/models.dart' as M; |
| 10 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | |
| 11 import 'package:observatory/src/elements/helpers/tag.dart'; | |
| 12 import 'package:observatory/src/elements/nav/bar.dart'; | |
| 13 import 'package:observatory/src/elements/nav/notify.dart'; | |
| 14 import 'package:observatory/src/elements/nav/top_menu.dart'; | |
| 15 import 'package:observatory/src/elements/view_footer.dart'; | |
| 10 | 16 |
| 11 /// Displays an Error ServiceObject. | 17 class ErrorViewElement extends HtmlElement implements Renderable{ |
| 12 @CustomTag('error-view') | 18 static const tag = const Tag<ErrorViewElement>('error-view', |
| 13 class ErrorViewElement extends ObservatoryElement { | 19 dependencies: const [NavBarElement.tag, |
| 14 @published DartError error; | 20 NavTopMenuElement.tag, |
| 21 NavNotifyElement.tag, | |
| 22 ViewFooterElement.tag]); | |
| 23 | |
| 24 RenderingScheduler _r; | |
| 25 | |
| 26 Stream<RenderedEvent<ErrorViewElement>> get onRendered => | |
| 27 _r.onRendered; | |
| 28 | |
| 29 M.Error _error; | |
| 30 M.NotificationRepository _notifications; | |
| 31 | |
| 32 M.Error get error => _error; | |
| 33 | |
| 34 factory ErrorViewElement(M.NotificationRepository notifications, | |
| 35 M.Error error, | |
| 36 {RenderingQueue queue}) { | |
| 37 assert(error != null); | |
| 38 assert(notifications != null); | |
| 39 ErrorViewElement e = document.createElement(tag.name); | |
| 40 e._r = new RenderingScheduler(e, queue: queue); | |
| 41 e._error = error; | |
| 42 e._notifications = notifications; | |
| 43 return e; | |
| 44 } | |
| 15 | 45 |
| 16 ErrorViewElement.created() : super.created(); | 46 ErrorViewElement.created() : super.created(); |
| 17 } | 47 |
| 48 @override | |
| 49 void attached() { | |
| 50 super.attached(); | |
| 51 _r.enable(); | |
| 52 } | |
| 53 | |
| 54 @override | |
| 55 void detached() { | |
| 56 super.detached(); | |
| 57 children = []; | |
| 58 _r.disable(notify: true); | |
| 59 } | |
| 60 | |
| 61 void render() { | |
| 62 children = [ | |
| 63 new NavBarElement(queue: _r.queue) | |
| 64 ..children = [ | |
| 65 new NavTopMenuElement(last: true, queue: _r.queue), | |
| 66 new NavNotifyElement(_notifications, queue: _r.queue) | |
| 67 ], | |
| 68 new DivElement() | |
| 69 ..classes = ['content-centered'] | |
| 70 ..children = [ | |
| 71 new HeadingElement.h1() | |
| 72 ..text = 'Error: ${_kindToString(_error.kind)}', | |
| 73 new BRElement(), | |
| 74 new DivElement()..classes = ['well'] | |
| 75 ..children = [ | |
| 76 new PreElement()..text = error.message | |
| 77 ] | |
| 78 ], | |
| 79 new ViewFooterElement(queue: _r.queue) | |
| 80 ]; | |
| 81 } | |
| 82 | |
| 83 static String _kindToString(M.ErrorKind kind) { | |
| 84 switch(kind) { | |
| 85 case M.ErrorKind.unhandledException: | |
| 86 return 'Unhandled Exception'; | |
| 87 case M.ErrorKind.languageError: | |
| 88 return 'Language Error'; | |
| 89 case M.ErrorKind.internalError: | |
| 90 return 'Internal Error'; | |
| 91 case M.ErrorKind.terminationError: | |
| 92 return 'Termination Error'; | |
| 93 } | |
| 94 throw new Exception('Unkown M.ErrorKind ($kind)'); | |
|
rmacnak
2016/08/26 17:05:26
unknown
| |
| 95 } | |
| 96 } | |
| OLD | NEW |