Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 Audits2.Audits2Panel = class extends UI.Panel { | 8 Audits2.Audits2Panel = class extends UI.PanelWithSidebar { |
| 9 constructor() { | 9 constructor() { |
| 10 super('audits2'); | 10 super('audits2'); |
| 11 this.setHideOnDetach(); | 11 this.setHideOnDetach(); |
| 12 this.registerRequiredCSS('audits2/audits2Panel.css'); | 12 this.registerRequiredCSS('audits2/audits2Panel.css'); |
| 13 this.registerRequiredCSS('audits2/lighthouse/report-styles.css'); | 13 this.registerRequiredCSS('audits2/lighthouse/report-styles.css'); |
| 14 | 14 |
| 15 this._protocolService = new Audits2.ProtocolService(); | 15 this._protocolService = new Audits2.ProtocolService(); |
| 16 this._protocolService.registerStatusCallback(msg => this._updateStatus(Commo n.UIString(msg))); | 16 this._protocolService.registerStatusCallback(msg => this._updateStatus(Commo n.UIString(msg))); |
| 17 | 17 |
| 18 this._settings = Audits2.Audits2Panel.Presets.map(preset => { | 18 var toolbar = new UI.Toolbar('', this.panelSidebarElement()); |
| 19 const setting = Common.settings.createSetting(preset.id, true); | |
| 20 setting.setTitle(Common.UIString(preset.description)); | |
| 21 return setting; | |
| 22 }); | |
| 23 | 19 |
| 24 var auditsViewElement = this.contentElement.createChild('div', 'hbox audits2 -view'); | 20 var newButton = new UI.ToolbarButton(Common.UIString('New audit\u2026'), 'la rgeicon-add'); |
| 25 this._resultsView = this.contentElement.createChild('div', 'vbox results-vie w'); | 21 toolbar.appendToolbarItem(newButton); |
| 26 this._createLauncherUI(auditsViewElement); | 22 newButton.addEventListener(UI.ToolbarButton.Events.Click, this._showLauncher UI.bind(this)); |
| 23 | |
| 24 var deleteButton = new UI.ToolbarButton(Common.UIString('Delete audit'), 'la rgeicon-delete'); | |
| 25 toolbar.appendToolbarItem(deleteButton); | |
| 26 deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._deleteSel ected.bind(this)); | |
| 27 | |
| 28 toolbar.appendSeparator(); | |
| 29 | |
| 30 var clearButton = new UI.ToolbarButton(Common.UIString('Clear all'), 'largei con-clear'); | |
| 31 toolbar.appendToolbarItem(clearButton); | |
| 32 clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clearAll.b ind(this)); | |
| 33 | |
| 34 this._treeOutline = new UI.TreeOutlineInShadow(); | |
| 35 this._treeOutline.registerRequiredCSS('audits2/lighthouse/report-styles.css' ); | |
| 36 this._treeOutline.registerRequiredCSS('audits2/audits2Tree.css'); | |
| 37 this.panelSidebarElement().appendChild(this._treeOutline.element); | |
| 38 | |
| 39 this._showLandingPage(); | |
| 27 } | 40 } |
| 28 | 41 |
| 29 _reset() { | 42 _clearAll() { |
| 30 this.contentElement.classList.remove('show-results'); | 43 this._treeOutline.removeChildren(); |
| 31 this._resultsView.removeChildren(); | 44 if (!this._treeOutline.rootElement().childCount()) |
| 45 this._showLandingPage(); | |
| 32 } | 46 } |
| 33 | 47 |
| 34 /** | 48 _deleteSelected() { |
| 35 * @param {!Element} auditsViewElement | 49 var selection = this._treeOutline.selectedTreeElement; |
| 36 */ | 50 if (selection) |
| 37 _createLauncherUI(auditsViewElement) { | 51 this._treeOutline.removeChild(selection); |
| 38 auditsViewElement.createChild('div', 'audits2-logo'); | 52 if (!this._treeOutline.rootElement().childCount()) |
| 53 this._showLandingPage(); | |
| 54 } | |
| 55 | |
| 56 _showLandingPage() { | |
| 57 this.mainElement().removeChildren(); | |
| 58 var landingPage = this.mainElement().createChild('div', 'vbox audits2-landin g-page'); | |
| 59 var landingCenter = landingPage.createChild('div', 'vbox audits2-landing-cen ter'); | |
| 60 landingCenter.createChild('div', 'audits2-logo'); | |
| 61 var text = landingCenter.createChild('div', 'audits2-landing-text'); | |
| 62 text.createChild('span', 'audits2-landing-bold-text').textContent = Common.U IString('Audits'); | |
| 63 text.createChild('span').textContent = Common.UIString(' help you identify a nd fix common problems that affect' + | |
| 64 + 'your site\'s performance, accessibility, and user experience. '); | |
| 65 var link = text.createChild('span', 'link'); | |
| 66 link.textContent = Common.UIString('Learn more'); | |
| 67 link.addEventListener( | |
| 68 'click', () => InspectorFrontendHost.openInNewTab('https://developers.go ogle.com/web/tools/lighthouse/')); | |
|
dgozman
2017/05/02 01:27:56
UI.createDocumentationLink('../lighthouse')
pfeldman
2017/05/02 17:54:46
What happens when our documentation moves?
| |
| 69 | |
| 70 var newButton = UI.createTextButton( | |
| 71 Common.UIString('Perform an audit\u2026'), this._showLauncherUI.bind(thi s), 'material-button default'); | |
| 72 landingCenter.appendChild(newButton); | |
| 73 } | |
| 74 | |
| 75 _showLauncherUI() { | |
| 76 this._dialog = new UI.Dialog(); | |
|
dgozman
2017/05/02 01:27:56
Let's not recreate dialog (and settings) if there
pfeldman
2017/05/02 17:54:46
I actually think this is a good one. Let me brush
| |
| 77 var root = UI.createShadowRootWithCoreStyles(this._dialog.contentElement, 'a udits2/audits2Dialog.css'); | |
| 78 var auditsViewElement = root.createChild('div', 'audits2-view'); | |
| 39 var uiElement = auditsViewElement.createChild('div'); | 79 var uiElement = auditsViewElement.createChild('div'); |
| 40 var headerElement = uiElement.createChild('header'); | 80 var headerElement = uiElement.createChild('header'); |
| 41 headerElement.createChild('p').textContent = Common.UIString( | 81 headerElement.createChild('p').textContent = Common.UIString('Audits to perf orm'); |
| 42 'Audits will analyze the page against modern development best practices and collect useful performance metrics and diagnostics. Select audits to collect :'); | |
| 43 uiElement.appendChild(headerElement); | 82 uiElement.appendChild(headerElement); |
| 44 | 83 |
| 45 var auditSelectorForm = uiElement.createChild('form', 'audits2-form'); | 84 var auditSelectorForm = uiElement.createChild('form', 'audits2-form'); |
| 46 | 85 |
| 47 this._settings | 86 for (var preset of Audits2.Audits2Panel.Presets) { |
| 48 .map(setting => new UI.ToolbarSettingCheckbox(setting)) | 87 var setting = Common.settings.createSetting(preset.id, true); |
| 49 .forEach(checkbox => auditSelectorForm.appendChild(checkbox.element)); | 88 setting.setTitle(preset.title); |
| 89 var checkbox = new UI.ToolbarSettingCheckbox(setting); | |
| 90 var row = auditSelectorForm.createChild('div', 'vbox audits2-launcher-row' ); | |
| 91 row.appendChild(checkbox.element); | |
| 92 row.createChild('span', 'audits2-launcher-description dimmed').textContent = preset.description; | |
| 93 } | |
| 50 | 94 |
| 51 this._startButton = UI.createTextButton( | 95 this._startButton = |
| 52 Common.UIString('Audit this page'), this._startButtonClicked.bind(this), 'run-audit audit-btn'); | 96 UI.createTextButton(Common.UIString('Run audit'), this._start.bind(this) , 'material-button default'); |
| 53 auditSelectorForm.appendChild(this._startButton); | 97 auditSelectorForm.appendChild(this._startButton); |
| 98 this._cancelButton = UI.createTextButton(Common.UIString('Cancel'), this._ca ncel.bind(this), 'material-button'); | |
| 99 auditSelectorForm.appendChild(this._cancelButton); | |
| 54 | 100 |
| 55 this._statusView = this._createStatusView(uiElement); | 101 this._statusView = this._createStatusView(uiElement); |
| 102 | |
| 103 this._dialog.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactWidthMaxHeigh t); | |
| 104 this._dialog.setMaxContentSize(new UI.Size(600, 400)); | |
| 105 this._dialog.show(this.mainElement()); | |
| 106 auditsViewElement.tabIndex = 0; | |
| 107 auditsViewElement.focus(); | |
| 56 } | 108 } |
| 57 | 109 |
| 58 /** | 110 /** |
| 59 * @param {!Element} launcherUIElement | 111 * @param {!Element} launcherUIElement |
| 60 * @return {!Element} | 112 * @return {!Element} |
| 61 */ | 113 */ |
| 62 _createStatusView(launcherUIElement) { | 114 _createStatusView(launcherUIElement) { |
| 63 var statusView = launcherUIElement.createChild('div', 'audits2-status hbox h idden'); | 115 var statusView = launcherUIElement.createChild('div', 'audits2-status hbox h idden'); |
| 64 this._statusIcon = statusView.createChild('span', 'icon'); | 116 this._statusIcon = statusView.createChild('span', 'icon'); |
| 65 this._statusElement = statusView.createChild('p'); | 117 this._statusElement = statusView.createChild('p'); |
| 66 this._updateStatus(Common.UIString('Loading...')); | 118 this._updateStatus(Common.UIString('Loading...')); |
| 67 return statusView; | 119 return statusView; |
| 68 } | 120 } |
| 69 | 121 |
| 70 _start() { | 122 _start() { |
| 71 this._inspectedURL = SDK.targetManager.mainTarget().inspectedURL(); | 123 this._inspectedURL = SDK.targetManager.mainTarget().inspectedURL(); |
| 72 | 124 |
| 73 const categoryIDs = this._settings.map(setting => { | 125 var categoryIDs = []; |
| 74 const preset = Audits2.Audits2Panel.Presets.find(preset => preset.id === s etting.name); | 126 for (var preset of Audits2.Audits2Panel.Presets) { |
| 75 return {configID: preset.configID, value: setting.get()}; | 127 if (Common.settings.createSetting(preset.id, true).get()) |
| 76 }).filter(agg => !!agg.value).map(agg => agg.configID); | 128 categoryIDs.push(preset.configID); |
| 129 } | |
| 77 | 130 |
| 78 return Promise.resolve() | 131 return Promise.resolve() |
| 79 .then(_ => this._protocolService.attach()) | 132 .then(_ => this._protocolService.attach()) |
| 80 .then(_ => { | 133 .then(_ => { |
| 81 this._auditRunning = true; | 134 this._auditRunning = true; |
| 82 this._updateButton(); | 135 this._updateButton(); |
| 83 this._updateStatus(Common.UIString('Loading...')); | 136 this._updateStatus(Common.UIString('Loading\u2026')); |
| 84 }) | 137 }) |
| 85 .then(_ => this._protocolService.startLighthouse(this._inspectedURL, cat egoryIDs)) | 138 .then(_ => this._protocolService.startLighthouse(this._inspectedURL, cat egoryIDs)) |
| 86 .then(lighthouseResult => { | 139 .then(lighthouseResult => { |
| 87 this._finish(lighthouseResult); | 140 this._finish(lighthouseResult); |
| 88 return this._stop(); | 141 return this._stop(); |
| 89 }).catch(err => { | 142 }) |
| 90 if (err instanceof Error) this._renderBugReport(err); | 143 .catch(err => { |
| 144 if (err instanceof Error) | |
| 145 this._renderBugReport(err); | |
| 91 }); | 146 }); |
| 92 } | 147 } |
| 93 | 148 |
| 94 /** | 149 _cancel() { |
| 95 * @param {!Event} event | 150 this._updateStatus(Common.UIString('Cancelling\u2026')); |
| 96 */ | 151 this._stop(); |
| 97 _startButtonClicked(event) { | 152 this._dialog.hide(); |
| 98 if (this._auditRunning) { | |
| 99 this._updateStatus(Common.UIString('Cancelling...')); | |
| 100 this._stop(); | |
| 101 return; | |
| 102 } | |
| 103 this._start(); | |
| 104 } | 153 } |
| 105 | 154 |
| 106 _updateButton() { | 155 _updateButton() { |
| 107 this._startButton.textContent = | 156 this._startButton.classList.toggle('default', !this._auditRunning); |
| 108 this._auditRunning ? Common.UIString('Cancel audit') : Common.UIString(' Audit this page'); | 157 this._startButton.disabled = this._auditRunning; |
| 109 this._startButton.classList.toggle('started', this._auditRunning); | |
| 110 this._statusView.classList.toggle('hidden', !this._auditRunning); | 158 this._statusView.classList.toggle('hidden', !this._auditRunning); |
| 111 } | 159 } |
| 112 | 160 |
| 113 /** | 161 /** |
| 114 * @param {string} statusMessage | 162 * @param {string} statusMessage |
| 115 */ | 163 */ |
| 116 _updateStatus(statusMessage) { | 164 _updateStatus(statusMessage) { |
| 117 this._statusElement.textContent = statusMessage; | 165 this._statusElement.textContent = statusMessage; |
| 118 } | 166 } |
| 119 | 167 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 132 } | 180 } |
| 133 | 181 |
| 134 /** | 182 /** |
| 135 * @param {!ReportRenderer.ReportJSON} lighthouseResult | 183 * @param {!ReportRenderer.ReportJSON} lighthouseResult |
| 136 */ | 184 */ |
| 137 _finish(lighthouseResult) { | 185 _finish(lighthouseResult) { |
| 138 if (lighthouseResult === null) { | 186 if (lighthouseResult === null) { |
| 139 this._updateStatus(Common.UIString('Auditing failed.')); | 187 this._updateStatus(Common.UIString('Auditing failed.')); |
| 140 return; | 188 return; |
| 141 } | 189 } |
| 142 this._resultsView.removeChildren(); | 190 var treeElement = new Audits2.Audits2Panel.TreeElement(lighthouseResult, thi s.mainElement()); |
| 143 | 191 this._treeOutline.appendChild(treeElement); |
| 144 var url = lighthouseResult.url; | 192 treeElement._populate(); |
| 145 var timestamp = lighthouseResult.generatedTime; | 193 treeElement.select(); |
| 146 this._createResultsBar(this._resultsView, url, timestamp); | 194 this._dialog.hide(); |
| 147 this._renderReport(this._resultsView, lighthouseResult); | |
| 148 this.contentElement.classList.add('show-results'); | |
| 149 } | 195 } |
| 150 | 196 |
| 151 /** | 197 /** |
| 152 * @param {!Error} err | 198 * @param {!Error} err |
| 153 */ | 199 */ |
| 154 _renderBugReport(err) { | 200 _renderBugReport(err) { |
| 155 console.error(err); | 201 console.error(err); |
| 156 this._statusElement.textContent = ''; | 202 this._statusElement.textContent = ''; |
| 157 this._statusIcon.classList.add('error'); | 203 this._statusIcon.classList.add('error'); |
| 158 this._statusElement.createTextChild(Common.UIString('We ran into an error. ' )); | 204 this._statusElement.createTextChild(Common.UIString('We ran into an error. ' )); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 170 var qsBody = ''; | 216 var qsBody = ''; |
| 171 qsBody += '**Error Message**: ' + err.message + '\n'; | 217 qsBody += '**Error Message**: ' + err.message + '\n'; |
| 172 qsBody += '**Stack Trace**:\n ```' + err.stack + '```'; | 218 qsBody += '**Stack Trace**:\n ```' + err.stack + '```'; |
| 173 var body = '&body=' + encodeURI(qsBody); | 219 var body = '&body=' + encodeURI(qsBody); |
| 174 | 220 |
| 175 var reportErrorEl = parentElem.createChild('a', 'audits2-link audits2-report -error'); | 221 var reportErrorEl = parentElem.createChild('a', 'audits2-link audits2-report -error'); |
| 176 reportErrorEl.href = baseURI + title + body; | 222 reportErrorEl.href = baseURI + title + body; |
| 177 reportErrorEl.textContent = Common.UIString('Report this bug'); | 223 reportErrorEl.textContent = Common.UIString('Report this bug'); |
| 178 reportErrorEl.target = '_blank'; | 224 reportErrorEl.target = '_blank'; |
| 179 } | 225 } |
| 180 | |
| 181 /** | |
| 182 * @param {!Element} resultsView | |
| 183 * @param {!ReportRenderer.ReportJSON} lighthouseResult | |
| 184 * @suppressGlobalPropertiesCheck | |
| 185 */ | |
| 186 _renderReport(resultsView, lighthouseResult) { | |
| 187 var reportContainer = resultsView.createChild('div', 'report-container lh-ro ot'); | |
| 188 | |
| 189 var dom = new DOM(document); | |
| 190 var detailsRenderer = new DetailsRenderer(dom); | |
| 191 var categoryRenderer = new CategoryRenderer(dom, detailsRenderer); | |
| 192 var renderer = new Audits2.ReportRenderer(dom, categoryRenderer); | |
| 193 | |
| 194 var templatesHTML = Runtime.cachedResources['audits2/lighthouse/templates.ht ml']; | |
| 195 var templatesDOM = new DOMParser().parseFromString(templatesHTML, 'text/html '); | |
| 196 if (!templatesDOM) | |
| 197 return; | |
| 198 | |
| 199 renderer.setTemplateContext(templatesDOM); | |
| 200 renderer.renderReport(lighthouseResult, reportContainer); | |
| 201 } | |
| 202 | |
| 203 /** | |
| 204 * @param {!Element} resultsView | |
| 205 * @param {string} url | |
| 206 * @param {string} timestamp | |
| 207 */ | |
| 208 _createResultsBar(resultsView, url, timestamp) { | |
| 209 var elem = resultsView.createChild('div', 'results-bar hbox'); | |
| 210 elem.createChild('div', 'audits2-logo audits2-logo-small'); | |
| 211 | |
| 212 var summaryElem = elem.createChild('div', 'audits2-summary'); | |
| 213 var reportFor = summaryElem.createChild('span'); | |
| 214 reportFor.createTextChild('Report for '); | |
| 215 var urlElem = reportFor.createChild('b'); | |
| 216 urlElem.textContent = url; | |
| 217 var timeElem = summaryElem.createChild('span'); | |
| 218 timeElem.textContent = | |
| 219 `Generated at ${new Date(timestamp).toLocaleDateString()} ${new Date(tim estamp).toLocaleTimeString()}`; | |
| 220 | |
| 221 var newAuditButton = | |
| 222 UI.createTextButton(Common.UIString('New Audit'), this._reset.bind(this) , 'new-audit audit-btn'); | |
| 223 elem.appendChild(newAuditButton); | |
| 224 } | |
| 225 }; | 226 }; |
| 226 | 227 |
| 227 /** | 228 /** |
| 228 * @override | 229 * @override |
| 229 */ | 230 */ |
| 230 Audits2.ReportRenderer = class extends ReportRenderer { | 231 Audits2.Audits2Panel.ReportRenderer = class extends ReportRenderer { |
| 231 /** | 232 /** |
| 232 * Provides empty element for left nav | 233 * Provides empty element for left nav |
| 233 * @override | 234 * @override |
| 234 * @returns {!DocumentFragment} | 235 * @returns {!DocumentFragment} |
| 235 */ | 236 */ |
| 236 _renderReportNav() { | 237 _renderReportNav() { |
| 237 return createDocumentFragment(); | 238 return createDocumentFragment(); |
| 238 } | 239 } |
| 240 | |
| 241 /** | |
| 242 * @param {!ReportRenderer.ReportJSON} report | |
| 243 * @override | |
| 244 * @return {!DocumentFragment} | |
| 245 */ | |
| 246 _renderReportHeader(report) { | |
| 247 return createDocumentFragment(); | |
| 248 } | |
| 239 }; | 249 }; |
| 240 | 250 |
| 241 | |
| 242 class ReportUIFeatures { | 251 class ReportUIFeatures { |
| 243 /** | 252 /** |
| 244 * @param {!ReportRenderer.ReportJSON} report | 253 * @param {!ReportRenderer.ReportJSON} report |
| 245 */ | 254 */ |
| 246 initFeatures(report) {} | 255 initFeatures(report) { |
| 256 } | |
| 247 } | 257 } |
| 248 | 258 |
| 249 /** @typedef {{id: string, configID: string, description: string}} */ | 259 /** @typedef {{id: string, configID: string, description: string}} */ |
| 250 Audits2.Audits2Panel.Preset; | 260 Audits2.Audits2Panel.Preset; |
| 251 | 261 |
| 252 /** @type {!Array.<!Audits2.Audits2Panel.Preset>} */ | 262 /** @type {!Array.<!Audits2.Audits2Panel.Preset>} */ |
| 253 Audits2.Audits2Panel.Presets = [ | 263 Audits2.Audits2Panel.Presets = [ |
| 254 // configID maps to Lighthouse's Object.keys(config.categories)[0] value | 264 // configID maps to Lighthouse's Object.keys(config.categories)[0] value |
| 255 {id: 'audits2_cat_pwa', configID: 'pwa', description: 'Progressive Web App'}, | 265 { |
| 256 {id: 'audits2_cat_perf', configID: 'performance', description: 'Performance me trics and diagnostics'}, | 266 id: 'audits2_cat_pwa', |
| 257 {id: 'audits2_cat_a11y', configID: 'accessibility', description: 'Accessibilit y'}, | 267 configID: 'pwa', |
| 258 {id: 'audits2_cat_best_practices', configID: 'best-practices', description: 'M odern best practices'}, | 268 title: 'Progressive Web App', |
| 269 description: 'Does this page meet the standard of a Progressive Web App' | |
|
dgozman
2017/05/02 01:27:56
can just inline setting here:
setting: Common.set
pfeldman
2017/05/02 17:54:46
Done.
| |
| 270 }, | |
| 271 { | |
| 272 id: 'audits2_cat_perf', | |
| 273 configID: 'performance', | |
| 274 title: 'Performance', | |
| 275 description: 'How long does this app take to show content and become usable' | |
| 276 }, | |
| 277 { | |
| 278 id: 'audits2_cat_best_practices', | |
| 279 configID: 'best-practices', | |
| 280 title: 'Best practices', | |
| 281 description: 'Does this page follow best practices for modern web developmen t' | |
| 282 }, | |
| 283 { | |
| 284 id: 'audits2_cat_a11y', | |
| 285 configID: 'accessibility', | |
| 286 title: 'Accessibility', | |
| 287 description: 'Is this page usable by people with disabilities or impairments ' | |
| 288 }, | |
| 259 ]; | 289 ]; |
| 260 | 290 |
| 261 Audits2.ProtocolService = class extends Common.Object { | 291 Audits2.ProtocolService = class extends Common.Object { |
| 262 constructor() { | 292 constructor() { |
| 263 super(); | 293 super(); |
| 264 /** @type {?Protocol.InspectorBackend.Connection} */ | 294 /** @type {?Protocol.InspectorBackend.Connection} */ |
| 265 this._rawConnection = null; | 295 this._rawConnection = null; |
| 266 /** @type {?Services.ServiceManager.Service} */ | 296 /** @type {?Services.ServiceManager.Service} */ |
| 267 this._backend = null; | 297 this._backend = null; |
| 268 /** @type {?Promise} */ | 298 /** @type {?Promise} */ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 * @param {!Object=} params | 360 * @param {!Object=} params |
| 331 * @return {!Promise<!ReportRenderer.ReportJSON>} | 361 * @return {!Promise<!ReportRenderer.ReportJSON>} |
| 332 */ | 362 */ |
| 333 _send(method, params) { | 363 _send(method, params) { |
| 334 if (!this._backendPromise) | 364 if (!this._backendPromise) |
| 335 this._initWorker(); | 365 this._initWorker(); |
| 336 | 366 |
| 337 return this._backendPromise.then(_ => this._backend.send(method, params)); | 367 return this._backendPromise.then(_ => this._backend.send(method, params)); |
| 338 } | 368 } |
| 339 }; | 369 }; |
| 370 | |
| 371 Audits2.Audits2Panel.TreeElement = class extends UI.TreeElement { | |
| 372 /** | |
| 373 * @param {!ReportRenderer.ReportJSON} lighthouseResult | |
| 374 * @param {!Element} resultsView | |
| 375 */ | |
| 376 constructor(lighthouseResult, resultsView) { | |
| 377 super('', false); | |
| 378 this._lighthouseResult = lighthouseResult; | |
| 379 this._resultsView = resultsView; | |
| 380 /** @type {?Element} */ | |
| 381 this._reportContainer = null; | |
| 382 | |
| 383 var url = new Common.ParsedURL(lighthouseResult.url); | |
| 384 var timestamp = lighthouseResult.generatedTime; | |
| 385 var titleElement = this.titleElement(); | |
| 386 titleElement.classList.add('audits2-report-tree-item'); | |
| 387 titleElement.createChild('div').textContent = url.domain(); | |
| 388 titleElement.createChild('span', 'dimmed').textContent = new Date(timestamp) .toLocaleString(); | |
| 389 } | |
| 390 | |
| 391 _populate() { | |
| 392 for (var category of this._lighthouseResult.reportCategories) { | |
| 393 var treeElement = new Audits2.Audits2Panel.TreeSubElement(category.id, cat egory.name, category.score); | |
| 394 this.appendChild(treeElement); | |
| 395 } | |
| 396 } | |
| 397 | |
| 398 /** | |
| 399 * @override | |
| 400 * @param {boolean=} selectedByUser | |
| 401 * @return {boolean} | |
| 402 */ | |
| 403 onselect(selectedByUser) { | |
| 404 this._renderReport(); | |
| 405 return true; | |
| 406 } | |
| 407 | |
| 408 /** | |
| 409 * @override | |
| 410 */ | |
| 411 onunbind() { | |
| 412 if (this._reportContainer && this._reportContainer.parentElement) | |
| 413 this._reportContainer.remove(); | |
| 414 } | |
| 415 | |
| 416 _renderReport() { | |
| 417 this._resultsView.removeChildren(); | |
| 418 if (this._reportContainer) { | |
| 419 this._resultsView.appendChild(this._reportContainer); | |
| 420 return; | |
| 421 } | |
| 422 | |
| 423 this._reportContainer = this._resultsView.createChild('div', 'report-contain er lh-root'); | |
| 424 | |
| 425 var dom = new DOM(/** @type {!Document} */(this._resultsView.ownerDocument)) ; | |
| 426 var detailsRenderer = new DetailsRenderer(dom); | |
| 427 var categoryRenderer = new CategoryRenderer(dom, detailsRenderer); | |
| 428 var renderer = new Audits2.Audits2Panel.ReportRenderer(dom, categoryRenderer ); | |
| 429 | |
| 430 var templatesHTML = Runtime.cachedResources['audits2/lighthouse/templates.ht ml']; | |
| 431 var templatesDOM = new DOMParser().parseFromString(templatesHTML, 'text/html '); | |
| 432 if (!templatesDOM) | |
| 433 return; | |
| 434 | |
| 435 renderer.setTemplateContext(templatesDOM); | |
| 436 renderer.renderReport(this._lighthouseResult, this._reportContainer); | |
| 437 } | |
| 438 }; | |
| 439 | |
| 440 Audits2.Audits2Panel.TreeSubElement = class extends UI.TreeElement { | |
| 441 /** | |
| 442 * @param {string} id | |
| 443 * @param {string} name | |
| 444 * @param {number} score | |
| 445 */ | |
| 446 constructor(id, name, score) { | |
| 447 super(''); | |
| 448 this._id = id; | |
| 449 this.listItemElement.textContent = name; | |
| 450 var label = Util.calculateRating(score); | |
| 451 var subtitleElement = this.listItemElement.createChild('span', 'lh-root audi ts2-tree-subtitle-' + label); | |
| 452 subtitleElement.textContent = String(Math.round(score)); | |
| 453 } | |
| 454 | |
| 455 /** | |
| 456 * @override | |
| 457 * @return {boolean} | |
| 458 */ | |
| 459 onselect() { | |
| 460 this.parent._renderReport(); | |
| 461 var node = this.parent._resultsView.querySelector('.lh-category[id=' + this. _id + ']'); | |
| 462 if (node) { | |
| 463 node.scrollIntoView(true); | |
| 464 return true; | |
| 465 } | |
| 466 return false; | |
| 467 } | |
| 468 }; | |
| OLD | NEW |