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
Improve user management page
Robin Dekkers6bfeac2ee27b
diff --git a/ui/app/or-app/src/index.ts b/ui/app/or-app/src/index.tsindex f7c29e1ad..b2a8fa0f1 100644--- a/ui/app/or-app/src/index.ts+++ b/ui/app/or-app/src/index.ts@@ -124,7 +124,8 @@ export function headerItemUsers<S extends AppStateKeyed, A extends AnyAction>(oricon: "account-group",value: "users",href: "users",- text: "user_plural"+ text: "user_plural",+ roles: ["write:admin"]};}export function getRealmQueryParameter(): string {@@ -178,6 +179,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {--or-app-color2: ${unsafeCSS(DefaultColor2)};--or-app-color3: #22211f;--or-app-color4: #4D9D2A;+ --or-console-primary-color: #4D9D2A;color: ${unsafeCSS(DefaultColor3)};fill: ${unsafeCSS(DefaultColor3)};font-size: 14px;diff --git a/ui/app/or-app/src/pages/page-users.ts b/ui/app/or-app/src/pages/page-users.tsindex 36a3d2f15..766b3506d 100644--- a/ui/app/or-app/src/pages/page-users.ts+++ b/ui/app/or-app/src/pages/page-users.ts@@ -3,10 +3,11 @@ import {customElement,html,property,+ PropertyValues,TemplateResult,unsafeCSS,} from "lit-element";-import manager from "@openremote/core";+import manager, { OREvent } from "@openremote/core";import "@openremote/or-panel";import "@openremote/or-translate";import { EnhancedStore } from "@reduxjs/toolkit";@@ -53,15 +54,24 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {width: 100%;max-width: 1360px;}-- #table-users {++ .panel {width: 100%;max-width: 1400px;+ background-color: white;+ border: 1px solid #e5e5e5;+ border-radius: 5px;+ position: relative;margin: 0 auto;+ padding: 20px;+ }++ #table-users {+ width: 100%;}.meta-item-container {- flex-direction: row;+ flex-direction: row;overflow: hidden;max-height: 0;transition: max-height 0.25s ease-out;@@ -90,6 +100,18 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {max-height: 1000px;transition: max-height 1s ease-in;}++ .button {+ cursor: pointer;+ display: flex;+ flex-direction: row;+ align-content: center;+ margin: 10px 0px;+ }++ .button or-icon {+ --or-icon-fill: var(--or-app-color4);+ }`,];}@@ -97,6 +119,9 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {@property()protected _users: User[] = [];+ @property()+ public realm?: string;+get name(): string {return "users";}@@ -106,11 +131,47 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {this.getUsers();}+ 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.getUsers();+ }++ return super.shouldUpdate(_changedProperties);+ }++ public connectedCallback() {+ super.connectedCallback();+ manager.addListener(this._onManagerEvent);+ }++ public disconnectedCallback() {+ super.disconnectedCallback();+ manager.removeListener(this._onManagerEvent);+ }++private getUsers() {manager.rest.api.UserResource.getAll(manager.displayRealm).then((usersResponse) => (this._users = [...usersResponse.data]));}++ private _createUser(user) {+ manager.rest.api.UserResource.create(manager.displayRealm, user).then(response => {+ this.getUsers()+ });++}+private _updateUser(user, passwords) {if(passwords && passwords.resetPassword && passwords.repeatPassword) {if(passwords.resetPassword !== passwords.repeatPassword) return;@@ -137,22 +198,15 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {<or-translate value="notSupported"></or-translate>`;}- const expanderToggle = (ev: MouseEvent) => {- const tdElem = ev.target as HTMLElement;- if (tdElem.className.indexOf("expander-cell") < 0) {- return;- }- const expanderIcon = tdElem.getElementsByTagName("or-icon")[0] as OrIcon;- const headerRow = tdElem.parentElement! as HTMLTableRowElement;- const metaRow = (headerRow.parentElement! as HTMLTableElement).rows[- headerRow.rowIndex- ];- if (expanderIcon.icon === "chevron-right") {- expanderIcon.icon = "chevron-down";- metaRow.classList.add("expanded");- } else {- expanderIcon.icon = "chevron-right";+ const 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";}};return html`@@ -162,68 +216,77 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {"user_plural")}</div>- <div id="table-users" class="mdc-data-table">- <table class="mdc-data-table__table" aria-label="attribute list" @click="${expanderToggle}">- <thead>- <tr class="mdc-data-table__header-row">- <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="username"></or-translate></th>- <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="email"></or-translate></th>- <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="user_role"></or-translate></th>- <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="status"></or-translate></th>- </tr>- </thead>- <tbody class="mdc-data-table__content">- ${this._users.map(- (user) => {- let passwords = {resetPassword: "", repeatPassword:""};- return html`- <tr class="mdc-data-table__row">- <td- class="padded-cell mdc-data-table__cell expander-cell"- >- <or-icon icon="chevron-right"></or-icon>- <span>${user.username}</span>- </td>- <td class="padded-cell mdc-data-table__cell">- ${user.email}- </td>- <td class="padded-cell mdc-data-table__cell">- </td>- <td class="padded-cell mdc-data-table__cell">- ${user.enabled}- </td>- </tr>- <tr class="attribute-meta-row">- <td colspan="4">- <div class="meta-item-container">- <div class="row">- <div class="column">- <or-input .label="${i18next.t("user")}" .type="${InputType.TEXT}" min="1" required .value="${user.username}" @or-input-changed="${(e: OrInputChangedEvent) => user.username = e.detail.value}"></or-input>- <or-input .label="${i18next.t("email")}" .type="${InputType.EMAIL}" min="1" required .value="${user.email}" @or-input-changed="${(e: OrInputChangedEvent) => user.email = e.detail.value}"></or-input>- <or-input .label="${i18next.t("firstName")}" .type="${InputType.TEXT}" min="1" required .value="${user.firstName}" @or-input-changed="${(e: OrInputChangedEvent) => user.firstName = e.detail.value}"></or-input>- <or-input .label="${i18next.t("lastName")}" .type="${InputType.TEXT}" min="1" required .value="${user.lastName}" @or-input-changed="${(e: OrInputChangedEvent) => user.lastName = e.detail.value}"></or-input>- </div>-- <div class="column">- <or-input .label="${i18next.t("resetPassword")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => passwords.resetPassword = e.detail.value}"></or-input>- <or-input .label="${i18next.t("repeatPassword")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => passwords.repeatPassword = e.detail.value}"></or-input>-- <or-input .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>- </div>- </div>-- <div class="row">- <or-input .label="${i18next.t("delete")}" .type="${InputType.BUTTON}" @click="${() => this._deleteUser(user)}"></or-input>- <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._updateUser(user, passwords)}"></or-input>- </div>-- </div>- </td>- </tr>- `- })}- </tbody>- </table>+ <div class="panel">+ <p>${i18next.t("user_plural")}</p>+ <div id="table-users" 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="username"></or-translate></th>+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="email"></or-translate></th>+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="user_role"></or-translate></th>+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="status"></or-translate></th>+ </tr>+ </thead>+ <tbody class="mdc-data-table__content">+ ${this._users.map(+ (user, index) => {+ let passwords = {resetPassword: "", repeatPassword:""};+ return html`+ <tr id="mdc-data-table-row-${index}" class="mdc-data-table__row" @click="${(ev) => 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>${user.username}</span>+ </td>+ <td class="padded-cell mdc-data-table__cell">+ ${user.email}+ </td>+ <td class="padded-cell mdc-data-table__cell">+ </td>+ <td class="padded-cell mdc-data-table__cell">+ ${user.enabled}+ </td>+ </tr>+ <tr id="attribute-meta-row-${index}" class="attribute-meta-row">+ <td colspan="4">+ <div class="meta-item-container">+ <div class="row">+ <div class="column">+ <or-input .label="${i18next.t("user")}" .type="${InputType.TEXT}" min="1" required .value="${user.username}" @or-input-changed="${(e: OrInputChangedEvent) => user.username = e.detail.value}"></or-input>+ <or-input .label="${i18next.t("email")}" .type="${InputType.EMAIL}" min="1" required .value="${user.email}" @or-input-changed="${(e: OrInputChangedEvent) => user.email = e.detail.value}"></or-input>+ <or-input .label="${i18next.t("firstName")}" .type="${InputType.TEXT}" min="1" required .value="${user.firstName}" @or-input-changed="${(e: OrInputChangedEvent) => user.firstName = e.detail.value}"></or-input>+ <or-input .label="${i18next.t("lastName")}" .type="${InputType.TEXT}" min="1" required .value="${user.lastName}" @or-input-changed="${(e: OrInputChangedEvent) => user.lastName = e.detail.value}"></or-input>+ </div>++ <div class="column">+ ${user.id ? html`+ <or-input .label="${i18next.t("resetPassword")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => passwords.resetPassword = e.detail.value}"></or-input>+ <or-input .label="${i18next.t("repeatPassword")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => passwords.repeatPassword = e.detail.value}"></or-input>+ ` :``}+ <or-input .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>+ </div>+ </div>++ <div class="row">+ ${user.id ? html`+ <or-input .label="${i18next.t("delete")}" .type="${InputType.BUTTON}" @click="${() => this._deleteUser(user)}"></or-input>+ <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._updateUser(user, passwords)}"></or-input>+ ` : html`+ <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._createUser(user)}"></or-input>+ `}+ </div>+ </div>+ </td>+ </tr>+ `+ })}+ </tbody>+ </table>+ </div>++ <a class="button" @click="${() => this._users = [...this._users, {}]}"><or-icon icon="plus"></or-icon><strong>${i18next.t("add")} ${i18next.t("user")}</strong></a></div></div>