Skip to content

armgit / core

Public Imported from GitHub
0

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

UI updates: or-asset-viewer edit mode WIP

Rich Turnerabf3b3b10aa7
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.json
index e56b522d1..96fc44ddc 100644
--- a/deployment/manager/shared/locales/en/or.json
+++ b/deployment/manager/shared/locales/en/or.json
@@ -315,6 +315,5 @@
"urn:openremote:asset:meta:ruleEventExpires": "Rule event expires",
"urn:openremote:asset:meta:protocolConfiguration": "Protocol configuration"
},
- "addMetaItems": "Add configuration items",
- "customAttribute": "Custom attribute"
+ "addMetaItems": "Add configuration items"
}
diff --git a/ui/app/or-app/src/pages/page-assets.ts b/ui/app/or-app/src/pages/page-assets.ts
index 0294533d6..5c92a6739 100644
--- a/ui/app/or-app/src/pages/page-assets.ts
+++ b/ui/app/or-app/src/pages/page-assets.ts
@@ -1,22 +1,25 @@
-import {css, customElement, html, property, TemplateResult, unsafeCSS} from "lit-element";
+import {css, customElement, html, property, TemplateResult, unsafeCSS, query} from "lit-element";
import "@openremote/or-asset-tree";
import "@openremote/or-asset-viewer";
-import {ViewerConfig} from "@openremote/or-asset-viewer";
-import {AssetTreeConfig, OrAssetTreeSelectionChangedEvent, OrAssetTreeRequestSelectEvent} from "@openremote/or-asset-tree";
+import {ViewerConfig, OrAssetViewer} from "@openremote/or-asset-viewer";
+import {AssetTreeConfig, OrAssetTreeSelectionChangedEvent, OrAssetTreeRequestSelectEvent, OrAssetTreeRequestEditToggleEvent, OrAssetTreeEditChangedEvent} from "@openremote/or-asset-tree";
import {DefaultBoxShadow} from "@openremote/core";
import {AppStateKeyed, Page, router} from "../index";
import {EnhancedStore} from "@reduxjs/toolkit";
+import { showDialog } from "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import i18next from "i18next";
export interface PageAssetsConfig {
viewer: ViewerConfig;
tree?: AssetTreeConfig;
}
-export function pageAssetsProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config: PageAssetsConfig = PAGE_ASSETS_DEFAULT_CONFIG) {
+export function pageAssetsProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config?: PageAssetsConfig) {
return {
routes: [
"assets",
- "assets/:id"
+ "assets/:editMode",
+ "assets/:editMode/:id"
],
pageCreator: () => {
const page = new PageAssets(store);
@@ -28,150 +31,6 @@ export function pageAssetsProvider<S extends AppStateKeyed>(store: EnhancedStore
};
}
-export const PAGE_ASSETS_DEFAULT_CONFIG: PageAssetsConfig = {
- viewer: {
- historyConfig: {
- table: {
- attributeNames: {
-
- }
- }
- },
- default: {
- panels: {
- "attributes": {
- exclude: ["location", "userNotes", "manufacturer", "model", "status"]
- },
- "info": {
- exclude: ["accessPublicRead"]
- }
- }
- },
- assetTypes: {
- // TODO: These need to move to custom project
- // "urn:openremote:asset:topic": {
- // panels: {
- // "attributes": {
- // exclude: ["location", "status"]
- // }
- // }
- // },
- // "urn:openremote:asset:tcn:soilmoisture": {
- // panels: {
- // "attributes": {
- // exclude: ["location", "name", "id", "code", "type"]
- // }
- // }
- // },
- // "urn:openremote:asset:tcn:meteo": {
- // panels: {
- // "attributes": {
- // exclude: ["location", "name", "id", "code", "type"]
- // }
- // }
- // },
- // "urn:openremote:asset:tcn:point": {
- // panels: {
- // "attributes": {
- // exclude: ["location", "name", "id", "code", "type"]
- // }
- // }
- // },
- // "urn:openremote:asset:residence": {
- // panels: {
- // "attributes": {
- // exclude: [
- // "dayScene",
- // "daySceneEnabledFRIDAY",
- // "daySceneEnabledMONDAY",
- // "daySceneEnabledTUESDAY",
- // "daySceneEnabledWEDNESDAY",
- // "daySceneEnabledTHURSDAY",
- // "daySceneEnabledSATURDAY",
- // "daySceneEnabledSUNDAY",
- // "daySceneTimeFRIDAY",
- // "daySceneTimeMONDAY",
- // "daySceneTimeTUESDAY",
- // "daySceneTimeWEDNESDAY",
- // "daySceneTimeTHURSDAY",
- // "daySceneTimeSATURDAY",
- // "daySceneTimeSUNDAY",
- // "disableSceneTimer",
- // "enableSceneTimer",
- // "eveningScene",
- // "dayScene",
- // "eveningSceneEnabledFRIDAY",
- // "eveningSceneEnabledMONDAY",
- // "eveningSceneEnabledTUESDAY",
- // "eveningSceneEnabledWEDNESDAY",
- // "eveningSceneEnabledTHURSDAY",
- // "eveningSceneEnabledSATURDAY",
- // "eveningSceneEnabledSUNDAY",
- // "eveningSceneTimeFRIDAY",
- // "eveningSceneTimeMONDAY",
- // "eveningSceneTimeTUESDAY",
- // "eveningSceneTimeWEDNESDAY",
- // "eveningSceneTimeTHURSDAY",
- // "eveningSceneTimeSATURDAY",
- // "eveningSceneTimeSUNDAY",
- // "morningScene",
- // "nightscene",
- // "morningSceneEnabledFRIDAY",
- // "morningSceneEnabledMONDAY",
- // "morningSceneEnabledTUESDAY",
- // "morningSceneEnabledWEDNESDAY",
- // "morningSceneEnabledTHURSDAY",
- // "morningSceneEnabledSATURDAY",
- // "morningSceneEnabledSUNDAY",
- // "morningSceneTimeFRIDAY",
- // "morningSceneTimeMONDAY",
- // "morningSceneTimeTUESDAY",
- // "morningSceneTimeWEDNESDAY",
- // "morningSceneTimeTHURSDAY",
- // "morningSceneTimeSATURDAY",
- // "morningSceneTimeSUNDAY",
- // "nightSceneEnabledFRIDAY",
- // "nightSceneEnabledMONDAY",
- // "nightSceneEnabledTUESDAY",
- // "nightSceneEnabledWEDNESDAY",
- // "nightSceneEnabledTHURSDAY",
- // "nightSceneEnabledSATURDAY",
- // "nightSceneEnabledSUNDAY",
- // "nightSceneTimeFRIDAY",
- // "nightSceneTimeMONDAY",
- // "nightSceneTimeTUESDAY",
- // "nightSceneTimeWEDNESDAY",
- // "nightSceneTimeTHURSDAY",
- // "nightSceneTimeSATURDAY",
- // "nightSceneTimeSUNDAY",
- // "vacationUntil",
- // "ventilationLevel",
- // "location",
- // "firstPresenceDetected",
- // "lastPresenceDetected",
- // "smartSwitchStartTimeA",
- // "smartSwitchStartTimeB",
- // "smartSwitchStartTimeC",
- // "smartSwitchEnabledA",
- // "smartSwitchEnabledB",
- // "smartSwitchEnabledC",
- // "smartSwitchStopTimeA",
- // "smartSwitchStopTimeB",
- // "smartSwitchStopTimeC",
- // "smartSwitchBeginEndA",
- // "smartSwitchBeginEndB",
- // "smartSwitchBeginEndC",
- // "smartSwitchModeA",
- // "smartSwitchModeB",
- // "smartSwitchModeC"
- // ]
- // }
- // }
- // }
- }
- }
-};
-
@customElement("page-assets")
class PageAssets<S extends AppStateKeyed> extends Page<S> {
@@ -214,13 +73,16 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
@property()
public config?: PageAssetsConfig;
-
+
@property()
- protected _selectedId;
+ protected _editMode: boolean;
@property()
protected _assetId;
+ @query("#viewer")
+ protected _viewer!: OrAssetViewer;
+
get name(): string {
return "assets";
}
@@ -233,6 +95,8 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
super.connectedCallback();
this.addEventListener(OrAssetTreeSelectionChangedEvent.NAME, this._onTreeSelectionChanged);
this.addEventListener(OrAssetTreeRequestSelectEvent.NAME, this._onTreeSelectionRequested);
+ this.addEventListener(OrAssetTreeRequestEditToggleEvent.NAME, this._onTreeEditToggleRequested);
+ this.addEventListener(OrAssetTreeEditChangedEvent.NAME, this._onTreeEditChanged);
}
disconnectedCallback() {
@@ -242,39 +106,89 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
}
protected render(): TemplateResult | void {
- const selectedIds = [this._selectedId];
+ const selectedIds = this._assetId ? [this._assetId] : undefined;
return html`
- <or-asset-tree .config="${this.config && this.config.tree ? this.config.tree : null}" id="pageAssetTree" class="${this._assetId ? "hideMobile" : ""}" .selectedIds="${selectedIds}"></or-asset-tree>
- <or-asset-viewer class="${!this._assetId ? "hideMobile" : ""}" .config="${this.config && this.config.viewer ? this.config.viewer : PAGE_ASSETS_DEFAULT_CONFIG}" .assetId="${this._assetId}"></or-asset-viewer>
+ <or-asset-tree id="tree" .editMode="${!!this._editMode}" .config="${this.config && this.config.tree ? this.config.tree : null}" class="${this._assetId ? "hideMobile" : ""}" .selectedIds="${selectedIds}"></or-asset-tree>
+ <or-asset-viewer id="viewer" .editMode="${!!this._editMode}" class="${!this._assetId ? "hideMobile" : ""}" .config="${this.config && this.config.viewer ? this.config.viewer : undefined}"></or-asset-viewer>
`;
}
stateChanged(state: S) {
- this._selectedId = state.app.params && state.app.params.id ? state.app.params.id : undefined;
+ const editMode = state.app.params && state.app.params.editMode === "true";
+ const id = state.app.params && state.app.params.id ? state.app.params.id : undefined;
+ this._assetId = id;
+ this._editMode = editMode;
}
protected _onTreeSelectionRequested(event: OrAssetTreeRequestSelectEvent) {
- // Block the selection change but update the route which will cause the change
+ // Block the navigation and show dialog then navigate
event.detail.allow = false;
const assetId = event.detail.detail.node.asset.id;
- if (assetId) {
- router.navigate("assets/" + assetId);
- } else {
- router.navigate("assets/");
- }
+ const action = () => {
+ this._assetId = assetId;
+ this._updateRoute(false);
+ };
+ this._checkIfModified(action);
}
protected _onTreeSelectionChanged(event: OrAssetTreeSelectionChangedEvent) {
const nodes = event.detail;
const assetId = nodes[0] ? nodes[0].asset.id : undefined;
+ this._assetId = assetId;
+ this._viewer.assetId = assetId;
+ this._updateRoute();
+ }
+
+ protected _onTreeEditToggleRequested(event: OrAssetTreeRequestEditToggleEvent) {
+ // Block the request and show dialog then toggle
+ event.detail.allow = false;
+ const editMode = event.detail.detail;
+ const action = () => {
+ this._editMode = editMode;
+ this._updateRoute(false);
+ };
+ this._checkIfModified(action);
+ }
+
+ protected _onTreeEditChanged(event: OrAssetTreeEditChangedEvent) {
+ this._editMode = event.detail;
+ this._updateRoute();
+ }
- if (this._selectedId !== assetId) {
- // Asset requested in route couldn't be selected so navigate to no asset
- router.navigate("assets/");
- this._assetId = undefined;
+ protected _checkIfModified(action: () => void) {
+ if (this._viewer.isModified()) {
+ showDialog(
+ {
+ content: html`<p>${i18next.t("confirmContinueAssetModified")}</p>`,
+ actions: [
+ {
+ actionName: "ok",
+ content: "ok",
+ action: action
+ },
+ {
+ actionName: "cancel",
+ content: "cancel",
+ default: true
+ }
+ ],
+ title: "assetModified"
+ }
+ )
} else {
- // Requested asset has been selected in the asset tree
- this._assetId = assetId;
+ action();
+ }
+ }
+
+ protected _updateRoute(silent: boolean = true) {
+ if (silent) {
+ router.pause();
+ }
+ const assetId = this._assetId ? "/" + this._assetId : "";
+ const editMode = !!this._editMode;
+ router.navigate("assets/" + editMode + assetId);
+ if (silent) {
+ router.resume();
}
}
}
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index e30ec1f3c..4c49959c5 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -8,12 +8,14 @@ import {style} from "./style";
import manager, {AssetModelUtil, Util, OREvent, EventCallback, subscribe} from "@openremote/core";
import {InputType, OrInputChangedEvent} from "@openremote/or-input";
import Qs from "qs";
-import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";
+import {getAssetDescriptorIconTemplate, OrIcon} from "@openremote/or-icon";
import "@openremote/or-mwc-components/dist/or-mwc-menu";
import {getContentWithMenuTemplate, MenuItem, OrMwcMenuChangedEvent} from "@openremote/or-mwc-components/dist/or-mwc-menu";
-import {i18next} from "@openremote/or-translate";
-import {DialogAction, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
-
+import "@openremote/or-mwc-components/dist/or-mwc-list";
+import {ListItem, OrMwcListChangedEvent} from "@openremote/or-mwc-components/dist/or-mwc-list";
+import {i18next, OrTranslate} from "@openremote/or-translate";
+import "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import {DialogAction, OrMwcDialog, showDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
export interface AssetTreeTypeConfig {
include?: string[];
@@ -22,10 +24,9 @@ export interface AssetTreeTypeConfig {
export interface AssetTreeConfig {
default?: AssetTreeTypeConfig;
- addAssetTypes?: { [assetType: string]: AssetTreeTypeConfig };
+ addAssetTypes?: AssetTreeTypeConfig;
}
-
export interface UiAssetTreeNode extends AssetTreeNode {
selected: boolean;
expandable: boolean;
@@ -62,17 +63,46 @@ export class OrAssetTreeRequestSelectEvent extends CustomEvent<RequestEventDetai
}
}
-export class OrAssetTreeRequestAddEvent extends CustomEvent<RequestEventDetail<void>> {
+export class OrAssetTreeRequestEditToggleEvent extends CustomEvent<RequestEventDetail<boolean>> {
+
+ public static readonly NAME = "or-asset-tree-request-edit-toggle";
+
+ constructor(edit: boolean) {
+ super(OrAssetTreeRequestEditToggleEvent.NAME, {
+ bubbles: true,
+ composed: true,
+ detail: {
+ allow: true,
+ detail: edit
+ }
+ });
+ }
+}
+
+export class OrAssetTreeEditChangedEvent extends CustomEvent<boolean> {
+
+ public static readonly NAME = "or-asset-tree-edit-changed";
+
+ constructor(edit: boolean) {
+ super(OrAssetTreeEditChangedEvent.NAME, {
+ bubbles: true,
+ composed: true,
+ detail: edit
+ });
+ }
+}
+
+export class OrAssetTreeRequestAddEvent extends CustomEvent<RequestEventDetail<Asset>> {
public static readonly NAME = "or-asset-tree-request-add";
- constructor() {
+ constructor(asset: Asset) {
super(OrAssetTreeRequestAddEvent.NAME, {
bubbles: true,
composed: true,
detail: {
allow: true,
- detail: undefined
+ detail: asset
}
});
}
@@ -130,6 +160,8 @@ declare global {
[OrAssetTreeRequestDeleteEvent.NAME]: OrAssetTreeRequestDeleteEvent;
[OrAssetTreeRequestCopyEvent.NAME]: OrAssetTreeRequestCopyEvent;
[OrAssetTreeSelectionChangedEvent.NAME]: OrAssetTreeSelectionChangedEvent;
+ [OrAssetTreeRequestEditToggleEvent.NAME]: OrAssetTreeRequestEditToggleEvent;
+ [OrAssetTreeEditChangedEvent.NAME]: OrAssetTreeEditChangedEvent;
}
}
@@ -152,52 +184,6 @@ export const getAssetTypes = async () => {
}
}
-function getActionTypesMenu(config?: AssetTreeConfig, selectedNodes?:UiAssetTreeNode[]): MenuItem[] {
- let assetDescriptors:AssetDescriptor[] = AssetModelUtil.getAssetDescriptors()
-
- if(config && config.addAssetTypes && selectedNodes && selectedNodes.length > 0) {
- const type = selectedNodes[0].asset && selectedNodes[0].asset.type ? selectedNodes[0].asset.type : ""
- const assetTypeConfig = config && config.addAssetTypes[type];
- const includedAssetTypes = assetTypeConfig && assetTypeConfig.include ? assetTypeConfig.include : undefined;
- const excludedAssetTypes = assetTypeConfig && assetTypeConfig.exclude ? assetTypeConfig.exclude : [];
- assetDescriptors = assetDescriptors.filter((assetDescriptor) =>
- (!includedAssetTypes || includedAssetTypes.indexOf(assetDescriptor.type!) >= 0)
- && (!excludedAssetTypes || excludedAssetTypes.indexOf(assetDescriptor.type!) < 0));
- }
-
- const menu: MenuItem[] = [];
-
- if (assetDescriptors) {
- menu.push(...assetDescriptors.map((ad) => {
- return getAssetTypeOption(ad)
- }));
- }
-
- return menu;
-}
-
-function getAssetTypeOption(assetDescriptor?: AssetDescriptor) {
- const color = AssetModelUtil.getAssetDescriptorColor(assetDescriptor);
- const icon = AssetModelUtil.getAssetDescriptorIcon(assetDescriptor);
- const styleMap = color ? {"--or-icon-fill": "#" + color} : undefined;
-
- if(assetDescriptor && assetDescriptor.name && assetDescriptor.type) {
- return {
- text: i18next.t(assetDescriptor.name, {defaultValue: assetDescriptor.name!.replace(/_/g, " ").toLowerCase()}),
- value: assetDescriptor.type,
- icon: icon ? icon : AssetType.THING.icon,
- styleMap: styleMap
- };
- } else {
- return{
- text: "",
- value: "",
- icon: icon ? icon : AssetType.THING.icon,
- styleMap: styleMap
- };
- }
-
-}
// TODO: Add websocket support
// TODO: Make modal a standalone component
@customElement("or-asset-tree")
@@ -224,9 +210,6 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
@property({type: Array})
public _assetTypeOptions?: string[];
- @property({type: Object})
- public _selectedAssetTypeOption?: AssetDescriptor;
-
@property({type: Array})
public rootAssets?: Asset[];
@@ -242,6 +225,9 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
@property({type: Boolean})
public multiSelect?: boolean = true;
+ @property({type: Boolean})
+ public editMode?: boolean = false;
+
@property({type: Function, noAccessor: true, attribute: false})
public selector?: (node: UiAssetTreeNode) => boolean;
@@ -293,45 +279,9 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
}
}
- protected renderDialogHTML() {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("mdc-dialog") as OrMwcDialog;
- if(!this.shadowRoot) return
-
- const form:HTMLElement|null = this.shadowRoot.getElementById('mdc-dialog-form-add');
- if (dialog && form) {
- dialog.dialogContent = html`${form}`;
- this.requestUpdate();
- }
- }
-
protected render() {
- const dialogActions: DialogAction[] = [
- {
- actionName: "cancel",
- content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,
- action: () => {
- // Nothing to do here
- }
- },
- {
- actionName: "yes",
- default: true,
- content: html`<or-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("add")}" data-mdc-dialog-action="yes"></or-input>`,
- action: () => {
- // TODO change this to open edit page
- if(!this.shadowRoot) return
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("mdc-dialog") as OrMwcDialog;
- if(!dialog.shadowRoot) return
- if(this._selectedAssetTypeOption){
- const type = this._selectedAssetTypeOption.type;
- this._doRequest(new OrAssetTreeRequestAddEvent(), () => this._doAdd("New Asset", type));
- }
+ const editMode = this.editMode;
- }
- }
- ];
- const selectedAssetTypeOption = getAssetTypeOption(this._selectedAssetTypeOption)
- const hasAssetWriteRole = manager.hasRole("write:assets");
return html`
<div id="header">
<div id="title-container">
@@ -339,9 +289,10 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
</div>
<div id="header-btns">
- <or-input style="display: none;" ?hidden="${this._isReadonly() || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="content-copy" @click="${() => this._onCopyClicked()}"></or-input>
- <or-input ?hidden="${this._isReadonly() || !hasAssetWriteRole || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="delete" @click="${() => this._onDeleteClicked()}"></or-input>
- <or-input ?hidden="${this._isReadonly() || !hasAssetWriteRole || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="plus" @click="${() => this._onAddClicked()}"></or-input>
+ <or-input style="display: none;" ?hidden="${this._isReadonly() || !editMode || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="content-copy" @click="${() => this._onCopyClicked()}"></or-input>
+ <or-input ?hidden="${this._isReadonly() || !editMode || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="delete" @click="${() => this._onDeleteClicked()}"></or-input>
+ <or-input ?hidden="${this._isReadonly() || !editMode || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="plus" @click="${() => this._onAddClicked()}"></or-input>
+ <or-input ?hidden="${this._isReadonly()}" type="${InputType.BUTTON_TOGGLE}" icon="eye" .value="${this.editMode}" iconOn="pencil" @or-input-changed="${(ev: OrInputChangedEvent) => this._onEditToggled(ev.detail.value)}"></or-input>
<or-input hidden type="${InputType.BUTTON}" icon="magnify" @click="${() => this._onSearchClicked()}"></or-input>
${getContentWithMenuTemplate(
@@ -367,21 +318,6 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
<div id="footer">
</div>
-
-
- <or-mwc-dialog id="mdc-dialog" dialogTitle="addAsset" .dialogActions="${dialogActions}"></or-mwc-dialog>
- <form id="mdc-dialog-form-add" style="display: flex; flex-direction: horizontal; height:400px; border-top: 1px solid var(--or-app-color2);">
- <div style="overflow-y: scroll;">
- <or-mwc-menu visible noSurface @or-mwc-menu-changed="${(evt: OrMwcMenuChangedEvent) => {this._selectedAssetTypeOption = typeof evt.detail === "string" ? AssetModelUtil.getAssetDescriptor(evt.detail) : undefined}} }" .menuItems="${getActionTypesMenu(this.config, this._selectedNodes)}" .values="${this._selectedAssetTypeOption}" id="menu"></or-mwc-menu>
- </div>
- <div class="asset-type-option-container" style="background-color: var(--or-app-color2); padding: 15px; width: 260px; max-width: 100%; ${selectedAssetTypeOption.styleMap ? styleMap(selectedAssetTypeOption.styleMap) : ""}">
- ${this._selectedAssetTypeOption ? html`
- <or-icon icon="${selectedAssetTypeOption.icon}"></or-icon>
- <span style="font-size: 16px;"><or-translate value="${selectedAssetTypeOption.text}"></or-translate></span>
- ` : ``}
- </div>
-
- </form>
`;
}
@@ -389,11 +325,11 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
return this.readonly || !manager.hasRole(ClientRole.WRITE_ASSETS);
}
- protected firstUpdated(_changedProperties: PropertyValues){
- this.renderDialogHTML();
- }
-
protected shouldUpdate(_changedProperties: PropertyValues): boolean {
+ if (this.editMode && this._isReadonly()) {
+ this.editMode = false;
+ }
+
const result = super.shouldUpdate(_changedProperties);
if (_changedProperties.has("_assetIdsOverride")
|| _changedProperties.has("assets")
@@ -497,9 +433,108 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
}
protected _onAddClicked() {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("mdc-dialog") as OrMwcDialog;
- console.log(dialog)
- dialog.open();
+
+ const includedAssetTypes = this.config && this.config.addAssetTypes && this.config.addAssetTypes.include ? this.config.addAssetTypes.include : undefined;
+ const excludedAssetTypes = this.config && this.config.addAssetTypes && this.config.addAssetTypes.exclude ? this.config.addAssetTypes.exclude : [];
+
+ const listItems: ListItem[] = AssetModelUtil.getAssetDescriptors()
+ .filter((descriptor) => (!includedAssetTypes || includedAssetTypes.indexOf(descriptor.type!) >= 0)
+ && (excludedAssetTypes.indexOf(descriptor.type!) < 0))
+ .sort(Util.sortByString((descriptor) => descriptor.name!))
+ .map((descriptor) => {
+ return {
+ styleMap: {
+ "--or-icon-fill": descriptor.color ? "#" + descriptor.color : "unset"
+ },
+ icon: descriptor.icon,
+ text: i18next.t(descriptor.name!, {defaultValue: descriptor.name!.replace(/_/g, " ").toLowerCase()}),
+ value: descriptor.type!,
+ data: descriptor
+ }
+ });
+
+ let descriptor: AssetDescriptor;
+
+ const onAssetTypeChanged = (listItem: ListItem) => {
+ descriptor = listItem.data as AssetDescriptor;
+ const icon = dialog.shadowRoot!.getElementById("type-icon") as OrIcon;
+ const description = dialog.shadowRoot!.getElementById("type-description") as OrTranslate;
+ icon.icon = descriptor.icon;
+ description.value = listItem.text;
+ };
+
+ const dialog = showDialog(
+ {
+ title: "addAsset",
+ content: html`
+ <form id="mdc-dialog-form-add">
+ <div id="type-list">
+ <or-mwc-list @or-mwc-list-changed="${(evt: OrMwcListChangedEvent) => onAssetTypeChanged(evt.detail[0] as ListItem)}" .listItems="${listItems}" id="menu"></or-mwc-list>
+ </div>
+ <div id="asset-type-option-container">
+ <or-icon id="type-icon" class="hidden"></or-icon>
+ <or-translate id="type-description" class="hidden"></or-translate>
+ </div>
+ </form>`,
+ actions: [
+ {
+ actionName: "cancel",
+ content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`
+ },
+ {
+ actionName: "yes",
+ default: true,
+ content: html`<or-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("add")}" data-mdc-dialog-action="yes"></or-input>`,
+ action: () => {
+ // TODO change this to open edit page
+ if (!descriptor) {
+ return;
+ }
+
+ const asset: Asset = {
+ name: "New Asset",
+ type: descriptor.type,
+ realm: manager.getRealm()
+ };
+ if(this.selectedIds) {
+ asset['parentId'] = this.selectedIds[0];
+ }
+ this._doRequest(new OrAssetTreeRequestAddEvent(asset), () => this._doAdd(asset));
+ }
+ }
+ ],
+ styles: html`
+ <style>
+ #mdc-dialog-form-add {
+ display: flex;
+ height:400px;
+ border-top: 1px solid var(--or-app-color2);
+ }
+ #asset-type-option-container {
+ background-color: var(--or-app-color2);
+ padding: 15px;
+ width: 260px;
+ max-width: 100%;
+ font-size: 16px;
+ }
+ #type-list {
+ overflow-y: scroll;
+ }
+ .hidden {
+ visibility: hidden;
+ }
+ </style>
+ `
+ }
+ )
+ }
+
+ protected _onEditToggled(edit: boolean) {
+ this._doRequest(new OrAssetTreeRequestEditToggleEvent(edit), () => this._doEditToggle(edit));
+ }
+
+ protected _doEditToggle(edit: boolean) {
+ this.editMode = edit;
}
protected _onSearchClicked() {
@@ -585,15 +620,8 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
return window.confirm(i18next.t("confirmDeleteAssets"));
}
- protected _doAdd(name:string, type:string | undefined) {
- const _asset: Asset = {
- name: name,
- type: type,
- realm: manager.getRealm()
- };
- if(this.selectedIds) _asset['parentId'] = this.selectedIds[0];
-
- manager.rest.api.AssetResource.create(_asset).then((response) => {
+ protected _doAdd(asset: Asset) {
+ manager.rest.api.AssetResource.create(asset).then((response) => {
this._loadAssets();
});
}
diff --git a/ui/component/or-asset-viewer/package.json b/ui/component/or-asset-viewer/package.json
index f59be4b10..89f2f4310 100644
--- a/ui/component/or-asset-viewer/package.json
+++ b/ui/component/or-asset-viewer/package.json
@@ -26,7 +26,8 @@
"@openremote/or-chart": "^1.1.0",
"@openremote/rest": "^1.1.0",
"@openremote/or-mwc-components": "^1.1.0",
- "lit-element": "^2.2.1"
+ "lit-element": "^2.2.1",
+ "@material/data-table": "^5.1.0"
},
"devDependencies": {
"tslint": ">=5.11.0",
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 7fa0e687f..b7a76c493 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -1,4 +1,7 @@
-import {customElement, html, LitElement, property, PropertyValues, TemplateResult} from "lit-element";
+// Declare require method which we'll use for importing webpack resources (using ES6 imports will confuse typescript parser)
+declare function require(name: string): any;
+
+import {customElement, html, LitElement, property, PropertyValues, TemplateResult, unsafeCSS} from "lit-element";
import "@openremote/or-icon";
import "@openremote/or-input";
import "@openremote/or-attribute-input";
@@ -9,9 +12,11 @@ import "@openremote/or-survey-results";
import "@openremote/or-table";
import "@openremote/or-panel";
import "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import {DialogAction, OrMwcDialog, showDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import "@openremote/or-mwc-components/dist/or-mwc-list";
import {OrTranslate, translate} from "@openremote/or-translate";
-import {InputType, OrInputChangedEvent, OrInput} from "@openremote/or-input";
-import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";
+import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";
+import manager, {AssetModelUtil, DefaultColor5, subscribe, Util} from "@openremote/core";
import {OrTable} from "@openremote/or-table";
import {OrChartConfig, OrChartEvent} from "@openremote/or-chart";
import {HistoryConfig, OrAttributeHistory, OrAttributeHistoryEvent} from "@openremote/or-attribute-history";
@@ -22,54 +27,88 @@ import {
AssetType,
Attribute,
AttributeEvent,
- AttributeType,
+ MetaItem,
MetaItemType,
- SharedEvent
+ SharedEvent,
+ ValueType,
+ AttributeDescriptor,
+ ClientRole
} from "@openremote/model";
-import {style} from "./style";
+import {panelStyles, style} from "./style";
import i18next from "i18next";
import {styleMap} from "lit-html/directives/style-map";
import {classMap} from "lit-html/directives/class-map";
-import {DialogAction, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
-import { GenericAxiosResponse } from "axios";
-import { OrIcon } from "@openremote/or-icon";
-
-export type PanelType = "property" | "attribute" | "history" | "group" | "survey" | "survey-results";
+import {GenericAxiosResponse} from "axios";
+import {OrIcon} from "@openremote/or-icon";
+import {OrAssetTree, UiAssetTreeNode} from "@openremote/or-asset-tree";
+import "./or-edit-asset-panel";
+import { OrEditAssetChangedEvent } from "./or-edit-asset-panel";
export interface PanelConfig {
- type?: PanelType;
+ type?: "info" | "history" | "group" | "survey" | "survey-results";
title?: string;
hide?: boolean;
hideOnMobile?: boolean;
- defaults?: string[];
+ panelStyles?: { [style: string]: string };
+}
+
+export interface InfoPanelItemConfig {
+ label?: string;
+ hideOnMobile?: boolean;
+ readonly?: boolean;
+ disabled?: boolean;
+ disableButton?: boolean;
+ disableHelperText?: boolean;
+ inputTypeOverride?: InputType;
+ priority?: number;
+ styles?: { [style: string]: string };
+}
+
+export interface InfoPanelConfig extends PanelConfig {
+ type: "info",
+ attributes: {
+ include?: string[];
+ exclude?: string[];
+ itemConfig?: {
+ [name: string]: InfoPanelItemConfig;
+ };
+ },
+ properties: {
+ include?: string[];
+ exclude?: string[];
+ itemConfig?: {
+ [name: string]: InfoPanelItemConfig;
+ };
+ }
+}
+
+export interface HistoryPanelConfig extends PanelConfig {
+ type: "history",
include?: string[];
exclude?: string[];
- readonly?: string[];
- panelStyles?: { [style: string]: string };
- fieldStyles?: { [field: string]: { [style: string]: string } };
- itemConfig?: {[name: string]: {
- readonly?: boolean;
- disabled?: boolean;
- label?: string;
- disableButton?: boolean;
- disableHelperText?: boolean;
- inputTypeOverride?: InputType;
- }};
}
export interface GroupPanelConfig extends PanelConfig {
- childAssetTypes?: { [assetType: string]: {
- availableAttributes?: string[];
- selectedAttributes?: string[];
- }};
+ type: "group",
+ childAssetTypes?: {
+ [assetType: string]: {
+ availableAttributes?: string[];
+ selectedAttributes?: string[];
+ }
+ };
}
+export type PanelConfigUnion = InfoPanelConfig | GroupPanelConfig | PanelConfig;
+export type PanelViewProvider = (asset: Asset, attributes: Attribute[], panelName: string, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfigUnion) => TemplateResult | undefined;
+export type PropertyViewProvider = (asset: Asset, property: string, value: any, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfigUnion) => TemplateResult | undefined;
+export type AttributeViewProvider = (asset: Asset, attribute: Attribute, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfigUnion) => TemplateResult | undefined;
+
export interface AssetViewerConfig {
- panels?: {[name: string]: PanelConfig};
+ panels?: {[name: string]: PanelConfigUnion};
viewerStyles?: { [style: string]: string };
- propertyViewProvider?: (asset: Asset, property: string, value: any, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
- attributeViewProvider?: (asset: Asset, attribute: Attribute, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
- panelViewProvider?: (asset: Asset, attributes: Attribute[], panelName: string, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
+ propertyViewProvider?: PropertyViewProvider;
+ attributeViewProvider?: AttributeViewProvider;
+ panelViewProvider?: PanelViewProvider;
historyConfig?: HistoryConfig;
chartConfig?: OrChartConfig;
}
@@ -80,6 +119,29 @@ export interface ViewerConfig {
historyConfig?: HistoryConfig;
}
+export const DEFAULT_ASSET_PROPERTIES = [
+ "name",
+ "createdOn",
+ "type",
+ "parentId",
+ "accessPublicRead"
+];
+
+export function getIncludedProperties(config?: InfoPanelConfig): string[] {
+ const includedProperties = config && config.properties && config.properties.include ? config.properties.include : DEFAULT_ASSET_PROPERTIES;
+ const excludedProperties = config && config.properties && config.properties.exclude ? config.properties.exclude : [];
+
+ return includedProperties.filter((prop) => !excludedProperties || excludedProperties.indexOf(prop) < 0);
+}
+
+export function getIncludedAttributes(attributes: Attribute[], config?: InfoPanelConfig): Attribute[] {
+ const includedAttributes = config && config.attributes && config.attributes.include ? config.attributes.include : undefined;
+ const excludedAttributes = config && config.attributes && config.attributes.exclude ? config.attributes.exclude : [];
+ return attributes.filter((attr) =>
+ (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)
+ && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0));
+}
+
class EventHandler {
_callbacks: Function[];
@@ -116,7 +178,7 @@ export class OrComputeGridEvent extends CustomEvent<void> {
const onRenderComplete = new EventHandler();
-function getPanel(name: string, panelConfig: PanelConfig, content: TemplateResult | undefined) {
+export function getPanel(name: string, panelConfig: PanelConfig, content: TemplateResult | undefined) {
if (!content) {
return;
@@ -136,11 +198,9 @@ function getPanel(name: string, panelConfig: PanelConfig, content: TemplateResul
`;
}
-export function getPanelContent(panelName: string, asset: Asset, attributes: AssetAttribute[], hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig): TemplateResult | undefined {
- if (panelConfig.hide || attributes.length === 0) {
- return;
- }
+export function getPanelContent(panelName: string, asset: Asset, attributes: Attribute[], hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig): TemplateResult | undefined {
+ // See if config has a custom way for rendering this panel
if (viewerConfig.panelViewProvider) {
const template = viewerConfig.panelViewProvider(asset, attributes, panelName, hostElement, viewerConfig, panelConfig);
if (template) {
@@ -148,111 +208,164 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
}
}
- const styles = panelConfig ? panelConfig.fieldStyles : undefined;
- const defaultAttributes = panelConfig && panelConfig.defaults ? panelConfig.defaults : undefined;
- const includedAttributes = panelConfig && panelConfig.include ? panelConfig.include : undefined;
- const excludedAttributes = panelConfig && panelConfig.exclude ? panelConfig.exclude : [];
- const attrs = attributes.filter((attr) =>
- (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)
- && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0));
-
- let content: TemplateResult | undefined;
+ if (panelConfig.type === "info") {
- if (panelConfig && panelConfig.type === "property") {
- // Special handling for info panel which only shows properties
- const properties = OrAssetViewer.getInfoProperties(panelConfig);
+ // This type of panel shows attributes and/or properties of the asset
+ const infoConfig = panelConfig as InfoPanelConfig;
+ const includedProperties = getIncludedProperties(infoConfig);
+ const includedAttributes = getIncludedAttributes(attributes, infoConfig);
- if (properties.length === 0) {
- return;
+ if (includedProperties.length === 0 && includedAttributes.length === 0) {
+ return undefined;
}
- content = html`
- ${properties.map((prop) => {
- const style = styles ? styles[prop!] : undefined;
- return prop === "attributes" ? `` : getField(prop, true, style, getPropertyTemplate(asset, prop, hostElement, viewerConfig, panelConfig));
- })}
- `;
- } else if (panelConfig && panelConfig.type === "survey") {
- content = html`
- <or-survey id="survey" .surveyId="${asset.id}"></or-survey>
+ const items: {item: string | Attribute, itemConfig: InfoPanelItemConfig}[] = [];
+
+ includedProperties.forEach((prop) => {
+ const itemConfig = infoConfig.properties && infoConfig.properties.itemConfig ? infoConfig.properties.itemConfig[prop] : {};
+ if (itemConfig.label === undefined) {
+ itemConfig.label = i18next.t(prop);
+ }
+ itemConfig.priority = itemConfig.priority || 0;
+ items.push({
+ item: prop,
+ itemConfig: itemConfig
+ });
+ });
+
+ includedAttributes.forEach((attribute) => {
+ const itemConfig = infoConfig.attributes && infoConfig.attributes.itemConfig && infoConfig.attributes.itemConfig[attribute.name!] ? infoConfig.attributes.itemConfig[attribute.name!] : {};
+ if (itemConfig.label === undefined) {
+ const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset.type!, attribute);
+ itemConfig.label = Util.getAttributeLabel(attribute, descriptors[0], descriptors[1], true);
+ }
+ itemConfig.priority = itemConfig.priority || 0;
+ items.push({
+ item: attribute,
+ itemConfig: itemConfig
+ });
+ });
+
+ const labelSort = Util.sortByString((item: {item: string | Attribute, itemConfig: InfoPanelItemConfig}) => item.itemConfig.label!.toUpperCase());
+
+ items.sort((a, b) => {
+ const priorityA = a.itemConfig.priority!;
+ const priorityB = b.itemConfig.priority!;
+
+ if (priorityA < priorityB) {
+ return 1;
+ }
+
+ if (priorityA > priorityB) {
+ return -1;
+ }
+
+ return labelSort(a,b);
+ });
+
+ return html`
+ ${items.map((item) => {
+ if (typeof item.item === "string") {
+ // This is a property
+ return getField(item.item, item.itemConfig, getPropertyTemplate(asset, item.item, hostElement, viewerConfig, panelConfig, item.itemConfig));
+ } else {
+ // This is an attribute
+ return getField(item.item.name!, item.itemConfig, getAttributeTemplate(asset, item.item, hostElement, viewerConfig, panelConfig, item.itemConfig));
+ }
+ })}`;
+ }
+
+ if (panelConfig && panelConfig.type === "survey") {
+ return html`
+ <or-survey id="survey" .surveyId="${asset.id}"></or-survey>
`;
}
- else if (panelConfig && panelConfig.type === "survey-results") {
- content = html`
- <or-survey-results id="survey-results" .survey="${asset}"></or-survey-results>
+
+ if (panelConfig && panelConfig.type === "survey-results") {
+ return html`
+ <or-survey-results id="survey-results" .survey="${asset}"></or-survey-results>
`;
}
- else if (panelConfig && panelConfig.type === "history") {
- // Special handling for history panel which shows an attribute selector and a graph/data table of historical values
- const historyAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!));
- if (historyAttrs.length > 0) {
- const attributeChanged = (attributeName: string) => {
- if (hostElement.shadowRoot) {
- const attributeHistory = hostElement.shadowRoot.getElementById("attribute-history") as OrAttributeHistory;
+ if (panelConfig && panelConfig.type === "history") {
+ // Special handling for history panel which shows an attribute selector and a graph/data table of historical values
+ const historyConfig = panelConfig as HistoryPanelConfig;
+ const includedAttributes = historyConfig.include ? historyConfig.include : undefined;
+ const excludedAttributes = historyConfig.exclude ? historyConfig.exclude : [];
+ const historyAttrs = attributes.filter((attr) =>
+ (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)
+ && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0)
+ && !!Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!));
+
+ if (historyAttrs.length === 0) {
+ return undefined;
+ }
- if (attributeHistory) {
+ const attributeChanged = (attributeName: string) => {
+ if (hostElement.shadowRoot) {
+ const attributeHistory = hostElement.shadowRoot.getElementById("attribute-history") as OrAttributeHistory;
- let attribute: AssetAttribute | undefined;
+ if (attributeHistory) {
- if (attributeName) {
- attribute = Util.getAssetAttribute(asset, attributeName);
- }
+ let attribute: AssetAttribute | undefined;
- attributeHistory.attribute = attribute;
+ if (attributeName) {
+ attribute = Util.getAssetAttribute(asset, attributeName);
}
- }
- };
- const options = historyAttrs.map((attr) => {
- const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset.type, attr);
- const label = Util.getAttributeLabel(attr, descriptors[0], descriptors[1], true);
- return [attr.name, label];
- });
- const attrName: string = historyAttrs[0].name!;
- onRenderComplete.addCallback(() => attributeChanged(attrName));
- content = html`
- <style>
- or-attribute-history{
- min-height: 70px;
- width: 100%;
- }
- #history-controls {
- flex: 0;
- margin-bottom: 10px;
- position: absolute;
- }
-
- #history-attribute-picker {
- flex: 0;
- width: 200px;
- }
-
- or-attribute-history {
- --or-attribute-history-controls-margin: 0 0 20px 204px;
- }
-
- @media screen and (max-width: 2028px) {
- #history-controls {
- position: unset;
- margin: 0 0 10px 0;
- }
-
- or-attribute-history {
- --or-attribute-history-controls-margin: 10px 0 0 0;
- --or-attribute-history-controls-margin-children: 0 20px 20px 0;
- }
- }
- </style>
- <div id="history-controls">
- <or-input id="history-attribute-picker" .checkAssetWrite="${false}" .value="${historyAttrs[0].name}" .label="${i18next.t("attribute")}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeChanged(evt.detail.value)}" .type="${InputType.SELECT}" .options="${options}"></or-input>
- </div>
- <or-attribute-history id="attribute-history" .config="${viewerConfig.historyConfig}" .assetType="${asset.type}"></or-attribute-history>
+ attributeHistory.attribute = attribute;
+ }
+ }
+ };
- `;
- }
+ const options = historyAttrs.map((attr) => {
+ const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset.type, attr);
+ const label = Util.getAttributeLabel(attr, descriptors[0], descriptors[1], true);
+ return [attr.name, label];
+ });
+ const attrName: string = historyAttrs[0].name!;
+ onRenderComplete.addCallback(() => attributeChanged(attrName));
+ return html`
+ <style>
+ or-attribute-history{
+ min-height: 70px;
+ width: 100%;
+ }
+ #history-controls {
+ flex: 0;
+ margin-bottom: 10px;
+ position: absolute;
+ }
+
+ #history-attribute-picker {
+ flex: 0;
+ width: 200px;
+ }
+
+ or-attribute-history {
+ --or-attribute-history-controls-margin: 0 0 20px 204px;
+ }
+
+ @media screen and (max-width: 2028px) {
+ #history-controls {
+ position: unset;
+ margin: 0 0 10px 0;
+ }
+
+ or-attribute-history {
+ --or-attribute-history-controls-margin: 10px 0 0 0;
+ --or-attribute-history-controls-margin-children: 0 20px 20px 0;
+ }
+ }
+ </style>
+ <div id="history-controls">
+ <or-input id="history-attribute-picker" .checkAssetWrite="${false}" .value="${historyAttrs[0].name}" .label="${i18next.t("attribute")}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeChanged(evt.detail.value)}" .type="${InputType.SELECT}" .options="${options}"></or-input>
+ </div>
+ <or-attribute-history id="attribute-history" .config="${viewerConfig.historyConfig}" .assetType="${asset.type}"></or-attribute-history>
+ `;
+ }
- } else if (panelConfig && panelConfig.type === "group") {
+ if (panelConfig && panelConfig.type === "group") {
if (asset.type !== "urn:openremote:asset:group") {
return;
@@ -377,7 +490,7 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
});
// Define the DOM content for this panel
- content = html`
+ return html`
<style>
.asset-group-add-remove-button {
position: absolute;
@@ -395,22 +508,12 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
<span><or-translate id="${panelName}-attribute-table-msg" value="loading"></or-translate></span>
<or-mwc-dialog id="${panelName}-attribute-modal" dialogTitle="addRemoveAttributes" .dialogActions="${attributePickerModalActions}"></or-mwc-dialog>
`;
- } else {
- if (attrs.length === 0) {
- return undefined;
- }
-
- content = html`
- ${attrs.sort((attr1, attr2) => attr1.name! < attr2.name! ? -1 : attr1.name! > attr2.name! ? 1 : 0).map((attr) => {
- const attrStyle = styles ? styles[attr.name!] : undefined;
- return getField(attr.name!, false, attrStyle, getAttributeTemplate(asset, attr, hostElement, viewerConfig, panelConfig));
- })}`;
}
- return content;
+ return undefined;
}
-export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {
+export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, itemConfig: InfoPanelItemConfig) {
if (viewerConfig.attributeViewProvider) {
const result = viewerConfig.attributeViewProvider(asset, attribute, hostElement, viewerConfig, panelConfig);
if (result) {
@@ -425,15 +528,13 @@ export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, ho
let attrInputType: InputType | undefined;
let attrDisableHelper: boolean | undefined;
-
- if (panelConfig.itemConfig && panelConfig.itemConfig[attribute.name!]) {
- const attrConfig = panelConfig.itemConfig[attribute.name!];
- attrLabel = attrConfig.label;
- attrDisabled = attrConfig.disabled;
- attrReadonly = attrConfig.readonly;
- attrDisableButton = attrConfig.disableButton;
- attrDisableHelper = attrConfig.disableHelperText;
- attrInputType = attrConfig.inputTypeOverride;
+ if (itemConfig) {
+ attrLabel = itemConfig.label;
+ attrDisabled = itemConfig.disabled;
+ attrReadonly = itemConfig.readonly;
+ attrDisableButton = itemConfig.disableButton;
+ attrDisableHelper = itemConfig.disableHelperText;
+ attrInputType = itemConfig.inputTypeOverride;
}
return html`
@@ -441,10 +542,10 @@ export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, ho
`;
}
-export function getPropertyTemplate(asset: Asset, property: string, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {
+export function getPropertyTemplate(asset: Asset, property: string, hostElement: LitElement, viewerConfig: AssetViewerConfig | undefined, panelConfig: PanelConfig | undefined, itemConfig: InfoPanelItemConfig) {
let value = (asset as { [index: string]: any })[property];
- if (viewerConfig.propertyViewProvider) {
+ if (viewerConfig && viewerConfig.propertyViewProvider && panelConfig) {
const result = viewerConfig.propertyViewProvider(asset, property, value, hostElement, viewerConfig, panelConfig);
if (result) {
return result;
@@ -452,27 +553,32 @@ export function getPropertyTemplate(asset: Asset, property: string, hostElement:
}
let type = InputType.TEXT;
- let minLength: number | undefined;
- let maxLength: number | undefined;
switch (property) {
- case "path":
+ case "parentId":
+ // Display the path instead
+ value = (asset as { [index: string]: any })["path"];
if (!value || !(Array.isArray(value))) {
return;
}
// Populate value when we get the response
- getAssetNames(value as string[]).then(
- (names) => {
- if (hostElement && hostElement.shadowRoot) {
- const pathField = hostElement.shadowRoot.getElementById("property-path") as OrInput;
- if (pathField) {
- pathField.value = names.reverse().join(" > ");
+ const ancestors = [...value];
+ ancestors.splice(0,1);
+ value = "";
+ if (ancestors.length > 0) {
+ getAssetNames(ancestors).then(
+ (names) => {
+ if (hostElement && hostElement.shadowRoot) {
+ const pathField = hostElement.shadowRoot.getElementById("property-parentId") as OrInput;
+ if (pathField) {
+ pathField.value = names.reverse().join(" > ");
+ }
}
}
- }
- );
- value = i18next.t("loading");
+ );
+ value = i18next.t("loading");
+ }
break;
case "createdOn":
type = InputType.DATETIME;
@@ -480,21 +586,18 @@ export function getPropertyTemplate(asset: Asset, property: string, hostElement:
case "accessPublicRead":
type = InputType.CHECKBOX;
break;
- case "name":
- minLength = 1;
- maxLength = 1023;
- break;
}
- return html`<or-input id="property-${property}" type="${type}" .minLength="${minLength}" .maxLength="${maxLength}" dense .value="${value}" readonly label="${i18next.t(property)}"></or-input>`;
+ return html`<or-input id="property-${property}" .type="${type}" dense .value="${value}" .readonly="${itemConfig.readonly !== undefined ? itemConfig.readonly : true}" .label="${itemConfig.label}"></or-input>`;
}
-export function getField(name: string, isProperty: boolean, styles: { [style: string]: string } | undefined, content: TemplateResult | undefined): TemplateResult {
+export function getField(name: string, itemConfig?: InfoPanelItemConfig, content?: TemplateResult): TemplateResult {
if (!content) {
return html``;
}
+
return html`
- <div id="field-${name}" style="${styles ? styleMap(styles) : ""}" class="field ${isProperty ? "field-property" : "field-attribute"}">
+ <div id="field-${name}" style="${itemConfig && itemConfig.styles ? styleMap(itemConfig.styles) : ""}" class=${classMap({field: true, mobileHidden: !!itemConfig && !!itemConfig.hideOnMobile})}>
${content}
</div>
`;
@@ -544,6 +647,9 @@ async function getAssetChildren(id: string, childAssetType: string): Promise<Ass
return response.data.filter((asset) => asset.type === childAssetType);
}
+// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
+const tableStyle = require("!!raw-loader!@material/data-table/dist/mdc.data-table.css");
+
@customElement("or-asset-viewer")
export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElement)) {
@@ -554,70 +660,52 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
panels: {
group: {
type: "group",
- // childAssetTypes: {
- // "urn:openremote:asset:environment": {
- // availableAttributes: ["nO2"],
- // selectedAttributes: ["nO2"]
- // }
- // },
- panelStyles: {}
- } as GroupPanelConfig,
+ title: "underlyingAssets"
+ },
info: {
- type: "attribute",
+ type: "info",
hideOnMobile: true,
- include: ["userNotes", "manufacturer", "model"],
- panelStyles: {
+ properties: {
+ include:[]
},
- fieldStyles: {
- name: {
- width: "60%"
- },
- createdOn: {
- width: "40%",
- paddingLeft: "20px",
- boxSizing: "border-box"
- }
+ attributes: {
+ include: ["userNotes", "manufacturer", "model"]
}
},
location: {
- type: "attribute",
- include: ["location"],
- panelStyles: {
+ type: "info",
+ properties: {
+ include:[]
},
- fieldStyles: {
- location: {
- }
- },
- itemConfig: {
- location: {
- label: "",
- readonly: true
+ attributes: {
+ include: ["location"],
+ itemConfig: {
+ location: {
+ label: "",
+ readonly: true
+ }
}
}
},
attributes: {
- type: "attribute",
- panelStyles: {
+ type: "info",
+ properties: {
+ include:[]
+ },
+ attributes: {
+ exclude: ["location", "userNotes", "manufacturer", "model", "status"]
}
},
history: {
- type: "history",
- panelStyles: {
- }
+ type: "history"
}
}
};
- public static DEFAULT_INFO_PROPERTIES = [
- "name",
- "createdOn",
- "type",
- "path",
- "accessPublicRead"
- ];
-
static get styles() {
return [
+ unsafeCSS(tableStyle),
+ panelStyles,
style
];
}
@@ -631,23 +719,48 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
@property({type: Object})
public config?: ViewerConfig;
+ @property({type: Boolean})
+ public editMode?: boolean;
+
+ @property({type: Boolean})
+ public readonly?: boolean;
+
@property()
protected _loading: boolean = false;
+ protected _assetModified = false;
protected _viewerConfig?: AssetViewerConfig;
- protected _attributes?: AssetAttribute[];
+ protected _attributes?: Attribute[];
+ protected resizeHandler = () => OrAssetViewer.generateGrid(this.shadowRoot);
constructor() {
super();
- window.addEventListener("resize", () => OrAssetViewer.generateGrid(this.shadowRoot));
-
this.addEventListener(OrComputeGridEvent.NAME, () => OrAssetViewer.generateGrid(this.shadowRoot));
this.addEventListener(OrChartEvent.NAME, () => OrAssetViewer.generateGrid(this.shadowRoot));
this.addEventListener(OrAttributeHistoryEvent.NAME, () => OrAssetViewer.generateGrid(this.shadowRoot));
+ this.addEventListener(OrEditAssetChangedEvent.NAME, () => this._onAssetChanged());
+ }
+
+ public isModified() {
+ return this.editMode && this._assetModified;
+ }
+
+ connectedCallback() {
+ super.connectedCallback();
+ window.addEventListener("resize", this.resizeHandler);
+ }
+
+ disconnectedCallback() {
+ super.disconnectedCallback();
+ window.removeEventListener("resize", this.resizeHandler);
}
shouldUpdate(changedProperties: PropertyValues): boolean {
+ if (this._isReadonly()) {
+ this.editMode = false;
+ }
+
if (changedProperties.has("asset")) {
this._viewerConfig = undefined;
this._attributes = undefined;
@@ -655,13 +768,14 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
if (this.asset) {
this._viewerConfig = this._getPanelConfig(this.asset);
this._attributes = Util.getAssetAttributes(this.asset);
+ this._assetModified = false;
}
}
return super.shouldUpdate(changedProperties);
}
- protected render() {
+ protected render(): TemplateResult | string {
if (this._loading) {
return html`
@@ -686,6 +800,26 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
const descriptor = AssetModelUtil.getAssetDescriptor(this.asset!.type!);
+ const editMode = !!this.editMode;
+
+ let content: TemplateResult | string = ``;
+
+ if (editMode) {
+ content = html`
+ <or-edit-asset-panel .asset="${this.asset}" .attrs="${this._attributes}"></or-edit-asset-panel>
+ `;
+ } else {
+ if (this._viewerConfig.panels) {
+ content = html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
+
+ if (panelConfig.hide) {
+ return ``;
+ }
+
+ return getPanel(name, panelConfig, getPanelContent(name, this.asset!, this._attributes!, this, this._viewerConfig!, panelConfig)) || ``;
+ })}`;
+ }
+ }
return html`
<div id="wrapper">
@@ -694,15 +828,14 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
<or-icon icon="chevron-left"></or-icon>
</a>
<div id="title">
- <or-icon title="${descriptor && descriptor.type ? descriptor.type : "unset"}" style="--or-icon-fill: ${descriptor && descriptor.color ? "#" + descriptor.color : "unset"}" icon="${descriptor && descriptor.icon ? descriptor.icon : AssetType.THING.icon}"></or-icon>${this.asset.name}
+ <or-icon title="${descriptor && descriptor.type ? descriptor.type : "unset"}" style="--or-icon-fill: ${descriptor && descriptor.color ? "#" + descriptor.color : "unset"}" icon="${descriptor && descriptor.icon ? descriptor.icon : AssetType.THING.icon}"></or-icon>
+ ${editMode ? html`<or-input id="name-input" .type="${InputType.TEXT}" min="1" max="1023" required outlined .label="${i18next.t("name")}" .value="${this.asset.name}"></or-input>` : html`<span>${this.asset.name}</span>`}
</div>
- <div id="created" class="mobileHidden"><or-translate value="createdOnWithDate" .options="${{ date: new Date(this.asset!.createdOn!) } as i18next.TOptions<i18next.InitOptions>}"></or-translate></div>
+ <div id="created-time" class="mobileHidden"><or-translate value="createdOnWithDate" .options="${{ date: new Date(this.asset!.createdOn!) } as i18next.TOptions<i18next.InitOptions>}"></or-translate></div>
+ ${editMode ? html`<or-input id="save-btn" raised .type="${InputType.BUTTON}" .label="${i18next.t("save")}" @or-input-changed="${() => this._saveAsset()}"></or-input>` : ``}
</div>
<div id="container" style="${this._viewerConfig.viewerStyles ? styleMap(this._viewerConfig.viewerStyles) : ""}">
- ${this._viewerConfig.panels ? html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
- const panelTemplate = getPanel(name, panelConfig, getPanelContent(name, this.asset!, this._attributes!, this, this._viewerConfig!, panelConfig));
- return panelTemplate || ``;
- })}` : ``}
+ ${content}
</div>
</div>
`;
@@ -720,6 +853,12 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
this._loading = false;
super.assetIds = undefined;
}
+ } else if (_changedProperties.has("editMode") && !this.editMode) {
+ this.asset = undefined;
+ if (this.assetId) {
+ this._loading = true;
+ super._refreshEventSubscriptions();
+ }
}
this.onCompleted().then(() => {
@@ -727,13 +866,29 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
OrAssetViewer.generateGrid(this.shadowRoot);
});
});
+ }
+ protected _isReadonly() {
+ return this.readonly || !manager.hasRole(ClientRole.WRITE_ASSETS);
}
async onCompleted() {
await this.updateComplete;
}
+ protected _toggleEdit(edit: boolean) {
+
+ }
+
+ protected _saveAsset() {
+
+ }
+
+ protected _onAssetChanged() {
+ this._assetModified = true;
+ this.requestUpdate();
+ }
+
public static generateGrid(shadowRoot: ShadowRoot | null) {
if (shadowRoot) {
const grid = shadowRoot.querySelector('#container');
@@ -754,26 +909,23 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
}
- public static getInfoProperties(config?: PanelConfig): string[] {
- let properties = config && config.include ? config.include : OrAssetViewer.DEFAULT_INFO_PROPERTIES;
-
- if (config && config.exclude) {
- properties = properties.filter((p) => !config.exclude!.find((excluded) => excluded === p))
- }
-
- return properties;
- }
-
// TODO: Add debounce in here to minimise render calls
_onEvent(event: SharedEvent) {
if (event.eventType === "asset") {
- this.asset = (event as AssetEvent).asset;
+ const asset = (event as AssetEvent).asset!;
+ if (asset.id !== this.assetId) {
+ return;
+ }
+ this.asset = asset;
this._loading = false;
return;
}
if (event.eventType === "attribute") {
const attributeEvent = event as AttributeEvent;
+ if (attributeEvent.attributeState!.attributeRef!.entityId !== this.assetId) {
+ return;
+ }
const attrName = attributeEvent.attributeState!.attributeRef!.attributeName!;
if (this.asset && this.asset.attributes && this.asset.attributes.hasOwnProperty(attrName)) {
@@ -804,10 +956,8 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
Object.entries(assetConfig.panels).forEach(([name, assetPanelConfig]) => {
if (config.panels!.hasOwnProperty(name)) {
const panelStyles = {...config.panels![name].panelStyles};
- const fieldStyles = {...config.panels![name].fieldStyles};
config.panels![name] = Object.assign(config.panels![name], {...assetPanelConfig});
config.panels![name].panelStyles = Object.assign(panelStyles, assetPanelConfig.panelStyles);
- config.panels![name].fieldStyles = Object.assign(fieldStyles, assetPanelConfig.fieldStyles);
} else {
config.panels![name] = {...assetPanelConfig};
}
diff --git a/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts b/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts
new file mode 100644
index 000000000..fbe58bc06
--- /dev/null
+++ b/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts
@@ -0,0 +1,127 @@
+import {customElement, html, LitElement, property, css} from "lit-element";
+import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";
+import i18next from "i18next";
+import {Asset, Attribute, AttributeValueDescriptor} from "@openremote/model";
+import {AssetModelUtil, Util} from "@openremote/core";
+import "@openremote/or-input";
+
+export class OrAddAttributePanelAttributeChangedEvent extends CustomEvent<Attribute> {
+
+ public static readonly NAME = "or-add-attribute-panel-attribute-changed";
+
+ constructor(attribute: Attribute) {
+ super(OrAddAttributePanelAttributeChangedEvent.NAME, {
+ bubbles: true,
+ composed: false,
+ detail: attribute
+ });
+ }
+}
+declare global {
+ export interface HTMLElementEventMap {
+ [OrAddAttributePanelAttributeChangedEvent.NAME]: OrAddAttributePanelAttributeChangedEvent;
+ }
+}
+
+@customElement("or-add-attribute-panel")
+export class OrAddAttributePanel extends LitElement {
+
+ @property({attribute: false})
+ protected asset!: Asset;
+
+ @property({attribute: false})
+ protected attribute: Attribute = {};
+
+ public static get styles() {
+ return css`
+ #attribute-creator > * {
+ padding: 20px;
+ }
+
+ #attribute-creator > * or-input {
+ width: 300px;
+ }
+
+ .hidden {
+ visibility: hidden;
+ }`;
+ }
+
+ protected render() {
+
+ let attributeTypes: [string, string][] = AssetModelUtil.getAttributeDescriptors()
+ .filter((descriptor) => !this.asset.attributes![descriptor.attributeName!])
+ .sort(Util.sortByString((descriptor) => descriptor.attributeName!))
+ .map((descriptor) => {
+ return [
+ descriptor.attributeName!,
+ Util.getAttributeLabel(undefined, descriptor, undefined, false)
+ ]
+ });
+ attributeTypes = [["@custom", i18next.t("custom")], ...attributeTypes];
+
+ const attributeValueTypes: [string, string][] = AssetModelUtil.getAttributeValueDescriptors()
+ .sort(Util.sortByString((descriptor) => descriptor.name!))
+ .map((descriptor) => {
+ return [descriptor.name!, descriptor.name!];
+ });
+
+ return html`
+ <div id="attribute-creator">
+ <div>
+ <or-input .type="${InputType.SELECT}" .options="${attributeTypes}" .label="${i18next.t("type")}" @or-input-changed="${(ev: OrInputChangedEvent) => this.onTypeChanged(ev.detail.value)}"></or-input>
+ </div>
+ <div id="name-input" class="hidden">
+ <or-input .type="${InputType.TEXT}" .label="${i18next.t("name")}" pattern="\\w+" required @keyup="${(ev: KeyboardEvent) => this.onNameChanged((ev.target as OrInput).currentValue)}" @or-input-changed="${(ev: OrInputChangedEvent) => this.onNameChanged(ev.detail.value)}"></or-input>
+ </div>
+ <div id="type-input" class="hidden">
+ <or-input .type="${InputType.SELECT}" .options="${attributeValueTypes}" .label="${i18next.t("valueType")}" @or-input-changed="${(ev: OrInputChangedEvent) => this.onValueTypeChanged(ev.detail.value)}"></or-input>
+ </div>
+ </div>
+ `;
+ }
+
+ protected onTypeChanged(name: string) {
+ const nameInput = this.shadowRoot!.getElementById("name-input");
+ const typeInput = this.shadowRoot!.getElementById("type-input");
+
+ if (name === "@custom") {
+ nameInput!.classList.remove("hidden");
+ typeInput!.classList.remove("hidden");
+ this.attribute = {
+ meta: []
+ };
+ } else {
+ nameInput!.classList.add("hidden");
+ typeInput!.classList.add("hidden");
+ const descriptor = AssetModelUtil.getAttributeDescriptor(name)!;
+ this.attribute = {};
+ this.attribute.name = descriptor.attributeName;
+ this.attribute.value = descriptor.initialValue;
+ this.attribute.type = descriptor.valueDescriptor!.name as AttributeValueDescriptor; // TODO: Fix once asset model works properly
+ if (descriptor.metaItemDescriptors) {
+ this.attribute.meta = descriptor.metaItemDescriptors.map((descriptor) => {
+ return {
+ name: descriptor.urn,
+ value: descriptor.initialValue
+ }
+ });
+ } else {
+ this.attribute.meta = [];
+ }
+ }
+
+ this.dispatchEvent(new OrAddAttributePanelAttributeChangedEvent(this.attribute));
+ };
+
+ protected onNameChanged(name: string) {
+ this.attribute.name = name;
+ this.dispatchEvent(new OrAddAttributePanelAttributeChangedEvent(this.attribute));
+ };
+
+ protected onValueTypeChanged(valueType: string) {
+ // @ts-ignore
+ this.attribute.type = valueType;
+ this.dispatchEvent(new OrAddAttributePanelAttributeChangedEvent(this.attribute));
+ };
+}
diff --git a/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts b/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts
new file mode 100644
index 000000000..01d2be888
--- /dev/null
+++ b/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts
@@ -0,0 +1,482 @@
+import {css, customElement, html, LitElement, property, TemplateResult, unsafeCSS} from "lit-element";
+import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";
+import i18next from "i18next";
+import {Asset, Attribute, MetaItem, ValueType} from "@openremote/model";
+import {AssetModelUtil, DefaultColor5, Util} from "@openremote/core";
+import "@openremote/or-input";
+import {OrIcon} from "@openremote/or-icon";
+import {showDialog, OrMwcDialog, DialogAction} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import {ListItem, ListType, OrMwcList} from "@openremote/or-mwc-components/dist/or-mwc-list";
+import "./or-add-attribute-panel";
+import {getField, getPanel, getPropertyTemplate} from "./index";
+import {OrAddAttributePanelAttributeChangedEvent} from "./or-add-attribute-panel";
+import {panelStyles} from "./style";
+import { OrAssetTree, UiAssetTreeNode } from "@openremote/or-asset-tree";
+
+// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
+const tableStyle = require("!!raw-loader!@material/data-table/dist/mdc.data-table.css");
+
+// language=CSS
+const style = css`
+ .panel {
+ margin: 10px auto;
+ max-width: 1200px;
+ }
+ #parent-edit-wrapper {
+ display: flex;
+ align-items: center;
+ }
+
+ #parent-edit-wrapper > #property-parentId {
+ width: 100%;
+ }
+
+ #change-parent-btn {
+ margin-left: 20px;
+ }
+ .mdc-data-table__row:hover {
+ background-color: inherit !important;
+ }
+ #attribute-table {
+ width: 100%;
+ }
+ .expander-cell {
+ --or-icon-width: 18px;
+ --or-icon-height: 18px;
+ cursor: pointer;
+ }
+ .expander-cell > * {
+ pointer-events: none;
+ }
+ .expander-cell > or-icon {
+ margin-right: 16px;
+ }
+ .actions-cell {
+ text-align: right;
+ width: 40px;
+ }
+ .meta-item-container {
+ overflow: hidden;
+ max-height: 0;
+ transition: max-height 0.25s ease-out;
+ padding: 0 20px 0 50px;
+ }
+ .attribute-meta-row.expanded .meta-item-container {
+ max-height: 1000px;
+ transition: max-height 1s ease-in;
+ }
+ .meta-item-container or-input {
+ width: 100%;
+ }
+ .meta-item-wrapper {
+ display: flex;
+ margin: 10px 0;
+ }
+ .meta-item-wrapper:first-child {
+ margin-top: 0;
+ }
+ .meta-item-wrapper:hover .button-clear {
+ visibility: visible;
+ }
+ .item-add {
+ margin-bottom: 10px;
+ }
+ .button-clear {
+ background: none;
+ color: ${unsafeCSS(DefaultColor5)};
+ --or-icon-fill: ${unsafeCSS(DefaultColor5)};
+ visibility: hidden;
+ display: inline-block;
+ border: none;
+ padding: 0;
+ cursor: pointer;
+ }
+ .button-clear:hover {
+ --or-icon-fill: var(--internal-or-asset-viewer-button-color);
+ }
+ .button-clear:focus {
+ outline: 0;
+ }
+ .button-clear.hidden {
+ visibility: hidden;
+ }
+`;
+
+export class OrEditAssetChangedEvent extends CustomEvent<void> {
+
+ public static readonly NAME = "or-edit-asset-changed";
+
+ constructor() {
+ super(OrEditAssetChangedEvent.NAME, {
+ bubbles: true,
+ composed: false
+ });
+ }
+}
+declare global {
+ export interface HTMLElementEventMap {
+ [OrEditAssetChangedEvent.NAME]: OrEditAssetChangedEvent;
+ }
+}
+
+@customElement("or-edit-asset-panel")
+export class OrEditAssetPanel extends LitElement {
+
+ @property({attribute: false})
+ protected asset!: Asset;
+
+ @property({attribute: false})
+ protected attrs!: Attribute[];
+
+ public static get styles() {
+ return [
+ unsafeCSS(tableStyle),
+ panelStyles,
+ style
+ ];
+ }
+
+ protected render() {
+
+ const updatePublicRead = (publicRead: boolean) => {
+ this.asset.accessPublicRead = publicRead;
+ this.onUpdated();
+ };
+
+ // Properties panel fields
+ const properties: TemplateResult[] = [
+ getField("type", undefined, getPropertyTemplate(this.asset, "type", this, undefined, undefined, {readonly: true, label: i18next.t("assetType")})),
+ getField("parent", undefined, this._getParentTemplate()),
+ html`<div @or-input-changed="${(ev: OrInputChangedEvent) => updatePublicRead(ev.detail.value as boolean)}">
+ ${getField("accessPublicRead", undefined, getPropertyTemplate(this.asset, "accessPublicRead", this, undefined, undefined, {readonly: false, label: i18next.t("accessPublicRead")}))}
+ </div>`
+ ];
+
+ 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";
+ metaRow.classList.remove("expanded");
+ }
+ };
+
+ const attributes = html`
+ <div id="attribute-table" 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="name"></or-translate></th>
+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="type"></or-translate></th>
+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="value"></or-translate></th>
+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col"></or-translate></th>
+ </tr>
+ </thead>
+ <tbody class="mdc-data-table__content">
+ ${this.attrs!.sort(Util.sortByString((attr: Attribute) => attr.name!.toUpperCase())).map((attr) => this._getEditAttributeTemplate(attr))}
+ <tr>
+ <td colspan="4">
+ <div class="item-add">
+ <or-input .type="${InputType.BUTTON}" .label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._addAttribute()}"></or-input>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ `;
+
+ return html`
+ <div id="edit-wrapper">
+ ${getPanel("properties", {}, html`${properties}`) || ``}
+ ${getPanel("attributes", {}, html`${attributes}`) || ``}
+ </div>
+ `;
+ }
+
+ protected _getEditAttributeTemplate(attribute: Attribute): TemplateResult {
+
+ const deleteAttribute = () => {
+ this.attrs!.splice(this.attrs!.indexOf(attribute), 1);
+ this.onUpdated();
+ };
+
+ return html`
+ <tr class="mdc-data-table__row">
+ <td class="mdc-data-table__cell expander-cell"><or-icon icon="chevron-right"></or-icon><span>${attribute.name}</span></td>
+ <td class="mdc-data-table__cell">${attribute.type}</td>
+ <td class="mdc-data-table__cell">${attribute.value}</td>
+ <td class="mdc-data-table__cell actions-cell"><or-input type="${InputType.BUTTON}" icon="delete" @click="${deleteAttribute}"></td>
+ </tr>
+ <tr class="attribute-meta-row">
+ <td colspan="4">
+ <div>
+ <div class="meta-item-container">
+ <div>
+ ${!attribute.meta ? `` : attribute.meta.sort(Util.sortByString((metaItem) => metaItem.name!)).map((metaItem) => this._getEditMetaItemTemplate(attribute, metaItem))}
+ </div>
+ <div class="item-add">
+ <or-input .type="${InputType.BUTTON}" .label="${i18next.t("addMetaItems")}" icon="plus" @click="${() => this._addMetaItems(attribute)}"></or-input>
+ </div>
+ </div>
+ </div>
+ </td>
+ </tr>
+ `;
+ };
+
+ protected onUpdated() {
+ this.dispatchEvent(new OrEditAssetChangedEvent());
+ this.requestUpdate();
+ }
+
+ protected _getEditMetaItemTemplate(attribute: Attribute, metaItem: MetaItem): TemplateResult {
+
+ const removeMetaItem = () => {
+ attribute.meta!.splice(attribute.meta!.indexOf(metaItem), 1);
+ this.onUpdated();
+ };
+
+ const descriptor = AssetModelUtil.getMetaItemDescriptor(metaItem.name);
+ let valueType = descriptor ? descriptor.valueType : undefined;
+ let inputType = InputType.TEXT;
+ if (!valueType && metaItem.value !== undefined && metaItem.value !== null) {
+ switch (typeof metaItem.value) {
+ case "object":
+ if (Array.isArray(metaItem.value)) {
+ valueType = ValueType.ARRAY;
+ } else {
+ valueType = ValueType.OBJECT;
+ }
+ break;
+ case "boolean":
+ valueType = ValueType.BOOLEAN;
+ break;
+ case "number":
+ valueType = ValueType.NUMBER;
+ break;
+ case "string":
+ valueType = ValueType.STRING;
+ break;
+ }
+ }
+
+ if (valueType) {
+ switch (valueType) {
+ case ValueType.NUMBER:
+ inputType = InputType.NUMBER;
+ break;
+ case ValueType.BOOLEAN:
+ inputType = InputType.CHECKBOX;
+ break;
+ case ValueType.ARRAY:
+ case ValueType.OBJECT:
+ inputType = InputType.JSON;
+ break;
+ }
+ }
+ const readonly = descriptor && !!descriptor.valueFixed;
+ return html`
+ <div class="meta-item-wrapper">
+ <or-input .label=${Util.getMetaItemLabel(metaItem.name!)} .type="${inputType}" .value="${metaItem.value}" ?disabled="${readonly}"></or-input>
+ <button class="button-clear" @click="${removeMetaItem}"><or-icon icon="close-circle"></or-icon></input>
+ </div>
+ `;
+ }
+
+ protected _addAttribute() {
+
+ const asset = this.asset!;
+ let attr: Attribute;
+
+ const onAttributeChanged = (attribute: Attribute) => {
+ const addDisabled = !(attribute.name && !asset.attributes![attribute.name] && attribute.type);
+ const addBtn = dialog!.shadowRoot!.getElementById("add-btn") as OrInput;
+ addBtn!.disabled = addDisabled;
+ attr = attribute;
+ };
+
+ const dialog = showDialog({
+ content: html`
+ <or-add-attribute-panel .asset="${asset}" @or-add-attribute-panel-attribute-changed="${(ev: OrAddAttributePanelAttributeChangedEvent) => onAttributeChanged(ev.detail)}"></or-add-attribute-panel>
+ `,
+ styles: html`
+ <style>
+ .mdc-dialog__surface {
+ overflow-x: visible !important;
+ overflow-y: visible !important;
+ }
+ #dialog-content {
+ border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
+ border-top-width: 1px;
+ border-top-style: solid;
+ border-bottom-width: 1px;
+ border-bottom-style: solid;
+ padding: 0;
+ overflow: visible;
+ }
+ </style>
+ `,
+ title: i18next.t("addAttribute"),
+ actions: [
+ {
+ default: true,
+ actionName: "add",
+ action: () => {
+ this.attrs!.push(attr);
+ this.onUpdated();
+ },
+ content: html`<or-input id="add-btn" .type="${InputType.BUTTON}" disabled .label="${i18next.t("add")}"></or-input>`
+ },
+ {
+ actionName: "cancel",
+ content: i18next.t("cancel")
+ }
+ ],
+ dismissAction: null
+ });
+ }
+
+ protected _addMetaItems(attribute: Attribute) {
+
+ const metaItemList: (ListItem | null)[] = AssetModelUtil.getMetaItemDescriptors()
+ .filter((descriptor) => !attribute.meta!.some((m) => m.name === descriptor.urn))
+ .map((descriptor) => {
+ return {
+ text: Util.getMetaItemLabel(descriptor.urn!),
+ value: descriptor.urn!,
+ translate: false
+ };
+ }).sort(Util.sortByString((item) => item.text));
+
+ const dialog = showDialog({
+ content: html`
+ <div id="meta-creator">
+ <or-mwc-list id="meta-creator-list" .type="${ListType.CHECKBOX}" .listItems="${metaItemList}"></or-mwc-list>
+ </div>
+ `,
+ styles: html`
+ <style>
+ #dialog-content {
+ border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
+ border-top-width: 1px;
+ border-top-style: solid;
+ border-bottom-width: 1px;
+ border-bottom-style: solid;
+ }
+ #meta-creator {
+ height: 600px;
+ max-height: 100%;
+ }
+
+ #meta-creator > or-mwc-list {
+ height: 100%;
+ }
+ </style>
+ `,
+ title: i18next.t("addMetaItems"),
+ actions: [
+ {
+ default: true,
+ actionName: "add",
+ action: () => {
+ const list = dialog!.shadowRoot!.getElementById("meta-creator-list") as OrMwcList;
+ const selectedItems = list ? list.selectedItems : undefined;
+ if (selectedItems) {
+ if (!attribute.meta) {
+ attribute.meta = [];
+ }
+ selectedItems.forEach((item) => {
+ const descriptor = AssetModelUtil.getMetaItemDescriptors().find((descriptor) => descriptor.urn === item.value);
+ if (descriptor) {
+ attribute.meta!.push(
+ {
+ name: descriptor.urn,
+ value: descriptor.initialValue
+ }
+ );
+ this.onUpdated();
+ }
+ });
+ }
+ },
+ content: i18next.t("add")
+ },
+ {
+ actionName: "cancel",
+ content: i18next.t("cancel")
+ }
+ ],
+ dismissAction: null
+ });
+ }
+
+ protected _getParentTemplate() {
+ const showDialog = () => {
+ const dialog = this.shadowRoot!.getElementById("asset-picker-modal") as OrMwcDialog;
+ dialog.open();
+ };
+ const viewer = this;
+
+ const setParent = () => {
+ const dialog = this.shadowRoot!.getElementById("asset-picker-modal") as OrMwcDialog;
+ const assetTree = dialog.shadowRoot!.getElementById("parent-asset-tree") as OrAssetTree;
+ this.asset.parentId = assetTree.selectedIds!.length === 1 ? assetTree.selectedIds![0] : undefined;
+ // Need to update the assets path as well
+ const path = [this.asset.id!];
+ let parentNode = assetTree.selectedNodes[0];
+ while (parentNode !== undefined) {
+ path.push(parentNode.asset!.id!);
+ parentNode = parentNode.parent;
+ }
+ this.asset.path = path;
+ this.onUpdated();
+ };
+
+ const clearParent = () => {
+ this.asset.parentId = undefined;
+ this.asset.path = [this.asset.id!];
+ this.onUpdated();
+ };
+
+ const blockEvent = (ev: Event) => {
+ ev.stopPropagation();
+ };
+
+ const parentSelector = (node: UiAssetTreeNode) => node.asset!.id !== this.asset.id;
+
+ // Prevent change event from bubbling up as it will affect any ancestor listeners that are interested in a different asset tree
+ const dialogContent = html`<or-asset-tree id="parent-asset-tree" .selectedIds="${this.asset!.parentId ? [this.asset.parentId] : []}" @or-asset-tree-request-select="${blockEvent}" @or-asset-tree-selection-changed="${blockEvent}" .selector="${parentSelector}"></or-asset-tree>`;
+
+ const dialogActions: DialogAction[] = [
+ {
+ actionName: "clear",
+ content: i18next.t("none"),
+ action: clearParent
+ },
+ {
+ default: true,
+ actionName: "ok",
+ content: i18next.t("ok"),
+ action: setParent
+ }
+ ];
+
+ return html`
+ <div id="parent-edit-wrapper">
+ ${getPropertyTemplate(this.asset, "parentId", this, undefined, undefined, {readonly: false, label: i18next.t("parent")})}
+ <or-input id="change-parent-btn" type="${InputType.BUTTON}" raised .label="${i18next.t("edit")}" @or-input-changed="${showDialog}"></or-input>
+ </div>
+ <or-mwc-dialog id="asset-picker-modal" .dialogContent="${dialogContent}" .dialogActions="${dialogActions}" .multiSelect="${false}"></or-mwc-dialog>
+ `;
+ }
+}
diff --git a/ui/component/or-asset-viewer/src/style.ts b/ui/component/or-asset-viewer/src/style.ts
index 32ee09376..56467cadf 100644
--- a/ui/component/or-asset-viewer/src/style.ts
+++ b/ui/component/or-asset-viewer/src/style.ts
@@ -1,5 +1,54 @@
import {css, unsafeCSS} from "lit-element";
-import {DefaultBoxShadow, DefaultColor1, DefaultColor2, DefaultColor3, DefaultColor5} from "@openremote/core";
+import {DefaultColor1, DefaultColor2, DefaultColor3, DefaultColor5, DefaultColor4} from "@openremote/core";
+
+// language=CSS
+export const panelStyles = css`
+ .panel {
+ background-color: var(--internal-or-asset-viewer-panel-color);
+ border: 1px solid #e5e5e5;
+ border-radius: 5px;
+ max-width: 100%;
+ position: relative;
+ }
+
+ .panel-content-wrapper {
+ padding: var(--internal-or-asset-viewer-panel-padding);
+ }
+
+ .panel-content {
+ display: flex;
+ flex-wrap: wrap;
+ }
+
+ .panel-title {
+ text-transform: uppercase;
+ font-weight: bolder;
+ line-height: 1em;
+ color: var(--internal-or-asset-viewer-title-text-color);
+ margin-bottom: 20px;
+ flex: 0 0 auto;
+ letter-spacing: 0.025em;
+ }
+
+ .field {
+ margin: 10px 0;
+ width: 100%;
+ flex: 0 0 auto;
+ }
+
+ .field > * {
+ width: 100%;
+ box-sizing: border-box;
+ }
+
+ .panel-content > :first-child {
+ margin-top: 0;
+ }
+
+ .panel-content > :last-child {
+ margin-bottom: 0;
+ }
+`;
// language=CSS
export const style = css`
@@ -12,7 +61,8 @@ export const style = css`
--internal-or-asset-viewer-title-text-color: var(--or-asset-viewer-title-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));
--internal-or-asset-viewer-panel-color: var(--or-asset-viewer-panel-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));
--internal-or-asset-viewer-line-color: var(--or-asset-viewer-line-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));
-
+ --internal-or-asset-viewer-button-color: var(--or-asset-viewer-button-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
+
height: 100%;
width: 100%;
background-color: var(--internal-or-asset-viewer-background-color);
@@ -45,6 +95,18 @@ export const style = css`
animation: fadein 0.3s;
}
+ #name-input {
+ width: 300px;
+ }
+
+ @media only screen and (max-width: 767px) {
+ #wrapper {
+ position: absolute;
+ left: 0;
+ right: 0;
+ }
+ }
+
@keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
@@ -90,24 +152,14 @@ export const style = css`
#title > or-icon {
margin-right: 10px;
}
-
- #created {
- text-align: right;
- flex: 1 0 auto;
+
+ #created-time {
+ flex: 0 0 auto;
font-size: 12px;
- font-color: #ccc;
- }
-
- .panel {
- background-color: var(--internal-or-asset-viewer-panel-color);
- border: 1px solid #e5e5e5;
- border-radius: 5px;
- max-width: 100%;
- position: relative;
}
-
- .panel-content-wrapper {
- padding: var(--internal-or-asset-viewer-panel-padding);
+
+ #save-btn {
+ margin-left: 20px;
}
#location-panel .panel-content {
@@ -118,40 +170,6 @@ export const style = css`
position: relative;
}
- .panel-content {
- display: flex;
- flex-wrap: wrap;
- }
-
- .panel-title {
- text-transform: uppercase;
- font-weight: bolder;
- line-height: 1em;
- color: var(--internal-or-asset-viewer-title-text-color);
- margin-bottom: 20px;
- flex: 0 0 auto;
- letter-spacing: 0.025em;
- }
-
- .field {
- margin: 10px 0;
- width: 100%;
- flex: 0 0 auto;
- }
-
- .field > * {
- width: 100%;
- box-sizing: border-box;
- }
-
- #attributes-panel .panel-content > :first-child, #info-panel .panel-content > :first-child {
- margin-top: 0;
- }
-
- #attributes-panel .panel-content > :last-child, #info-panel .panel-content > :last-child {
- margin-bottom: 0;
- }
-
.msg {
display: flex;
justify-content: center;
@@ -165,6 +183,11 @@ export const style = css`
cursor: pointer;
}
+ or-edit-asset-panel {
+ grid-column-start: 1;
+ grid-column-end: 3;
+ }
+
@media screen and (max-width: 769px) {
#wrapper {
position: absolute;
@@ -199,8 +222,7 @@ export const style = css`
grid-row-start: 2;
}
- #location-panel {
-
+ #location-panel {
grid-row-start: 3;
}
@@ -214,4 +236,4 @@ export const style = css`
padding: 20px 0;
}
}
-`;
\ No newline at end of file
+`;
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 53fc3efc9..e6265d437 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -266,7 +266,7 @@ export class OrInput extends LitElement {
@property({type: Boolean})
public multiple: boolean = false;
- @property({type: String})
+ @property({type: String, attribute: true, reflect: false})
public pattern?: string;
@property({type: String})
@@ -549,7 +549,7 @@ export class OrInput extends LitElement {
<button id="component" class="mdc-icon-button ${this.value ? "mdc-icon-button--on" : ""}"
?readonly="${this.readonly}"
?disabled="${this.disabled}"
- @MDCIconButtonToggle:change="${(evt: MDCIconButtonToggleEventDetail) => this.onValueChange(undefined, evt.isOn)}">
+ @MDCIconButtonToggle:change="${(evt: CustomEvent<MDCIconButtonToggleEventDetail>) => this.onValueChange(undefined, evt.detail.isOn)}">
${this.icon ? html`<or-icon class="mdc-icon-button__icon" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}
${this.iconOn ? html`<or-icon class="mdc-icon-button__icon mdc-icon-button__icon--on" aria-hidden="true" icon="${this.iconOn}"></or-icon>` : ``}
</button>
@@ -725,7 +725,7 @@ export class OrInput extends LitElement {
<input type="${type}" id="elem" aria-labelledby="${ifDefined(label ? "label" : undefined)}"
class="mdc-text-field__input" ?required="${this.required}" ?readonly="${this.readonly}"
?disabled="${this.disabled}" min="${ifDefined(valMinMax[1])}" max="${ifDefined(valMinMax[2])}"
- step="${this.step ? this.step : "any"}" minlength="${ifDefined(this.minLength)}"
+ step="${ifDefined(this.step)}" minlength="${ifDefined(this.minLength)}" pattern="${ifDefined(this.pattern)}"
maxlength="${ifDefined(this.maxLength)}" placeholder="${ifDefined(this.placeHolder)}"
.value="${valMinMax[0] !== null && valMinMax[0] !== undefined ? valMinMax[0] : ""}"
@change="${(e: Event) => this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value)}" />`;
@@ -949,4 +949,10 @@ export class OrInput extends LitElement {
return true;
}
+ public get currentValue(): any {
+ const elem = this.shadowRoot!.getElementById("elem") as any;
+ if (elem && elem.value) {
+ return elem.value;
+ }
+ }
}
diff --git a/ui/component/or-mwc-components/src/or-mwc-dialog.ts b/ui/component/or-mwc-components/src/or-mwc-dialog.ts
index 1fcf60acf..94f38302e 100644
--- a/ui/component/or-mwc-components/src/or-mwc-dialog.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts
@@ -17,7 +17,7 @@ export interface DialogConfig {
}
export interface DialogActionBase {
actionName: string;
- action?: () => void;
+ action?: (dialog: OrMwcDialog) => void;
}
export interface DialogAction extends DialogActionBase {
@@ -58,9 +58,9 @@ declare global {
}
}
-export function showDialog(config: DialogConfig, hostElement: HTMLElement = document.body): OrMwcDialog | undefined {
+export function showDialog(config: DialogConfig, hostElement: HTMLElement = document.body): OrMwcDialog {
if (!hostElement) {
- return;
+ hostElement = document.body;
}
const dialog = new OrMwcDialog();
@@ -242,11 +242,11 @@ export class OrMwcDialog extends LitElement {
protected _onDialogClosed(action?: string) {
if (action === "close" && this.dismissAction && this.dismissAction.action) {
- this.dismissAction.action();
+ this.dismissAction.action(this);
} else if (action && this.dialogActions) {
const matchedAction = this.dialogActions.find((dialogAction) => dialogAction.actionName === action);
if (matchedAction && matchedAction.action) {
- matchedAction.action();
+ matchedAction.action(this);
}
}
this.dispatchEvent(new OrMwcDialogClosedEvent(action));
diff --git a/ui/tslint.json b/ui/tslint.json
index fe087c064..6282a847e 100644
--- a/ui/tslint.json
+++ b/ui/tslint.json
@@ -15,6 +15,7 @@
"array-type": false,
"object-literal-shorthand": false,
"no-string-literal": false,
- "no-shadowed-variable": false
+ "no-shadowed-variable": false,
+ "no-var-requires": false
}
}