Skip to content

armgit / core

Public Imported from GitHub
0

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

702 non existing asset type warning (#760)

Jérôme Vervierec3a104dedad
diff --git a/manager/src/web/shared/locales/ar/or.json b/manager/src/web/shared/locales/ar/or.json
index 1e62901af..800728774 100644
--- a/manager/src/web/shared/locales/ar/or.json
+++ b/manager/src/web/shared/locales/ar/or.json
@@ -398,6 +398,7 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
}
}
diff --git a/manager/src/web/shared/locales/cn/or.json b/manager/src/web/shared/locales/cn/or.json
index fc987125d..066434092 100644
--- a/manager/src/web/shared/locales/cn/or.json
+++ b/manager/src/web/shared/locales/cn/or.json
@@ -447,6 +447,7 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
}
}
diff --git a/manager/src/web/shared/locales/de/or.json b/manager/src/web/shared/locales/de/or.json
index 8a000f3d8..58ae71d75 100644
--- a/manager/src/web/shared/locales/de/or.json
+++ b/manager/src/web/shared/locales/de/or.json
@@ -476,6 +476,7 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
}
}
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.json
index 7bceed2d0..301237ae7 100644
--- a/manager/src/web/shared/locales/en/or.json
+++ b/manager/src/web/shared/locales/en/or.json
@@ -486,7 +486,8 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
},
"realmDeleteConfirm": "Warning! this will delete everything in this realm, type the realm name '{{realmName}}' to confirm.",
"realmDeleteFailed": "Failed to delete realm"
diff --git a/manager/src/web/shared/locales/es/or.json b/manager/src/web/shared/locales/es/or.json
index 1b1849b9c..1424fce40 100644
--- a/manager/src/web/shared/locales/es/or.json
+++ b/manager/src/web/shared/locales/es/or.json
@@ -447,6 +447,7 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
}
}
diff --git a/manager/src/web/shared/locales/fr/or.json b/manager/src/web/shared/locales/fr/or.json
index 778ee1529..b9c7b0e65 100644
--- a/manager/src/web/shared/locales/fr/or.json
+++ b/manager/src/web/shared/locales/fr/or.json
@@ -447,6 +447,7 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
}
}
diff --git a/manager/src/web/shared/locales/it/or.json b/manager/src/web/shared/locales/it/or.json
index 332ac95a2..1bedefb80 100644
--- a/manager/src/web/shared/locales/it/or.json
+++ b/manager/src/web/shared/locales/it/or.json
@@ -447,6 +447,7 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
}
}
diff --git a/manager/src/web/shared/locales/nl/or.json b/manager/src/web/shared/locales/nl/or.json
index 8abab0984..ee9b7f029 100644
--- a/manager/src/web/shared/locales/nl/or.json
+++ b/manager/src/web/shared/locales/nl/or.json
@@ -481,6 +481,7 @@
"assetTypeNone": "Geen",
"assetTypeMenuNone": "Geen",
"attributeLabel": "Attribuut",
- "attributeValueLabel": "Attribuutwaarde"
+ "attributeValueLabel": "Attribuutwaarde",
+ "assetTypeDoesNotExist": "Filter: Asset type bestaat niet"
}
}
diff --git a/manager/src/web/shared/locales/pt/or.json b/manager/src/web/shared/locales/pt/or.json
index bd096c9c7..586083159 100644
--- a/manager/src/web/shared/locales/pt/or.json
+++ b/manager/src/web/shared/locales/pt/or.json
@@ -435,6 +435,7 @@
"assetTypeNone": "None",
"assetTypeMenuNone": "None",
"attributeLabel": "Attribute",
- "attributeValueLabel": "Attribute value"
+ "attributeValueLabel": "Attribute value",
+ "assetTypeDoesNotExist": "Filter : Asset type does not exist"
}
}
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index d63e0f6dd..66a10406d 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -43,6 +43,7 @@ import {
} from "@openremote/or-mwc-components/or-mwc-dialog";
import {OrAddAssetDialog, OrAddChangedEvent} from "./or-add-asset-dialog";
import "./or-add-asset-dialog";
+import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";
export interface AssetTreeTypeConfig {
include?: string[];
@@ -485,6 +486,8 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
if (this._filter.assetType.length > 0) {
this._assetTypeFilter = this._filter.assetType[0];
+ } else {
+ this._assetTypeFilter = '';
}
}
}}"></or-icon>
@@ -493,7 +496,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
<div class="advanced-filter">
${this._assetTypes.length > 0 ? getContentWithMenuTemplate(
this.assetTypeSelect(),
- this.mapDescriptors(this._assetTypes, { text: i18next.t("filter.assetTypeMenuNone"), value: "", icon: "selection-ellipse" }),
+ this.mapDescriptors(this._assetTypes, { text: i18next.t("filter.assetTypeMenuNone"), value: "", icon: "selection-ellipse" }),
undefined,
(v: string[] | string) => {
this._assetTypeFilter = (v as string);
@@ -882,6 +885,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
const matchingVal: string = value.toString().substring(startIndex + 'attribute:'.length + 1, value.toString().length-1);
resultingFilter.attribute.push(matchingVal);
+ resultingFilter.attributeValue.push('');
});
}
@@ -903,7 +907,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
}
}
- matchingResult = searchValue.match(/(\"[^\s]+\")\:\S+/g);
+ matchingResult = searchValue.match(/(\"[^\"]+\")\:(([^\"\s]+)|(\"[^\"]+\"))/g);
if (matchingResult) {
if (matchingResult.length > 0) {
matchingResult.forEach((value: string, index: number) => {
@@ -911,10 +915,14 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
const startIndex: number = value.toString().indexOf('":');
// Adding 2 to remove the ": matched before
- const matchingVal: string = value.toString().substring(startIndex + 2);
+ let matchingVal: string = value.toString().substring(startIndex + 2);
// Starting from position 1 to remove first "
const matchingName: string = value.toString().substring(1, startIndex);
+ if (matchingVal[0] === '"' && matchingVal[matchingVal.length-1] === '"') {
+ matchingVal = matchingVal.substring(1,matchingVal.length-1);
+ }
+
resultingFilter.attribute.push(matchingName);
resultingFilter.attributeValue.push(matchingVal);
});
@@ -992,7 +1000,10 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
}
if ( this._attributeNameFilter.value && this._attributeValueFilter.value ) {
- const attributeValueValue: string = this._attributeValueFilter.value.replace(' ', '');
+ let attributeValueValue: string = this._attributeValueFilter.value;
+ if (attributeValueValue.includes(' ')) {
+ attributeValueValue = '"' + attributeValueValue + '"';
+ }
filter.attributeValue = [ attributeValueValue ];
} else {
filter.attributeValue = [];
@@ -1157,17 +1168,35 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
attributes: attributeCond
};
- const response = await manager.rest.api.AssetResource.queryAssets(query);
- const foundAssetIds: string[] = response.data.map((asset: Asset) => asset.id!);
+
+ let response: any;
+ let foundAssetIds: string[];
+
+ try {
+ response = await manager.rest.api.AssetResource.queryAssets(query);
+ foundAssetIds = response.data.map((asset: Asset) => asset.id!);
+ } catch (e) {
+ this._filter.assetType.forEach((assetT: string) => {
+ if(this._assetTypes.findIndex((assetD: AssetDescriptor) => { return assetD.name === assetT; }) === -1) {
+ showSnackbar(undefined, i18next.t('filter.assetTypeDoesNotExist'), i18next.t("dismiss"));
+ }
+ });
+ foundAssetIds = [];
+ }
return (asset) => {
let attrValueCheck = true;
if (this._filter.attribute.length > 0 && this._filter.attributeValue.length > 0 && foundAssetIds.includes(asset.id!)) {
- let attributeVal: [string, string][] = this._filter.attributeValue.map((value: string, index: number) => {
- return [this._filter.attribute[index], value];
+ let attributeVal: [string, string][] = [];
+
+ this._filter.attributeValue.forEach((attrVal: string, index: number) => {
+ if (attrVal.length > 0) {
+ attributeVal.push([this._filter.attribute[index], attrVal]);
+ }
});
+
let matchingAsset: Asset | undefined = response.data.find((a: Asset) => a.id === asset.id );
if (matchingAsset && matchingAsset.attributes) {
@@ -1194,6 +1223,11 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
if (currentAttributeVal[1].startsWith('=') && currentAttributeVal[1][1] !== '=') {
value = '=' + value;
}
+
+ if (/^[0-9]+$/.test(currentAttributeVal[1])) {
+ value = '==' + value;
+ }
+
const resultNumberEval: boolean = eval(attr.value + value);
if (resultNumberEval) {
@@ -1206,9 +1240,11 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
const multicharString: string = '*';
let parsedValue: string = unparsedValue.replace(multicharString, '.*');
+ parsedValue = parsedValue.replace(/"/g,'');
let valueFromAttribute: string = attr.value as string;
let answer = valueFromAttribute.match(parsedValue);
+
if (answer && answer.length > 0) {
atLeastOneAttributeMatchValue = true;
}
@@ -1227,6 +1263,10 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
};
}
+ protected isAnyFilter(): boolean {
+ return this._filter.asset !== undefined || this._filter.assetType.length > 0 || this._filter.attribute.length > 0;
+ }
+
protected filterTreeNode(currentNode: UiAssetTreeNode, matcher: (asset: Asset) => boolean, parentMatching: boolean = false): boolean {
let nodeOrDescendantMatches = matcher(currentNode.asset!);
currentNode.notMatchingFilter = !nodeOrDescendantMatches;
@@ -1235,8 +1275,9 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
return this.filterTreeNode(childNode, matcher, nodeOrDescendantMatches);
});
- nodeOrDescendantMatches = nodeOrDescendantMatches || childOrDescendantMatches.some(m => m);
- currentNode.expanded = nodeOrDescendantMatches && currentNode.children.length > 0;
+ let childMatches: boolean = childOrDescendantMatches.some(m => m);
+ nodeOrDescendantMatches = nodeOrDescendantMatches || childMatches;
+ currentNode.expanded = childMatches && currentNode.children.length > 0 && this.isAnyFilter();
currentNode.hidden = !nodeOrDescendantMatches && !parentMatching;
return nodeOrDescendantMatches;
}
@@ -1825,7 +1866,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
<div class="node-container draggable" node-asset-id="${treeNode.asset ? treeNode.asset.id : ''}" draggable="true" @dragleave=${(ev: DragEvent) => { this._onDragLeave(ev) }} @dragenter="${(ev: DragEvent) => this._onDragEnter(ev)}" @dragstart="${(ev: DragEvent) => this._onDragStart(ev)}" @dragend="${(ev: DragEvent) => this._onDragEnd(ev)}" @dragover="${(ev: DragEvent) => this._onDragOver(ev)}" style="padding-left: ${level * 22}px">
<div class="node-name">
<div class="expander" ?data-expandable="${treeNode.expandable}"></div>
- ${getAssetDescriptorIconTemplate(descriptor, undefined, undefined, (filterColorForNonMatchingAsset ? '#d3d3d3;' : undefined))}
+ ${getAssetDescriptorIconTemplate(descriptor, undefined, undefined, (filterColorForNonMatchingAsset ? 'd3d3d3' : undefined))}
<span style="color: ${filterColorForNonMatchingAsset ? '#d3d3d3;' : ''}">${treeNode.asset!.name}</span>
${this.checkboxes ? html`
<span class="mdc-list-item__graphic">
diff --git a/ui/component/or-asset-tree/src/style.ts b/ui/component/or-asset-tree/src/style.ts
index 7a93cf5a2..bed82443a 100644
--- a/ui/component/or-asset-tree/src/style.ts
+++ b/ui/component/or-asset-tree/src/style.ts
@@ -240,22 +240,6 @@ export const style = css`
#filterInput {
padding: 7px 12px 7px 7px;
}
-
- #clearIconContainer {
- position: absolute;
- right: 24px;
- padding-right: 14px;
- display: none;
- }
-
- #clearIcon {
- --or-icon-width: 20px;
- --or-icon-height: 20px;
- position: relative;
- right: 0;
- padding-right: 16px;
- cursor: pointer;
- }
#filterAssetTypeDownIcon {
width: 16px;
diff --git a/ui/component/or-mwc-components/src/or-mwc-input.ts b/ui/component/or-mwc-components/src/or-mwc-input.ts
index 9991c556f..805a64730 100644
--- a/ui/component/or-mwc-components/src/or-mwc-input.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts
@@ -592,10 +592,6 @@ const style = css`
.mdc-select__menu .mdc-list .mdc-list-item.mdc-list-item--selected or-icon {
--or-icon-fill: var(--or-app-color4);
}
-
- .or-label-with-icon {
- left: 42px !important;
- }
`;
@customElement("or-mwc-input")
@@ -852,7 +848,7 @@ export class OrMwcInput extends LitElement {
"mdc-text-field-helper-text--validation-msg": showValidationMessage,
};
const hasValue = this.value || this.value === false;
- let labelTemplate = showLabel ? html`<span class="mdc-floating-label ${hasValue ? "mdc-floating-label--float-above" : ""} ${!!this.icon && this.type === InputType.TEXT && hasValue ? "or-label-with-icon" : ""}" id="label">${this.label}</span>` : undefined;
+ let labelTemplate = showLabel ? html`<span class="mdc-floating-label ${hasValue ? "mdc-floating-label--float-above" : ""}" id="label">${this.label}</span>` : undefined;
switch (this.type) {
case InputType.RADIO:
@@ -1322,7 +1318,7 @@ export class OrMwcInput extends LitElement {
inputElem = html`
<label id="${componentId}" class="${classMap(classes)}">
- ${this.icon ? html`<or-icon class="mdc-text-field__icon mdc-text-field__icon--leading" style="--or-icon-fill: ${this.iconColor ? "#" + this.iconColor : "unset"}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}
+ ${this.icon ? html`<or-icon class="mdc-text-field__icon mdc-text-field__icon--leading" style="color: ${this.iconColor ? "#" + this.iconColor : "unset"}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}
${outlined ? `` : html`<span class="mdc-text-field__ripple"></span>`}
${inputElem}
${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}