Skip to content

armgit / core

Public Imported from GitHub
0

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

UI enhancement: allow more than 10 dashboard widgets

Wouter Voorberg43f5a14f2231
diff --git a/ui/component/or-dashboard-builder/src/index.ts b/ui/component/or-dashboard-builder/src/index.ts
index 67b7a9a29..3bf5a4853 100644
--- a/ui/component/or-dashboard-builder/src/index.ts
+++ b/ui/component/or-dashboard-builder/src/index.ts
@@ -721,7 +721,7 @@ export class OrDashboardBuilder extends LitElement {
<div style="border-bottom: 1px solid ${unsafeCSS(DefaultColor5)};">
<or-mwc-tabs .items="${this.tabItems}" noScroll @activated="${(event: CustomEvent) => { this.sidebarMenuIndex = event.detail.index; }}" style="pointer-events: ${this.selectedDashboard ? undefined : 'none'}"></or-mwc-tabs>
</div>
- <div id="content" class="hidescroll" style="flex: 1; overflow: hidden auto;">
+ <div id="content" style="flex: 1; overflow: auto;">
<div style="position: relative;">
<or-dashboard-browser id="browser" style="position: absolute; ${this.sidebarMenuIndex != 0 ? css`display: none` : null}"></or-dashboard-browser>
<or-dashboard-boardsettings style="position: absolute; ${this.sidebarMenuIndex != 1 ? css`display: none` : null}"
diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-browser.ts b/ui/component/or-dashboard-builder/src/or-dashboard-browser.ts
index c5516390d..538f9532d 100644
--- a/ui/component/or-dashboard-builder/src/or-dashboard-browser.ts
+++ b/ui/component/or-dashboard-builder/src/or-dashboard-browser.ts
@@ -65,7 +65,7 @@ export class OrDashboardBrowser extends LitElement {
protected renderGrid() {
const sidebarElement = this.shadowRoot?.getElementById("sidebarElement");
- const coords: Array<[number, number]> = new Array<[number, number]>([0,0],[2,0], [0,2], [2,2], [0,4], [2,4], [0,6], [2,6], [0,8], [2,8]) // TODO: make this unlimited possibilities with a formula
+ const coords: Array<[number, number]> = this.generateGridCoords(Array.from(widgetTypes).length);
const sidebarItems: any[] = Array.from(widgetTypes)
.sort((a, b) => a[1].displayName.localeCompare(b[1].displayName))
.map((typeArr, index) => {
@@ -157,4 +157,26 @@ export class OrDashboardBrowser extends LitElement {
</div>
`
}
+
+ protected generateGridCoords(count: number): [number, number][] {
+ const result: [number, number][] = [];
+ const step = 2;
+
+ let x = 0;
+ let y = 0;
+
+ for (let i = 0; i < count; i++) {
+ result.push([x, y]);
+
+ // Alternate between x and y stepping
+ if (x === 0) {
+ x = step;
+ } else {
+ x = 0;
+ y += step;
+ }
+ }
+
+ return result;
+ }
}