1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96

ash / webui / connectivity_diagnostics / resources / connectivity_diagnostics.ts [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'chrome://resources/ash/common/network_health/network_diagnostics.js';
import 'chrome://resources/ash/common/network_health/network_health_summary.js';
import 'chrome://resources/ash/common/cr_elements/cr_shared_style.css.js';
import '/strings.m.js';

import {CrContainerShadowMixin} from 'chrome://resources/ash/common/cr_elements/cr_container_shadow_mixin.js';
import {I18nMixin} from 'chrome://resources/ash/common/cr_elements/i18n_mixin.js';
import {NetworkDiagnosticsElement} from 'chrome://resources/ash/common/network_health/network_diagnostics.js';
import {sendWithPromise} from 'chrome://resources/js/cr.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {getTemplate} from './connectivity_diagnostics.html.js';

/**
 * @fileoverview
 * Polymer element connectivity diagnostics UI.
 */

export interface ConnectivityDiagnosticsElement {
  $: {
    networkDiagnostics: NetworkDiagnosticsElement,
  };
}

const ConnectivityDiagnosticsElementBase =
    I18nMixin(CrContainerShadowMixin(PolymerElement));

export class ConnectivityDiagnosticsElement extends
    ConnectivityDiagnosticsElementBase {
  static get is() {
    return 'connectivity-diagnostics';
  }

  static get template() {
    return getTemplate();
  }

  static get properties() {
    return {
      /**
       * Boolean flag to show the feedback button in the app.
       */
      showFeedbackBtn_: {
        type: Boolean,
        value: false,
      },
    };
  }

  private showFeedbackBtn_: boolean;

  override connectedCallback() {
    super.connectedCallback();
    this.getShowFeedbackBtn_();
    this.runAllRoutines_();
  }

  private runAllRoutines_(): void {
    this.$.networkDiagnostics.runAllRoutines();
  }

  private onCloseClick_(): void {
    self.close();
  }

  private onRunAllRoutinesClick_(): void {
    this.runAllRoutines_();
  }

  /**
   * Handles requests to open the feedback report dialog. The provided string
   * in the event will be sent as a part of the feedback report.
   */
  private onSendFeedbackClick_(): void {
    chrome.send('sendFeedbackReport');
  }

  private getShowFeedbackBtn_(): void {
    sendWithPromise('getShowFeedbackButton').then(result => {
      this.showFeedbackBtn_ = result[0];
    });
  }
}

declare global {
  interface HTMLElementTagNameMap {
    'connectivity-diagnostics': ConnectivityDiagnosticsElement;
  }
}

customElements.define(
    ConnectivityDiagnosticsElement.is, ConnectivityDiagnosticsElement);