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 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'package:observatory/models.dart' as M show IsolateRef, ContextRef; | 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/src/elements/curly_block.dart'; |
| 9 import 'package:observatory/src/elements/helpers/any_ref.dart'; |
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 10 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
9 import 'package:observatory/src/elements/helpers/tag.dart'; | 11 import 'package:observatory/src/elements/helpers/tag.dart'; |
10 import 'package:observatory/src/elements/helpers/uris.dart'; | 12 import 'package:observatory/src/elements/helpers/uris.dart'; |
11 | 13 |
12 class ContextRefElement extends HtmlElement implements Renderable { | 14 class ContextRefElement extends HtmlElement implements Renderable { |
13 static const tag = const Tag<ContextRefElement>('context-ref'); | 15 static const tag = const Tag<ContextRefElement>('context-ref', |
| 16 dependencies: const [CurlyBlockElement.tag]); |
14 | 17 |
15 RenderingScheduler<ContextRefElement> _r; | 18 RenderingScheduler<ContextRefElement> _r; |
16 | 19 |
17 Stream<RenderedEvent<ContextRefElement>> get onRendered => _r.onRendered; | 20 Stream<RenderedEvent<ContextRefElement>> get onRendered => _r.onRendered; |
18 | 21 |
19 M.IsolateRef _isolate; | 22 M.IsolateRef _isolate; |
20 M.ContextRef _context; | 23 M.ContextRef _context; |
| 24 M.ObjectRepository _objects; |
| 25 M.Context _loadedContext; |
| 26 bool _expanded = false; |
21 | 27 |
22 M.IsolateRef get isolate => _isolate; | 28 M.IsolateRef get isolate => _isolate; |
23 M.ContextRef get context => _context; | 29 M.ContextRef get context => _context; |
24 | 30 |
25 factory ContextRefElement(M.IsolateRef isolate, M.ContextRef context, | 31 factory ContextRefElement( |
| 32 M.IsolateRef isolate, M.ContextRef context, M.ObjectRepository objects, |
26 {RenderingQueue queue}) { | 33 {RenderingQueue queue}) { |
27 assert(isolate != null); | 34 assert(isolate != null); |
28 assert(context != null); | 35 assert(context != null); |
| 36 assert(objects != null); |
29 ContextRefElement e = document.createElement(tag.name); | 37 ContextRefElement e = document.createElement(tag.name); |
30 e._r = new RenderingScheduler(e, queue: queue); | 38 e._r = new RenderingScheduler(e, queue: queue); |
31 e._isolate = isolate; | 39 e._isolate = isolate; |
32 e._context = context; | 40 e._context = context; |
| 41 e._objects = objects; |
33 return e; | 42 return e; |
34 } | 43 } |
35 | 44 |
36 ContextRefElement.created() : super.created(); | 45 ContextRefElement.created() : super.created(); |
37 | 46 |
38 @override | 47 @override |
39 void attached() { | 48 void attached() { |
40 super.attached(); | 49 super.attached(); |
41 _r.enable(); | 50 _r.enable(); |
42 } | 51 } |
43 | 52 |
44 @override | 53 @override |
45 void detached() { | 54 void detached() { |
46 super.detached(); | 55 super.detached(); |
47 _r.disable(notify: true); | 56 _r.disable(notify: true); |
48 children = []; | 57 children = []; |
49 } | 58 } |
50 | 59 |
| 60 Future _refresh() async { |
| 61 _loadedContext = await _objects.get(_isolate, _context.id); |
| 62 _r.dirty(); |
| 63 } |
| 64 |
51 void render() { | 65 void render() { |
52 children = [ | 66 children = [ |
53 new AnchorElement(href: Uris.inspect(_isolate, object: _context)) | 67 new AnchorElement(href: Uris.inspect(_isolate, object: _context)) |
54 ..children = [ | 68 ..children = [ |
55 new SpanElement() | 69 new SpanElement() |
56 ..classes = ['emphasize'] | 70 ..classes = ['emphasize'] |
57 ..text = 'Context', | 71 ..text = 'Context', |
58 new SpanElement()..text = ' (${_context.length})' | 72 new SpanElement()..text = ' (${_context.length})', |
| 73 ], |
| 74 new SpanElement()..text = ' ', |
| 75 new CurlyBlockElement(expanded: _expanded, queue: _r.queue) |
| 76 ..content = [ |
| 77 new DivElement() |
| 78 ..classes = ['indent'] |
| 79 ..children = _createValue() |
59 ] | 80 ] |
| 81 ..onToggle.listen((e) async { |
| 82 _expanded = e.control.expanded; |
| 83 if (_expanded) { |
| 84 e.control.disabled = true; |
| 85 await _refresh(); |
| 86 e.control.disabled = false; |
| 87 } |
| 88 }) |
| 89 ]; |
| 90 } |
| 91 |
| 92 List<Element> _createValue() { |
| 93 if (_loadedContext == null) { |
| 94 return [new SpanElement()..text = 'Loading...']; |
| 95 } |
| 96 var members = new List<Element>(); |
| 97 if (_loadedContext.parentContext != null) { |
| 98 members.add(new DivElement() |
| 99 ..classes = ['memberItem'] |
| 100 ..children = [ |
| 101 new DivElement() |
| 102 ..classes = ['memberName'] |
| 103 ..text = 'parent context', |
| 104 new DivElement() |
| 105 ..classes = ['memberName'] |
| 106 ..children = [ |
| 107 new ContextRefElement( |
| 108 _isolate, _loadedContext.parentContext, _objects, |
| 109 queue: _r.queue) |
| 110 ] |
| 111 ]); |
| 112 } |
| 113 if (_loadedContext.variables.isNotEmpty) { |
| 114 var variables = _loadedContext.variables.toList(); |
| 115 for (var index = 0; index < variables.length; index++) { |
| 116 var variable = variables[index]; |
| 117 members.add(new DivElement() |
| 118 ..classes = ['memberItem'] |
| 119 ..children = [ |
| 120 new DivElement() |
| 121 ..classes = ['memberName'] |
| 122 ..text = '[ $index ]', |
| 123 new DivElement() |
| 124 ..classes = ['memberName'] |
| 125 ..children = [ |
| 126 anyRef(_isolate, variable.value, _objects, queue: _r.queue) |
| 127 ] |
| 128 ]); |
| 129 } |
| 130 } |
| 131 return [ |
| 132 new DivElement() |
| 133 ..classes = ['memberList'] |
| 134 ..children = members |
60 ]; | 135 ]; |
61 } | 136 } |
62 } | 137 } |
OLD | NEW |