OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 isolate_reconnect_element; | 5 library isolate_reconnect_element; |
6 | 6 |
7 import 'package:polymer/polymer.dart'; | 7 import 'dart:html'; |
8 import 'observatory_element.dart'; | 8 import 'dart:async'; |
| 9 import 'package:observatory/models.dart' as M; |
| 10 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
| 11 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 12 import 'package:observatory/src/elements/helpers/uris.dart'; |
| 13 import 'package:observatory/src/elements/nav/bar.dart'; |
| 14 import 'package:observatory/src/elements/nav/notify.dart'; |
| 15 import 'package:observatory/src/elements/nav/top_menu.dart'; |
| 16 import 'package:observatory/src/elements/view_footer.dart'; |
9 | 17 |
10 @CustomTag('isolate-reconnect') | 18 class IsolateReconnectElement extends HtmlElement implements Renderable{ |
11 class IsolateReconnectElement extends ObservatoryElement { | 19 static const tag = const Tag<IsolateReconnectElement>('isolate-reconnect', |
| 20 dependencies: const [NavBarElement.tag, |
| 21 NavTopMenuElement.tag, |
| 22 NavNotifyElement.tag, |
| 23 ViewFooterElement.tag]); |
| 24 |
| 25 RenderingScheduler _r; |
| 26 |
| 27 Stream<RenderedEvent<IsolateReconnectElement>> get onRendered => |
| 28 _r.onRendered; |
| 29 |
| 30 M.VM _vm; |
| 31 String _missing; |
| 32 Uri _uri; |
| 33 M.EventRepository _events; |
| 34 StreamSubscription _subscription; |
| 35 |
| 36 M.VM get vm => _vm; |
| 37 String get missing => _missing; |
| 38 Uri get uri => _uri; |
| 39 |
| 40 M.NotificationRepository _notifications; |
| 41 factory IsolateReconnectElement(M.VM vm, M.EventRepository events, |
| 42 M.NotificationRepository notifications, String missing, Uri uri, |
| 43 {RenderingQueue queue}) { |
| 44 assert(vm != null); |
| 45 assert(events != null); |
| 46 assert(missing != null); |
| 47 assert(uri != null); |
| 48 assert(notifications != null); |
| 49 IsolateReconnectElement e = document.createElement(tag.name); |
| 50 e._r = new RenderingScheduler(e, queue: queue); |
| 51 e._vm = vm; |
| 52 e._events = events; |
| 53 e._missing = missing; |
| 54 e._uri = uri; |
| 55 e._notifications = notifications; |
| 56 return e; |
| 57 } |
| 58 |
12 IsolateReconnectElement.created() : super.created(); | 59 IsolateReconnectElement.created() : super.created(); |
13 | 60 |
14 get missingIsolateId { | 61 @override |
15 return app.locationManager.uri.queryParameters['originalIsolateId']; | 62 void attached() { |
| 63 super.attached(); |
| 64 _subscription = _events.onVMUpdate.listen((e) { |
| 65 _vm = e.vm; |
| 66 _r.dirty(); |
| 67 }); |
| 68 _r.enable(); |
16 } | 69 } |
17 | 70 |
18 linkToContinueIn(isolate) { | 71 @override |
19 var parameters = new Map.from(app.locationManager.uri.queryParameters); | 72 void detached() { |
20 parameters['isolateId'] = isolate.id; | 73 super.detached(); |
21 parameters.remove('originalIsolateId'); | 74 children = []; |
22 var path = parameters.remove('originalPath'); | 75 _r.disable(notify: true); |
23 path = "/$path"; | 76 _subscription.cancel(); |
24 var generatedUri = new Uri(path: path, queryParameters: parameters); | 77 } |
25 return app.locationManager.makeLink(generatedUri.toString()); | 78 |
| 79 void render() { |
| 80 children = [ |
| 81 new NavBarElement(queue: _r.queue) |
| 82 ..children = [ |
| 83 new NavTopMenuElement(last: true, queue: _r.queue), |
| 84 new NavNotifyElement(_notifications, queue: _r.queue) |
| 85 ], |
| 86 new DivElement() |
| 87 ..classes = ['content-centered'] |
| 88 ..children = [ |
| 89 new HeadingElement.h1()..text = 'Isolate $_missing no longer exists', |
| 90 new BRElement(), new HRElement(), |
| 91 new DivElement()..classes = ['memberList'] |
| 92 ..children = (_vm.isolates.map((isolate) { |
| 93 final query = new Map.from(_uri.queryParameters); |
| 94 query['isolateId'] = isolate.id; |
| 95 final href = new Uri(path: _uri.path, queryParameters: query); |
| 96 return new DivElement()..classes = ['memberItem', 'doubleSpaced'] |
| 97 ..children = [ |
| 98 new SpanElement()..text = 'Continue in ', |
| 99 new AnchorElement(href: '#$href')..classes = ['isolate-link'] |
| 100 ..text = '${isolate.id} (${isolate.name})' |
| 101 ]; |
| 102 }).toList()..add( |
| 103 new DivElement()..classes = ['memberItem', 'doubleSpaced'] |
| 104 ..children = [ |
| 105 new SpanElement()..text = 'Go to ', |
| 106 new AnchorElement(href: Uris.vm()) |
| 107 ..text = 'isolates summary', |
| 108 ] |
| 109 )) |
| 110 ], |
| 111 new ViewFooterElement(queue: _r.queue) |
| 112 ]; |
26 } | 113 } |
27 } | 114 } |
OLD | NEW |