OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 import 'dart:html'; | |
6 | |
7 import 'package:observatory/app.dart'; | |
8 import 'package:observatory/service_html.dart'; | |
9 import 'package:observatory/src/elements/helpers/tag.dart'; | |
10 import 'package:observatory/src/elements/shims/binding.dart'; | |
11 import 'package:observatory/src/elements/vm_connect_target.dart'; | |
12 | |
13 @bindable | |
14 class VMConnectTargetElementWrapper extends HtmlElement { | |
15 static const binder = const Binder<VMConnectTargetElementWrapper>(const { | |
16 'target': #target | |
17 }); | |
18 | |
19 static const tag = | |
20 const Tag<VMConnectTargetElementWrapper>('vm-connect-target'); | |
21 | |
22 WebSocketVMTarget _target; | |
23 WebSocketVMTarget get target => _target; | |
24 void set target(WebSocketVMTarget target) { _target = target; render(); } | |
25 | |
26 VMConnectTargetElementWrapper.created() : super.created() { | |
27 binder.registerCallback(this); | |
28 createShadowRoot(); | |
29 render(); | |
30 } | |
31 | |
32 @override | |
33 void attached() { | |
34 super.attached(); | |
35 render(); | |
36 } | |
37 | |
38 void render() { | |
39 if (target == null) return; | |
40 | |
41 shadowRoot.children = [ | |
42 new StyleElement() | |
43 ..text = ''' | |
44 vm-connect-target-wrapped > button.delete-button { | |
45 margin-left: 0.28em; | |
46 padding: 4px; | |
47 background: transparent; | |
48 border: none !important; | |
49 } | |
50 | |
51 vm-connect-target-wrapped > button.delete-button:hover { | |
52 background: #ff0000; | |
53 }''', | |
54 new VMConnectTargetElement(target, current: current, | |
55 queue: application.queue) | |
56 ..onConnect.listen(connectToVm) | |
57 ..onDelete.listen(deleteVm) | |
58 ]; | |
59 } | |
60 | |
61 static ObservatoryApplication get application => ObservatoryApplication.app; | |
62 | |
63 bool get current { | |
64 if (application.vm == null) { return false; } | |
65 return (application.vm as WebSocketVM).target == target; | |
66 } | |
67 | |
68 static void connectToVm(TargetEvent event) { | |
69 WebSocketVM currentVM = application.vm; | |
70 if ((currentVM == null) || | |
71 currentVM.isDisconnected || | |
72 (currentVM.target != event.target)) { | |
73 application.vm = new WebSocketVM(event.target); | |
74 } | |
75 } | |
76 | |
77 static void deleteVm(TargetEvent event) { | |
78 application.targets.remove(event.target); | |
79 } | |
80 } | |
OLD | NEW |