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

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

Issue 427623002: Polymer transformer logs now show on the frontend for pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: added option to enable the element (opt in now) and cleanup 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
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
7 /// groups the logs by level.
8 library polymer.build.log_injector;
9
10 import 'dart:convert';
11 import 'dart:html';
12
13 import 'package:path/path.dart' as path;
14
15 class LogInjector {
16 Element selectedMenu;
17 Element selectedContent;
18
19 // Gets the logs and builds the html for the logs element, and injects that
20 // into the dom. Currently, we do not use Polymer just to ensure that the
21 // page works regardless of the state of the app. Ideally, we could have
22 // multiple scripts running independently so we could ensure that this would
23 // always be running.
24 injectLogs() {
25 var buildLogsUrl = '${window.location.href}._buildLogs';
26 var r = HttpRequest.getString(buildLogsUrl).then((data) {
27 // Group all logs by level.
28 var logsByLevel = {
29 };
30 JSON.decode(data).forEach((log) {
31 logsByLevel.putIfAbsent(log['level'], () => []);
32 logsByLevel[log['level']].add(log);
33 });
34 if (logsByLevel.isEmpty) return;
35
36 // Build the wrapper, menu, and content divs.
37
38 var menuWrapper = new DivElement()
39 ..classes.add('menu');
40 var contentWrapper = new DivElement()
41 ..classes.add('content');
42 var wrapperDiv = new DivElement()
43 ..classes.add('build-logs')
44 ..append(menuWrapper)
45 ..append(contentWrapper);
46
47 // For each log level, add a menu item, content section, and all the logs.
48 logsByLevel.forEach((level, logs) {
49 var levelClassName = level.toLowerCase();
50
51 // Add the menu item and content item.
52 var menuItem = new Element.html(
53 '<div class="$levelClassName">'
54 '$level <span class="num">(${logs.length})</span>'
55 '</div>');
56 menuWrapper.append(menuItem);
57 var contentItem = new DivElement()
58 ..classes.add(levelClassName);
59 contentWrapper.append(contentItem);
60
61 // Set up the click handlers.
62 menuItem.onClick.listen((_) {
63 if (selectedMenu == menuItem) {
64 selectedMenu = null;
65 selectedContent = null;
66 } else {
67 if (selectedMenu != null) {
68 selectedMenu.classes.remove('active');
69 selectedContent.classes.remove('active');
70 }
71
72 selectedMenu = menuItem;
73 selectedContent = contentItem;
74 }
75
76 menuItem.classes.toggle('active');
77 contentItem.classes.toggle('active');
78 });
79
80 // Add the logs to the content item.
81 for (var log in logs) {
82 var logHtml = new StringBuffer();
83 logHtml.write('<div class="log">');
84 logHtml.write(
85 '<div class="message $levelClassName">${log['message']}</div>');
86 var assetId = log['assetId'];
87 if (assetId != null) {
88 logHtml.write(
89 '<div class="asset">'
90 ' <span class="package">${assetId['package']}</span>:'
91 ' <span class="path">${assetId['path']}</span>''</div>');
92 }
93 var span = log['span'];
94 if (span != null) {
95 logHtml.write(
96 '<div class="span">'
97 ' <div class="location">${span['location']}</div>'
98 ' <code class="text">${span['text']}</code>''</div>');
99 }
100 logHtml.write('</div>');
101
102 contentItem.append(new Element.html(logHtml.toString()));
103 };
104 });
105
106 document.body.append(wrapperDiv);
107 });
108 }
109
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698