mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 10:16:46 +00:00
HA Logs: Copy log (#6945)
This commit is contained in:
parent
1bc9b95289
commit
868399ed6f
@ -1,14 +1,21 @@
|
|||||||
|
import "@material/mwc-icon-button/mwc-icon-button";
|
||||||
|
import { mdiContentCopy } from "@mdi/js";
|
||||||
import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable";
|
import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable";
|
||||||
|
import "@polymer/paper-tooltip/paper-tooltip";
|
||||||
|
import type { PaperTooltipElement } from "@polymer/paper-tooltip/paper-tooltip";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
CSSResult,
|
CSSResult,
|
||||||
html,
|
html,
|
||||||
|
internalProperty,
|
||||||
LitElement,
|
LitElement,
|
||||||
property,
|
property,
|
||||||
internalProperty,
|
query,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/dialog/ha-paper-dialog";
|
import "../../../components/dialog/ha-paper-dialog";
|
||||||
|
import "../../../components/ha-svg-icon";
|
||||||
import {
|
import {
|
||||||
domainToName,
|
domainToName,
|
||||||
fetchIntegrationManifest,
|
fetchIntegrationManifest,
|
||||||
@ -16,12 +23,11 @@ import {
|
|||||||
IntegrationManifest,
|
IntegrationManifest,
|
||||||
} from "../../../data/integration";
|
} from "../../../data/integration";
|
||||||
import { getLoggedErrorIntegration } from "../../../data/system_log";
|
import { getLoggedErrorIntegration } from "../../../data/system_log";
|
||||||
import { PolymerChangedEvent } from "../../../polymer-types";
|
import type { PolymerChangedEvent } from "../../../polymer-types";
|
||||||
import { haStyleDialog } from "../../../resources/styles";
|
import { haStyleDialog } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import { SystemLogDetailDialogParams } from "./show-dialog-system-log-detail";
|
import type { SystemLogDetailDialogParams } from "./show-dialog-system-log-detail";
|
||||||
import { formatSystemLogTime } from "./util";
|
import { formatSystemLogTime } from "./util";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
|
||||||
|
|
||||||
class DialogSystemLogDetail extends LitElement {
|
class DialogSystemLogDetail extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@ -30,6 +36,8 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _manifest?: IntegrationManifest;
|
@internalProperty() private _manifest?: IntegrationManifest;
|
||||||
|
|
||||||
|
@query("paper-tooltip") private _toolTip?: PaperTooltipElement;
|
||||||
|
|
||||||
public async showDialog(params: SystemLogDetailDialogParams): Promise<void> {
|
public async showDialog(params: SystemLogDetailDialogParams): Promise<void> {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
this._manifest = undefined;
|
this._manifest = undefined;
|
||||||
@ -66,13 +74,25 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
opened
|
opened
|
||||||
@opened-changed="${this._openedChanged}"
|
@opened-changed="${this._openedChanged}"
|
||||||
>
|
>
|
||||||
<h2>
|
<div class="heading">
|
||||||
${this.hass.localize(
|
<h2>
|
||||||
"ui.panel.config.logs.details",
|
${this.hass.localize(
|
||||||
"level",
|
"ui.panel.config.logs.details",
|
||||||
item.level
|
"level",
|
||||||
)}
|
item.level
|
||||||
</h2>
|
)}
|
||||||
|
</h2>
|
||||||
|
<mwc-icon-button id="copy" @click=${this._copyLog}>
|
||||||
|
<ha-svg-icon .path=${mdiContentCopy}></ha-svg-icon>
|
||||||
|
</mwc-icon-button>
|
||||||
|
<paper-tooltip
|
||||||
|
manual-mode
|
||||||
|
for="copy"
|
||||||
|
position="top"
|
||||||
|
animation-delay="0"
|
||||||
|
>${this.hass.localize("ui.common.copied")}</paper-tooltip
|
||||||
|
>
|
||||||
|
</div>
|
||||||
<paper-dialog-scrollable>
|
<paper-dialog-scrollable>
|
||||||
<p>
|
<p>
|
||||||
Logger: ${item.name}<br />
|
Logger: ${item.name}<br />
|
||||||
@ -148,6 +168,25 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _copyLog(): void {
|
||||||
|
const copyElement = this.shadowRoot?.querySelector(
|
||||||
|
"paper-dialog-scrollable"
|
||||||
|
) as HTMLElement;
|
||||||
|
|
||||||
|
const selection = window.getSelection()!;
|
||||||
|
const range = document.createRange();
|
||||||
|
|
||||||
|
range.selectNodeContents(copyElement);
|
||||||
|
selection.removeAllRanges();
|
||||||
|
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 [
|
return [
|
||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
@ -164,6 +203,15 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
pre {
|
pre {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
.heading {
|
||||||
|
display: flex;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
.heading ha-svg-icon {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,8 @@
|
|||||||
"successfully_saved": "Successfully saved",
|
"successfully_saved": "Successfully saved",
|
||||||
"successfully_deleted": "Successfully deleted",
|
"successfully_deleted": "Successfully deleted",
|
||||||
"back": "Back",
|
"back": "Back",
|
||||||
"error_required": "Required"
|
"error_required": "Required",
|
||||||
|
"copied": "Copied"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"logbook": {
|
"logbook": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user