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: Bugfixes for insights (#926)

Martin Peeters6ef836d2144b
diff --git a/ui/component/or-dashboard-builder/package.json b/ui/component/or-dashboard-builder/package.json
index 8a4403c6e..3f1da1278 100644
--- a/ui/component/or-dashboard-builder/package.json
+++ b/ui/component/or-dashboard-builder/package.json
@@ -19,7 +19,7 @@
"@openremote/core": "workspace:*",
"@openremote/model": "workspace:*",
"@openremote/rest": "workspace:*",
- "gridstack": "^6.0.2",
+ "gridstack": "^7.2.0",
"lit": "^2.0.2"
},
"devDependencies": {
diff --git a/ui/component/or-dashboard-builder/src/index.ts b/ui/component/or-dashboard-builder/src/index.ts
index faf1dae21..ee7fdf86d 100644
--- a/ui/component/or-dashboard-builder/src/index.ts
+++ b/ui/component/or-dashboard-builder/src/index.ts
@@ -1,6 +1,7 @@
import {css, html, LitElement, unsafeCSS} from "lit";
import {customElement, property, state} from "lit/decorators.js";
import {when} from 'lit/directives/when.js';
+import {styleMap} from 'lit/directives/style-map.js';
import "./or-dashboard-tree";
import "./or-dashboard-browser";
import "./or-dashboard-preview";
@@ -39,12 +40,20 @@ const styling = css`
@media only screen and (min-width: 641px){
#tree {
- max-width: 300px !important;
+ min-width: 300px !important;
+ }
+ }
+ @media only screen and (max-width: 641px) {
+ #tree {
+ flex: 1 !important;
+ }
+ #builder {
+ max-height: inherit !important;
}
}
#tree {
- flex-shrink: 0;
+ flex: 0;
align-items: stretch;
z-index: 1;
box-shadow: rgb(0 0 0 / 21%) 0px 1px 3px 0px;
@@ -52,8 +61,6 @@ const styling = css`
/* Header related styling */
#header {
- display: table-row;
- height: 1px;
background: var(--or-app-color1, ${unsafeCSS(DefaultColor1)});
}
#header-wrapper {
@@ -81,10 +88,6 @@ const styling = css`
}
/* Header related styling */
- #fullscreen-header {
- display: table-row;
- height: 1px;
- }
@media screen and (max-width: 700px) {
#fullscreen-header-wrapper {
padding: 11px !important;
@@ -432,7 +435,7 @@ export class OrDashboardBuilder extends LitElement {
if(this.selectedDashboard != null) {
const dashboard = this.selectedDashboard;
dashboard.displayName = value;
- this.selectedDashboard = Object.assign({}, dashboard);
+ this.requestUpdate("selectedDashboard");
}
}
@@ -504,6 +507,10 @@ export class OrDashboardBuilder extends LitElement {
this.dispatchEvent(new CustomEvent('editToggle', { detail: false }));
this.showDashboardTree = true;
}
+ const builderStyles = {
+ display: (this.editMode && (this._isReadonly() || !this._hasEditAccess())) ? 'none' : undefined,
+ maxHeight: this.editMode ? "calc(100vh - 77px - 50px)" : "inherit"
+ };
return (!this.isInitializing || (this.dashboards != null && this.dashboards.length == 0)) ? html`
<div id="container">
${(this.showDashboardTree) ? html`
@@ -514,9 +521,9 @@ export class OrDashboardBuilder extends LitElement {
@select="${(event: CustomEvent) => { this.selectDashboard(event.detail); }}"
></or-dashboard-tree>
` : undefined}
- <div id="container" class="${this.selectedDashboard == null ? 'hideMobile' : undefined}" style="display: table;">
+ <div class="${this.selectedDashboard == null ? 'hideMobile' : undefined}" style="flex: 1; display: flex; flex-direction: column;">
${this.editMode ? html`
- <div id="header" class="hideMobile" style="display: ${this.selectedDashboard == null && 'none'}">
+ <div id="header" class="hideMobile">
<div id="header-wrapper">
<div id="header-title">
<or-icon icon="view-dashboard"></or-icon>
@@ -564,14 +571,14 @@ export class OrDashboardBuilder extends LitElement {
</div>
</div>
`}
- <div id="content">
+ <div id="content" style="flex: 1;">
<div id="container">
${(this.editMode && (this._isReadonly() || !this._hasEditAccess())) ? html`
<div style="display: flex; justify-content: center; align-items: center; height: 100%;">
<span>${!this._hasEditAccess() ? i18next.t('noDashboardWriteAccess') : i18next.t('errorOccurred')}.</span>
</div>
` : undefined}
- <div id="builder" style="${(this.editMode && (this._isReadonly() || !this._hasEditAccess())) ? 'display: none' : undefined}">
+ <div id="builder" style="${styleMap(builderStyles)}">
${(this.selectedDashboard != null) ? html`
<or-dashboard-preview class="editor" style="background: transparent;"
.realm="${this.realm}" .template="${this.currentTemplate}" .rerenderPending="${this.rerenderPending}"
diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts b/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts
index cff87e1bc..f44b70a16 100644
--- a/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts
+++ b/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts
@@ -42,7 +42,7 @@ const editorStyling = css`
.maingridContainer {
position: absolute;
- padding-bottom: 64px;
+ padding-bottom: 32px;
}
.maingridContainer__fullscreen {
width: 100%;
@@ -63,7 +63,7 @@ const editorStyling = css`
border-radius: 0;
overflow-x: hidden;
overflow-y: scroll;
- /*height: 100% !important;*/ /* To override .maingrid */
+ height: 100% !important; /* To override .maingrid */
width: 100% !important; /* To override .maingrid */
padding: 0;
/*pointer-events: none;*/
@@ -468,18 +468,6 @@ export class OrDashboardPreview extends LitElement {
}
} catch (e) { console.error(e); }
- // Set manual px height in case of fullscreen, to make scrollbar work without issues (especially when drag-and-dropping widgets)
- this.waitUntil((_: any) => this.shadowRoot?.querySelector('.maingrid') != null).then(() => {
- const grid: HTMLElement = this.shadowRoot?.querySelector('.maingrid') as HTMLElement;
- if(grid && this.fullscreen) {
- grid.style.height = grid.parentElement!.clientHeight + "px";
- }
- const background: HTMLElement = this.shadowRoot?.getElementById('gridElement') as HTMLElement;
- if(background) {
- background.style.height = grid.scrollHeight + "px";
- }
- })
-
const customPreset = "Custom";
let screenPresets = this.template?.screenPresets?.map(s => s.displayName);
screenPresets?.push(customPreset);
@@ -595,6 +583,11 @@ export class OrDashboardPreview extends LitElement {
protected previousObserverEntry?: ResizeObserverEntry;
+ disconnectedCallback() {
+ super.disconnectedCallback()
+ this.resizeObserver?.disconnect();
+ }
+
// Triggering a Grid rerender on every time the element resizes.
// In fullscreen, debounce (only trigger after 550ms of no changes) to limit amount of rerenders.
setupResizeObserver(element: Element): ResizeObserver {
diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.ts b/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.ts
index 05221227d..afb7464de 100644
--- a/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.ts
+++ b/ui/component/or-dashboard-builder/src/or-dashboard-settingspanel.ts
@@ -311,7 +311,6 @@ export class OrDashboardSettingsPanel extends LitElement {
style="padding: 8px 0; display: flex; flex-direction: row; align-items: center;">
<div style="height: 100%; padding: 8px 14px 8px 0;">
<or-mwc-input type="${InputType.COLOUR}" value="${threshold[1]}"
- style="width: 32px; height: 32px;"
@or-mwc-input-changed="${(event: CustomEvent) => {
this._config.thresholds[index][1] = event.detail.value;
this.updateParent(new Map<string, any>([["config", this._config]]));
@@ -348,7 +347,6 @@ export class OrDashboardSettingsPanel extends LitElement {
style="padding: 8px 0; display: flex; flex-direction: row; align-items: center;">
<div style="height: 100%; padding: 8px 14px 8px 0;">
<or-mwc-input type="${InputType.COLOUR}" value="${config.boolColors.true}"
- style="width: 32px; height: 32px;"
@or-mwc-input-changed="${(event: CustomEvent) => {
this._config.boolColors.true = event.detail.value;
this.updateParent(new Map<string, any>([["config", this._config]]));
@@ -362,7 +360,6 @@ export class OrDashboardSettingsPanel extends LitElement {
style="padding: 8px 0; display: flex; flex-direction: row; align-items: center;">
<div style="height: 100%; padding: 8px 14px 8px 0;">
<or-mwc-input type="${InputType.COLOUR}" value="${config.boolColors.false}"
- style="width: 32px; height: 32px;"
@or-mwc-input-changed="${(event: CustomEvent) => {
this._config.boolColors.false = event.detail.value;
this.updateParent(new Map<string, any>([["config", this._config]]));
@@ -380,7 +377,6 @@ export class OrDashboardSettingsPanel extends LitElement {
style="padding: 8px 0; display: flex; flex-direction: row; align-items: center;">
<div style="height: 100%; padding: 8px 14px 8px 0;">
<or-mwc-input type="${InputType.COLOUR}" value="${threshold[1]}"
- style="width: 32px; height: 32px;"
@or-mwc-input-changed="${(event: CustomEvent) => {
this._config.textColors[index][1] = event.detail.value;
this.updateParent(new Map<string, any>([["config", this._config]]));
diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-tree.ts b/ui/component/or-dashboard-builder/src/or-dashboard-tree.ts
index 1cd807eab..211cdbf2c 100644
--- a/ui/component/or-dashboard-builder/src/or-dashboard-tree.ts
+++ b/ui/component/or-dashboard-builder/src/or-dashboard-tree.ts
@@ -42,9 +42,7 @@ export class OrDashboardTree extends LitElement {
@property()
private dashboards: Dashboard[] | undefined;
- @property({hasChanged: (oldVal, val): boolean => {
- return JSON.stringify(oldVal) != JSON.stringify(val);
- }})
+ @property()
private selected: Dashboard | undefined;
@property() // REQUIRED
@@ -71,6 +69,18 @@ export class OrDashboardTree extends LitElement {
});
}
+ shouldUpdate(changedProperties: Map<string, any>) {
+ if(changedProperties.size == 1) {
+
+ // Prevent any update since it is not necessary in its current state.
+ // However, do update when dashboard is saved (aka when hasChanged is set back to false)
+ if(changedProperties.has("hasChanged") && this.hasChanged) {
+ return false;
+ }
+ }
+ return super.shouldUpdate(changedProperties);
+ }
+
private async getAllDashboards() {
return manager.rest.api.DashboardResource.getAllRealmDashboards(this.realm!)
.then((result) => {
@@ -157,12 +167,16 @@ export class OrDashboardTree extends LitElement {
})
if(myDashboards.length > 0) {
const items: ListItem[] = [];
- myDashboards.forEach((d) => { items.push({ icon: "view-dashboard", text: d.displayName, value: d.id }); });
+ myDashboards.sort((a, b) => a.displayName ? a.displayName.localeCompare(b.displayName!) : 0).forEach((d) => {
+ items.push({ icon: "view-dashboard", text: d.displayName, value: d.id });
+ });
dashboardItems.push(items);
}
if(otherDashboards.length > 0) {
const items: ListItem[] = [];
- otherDashboards.forEach((d) => { items.push({ icon: "view-dashboard", text: d.displayName, value: d.id }); });
+ otherDashboards.sort((a, b) => a.displayName ? a.displayName.localeCompare(b.displayName!) : 0).forEach((d) => {
+ items.push({ icon: "view-dashboard", text: d.displayName, value: d.id });
+ });
dashboardItems.push(items);
}
}
diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-widget.ts b/ui/component/or-dashboard-builder/src/or-dashboard-widget.ts
index eac912167..9abdcc64c 100644
--- a/ui/component/or-dashboard-builder/src/or-dashboard-widget.ts
+++ b/ui/component/or-dashboard-builder/src/or-dashboard-widget.ts
@@ -53,6 +53,11 @@ export class OrDashboardWidget extends LitElement {
return changed.size > 0;
}
+ disconnectedCallback() {
+ super.disconnectedCallback()
+ this.resizeObserver?.disconnect();
+ }
+
firstUpdated(_changedProperties: Map<string, any>) {
this.updateComplete.then(() => {
const gridItemElement = this.widgetContainerElement;
diff --git a/ui/component/or-dashboard-builder/src/style.ts b/ui/component/or-dashboard-builder/src/style.ts
index f2fb9f4ca..2b953da6f 100644
--- a/ui/component/or-dashboard-builder/src/style.ts
+++ b/ui/component/or-dashboard-builder/src/style.ts
@@ -37,10 +37,7 @@ export const style = css`
display: none !important;
}
}
-
- #content {
- display: table-row;
- }
+
#container {
display: flex;
width: 100%;
diff --git a/yarn.lock b/yarn.lock
index 778f37b6f..8b207ef08 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2456,7 +2456,7 @@ __metadata:
"@openremote/model": "workspace:*"
"@openremote/rest": "workspace:*"
"@openremote/util": "workspace:*"
- gridstack: ^6.0.2
+ gridstack: ^7.2.0
lit: ^2.0.2
languageName: unknown
linkType: soft
@@ -5563,10 +5563,10 @@ __metadata:
languageName: node
linkType: hard
-"gridstack@npm:^6.0.2":
- version: 6.0.2
- resolution: "gridstack@npm:6.0.2"
- checksum: 6ed7b323d549e7e7a4a09617994de61a8a22ec7949c1f3042eab274f4e931a0e9df49e9797bfc13cad1f7f6f06ed680137c1356c0b9e075f6bf05447b9a4eec9
+"gridstack@npm:^7.2.0":
+ version: 7.2.0
+ resolution: "gridstack@npm:7.2.0"
+ checksum: 695183f0e1aa1610990466b8df95ace8e014cb0f1f50b94aa38d445665cc9224707de280941242685f80ccdba43be6395afd72b005b13d7e150791e9ada83434
languageName: node
linkType: hard