Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | /** |
| 6 | * @unrestricted |
| 7 | */ |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 8 | Audits.StartView = class extends UI.Widget { |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 9 | /** |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 10 | * @param {!Audits.AuditController} controller |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 11 | */ |
| 12 | constructor(controller) { |
| 13 | super(); |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 14 | this.registerRequiredCSS('audits/auditsStartView.css'); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 15 | this._controller = controller; |
| 16 | this._render(); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @param {string} settingName |
John Emau | 7347716 | 2019-07-17 00:30:51 +0000 | [diff] [blame] | 21 | * @param {string} label |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 22 | * @param {!Element} parentElement |
| 23 | */ |
John Emau | 7347716 | 2019-07-17 00:30:51 +0000 | [diff] [blame] | 24 | _populateRuntimeSettingAsRadio(settingName, label, parentElement) { |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 25 | const runtimeSetting = Audits.RuntimeSettings.find(item => item.setting.name === settingName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 26 | if (!runtimeSetting || !runtimeSetting.options) { |
Patrick Hulce | 05c18ce | 2018-05-24 00:34:56 +0000 | [diff] [blame] | 27 | throw new Error(`${settingName} is not a setting with options`); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 28 | } |
Patrick Hulce | 05c18ce | 2018-05-24 00:34:56 +0000 | [diff] [blame] | 29 | |
John Emau | 84ddefb | 2019-07-16 19:25:56 +0000 | [diff] [blame] | 30 | const control = new Audits.RadioSetting(runtimeSetting.options, runtimeSetting.setting, runtimeSetting.description); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 31 | parentElement.appendChild(control.element); |
John Emau | 7347716 | 2019-07-17 00:30:51 +0000 | [diff] [blame] | 32 | UI.ARIAUtils.setAccessibleName(control.element, label); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | /** |
Patrick Hulce | 05c18ce | 2018-05-24 00:34:56 +0000 | [diff] [blame] | 36 | * @param {string} settingName |
| 37 | * @param {!Element} parentElement |
| 38 | */ |
| 39 | _populateRuntimeSettingAsCheckbox(settingName, parentElement) { |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 40 | const runtimeSetting = Audits.RuntimeSettings.find(item => item.setting.name === settingName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 41 | if (!runtimeSetting || !runtimeSetting.title) { |
Patrick Hulce | 05c18ce | 2018-05-24 00:34:56 +0000 | [diff] [blame] | 42 | throw new Error(`${settingName} is not a setting with a title`); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 43 | } |
Patrick Hulce | 05c18ce | 2018-05-24 00:34:56 +0000 | [diff] [blame] | 44 | |
| 45 | runtimeSetting.setting.setTitle(runtimeSetting.title); |
| 46 | const control = new UI.ToolbarSettingCheckbox(runtimeSetting.setting, runtimeSetting.description); |
| 47 | parentElement.appendChild(control.element); |
| 48 | } |
| 49 | |
| 50 | /** |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 51 | * @param {!UI.Fragment} fragment |
| 52 | */ |
| 53 | _populateFormControls(fragment) { |
| 54 | // Populate the device type |
| 55 | const deviceTypeFormElements = fragment.$('device-type-form-elements'); |
John Emau | 7347716 | 2019-07-17 00:30:51 +0000 | [diff] [blame] | 56 | this._populateRuntimeSettingAsRadio('audits.device_type', ls`Device`, deviceTypeFormElements); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 57 | |
| 58 | // Populate the audit categories |
| 59 | const categoryFormElements = fragment.$('categories-form-elements'); |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 60 | for (const preset of Audits.Presets) { |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 61 | preset.setting.setTitle(preset.title); |
| 62 | const checkbox = new UI.ToolbarSettingCheckbox(preset.setting); |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 63 | const row = categoryFormElements.createChild('div', 'vbox audits-launcher-row'); |
Patrick Hulce | 05c18ce | 2018-05-24 00:34:56 +0000 | [diff] [blame] | 64 | row.title = preset.description; |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 65 | row.appendChild(checkbox.element); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 66 | } |
John Emau | 62fdcee | 2019-10-16 00:08:52 +0000 | [diff] [blame^] | 67 | UI.ARIAUtils.markAsGroup(categoryFormElements); |
| 68 | UI.ARIAUtils.setAccessibleName(categoryFormElements, ls`Audits`); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 69 | |
| 70 | // Populate the throttling |
| 71 | const throttlingFormElements = fragment.$('throttling-form-elements'); |
John Emau | 7347716 | 2019-07-17 00:30:51 +0000 | [diff] [blame] | 72 | this._populateRuntimeSettingAsRadio('audits.throttling', ls`Throttling`, throttlingFormElements); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | // Populate other settings |
| 76 | const otherFormElements = fragment.$('other-form-elements'); |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 77 | this._populateRuntimeSettingAsCheckbox('audits.clear_storage', otherFormElements); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | _render() { |
| 81 | this._startButton = UI.createTextButton( |
vidorteg | 6afbe79 | 2019-09-04 19:00:37 +0000 | [diff] [blame] | 82 | ls`Run audits`, () => this._controller.dispatchEventToListeners(Audits.Events.RequestAuditStart), '', |
| 83 | true /* primary */); |
Patrick Hulce | 05c18ce | 2018-05-24 00:34:56 +0000 | [diff] [blame] | 84 | this.setDefaultFocusedElement(this._startButton); |
| 85 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 86 | const deviceIcon = UI.Icon.create('largeicon-phone'); |
| 87 | const categoriesIcon = UI.Icon.create('largeicon-checkmark'); |
| 88 | const throttlingIcon = UI.Icon.create('largeicon-settings-gear'); |
Christy Chen | 1eea03c | 2019-06-26 19:31:24 +0000 | [diff] [blame] | 89 | const auditsDescription = ls |
| 90 | `Identify and fix common problems that affect your site's performance, accessibility, and user experience.`; // crbug.com/972969 |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 91 | |
| 92 | const fragment = UI.Fragment.build` |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 93 | <div class="vbox audits-start-view"> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 94 | <header> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 95 | <div class="audits-logo"></div> |
| 96 | <div class="audits-start-view-text"> |
John Emau | 0c45387 | 2019-07-17 06:33:22 +0000 | [diff] [blame] | 97 | <h1>${ls`Audits`}</h1> |
Christy Chen | 1eea03c | 2019-06-26 19:31:24 +0000 | [diff] [blame] | 98 | <p> |
| 99 | <span class="text">${auditsDescription}</span> |
John Emau | 97832ab | 2019-07-16 00:37:34 +0000 | [diff] [blame] | 100 | ${UI.XLink.create('https://developers.google.com/web/tools/lighthouse/', ls`Learn more`)} |
Christy Chen | 1eea03c | 2019-06-26 19:31:24 +0000 | [diff] [blame] | 101 | </p> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 102 | </div> |
| 103 | </header> |
| 104 | <form> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 105 | <div class="audits-form-section"> |
| 106 | <div class="audits-form-section-label"> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 107 | <i>${deviceIcon}</i> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 108 | <div class="audits-icon-label">${ls`Device`}</div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 109 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 110 | <div class="audits-form-elements" $="device-type-form-elements"></div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 111 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 112 | <div class="audits-form-section"> |
| 113 | <div class="audits-form-section-label"> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 114 | <i>${categoriesIcon}</i> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 115 | <div class="audits-icon-label">${ls`Audits`}</div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 116 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 117 | <div class="audits-form-elements" $="categories-form-elements"></div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 118 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 119 | <div class="audits-form-section"> |
| 120 | <div class="audits-form-section-label"> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 121 | <i>${throttlingIcon}</i> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 122 | <div class="audits-icon-label">${ls`Throttling`}</div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 123 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 124 | <div class="audits-form-elements" $="throttling-form-elements"></div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 125 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 126 | <div class="audits-form-section"> |
| 127 | <div class="audits-form-section-label"></div> |
| 128 | <div class="audits-form-elements" $="other-form-elements"></div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 129 | </div> |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 130 | <div class="audits-form-section"> |
| 131 | <div class="audits-form-section-label"></div> |
| 132 | <div class="audits-form-elements audits-start-button-container hbox"> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 133 | ${this._startButton} |
cjamcl@google.com | aa1532c | 2019-05-31 03:01:24 +0000 | [diff] [blame] | 134 | <div $="help-text" class="audits-help-text hidden"></div> |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 135 | </div> |
| 136 | </div> |
| 137 | </form> |
| 138 | </div> |
| 139 | `; |
| 140 | |
| 141 | this._helpText = fragment.$('help-text'); |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 142 | this._populateFormControls(fragment); |
| 143 | this.contentElement.appendChild(fragment.element()); |
| 144 | this.contentElement.style.overflow = 'auto'; |
| 145 | } |
| 146 | |
Patrick Hulce | 8d387f1 | 2018-05-29 18:54:54 +0000 | [diff] [blame] | 147 | focusStartButton() { |
| 148 | this._startButton.focus(); |
| 149 | } |
| 150 | |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 151 | /** |
| 152 | * @param {boolean} isEnabled |
| 153 | */ |
| 154 | setStartButtonEnabled(isEnabled) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 155 | if (this._helpText) { |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 156 | this._helpText.classList.toggle('hidden', isEnabled); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 157 | } |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 158 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 159 | if (this._startButton) { |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 160 | this._startButton.disabled = !isEnabled; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 161 | } |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
| 165 | * @param {?string} text |
| 166 | */ |
| 167 | setUnauditableExplanation(text) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 168 | if (this._helpText) { |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 169 | this._helpText.textContent = text; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 +0000 | [diff] [blame] | 170 | } |
Patrick Hulce | a087f62 | 2018-05-18 00:37:53 +0000 | [diff] [blame] | 171 | } |
| 172 | }; |