Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report: header, footer, leftnav, share, oh my #2000

Merged
merged 34 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
45b289e
Report header
ebidel Apr 12, 2017
9f8014d
Reponsive styling. Use share icon instead of "Export..."
ebidel Apr 12, 2017
fef3a99
Runtime settings
ebidel Apr 12, 2017
8b4d2e7
Support report re-ender into page
ebidel Apr 12, 2017
7d9e20c
Add report functionality
ebidel Apr 12, 2017
6887af7
Split files
ebidel Apr 12, 2017
2b84229
Remove css focus stuff
ebidel Apr 12, 2017
b138885
Remove placeholders
ebidel Apr 12, 2017
c9633af
Fix tests
ebidel Apr 12, 2017
ee7fcb1
Feedback
ebidel Apr 13, 2017
3b7e90f
lighthouse -> lh
ebidel Apr 13, 2017
c717870
Tests for header/footer
ebidel Apr 13, 2017
85d6b8e
Tests for header/footer/formatter helps
ebidel Apr 13, 2017
2ff34f7
Add more tests
ebidel Apr 13, 2017
e9751c7
Fix rebase
ebidel Apr 13, 2017
2918469
Fix travis tests
ebidel Apr 14, 2017
2a60c3a
Feedback and leftnav
ebidel Apr 15, 2017
121fda3
Add 2nd arg
ebidel Apr 15, 2017
a445a6e
Styling tweaks
ebidel Apr 15, 2017
703043a
Leftnav tests
ebidel Apr 15, 2017
c237657
Disable open in viewer in ui
ebidel Apr 15, 2017
d7f3c29
Adjust passing audits summary
ebidel Apr 15, 2017
aa93acc
Merge branch 'master' into GoogleChrome-tablesclear
patrickhulce Apr 21, 2017
3899e47
Merge after rebase
ebidel Apr 25, 2017
33021e5
Fix up styling after merge
ebidel Apr 25, 2017
31a7385
Update dom usage and reset state of template stamping when exporting …
ebidel Apr 25, 2017
d33cc21
Closure cleanup
ebidel Apr 25, 2017
4bbba21
cleanup
ebidel Apr 26, 2017
a30c86e
Tests
ebidel Apr 26, 2017
d8ce09f
lh-analytics custom event
ebidel Apr 26, 2017
777adfe
fix travis
ebidel Apr 26, 2017
a1ffbf5
Travis fix?
ebidel Apr 26, 2017
e542539
bckenny feedback
ebidel Apr 28, 2017
8bf076f
3 big changes
ebidel Apr 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lighthouse-core/closure/closure-type-checking.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gulp.task('compile-report', () => {
return gulp.src([
// externs
'closure/third_party/commonjs.js',

'lib/filer-namer.js',
'report/v2/renderer/*.js',
])

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/file-namer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Generate a filenamePrefix of hostname_YYYY-MM-DD_HH-MM-SS
* Date/time uses the local timezone, however Node has unreliable ICU
* support, so we must construct a YYYY-MM-DD date format manually. :/
* @param {!Object} results
* @param {!{url: string, generatedTime: string}} results
* @returns string
*/
function getFilenamePrefix(results) {
Expand Down
8 changes: 3 additions & 5 deletions lighthouse-core/report/scripts/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@

/**
* Logs messages via a UI butter.
* @class
*/
class Logger {
constructor(selector) {
/** @type {!Element} */
this.el = document.querySelector(selector);
}

/**
* Shows a butter bar.
* @param {!string} msg The message to show.
* @param {boolean=} optAutoHide True to hide the message after a duration.
* @param {boolean=} autoHide True to hide the message after a duration.
* Default is true.
*/
log(msg, optAutoHide) {
const autoHide = typeof optAutoHide === 'undefined' ? true : optAutoHide;

log(msg, autoHide = true) {
clearTimeout(this._id);

this.el.textContent = msg;
Expand Down
38 changes: 4 additions & 34 deletions lighthouse-core/report/v2/renderer/category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,7 @@
*/
'use strict';

/* globals self */

const RATINGS = {
PASS: {label: 'pass', minScore: 75},
AVERAGE: {label: 'average', minScore: 45},
FAIL: {label: 'fail'}
};

/**
* Convert a score to a rating label.
* @param {number} score
* @return {string}
*/
function calculateRating(score) {
let rating = RATINGS.FAIL.label;
if (score >= RATINGS.PASS.minScore) {
rating = RATINGS.PASS.label;
} else if (score >= RATINGS.AVERAGE.minScore) {
rating = RATINGS.AVERAGE.label;
}
return rating;
}

/**
* Format number.
* @param {number} number
* @return {string}
*/
function formatNumber(number) {
return number.toLocaleString(undefined, {maximumFractionDigits: 1});
}
/* globals self, Util */

class CategoryRenderer {
/**
Expand Down Expand Up @@ -105,8 +75,8 @@ class CategoryRenderer {
_populateScore(element, score, scoringMode, title, description) {
// Fill in the blanks.
const valueEl = this._dom.find('.lh-score__value', element);
valueEl.textContent = formatNumber(score);
valueEl.classList.add(`lh-score__value--${calculateRating(score)}`,
valueEl.textContent = Util.formatNumber(score);
valueEl.classList.add(`lh-score__value--${Util.calculateRating(score)}`,
`lh-score__value--${scoringMode}`);

this._dom.find('.lh-score__title', element).textContent = title;
Expand Down Expand Up @@ -157,7 +127,7 @@ class CategoryRenderer {

const gauge = this._dom.find('.lh-gauge', tmpl);
gauge.setAttribute('data-progress', score); // .dataset not supported in jsdom.
gauge.classList.add(`lh-gauge--${calculateRating(score)}`);
gauge.classList.add(`lh-gauge--${Util.calculateRating(score)}`);

this._dom.findAll('.lh-gauge__fill', gauge).forEach(el => {
el.style.transform = `rotate(${fillRotation}deg)`;
Expand Down
17 changes: 13 additions & 4 deletions lighthouse-core/report/v2/renderer/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DOM {

/**
* @param {string} selector
* @param {!Document|!Element} context
* @param {!Node} context
* @return {!DocumentFragment} A clone of the template content.
* @throws {Error}
*/
Expand All @@ -73,6 +73,15 @@ class DOM {
return clone;
}

/**
* Resets the "stamped" state of the templates.
*/
resetTemplates() {
this.findAll('template[data-stamped]', this._document).forEach(t => {
t.removeAttribute('data-stamped');
});
}

/**
* @param {string} text
* @return {!Element}
Expand Down Expand Up @@ -113,7 +122,7 @@ class DOM {
* Guaranteed context.querySelector. Always returns an element or throws if
* nothing matches query.
* @param {string} query
* @param {!DocumentFragment|!Element} context
* @param {!Node} context
* @return {!Element}
*/
find(query, context) {
Expand All @@ -127,8 +136,8 @@ class DOM {
/**
* Helper for context.querySelectorAll. Returns an Array instead of a NodeList.
* @param {string} query
* @param {!DocumentFragment|!Element} context
* @return {!Array<Element>}
* @param {!Node} context
* @return {!Array<!Element>}
*/
findAll(query, context) {
return Array.from(context.querySelectorAll(query));
Expand Down
77 changes: 77 additions & 0 deletions lighthouse-core/report/v2/renderer/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does devtools want a logger? This PR might need to adjust to the model in #2002

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK. I'm just porting :)

Knowing the separation of LH proper and integrations of LH is still unclear. Right now the operating assumption is that we're keeping everything we currently have b/c #1937 doesn't capture these types of details.

For me, the dream is that there will be all sorts of existing tools that adopt a LH report. It's impossible to foresee all those integration touch points. Rather than designing our system around a particular integration , it might be easier to flip it. IOW, the integration (e.g. devtools) decides what parts of LH it wants to throw away or replace. Removing handlebars, adding templateContext are a step towards that.

For the features stuff, I've updated it to take the approach in b12f2ea. Devtools can decide not to load the feature (including logger).


Some open thoughts/questions for everyone. "Integration X" can be substituted for "devtools".

  • The core report should contain the features we want to show up in the most places. For example, if you run LH in the CLI/extension/WPT/Gulliver/LHaaS, you'll get the UI we vend (logger, export, etc.).
  • What happens if you generate an html report in Integration X and open it later? Do you see LH's base UI or their version?
  • What happens if you open that same report in Viewer?
  • CSS is the easiest way to get rid of base UI: #lh-log { display: none}. We're already doing that today.
    • Alternatively, Integration X loads its own stylesheets and effectively changes the entire report.
  • If you also want to nuke code, don't inject ReportUIFeature (here), or stub files: class Logger { log() {} }. We could even provide those files for people if it makes sense.

* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* Logs messages via a UI butter.
*/
class Logger {
/**
* @param {!Element} element
*/
constructor(element) {
/** @type {!Element} */
this.el = element;
/** @private {?number} */
this._id = null;
}

/**
* Shows a butter bar.
* @param {!string} msg The message to show.
* @param {boolean=} autoHide True to hide the message after a duration.
* Default is true.
*/
log(msg, autoHide = true) {
clearTimeout(this._id);

this.el.textContent = msg;
this.el.classList.add('show');
if (autoHide) {
this._id = setTimeout(_ => {
this.el.classList.remove('show');
}, 7000);
}
}

/**
* @param {string} msg
*/
warn(msg) {
this.log('Warning: ' + msg);
}

/**
* @param {string} msg
*/
error(msg) {
this.log(msg);
}

/**
* Explicitly hides the butter bar.
*/
hide() {
clearTimeout(this._id);
this.el.classList.remove('show');
}
}

if (typeof module !== 'undefined' && module.exports) {
module.exports = Logger;
}
Loading