Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI updates: Added copy button for individual logs (#1877)

Sakib Mahmud82d38fbca2eb
diff --git a/ui/app/shared/locales/en/or.json b/ui/app/shared/locales/en/or.json
index d96260358..a427680bb 100644
--- a/ui/app/shared/locales/en/or.json
+++ b/ui/app/shared/locales/en/or.json
@@ -294,6 +294,7 @@
"subCategoryFilters": "Sub category filters",
"category": "Category",
"subCategory": "Sub category",
+ "copiedToClipboard": "Copied to clipboard successfully.",
"message": "Message",
"warn": "Warning",
"error": "Error",
diff --git a/ui/app/shared/locales/nl/or.json b/ui/app/shared/locales/nl/or.json
index aa654b262..ea308fd5e 100644
--- a/ui/app/shared/locales/nl/or.json
+++ b/ui/app/shared/locales/nl/or.json
@@ -294,6 +294,7 @@
"subCategoryFilters": "Subcategorie filters",
"category": "Categorie",
"subCategory": "Subcategorie",
+ "copiedToClipboard": "Bericht naar klembord gekopieerd!",
"message": "Bericht",
"warn": "Waarschuwing",
"error": "Fout",
@@ -382,7 +383,7 @@
"stop": "Stop",
"stopWarning": "Deze actie sluit de tunnel, en beëindigt alle actieve verbindingen.",
"copyAddress": "Kopieer adres",
- "copySuccess": "Adres gekopieerd naar je klipbord",
+ "copySuccess": "Adres gekopieerd naar je klembord",
"id": "ID",
"gatewayId": "Gateway ID",
"type": "Type",
diff --git a/ui/component/or-log-viewer/src/index.ts b/ui/component/or-log-viewer/src/index.ts
index a61d158f3..15ce718e9 100644
--- a/ui/component/or-log-viewer/src/index.ts
+++ b/ui/component/or-log-viewer/src/index.ts
@@ -10,7 +10,7 @@ import {customElement, property, query} from "lit/decorators.js";
import i18next from "i18next";
import {translate} from "@openremote/or-translate";
import * as Model from "@openremote/model";
-import manager, {DefaultColor2, DefaultColor3, Util} from "@openremote/core";
+import manager, {DefaultColor2, DefaultColor3, DefaultColor4, DefaultColor5, Util} from "@openremote/core";
import "@openremote/or-mwc-components/or-mwc-input";
import "@openremote/or-components/or-panel";
import "@openremote/or-translate";
@@ -21,6 +21,9 @@ import "@openremote/or-mwc-components/or-mwc-menu";
import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";
import {ListItem} from "@openremote/or-mwc-components/or-mwc-list";
import { GenericAxiosResponse } from "axios";
+import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";
+import { when } from "lit/directives/when.js";
+
// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
const linkParser = require("http-link-header");
@@ -144,10 +147,18 @@ const style = css`
table-layout: fixed;
}
- #table th, #table td {
+ #table th:not(.icon-cell), #table td:not(.icon-cell) {
word-wrap: break-word;
white-space: pre-wrap;
}
+
+ .copy-button {
+ --or-mwc-input-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
+ }
+
+ .copy-button:hover {
+ --or-mwc-input-color: var(--or-app-color4, ${unsafeCSS(DefaultColor4)});
+ }
`;
@customElement("or-log-viewer")
@@ -410,7 +421,6 @@ export class OrLogViewer extends translate(i18next)(LitElement) {
}
protected _getTable(): TemplateResult {
-
return html`
<div id="table" class="mdc-data-table">
<table class="mdc-data-table__table" aria-label="logs list">
@@ -420,7 +430,8 @@ export class OrLogViewer extends translate(i18next)(LitElement) {
<th style="width: 80px" class="mdc-data-table__header-cell" role="columnheader" scope="col">${i18next.t("level")}</th>
<th style="width: 130px" class="mdc-data-table__header-cell" role="columnheader" scope="col">${i18next.t("category")}</th>
<th style="width: 180px" class="mdc-data-table__header-cell" role="columnheader" scope="col">${i18next.t("subCategory")}</th>
- <th style="width: 100%; min-width: 300px;" class="mdc-data-table__header-cell" role="columnheader" scope="col">${i18next.t("message")}</th>
+ <th style="width: 100%; min-width: 300px;" class="mdc-data-table__header-cell" role="columnheader" scope="col">${i18next.t("message")}</th>
+ <th style="width: 80px;" class="mdc-data-table__header-cell" role="columnheader" scope="col"></th>
</tr>
</thead>
<tbody class="mdc-data-table__content">
@@ -430,8 +441,13 @@ export class OrLogViewer extends translate(i18next)(LitElement) {
<td class="mdc-data-table__cell">${moment(ev.timestamp).format(OrLogViewer.DEFAULT_TIMESTAMP_FORMAT)}</td>
<td class="mdc-data-table__cell">${i18next.t(ev.level!)}</td>
<td class="mdc-data-table__cell">${i18next.t(ev.category!)}</td>
- <td class="mdc-data-table__cell">${i18next.t(ev.subCategory!)}</td>
- <td class="mdc-data-table__cell">${ev.message}</td>
+ <td class="mdc-data-table__cell">${i18next.t(ev.subCategory!)}</td>
+ <td class="mdc-data-table__cell">${ev.message}</td>
+ <td class="mdc-data-table__cell icon-cell">
+ ${when(window.isSecureContext, () => html`
+ <or-mwc-input type="${InputType.BUTTON}" class="copy-button" icon="content-copy" @or-mwc-input-changed=${() => this._copyRow(ev)}></or-mwc-input>
+ `)}
+ </td>
</tr>
`;
})}
@@ -440,6 +456,17 @@ export class OrLogViewer extends translate(i18next)(LitElement) {
</div>
`;
}
+
+ /** Copy a single log event to the clipboard as JSON */
+ protected async _copyRow(row: Model.SyslogEvent) {
+ try {
+ const text = row.message || "";
+ await navigator.clipboard.writeText(text);
+ showSnackbar(undefined, i18next.t("copiedToClipboard"));
+ } catch (err){
+ console.error("Failed to copy:", err);
+ }
+ }
protected _getIntervalOptions(): [string, string][] {
return [