Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: pkg/polymer/lib/src/build/log_injector.dart

Issue 451933002: Tweaks to the injector UI (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /// This library provides a single function called injectLogs which when called 5 /// This library provides a single function called injectLogs which when called
6 /// will request a logs json file and build a small widget out of them which 6 /// will request a logs json file and build a small widget out of them which
7 /// groups the logs by level. 7 /// groups the logs by level.
8 library polymer.build.log_injector; 8 library polymer.build.log_injector;
9 9
10 import 'dart:async'; 10 import 'dart:async';
11 import 'dart:convert'; 11 import 'dart:convert';
12 import 'dart:html'; 12 import 'dart:html';
13 13
14 import 'package:path/path.dart' as path; 14 import 'package:path/path.dart' as path;
15 15
16 class LogInjector { 16 class LogInjector {
17 Element selectedMenu; 17 Element selectedMenu;
18 Element selectedContent; 18 Element selectedContent;
19 19
20 // Gets the logs from a url and inject them into the dom. 20 // Gets the logs from a url and inject them into the dom.
21 Future injectLogsFromUrl([String url]) { 21 Future injectLogsFromUrl(String url) =>
22 if (url == null) url = '${Uri.base.path}._buildLogs'; 22 HttpRequest.getString(url).then((data) => injectLogs(data));
23 return HttpRequest.getString(url).then((data) => injectLogs(data));
24 }
25 23
26 // Builds the html for the logs element given some logs, and injects that 24 // Builds the html for the logs element given some logs, and injects that
27 // into the dom. Currently, we do not use Polymer just to ensure that the 25 // into the dom. Currently, we do not use Polymer just to ensure that the
28 // page works regardless of the state of the app. Ideally, we could have 26 // page works regardless of the state of the app. Ideally, we could have
29 // multiple scripts running independently so we could ensure that this would 27 // multiple scripts running independently so we could ensure that this would
30 // always be running. 28 // always be running.
31 injectLogs(String data) { 29 injectLogs(String data) {
32 // Group all logs by level. 30 // Group all logs by level.
33 var logsByLevel = { 31 var logsByLevel = {
34 }; 32 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 77 }
80 78
81 menuItem.classes.toggle('active'); 79 menuItem.classes.toggle('active');
82 contentItem.classes.toggle('active'); 80 contentItem.classes.toggle('active');
83 }); 81 });
84 82
85 // Add the logs to the content item. 83 // Add the logs to the content item.
86 for (var log in logs) { 84 for (var log in logs) {
87 var logHtml = new StringBuffer(); 85 var logHtml = new StringBuffer();
88 logHtml.write('<div class="log">'); 86 logHtml.write('<div class="log">');
89 logHtml.write( 87 var message = log['message'].replaceAllMapped(_urlRegex,
90 '<div class="message $levelClassName">${log['message']}</div>'); 88 (m) => '<a href="${m.group(0)}" target="blank">${m.group(0)}</a>');
89 logHtml.write('<div class="message $levelClassName">$message</div>');
91 var assetId = log['assetId']; 90 var assetId = log['assetId'];
91 var span = log['span'];
92 bool hasLocation = assetId != null || span != null;
93 if (hasLocation) logHtml.write('<div class="location">');
jakemac 2014/08/11 13:49:52 imo it would be clearer to just put all of this lo
92 if (assetId != null) { 94 if (assetId != null) {
93 logHtml.write( 95 logHtml.write(
94 '<div class="asset">' 96 ' <span class="package">${assetId['package']}</span>:');
95 ' <span class="package">${assetId['package']}</span>:' 97 if (span == null) {
96 ' <span class="path">${assetId['path']}</span>''</div>'); 98 logHtml.write(' <span class="location">${assetId['path']}</span>');
99 }
97 } 100 }
98 var span = log['span'];
99 if (span != null) { 101 if (span != null) {
100 logHtml.write( 102 logHtml.write(
101 '<div class="span">' 103 ' <span class="location">${span['location']}</span></div>'
102 ' <div class="location">${span['location']}</div>' 104 ' <span class="text">${span['text']}</span>''</div>');
103 ' <code class="text">${span['text']}</code>''</div>'); 105 } else if (hasLocation) {
106 logHtml.write('</div>');
104 } 107 }
105 logHtml.write('</div>'); 108 logHtml.write('</div>');
106 109
107 contentItem.append(new Element.html(logHtml.toString())); 110 var logElement = new Element.html(logHtml.toString(),
111 validator: new NodeValidatorBuilder.common()
112 ..allowNavigation(new _OpenUriPolicy()));
113 contentItem.append(logElement);
114 var messageElement = logElement.querySelector('.message');
115 messageElement.onClick.listen((e) {
116 if (e.target == messageElement) {
117 messageElement.classes.toggle('expanded');
118 }
119 });
108 }; 120 };
109 }); 121 });
110 122
111 document.body.append(wrapperDiv); 123 document.body.append(wrapperDiv);
112 } 124 }
113 125
114 } 126 }
127
128 final _urlRegex = new RegExp('http://[^ ]*');
129 class _OpenUriPolicy implements UriPolicy {
130 bool allowsUri(String uri) => true;
131 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/build/log_injector.css ('k') | pkg/polymer/lib/src/build/script_compactor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698