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 updates: added or-gateway-connection-panel and page-gateway to main app
Rich Turnerb0538ce53fa7
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.jsonindex ad582a5b9..6d8dfe274 100644--- a/deployment/manager/shared/locales/en/or.json+++ b/deployment/manager/shared/locales/en/or.json@@ -190,5 +190,12 @@"ENERGY": "%.1f","CO2": "%.1f","HUMIDITY": "%.1f"- }+ },+ "gatewayConnection": "Manager interconnect",+ "secured": "Secured",+ "clientSecret": "Client secret",+ "clientId": "Client ID",+ "realm": "Realm",+ "port": "Port",+ "host": "Hostname"}diff --git a/ui/app/main/locales/en/app.json b/ui/app/main/locales/en/app.jsonindex ae32ee8ef..c99b1e82d 100644--- a/ui/app/main/locales/en/app.json+++ b/ui/app/main/locales/en/app.json@@ -128,5 +128,6 @@"lightSwitch": "Light switch","windowOpen": "Window open","lightSwitchTriggerTimes": "Light switch times",- "lightsStand": "Standing light"+ "lightsStand": "Standing light",+ "gateway": "Gateway"}\ No newline at end of filediff --git a/ui/app/main/src/components/my-app.ts b/ui/app/main/src/components/my-app.tsindex 0e72b24ce..857054366 100644--- a/ui/app/main/src/components/my-app.ts+++ b/ui/app/main/src/components/my-app.ts@@ -10,6 +10,7 @@ import "../components/pages/page-assets";import "../components/pages/page-rules";import "../components/pages/page-insights";import "../components/pages/page-logs";+import "../components/pages/page-gateway";import i18next from "i18next";import {connect} from "pwa-helpers/connect-mixin";@@ -89,6 +90,7 @@ class MyApp extends connect(store)(LitElement) {${this.page === "rules" ? html`<page-rules class="page"></page-rules>` : ``}${this.page === "insights" ? html`<page-insights class="page"></page-insights>` : ``}${this.page === "logs" ? html`<page-logs class="page"></page-logs>` : ``}+ ${this.page === "gateway" ? html`<page-gateway class="page"></page-gateway>` : ``}</main>`;}diff --git a/ui/app/main/src/components/or-gateway-connection-panel/src/index.ts b/ui/app/main/src/components/or-gateway-connection-panel/src/index.tsnew file mode 100644index 000000000..821776dcb--- /dev/null+++ b/ui/app/main/src/components/or-gateway-connection-panel/src/index.ts@@ -0,0 +1,198 @@+import {css, customElement, html, LitElement, property, PropertyValues, TemplateResult, unsafeCSS} from "lit-element";+import i18next from "i18next";+import "@openremote/or-log-viewer";+import "@openremote/or-panel";+import {GatewayConnection, GatewayConnectionStatusEvent, ConnectionStatus} from "@openremote/model";+import { translate } from "@openremote/or-translate";+import manager, { DefaultColor1 } from "@openremote/core";+import { InputType, OrInputChangedEvent } from "@openremote/or-input";++@customElement("or-gateway-connection-panel")+export class OrGatewayConnectionPanel extends translate(i18next)(LitElement) {++ // language=CSS+ static get styles() {+ return css`+ :host {+ flex: 1;+ width: 100%;+ --or-panel-heading-margin: 0 0 5px 10px;+ --or-panel-background-color: var(--or-app-color1, ${unsafeCSS(DefaultColor1)});+ --or-panel-heading-font-size: large;+ }++ or-panel {+ position: relative;+ }++ #status {+ position: absolute;+ top: 15px;+ right: 25px;+ font-weight: bold;++ }++ #fields {+ display: flex;+ flex-direction: column;+ padding: 10px;+ }++ #fields > or-input {+ margin: 10px 0;+ width: 100%;+ }++ #buttons {+ text-align: right;+ }++ #buttons > or-input {+ margin: 10px;++ }+ `;+ }++ @property()+ public realm?: string;++ @property()+ protected _loading = true;++ @property()+ protected _connection?: GatewayConnection;++ @property()+ protected _connectionStatus?: ConnectionStatus;++ @property()+ protected _dirty = false;++ protected _readonly = false;+ protected _eventSubscriptionId?: string;++ connectedCallback() {+ super.connectedCallback();+ this._readonly = !manager.hasRole("write:admin");+ this._subscribeEvents();+ }++ disconnectedCallback(): void {+ super.disconnectedCallback();+ this._unsubscribeEvents();+ }++ public shouldUpdate(_changedProperties: PropertyValues): boolean {++ if (_changedProperties.has("realm")) {+ this._loadData();+ }++ return super.shouldUpdate(_changedProperties);+ }++ public updated(_changedProperties: PropertyValues): void {+ super.updated(_changedProperties);++ if (!this.realm) {+ this.realm = this._getRealm();+ }+ }++ protected render(): TemplateResult | void {+ const connection = this._connection;++ return html`+ <or-panel ?disabled="${this._loading}" .heading="${i18next.t("gatewayConnection") + " (" + this.realm + ")"}">+ <div id="status">+ ${this._connectionStatus}+ </div>+ <div id="fields">+ <or-input .label="${i18next.t("host")}" .type="${InputType.TEXT}" ?disabled="${this._loading || this._readonly}" .value="${connection ? connection.host : ""}" @or-input-changed="${(e: OrInputChangedEvent) => this._setConnectionProperty("host", e.detail.value)}"></or-input>+ <or-input .label="${i18next.t("port")}" .type="${InputType.NUMBER}" ?disabled="${this._loading || this._readonly}" min="1" max="65536" step="1" .value="${connection ? connection.port : undefined}" @or-input-changed="${(e: OrInputChangedEvent) => this._setConnectionProperty("port", e.detail.value)}"></or-input>+ <or-input .label="${i18next.t("realm")}" .type="${InputType.TEXT}" ?disabled="${this._loading || this._readonly}" .value="${connection ? connection.realm : ""}" @or-input-changed="${(e: OrInputChangedEvent) => this._setConnectionProperty("realm", e.detail.value)}"></or-input>+ <or-input .label="${i18next.t("clientId")}" .type="${InputType.TEXT}" ?disabled="${this._loading || this._readonly}" .value="${connection ? connection.clientId : ""}" @or-input-changed="${(e: OrInputChangedEvent) => this._setConnectionProperty("clientId", e.detail.value)}"></or-input>+ <or-input .label="${i18next.t("clientSecret")}" .type="${InputType.TEXT}" ?disabled="${this._loading || this._readonly}" .value="${connection ? connection.clientSecret : ""}" @or-input-changed="${(e: OrInputChangedEvent) => this._setConnectionProperty("clientSecret", e.detail.value)}"></or-input>+ <or-input .label="${i18next.t("secured")}" .type="${InputType.SWITCH}" ?disabled="${this._loading || this._readonly}" .value="${connection ? connection.secured : false}" @or-input-changed="${(e: OrInputChangedEvent) => this._setConnectionProperty("secured", e.detail.value)}"></or-input>+ <or-input .label="${i18next.t("disabled")}" .type="${InputType.SWITCH}" ?disabled="${this._loading || this._readonly}" .value="${connection ? connection.disabled : false}" @or-input-changed="${(e: OrInputChangedEvent) => this._setConnectionProperty("disabled", e.detail.value)}"></or-input>+ </div>+ <div id="buttons">+ <or-input .label="${i18next.t("reset")}" ?disabled="${!this._dirty || this._loading || this._readonly}" .type="${InputType.BUTTON}" raised @click="${() => this._reset()}"></or-input>+ <or-input .label="${i18next.t("delete")}" ?disabled="${this._loading || this._readonly}" .type="${InputType.BUTTON}" raised @click="${() => this._delete()}"></or-input>+ <or-input .label="${i18next.t("save")}" ?disabled="${!this._dirty || this._loading || this._readonly}" .type="${InputType.BUTTON}" raised @click="${() => this._save()}"></or-input>+ </div>+ </or-panel>+ `;+ }++ protected async _subscribeEvents() {+ if (manager.events) {+ this._eventSubscriptionId = await manager.events.subscribe<GatewayConnectionStatusEvent>({+ eventType: "gateway-connection-status"+ }, (ev) => this._onEvent(ev));+ }+ }++ protected _unsubscribeEvents() {+ if (this._eventSubscriptionId) {+ manager.events!.unsubscribe(this._eventSubscriptionId);+ this._eventSubscriptionId = undefined;+ }+ }++ protected async _loadData() {+ this._loading = true;+ this._connection = {secured: true};+ this._connectionStatus = null;+ const connectionResponse = await manager.rest.api.GatewayClientResource.getConnection(this.realm);+ const statusResponse = await manager.rest.api.GatewayClientResource.getConnectionStatus(this.realm);++ this._setConnection(connectionResponse.data);+ this._connectionStatus = statusResponse.data;+ }++ protected _setConnectionProperty(propName: string, value: any) {+ this._connection[propName] = value;+ this._dirty = true;+ }++ protected _reset() {+ this._loadData();+ }++ protected async _delete() {+ this._loading = true;+ const response = await manager.rest.api.GatewayClientResource.deleteConnection(this.realm);+ if (response.status !== 204) {+ // TODO: Toast message+ }+ this._loadData();+ }++ protected async _save() {+ this._loading = true;+ const response = await manager.rest.api.GatewayClientResource.setConnection(this.realm, this._connection);+ if (response.status !== 204) {+ // TODO: Toast message+ }+ this._loadData();+ }++ protected _setConnection(connection: GatewayConnection) {+ this._connection = connection || {secured: true};+ this._loading = false;+ this._dirty = false;+ }++ protected _onEvent(event: GatewayConnectionStatusEvent) {+ if (event.realm === this.realm) {+ this._connectionStatus = event.connectionStatus;+ }+ }++ protected _getRealm(): string {+ return this.realm || manager.getRealm();+ }+}diff --git a/ui/app/main/src/components/pages/page-gateway.ts b/ui/app/main/src/components/pages/page-gateway.tsnew file mode 100644index 000000000..6c10414c0--- /dev/null+++ b/ui/app/main/src/components/pages/page-gateway.ts@@ -0,0 +1,38 @@+import {css, customElement, html, LitElement} from "lit-element";+import {store} from "../../store";+import {connect} from "pwa-helpers/connect-mixin";+import "../or-gateway-connection-panel/src/index";++@customElement("page-gateway")+class PageGateway extends connect(store)(LitElement) {+ // language=CSS+ static get styles() {+ return css`+ :host {+ flex: 1;+ width: 100%;++ display: flex;+ justify-content: center;+ }++ or-gateway-connection-panel {+ max-width: 1000px;+ margin-top: 40px;+ }++ @media only screen and (max-width: 1080px){+ or-gateway-connection-panel {+ margin: 0;+ }+ }+ `;+ }++ protected render() {+ return html`++ <or-gateway-connection-panel></or-gateway-connection-panel>+ `;+ }+}diff --git a/ui/app/main/src/index.ts b/ui/app/main/src/index.tsindex e020bb2dd..0b1ab2a7a 100644--- a/ui/app/main/src/index.ts+++ b/ui/app/main/src/index.ts@@ -45,6 +45,9 @@ router.on({"logs": (params, query) => {store.dispatch(updatePage("logs"));},+ "gateway": (params, query) => {+ store.dispatch(updatePage("gateway"));+ },"*": (params, query) => {store.dispatch(updatePage("map"));}diff --git a/ui/component/or-header/src/index.ts b/ui/component/or-header/src/index.tsindex 9b39e8717..05f76ae03 100644--- a/ui/component/or-header/src/index.ts+++ b/ui/component/or-header/src/index.ts@@ -2,23 +2,25 @@ import {style} from "./style";import {customElement, html, LitElement, property, query} from "lit-element";import {MDCDialog} from "@material/dialog";import i18next from "i18next";-import manager from "@openremote/core";+import manager, {Util} from "@openremote/core";import {MenuItem} from "@openremote/or-mwc-components/dist/or-mwc-menu";import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/dist/or-mwc-menu";import "@openremote/or-icon";import "./or-language";import "./or-language-modal";import "./or-realm-picker";+import {Constants} from "@openremote/model";-interface menuOption {+interface MenuOption {icon: string;text: string;value?: string;href?: string;hideMobile?: boolean;+ roles?: string[];}-const mainItems: menuOption[] = [+const mainItems: MenuOption[] = [{icon: "map",href: "#!map",@@ -48,13 +50,13 @@ const mainItems: menuOption[] = [// }];-const secondaryItems: menuOption[] = [- // {- // icon: "cloud",- // value: "cloud",- // text: "Cloud connection",- // isSuperUser: true- // },+const secondaryItems: MenuOption[] = [+ {+ icon: "cloud",+ href: "#!gateway",+ text: "gatewayConnection",+ roles: ["write:admin", "read:admin"]+ },{icon: "web",value: "language",@@ -85,8 +87,8 @@ const secondaryItems: menuOption[] = [}];-function getHeaderMenu(items: menuOption[]): MenuItem[] {- return items.map(option => {+function getHeaderMenu(items: MenuOption[]): MenuItem[] {+ return items.filter(option => !option.roles || option.roles.some(r => manager.hasRole(r))).map(option => {return {text: option.text,value: option.value ? option.value : "",@@ -95,6 +97,7 @@ function getHeaderMenu(items: menuOption[]): MenuItem[] {};});}+export class OrHeaderMenuChangedEvent extends CustomEvent<boolean> {public static readonly NAME = "or-header-menu-changed";@@ -119,10 +122,10 @@ class OrHeader extends LitElement {private logoMobile = "";@property({ type: Array })- private mainItems: menuOption[] = mainItems;+ private mainItems: MenuOption[] = mainItems;@property({ type: Array })- private secondaryItems: menuOption[] = secondaryItems;+ private secondaryItems: MenuOption[] = secondaryItems;@property({ type: String })private activeMenu: string | undefined = window.location.hash ? window.location.hash : "#!map";@@ -164,7 +167,7 @@ class OrHeader extends LitElement {<nav id="toolbar-list"><div id="desktop-left">- ${this.mainItems.map(menuItem => {+ ${this.mainItems.filter(option => !option.roles || option.roles.some(r => manager.hasRole(r))).map(menuItem => {return html`<a class="menu-item" href="${menuItem.href}" ?selected="${this.activeMenu === menuItem.href}" data-navigo @click="${() => this.activeMenu = menuItem.href}"><or-icon icon="${menuItem.icon}"></or-icon><or-translate value="${menuItem.text}"></or-translate></a>`@@ -192,8 +195,7 @@ class OrHeader extends LitElement {<div><div id="mobile-top"><nav id="drawer-list">- ${this.mainItems.map(menuItem => {- if (menuItem.hideMobile) return html``;+ ${this.mainItems.filter(option => !option.hideMobile && (!option.roles || option.roles.some(r => manager.hasRole(r)))).map(menuItem => {return html`<a class="menu-item" href="${menuItem.href}" ?selected="${this.activeMenu === menuItem.href}" data-navigo @click="${() => this.activeMenu = menuItem.href}"><or-icon icon="${menuItem.icon}"></or-icon><or-translate value="${menuItem.text}"></or-translate></a>`@@ -202,8 +204,7 @@ class OrHeader extends LitElement {</div><div id="mobile-bottom">- ${this.secondaryItems.map(menuItem => {- if (menuItem.hideMobile) return html``;+ ${this.secondaryItems.filter(option => !option.hideMobile && (!option.roles || option.roles.some(r => manager.hasRole(r)))).map(menuItem => {if(menuItem.href)return html`<a class="menu-item" href="${menuItem.href}" ?selected="${this.activeMenu === menuItem.href}" data-navigo @click="${() => this.activeMenu = menuItem.href}"><or-icon icon="${menuItem.icon}"></or-icon><or-translate value="${menuItem.text}"></or-translate></a>@@ -216,9 +217,6 @@ class OrHeader extends LitElement {</div></div></div>---`;}diff --git a/ui/component/or-log-viewer/src/index.ts b/ui/component/or-log-viewer/src/index.tsindex 070f005ff..724dd32a7 100644--- a/ui/component/or-log-viewer/src/index.ts+++ b/ui/component/or-log-viewer/src/index.ts@@ -265,10 +265,12 @@ export class OrLogViewer extends translate(i18next)(LitElement) {this._loadData();}- if (this.live) {- this._subscribeEvents();- } else {- this._unsubscribeEvents();+ if (_changedProperties.has("live")) {+ if (this.live) {+ this._subscribeEvents();+ } else {+ this._unsubscribeEvents();+ }}return super.shouldUpdate(_changedProperties);diff --git a/ui/component/or-panel/src/index.ts b/ui/component/or-panel/src/index.tsindex 8ecc45033..e8cf7391d 100644--- a/ui/component/or-panel/src/index.ts+++ b/ui/component/or-panel/src/index.ts@@ -15,7 +15,8 @@ const style = css`--internal-or-panel-heading-margin: var(--or-panel-heading-margin, 0 0 5px 7px);--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-font-size: var(--or-panel-heading-font-size, larger);+display: block;}@@ -37,7 +38,7 @@ const style = css`strong {margin: var(--internal-or-panel-heading-margin);- font-size: 16px;+ font-size: var(--internal-or-panel-heading-font-size);}`;