mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-30 20:56:36 +00:00
Add option to copy system info into clipboard (#7323)
This commit is contained in:
parent
3dc6898673
commit
b67575586e
@ -1,14 +1,18 @@
|
|||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
|
import { mdiContentCopy } from "@mdi/js";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
CSSResult,
|
CSSResult,
|
||||||
html,
|
html,
|
||||||
|
internalProperty,
|
||||||
LitElement,
|
LitElement,
|
||||||
property,
|
property,
|
||||||
internalProperty,
|
query,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
|
import "@polymer/paper-tooltip/paper-tooltip";
|
||||||
|
import type { PaperTooltipElement } from "@polymer/paper-tooltip/paper-tooltip";
|
||||||
import { domainToName } from "../../../data/integration";
|
import { domainToName } from "../../../data/integration";
|
||||||
import {
|
import {
|
||||||
fetchSystemHealthInfo,
|
fetchSystemHealthInfo,
|
||||||
@ -37,6 +41,8 @@ class SystemHealthCard extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _info?: SystemHealthInfo;
|
@internalProperty() private _info?: SystemHealthInfo;
|
||||||
|
|
||||||
|
@query("paper-tooltip", true) private _toolTip?: PaperTooltipElement;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -78,7 +84,24 @@ class SystemHealthCard extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card .header=${domainToName(this.hass.localize, "system_health")}>
|
<ha-card>
|
||||||
|
<h1 class="card-header">
|
||||||
|
<div class="card-header-text">
|
||||||
|
${domainToName(this.hass.localize, "system_health")}
|
||||||
|
</div>
|
||||||
|
<mwc-icon-button id="copy" @click=${this._copyInfo}>
|
||||||
|
<ha-svg-icon .path=${mdiContentCopy}></ha-svg-icon>
|
||||||
|
</mwc-icon-button>
|
||||||
|
<paper-tooltip
|
||||||
|
manual-mode
|
||||||
|
for="copy"
|
||||||
|
position="left"
|
||||||
|
animation-delay="0"
|
||||||
|
offset="4"
|
||||||
|
>
|
||||||
|
${this.hass.localize("ui.common.copied")}
|
||||||
|
</paper-tooltip>
|
||||||
|
</h1>
|
||||||
<div class="card-content">${sections}</div>
|
<div class="card-content">${sections}</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
`;
|
`;
|
||||||
@ -104,6 +127,25 @@ class SystemHealthCard extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _copyInfo(): void {
|
||||||
|
const selection = window.getSelection()!;
|
||||||
|
selection.removeAllRanges();
|
||||||
|
|
||||||
|
const copyElement = this.shadowRoot?.querySelector(
|
||||||
|
"ha-card"
|
||||||
|
) as HTMLElement;
|
||||||
|
|
||||||
|
const range = document.createRange();
|
||||||
|
range.selectNodeContents(copyElement);
|
||||||
|
selection.addRange(range);
|
||||||
|
|
||||||
|
document.execCommand("copy");
|
||||||
|
window.getSelection()!.removeAllRanges();
|
||||||
|
|
||||||
|
this._toolTip!.show();
|
||||||
|
setTimeout(() => this._toolTip?.hide(), 3000);
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult {
|
static get styles(): CSSResult {
|
||||||
return css`
|
return css`
|
||||||
table {
|
table {
|
||||||
@ -119,6 +161,11 @@ class SystemHealthCard extends LitElement {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
justify-content: space-between;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,6 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
font-family: var(--code-font-family, monospace);
|
font-family: var(--code-font-family, monospace);
|
||||||
}
|
}
|
||||||
.heading {
|
.heading {
|
||||||
display: flex;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user