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
Add realm page
Robin Dekkers7d16901800d8
diff --git a/ui/app/main/src/index.ts b/ui/app/main/src/index.tsindex 68a783e3c..2d4e83274 100644--- a/ui/app/main/src/index.ts+++ b/ui/app/main/src/index.ts@@ -17,6 +17,7 @@ import {headerItemAccount,headerItemUsers,headerItemRoles,+ headerItemRealms,headerItemInsights} from "@openremote/or-app";import "@openremote/or-app/dist/pages/page-map";import {pageMapReducer, pageMapProvider} from "@openremote/or-app/dist/pages/page-map";@@ -36,6 +37,8 @@ import "@openremote/or-app/dist/pages/page-users";import {pageUsersProvider} from "@openremote/or-app/dist/pages/page-users";import "@openremote/or-app/dist/pages/page-roles";import {pageRolesProvider} from "@openremote/or-app/dist/pages/page-roles";+import "@openremote/or-app/dist/pages/page-realms";+import {pageRealmsProvider} from "@openremote/or-app/dist/pages/page-realms";const rootReducer = combineReducers({app: appReducer,@@ -60,7 +63,9 @@ const appConfig: AppConfig<RootState> = {rules: pageRulesProvider(store),account: pageAccountProvider(store),roles: pageRolesProvider(store),- users: pageUsersProvider(store)+ users: pageUsersProvider(store),+ realms: pageRealmsProvider(store),+},default: {appTitle: "OpenRemote Demo",@@ -85,6 +90,7 @@ const appConfig: AppConfig<RootState> = {headerItemAccount(orApp),headerItemUsers(orApp),headerItemRoles(orApp),+ headerItemRealms(orApp),headerItemLogout(orApp)// {// icon: "account-cog",diff --git a/ui/app/or-app/src/index.ts b/ui/app/or-app/src/index.tsindex 91432a3c6..fe812ef6c 100644--- a/ui/app/or-app/src/index.ts+++ b/ui/app/or-app/src/index.ts@@ -25,6 +25,7 @@ import {ThunkMiddleware} from "redux-thunk";import {AppStateKeyed, updatePage} from "./app";import { InputType, OrInputChangedEvent } from "@openremote/or-input";import {getMapRoute} from "./pages/page-map";+export * from "./app";export * from "./or-header";export * from "./types";@@ -137,6 +138,16 @@ export function headerItemRoles<S extends AppStateKeyed, A extends AnyAction>(orroles: ["write:admin"]};}+export function headerItemRealms<S extends AppStateKeyed, A extends AnyAction>(orApp: OrApp<S>): HeaderItem {+ return {+ icon: " account-circle",+ value: "realms",+ href: "realms",+ text: "realms",+ roles: ["write:admin"]+ };+}+export function getRealmQueryParameter(): string {if(location.search && location.search !== "") {return Util.getQueryParameter(location.search, "realm");diff --git a/ui/app/or-app/src/pages/page-realms.ts b/ui/app/or-app/src/pages/page-realms.tsnew file mode 100644index 000000000..a01ce746b--- /dev/null+++ b/ui/app/or-app/src/pages/page-realms.ts@@ -0,0 +1,397 @@+import {+ css,+ customElement,+ html,+ property,+ PropertyValues,+ TemplateResult,+ unsafeCSS,+} from "lit-element";+import manager, { OREvent } from "@openremote/core";+import "@openremote/or-panel";+import "@openremote/or-translate";+import { EnhancedStore } from "@reduxjs/toolkit";+import { AppStateKeyed } from "../app";+import { Page } from "../types";+import { ClientRole, Tenant } from "@openremote/model";+import { i18next } from "@openremote/or-translate";+import { OrIcon } from "@openremote/or-icon";+import { InputType, OrInputChangedEvent } from "@openremote/or-input";+import {showOkCancelDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";++const tableStyle = require("@material/data-table/dist/mdc.data-table.css");++export function pageRealmsProvider<S extends AppStateKeyed>(+ store: EnhancedStore<S>+) {+ return {+ routes: ["realms"],+ pageCreator: () => {+ return new PageRealms(store);+ },+ };+}+++@customElement("page-realms")+class PageRealms<S extends AppStateKeyed> extends Page<S> {+ static get styles() {+ // language=CSS+ return [+ unsafeCSS(tableStyle),+ css`+ #wrapper {+ height: 100%;+ width: 100%;+ display: flex;+ flex-direction: column;+ overflow: auto;+ }++ #title {+ padding: 0 20px;+ font-size: 18px;+ font-weight: bold;+ width: calc(100% - 40px);+ max-width: 1360px;+ margin: 20px auto;+ }++ #title or-icon {+ margin-right: 10px;+ margin-left: 14px;+ }++ .panel {+ width: calc(100% - 90px);+ padding: 0 20px;+ max-width: 1320px;+ background-color: white;+ border: 1px solid #e5e5e5;+ border-radius: 5px;+ position: relative;+ margin: 0 auto;+ padding: 24px;+ }++ .panel-title {+ text-transform: uppercase;+ font-weight: bolder;+ line-height: 1em;+ color: var(--internal-or-asset-viewer-title-text-color);+ margin-bottom: 20px;+ margin-top: 0;+ flex: 0 0 auto;+ letter-spacing: 0.025em;+ }+++ #table-roles,+ #table-roles table{+ width: 100%;+ white-space: nowrap;+ }++ .mdc-data-table__row {+ border-top-color: lightgrey;+ }++ td, th {+ width: 25%;+ border: none;+ }++ td.large, th.large {+ width: 50%+ }++ .meta-item-container {+ flex-direction: row;+ overflow: hidden;+ max-height: 0;+ transition: max-height 0.25s ease-out;+ padding: 0 20px;+ }++ or-input {+ margin-bottom: 10px;+ margin-right: 20px;+ }++ or-icon {+ vertical-align: middle;+ --or-icon-width: 20px;+ --or-icon-height: 20px;+ }++ .row {+ display: flex;+ flex-direction: row;+ margin: 10px 0;+ flex: 1 1 0;+ }++ .column {+ display: flex;+ flex-direction: column;+ margin: 0px;+ flex: 1 1 0;++ }++ .mdc-data-table__header-cell {+ font-weight: bold;+ }++ .padded-cell {+ overflow-wrap: break-word;+ word-wrap: break-word+ }++ .attribute-meta-row td {+ padding: 0;+ }++ .attribute-meta-row {+ max-width: 0px;+ }++ .attribute-meta-row.expanded .meta-item-container {+ max-height: 1000px;+ max-width: none;+ transition: max-height 1s ease-in;+ }++ .button {+ cursor: pointer;+ display: flex;+ flex-direction: row;+ align-content: center;+ margin: 10px 15px;+ align-items: center;+ }++ .button or-icon {+ --or-icon-fill: var(--or-app-color4);+ }++ @media screen and (max-width: 1024px){+ .row {+ display: block;+ flex-direction: column;+ }+ }++ @media screen and (max-width: 768px){+ #title {+ padding: 0;+ width: 100%;+ }+ .panel {+ width: calc(100% - 40px);+ border-radius: 0;+ }+ .hide-mobile {+ display: none;+ }+ td, th {+ width: 50%+ }+ }+ `,+ ];+ }++ @property()+ protected _tenants: Tenant[] = [];++ @property()+ public realm?: string;++ get name(): string {+ return "roles";+ }++ constructor(store: EnhancedStore<S>) {+ super(store);+ this._getTenants();+ }++ protected _onManagerEvent = (event: OREvent) => {+ switch (event) {+ case OREvent.DISPLAY_REALM_CHANGED:+ this.realm = manager.displayRealm;+ break;+ }+ };++ public shouldUpdate(_changedProperties: PropertyValues): boolean {++ if (_changedProperties.has("realm")) {+ this._getTenants();+ }++ return super.shouldUpdate(_changedProperties);+ }++ public connectedCallback() {+ super.connectedCallback();+ manager.addListener(this._onManagerEvent);+ }++ public disconnectedCallback() {+ super.disconnectedCallback();+ manager.removeListener(this._onManagerEvent);+ }++++ protected async _getTenants() {+ const response = await manager.rest.api.TenantResource.getAll();+ this._tenants = response.data;+ return this._tenants;+ }++ private async _updateTenant(tenant) {+ const response = await manager.rest.api.TenantResource.update(tenant.realm, tenant);+ const data:any = response.data;+ this._tenants = this._tenants.map(t => {+ if(t.id === data.id) {+ return data;+ } else {+ return t+ }+ })+ }++ private async _createTenant(tenant) {+ await manager.rest.api.TenantResource.create(tenant);+ this._getTenants()+ }++ private _deleteRealms(role) {+ showOkCancelDialog(i18next.t("delete"), i18next.t("deleteTenantConfirm"))+ .then((ok) => {+ if (ok) {+ this.doDelete(role);+ }+ });+ }++ private doDelete(realm) {+ this._tenants = [...this._tenants.filter(u => u.id != realm.id)]+ }++ private expanderToggle(ev: MouseEvent, index:number) {+ const metaRow = this.shadowRoot.getElementById('attribute-meta-row-'+index)+ const expanderIcon = this.shadowRoot.getElementById('mdc-data-table-icon-'+index) as OrIcon+ if(metaRow.classList.contains('expanded')){+ metaRow.classList.remove("expanded");+ expanderIcon.icon = "chevron-right";+ } else {+ metaRow.classList.add("expanded");+ expanderIcon.icon = "chevron-down";+ }+ }++ protected render(): TemplateResult | void {+ if (!manager.authenticated) {+ return html`+ <or-translate value="notAuthenticated"></or-translate>+ `;+ }++ if (!manager.isKeycloak()) {+ return html`+ <or-translate value="notSupported"></or-translate>+ `;+ }++ const readonly = !manager.hasRole(ClientRole.WRITE_USER);+ return html`+ <div id="wrapper">+ <div id="title">+ <or-icon icon="account-box-multiple"></or-icon>${i18next.t(+ "realm management"+ )}+ </div>+ <div class="panel">+ <p class="panel-title">${i18next.t("realms")}</p>+ <div id="table-roles" class="mdc-data-table">+ <table class="mdc-data-table__table" aria-label="attribute list" >+ <thead>+ <tr class="mdc-data-table__header-row">+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="name"></or-translate></th>+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="description"></or-translate></th>+ <th class="mdc-data-table__header-cell hide-mobile large" role="columnheader" scope="col"><or-translate value="permissions"></or-translate></th>+ </tr>+ </thead>+ <tbody class="mdc-data-table__content">+ ${this._tenants.map(+ (tenant, index) => {++ return html`+ <tr id="mdc-data-table-row-${index}" class="mdc-data-table__row" @click="${(ev) => this.expanderToggle(ev, index)}">+ <td class="padded-cell mdc-data-table__cell"+ >+ <or-icon id="mdc-data-table-icon-${index}" icon="chevron-right"></or-icon>+ <span>${tenant.realm}</span>+ </td>+ <td class="padded-cell mdc-data-table__cell">+ ${tenant.displayName}+ </td>+ <td class="padded-cell hide-mobile mdc-data-table__cell large">+ ${tenant.enabled ? "Enabled" : "Disabled"}++ </td>+ </tr>+ <tr id="attribute-meta-row-${index}" class="attribute-meta-row${!tenant.id ? " expanded" : ""}">+ <td colspan="100%">+ <div class="meta-item-container">++ <div class="row">+ <div class="column">+ <or-input ?readonly="${tenant.id}" .label="${i18next.t("realm")}" .type="${InputType.TEXT}" min="1" required .value="${tenant.realm}" @or-input-changed="${(e: OrInputChangedEvent) => tenant.realm = e.detail.value}"></or-input>+ </div>+ <div class="column">+ <or-input .label="${i18next.t("displayName")}" .type="${InputType.TEXT}" min="1" required .value="${tenant.displayName}" @or-input-changed="${(e: OrInputChangedEvent) => tenant.displayName = e.detail.value}"></or-input>+ </div>+ <or-input ?readonly="${readonly}" .label="${i18next.t("enabled")}" .type="${InputType.SWITCH}" min="1" .value="${tenant.enabled}" @or-input-changed="${(e: OrInputChangedEvent) =>tenant.enabled = e.detail.value}}"></or-input>++ </div>++++ <div class="row" style="margin-bottom: 0;">+ ${tenant.id && !readonly ? html`+ <or-input .label="${i18next.t("delete")}" .type="${InputType.BUTTON}" @click="${() => this._deleteRealms(tenant)}"></or-input>+ <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._updateTenant(tenant)}"></or-input>+ ` : html`+ <or-input .label="${i18next.t("cancel")}" .type="${InputType.BUTTON}" @click="${() => {this._tenants.splice(-1,1); this._tenants = [...this._tenants]}}"></or-input>+ <or-input style="margin-left: auto;" .label="${i18next.t("create")}" .type="${InputType.BUTTON}" @click="${() => this._createTenant(tenant)}"></or-input>+ `}+ </div>+ </div>+ </td>+ </tr>+ `+ })}+ ${this._tenants.length > 0 && !!this._tenants[this._tenants.length -1].id && !readonly ? html`+ <tr class="mdc-data-table__row">+ <td colspan="100%">+ <a class="button" @click="${() => this._tenants = [...this._tenants, {displayName:"", enabled: true}]}"><or-icon icon="plus"></or-icon><strong>${i18next.t("add")} ${i18next.t("realm")}</strong></a>+ </td>+ </tr>+ ` : ``}+ </tbody>+ </table>+ </div>++ </div>+ </div>++ `;+ }++ public stateChanged(state: S) {}+}diff --git a/ui/app/or-app/src/pages/page-users.ts b/ui/app/or-app/src/pages/page-users.tsindex 49aa1fe8f..49fa3e5d9 100644--- a/ui/app/or-app/src/pages/page-users.ts+++ b/ui/app/or-app/src/pages/page-users.ts@@ -419,7 +419,7 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {<or-input id="password-${index}" ?readonly="${readonly}" .label="${i18next.t("password")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => { this.checkPassword(index) }}"></or-input><or-input id="repeatPassword-${index}" helperPersistent ?readonly="${readonly}" .label="${i18next.t("repeatPassword")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => { this.checkPassword(index) }}"></or-input>- <or-input ?readonly="${readonly}" .label="${i18next.t("enabled")}" .type="${InputType.SWITCH}" min="1" required .value="${user.enabled}" @or-input-changed="${(e: OrInputChangedEvent) => user.enabled = e.detail.value}"></or-input>+ <or-input ?readonly="${readonly}" .label="${i18next.t("enabled")}" .type="${InputType.SWITCH}" min="1" .value="${user.enabled}" @or-input-changed="${(e: OrInputChangedEvent) => user.enabled = e.detail.value}"></or-input></div></div>diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.tsindex daf3b7a9e..6c1e1a6dd 100644--- a/ui/component/or-input/src/index.ts+++ b/ui/component/or-input/src/index.ts@@ -1249,7 +1249,6 @@ export class OrInput extends LitElement {}if(!valid) return}-const previousValue = this.value;if (newValue === "null") {