OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'dart:html'; | 5 import 'dart:html'; |
6 | 6 |
7 import 'package:observatory/app.dart'; | 7 import 'package:observatory/app.dart'; |
8 import 'package:observatory/mocks.dart' show ErrorRefMock; | 8 import 'package:observatory/service.dart'; |
9 import 'package:observatory/service_html.dart' show ServiceMap, DartError; | |
10 import 'package:observatory/src/elements/error_ref.dart'; | 9 import 'package:observatory/src/elements/error_ref.dart'; |
11 import 'package:observatory/src/elements/helpers/tag.dart'; | 10 import 'package:observatory/src/elements/helpers/tag.dart'; |
12 import 'package:observatory/src/elements/shims/binding.dart'; | 11 import 'package:observatory/src/elements/shims/binding.dart'; |
13 | 12 |
14 class ErrorRefElementWrapper extends HtmlElement { | 13 class ErrorRefElementWrapper extends HtmlElement { |
15 | 14 |
16 static const binder = const Binder<ErrorRefElementWrapper>(const { | 15 static const binder = const Binder<ErrorRefElementWrapper>(const { |
17 'ref': #ref | 16 'ref': #ref |
18 }); | 17 }); |
19 | 18 |
20 static const tag = const Tag<ErrorRefElementWrapper>('error-ref'); | 19 static const tag = const Tag<ErrorRefElementWrapper>('error-ref'); |
21 | 20 |
22 ServiceMap _error; | 21 DartError _error; |
23 ServiceMap get ref => _error; | 22 DartError get ref => _error; |
24 void set ref(ServiceMap ref) { _error = ref; render(); } | 23 void set ref(DartError ref) { _error = ref; render(); } |
25 | 24 |
26 ErrorRefElementWrapper.created() : super.created() { | 25 ErrorRefElementWrapper.created() : super.created() { |
27 binder.registerCallback(this); | 26 binder.registerCallback(this); |
28 createShadowRoot(); | 27 createShadowRoot(); |
29 render(); | 28 render(); |
30 } | 29 } |
31 | 30 |
32 @override | 31 @override |
33 void attached() { | 32 void attached() { |
34 super.attached(); | 33 super.attached(); |
35 render(); | 34 render(); |
36 } | 35 } |
37 | 36 |
38 void render() { | 37 void render() { |
39 shadowRoot.children = []; | 38 shadowRoot.children = []; |
40 if (_error == null) return; | 39 if (_error == null) return; |
41 | 40 shadowRoot.children = [ |
42 if (ref is Map) { | 41 new StyleElement() |
43 shadowRoot.children = [ | 42 ..text = ''' |
44 new StyleElement() | 43 error-ref-wrapped > pre { |
45 ..text = ''' | 44 background-color: #f5f5f5; |
46 error-ref-wrapped > pre { | 45 border: 1px solid #ccc; |
47 background-color: #f5f5f5; | 46 padding: 10px; |
48 border: 1px solid #ccc; | 47 font-family: consolas, courier, monospace; |
49 padding: 10px; | 48 font-size: 1em; |
50 font-family: consolas, courier, monospace; | 49 line-height: 1.2em; |
51 font-size: 1em; | 50 white-space: pre; |
52 line-height: 1.2em; | 51 } |
53 white-space: pre; | 52 ''', |
54 } | 53 new ErrorRefElement(_error, queue: ObservatoryApplication.app.queue) |
55 ''', | 54 ]; |
56 new ErrorRefElement(new ErrorRefMock(message: ref['message'])) | |
57 ]; | |
58 } else { | |
59 shadowRoot.children = [ | |
60 new StyleElement() | |
61 ..text = ''' | |
62 error-ref-wrapped > pre { | |
63 background-color: #f5f5f5; | |
64 border: 1px solid #ccc; | |
65 padding: 10px; | |
66 font-family: consolas, courier, monospace; | |
67 font-size: 1em; | |
68 line-height: 1.2em; | |
69 white-space: pre; | |
70 } | |
71 ''', | |
72 new ErrorRefElement( | |
73 new ErrorRefMock(message: (ref as DartError).message), | |
74 queue: ObservatoryApplication.app.queue) | |
75 ]; | |
76 } | |
77 } | 55 } |
78 } | 56 } |
OLD | NEW |