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