Skip to content

armgit / core

Public Imported from GitHub
0

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

Add create asset modal, update asset viewer

Robin Dekkers3263b3168560
diff --git a/ui/app/or-app/src/pages/page-assets.ts b/ui/app/or-app/src/pages/page-assets.ts
index 6957c5833..d818cbd85 100644
--- a/ui/app/or-app/src/pages/page-assets.ts
+++ b/ui/app/or-app/src/pages/page-assets.ts
@@ -2,13 +2,14 @@ import {css, customElement, html, property, TemplateResult, unsafeCSS} from "lit
import "@openremote/or-asset-tree";
import "@openremote/or-asset-viewer";
import {ViewerConfig} from "@openremote/or-asset-viewer";
-import {OrAssetTreeSelectionChangedEvent} from "@openremote/or-asset-tree";
+import {OrAssetTreeSelectionChangedEvent, AssetTreeConfig} from "@openremote/or-asset-tree";
import {DefaultBoxShadow} from "@openremote/core";
import {AppStateKeyed, Page, router} from "../index";
import {EnhancedStore} from "@reduxjs/toolkit";
export interface PageAssetsConfig {
viewer: ViewerConfig;
+ tree?: AssetTreeConfig;
}
export function pageAssetsProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config: PageAssetsConfig = PAGE_ASSETS_DEFAULT_CONFIG) {
@@ -509,7 +510,7 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
protected render(): TemplateResult | void {
const selectedIds = [this._assetId];
return html`
- <or-asset-tree id="pageAssetTree" class="${this._assetId ? "hideMobile" : ""}" .selectedIds="${selectedIds}"></or-asset-tree>
+ <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>
`;
}
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index b8d77e8eb..6290fd91d 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -1,15 +1,30 @@
import {customElement, html, LitElement, property, PropertyValues, query, TemplateResult} from "lit-element";
+import {styleMap} from "lit-html/directives/style-map";
import "@openremote/or-input";
import "@openremote/or-icon";
-import {Asset, AssetQuery, AssetTreeNode, ClientRole, SharedEvent, AssetsEvent, AssetEvent, AssetEventCause} from "@openremote/model";
+import {Asset, AssetQuery, AssetTreeNode, ClientRole, SharedEvent, AssetsEvent, AssetEvent, AssetEventCause, AssetDescriptor, AssetType} from "@openremote/model";
import "@openremote/or-translate";
import {style} from "./style";
-import manager, {Util, AssetModelUtil, OREvent, EventCallback, subscribe} from "@openremote/core";
-import {InputType} from "@openremote/or-input";
+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 {getContentWithMenuTemplate, MenuItem} from "@openremote/or-mwc-components/dist/or-mwc-menu";
+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";
+
+
+export interface AssetTreeTypeConfig {
+ include?: string[];
+ exclude?: string[];
+}
+
+export interface AssetTreeConfig {
+ default?: AssetTreeTypeConfig;
+ addAssetTypes?: { [assetType: string]: AssetTreeTypeConfig };
+}
+
export interface UiAssetTreeNode extends AssetTreeNode {
selected: boolean;
@@ -118,6 +133,71 @@ declare global {
}
}
+export const getAssetTypes = async () => {
+ const response = await manager.rest.api.AssetResource.queryAssets({
+ select: {
+ excludeAttributes: true,
+ excludeParentInfo: true,
+ excludePath: true,
+ excludeAttributeMeta: true,
+ excludeAttributeTimestamp: true,
+ excludeAttributeType: true,
+ excludeAttributeValue: true
+ },
+ recursive: true
+ });
+
+ if(response && response.data) {
+ return response.data.map(asset => asset.type!);
+ }
+}
+
+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")
@@ -135,9 +215,18 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
@property({type: Array, reflect: false})
public assets?: Asset[];
+ @property({type: Object})
+ public assetDescriptors?: AssetDescriptor[];
+
@property({type: Array})
public _assetIdsOverride?: string[];
+ @property({type: Array})
+ public _assetTypeOptions?: string[];
+
+ @property({type: Object})
+ public _selectedAssetTypeOption?: AssetDescriptor;
+
@property({type: Array})
public rootAssets?: Asset[];
@@ -165,6 +254,8 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
@property({type: String})
public sortBy?: string = "name";
+ protected config?: AssetTreeConfig;
+
@property({attribute: false})
protected _nodes?: UiAssetTreeNode[];
@@ -202,8 +293,44 @@ 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 selectedAssetTypeOption = getAssetTypeOption(this._selectedAssetTypeOption)
return html`
<div id="header">
<div id="title-container">
@@ -213,7 +340,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
<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() || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="delete" @click="${() => this._onDeleteClicked()}"></or-input>
- <or-input style="display: none;" ?hidden="${this._isReadonly()}" type="${InputType.BUTTON}" icon="plus" @click="${() => this._onAddClicked()}"></or-input>
+ <or-input ?hidden="${this._isReadonly() || !this.selectedIds || this.selectedIds.length === 0}" type="${InputType.BUTTON}" icon="plus" @click="${() => this._onAddClicked()}"></or-input>
<or-input hidden type="${InputType.BUTTON}" icon="magnify" @click="${() => this._onSearchClicked()}"></or-input>
${getContentWithMenuTemplate(
@@ -239,16 +366,34 @@ 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>
`;
}
protected _isReadonly() {
- return this.readonly || !manager.hasRole(ClientRole.WRITE_RULES);
+ return this.readonly || !manager.hasRole(ClientRole.WRITE_ASSETS);
+ }
+
+ protected firstUpdated(_changedProperties: PropertyValues){
+ this.renderDialogHTML();
}
protected shouldUpdate(_changedProperties: PropertyValues): boolean {
const result = super.shouldUpdate(_changedProperties);
-
if (_changedProperties.has("_assetIdsOverride")
|| _changedProperties.has("assets")
|| _changedProperties.has("rootAssets")
@@ -351,7 +496,9 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
}
protected _onAddClicked() {
- this._doRequest(new OrAssetTreeRequestAddEvent(), () => this._doAdd());
+ const dialog: OrMwcDialog = this.shadowRoot!.getElementById("mdc-dialog") as OrMwcDialog;
+ console.log(dialog)
+ dialog.open();
}
protected _onSearchClicked() {
@@ -437,8 +584,17 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
return window.confirm(i18next.t("confirmDeleteAssets"));
}
- protected _doAdd() {
+ 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) => {
+ this._loadAssets();
+ });
}
protected _doCopy(node: UiAssetTreeNode) {
@@ -480,7 +636,6 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
query.ids = this.rootAssetIds;
query.recursive = true;
}
-
this._sendEventWithReply({
event: {
eventType: "read-assets",
@@ -577,7 +732,6 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
rootAssets.sort(sortFunction);
rootAssets.forEach((rootAsset) => this._buildChildTreeNodes(rootAsset, assets, sortFunction));
-
this._nodes = rootAssets;
}
diff --git a/ui/component/or-asset-viewer/package.json b/ui/component/or-asset-viewer/package.json
index 92bc56cac..f59be4b10 100644
--- a/ui/component/or-asset-viewer/package.json
+++ b/ui/component/or-asset-viewer/package.json
@@ -18,6 +18,8 @@
"@openremote/or-input": "^1.1.0",
"@openremote/or-attribute-input": "^1.1.0",
"@openremote/or-attribute-history": "^1.1.0",
+ "@openremote/or-survey": "^1.1.0",
+ "@openremote/or-survey-results": "^1.1.0",
"@openremote/or-translate": "^1.1.0",
"@openremote/or-panel": "^1.1.0",
"@openremote/or-table": "^1.1.0",
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 19cd52633..e6c29d723 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -4,6 +4,8 @@ import "@openremote/or-input";
import "@openremote/or-attribute-input";
import "@openremote/or-attribute-history";
import "@openremote/or-chart";
+import "@openremote/or-survey";
+import "@openremote/or-survey-results";
import "@openremote/or-table";
import "@openremote/or-panel";
import "@openremote/or-mwc-components/dist/or-mwc-dialog";
@@ -32,7 +34,7 @@ import {DialogAction, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-m
import { GenericAxiosResponse } from "axios";
import { OrIcon } from "@openremote/or-icon";
-export type PanelType = "property" | "location" | "attribute" | "history" | "chart" | "group";
+export type PanelType = "property" | "location" | "attribute" | "history" | "chart" | "group" | "survey" | "survey-results";
export interface PanelConfig {
type?: PanelType;
@@ -91,6 +93,22 @@ class EventHandler {
this._callbacks.push(callback);
}
}
+
+export interface OrComputeGridEventDetail {
+}
+
+export class OrComputeGridEvent extends CustomEvent<OrComputeGridEventDetail> {
+
+ public static readonly NAME = "or-compute-grid-event";
+
+ constructor() {
+ super(OrComputeGridEvent.NAME, {
+ bubbles: true,
+ composed: true
+ });
+ }
+}
+
const onRenderComplete = new EventHandler();
function getPanel(name: string, panelConfig: PanelConfig, content: TemplateResult | undefined) {
@@ -150,7 +168,17 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
// })}
// `;
// } else
- if (panelConfig && panelConfig.type === "history") {
+ if (panelConfig && panelConfig.type === "survey") {
+ content = 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>
+ `;
+ }
+ 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) {
@@ -259,7 +287,6 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
`;
}
} else if (panelConfig && panelConfig.type === "group") {
-
if (asset.type !== "urn:openremote:asset:group") {
return;
}
@@ -520,6 +547,16 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
type: "history",
panelStyles: {
}
+ },
+ survey: {
+ type: "survey",
+ panelStyles: {
+ }
+ },
+ surveyResults: {
+ type: "survey-results",
+ panelStyles: {
+ }
}
}
};
@@ -557,6 +594,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
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));
}
diff --git a/ui/component/or-asset-viewer/tsconfig.json b/ui/component/or-asset-viewer/tsconfig.json
index c72451d02..16a6812a2 100644
--- a/ui/component/or-asset-viewer/tsconfig.json
+++ b/ui/component/or-asset-viewer/tsconfig.json
@@ -17,6 +17,9 @@
{ "path": "../or-table" },
{ "path": "../or-translate" },
{ "path": "../or-icon" },
+ { "path": "../or-map" },
+ { "path": "../or-survey" },
+ { "path": "../or-survey-results" },
{ "path": "../or-attribute-input" },
{ "path": "../or-attribute-history" },
{ "path": "../or-mwc-components" }
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 8a8a3a73f..554b26892 100644
--- a/ui/component/or-mwc-components/src/or-mwc-menu.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-menu.ts
@@ -125,6 +125,9 @@ export class OrMwcMenu extends LitElement {
@property({type: Boolean, attribute: true})
public visible?: boolean;
+ @property({type: Boolean, attribute: true})
+ public noSurface?: boolean = false;
+
@property({type: Boolean, attribute: true})
public twoLine?: boolean;
@@ -158,7 +161,7 @@ export class OrMwcMenu extends LitElement {
return html`
<div id="wrapper" class="mdc-menu-surface--anchor">
- <div class="mdc-menu mdc-menu-surface" id="menu" @MDCMenuSurface:closed="${this._onMenuClosed}">
+ <div class="mdc-menu ${this.noSurface ? "" : "mdc-menu-surface"}" id="menu" @MDCMenuSurface:closed="${this._onMenuClosed}">
<ul class="mdc-list ${this.twoLine ? "mdc-list--two-line" : ""}" role="menu" aria-hidden="true" aria-orientation="vertical" tabindex="-1">
${this.getItemsTemplate(this.menuItems)}
</ul>
@@ -262,7 +265,9 @@ export class OrMwcMenu extends LitElement {
if (!this.multiSelect) {
this.values = value;
- this._mdcComponent!.open = false;
+ if(!this.noSurface){
+ this._mdcComponent!.open = false;
+ }
} else {
if (!Array.isArray(this.values)) {
this.values = this.values ? [this.values] : [];
diff --git a/ui/component/or-survey/src/index.ts b/ui/component/or-survey/src/index.ts
index ab087d9fb..a35ba6cfe 100644
--- a/ui/component/or-survey/src/index.ts
+++ b/ui/component/or-survey/src/index.ts
@@ -1,7 +1,6 @@
import {customElement, html, LitElement, property, PropertyValues} from "lit-element";
import { Asset, AssetQuery, AssetQueryMatch} from "@openremote/model";
import {surveySectionStyle, surveyLayoutStyle} from "./style";
-
import set from "lodash-es/set";
import get from "lodash-es/get";
import orderBy from "lodash-es/orderBy";
@@ -12,6 +11,20 @@ import filter from "lodash-es/filter";
import "@openremote/or-translate";
declare var MANAGER_URL: string;
+export interface OrComputeGridEventDetail {
+}
+
+export class OrComputeGridEvent extends CustomEvent<OrComputeGridEventDetail> {
+
+ public static readonly NAME = "or-compute-grid-event";
+
+ constructor() {
+ super(OrComputeGridEvent.NAME, {
+ bubbles: true,
+ composed: true
+ });
+ }
+}
export interface AnswerOption {
value: string
}
@@ -212,9 +225,11 @@ class OrSurvey extends LitElement {
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);
- if(_changedProperties.has('survey')) {
+ if(_changedProperties.has('survey') || _changedProperties.has('surveyId')) {
this.resetSurvey();
}
+
+ this.dispatchEvent(new OrComputeGridEvent())
}
checkAssetPeriode(asset:Asset) {
@@ -401,10 +416,9 @@ class OrSurvey extends LitElement {
}
getSurvey() {
-
let surveyId: string;
if (location.hash.indexOf('survey') != -1) {
- surveyId = location.hash.split(':')[1];
+ surveyId = location.hash.split('/')[1];
if(!surveyId) {
this.checkButtons();
return;
@@ -416,7 +430,6 @@ class OrSurvey extends LitElement {
return;
}
-
const surveyQuery: AssetQuery = {
select: {
excludeAttributeMeta: false,
@@ -426,9 +439,8 @@ class OrSurvey extends LitElement {
excludeAttributeType: false
},
ids: [surveyId],
- types: [{predicateType: "string", value: "urn:openremote:asset:eindhoven:survey"}]
+ types: [{predicateType: "string", value: "urn:openremote:asset:"+manager.getRealm()+":survey"}]
};
-
manager.rest.api.AssetResource.queryPublicAssets(surveyQuery).then((response) => {
if (response && response.data) {
this.survey = response.data[0];
@@ -451,7 +463,7 @@ class OrSurvey extends LitElement {
excludeAttributeTimestamp: false,
excludeAttributeType: false
},
- types: [{predicateType: "string", value: "urn:openremote:asset:eindhoven:survey:question", match: AssetQueryMatch.CONTAINS}]
+ types: [{predicateType: "string", value: "urn:openremote:asset:"+manager.getRealm()+":survey:question", match: AssetQueryMatch.CONTAINS}]
};
manager.rest.api.AssetResource.queryPublicAssets(questionQuery).then((response) => {
@@ -466,6 +478,7 @@ class OrSurvey extends LitElement {
this.checkButtons();
this.requestUpdate();
+
}
}).catch((reason) => {
console.error("Error: " + reason);