OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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/helpers/any_ref.dart'; | 8 import 'package:observatory/src/elements/helpers/any_ref.dart'; |
9 import 'package:observatory/src/elements/helpers/nav_bar.dart'; | 9 import 'package:observatory/src/elements/helpers/nav_bar.dart'; |
10 import 'package:observatory/src/elements/helpers/nav_menu.dart'; | 10 import 'package:observatory/src/elements/helpers/nav_menu.dart'; |
11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
12 import 'package:observatory/src/elements/helpers/tag.dart'; | 12 import 'package:observatory/src/elements/helpers/tag.dart'; |
13 import 'package:observatory/src/elements/instance_ref.dart'; | 13 import 'package:observatory/src/elements/instance_ref.dart'; |
14 import 'package:observatory/src/elements/nav/isolate_menu.dart'; | 14 import 'package:observatory/src/elements/nav/isolate_menu.dart'; |
15 import 'package:observatory/src/elements/nav/notify.dart'; | 15 import 'package:observatory/src/elements/nav/notify.dart'; |
16 import 'package:observatory/src/elements/nav/refresh.dart'; | 16 import 'package:observatory/src/elements/nav/refresh.dart'; |
17 import 'package:observatory/src/elements/nav/top_menu.dart'; | 17 import 'package:observatory/src/elements/nav/top_menu.dart'; |
18 import 'package:observatory/src/elements/nav/vm_menu.dart'; | 18 import 'package:observatory/src/elements/nav/vm_menu.dart'; |
19 import 'package:observatory/src/elements/view_footer.dart'; | 19 import 'package:observatory/src/elements/view_footer.dart'; |
20 | 20 |
21 class PortsElement extends HtmlElement implements Renderable { | 21 class PortsElement extends HtmlElement implements Renderable { |
22 static const tag = const Tag<PortsElement>('ports-page', | 22 static const tag = const Tag<PortsElement>('ports-page', dependencies: const [ |
23 dependencies: const [ | 23 NavTopMenuElement.tag, |
24 NavTopMenuElement.tag, | 24 NavVMMenuElement.tag, |
25 NavVMMenuElement.tag, | 25 NavIsolateMenuElement.tag, |
26 NavIsolateMenuElement.tag, | 26 NavRefreshElement.tag, |
27 NavRefreshElement.tag, | 27 NavNotifyElement.tag, |
28 NavNotifyElement.tag, | 28 InstanceRefElement.tag, |
29 InstanceRefElement.tag, | 29 ViewFooterElement.tag |
30 ViewFooterElement.tag | 30 ]); |
31 ]); | |
32 | 31 |
33 RenderingScheduler<PortsElement> _r; | 32 RenderingScheduler<PortsElement> _r; |
34 | 33 |
35 Stream<RenderedEvent<PortsElement>> get onRendered => _r.onRendered; | 34 Stream<RenderedEvent<PortsElement>> get onRendered => _r.onRendered; |
36 | 35 |
37 M.VM _vm; | 36 M.VM _vm; |
38 M.IsolateRef _isolate; | 37 M.IsolateRef _isolate; |
39 M.EventRepository _events; | 38 M.EventRepository _events; |
40 M.NotificationRepository _notifications; | 39 M.NotificationRepository _notifications; |
41 M.PortsRepository _ports; | 40 M.PortsRepository _ports; |
42 M.InstanceRepository _instances; | 41 M.InstanceRepository _instances; |
43 M.Ports _isolatePorts; | 42 M.Ports _isolatePorts; |
44 | 43 |
45 | |
46 M.IsolateRef get isolate => _isolate; | 44 M.IsolateRef get isolate => _isolate; |
47 M.NotificationRepository get notifications => _notifications; | 45 M.NotificationRepository get notifications => _notifications; |
48 M.PortsRepository get ports => _ports; | 46 M.PortsRepository get ports => _ports; |
49 M.VMRef get vm => _vm; | 47 M.VMRef get vm => _vm; |
50 | 48 |
51 factory PortsElement(M.VM vm, M.IsolateRef isolate, | 49 factory PortsElement( |
52 M.EventRepository events, | 50 M.VM vm, |
53 M.NotificationRepository notifications, | 51 M.IsolateRef isolate, |
54 M.PortsRepository ports, | 52 M.EventRepository events, |
55 M.InstanceRepository instances, | 53 M.NotificationRepository notifications, |
56 {RenderingQueue queue}) { | 54 M.PortsRepository ports, |
| 55 M.InstanceRepository instances, |
| 56 {RenderingQueue queue}) { |
57 assert(vm != null); | 57 assert(vm != null); |
58 assert(isolate != null); | 58 assert(isolate != null); |
59 assert(events != null); | 59 assert(events != null); |
60 assert(notifications != null); | 60 assert(notifications != null); |
61 assert(ports != null); | 61 assert(ports != null); |
62 assert(instances != null); | 62 assert(instances != null); |
63 PortsElement e = document.createElement(tag.name); | 63 PortsElement e = document.createElement(tag.name); |
64 e._r = new RenderingScheduler(e, queue: queue); | 64 e._r = new RenderingScheduler(e, queue: queue); |
65 e._vm = vm; | 65 e._vm = vm; |
66 e._isolate = isolate; | 66 e._isolate = isolate; |
(...skipping 28 matching lines...) Expand all Loading... |
95 new NavIsolateMenuElement(_isolate, _events, queue: _r.queue), | 95 new NavIsolateMenuElement(_isolate, _events, queue: _r.queue), |
96 navMenu('ports'), | 96 navMenu('ports'), |
97 new NavRefreshElement(queue: _r.queue) | 97 new NavRefreshElement(queue: _r.queue) |
98 ..onRefresh.listen((_) => _refresh()), | 98 ..onRefresh.listen((_) => _refresh()), |
99 new NavNotifyElement(_notifications, queue: _r.queue) | 99 new NavNotifyElement(_notifications, queue: _r.queue) |
100 ]), | 100 ]), |
101 new DivElement() | 101 new DivElement() |
102 ..classes = ['content-centered'] | 102 ..classes = ['content-centered'] |
103 ..children = [ | 103 ..children = [ |
104 new HeadingElement.h1()..text = 'Ports', | 104 new HeadingElement.h1()..text = 'Ports', |
105 new BRElement(), new HRElement(), | 105 new BRElement(), |
106 new DivElement() | 106 new HRElement(), |
107 ..children = _createList(), | 107 new DivElement()..children = _createList(), |
108 new HRElement() | 108 new HRElement() |
109 ], | 109 ], |
110 new ViewFooterElement(queue: _r.queue) | 110 new ViewFooterElement(queue: _r.queue) |
111 ]; | 111 ]; |
112 } | 112 } |
113 | 113 |
114 List<Element> _createList() { | 114 List<Element> _createList() { |
115 if (_isolatePorts == null) { | 115 if (_isolatePorts == null) { |
116 return const []; | 116 return const []; |
117 } | 117 } |
118 int i = 0; | 118 int i = 0; |
119 return _isolatePorts.elements.map((port) => | 119 return _isolatePorts.elements |
120 new DivElement()..classes = ['memberItem'] | 120 .map((port) => new DivElement() |
121 ..children = [ | 121 ..classes = ['memberItem'] |
122 new DivElement()..classes = ['memberName'] | 122 ..children = [ |
123 ..children = [ | 123 new DivElement() |
124 new SpanElement()..classes = ['port-number'] | 124 ..classes = ['memberName'] |
125 ..text = '[ ${++i} ] ', | 125 ..children = [ |
126 new SpanElement()..text = '${port.name}' | 126 new SpanElement() |
127 ], | 127 ..classes = ['port-number'] |
128 new DivElement()..classes = ['memberValue'] | 128 ..text = '[ ${++i} ] ', |
129 ..children = [ | 129 new SpanElement()..text = '${port.name}' |
130 anyRef(_isolate, port.handler, _instances, queue: _r.queue) | 130 ], |
131 ] | 131 new DivElement() |
132 ] | 132 ..classes = ['memberValue'] |
133 ).toList(); | 133 ..children = [ |
| 134 anyRef(_isolate, port.handler, _instances, queue: _r.queue) |
| 135 ] |
| 136 ]) |
| 137 .toList(); |
134 } | 138 } |
135 | 139 |
136 Future _refresh() async { | 140 Future _refresh() async { |
137 _isolatePorts = null; | 141 _isolatePorts = null; |
138 _r.dirty(); | 142 _r.dirty(); |
139 _isolatePorts = await _ports.get(_isolate); | 143 _isolatePorts = await _ports.get(_isolate); |
140 _r.dirty(); | 144 _r.dirty(); |
141 } | 145 } |
142 } | 146 } |
OLD | NEW |