Skip to content

armgit / core

Public Imported from GitHub
0

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

Update or-header to use menuItems insteed of slots

Robin Dekkers168d4a032489
diff --git a/ui/app/main/src/components/my-app.ts b/ui/app/main/src/components/my-app.ts
index ca47bd457..37618bf67 100644
--- a/ui/app/main/src/components/my-app.ts
+++ b/ui/app/main/src/components/my-app.ts
@@ -79,17 +79,7 @@ class MyApp extends connect(store)(LitElement) {
}
return html`
- <or-header logo="${logoImage}" logoMobile="${logoMobileImage}">
- <a slot="desktop-left" ?selected="${this.page === "map"}" @click="${() => router.navigate("map")}"><or-icon icon="map"></or-icon><or-translate value="map"></or-translate></a>
- <a slot="desktop-left" ?selected="${this.page === "assets"}" @click="${() => router.navigate("assets")}"><or-icon icon="sitemap"></or-icon><or-translate value="asset_plural"></or-translate></a>
- <a slot="desktop-left" ?selected="${this.page === "rules"}" @click="${() => router.navigate("rules")}"><or-icon icon="cogs"></or-icon><or-translate value="rule_plural"></or-translate></a>
- ${(manager.isSuperUser() ? html`<a slot="desktop-right"><or-realm-picker></or-realm-picker></a>` : ``)}
- <a slot="desktop-right"><or-language></or-language></a>
- <a slot="desktop-right" @click="${() => this.logout()}"><or-translate value="logout"></or-translate></a>
- <a slot="mobile-top" ?selected="${this.page === "map"}" @click="${() => router.navigate("map")}"><or-icon icon="map"></or-icon><or-translate value="map"></or-translate></a>
- <a slot="mobile-top" ?selected="${this.page === "assets"}" @click="${() => router.navigate("assets")}"><or-icon icon="sitemap"></or-icon><or-translate value="asset_plural"></or-translate></a>
- <a slot="mobile-top" @click="${() => this.logout()}"><or-icon icon="logout"></or-icon><or-translate value="logout"></or-translate></a>
- </or-header>
+ <or-header logo="${logoImage}" logoMobile="${logoMobileImage}"></or-header>
<!-- Main content -->
<main role="main" class="main-content d-none">
diff --git a/ui/component/or-attribute-history/src/index.ts b/ui/component/or-attribute-history/src/index.ts
index a8c22fc15..7e0bdb1d7 100644
--- a/ui/component/or-attribute-history/src/index.ts
+++ b/ui/component/or-attribute-history/src/index.ts
@@ -234,7 +234,7 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
public attributeRef?: AttributeRef;
@property({type: String})
- public period: moment.unitOfTime.Base = "hour";
+ public period: moment.unitOfTime.Base = "day";
@property({type: Number})
public fromTimestamp?: Date;
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
index 0df9bb271..682ef56ca 100644
--- a/ui/component/or-chart/src/index.ts
+++ b/ui/component/or-chart/src/index.ts
@@ -392,6 +392,7 @@ export class OrChart extends translate(i18next)(LitElement) {
if(assetTreeElement){
assetTreeElement.addEventListener(OrAssetTreeSelectionChangedEvent.NAME, (evt) => this._onTreeSelectionChanged(evt));
}
+
this._dialog = new MDCDialog(this._dialogElem);
this.assetAttributes.map((attr, index) => {
diff --git a/ui/component/or-header/src/index.ts b/ui/component/or-header/src/index.ts
index 63861bf37..60ea0b9eb 100644
--- a/ui/component/or-header/src/index.ts
+++ b/ui/component/or-header/src/index.ts
@@ -1,9 +1,100 @@
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 {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";
+interface menuOption {
+ icon: string;
+ text: string;
+ value?: string;
+ href?: string;
+ hideMobile?: boolean;
+}
+
+const mainItems: menuOption[] = [
+ {
+ icon: "map",
+ href: "#!map",
+ text: "map"
+ },
+ {
+ icon: "rhombus-split",
+ href: "#!assets",
+ text: "asset_plural",
+ },
+ {
+ icon: "state-machine",
+ href: "#!rules",
+ text: "rule_plural",
+ hideMobile: true
+ },
+ {
+ icon: "chart-areaspline",
+ href: "#!insights",
+ text: "insights",
+ hideMobile: true
+ },
+ // {
+ // icon: "android-messages",
+ // href: "#!messages",
+ // text: "messages",
+ // }
+];
+
+const secondaryItems: menuOption[] = [
+ // {
+ // icon: "cloud",
+ // value: "cloud",
+ // text: "Cloud connection",
+ // isSuperUser: true
+ // },
+ {
+ icon: "web",
+ value: "language",
+ text: "Language"
+ },
+ {
+ icon: "file-document-box-search-outline",
+ value: "logs",
+ href: "#!logs",
+ text: "Logs"
+ },
+ // {
+ // icon: "account-cog",
+ // value: "User management",
+ // text: "User management",
+ // isSuperUser: true
+ // },
+ // {
+ // icon: "tune",
+ // value: "Settings",
+ // text: "Settings"
+ // },
+ {
+ icon: "logout",
+ value: "logout",
+ text: "Log out"
+ }
+];
+
+function getHeaderMenu(items: menuOption[]): MenuItem[] {
+ return items.map(option => {
+ return {
+ text: i18next.t(option.text),
+ value: option.value ? option.value : "",
+ icon: option.icon,
+ href: option.href
+ };
+ });
+}
+
@customElement("or-header")
class OrHeader extends LitElement {
@@ -16,13 +107,27 @@ class OrHeader extends LitElement {
@property({ type: String })
private logoMobile = "";
+ @property({ type: Array })
+ private mainItems: menuOption[] = mainItems;
+
+ @property({ type: Array })
+ private secondaryItems: menuOption[] = secondaryItems;
+
+ @property({ type: String })
+ private activeMenu: string | undefined = window.location.hash;
+
@query("slot[name=mobile-bottom]")
protected _mobileBottomSlot?: HTMLSlotElement;
@query("div[id=mobile-bottom]")
protected _mobileBottomDiv?: HTMLDivElement;
- static styles = style;
+
+ static get styles() {
+ return [
+ style
+ ];
+ }
protected render() {
return html`
@@ -34,31 +139,60 @@ class OrHeader extends LitElement {
<nav id="toolbar-list">
<div id="desktop-left">
- <slot name="desktop-left"></slot>
+ ${this.mainItems.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>
+ `
+ })}
</div>
</nav>
-
<div id="desktop-right">
+ ${(manager.isSuperUser() ? html`<a slot="desktop-right"><or-realm-picker></or-realm-picker></a>` : ``)}
<slot name="desktop-right"></slot>
</div>
-
- <button id="menu-btn" title="Menu" @click="${this._menuButtonClicked}">${this._drawerOpened ? html`<or-icon icon="close"></or-icon>` : html`<or-icon icon="menu"></or-icon>`}</button>
+ ${getContentWithMenuTemplate(
+ html`
+ <button id="desktop-menu-btn" class="menu-btn" title="Menu"><or-icon icon="dots-vertical"></or-icon></button>
+ `,
+ getHeaderMenu(this.secondaryItems),
+ this.activeMenu,
+ (values: string | string[]) => this.setActiveMenu(values as string))}
+ <span id="menu-btn-mobile" >
+ <button id="menu-btn" class="menu-btn" title="Menu" @click="${this._menuButtonClicked}">${this._drawerOpened ? html`<or-icon icon="close"></or-icon>` : html`<or-icon icon="menu"></or-icon>`}</button>
+ </span>
</div>
</div>
-
+ <or-language-modal id="language-modal"></or-language-modal>
<div id="drawer" ?opened="${this._drawerOpened}" @click="${this._close}">
<div>
<div id="mobile-top">
<nav id="drawer-list">
- <slot name="mobile-top"></slot>
+ ${this.mainItems.map(menuItem => {
+ if (menuItem.hideMobile) return html``;
+ 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>
+ `
+ })}
</nav>
</div>
<div id="mobile-bottom">
- <slot name="mobile-bottom"></slot>
+ ${this.secondaryItems.map(menuItem => {
+ if (menuItem.hideMobile) return html``;
+ 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>
+ `
+ else
+ return html`
+ <a class="menu-item" @click=${() => this.setActiveMenu(menuItem.value as string)} ><or-icon icon="${menuItem.icon}"></or-icon><or-translate value="${menuItem.text}"></or-translate></a>
+ `
+ })}
</div>
</div>
- </divr>
+ </div>
+
+
`;
}
@@ -79,4 +213,27 @@ class OrHeader extends LitElement {
private _menuButtonClicked() {
this._drawerOpened = !this._drawerOpened;
}
+
+ setActiveMenu(value: string) {
+ switch (value) {
+ case "logout":
+ manager.logout()
+ break;
+ case "language":
+ const modal = this.shadowRoot!.getElementById("language-modal")
+ if(modal && modal.shadowRoot) {
+ const component = modal.shadowRoot.getElementById("mdc-dialog-language");
+ if(component){
+ const dialog = new MDCDialog(component);
+ if(dialog){
+ dialog.open();
+ }
+ }
+ }
+
+ break;
+ }
+ this.activeMenu = value;
+ }
+
}
diff --git a/ui/component/or-header/src/or-language-modal.ts b/ui/component/or-header/src/or-language-modal.ts
new file mode 100644
index 000000000..a75989bc1
--- /dev/null
+++ b/ui/component/or-header/src/or-language-modal.ts
@@ -0,0 +1,116 @@
+import {customElement, html, css, LitElement, property, query, unsafeCSS} from "lit-element";
+import "@openremote/or-icon";
+import i18next from "i18next";
+import manager from "@openremote/core";
+import { InputType } from "@openremote/or-input";
+import {MDCDialog} from '@material/dialog';
+const dialogStyle = require("!!raw-loader!@material/dialog/dist/mdc.dialog.css");
+
+// language=CSS
+const style = css`
+ :host {
+ position: relative;
+ }
+
+ #language-dialog-content {
+ display: flex;
+ }
+
+ #language-picker {
+ flex: 1 1 0;
+ }
+
+`;
+interface languageOptions {
+ [key: string]: string;
+}
+
+export const languageOptions: languageOptions = {
+ "en": "english",
+ "nl": "dutch",
+ "fr": "french",
+ "de": "german",
+ "es": "spanish"
+};
+
+const getLanguageOptions = () => {
+ return Object.entries(languageOptions);
+}
+
+@customElement("or-language-modal")
+export class OrLanguageModal extends LitElement {
+
+
+ @property({type: Boolean})
+ isVisible?: boolean = false;
+
+ @property({type: String})
+ language: string = manager.language;
+
+ @query("#mdc-dialog-language")
+ protected _dialogElem!: HTMLElement;
+
+ protected _dialog!: MDCDialog;
+
+
+ static get styles() {
+ return [
+ css`${unsafeCSS(dialogStyle)}`,
+ style
+ ];
+ }
+
+
+ firstUpdated() {
+ this.language = manager.language ? manager.language : "en";
+ this._dialog = new MDCDialog(this._dialogElem);
+ }
+
+ protected render() {
+ return html`
+ <div id="mdc-dialog-language"
+ class="mdc-dialog"
+ role="alertdialog"
+ aria-modal="true"
+ aria-labelledby="my-dialog-title"
+ aria-describedby="my-dialog-content">
+ <div class="mdc-dialog__container">
+ <div class="mdc-dialog__surface">
+ <h2 class="mdc-dialog__title" id="my-dialog-title">Choice language</h2>
+ <div class="dialog-container mdc-dialog__content" id="language-dialog-content">
+ <or-input id="language-picker"
+ .label="${i18next.t("language")}"
+ .type="${InputType.LIST}"
+ .options="${getLanguageOptions()}"></or-input>
+ </div>
+ <footer class="mdc-dialog__actions">
+ <or-input class="button"
+ slot="secondaryAction"
+ .type="${InputType.BUTTON}"
+ label="${i18next.t("Cancel")}"
+ class="mdc-button mdc-dialog__button"
+ data-mdc-dialog-action="no"></or-input>
+
+ <or-input class="button"
+ slot="primaryAction"
+ .type="${InputType.BUTTON}"
+ label="${i18next.t("ok")}"
+ class="mdc-button mdc-dialog__button"
+ data-mdc-dialog-action="yes"
+ @click="${this.changeLanguage}"></or-input>
+
+ </footer>
+ </div>
+ </div>
+ <div class="mdc-dialog__scrim"></div>
+ </div>
+ `;
+ }
+
+ changeLanguage() {
+ if(this.shadowRoot && this.shadowRoot.getElementById('language-picker')){
+ const elm = this.shadowRoot.getElementById('language-picker') as HTMLInputElement;
+ manager.language = elm.value;
+ }
+ }
+}
diff --git a/ui/component/or-header/src/or-language.ts b/ui/component/or-header/src/or-language.ts
index 7c0192344..e9ccc43cd 100644
--- a/ui/component/or-header/src/or-language.ts
+++ b/ui/component/or-header/src/or-language.ts
@@ -21,7 +21,7 @@ interface languageOptions {
[key: string]: string;
}
-const languageOptions: languageOptions = {
+export const languageOptions: languageOptions = {
"en": "english",
"nl": "dutch",
"fr": "french",
@@ -38,7 +38,7 @@ function getLanguageMenu(): MenuItem[] {
};
});
}
-
+// TODO remove because deprecated?
@customElement("or-language")
export class OrLanguage extends LitElement {
diff --git a/ui/component/or-header/src/or-realm-picker.ts b/ui/component/or-header/src/or-realm-picker.ts
index bbd43e767..4ebe45e96 100644
--- a/ui/component/or-header/src/or-realm-picker.ts
+++ b/ui/component/or-header/src/or-realm-picker.ts
@@ -53,8 +53,8 @@ export class OrRealmPicker extends LitElement {
${getContentWithMenuTemplate(
html`
<div class="or-realm-picker-container">
- <or-icon icon="home"></or-icon>
<span style="margin-left: 10px;">${manager.displayRealm}</span>
+ <or-icon icon="chevron-down"></or-icon>
</div>
`,
this.getMenuItems(),
diff --git a/ui/component/or-header/src/style.ts b/ui/component/or-header/src/style.ts
index df15e5450..1be0db339 100644
--- a/ui/component/or-header/src/style.ts
+++ b/ui/component/or-header/src/style.ts
@@ -88,12 +88,21 @@ export const style = css`
position: relative;
}
- #menu-btn {
+ .menu-btn {
background: none;
border: none;
cursor: pointer;
padding: 0 6px;
- margin: 10px 10px 10px auto;
+ height: 100%;
+ margin: 0 10px 0 auto;
+ }
+
+ #menu-btn-mobile {
+ margin-left: auto;
+ }
+
+ #desktop-menu-btn {
+ display: none;
}
#desktop-right {
@@ -113,48 +122,50 @@ export const style = css`
border-top: 2px solid var(--internal-or-header-drawer-separator-color);
}
- ::slotted(*) {
+ .menu-item {
opacity: 0.7;
cursor: pointer;
- text-decoration: none !important;
+ text-decoration: none !important;
+ color: inherit;
+ padding: 0 20px;
+ font-size: 14px;
}
- ::slotted(*), ::slotted(*:link), ::slotted(*:visited) {
- color: inherit;
- }
- ::slotted(*[selected]), ::slotted(*:hover), #desktop-right ::slotted(*) {
+
+ .menu-item[selected] {
opacity: 1;
}
- #desktop-left ::slotted(*), #desktop-right ::slotted(*) {
- padding: 0 20px;
- font-size: 14px;
- }
-
- #desktop-left ::slotted(*) {
+
+ #desktop-left .menu-item {
display: none;
line-height: calc(var(--internal-or-header-height) - 4px);
}
- #desktop-right ::slotted(*) {
+ #desktop-right .menu-item {
line-height: var(--internal-or-header-height);
}
- #drawer ::slotted(*) {
+ #drawer .menu-item {
display: block;
line-height: var(--internal-or-header-drawer-item-size);
margin: 10px 0;
}
- #desktop-left ::slotted(*[selected]) {
+ #desktop-left .menu-item[selected] {
display: inline-block;
line-height: var(--internal-or-header-height);
}
+
/* Wide layout: when the viewport width is bigger than 780px, layout
changes to a wide layout. */
+
@media (min-width: 780px) {
+ #desktop-menu-btn {
+ display: block;
+ }
#logo {
margin: var(--internal-or-header-logo-margin);
@@ -166,7 +177,7 @@ export const style = css`
display: none;
}
- #menu-btn {
+ #menu-btn-mobile {
display: none;
}
@@ -178,11 +189,11 @@ export const style = css`
display: block;
}
- #desktop-left ::slotted(*) {
+ #desktop-left .menu-item {
display: inline-block;
}
-
- #desktop-left ::slotted(*[selected]) {
+
+ #desktop-left .menu-item[selected] {
border-bottom: 4px solid var(--internal-or-header-selected-color);
line-height: calc(var(--internal-or-header-height) - 4px);
}
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 3f5b4a603..c5644d83e 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -399,7 +399,6 @@ export class OrInput extends LitElement {
}
this._selectedIndex = -1;
-
return html`
<div id="component" class="mdc-select ${classMap(classesList)}" @MDCList:action="${(e: MDCListActionEvent) => this.onValueChange(undefined, e.detail.index === -1 ? undefined : Array.isArray(this.options![e.detail.index]) ? this.options![e.detail.index][0] : this.options![e.detail.index])}">
<ul class="mdc-list">
diff --git a/ui/component/or-mwc-components/src/or-mwc-menu.ts b/ui/component/or-mwc-components/src/or-mwc-menu.ts
index a961831a6..550fc2a6c 100644
--- a/ui/component/or-mwc-components/src/or-mwc-menu.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-menu.ts
@@ -24,6 +24,7 @@ export interface MenuItem {
text?: string;
secondaryText?: string;
value: string;
+ href?: string;
styleMap?: {[style: string]: string};
}
@@ -91,7 +92,13 @@ const style = css`
.mdc-list-item__graphic {
margin-right: 16px;
- }
+ }
+
+ a {
+ text-decoration: none;
+ color: rgba(0, 0, 0, 0.87);
+ }
+
`;
@customElement("or-mwc-menu")
@@ -182,6 +189,7 @@ export class OrMwcMenu extends LitElement {
const isSelected = this.isValueSelected((item as MenuItem).value);
let icon = item.icon;
+ const href = item.href;
const text = item.text !== undefined ? item.text : item.value;
let leftTemplate: TemplateResult | string = ``;
let rightTemplate: TemplateResult | string = ``;
@@ -201,8 +209,7 @@ export class OrMwcMenu extends LitElement {
<or-icon icon="${item.trailingIcon}"></or-icon>
</span>`;
}
-
- return html`
+ const listItem = html`
<li @click="${(e: MouseEvent) => {this._itemClicked(e, item)}}" style="${item.styleMap ? styleMap(item.styleMap) : ""}" class="mdc-list-item ${isSelected ? "mdc-menu-item--selected" : ""}" role="menuitem" aria-checked="${isSelected}">
${leftTemplate}
${!text ? html`` : html`
@@ -214,6 +221,18 @@ export class OrMwcMenu extends LitElement {
${rightTemplate}
</li>
`;
+
+ if(href) {
+ return html`
+ <a href="${href}" data-navigo>
+ ${listItem}
+ </a>
+ `;
+ } else {
+ return listItem;
+ }
+
+
})}
`;
}
diff --git a/ui/component/or-mwc-components/src/style.ts b/ui/component/or-mwc-components/src/style.ts
index 5a6311201..1cb1bb5c4 100644
--- a/ui/component/or-mwc-components/src/style.ts
+++ b/ui/component/or-mwc-components/src/style.ts
@@ -14,7 +14,7 @@ export const orInputStyle = css`
--mdc-theme-on-primary: var(--internal-or-input-text-color);
--mdc-theme-secondary: var(--internal-or-input-color);
}
-
+
.or-input--rounded {
border-radius: 50% !important;
}
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
index 786d1c244..afdf4cc76 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
@@ -139,10 +139,10 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
<or-input id="matchSelect" .label="${i18next.t("asset")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" ?readonly="${this.readonly}" .options="${idOptions}" .value="${idValue}"></or-input>
${attributes.length > 0 ? html`
<or-input id="attributeSelect" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(e.detail.value)}" ?readonly="${this.readonly}" .options="${attributes}" .value="${this.action.attributeName}"></or-input>
+ ${inputTemplate ? inputTemplate(this.action.value) : ``}
` : html`
<or-translate value="No attributes with write permission"></or-translate>
`}
- ${inputTemplate ? inputTemplate(this.action.value) : ``}
`;
}
@@ -204,7 +204,6 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
}
],
select: {
- excludeAttributeMeta: true,
excludeAttributeTimestamp: true,
excludeAttributeValue: true,
excludeParentInfo: true,