Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: runtime/observatory/lib/src/elements/nav/notify_exception.dart

Issue 2167053002: Converted Observatory nav-notify element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Added tests Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:html';
6 import 'dart:async';
7 import 'package:observatory/src/elements/helpers/tag.dart';
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
9 import 'package:observatory/models.dart' show ConnectionException;
10
11
12 class ExceptionDeleteEvent{
13 final Exception exception;
14 final StackTrace stacktrace;
15
16 ExceptionDeleteEvent(this.exception, {this.stacktrace});
17 }
18
19 class NavNotifyExceptionElement extends HtmlElement implements Renderable {
20 static const tag = const Tag<NavNotifyExceptionElement>('nav-exception');
21
22 RenderingScheduler _r;
23
24 Stream<RenderedEvent<NavNotifyExceptionElement>> get onRendered =>
25 _r.onRendered;
26
27 final StreamController<ExceptionDeleteEvent> _onDelete =
28 new StreamController<ExceptionDeleteEvent>.broadcast();
29 Stream<ExceptionDeleteEvent> get onDelete => _onDelete.stream;
30
31 Exception _exception;
32 StackTrace _stacktrace;
33 Exception get exception => _exception;
34 StackTrace get stacktrace => _stacktrace;
35
36 factory NavNotifyExceptionElement(Exception exception,
37 {StackTrace stacktrace: null, RenderingQueue queue}) {
38 assert(exception != null);
39 NavNotifyExceptionElement e = document.createElement(tag.name);
40 e._r = new RenderingScheduler(e, queue: queue);
41 e._exception = exception;
42 e._stacktrace = stacktrace;
43 return e;
44 }
45
46 NavNotifyExceptionElement.created() : super.created();
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 if (exception is ConnectionException) {
63 renderConnectionException();
64 } else {
65 renderGenericException();
66 }
67 }
68
69 void renderConnectionException() {
70 children = [
71 new DivElement()
72 ..children = [
73 new SpanElement()..text = 'The request cannot be completed because the '
74 'VM is currently disconnected',
75 new BRElement(), new BRElement(),
76 new SpanElement()..text = '[',
77 new AnchorElement(href: '#/vm-connect')
78 ..text = 'Connect to a different VM',
79 new SpanElement()..text = ']',
80 new ButtonElement()..innerHtml = '&times;'
81 ..onClick.map(_toEvent).listen(_delete)
82 ]
83 ];
84 }
85
86 void renderGenericException() {
87 List<Node> content;
88 content = [
89 new SpanElement()..text = 'Unexpected exception:',
90 new BRElement(), new BRElement(),
91 new DivElement()..text = exception.toString(),
92 new BRElement()
93 ];
94 if (stacktrace != null) {
95 content.addAll([
96 new SpanElement()..text = 'Stacktrace:',
97 new BRElement(), new BRElement(),
98 new DivElement()..text = stacktrace.toString(),
99 new BRElement()
100 ]);
101 }
102 content.addAll([
103 new SpanElement()..text = '[',
104 new AnchorElement(href: '#/vm-connect')
105 ..text = 'Connect to a different VM',
106 new SpanElement()..text = ']',
107 new ButtonElement()..innerHtml = '&times;'
108 ..onClick.map(_toEvent).listen(_delete)
109 ]);
110 children = [
111 new DivElement()
112 ..children = content
113 ];
114 }
115
116 ExceptionDeleteEvent _toEvent(_) {
117 return new ExceptionDeleteEvent(exception, stacktrace: stacktrace);
118 }
119
120 void _delete(ExceptionDeleteEvent e) {
121 _onDelete.add(e);
122 }
123
124 void delete() {
125 _onDelete.add(new ExceptionDeleteEvent(exception, stacktrace: stacktrace));
126 }
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698