OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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/tag.dart'; | 8 import 'package:observatory/src/elements/helpers/tag.dart'; |
9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
10 import 'package:observatory/src/elements/nav/notify_event.dart'; | 10 import 'package:observatory/src/elements/nav/notify_event.dart'; |
11 import 'package:observatory/src/elements/nav/notify_exception.dart'; | 11 import 'package:observatory/src/elements/nav/notify_exception.dart'; |
12 | 12 |
13 class NavNotifyElement extends HtmlElement implements Renderable { | 13 class NavNotifyElement extends HtmlElement implements Renderable { |
14 static const tag = const Tag<NavNotifyElement>('nav-notify', | 14 static const tag = const Tag<NavNotifyElement>('nav-notify', |
15 dependencies: const [ NavNotifyEventElement.tag, | 15 dependencies: const [ |
16 NavNotifyExceptionElement.tag ]); | 16 NavNotifyEventElement.tag, |
| 17 NavNotifyExceptionElement.tag |
| 18 ]); |
17 | 19 |
18 RenderingScheduler _r; | 20 RenderingScheduler _r; |
19 | 21 |
20 Stream<RenderedEvent<NavNotifyElement>> get onRendered => _r.onRendered; | 22 Stream<RenderedEvent<NavNotifyElement>> get onRendered => _r.onRendered; |
21 | 23 |
22 M.NotificationRepository _repository; | 24 M.NotificationRepository _repository; |
23 StreamSubscription _subscription; | 25 StreamSubscription _subscription; |
24 | 26 |
25 bool _notifyOnPause; | 27 bool _notifyOnPause; |
26 | 28 |
27 bool get notifyOnPause => _notifyOnPause; | 29 bool get notifyOnPause => _notifyOnPause; |
28 | 30 |
29 set notifyOnPause(bool value) => | 31 set notifyOnPause(bool value) => |
30 _notifyOnPause = _r.checkAndReact(_notifyOnPause, value); | 32 _notifyOnPause = _r.checkAndReact(_notifyOnPause, value); |
31 | 33 |
32 factory NavNotifyElement(M.NotificationRepository repository, | 34 factory NavNotifyElement(M.NotificationRepository repository, |
33 {bool notifyOnPause: true, RenderingQueue queue}) { | 35 {bool notifyOnPause: true, RenderingQueue queue}) { |
34 assert(repository != null); | 36 assert(repository != null); |
35 assert(notifyOnPause != null); | 37 assert(notifyOnPause != null); |
36 NavNotifyElement e = document.createElement(tag.name); | 38 NavNotifyElement e = document.createElement(tag.name); |
37 e._r = new RenderingScheduler(e, queue: queue); | 39 e._r = new RenderingScheduler(e, queue: queue); |
38 e._repository = repository; | 40 e._repository = repository; |
39 e._notifyOnPause = notifyOnPause; | 41 e._notifyOnPause = notifyOnPause; |
40 return e; | 42 return e; |
41 } | 43 } |
42 | 44 |
43 NavNotifyElement.created() : super.created(); | 45 NavNotifyElement.created() : super.created(); |
(...skipping 11 matching lines...) Expand all Loading... |
55 children = []; | 57 children = []; |
56 _r.disable(notify: true); | 58 _r.disable(notify: true); |
57 _subscription.cancel(); | 59 _subscription.cancel(); |
58 } | 60 } |
59 | 61 |
60 void render() { | 62 void render() { |
61 children = [ | 63 children = [ |
62 new DivElement() | 64 new DivElement() |
63 ..children = [ | 65 ..children = [ |
64 new DivElement() | 66 new DivElement() |
65 ..children = _repository.list() | 67 ..children = |
66 .where(_filter).map(_toElement).toList() | 68 _repository.list().where(_filter).map(_toElement).toList() |
67 ] | 69 ] |
68 ]; | 70 ]; |
69 } | 71 } |
70 | 72 |
71 bool _filter(M.Notification notification) { | 73 bool _filter(M.Notification notification) { |
72 if (!_notifyOnPause && notification is M.EventNotification) { | 74 if (!_notifyOnPause && notification is M.EventNotification) { |
73 return !M.Event.isPauseEvent(notification.event); | 75 return !M.Event.isPauseEvent(notification.event); |
74 } | 76 } |
75 return true; | 77 return true; |
76 } | 78 } |
77 | 79 |
78 HtmlElement _toElement(M.Notification notification) { | 80 HtmlElement _toElement(M.Notification notification) { |
79 if (notification is M.EventNotification) { | 81 if (notification is M.EventNotification) { |
80 return new NavNotifyEventElement(notification.event, queue: _r.queue) | 82 return new NavNotifyEventElement(notification.event, queue: _r.queue) |
81 ..onDelete.listen((_) => _repository.delete(notification)); | 83 ..onDelete.listen((_) => _repository.delete(notification)); |
82 } else if (notification is M.ExceptionNotification) { | 84 } else if (notification is M.ExceptionNotification) { |
83 return new NavNotifyExceptionElement( | 85 return new NavNotifyExceptionElement(notification.exception, |
84 notification.exception, stacktrace: notification.stacktrace, | 86 stacktrace: notification.stacktrace, queue: _r.queue) |
85 queue: _r.queue) | 87 ..onDelete.listen((_) => _repository.delete(notification)); |
86 ..onDelete.listen((_) => _repository.delete(notification)); | |
87 } else { | 88 } else { |
88 assert(false); | 89 assert(false); |
89 return new DivElement()..text = 'Invalid Notification Type'; | 90 return new DivElement()..text = 'Invalid Notification Type'; |
90 } | 91 } |
91 } | 92 } |
92 } | 93 } |
OLD | NEW |