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 import 'package:observatory/app.dart'; |
| 7 import 'package:observatory/service_html.dart'; |
| 8 import 'vm_connect_target.dart'; |
| 9 import 'shims/binding.dart'; |
| 10 import 'helpers/tag.dart'; |
| 11 |
| 12 class VmConnectTargetElementWrapper extends HtmlElement { |
| 13 static final binder = new Binder<VmConnectTargetElementWrapper>( |
| 14 const [const Binding('target')]); |
| 15 |
| 16 static const tag = |
| 17 const Tag<VmConnectTargetElementWrapper>('vm-connect-target'); |
| 18 |
| 19 WebSocketVMTarget _target; |
| 20 WebSocketVMTarget get target => _target; |
| 21 void set target(WebSocketVMTarget target) { _target = target; render(); } |
| 22 |
| 23 VmConnectTargetElementWrapper.created() : super.created() { |
| 24 binder.registerCallback(this); |
| 25 createShadowRoot(); |
| 26 render(); |
| 27 } |
| 28 |
| 29 @override |
| 30 void attached() { |
| 31 super.attached(); |
| 32 render(); |
| 33 } |
| 34 |
| 35 void render() { |
| 36 if (target == null) return; |
| 37 |
| 38 shadowRoot.children = [ |
| 39 new VmConnectTargetElement(target: target, isCurrent: isCurrent) |
| 40 ..onConnect.listen(connectToVm) |
| 41 ..onDelete.listen(deleteVm) |
| 42 ]; |
| 43 } |
| 44 |
| 45 static ObservatoryApplication get application => ObservatoryApplication.app; |
| 46 |
| 47 bool get isCurrent { |
| 48 if (application.vm == null) { return false; } |
| 49 return (application.vm as WebSocketVM).target == target; |
| 50 } |
| 51 |
| 52 static void connectToVm(WebSocketVMTargetEvent event) { |
| 53 WebSocketVM currentVM = application.vm; |
| 54 if ((currentVM == null) || |
| 55 currentVM.isDisconnected || |
| 56 (currentVM.target != event.target)) { |
| 57 application.vm = new WebSocketVM(event.target); |
| 58 } |
| 59 } |
| 60 |
| 61 static void deleteVm(WebSocketVMTargetEvent event) { |
| 62 application.targets.remove(event.target); |
| 63 } |
| 64 } |
OLD | NEW |