100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI update: Several bugfixes for appearance page (#1062)
Martin Peeters3de4f7842b00
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.jsonindex 013d1c83b..ccf310657 100644--- a/manager/src/web/shared/locales/en/or.json+++ b/manager/src/web/shared/locales/en/or.json@@ -669,7 +669,7 @@"deleteRealmCustomization": "Delete Style","deleteRealmCustomizationConfirm":"Are you sure you want to delete this Realm style?","mapBounds": "Boundaries",- "mapBoundsDescription": "Define a view box that the user sees",+ "mapBoundsDescription": "Override the default bounds of the map","mapZoom": "Zoom","mapZoomDescription": "Define the zoom level. The entire Earth is '1' and '24' shows the most detail","mapSettings": "Map settings",diff --git a/manager/src/web/shared/locales/nl/or.json b/manager/src/web/shared/locales/nl/or.jsonindex 869941510..c129d8ab6 100644--- a/manager/src/web/shared/locales/nl/or.json+++ b/manager/src/web/shared/locales/nl/or.json@@ -669,7 +669,7 @@"deleteRealmCustomization": "Verwijder stijl","deleteRealmCustomizationConfirm":"Weet je zeker dat je deze realm stijl wilt verwijderen?","mapBounds": "Randen",- "mapBoundsDescription": "Defineer het gebied dat de gebruiker kan gebruiken",+ "mapBoundsDescription": "Overschrijf de standaard kaders van de kaart","mapZoom": "Zoom","mapZoomDescription": "Defineer het zoom niveau. De gehele wereld is '1' en '24' laat het meeste detail zien","mapSettings": "Kaartinstelling",diff --git a/ui/app/manager/src/components/configuration/or-conf-json.ts b/ui/app/manager/src/components/configuration/or-conf-json.tsindex a19294a6f..761766bc4 100644--- a/ui/app/manager/src/components/configuration/or-conf-json.ts+++ b/ui/app/manager/src/components/configuration/or-conf-json.ts@@ -30,80 +30,80 @@ import { ManagerAppConfig } from "@openremote/model";@customElement("or-conf-json")export class OrConfJson extends LitElement {- @property({attribute: false})- public managerConfig: ManagerAppConfig = {};+ @property({attribute: false})+ public managerConfig: ManagerAppConfig = {};- protected _aceEditor: Ref<OrAceEditor> = createRef();+ protected _aceEditor: Ref<OrAceEditor> = createRef();- public beforeSave():false|string|undefined {- if (!this._aceEditor.value) {- return false;+ public beforeSave():false|string|undefined {+ if (!this._aceEditor.value) {+ return false;+ }+ const value = this._aceEditor.value.getValue()+ try {+ return JSON.parse(value || '{}');+ } catch (e) {+ return false;+ }}- const value = this._aceEditor.value.getValue()- try {- return JSON.parse(value ? value : '{}');- } catch (e) {- return false;- }- }- protected _showManagerConfigDialog(){- const _saveConfig = ()=>{- const config = this.beforeSave()- if (config){- this.managerConfig = config as ManagerAppConfig- document.dispatchEvent(- new CustomEvent('saveLocalManagerConfig',- {detail: {value: this.managerConfig}}- )- )- return true- }- return false- }- const dialogActions: DialogAction[] = [- {- actionName: "cancel",- content: i18next.t("cancel")- },- {- actionName: "ok",- content: i18next.t("update"),- action: _saveConfig- },+ protected _showManagerConfigDialog(){+ const _saveConfig = ()=>{+ const config = this.beforeSave()+ if (config) {+ this.managerConfig = config as ManagerAppConfig+ this.dispatchEvent(+ new CustomEvent('saveLocalManagerConfig',+ {detail: {value: this.managerConfig}}+ )+ )+ return true+ }+ return false+ }+ const dialogActions: DialogAction[] = [+ {+ actionName: "cancel",+ content: i18next.t("cancel")+ },+ {+ actionName: "ok",+ content: i18next.t("update"),+ action: _saveConfig+ },- ];- const dialog = showDialog(new OrMwcDialog()- .setActions(dialogActions)- .setHeading("manager_config.json")- .setContent(html `<or-ace-editor ${ref(this._aceEditor)} .value="${this.managerConfig}" ></or-ace-editor>`)- .setStyles(html`- <style>- .mdc-dialog__surface {- width: 1024px;- overflow-x: visible !important;- overflow-y: visible !important;- }- #dialog-content {- border-top-width: 1px;- border-top-style: solid;- border-bottom-width: 1px;- border-bottom-style: solid;- padding: 0;- overflow: visible;- height: 60vh;- }- </style>- `)- .setDismissAction(null));+ ];+ showDialog(new OrMwcDialog()+ .setActions(dialogActions)+ .setHeading("manager_config.json")+ .setContent(html `<or-ace-editor ${ref(this._aceEditor)} .value="${this.managerConfig}" ></or-ace-editor>`)+ .setStyles(html`+ <style>+ .mdc-dialog__surface {+ width: 1024px;+ overflow-x: visible !important;+ overflow-y: visible !important;+ }+ #dialog-content {+ border-top-width: 1px;+ border-top-style: solid;+ border-bottom-width: 1px;+ border-bottom-style: solid;+ padding: 0;+ overflow: visible;+ height: 60vh;+ }+ </style>+ `)+ .setDismissAction(null));- }+ }- render() {- return html`- <or-mwc-input type="button" label="JSON" outlined icon="pencil" @click="${() => {this._showManagerConfigDialog()}}"></or-mwc-input>- `- }+ render() {+ return html`+ <or-mwc-input type="button" label="JSON" outlined icon="pencil" @click="${() => {this._showManagerConfigDialog()}}"></or-mwc-input>+ `+ }diff --git a/ui/app/manager/src/components/configuration/or-conf-map/index.ts b/ui/app/manager/src/components/configuration/or-conf-map/index.tsdeleted file mode 100644index eae69bbf3..000000000--- a/ui/app/manager/src/components/configuration/or-conf-map/index.ts+++ /dev/null@@ -1,138 +0,0 @@-import { css, html, LitElement, PropertyValues } from "lit";-import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";-import "./or-conf-map-card";-import { customElement, property } from "lit/decorators.js";-import manager from "@openremote/core";-import { MapConfig } from "@openremote/model";-import { DialogAction, OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";-import { i18next } from "@openremote/or-translate";-import "@openremote/or-components/or-loading-indicator";---@customElement("or-conf-map")-export class OrConfMap extends LitElement {--- static styles = css`- #btn-add-realm {- margin-top: 4px;- }- `;-- @property({attribute: false})- public config: MapConfig = {};-- protected _availableRealms: {name:string, displayName:string}[] = [];- protected _allRealms: {name:string, displayName:string}[] = [];- protected _addedRealm: null|string = null-- protected firstUpdated(_changedProperties: Map<PropertyKey, unknown>): void {- const app = this- manager.rest.api.RealmResource.getAccessible().then((response)=>{- app._allRealms = response.data as {name:string, displayName:string}[];- app._allRealms.push({name: 'default', displayName: 'Default'})- app._loadListOfAvailableRealms()- });- }-- protected _removeRealm(realm:string){- if (this.config){- delete this.config[realm]- this._loadListOfAvailableRealms()- this.requestUpdate()- }- }-- protected _loadListOfAvailableRealms(){- const app = this- this._availableRealms = this._allRealms.filter(function(realm){- if (!!realm.name && !!app.config){- if (realm.name in app.config){- return null- }- }- return realm- }).sort(function(a, b){- if (a.displayName && b.displayName){- return (a.displayName > b.displayName) ? 1 : -1- }- return -1- })- }-- protected _showAddingRealmDialog(){- this._addedRealm = null;- const _AddRealmToView = () => {- if (this._addedRealm){- if (!this.config){- this.config = {}- }- this.config[this._addedRealm] = {bounds: [4.42, 51.88, 4.55, 51.94], center: [4.485222, 51.911712], zoom: 14, minZoom: 14, maxZoom: 19, boxZoom: false}- this._loadListOfAvailableRealms()- this.requestUpdate()- return true- }- return false- }- const dialogActions: DialogAction[] = [- {- actionName: "cancel",- content: i18next.t("cancel")- },- {- default: true,- actionName: "ok",- content: i18next.t("ok"),- action: _AddRealmToView- },-- ];- const dialog = showDialog(new OrMwcDialog()- .setHeading(i18next.t('configuration.addMapCustomization'))- .setActions(dialogActions)- .setContent(html `- <or-mwc-input class="selector" label="Realm" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._addedRealm = e.detail.value}" .type="${InputType.SELECT}" .options="${Object.entries(this._availableRealms).map(([key, value]) => {return [value.name, value.displayName]})}"></or-mwc-input>- `)- .setStyles(html`- <style>- .mdc-dialog__surface {- padding: 4px 8px;- }- #dialog-content {- flex: 1;- overflow: visible;- min-height: 0;- padding: 0;- }- or-mwc-input.selector {- width: 300px;- display: block;- padding: 10px 20px;- }- </style>- `)- .setDismissAction(null));-- }---- updated(changedProperties: PropertyValues) {- super.updated(changedProperties);- }-- render() {- const app = this;- return html`- <div class="panels">- ${Object.entries(this.config === undefined ? {} : this.config).map(([key , value]) => {- return html`<or-conf-map-card .expanded="${app._addedRealm === key}" .name="${key}" .map="${value}" .onRemove="${() => {app._removeRealm(key)}}"></or-conf-map-card>`- })}- </div>-- <or-mwc-input id="btn-add-realm" .type="${InputType.BUTTON}" .label="${i18next.t('configuration.addMapCustomization')}" icon="plus" @click="${() => this._showAddingRealmDialog()}"></or-mwc-input>- `- }---}diff --git a/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-card.ts b/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-card.tsindex 6e5637724..e63ccadcb 100644--- a/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-card.ts+++ b/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-card.ts@@ -18,10 +18,11 @@* along with this program. If not, see <http://www.gnu.org/licenses/>.*/import { css, html, LitElement } from "lit";-import { customElement, property } from "lit/decorators.js";+import { customElement, property, state } from "lit/decorators.js";+import { when } from 'lit/directives/when.js';import "@openremote/or-components/or-file-uploader";import { i18next } from "@openremote/or-translate";-import { MapRealmConfig } from "@openremote/model";+import {MapRealmConfig} from "@openremote/model";import { DialogAction, OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";import { OrMapLongPressEvent } from "@openremote/or-map";@@ -31,270 +32,286 @@ import "./or-conf-map-geojson";@customElement("or-conf-map-card")export class OrConfMapCard extends LitElement {- static styles = css`- #remove-map {- margin: 12px 0 0 0;- }+ static styles = css`+ #remove-map {+ margin: 12px 0 0 0;+ }- .subheader {- padding: 10px 0 4px;- font-weight: bolder;- }+ .subheader {+ padding: 10px 0 4px;+ font-weight: bolder;+ }- .d-inline-flex {- display: inline-flex;- }+ .d-inline-flex {+ display: inline-flex;+ }- .panel-content {- padding: 0 24px 24px;- }+ .panel-content {+ padding: 0 24px 24px;+ }- .description {- font-size: 12px;- }+ .description {+ font-size: 12px;+ }- or-collapsible-panel {- margin-bottom: 10px;- }+ or-collapsible-panel {+ margin-bottom: 10px;+ }- .boundary-container {- width: 50%;- }+ .boundary-container {+ width: 50%;+ }- .boundary-item, .input {- width: 100%;- max-width: 800px;- padding: 10px 0;- }+ .boundary-item, .input {+ width: 100%;+ max-width: 800px;+ padding: 10px 0;+ }- .input or-mwc-input:not([icon]) {- width: 80%;- }+ .input or-mwc-input:not([icon]) {+ width: 80%;+ }++ .zoom-group {+ width: 50%;+ padding-left: 12px;+ }++ .map-container {+ width: 100%+ }+ .settings-container{+ display: inline-flex;+ }++ @media screen and (max-width: 768px) {+ .zoom-group, .boundary-container{+ width: 100%;+ padding: unset;+ }+ .settings-container{+ display: block;+ }+ }+ `;++ @property({ attribute: false })+ public map: MapRealmConfig = {};++ @property({ attribute: true })+ public name: string = "";++ @property({ type: Boolean })+ expanded: boolean = false;++ @property()+ public canRemove: boolean = false;++ @state()+ protected zoom: number = 1;- .zoom-group {- width: 50%;- padding-left: 12px;+ protected notifyConfigChange(config: MapRealmConfig) {+ this.dispatchEvent(new CustomEvent("change", { detail: config }));}- .map-container {- width: 100%+ protected _showRemoveMapDialog() {++ const dialogActions: DialogAction[] = [+ {+ actionName: "cancel",+ content: i18next.t("cancel"),+ },+ {+ default: true,+ actionName: "ok",+ content: i18next.t("yes"),+ action: () => {+ this.dispatchEvent(new CustomEvent("remove"));+ },+ },++ ];+ showDialog(new OrMwcDialog()+ .setHeading(i18next.t("delete"))+ .setActions(dialogActions)+ .setContent(html`+ ${i18next.t("configuration.deleteMapCustomizationConfirm")}+ `)+ .setStyles(html`+ <style>+ .mdc-dialog__surface {+ padding: 4px 8px;+ }++ #dialog-content {+ padding: 24px;+ }+ </style>+ `)+ .setDismissAction(null));+}- .settings-container{- display: inline-flex;++ protected setBoundary(key: number, value: any) {+ this.map.bounds[key] = parseFloat(parseFloat(value).toFixed(2));+ this.requestUpdate("map");+ this.notifyConfigChange(this.map);}- @media screen and (max-width: 768px) {- .zoom-group, .boundary-container{- width: 100%;- padding: unset;- }- .settings-container{- display: block;- }+ protected setCenter(cor: LngLat|string) {+ let centerCoordinate: LngLat+ if (typeof cor === "string"){+ centerCoordinate = {+ lat: parseFloat(cor.split(',')[1]),+ lng: parseFloat(cor.split(',')[0])+ } as never;+ } else {+ centerCoordinate = cor+ }+ const BetweenNorthSouth = this.map.bounds[3] > centerCoordinate.lat && this.map.bounds[1] < centerCoordinate.lat;+ const BetweenWestEast = this.map.bounds[0] < centerCoordinate.lng && this.map.bounds[2] > centerCoordinate.lng;+ if (!(BetweenNorthSouth && BetweenWestEast)) {+ this.map.bounds = [+ parseFloat((centerCoordinate.lng - .2).toFixed(3)),+ parseFloat((centerCoordinate.lat - .1).toFixed(3)),+ parseFloat((centerCoordinate.lng + .2).toFixed(3)),+ parseFloat((centerCoordinate.lat + .1).toFixed(3)),+ ];+ }+ this.map.center = [centerCoordinate.lng, centerCoordinate.lat];+ this.requestUpdate("map");+ this.notifyConfigChange(this.map);}- `;-- @property({ attribute: false })- public map: MapRealmConfig = {};-- @property({ attribute: true })- public name: string = "";-- @property({ type: Boolean })- expanded: boolean = false;-- @property({ attribute: true })- public onRemove: CallableFunction = () => {- };-- protected _showRemoveMapDialog() {-- const dialogActions: DialogAction[] = [- {- actionName: "cancel",- content: i18next.t("cancel"),- },- {- default: true,- actionName: "ok",- content: i18next.t("yes"),- action: () => {- this.onRemove();- },- },-- ];- const dialog = showDialog(new OrMwcDialog()- .setHeading(i18next.t("delete"))- .setActions(dialogActions)- .setContent(html`- ${i18next.t("configuration.deleteMapCustomizationConfirm")}- `)- .setStyles(html`- <style>- .mdc-dialog__surface {- padding: 4px 8px;- }-- #dialog-content {- padding: 24px;- }- </style>- `)- .setDismissAction(null));-- }-- protected firstUpdated(_changedProperties: Map<PropertyKey, unknown>): void {- }-- protected setBoundary(key: number, value: any) {- this.map.bounds[key] = parseFloat(parseFloat(value).toFixed(2));- this.map.bounds = JSON.parse(JSON.stringify(this.map.bounds));- this.requestUpdate();- }-- protected setCenter(cor: LngLat|string) {- let centerCoordinate: LngLat- if (typeof cor == "string"){- // @ts-ignore- centerCoordinate = {- lat: parseFloat(cor.split(',')[1]),- lng: parseFloat(cor.split(',')[0])- }- } else {- centerCoordinate = cor++ protected setZoom(nr:number){+ this.zoom = nr;}- const BetweenNorthSouth = this.map.bounds[3] > centerCoordinate.lat && this.map.bounds[1] < centerCoordinate.lat;- const BetweenWestEast = this.map.bounds[0] < centerCoordinate.lng && this.map.bounds[2] > centerCoordinate.lng;- if (!(BetweenNorthSouth && BetweenWestEast)) {- this.map.bounds = [- parseFloat((centerCoordinate.lng - .2).toFixed(3)),- parseFloat((centerCoordinate.lat - .1).toFixed(3)),- parseFloat((centerCoordinate.lng + .2).toFixed(3)),- parseFloat((centerCoordinate.lat + .1).toFixed(3)),- ];+++ render() {+ return html`+ <or-collapsible-panel .expanded="${this.expanded}">+ <div slot="header" class="header-container">+ ${this.name}+ </div>+ <div slot="content" class="panel-content">+ <div class="map-container">+ <div class="subheader">${i18next.t("map")}</div>+ <or-map id="vectorMap" .showBoundaryBoxControl="${true}" .zoom="${this.zoom}"+ .boundary="${this.map.bounds}"+ @or-map-long-press="${(ev: OrMapLongPressEvent) => {+ this.setCenter(ev.detail.lngLat);+ }}" .showGeoCodingControl="${true}"+ .showGeoJson="${this.map.geoJson != undefined}"+ .geoJson="${this.map.geoJson}"+ .useZoomControl="${false}"+ style="height: 500px; width: 100%;">+ ${when(this.map.center, () => html`+ <or-map-marker id="geo-json-point-marker" .lng="${this.map.center[0]}" .lat="${this.map.center[1]}"></or-map-marker>+ `)}+ </or-map>+ </div>++ <div class="settings-container">+ <div class="boundary-container">+ <div class="subheader">${i18next.t("configuration.mapBounds")}</div>+ <span>${i18next.t("configuration.mapBoundsDescription")}</span>+ <or-mwc-input .value="${this.map?.bounds[3]}" .type="${InputType.NUMBER}" .label="${i18next.t("north")}"+ class="boundary-item"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(3, e.detail.value)}"+ .step="${.01}"></or-mwc-input>+ <or-mwc-input .value="${this.map?.bounds[2]}" .type="${InputType.NUMBER}" .label="${i18next.t("east")}"+ class="boundary-item"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(2, e.detail.value)}"+ .step="${.01}"></or-mwc-input>+ <or-mwc-input .value="${this.map?.bounds[1]}" .type="${InputType.NUMBER}" .label="${i18next.t("south")}"+ class="boundary-item"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(1, e.detail.value)}"+ .step="${.01}"></or-mwc-input>+ <or-mwc-input .value="${this.map?.bounds[0]}" .type="${InputType.NUMBER}" .label="${i18next.t("west")}"+ class="boundary-item"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(0, e.detail.value)}"+ .step="${.01}"></or-mwc-input>+ <div class="subheader">${i18next.t("configuration.center")}</div>+ <span>${i18next.t("configuration.centerDescription")}</span>+ <or-mwc-input .value="${Array.isArray(this.map.center) ? this.map.center.join() : undefined}"+ .type="${InputType.TEXT}" label="${i18next.t("configuration.center")}"+ class="boundary-item"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setCenter(e.detail.value)}"+ .step="${.01}"></or-mwc-input>+ <div class="subheader">${i18next.t("configuration.geoJson")}</div>+ <span>${i18next.t("configuration.geoJsonDescription")}</span>+ <div class="input" style="height: 56px; display: flex; align-items: center;">+ <or-conf-map-geojson .geoJson="${this.map.geoJson}" @update="${(e: CustomEvent) => {+ this.map.geoJson = e.detail.value;+ this.requestUpdate();+ this.notifyConfigChange(this.map);+ }}"></or-conf-map-geojson>+ </div>+ </div>++ <div class="zoom-group">+ <div class="subheader">${i18next.t("configuration.mapZoom")}</div>+ <span>${i18next.t("configuration.mapZoomDescription")}</span>+ <div class="input">+ <or-mwc-input .value="${this.map.zoom}" .type="${InputType.NUMBER}" .label="${i18next.t('default')}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => {+ this.map.zoom = e.detail.value;+ this.notifyConfigChange(this.map);+ }}"+ .step="${1}"></or-mwc-input>+ <or-mwc-input .type="${InputType.BUTTON}" icon="eye"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setZoom(this.map.zoom)}"+ .step="${1}"></or-mwc-input>+ </div>+ <div class="input">+ <or-mwc-input .value="${this.map.minZoom}" .type="${InputType.NUMBER}"+ .label="${i18next.t("configuration.minZoom")}"+ max="${this.map.maxZoom}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => {+ this.map.minZoom = e.detail.value;+ this.requestUpdate();+ this.notifyConfigChange(this.map);+ }}"+ .step="${1}"></or-mwc-input>+ <or-mwc-input .type="${InputType.BUTTON}" icon="eye"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setZoom(this.map.minZoom)}"+ .step="${1}"></or-mwc-input>+ </div>+ <div class="input">+ <or-mwc-input .value="${this.map.maxZoom}" .type="${InputType.NUMBER}"+ .label="${i18next.t("configuration.maxZoom")}"+ min="${this.map.minZoom}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => {+ this.map.maxZoom = e.detail.value;+ this.requestUpdate("map");+ this.notifyConfigChange(this.map);+ }}"+ .step="${1}"></or-mwc-input>+ <or-mwc-input .type="${InputType.BUTTON}" icon="eye"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setZoom(this.map.maxZoom)}"+ .step="${1}"></or-mwc-input>+ </div>++ <div class="input" style="height: 56px;">+ <or-mwc-input .value="${this.map.boxZoom}" .type="${InputType.SWITCH}" label="BoxZoom"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => {+ this.map.boxZoom = e.detail.value;+ this.notifyConfigChange(this.map);+ }}"+ .step="${1}"></or-mwc-input>+ </div>+ </div>+ </div>++ ${when(this.canRemove, () => html`+ <or-mwc-input outlined .type="${InputType.BUTTON}" id="remove-map"+ .label="${i18next.t("configuration.deleteMapCustomization")}"+ @click="${() => { this._showRemoveMapDialog(); }}"+ ></or-mwc-input>+ `)}+ </div>+ </or-collapsible-panel>+ `;}- this.map.center = [centerCoordinate.lng, centerCoordinate.lat];- this.requestUpdate();- }-- protected setZoom(nr:number){- this.zoom = nr;- return this.requestUpdate()- }-- protected zoom = 1;--- render() {- return html`- <or-collapsible-panel- .expanded="${this.expanded}">- <div slot="header" class="header-container">- ${this.name}- </div>- <div slot="content" class="panel-content">- <div class="map-container">- <div class="subheader">${i18next.t("map")}</div>- <or-map id="vectorMap" .showBoundaryBoxControl="${true}" .zoom="${this.zoom}"- .boundary="${this.map.bounds}"- @or-map-long-press="${(ev: OrMapLongPressEvent) => {- this.setCenter(ev.detail.lngLat);- }}" .showGeoCodingControl="${true}"- .showGeoJson="${this.map.geoJson != undefined}"- .geoJson="${this.map.geoJson}"- .useZoomControl="${false}"- style="height: 500px; width: 100%;">- ${this.map.center ? html`- <or-map-marker id="geo-json-point-marker" .lng="${this.map.center[0]}"- .lat="${this.map.center[1]}"></or-map-marker>` : ""}-- </or-map>- </div>-- <div class="settings-container">- <div class="boundary-container">- <div class="subheader">${i18next.t("configuration.mapBounds")}</div>- <span>${i18next.t("configuration.mapBoundsDescription")}</span>- <or-mwc-input .value="${this.map?.bounds[3]}" .type="${InputType.NUMBER}" .label="${i18next.t("north")}"- class="boundary-item"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(3, e.detail.value)}"- .step="${.01}"></or-mwc-input>- <or-mwc-input .value="${this.map?.bounds[2]}" .type="${InputType.NUMBER}" .label="${i18next.t("east")}"- class="boundary-item"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(2, e.detail.value)}"- .step="${.01}"></or-mwc-input>- <or-mwc-input .value="${this.map?.bounds[0]}" .type="${InputType.NUMBER}" .label="${i18next.t("west")}"- class="boundary-item"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(0, e.detail.value)}"- .step="${.01}"></or-mwc-input>- <or-mwc-input .value="${this.map?.bounds[1]}" .type="${InputType.NUMBER}" .label="${i18next.t("south")}"- class="boundary-item"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setBoundary(1, e.detail.value)}"- .step="${.01}"></or-mwc-input>- <div class="subheader">${i18next.t("configuration.center")}</div>- <span>${i18next.t("configuration.centerDescription")}</span>- <or-mwc-input .value="${Array.isArray(this.map.center) ? this.map.center.join() : undefined}"- .type="${InputType.TEXT}" label="${i18next.t("configuration.center")}"- class="boundary-item"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setCenter(e.detail.value)}"- .step="${.01}"></or-mwc-input>- <div class="subheader">${i18next.t("configuration.geoJson")}</div>- <span>${i18next.t("configuration.geoJsonDescription")}</span>- <div class="input" style="height: 56px; display: flex; align-items: center;">- <or-conf-map-geojson .geoJson="${this.map.geoJson}" @update="${(e: CustomEvent) => { this.map.geoJson = e.detail.value; this.requestUpdate(); }}"></or-conf-map-geojson>- </div>- </div>-- <div class="zoom-group">- <div class="subheader">${i18next.t("configuration.mapZoom")}</div>- <span>${i18next.t("configuration.mapZoomDescription")}</span>- <div class="input">- <or-mwc-input .value="${this.map.zoom}" .type="${InputType.NUMBER}" .label="${i18next.t('default')}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.map.zoom = e.detail.value}"- .step="${1}"></or-mwc-input>- <or-mwc-input .type="${InputType.BUTTON}" icon="eye"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setZoom(this.map.zoom)}"- .step="${1}"></or-mwc-input>- </div>- <div class="input">- <or-mwc-input .value="${this.map.minZoom}" .type="${InputType.NUMBER}"- .label="${i18next.t("configuration.minZoom")}"- max="${this.map.maxZoom}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => {this.map.minZoom = e.detail.value; this.requestUpdate() }}"- .step="${1}"></or-mwc-input>- <or-mwc-input .type="${InputType.BUTTON}" icon="eye"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setZoom(this.map.minZoom)}"- .step="${1}"></or-mwc-input>- </div>- <div class="input">- <or-mwc-input .value="${this.map.maxZoom}" .type="${InputType.NUMBER}"- .label="${i18next.t("configuration.maxZoom")}"- min="${this.map.minZoom}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => { this.map.maxZoom = e.detail.value;this.requestUpdate()}}"- .step="${1}"></or-mwc-input>- <or-mwc-input .type="${InputType.BUTTON}" icon="eye"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setZoom(this.map.maxZoom)}"- .step="${1}"></or-mwc-input>- </div>-- <div class="input" style="height: 56px;">- <or-mwc-input .value="${this.map.boxZoom}" .type="${InputType.SWITCH}" label="BoxZoom"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.map.boxZoom = e.detail.value}"- .step="${1}"></or-mwc-input>- </div>- </div>- </div>--- <or-mwc-input outlined .type="${InputType.BUTTON}" id="remove-map"- .label="${i18next.t("configuration.deleteMapCustomization")}"- @click="${() => {- this._showRemoveMapDialog();- }}"></or-mwc-input>- </div>- </or-collapsible-panel>- `;- }}diff --git a/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-geojson.ts b/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-geojson.tsindex f96242aee..5fe6d09b3 100644--- a/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-geojson.ts+++ b/ui/app/manager/src/components/configuration/or-conf-map/or-conf-map-geojson.ts@@ -22,7 +22,7 @@ export class OrConfMapGeoJson extends LitElement {protected _aceEditorValue: string;- /* --------------*/+ /* -------------- */protected render() {const heading = "GeoJSON editor"diff --git a/ui/app/manager/src/components/configuration/or-conf-panel.ts b/ui/app/manager/src/components/configuration/or-conf-panel.tsnew file mode 100644index 000000000..454da96a6--- /dev/null+++ b/ui/app/manager/src/components/configuration/or-conf-panel.ts@@ -0,0 +1,204 @@+import {html, LitElement, TemplateResult} from "lit";+import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";+import {customElement, property} from "lit/decorators.js";+import {when} from 'lit/directives/when.js';+import {ManagerAppConfig} from "@openremote/model";+import {DialogAction, OrMwcDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {i18next} from "@openremote/or-translate";+import "@openremote/or-components/or-loading-indicator";+import "./or-conf-map/or-conf-map-card";+import "./or-conf-realm/or-conf-realm-card";+import {OrConfRealmCard} from "./or-conf-realm/or-conf-realm-card";+import {OrConfMapCard} from "./or-conf-map/or-conf-map-card";++@customElement("or-conf-panel")+export class OrConfPanel extends LitElement {++ @property()+ public config?: {[id: string]: any} | ManagerAppConfig = {};++ @property()+ public realmOptions: { name: string, displayName: string, canDelete: boolean }[] = [];++ protected _addedRealm: null | string = null++ public getCardElement(): OrConfRealmCard | OrConfMapCard | undefined {+ if(this.isManagerConfig(this.config)) {+ return this.shadowRoot?.querySelector('or-conf-realm-card');+ } else if (this.isMapConfig(this.config)) {+ return this.shadowRoot?.querySelector('or-conf-map-card');+ }+ }++ protected getRealmsProperty(config: unknown): { [index: string]: any } | undefined {+ if(this.isManagerConfig(config)) {+ return config.realms;+ } else if(this.isMapConfig(config)) {+ return config;+ }+ return undefined;+ }++ protected isMapConfig(object: unknown): boolean {+ const keys = Object.keys(object);+ return this.realmOptions.filter((o) => keys.includes(o.name)).length === keys.length;+ }++ protected isManagerConfig(object: any): object is ManagerAppConfig {+ return 'realms' in object;+ }++ protected notifyConfigChange(config: {[id: string]: any} | ManagerAppConfig) {+ this.dispatchEvent(new CustomEvent("change", { detail: config }));+ }++ /* ------------------------------ */++ render(): TemplateResult {++ // Define the type of config+ let type: 'managerconfig' | 'mapconfig' | undefined;+ if(this.isManagerConfig(this.config)) {+ type = 'managerconfig';+ } else if(this.isMapConfig(this.config)) {+ type = 'mapconfig';+ }++ // Render the panels+ const realmConfigs = this.getRealmsProperty(this.config);+ const availableRealms = this.getAvailableRealms(this.config, this.realmOptions);+ return html`+ <div class="panels">+ ${Object.entries(realmConfigs === undefined ? {} : realmConfigs).map(([key, value]) => {+ const realmOption = this.realmOptions.find((r) => r.name === key);+ switch (type) {+ case "managerconfig":+ return html`+ <or-conf-realm-card .expanded="${this._addedRealm === key}" .name="${key}" .realm="${value}" .canRemove="${realmOption?.canDelete}"+ @change="${() => this.notifyConfigChange(this.config)}" @remove="${() => this._removeRealm(key)}"+ ></or-conf-realm-card>+ `;+ case "mapconfig":+ return html`+ <or-conf-map-card .expanded="${this._addedRealm === key}" .name="${key}" .map="${value}" .canRemove="${realmOption?.canDelete}"+ @change="${() => this.notifyConfigChange(this.config)}" @remove="${() => this._removeRealm(key)}"+ ></or-conf-map-card>+ `;+ default:+ return html`Unknown error.`+ }+ })}+ </div>+ <!-- Show an "ADD REALM" button if there are realms available to be added -->+ <div style="display: flex; justify-content: space-between;">+ ${when(availableRealms.length > 0, () => html`+ <or-mwc-input id="btn-add-realm" .type="${InputType.BUTTON}" .label="${i18next.t('configuration.addMapCustomization')}" icon="plus"+ @click="${() => this._showAddingRealmDialog()}"+ ></or-mwc-input>+ `)}+ </div>+ `+ }+++ /* ----------------------------------- */++ protected _removeRealm(realm: string) {+ const realms = this.getRealmsProperty(this.config);+ if (realms) {+ delete realms[realm];+ this.requestUpdate("config")+ this.notifyConfigChange(this.config);+ } else {+ console.error("No config found when attempting to remove realm.")+ }+ }++ // Filter the list of realms that are not present in the config.+ // Most used for the "add realm" dialog, to hide the realms that are already present.+ protected getAvailableRealms(config?: ManagerAppConfig | {[id: string]: any}, realmOptions?: { name: string, displayName: string, canDelete: boolean }[]): { name: string, displayName: string, canDelete: boolean }[] {+ const realms = this.getRealmsProperty(config);+ if(realms) {+ return realmOptions.filter((r) => {+ if (r.name in realms) {+ return null;+ }+ return r;+ }).sort((a, b) => {+ if (a.displayName && b.displayName) {+ return (a.displayName > b.displayName) ? 1 : -1;+ }+ return -1;+ })+ } else {+ console.error("Could not filter available realms!");+ return [];+ }+ }+++ /* ------------------------------- */++ // Show the dialog to "add realm", that allows users to override realm options.+ protected _showAddingRealmDialog() {+ this._addedRealm = null;+ const dialogActions: DialogAction[] = [+ {+ actionName: "cancel",+ content: i18next.t("cancel")+ },+ {+ default: true,+ actionName: "ok",+ content: i18next.t("ok"),+ action: () => {+ if (this._addedRealm) {+ let realms = this.getRealmsProperty(this.config);+ if (!realms) {+ realms = {}+ }+ if(this.isManagerConfig(this.config)) {+ realms[this._addedRealm] = {}; // empty object since no fields are required+ } else if(this.isMapConfig(this.config)) {+ realms[this._addedRealm] = {bounds: [4.42, 51.88, 4.55, 51.94], center: [4.485222, 51.911712], zoom: 14, minZoom: 14, maxZoom: 19, boxZoom: false}+ }+ this.requestUpdate("config");+ this.notifyConfigChange(this.config);+ }+ }+ },+ ];+ showDialog(new OrMwcDialog()+ .setHeading(i18next.t('configuration.addMapCustomization'))+ .setActions(dialogActions)+ .setContent(html`+ <or-mwc-input class="selector" label="Realm" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._addedRealm = e.detail.value}" .type="${InputType.SELECT}"+ .options="${Object.entries(this.getAvailableRealms(this.config, this.realmOptions)).map(([, value]) => {+ return [value.name, value.displayName]+ })}"+ ></or-mwc-input>+ `)+ .setStyles(html`+ <style>+ .mdc-dialog__surface {+ padding: 4px 8px;+ }++ #dialog-content {+ flex: 1;+ overflow: visible;+ min-height: 0;+ padding: 0;+ }++ or-mwc-input.selector {+ width: 300px;+ display: block;+ padding: 10px 20px;+ }+ </style>+ `)+ .setDismissAction(null));++ }+}diff --git a/ui/app/manager/src/components/configuration/or-conf-realm/index.ts b/ui/app/manager/src/components/configuration/or-conf-realm/index.tsdeleted file mode 100644index 62c5da733..000000000--- a/ui/app/manager/src/components/configuration/or-conf-realm/index.ts+++ /dev/null@@ -1,155 +0,0 @@-/*- * Copyright 2022, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-import { css, html, LitElement, PropertyValues } from "lit";-import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";-import "./or-conf-realm-card";-import { customElement, property } from "lit/decorators.js";-import manager from "@openremote/core";-import { ManagerAppConfig } from "@openremote/model";-import { DialogAction, OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";-import { i18next } from "@openremote/or-translate";-import "@openremote/or-components/or-loading-indicator";--@customElement("or-conf-realm")-export class OrConfRealm extends LitElement {-- static styles = css`- #btn-add-realm {- margin-top: 4px;- }- `;-- @property({attribute: false})- public config: ManagerAppConfig = {};-- protected _availableRealms: {name:string, displayName:string}[] = [];- protected _allRealms: {name:string, displayName:string}[] = [];- protected _addedRealm: null|string = null-- protected firstUpdated(_changedProperties: Map<PropertyKey, unknown>): void {- const app = this- manager.rest.api.RealmResource.getAccessible().then((response)=>{- app._allRealms = response.data as {name:string, displayName:string}[];- app._allRealms.push({name: 'default', displayName: 'Default'})- app._loadListOfAvailableRealms()- });- }-- protected _removeRealm(realm:string){- if (this.config.realms){- delete this.config?.realms[realm]- this._loadListOfAvailableRealms()- this.requestUpdate()- }- }-- protected _loadListOfAvailableRealms() {- const app = this;- this._availableRealms = this._allRealms.filter(function(realm) {- if (!!realm.name && !!app.config){- if (realm.name in app.config?.realms){- return null- }- }- return realm;- }).sort(function(a, b) {- if (a.displayName && b.displayName) {- return (a.displayName > b.displayName) ? 1 : -1;- }- return -1;- });- }-- protected _showAddingRealmDialog(){- this._addedRealm = null;- const _AddRealmToView = () => {- if (this._addedRealm){- if (!this.config.realms){- this.config.realms = {}- }- this.config.realms[this._addedRealm] = {- styles: ":host > * {--or-app-color1:#FFFFFF;--or-app-color2:#F9F9F9;--or-app-color3:#4c4c4c;--or-app-color4:#4d9d2a;--or-app-color5:#CCCCCC;--or-app-color6:#be0000;"- }- this._loadListOfAvailableRealms()- this.requestUpdate()- return true- }- return false- }- const dialogActions: DialogAction[] = [- {- actionName: "cancel",- content: i18next.t("cancel")- },- {- default: true,- actionName: "ok",- content: i18next.t("ok"),- action: _AddRealmToView- },-- ];- const dialog = showDialog(new OrMwcDialog()- .setHeading(i18next.t('configuration.addRealmCustomization'))- .setActions(dialogActions)- .setContent(html `- <or-mwc-input class="selector" label="Realm" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._addedRealm = e.detail.value}" .type="${InputType.SELECT}" .options="${Object.entries(this._availableRealms).map(([key, value]) => {return [value.name, value.displayName]})}"></or-mwc-input>- `)- .setStyles(html`- <style>- .mdc-dialog__surface {- padding: 4px 8px;- }- #dialog-content {- flex: 1;- overflow: visible;- min-height: 0;- padding: 0;- }- or-mwc-input.selector {- width: 300px;- display: block;- padding: 10px 20px;- }- </style>- `)- .setDismissAction(null));-- }---- updated(changedProperties: PropertyValues) {- super.updated(changedProperties);- }-- render() {- const app = this;- return html`- <div class="panels">- ${Object.entries(this.config.realms === undefined ? {} : this.config.realms).map(function([key , value]){- return html`<or-conf-realm-card .expanded="${app._addedRealm === key}" .name="${key}" .realm="${value}" .onRemove="${() => {app._removeRealm(key)}}"></or-conf-realm-card>`- })}- </div>-- <or-mwc-input id="btn-add-realm" .type="${InputType.BUTTON}" .label="${i18next.t('configuration.addRealmCustomization')}" icon="plus" @click="${() => this._showAddingRealmDialog()}"></or-mwc-input>- `- }-}diff --git a/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.ts b/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.tsindex 80b320a78..abab272ab 100644--- a/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.ts+++ b/ui/app/manager/src/components/configuration/or-conf-realm/or-conf-realm-card.ts@@ -21,342 +21,353 @@ import { css, html, LitElement, unsafeCSS } from "lit";import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";import { customElement, property } from "lit/decorators.js";import "@openremote/or-components/or-file-uploader";-import manager, {- DEFAULT_LANGUAGES,- DefaultColor1,- DefaultColor2,- DefaultColor3,- DefaultColor4,- DefaultColor5,- DefaultColor6,- DefaultColor8,- Util,+import {+ DEFAULT_LANGUAGES,+ DefaultColor1,+ DefaultColor2,+ DefaultColor3,+ DefaultColor4,+ DefaultColor5,+ DefaultColor6,+ DefaultColor8,+ Util,} from "@openremote/core";import { i18next } from "@openremote/or-translate";import { FileInfo, ManagerAppRealmConfig } from "@openremote/model";import { DialogAction, OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";+import {when} from 'lit/directives/when.js';@customElement("or-conf-realm-card")export class OrConfRealmCard extends LitElement {- static styles = css`- .language {- width: 100%;- padding: 10px 0px;- max-width: 800px;- }+ static styles = css`+ .language {+ width: 100%;+ padding: 10px 0px;+ max-width: 800px;+ }- .appTitle {- width: 100%;- max-width: 800px;- padding: 10px 0px;- }+ .appTitle {+ width: 100%;+ max-width: 800px;+ padding: 10px 0px;+ }- .header-group .header-item {- width: 100%;- padding: 10px 0px;- max-width: 800px;- }+ .header-group .header-item {+ width: 100%;+ padding: 10px 0px;+ max-width: 800px;+ }- .color-group .color-item {- width: 100%;- }+ .color-group .color-item {+ width: 100%;+ }- .logo-group {- width: 100%;- }+ .logo-group {+ width: 100%;+ }++ @media screen and (max-width: 768px) {+ .logo-group or-file-uploader {+ min-width: calc(50% - 6px);+ padding: 0 12px 12px 0!important;+ }++ .logo-group or-file-uploader:nth-child(2n + 2){+ padding: 0 0 12px 0!important;+ }++ .logo-group .d-inline-flex{+ display: flex;+ flex-wrap: wrap;+ }+ }- @media screen and (max-width: 768px) {.logo-group or-file-uploader {- min-width: calc(50% - 6px);- padding: 0 12px 12px 0!important;+ padding: 0 24px 12px 0;}- .logo-group or-file-uploader:nth-child(2n + 2){- padding: 0 0 12px 0!important;+ #remove-realm {+ margin: 12px 0 0 0;}- .logo-group .d-inline-flex{- display: flex;- flex-wrap: wrap;+ .subheader {+ padding: 10px 0 4px;+ font-weight: bolder;}- }- .logo-group or-file-uploader {- padding: 0 24px 12px 0;- }+ .d-inline-flex {+ display: inline-flex;+ }- #remove-realm {- margin: 12px 0 0 0;- }+ .panel-content {+ padding: 0 24px 24px;+ }- .subheader {- padding: 10px 0 4px;- font-weight: bolder;- }+ .description {+ font-size: 12px;+ }- .d-inline-flex {- display: inline-flex;- }+ or-collapsible-panel {+ margin-bottom: 10px;+ }+ `;- .panel-content {- padding: 0 24px 24px;- }+ @property({ attribute: false })+ public realm: ManagerAppRealmConfig = {};++ @property({ attribute: true })+ public name: string = "";++ @property({type: Boolean})+ expanded: boolean = false;++ @property()+ public canRemove: boolean = false;++ protected logo:string = this.realm.logo;+ protected logoMobile:string = this.realm.logoMobile;+ protected favicon:string = this.realm.favicon;++ protected headerListPrimary: string[] = [+ "map",+ "assets",+ "rules",+ "insights",+ ];- .description {- font-size: 12px;++ protected headerListSecondary: string[] = [+ "gateway",+ "export",+ "logs",+ "realms",++ "users",+ "roles",++ "account",+ "language",+ "appearance",+ "logout"++ ];++ protected _getColors() {+ const colors: { [name: string]: string } = {+ "--or-app-color1": unsafeCSS(DefaultColor1).toString(),+ "--or-app-color2": unsafeCSS(DefaultColor2).toString(),+ '--or-app-color3': unsafeCSS(DefaultColor3).toString(),+ '--or-app-color4': unsafeCSS(DefaultColor4).toString(),+ '--or-app-color5': unsafeCSS(DefaultColor5).toString(),+ '--or-app-color6': unsafeCSS(DefaultColor6).toString(),+ '--or-app-color8': unsafeCSS(DefaultColor8).toString()+ }+ if (this.realm?.styles){+ //TODO use regex for filtering and getting color codes CSS+ const css = this.realm.styles.slice(this.realm.styles.indexOf("{") +1, this.realm.styles.indexOf("}"))+ css.split(";").forEach(function(value){+ const col = value.split(":")+ if (col.length >= 2){+ colors[col[0].trim()] = col[1].trim()+ }+ })+ }+ return colors}- or-collapsible-panel {- margin-bottom: 10px;+ protected _setColor(key:string, value:string){+ const colors = this._getColors()+ colors[key] = value+ let css = ":host > * {"+ Object.entries(colors).forEach(([key, value]) => {+ css += key +":" +value + ";"+ })+ this.realm.styles = css+ this.notifyConfigChange(this.realm);}- `;-- @property({ attribute: false })- public realm: ManagerAppRealmConfig = {};-- @property({ attribute: true })- public name: string = "";-- @property({type: Boolean})- expanded: boolean = false;-- @property({ attribute: true })- public onRemove: CallableFunction = () => {- };-- protected logo:string = this.realm.logo;- protected logoMobile:string = this.realm.logoMobile;- protected favicon:string = this.realm.favicon;-- protected headerListPrimary: string[] = [- "map",- "assets",- "rules",- "insights",- ];--- protected headerListSecondary: string[] = [- "gateway",- "export",- "logs",- "realms",-- "users",- "roles",-- "account",- "language",- "appearance",- "logout"-- ];-- protected _getColors() {- const colors: { [name: string]: string } = {- "--or-app-color1": unsafeCSS(DefaultColor1).toString(),- "--or-app-color2": unsafeCSS(DefaultColor2).toString(),- '--or-app-color3': unsafeCSS(DefaultColor3).toString(),- '--or-app-color4': unsafeCSS(DefaultColor4).toString(),- '--or-app-color5': unsafeCSS(DefaultColor5).toString(),- '--or-app-color6': unsafeCSS(DefaultColor6).toString(),- '--or-app-color8': unsafeCSS(DefaultColor8).toString()++ protected _setHeader(keys: string[], list: string[]) {+ if (!this.realm.headers) {+ this.realm.headers = this.headerListSecondary.concat(this.headerListPrimary);+ }+ this.realm.headers = this.realm.headers?.filter(function(ele) {+ return !list.includes(ele);+ });+ this.realm.headers = this.realm.headers?.concat(keys);+ this.notifyConfigChange(this.realm);}- if (this.realm?.styles){- //TODO use regex for filtering and getting color codes CSS- const css = this.realm.styles.slice(this.realm.styles.indexOf("{") +1, this.realm.styles.indexOf("}"))- css.split(";").forEach(function(value){- const col = value.split(":")- if (col.length >= 2){- colors[col[0].trim()] = col[1].trim()++ protected _getImagePath(file:File, fileName: string){+ if (file.type.startsWith("image/")){+ const extension = file.name.slice(file.name.lastIndexOf('.'), file.name.length);+ return "/images/" + this.name + "/" + fileName + extension}- })+ return null}- return colors- }-- protected _setColor(key:string, value:string){- const colors = this._getColors()- colors[key] = value- let css = ":host > * {"- Object.entries(colors).map(([key, value]) => {- css += key +":" +value + ";"- })- this.realm.styles = css- }-- protected _setHeader(keys: string[], list: string[]) {- if (!this.realm.headers) {- this.realm.headers = this.headerListSecondary.concat(this.headerListPrimary);++ protected files: {[name:string] : FileInfo} = {}++ protected async _setImageForUpload(file: File, fileName: string) {+ const path = this._getImagePath(file, fileName)+ if (path){+ this.files[path] = {+ path: path,+ contents: await Util.blobToBase64(file),+ } as FileInfo;+ this.realm[fileName] = path+ this[fileName] = this.files[path].contents+ this.requestUpdate()+ this.notifyConfigChange(this.realm);+ return this.files[path].contents;+ }}- this.realm.headers = this.realm.headers?.filter(function(ele) {- return !list.includes(ele);- });- this.realm.headers = this.realm.headers?.concat(keys);- }-- protected _getImagePath(file:File, fileName: string){- if (file.type.startsWith("image/")){- let extension = file.name.slice(file.name.lastIndexOf('.'), file.name.length);- return "/images/" + this.name + "/" + fileName + extension++ // Public GET method for getting the files uploaded by the user.+ public getFiles() {+ return this.files;}- return null- }-- protected files: {[name:string] : FileInfo} = {}-- protected async _setImageForUpload(file: File, fileName: string) {- const path = this._getImagePath(file, fileName)- if (path){- this.files[path] = {- path: path,- contents: await Util.blobToBase64(file),- } as FileInfo;- this.realm[fileName] = path- this[fileName] = this.files[path].contents- this.requestUpdate()- return this.files[path].contents;++ protected _showRemoveRealmDialog(){++ const dialogActions: DialogAction[] = [+ {+ actionName: "cancel",+ content: i18next.t("cancel")+ },+ {+ default: true,+ actionName: "ok",+ content: i18next.t("yes"),+ action: () => {+ this.dispatchEvent(new CustomEvent("remove"));+ }},++ ];+ showDialog(new OrMwcDialog()+ .setHeading(i18next.t('delete'))+ .setActions(dialogActions)+ .setContent(html `+ ${i18next.t('configuration.deleteRealmCustomizationConfirm')}+ `)+ .setStyles(html`+ <style>+ .mdc-dialog__surface {+ padding: 4px 8px;+ }++ #dialog-content {+ padding: 24px;+ }+ </style>+ `)+ .setDismissAction(null));+}- }- protected _showRemoveRealmDialog(){+ protected notifyConfigChange(config: ManagerAppRealmConfig) {+ this.dispatchEvent(new CustomEvent("change", { detail: config }));+ }- const dialogActions: DialogAction[] = [- {- actionName: "cancel",- content: i18next.t("cancel")- },- {- default: true,- actionName: "ok",- content: i18next.t("yes"),- action: () => {this.onRemove()}},- ];- const dialog = showDialog(new OrMwcDialog()- .setHeading(i18next.t('delete'))- .setActions(dialogActions)- .setContent(html `- ${i18next.t('configuration.deleteRealmCustomizationConfirm')}- `)- .setStyles(html`- <style>- .mdc-dialog__surface {- padding: 4px 8px;- }-- #dialog-content {- padding: 24px;- }- </style>- `)- .setDismissAction(null));-- }-- protected firstUpdated(_changedProperties: Map<PropertyKey, unknown>): void {- document.addEventListener('saveManagerConfig', () => {- Object.entries(this.files).map(async ([x, y]) => {- await manager.rest.api.ConfigurationResource.fileUpload(y, { path: x })- })- });- }--- render() {- const colors = this._getColors();- const app = this;- return html`- <or-collapsible-panel- .expanded="${this.expanded}">- <div slot="header" class="header-container">- ${this.name}- </div>- <div slot="content" class="panel-content">- <div class="subheader">${i18next.t("configuration.main")}</div>- <or-mwc-input class="appTitle" .type="${InputType.TEXT}" value="${this.realm?.appTitle}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.realm.appTitle = e.detail.value}"- .label="${i18next.t("configuration.realmTitle")}"></or-mwc-input>- <or-mwc-input class="language" .type="${InputType.SELECT}" value="${this.realm?.language}"- .options="${Object.entries(DEFAULT_LANGUAGES).map(([key, value]) => {- return [key, i18next.t(value)];- })}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.realm.language = e.detail.value}"- .label="${i18next.t("configuration.defaultLanguage")}"></or-mwc-input>- <div class="logo-group">- <div class="subheader">${i18next.t("configuration.images")}</div>- <div class="d-inline-flex">- <or-file-uploader .title="${i18next.t('configuration.logo')}"- @change="${async (e: CustomEvent) => await this._setImageForUpload(e.detail.value[0], "logo")}"- .src="${this.logo ? this.logo : this.realm.logo}"></or-file-uploader>- <or-file-uploader .title="${i18next.t('configuration.logoMobile')}"- @change="${async (e: CustomEvent) => await this._setImageForUpload(e.detail.value[0], "logoMobile")}"- .src="${this.logoMobile ? this.logoMobile : this.realm.logoMobile}"></or-file-uploader>- <or-file-uploader .title="${html`Favicon`}"- @change="${async (e: CustomEvent) => await this._setImageForUpload(e.detail.value[0], "favicon")}"- .src="${this.favicon ? this.favicon : this.realm.favicon}"></or-file-uploader>- </div>- </div>- <div class="color-group">- <div class="subheader">${i18next.t('configuration.realmColors')}</div>- <div>- <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color4"]}"- .label="${i18next.t('configuration.--or-app-color4')}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setColor("--or-app-color4", e.detail.value)}"></or-mwc-input>- <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color5"]}"- .label="${i18next.t('configuration.--or-app-color5')}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setColor("--or-app-color5", e.detail.value)}"></or-mwc-input>- <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color6"]}"- .label="${i18next.t("configuration.--or-app-color6")}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setColor("--or-app-color6", e.detail.value)}"></or-mwc-input>- <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color1"]}"- .label="${i18next.t("configuration.--or-app-color1")}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setColor("--or-app-color1", e.detail.value)}"></or-mwc-input>- <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color2"]}"- .label="${i18next.t("configuration.--or-app-color2")}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setColor("--or-app-color2", e.detail.value)}"></or-mwc-input>- <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color3"]}"- .label="${i18next.t("configuration.--or-app-color3")}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setColor("--or-app-color3", e.detail.value)}"></or-mwc-input>- <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color8"]}"- .label="${i18next.t("configuration.--or-app-color8")}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setColor("--or-app-color8", e.detail.value)}"></or-mwc-input>- </div>- </div>- <div class="header-group">- <div class="subheader">${i18next.t("configuration.navigation")}</div>- <span>${i18next.t("configuration.navigationDescription")}</span>- <div>- <or-mwc-input- .type="${InputType.SELECT}" multiple- class="header-item"- .label="${i18next.t("configuration.primaryNavigation")}"- .value="${!!this.realm.headers ? this.realm.headers?.filter(function(ele: string) {- return app.headerListPrimary.includes(ele);- }) : this.headerListPrimary}"- .options="${this.headerListPrimary}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setHeader(e.detail.value, this.headerListPrimary)}"- ></or-mwc-input>- <or-mwc-input- .type="${InputType.SELECT}" multiple- class="header-item"- .label="${i18next.t("configuration.secondaryNavigation")}"- .value="${!!this.realm.headers ? this.realm.headers?.filter(function(ele: string) {- return app.headerListSecondary.includes(ele);- }) : this.headerListSecondary}"- .options="${this.headerListSecondary}"- @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._setHeader(e.detail.value, this.headerListSecondary)}"- ></or-mwc-input>- </div>- </div>-- <or-mwc-input outlined id="remove-realm" .type="${InputType.BUTTON}"- .label="${i18next.t("configuration.deleteRealmCustomization")}"- @click="${() => {- this._showRemoveRealmDialog();- }}"></or-mwc-input>- </div>- </or-collapsible-panel>- `;- }+ render() {+ const colors = this._getColors();+ const app = this;+ return html`+ <or-collapsible-panel .expanded="${app.expanded}">+ <div slot="header" class="header-container">+ ${app.name}+ </div>+ <div slot="content" class="panel-content">+ <div class="subheader">${i18next.t("configuration.main")}</div>+ <or-mwc-input class="appTitle" .type="${InputType.TEXT}" .label="${i18next.t("configuration.realmTitle")}" value="${app.realm?.appTitle}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => {+ app.realm.appTitle = e.detail.value;+ app.notifyConfigChange(app.realm);+ }}"+ ></or-mwc-input>+ <or-mwc-input class="language" .type="${InputType.SELECT}" .label="${i18next.t("configuration.defaultLanguage")}" value="${app.realm?.language}"+ .options="${Object.entries(DEFAULT_LANGUAGES).map(([key, value]) => [key, i18next.t(value)])}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => {+ app.realm.language = e.detail.value;+ app.notifyConfigChange(app.realm);+ }}"+ ></or-mwc-input>+ <div class="logo-group">+ <div class="subheader">${i18next.t("configuration.images")}</div>+ <div class="d-inline-flex">+ <or-file-uploader .title="${i18next.t('configuration.logo')}"+ @change="${async (e: CustomEvent) => await app._setImageForUpload(e.detail.value[0], "logo")}"+ .src="${app.logo ? app.logo : app.realm.logo}"></or-file-uploader>+ <or-file-uploader .title="${i18next.t('configuration.logoMobile')}"+ @change="${async (e: CustomEvent) => await app._setImageForUpload(e.detail.value[0], "logoMobile")}"+ .src="${app.logoMobile ? app.logoMobile : app.realm.logoMobile}"></or-file-uploader>+ <or-file-uploader .title="${html`Favicon`}"+ @change="${async (e: CustomEvent) => await app._setImageForUpload(e.detail.value[0], "favicon")}"+ .src="${app.favicon ? app.favicon : app.realm.favicon}"></or-file-uploader>+ </div>+ </div>+ <div class="color-group">+ <div class="subheader">${i18next.t('configuration.realmColors')}</div>+ <div>+ <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color4"]}"+ .label="${i18next.t('configuration.--or-app-color4')}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setColor("--or-app-color4", e.detail.value)}"></or-mwc-input>+ <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color5"]}"+ .label="${i18next.t('configuration.--or-app-color5')}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setColor("--or-app-color5", e.detail.value)}"></or-mwc-input>+ <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color6"]}"+ .label="${i18next.t("configuration.--or-app-color6")}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setColor("--or-app-color6", e.detail.value)}"></or-mwc-input>+ <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color1"]}"+ .label="${i18next.t("configuration.--or-app-color1")}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setColor("--or-app-color1", e.detail.value)}"></or-mwc-input>+ <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color2"]}"+ .label="${i18next.t("configuration.--or-app-color2")}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setColor("--or-app-color2", e.detail.value)}"></or-mwc-input>+ <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color3"]}"+ .label="${i18next.t("configuration.--or-app-color3")}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setColor("--or-app-color3", e.detail.value)}"></or-mwc-input>+ <or-mwc-input class="color-item" .type="${InputType.COLOUR}" value="${colors["--or-app-color8"]}"+ .label="${i18next.t("configuration.--or-app-color8")}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setColor("--or-app-color8", e.detail.value)}"></or-mwc-input>+ </div>+ </div>+ <div class="header-group">+ <div class="subheader">${i18next.t("configuration.navigation")}</div>+ <span>${i18next.t("configuration.navigationDescription")}</span>+ <div>+ <or-mwc-input+ .type="${InputType.SELECT}" multiple+ class="header-item"+ .label="${i18next.t("configuration.primaryNavigation")}"+ .value="${!!app.realm.headers ? app.realm.headers?.filter(function(ele: string) {+ return app.headerListPrimary.includes(ele);+ }) : app.headerListPrimary}"+ .options="${app.headerListPrimary}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setHeader(e.detail.value, app.headerListPrimary)}"+ ></or-mwc-input>+ <or-mwc-input+ .type="${InputType.SELECT}" multiple+ class="header-item"+ .label="${i18next.t("configuration.secondaryNavigation")}"+ .value="${!!app.realm.headers ? app.realm.headers?.filter(function(ele: string) {+ return app.headerListSecondary.includes(ele);+ }) : app.headerListSecondary}"+ .options="${app.headerListSecondary}"+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => app._setHeader(e.detail.value, app.headerListSecondary)}"+ ></or-mwc-input>+ </div>+ </div>++ ${when(app.canRemove, () => html`+ <or-mwc-input outlined id="remove-realm" .type="${InputType.BUTTON}"+ .label="${i18next.t("configuration.deleteRealmCustomization")}"+ @click="${() => { app._showRemoveRealmDialog(); }}"+ ></or-mwc-input>+ `)}+ </div>+ </or-collapsible-panel>+ `;+ }}diff --git a/ui/app/manager/src/pages/page-configuration.ts b/ui/app/manager/src/pages/page-configuration.tsindex 5ec76c0d0..d41b1b4b2 100644--- a/ui/app/manager/src/pages/page-configuration.ts+++ b/ui/app/manager/src/pages/page-configuration.ts@@ -17,23 +17,26 @@* You should have received a copy of the GNU Affero General Public License* along with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { css, html, TemplateResult, unsafeCSS } from "lit";-import { customElement } from "lit/decorators.js";-import manager, { DefaultColor1, DefaultColor3 } from "@openremote/core";+import {css, html, TemplateResult, PropertyValues, unsafeCSS} from "lit";+import {customElement, state, query} from "lit/decorators.js";+import manager, {DefaultColor1, DefaultColor3} from "@openremote/core";import "@openremote/or-components/or-panel";import "@openremote/or-translate";-import { Store } from "@reduxjs/toolkit";-import { AppStateKeyed, Page, PageProvider } from "@openremote/or-app";+import {Store} from "@reduxjs/toolkit";+import {AppStateKeyed, Page, PageProvider} from "@openremote/or-app";+import {when} from "lit/directives/when.js"import "@openremote/or-components/or-collapsible-panel";import "@openremote/or-mwc-components/or-mwc-input";import "../components/configuration/or-conf-json";-import "../components/configuration/or-conf-realm/index";-import "../components/configuration/or-conf-map/index";-import { ManagerAppConfig } from "@openremote/model";-import { i18next } from "@openremote/or-translate";+import "../components/configuration/or-conf-panel";+import {ManagerAppConfig, MapRealmConfig, Realm} from "@openremote/model";+import {i18next} from "@openremote/or-translate";import "@openremote/or-components/or-loading-indicator";+import {OrConfRealmCard} from "../components/configuration/or-conf-realm/or-conf-realm-card";+import {OrConfPanel} from "../components/configuration/or-conf-panel";++declare const CONFIG_URL_PREFIX: string;-declare var CONFIG_URL_PREFIX: string;export function pageConfigurationProvider(store: Store<AppStateKeyed>): PageProvider<AppStateKeyed> {return {name: "configuration",@@ -47,15 +50,11 @@ export function pageConfigurationProvider(store: Store<AppStateKeyed>): PageProv}@customElement("page-configuration")-export class PageConfiguration extends Page<AppStateKeyed> {+export class PageConfiguration extends Page<AppStateKeyed> {static get styles() {// language=CSSreturn css`- .main-content{- display: unset!important;- }-:host {flex: 1;width: 100%;@@ -66,7 +65,7 @@ export class PageConfiguration extends Page<AppStateKeyed> {--or-collapisble-panel-background-color: #fff;--or-panel-background-color: #fff;--or-panel-padding: 18px 24px 24px;- --or-panel-heading-margin: 0 0 14px 0;+ --or-panel-heading-margin: 0 0 10px 0;--or-panel-background-color: var(--or-app-color1, ${unsafeCSS(DefaultColor1)});--or-panel-heading-font-size: 14px;}@@ -111,7 +110,7 @@ export class PageConfiguration extends Page<AppStateKeyed> {margin-left: 14px;}- #header-actions or-mwc-input{+ #header-actions or-mwc-input {margin-left: 12px;}@@ -131,10 +130,6 @@ export class PageConfiguration extends Page<AppStateKeyed> {--or-panel-border-radius: 0;}- #header-wrapper{- /*width: 100%*/- }-.hide-mobile {display: none;}@@ -146,101 +141,186 @@ export class PageConfiguration extends Page<AppStateKeyed> {return "appearance";}- constructor(store: Store<AppStateKeyed>) {- super(store);- }+ @state()+ public managerConfiguration?: ManagerAppConfig;- private urlPrefix:string = (CONFIG_URL_PREFIX || "")- private mapConfig = {};- private getManagerConfig(): void {- fetch(this.urlPrefix + "/manager_config.json", { cache: "reload" })- .then(async (response) => {- return response.json().then((json) => {- this.managerConfiguration = json;- this.loading = false;- return true;- });-- }).catch(() => {- this.managerConfiguration = {};- this.loading = false;- return false;- }).finally(() => {- this.requestUpdate();- });+ @state()+ public mapConfig?: {[id: string]: any};- manager.rest.api.MapResource.getSettings().then((response) => {- this.mapConfig = response.data.options- this.loading = false;- this.requestUpdate();- })+ @state()+ protected realms?: Realm[];++ @state()+ protected loading: boolean = false;++ @state()+ protected managerConfigurationChanged = false;++ @state()+ protected mapConfigChanged = false;++ @query("#managerConfig-panel")+ protected realmCardElem?: OrConfPanel;++ private readonly urlPrefix: string = (CONFIG_URL_PREFIX || "")+++ /* ------------------------------------------ */++ public stateChanged(state: AppStateKeyed) {}- private loading: boolean = true;- private managerConfiguration: ManagerAppConfig = {};-- protected firstUpdated(_changedProperties: Map<PropertyKey, unknown>): void {- const app = this;- document.addEventListener("saveLocalManagerConfig", (e: CustomEvent) => {- this.managerConfiguration = e.detail?.value as ManagerAppConfig;- app.requestUpdate();- });-- document.addEventListener("saveManagerConfig", (e: CustomEvent) => {- manager.rest.api.ConfigurationResource.update(e.detail?.value as ManagerAppConfig).then(() => {- fetch(this.urlPrefix + "/manager_config.json", { cache: "reload" });- this.managerConfiguration = e.detail?.value as ManagerAppConfig;- Object.entries(this.managerConfiguration.realms).map(([name, settings]) => {- fetch(this.urlPrefix + settings?.favicon, { cache: "reload" });- fetch(this.urlPrefix + settings?.logo, { cache: "reload" });- fetch(this.urlPrefix + settings?.logoMobile, { cache: "reload" });+ // On every update..+ willUpdate(changedProps: PropertyValues<this>) {++ if(!this.loading) {+ let managerConfigPromise;+ if(this.managerConfiguration === undefined) {+ managerConfigPromise = this.getManagerConfig().then((value) => {+ this.managerConfiguration = value;});- app.requestUpdate();- })- manager.rest.api.MapResource.saveSettings(this.mapConfig).then(() => {- app.requestUpdate();- })- })+ }+ let mapConfigPromise;+ if(this.mapConfig === undefined) {+ mapConfigPromise = this.getMapConfig().then((value) => {+ this.mapConfig = value;+ });+ }+ let realmsPromise;+ if(this.realms === undefined) {+ realmsPromise = this.getAccessibleRealms().then((value) => {+ this.realms = value;+ });+ }- this.getManagerConfig();+ // Wait for both promises to complete, to only update UI once.+ if(managerConfigPromise || mapConfigPromise || realmsPromise) {+ this.loading = true;+ Promise.all([managerConfigPromise, mapConfigPromise, realmsPromise]).finally(() => {+ this.loading = false;+ })+ }+ }}++ /* ------------------------ */+protected render(): TemplateResult | void {if (!manager.authenticated) {- return html`- <or-translate value="notAuthenticated"></or-translate>- `;+ return html`<or-translate value="notAuthenticated"></or-translate>`;}return html`- ${this.loading ? html`- <or-loading-indicator .overlay="${true}"></or-loading-indicator>` : html`- <div id="wrapper">- <div id="header-wrapper">- <div id="header-title">- <or-icon icon="palette-outline"></or-icon>- ${i18next.t("appearance")}- </div>- <div id="header-actions">- <or-conf-json .managerConfig="${this.managerConfiguration}"- class="hide-mobile"></or-conf-json>- <or-mwc-input id="save-btn" raised="" type="button" .label="${i18next.t("save")}"- @click="${() => {- document.dispatchEvent(new CustomEvent("saveManagerConfig", { detail: { value: this.managerConfiguration } }));- }}"></or-mwc-input>+ ${when(this.loading, () => html`+ <or-loading-indicator></or-loading-indicator>+ `, () => {+ const realmHeading = html`+ <div id="heading" style="justify-content: space-between;">+ <span style="margin: 0;">${i18next.t("configuration.realmStyling")}</span>+ <or-conf-json .managerConfig="${this.managerConfiguration}" class="hide-mobile"+ @saveLocalManagerConfig="${(ev: CustomEvent) => {+ this.managerConfiguration = ev.detail.value as ManagerAppConfig;+ this.managerConfigurationChanged = true;+ }}"+ ></or-conf-json>+ </div>+ `;+ const realmOptions = this.realms?.map((r) => ({ name: r.name, displayName: r.displayName, canDelete: true }));+ realmOptions.push({name: 'default', displayName: 'Default', canDelete: false});+ return html`+ <div id="wrapper">+ <div id="header-wrapper">+ <div id="header-title">+ <or-icon icon="palette-outline"></or-icon>+ ${i18next.t("appearance")}+ </div>+ <div id="header-actions">+ <or-mwc-input id="save-btn" .disabled="${!this.managerConfigurationChanged && !this.mapConfigChanged}" raised type="button" .label="${i18next.t("save")}"+ @click="${() => this.saveAllConfigs(this.managerConfiguration, this.mapConfig)}"+ ></or-mwc-input>+ </div></div>+ <or-panel .heading="${realmHeading}">+ <or-conf-panel id="managerConfig-panel" .config="${this.managerConfiguration}" .realmOptions="${realmOptions}"+ @change="${() => { this.managerConfigurationChanged = true; }}"+ ></or-conf-panel>+ </or-panel>+ <or-panel .heading="${i18next.t("configuration.mapSettings").toUpperCase()}">+ <or-conf-panel id="mapConfig-panel" .config="${this.mapConfig}" .realmOptions="${realmOptions}"+ @change="${() => { this.mapConfigChanged = true; }}"+ ></or-conf-panel>+ </or-panel></div>- <or-panel .heading="${i18next.t("configuration.realmStyling")}">- <or-conf-realm .config="${this.managerConfiguration}"></or-conf-realm>- </or-panel>- <or-panel .heading="${i18next.t("configuration.mapSettings").toUpperCase()}">- <or-conf-map .config="${this.mapConfig}"></or-conf-map>- </or-panel>- </div>`}+ `+ })}`;+ }+ /* ---------------- */++ // FETCH METHODS++ protected async getManagerConfig(): Promise<ManagerAppConfig | undefined> {+ const response = await fetch(this.urlPrefix + "/manager_config.json", { cache: "reload" });+ return await response.json() as ManagerAppConfig;}- public stateChanged(state: AppStateKeyed) {+ protected async getMapConfig(): Promise<{[id: string]: any}> {+ const response = await manager.rest.api.MapResource.getSettings();+ return (response.data.options as {[id: string]: any});+ }++ protected async getAccessibleRealms(): Promise<Realm[]> {+ return (await manager.rest.api.RealmResource.getAccessible()).data;+ }++ protected saveAllConfigs(config: ManagerAppConfig, mapConfig: {[p: string]: MapRealmConfig}) {+ this.loading = true;+ let managerPromise;++ // POST manager config if changed...+ if (this.managerConfigurationChanged) {+ managerPromise = manager.rest.api.ConfigurationResource.update(config).then(() => {+ fetch(this.urlPrefix + "/manager_config.json", {cache: "reload"});+ this.managerConfiguration = config;+ Object.entries(this.managerConfiguration.realms).forEach(([name, settings]) => {+ fetch(this.urlPrefix + settings?.favicon, {cache: "reload"});+ fetch(this.urlPrefix + settings?.logo, {cache: "reload"});+ fetch(this.urlPrefix + settings?.logoMobile, {cache: "reload"});+ });+ }).catch((reason) => {+ console.error(reason);+ });+ }++ // POST map config if changed...+ let mapPromise;+ if(this.mapConfigChanged) {+ mapPromise = manager.rest.api.MapResource.saveSettings(mapConfig)+ .then(() => {+ this.mapConfig = mapConfig;+ }).catch((reason) => {+ console.error(reason);+ });+ }++ // Save the images to the server that have been uploaded by the user.+ // TODO: Optimize code so it only saves images that have been changed.+ const imagePromises = [];+ if(this.realmCardElem !== undefined) {+ const elem = this.realmCardElem?.getCardElement() as OrConfRealmCard;+ Object.entries(elem?.getFiles()).forEach(async ([x, y]) => {+ imagePromises.push(manager.rest.api.ConfigurationResource.fileUpload(y, {path: x}));+ });+ }++ // Wait for all requests to complete, then finish loading.+ const promises = [...imagePromises, managerPromise, mapPromise];+ Promise.all(promises).finally(() => {+ this.loading = false;+ this.managerConfigurationChanged = false;+ this.mapConfigChanged = false;+ })}}diff --git a/ui/app/manager/src/pages/page-gateway.ts b/ui/app/manager/src/pages/page-gateway.tsindex 79c71917a..882015a35 100644--- a/ui/app/manager/src/pages/page-gateway.ts+++ b/ui/app/manager/src/pages/page-gateway.ts@@ -34,13 +34,14 @@ export class PageGateway extends Page<AppStateKeyed> {display: flex;justify-content: center;+ --or-panel-heading-min-height: 0px;--or-panel-heading-margin: 4px 0 0 10px;--or-panel-background-color: var(--or-app-color1, ${unsafeCSS(DefaultColor1)});--or-panel-heading-font-size: 14px;--or-panel-padding: 14px;}- #wrapper {+ #wrapper {height: 100%;width: 100%;display: flex;diff --git a/ui/component/or-components/src/or-file-uploader.ts b/ui/component/or-components/src/or-file-uploader.tsindex 4f3826e15..ab7785612 100644--- a/ui/component/or-components/src/or-file-uploader.ts+++ b/ui/component/or-components/src/or-file-uploader.ts@@ -26,7 +26,7 @@ import "./or-loading-indicator";@customElement("or-file-uploader")export class OrFileUploader extends LitElement {- //Contains the content that will be shown towards the user.+ // Contains the content that will be shown towards the user.@property({ attribute: false })public src: string = "";@@ -132,14 +132,12 @@ export class OrFileUploader extends LitElement {<div class="title">${this.title}</div><div id="imageContainer">- ${!!this.src ?- html`<img src="${this.src}" alt="OR-File-Uploader">- <div class="pencil-container">- <or-icon icon="pencil-circle"></or-icon>- </div>- `- :- html`+ ${this.src ? html`+ <img src="${this.src}" alt="OR-File-Uploader">+ <div class="pencil-container">+ <or-icon icon="pencil-circle"></or-icon>+ </div>+ ` : html`<div class="placeholder-container"><or-icon icon="upload"></or-icon>${i18next.t('uploadFile')}diff --git a/ui/component/or-components/src/or-panel.ts b/ui/component/or-components/src/or-panel.tsindex bbfb66c5f..608333070 100644--- a/ui/component/or-components/src/or-panel.ts+++ b/ui/component/or-components/src/or-panel.ts@@ -1,6 +1,7 @@-import {css, html, LitElement, PropertyValues, unsafeCSS} from "lit";+import {css, html, LitElement, TemplateResult, unsafeCSS} from "lit";import {customElement, property, query} from "lit/decorators.js";import {DefaultColor2, DefaultColor3} from "@openremote/core";+import {when} from "lit/directives/when.js";// TODO: Add webpack/rollup to build so consumers aren't forced to use the same toolingconst simpleBarStyle = require("simplebar/dist/simplebar.css");@@ -12,10 +13,11 @@ const style = css`:host {--internal-or-panel-background-color: var(--or-panel-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));--internal-or-panel-padding: var(--or-panel-padding, 10px);- --internal-or-panel-heading-margin: var(--or-panel-heading-margin, 0 0 5px 7px);- --internal-or-panel-heading-color: var(--or-panel-heading-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));--internal-or-panel-border: var(--or-panel-border, 1px solid #e5e5e5);--internal-or-panel-border-radius: var(--or-panel-border-radius, 5px);+ --internal-or-panel-heading-margin: var(--or-panel-heading-margin, 0 0 10px 7px);+ --internal-or-panel-heading-min-height: var(--or-panel-heading-min-height, 36px);+ --internal-or-panel-heading-color: var(--or-panel-heading-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));--internal-or-panel-heading-font-size: var(--or-panel-heading-font-size, larger);--internal-or-panel-heading-font-weight: var(--or-panel-heading-font-weight, bolder);@@ -39,7 +41,10 @@ const style = css`}#heading {+ display: flex;+ align-items: center;margin: var(--internal-or-panel-heading-margin);+ min-height: var(--internal-or-panel-heading-min-height);font-size: var(--internal-or-panel-heading-font-size);font-weight: var(--internal-or-panel-heading-font-weight);color: var(--internal-or-panel-heading-color);@@ -61,29 +66,24 @@ export class OrPanel extends LitElement {zLevel?: number;@property({type: String})- public heading?: string;+ public heading?: string | TemplateResult;@query("#panel")protected _panel!: HTMLDivElement;- protected firstUpdated(_changedProperties: PropertyValues): void {- super.firstUpdated(_changedProperties);-- // if (this._panel) {- // new SimpleBar(this._panel, {- // autoHide: this.autoHide,- // // @ts-ignore- // forceVisible: this.forceVisible- // });- // }- }-render() {-return html`<div id="wrapper"><div id="panel">- ${this.heading ? html`<div id="heading">${this.heading}</div>` : ``}+ ${this.heading ? html`+ ${when(!(typeof this.heading === 'string'), () => html`+ ${this.heading}+ `, () => html`+ <div id="heading">+ <span>${this.heading}</span>+ </div>+ `)}+ ` : ``}<slot></slot></div></div>