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

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: code review updates 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 LogInjector created();
Siggi Cherem (dart-lang) 2014/08/04 20:38:37 delete?
jakemac 2014/08/04 22:21:57 Done.
20
21 // Gets the logs and builds the html for the logs element, and injects that in to
Siggi Cherem (dart-lang) 2014/08/04 20:38:37 nit: 80 colums
jakemac 2014/08/04 22:21:58 Done.
22 // the dom. Currently, we do not use Polymer just to ensure that the page wor ks
23 // regardless of the state of the app. Ideally, we could have multiple scripts
24 // running independently so we could ensure that this would always be running.
25 injectLogs() {
26 var buildLogsUrl = '${window.location.href}._buildLogs';
27 var r = HttpRequest.getString(buildLogsUrl).then((data) {
28 // Group all logs by level.
29 var logsByLevel = {
30 };
31 JSON.decode(data).forEach((log) {
32 logsByLevel.putIfAbsent(log['level'], () => []);
33 logsByLevel[log['level']].add(log);
34 });
35 if (logsByLevel.isEmpty) return;
36
37 // Build the wrapper, menu, and content divs.
38 var wrapperDiv = new DivElement()
Siggi Cherem (dart-lang) 2014/08/04 20:38:37 nit: we could move this wrapper down, and have the
jakemac 2014/08/04 22:21:58 Done.
39 ..classes.add('build-logs');
40 var menuWrapper = new DivElement()
41 ..classes.add('menu');
42 var contentWrapper = new DivElement()
43 ..classes.add('content');
44 wrapperDiv
45 ..append(menuWrapper)
46 ..append(contentWrapper);
47
48 // For each log level, add a menu item, content section, and all the logs.
49 logsByLevel.forEach((level, logs) {
50 var levelClassName = level.toLowerCase();
51
52 // Add the menu item and content item.
53 var menuItem = new Element.html(
54 '<div class="$levelClassName">'
55 '$level <span class="num">(${logs.length})</span>'
56 '</div>');
57 menuWrapper.append(menuItem);
58 var contentItem = new DivElement()
59 ..classes.add(levelClassName);
60 contentWrapper.append(contentItem);
61
62 // Set up the click handlers.
63 menuItem.onClick.listen((_) {
64 if (selectedMenu == menuItem) {
65 selectedMenu = null;
66 selectedContent = null;
67 } else {
68 if (selectedMenu != null) {
69 selectedMenu.classes.remove('active');
70 selectedContent.classes.remove('active');
71 }
72
73 selectedMenu = menuItem;
74 selectedContent = contentItem;
75 }
76
77 menuItem.classes.toggle('active');
78 contentItem.classes.toggle('active');
79 });
80
81 // Add the logs to the content item.
82 for (var log in logs) {
83 var logHtml = new StringBuffer();
84 logHtml.write('<div class="log">');
85 logHtml.write(
86 '<div class="message $levelClassName">${log['message']}</div>');
87 var assetId = log['assetId'];
88 if (assetId != null) {
89 logHtml.write(
90 '<div class="asset">'
91 ' <span class="package">${assetId['package']}</span>:'
92 ' <span class="path">${assetId['path']}</span>''</div>');
93 }
94 var span = log['span'];
95 if (span != null) {
96 logHtml.write(
97 '<div class="span">'
98 ' <div class="location">${span['location']}</div>'
99 ' <code class="text">${span['text']}</code>''</div>');
100 }
101 logHtml.write('</div>');
102
103 contentItem.append(new Element.html(logHtml.toString()));
104 };
105 });
106
107 document.body.append(wrapperDiv);
108 });
109 }
110
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698