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 library objectstore_view_element; | 5 library objectstore_view_element; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'package:observatory/models.dart' as M; | 9 import 'package:observatory/models.dart' as M; |
10 import 'package:observatory/src/elements/helpers/any_ref.dart'; | 10 import 'package:observatory/src/elements/helpers/any_ref.dart'; |
11 import 'package:observatory/src/elements/helpers/nav_bar.dart'; | 11 import 'package:observatory/src/elements/helpers/nav_bar.dart'; |
12 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 12 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
13 import 'package:observatory/src/elements/helpers/tag.dart'; | 13 import 'package:observatory/src/elements/helpers/tag.dart'; |
14 import 'package:observatory/src/elements/instance_ref.dart'; | 14 import 'package:observatory/src/elements/instance_ref.dart'; |
15 import 'package:observatory/src/elements/nav/isolate_menu.dart'; | 15 import 'package:observatory/src/elements/nav/isolate_menu.dart'; |
16 import 'package:observatory/src/elements/nav/notify.dart'; | 16 import 'package:observatory/src/elements/nav/notify.dart'; |
17 import 'package:observatory/src/elements/nav/refresh.dart'; | 17 import 'package:observatory/src/elements/nav/refresh.dart'; |
18 import 'package:observatory/src/elements/nav/top_menu.dart'; | 18 import 'package:observatory/src/elements/nav/top_menu.dart'; |
19 import 'package:observatory/src/elements/nav/vm_menu.dart'; | 19 import 'package:observatory/src/elements/nav/vm_menu.dart'; |
20 import 'package:observatory/src/elements/view_footer.dart'; | 20 import 'package:observatory/src/elements/view_footer.dart'; |
21 | 21 |
22 class ObjectStoreViewElement extends HtmlElement implements Renderable { | 22 class ObjectStoreViewElement extends HtmlElement implements Renderable { |
23 static const tag = const Tag<ObjectStoreViewElement>('objectstore-view', | 23 static const tag = const Tag<ObjectStoreViewElement>('objectstore-view', |
24 dependencies: const [ | 24 dependencies: const [ |
25 InstanceRefElement.tag, | 25 InstanceRefElement.tag, |
26 NavTopMenuElement.tag, | 26 NavTopMenuElement.tag, |
27 NavVMMenuElement.tag, | 27 NavVMMenuElement.tag, |
28 NavIsolateMenuElement.tag, | 28 NavIsolateMenuElement.tag, |
29 NavRefreshElement.tag, | 29 NavRefreshElement.tag, |
30 NavNotifyElement.tag, | 30 NavNotifyElement.tag, |
31 ViewFooterElement.tag | 31 ViewFooterElement.tag |
32 ]); | 32 ]); |
33 | 33 |
34 RenderingScheduler<ObjectStoreViewElement> _r; | 34 RenderingScheduler<ObjectStoreViewElement> _r; |
35 | 35 |
36 Stream<RenderedEvent<ObjectStoreViewElement>> get onRendered => _r.onRendered; | 36 Stream<RenderedEvent<ObjectStoreViewElement>> get onRendered => _r.onRendered; |
37 | 37 |
38 M.VM _vm; | 38 M.VM _vm; |
39 M.IsolateRef _isolate; | 39 M.IsolateRef _isolate; |
40 M.EventRepository _events; | 40 M.EventRepository _events; |
41 M.NotificationRepository _notifications; | 41 M.NotificationRepository _notifications; |
42 M.ObjectStore _store; | 42 M.ObjectStore _store; |
43 M.ObjectStoreRepository _stores; | 43 M.ObjectStoreRepository _stores; |
44 M.InstanceRepository _instances; | 44 M.InstanceRepository _instances; |
45 | 45 |
46 | |
47 M.VMRef get vm => _vm; | 46 M.VMRef get vm => _vm; |
48 M.IsolateRef get isolate => _isolate; | 47 M.IsolateRef get isolate => _isolate; |
49 M.NotificationRepository get notifications => _notifications; | 48 M.NotificationRepository get notifications => _notifications; |
50 | 49 |
51 factory ObjectStoreViewElement(M.VM vm, M.IsolateRef isolate, | 50 factory ObjectStoreViewElement( |
52 M.EventRepository events, | 51 M.VM vm, |
53 M.NotificationRepository notifications, | 52 M.IsolateRef isolate, |
54 M.ObjectStoreRepository stores, | 53 M.EventRepository events, |
55 M.InstanceRepository instances, | 54 M.NotificationRepository notifications, |
56 {RenderingQueue queue}) { | 55 M.ObjectStoreRepository stores, |
| 56 M.InstanceRepository instances, |
| 57 {RenderingQueue queue}) { |
57 assert(vm != null); | 58 assert(vm != null); |
58 assert(isolate != null); | 59 assert(isolate != null); |
59 assert(events != null); | 60 assert(events != null); |
60 assert(notifications != null); | 61 assert(notifications != null); |
61 assert(stores != null); | 62 assert(stores != null); |
62 assert(instances != null); | 63 assert(instances != null); |
63 ObjectStoreViewElement e = document.createElement(tag.name); | 64 ObjectStoreViewElement e = document.createElement(tag.name); |
64 e._r = new RenderingScheduler(e, queue: queue); | 65 e._r = new RenderingScheduler(e, queue: queue); |
65 e._vm = vm; | 66 e._vm = vm; |
66 e._isolate = isolate; | 67 e._isolate = isolate; |
(...skipping 21 matching lines...) Expand all Loading... |
88 } | 89 } |
89 | 90 |
90 void render() { | 91 void render() { |
91 final fields = _store?.fields?.toList(growable: false); | 92 final fields = _store?.fields?.toList(growable: false); |
92 children = [ | 93 children = [ |
93 navBar([ | 94 navBar([ |
94 new NavTopMenuElement(queue: _r.queue), | 95 new NavTopMenuElement(queue: _r.queue), |
95 new NavVMMenuElement(_vm, _events, queue: _r.queue), | 96 new NavVMMenuElement(_vm, _events, queue: _r.queue), |
96 new NavIsolateMenuElement(_isolate, _events, queue: _r.queue), | 97 new NavIsolateMenuElement(_isolate, _events, queue: _r.queue), |
97 new NavRefreshElement(disabled: _store == null, queue: _r.queue) | 98 new NavRefreshElement(disabled: _store == null, queue: _r.queue) |
98 ..onRefresh.listen((e) => _refresh()), | 99 ..onRefresh.listen((e) => _refresh()), |
99 new NavNotifyElement(_notifications, queue: _r.queue) | 100 new NavNotifyElement(_notifications, queue: _r.queue) |
100 ]), | 101 ]), |
101 new DivElement()..classes = ['content-centered-big'] | 102 new DivElement() |
| 103 ..classes = ['content-centered-big'] |
102 ..children = [ | 104 ..children = [ |
103 new HeadingElement.h1() | 105 new HeadingElement.h1() |
104 ..text = fields == null | 106 ..text = fields == null |
105 ? 'Object Store' | 107 ? 'Object Store' |
106 : 'Object Store (${fields.length})', | 108 : 'Object Store (${fields.length})', |
107 new HRElement(), | 109 new HRElement(), |
108 fields == null | 110 fields == null |
109 ? (new HeadingElement.h2()..text = 'Loading...') | 111 ? (new HeadingElement.h2()..text = 'Loading...') |
110 : (new DivElement()..classes = ['memberList'] | 112 : (new DivElement() |
111 ..children = fields.map((field) => | 113 ..classes = ['memberList'] |
112 new DivElement()..classes = ['memberItem'] | 114 ..children = fields |
113 ..children = [ | 115 .map((field) => new DivElement() |
114 new DivElement()..classes = ['memberName'] | 116 ..classes = ['memberItem'] |
115 ..text = field.name, | 117 ..children = [ |
116 new DivElement()..classes = ['memberValue'] | 118 new DivElement() |
117 ..children = [ | 119 ..classes = ['memberName'] |
118 anyRef(_isolate, field.value, _instances, | 120 ..text = field.name, |
| 121 new DivElement() |
| 122 ..classes = ['memberValue'] |
| 123 ..children = [ |
| 124 anyRef(_isolate, field.value, _instances, |
119 queue: _r.queue) | 125 queue: _r.queue) |
120 ] | 126 ] |
121 ]).toList()), | 127 ]) |
| 128 .toList()), |
122 new ViewFooterElement(queue: _r.queue) | 129 new ViewFooterElement(queue: _r.queue) |
123 ] | 130 ] |
124 ]; | 131 ]; |
125 } | 132 } |
126 | 133 |
127 Future _refresh() async { | 134 Future _refresh() async { |
128 _store = null; | 135 _store = null; |
129 _r.dirty(); | 136 _r.dirty(); |
130 _store = await _stores.get(_isolate); | 137 _store = await _stores.get(_isolate); |
131 _r.dirty(); | 138 _r.dirty(); |
132 } | 139 } |
133 } | 140 } |
OLD | NEW |