Skip to content

armgit / core

Public Imported from GitHub
0

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

Feature/asset tree filter improvement (#648)

Jérôme Vervier1e2bab756f02
diff --git a/manager/src/web/shared/locales/ar/or.json b/manager/src/web/shared/locales/ar/or.json
index d61f09627..9e7d77aeb 100644
--- a/manager/src/web/shared/locales/ar/or.json
+++ b/manager/src/web/shared/locales/ar/or.json
@@ -388,5 +388,13 @@
},
"readPermissions": "صلاحيات القراءة",
"writePermissions": "صلاحيات الكتابة",
- "valueType": "نوع القيمة"
+ "valueType": "نوع القيمة",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/cn/or.json b/manager/src/web/shared/locales/cn/or.json
index 528ed8ef1..407a11c10 100644
--- a/manager/src/web/shared/locales/cn/or.json
+++ b/manager/src/web/shared/locales/cn/or.json
@@ -437,5 +437,13 @@
"keyAlreadyExists": "Key already exists"
},
"yes": "是的",
- "no": "不"
+ "no": "不",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/de/or.json b/manager/src/web/shared/locales/de/or.json
index a50dbf9a4..ac0937a7c 100644
--- a/manager/src/web/shared/locales/de/or.json
+++ b/manager/src/web/shared/locales/de/or.json
@@ -463,5 +463,13 @@
}
},
"yes": "Ja",
- "no": "Nein"
+ "no": "Nein",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.json
index a4f25ab38..09838a139 100644
--- a/manager/src/web/shared/locales/en/or.json
+++ b/manager/src/web/shared/locales/en/or.json
@@ -470,5 +470,13 @@
"invalidEmail": "Invalid email address",
"yes": "Yes",
"no": "No",
- "linked": "Linked"
+ "linked": "Linked",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/es/or.json b/manager/src/web/shared/locales/es/or.json
index 8c083edab..edf43816f 100644
--- a/manager/src/web/shared/locales/es/or.json
+++ b/manager/src/web/shared/locales/es/or.json
@@ -437,5 +437,13 @@
"keyAlreadyExists": "La clave ya existe"
},
"yes": "Sí",
- "no": "No"
+ "no": "No",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/fr/or.json b/manager/src/web/shared/locales/fr/or.json
index 3b73c4867..127de4148 100644
--- a/manager/src/web/shared/locales/fr/or.json
+++ b/manager/src/web/shared/locales/fr/or.json
@@ -437,5 +437,13 @@
"keyAlreadyExists": "La clé existe déjà"
},
"yes": "Oui",
- "no": "Non"
+ "no": "Non",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/it/or.json b/manager/src/web/shared/locales/it/or.json
index fdda402ae..e59cf6618 100644
--- a/manager/src/web/shared/locales/it/or.json
+++ b/manager/src/web/shared/locales/it/or.json
@@ -437,5 +437,13 @@
"keyAlreadyExists": "La chiave non esiste"
},
"yes": "Sì",
- "no": "No"
+ "no": "No",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/nl/or.json b/manager/src/web/shared/locales/nl/or.json
index 262450a8b..a79da948b 100644
--- a/manager/src/web/shared/locales/nl/or.json
+++ b/manager/src/web/shared/locales/nl/or.json
@@ -465,5 +465,13 @@
}
},
"yes": "Ja",
- "no": "Nee"
+ "no": "Nee",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/manager/src/web/shared/locales/pt/or.json b/manager/src/web/shared/locales/pt/or.json
index 2baec3442..a31ff0c7e 100644
--- a/manager/src/web/shared/locales/pt/or.json
+++ b/manager/src/web/shared/locales/pt/or.json
@@ -425,5 +425,13 @@
"keyAlreadyExists": "A chave já existe"
},
"yes": "Sim",
- "no": "Não"
+ "no": "Não",
+ "filter": {
+ "action": "FILTER",
+ "assetTypeLabel": "Asset type",
+ "assetTypeNone": "None",
+ "assetTypeMenuNone": "None",
+ "attributeLabel": "Attribute",
+ "attributeValueLabel": "Attribute value"
+ }
}
diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.ts
index cb93a05c4..df8a24eba 100644
--- a/ui/component/core/src/util.ts
+++ b/ui/component/core/src/util.ts
@@ -269,6 +269,19 @@ export function arrayRemove<T>(arr: T[], item: T) {
}
}
+export function sentenceCaseToCamelCase(str: string | undefined): string {
+ if (str === undefined || str === null) {
+ return "";
+ }
+
+ return str.split(' ').map((value: string, index: number): string => {
+ if (index === 0) {
+ return value[0].toLowerCase() + value.substring(1);
+ }
+ return value[0].toUpperCase() + value.substring(1);
+ }).join('');
+}
+
export function camelCaseToSentenceCase(str: string | undefined): string {
if (str === undefined || str === null) {
return "";
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index c57721608..8726d6a1d 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -1,4 +1,4 @@
-import {html, LitElement, PropertyValues, TemplateResult} from "lit";
+import {html, css, LitElement, PropertyValues, TemplateResult} from "lit";
import {customElement, property, query, state} from "lit/decorators.js";
import "@openremote/or-mwc-components/or-mwc-input";
import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";
@@ -9,6 +9,10 @@ import {
AssetEvent,
AssetEventCause,
AssetQuery,
+ StringPredicate,
+ LogicGroup,
+ AttributePredicate,
+ LogicGroupOperator,
AssetQueryMatch,
AssetsEvent,
AssetTreeNode,
@@ -112,6 +116,10 @@ export class OrAssetTreeSelectionEvent extends CustomEvent<NodeSelectEventDetail
}
}
+enum FilterElementType {
+ SEARCH_FILTER, ASSET_TYPE,ATTRIBUTE_NAME, ATTRIBUTE_VALUE
+}
+
export type AddEventDetail = {
sourceAsset?: Asset;
asset: Asset;
@@ -175,6 +183,20 @@ export class OrAssetTreeAssetEvent extends CustomEvent<AssetEvent> {
}
}
+export class OrAssetTreeFilter {
+ asset: string | undefined;
+ assetType: string[];
+ attribute: string[];
+ attributeValue: string[];
+
+ constructor() {
+ this.asset = undefined;
+ this.assetType = [];
+ this.attribute = [];
+ this.attributeValue = [];
+ }
+}
+
declare global {
export interface HTMLElementEventMap {
[OrAssetTreeRequestSelectionEvent.NAME]: OrAssetTreeRequestSelectionEvent;
@@ -271,12 +293,24 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
protected _expandedNodes: UiAssetTreeNode[] = [];
protected _initCallback?: EventCallback;
- protected _filterValue?: string;
+ @state()
+ protected _filter: OrAssetTreeFilter = new OrAssetTreeFilter();
protected _searchInputTimer?: number = undefined;
- @query("#clearIcon")
- protected _clearIcon!: HTMLElement;
+ @query("#clearIconContainer")
+ protected _clearIconContainer!: HTMLElement;
@query("#filterInput")
protected _filterInput!: OrMwcInput;
+ @query("#asset-tree-filter-setting")
+ protected _filterSetting!: HTMLElement;
+ @state()
+ protected _assetTypes: AssetDescriptor[] = [];
+ @query("#attributeNameFilter")
+ protected _attributeNameFilter!: OrMwcInput;
+ @query("#attributeValueFilter")
+ protected _attributeValueFilter!: OrMwcInput;
+ @state()
+ protected _assetTypeFilter!: string;
+ protected _uniqueAssetTypes: string[] = [];
public get selectedNodes(): UiAssetTreeNode[] {
return this._selectedNodes ? [...this._selectedNodes] : [];
@@ -314,6 +348,60 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
return false;
}
+ protected mapDescriptors(descriptors: (AssetDescriptor)[], withNoneValue?: ListItem): ListItem[] {
+ let items: ListItem[] = descriptors.map((descriptor) => {
+ return {
+ styleMap: {
+ "--or-icon-fill": descriptor.colour ? "#" + descriptor.colour : "unset"
+ },
+ icon: descriptor.icon,
+ text: Util.getAssetTypeLabel(descriptor),
+ value: descriptor.name!,
+ data: descriptor
+ }
+ }).sort(Util.sortByString((listItem) => listItem.text));
+
+ if (withNoneValue) {
+ items.splice(0,0, withNoneValue);
+ }
+
+ return items;
+ }
+
+
+
+ protected getSelectHeader(): TemplateResult {
+ return html `<or-mwc-input style="width:100%;" ?disabled="${this._loading}" type="${InputType.TEXT}" .label="${i18next.t("filter.assetTypeLabel")}" iconTrailing="menu-down" iconColor="rgba(0, 0, 0, 0.87)" icon="selection-ellipse" value="${i18next.t("filter.assetTypeNone")}"></or-mwc-input>`;
+ }
+
+ protected getSelectedHeader(descriptor: AssetDescriptor): TemplateResult {
+ return html `<or-mwc-input style="width:100%;" ?disabled="${this._loading}" type="${InputType.TEXT}" .label="${i18next.t("filter.assetTypeLabel")}" .iconColor="${descriptor.colour}" iconTrailing="menu-down" icon="${descriptor.icon}" value="${Util.getAssetTypeLabel(descriptor)}"></or-mwc-input>`;
+ }
+
+ protected assetTypeSelect(): TemplateResult {
+ if (this._assetTypeFilter) {
+ const descriptor: AssetDescriptor | undefined = this._assetTypes.find((at: AssetDescriptor) => { return at.name === this._assetTypeFilter });
+ if (descriptor) {
+ return this.getSelectedHeader(descriptor);
+ } else {
+ return this.getSelectHeader();
+ }
+ } else {
+ return this.getSelectHeader();
+ }
+ }
+
+
+ protected atLeastOneNodeToBeShown(): boolean {
+ let atLeastOne: boolean = false;
+ this._nodes?.forEach((value: UiAssetTreeNode) => {
+ if (!value.hidden) {
+ atLeastOne = true;
+ }
+ });
+ return atLeastOne;
+ }
+
protected render() {
return html`
<div id="header">
@@ -346,27 +434,102 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
outlined="true"
@input="${(e: KeyboardEvent) => {
// Means some input is occurring so delay filter
- this._onFilterInput(e);
+ this._onFilterInputEvent(e);
}}"
@or-mwc-input-changed="${ (e: OrInputChangedEvent) => {
// Means field has lost focus so do filter immediately
- this._doFiltering((e.detail.value as string) || undefined);
- }}">
+ this._onFilterInput((e.detail.value as string) || undefined, true);
+ }}"
+ trailingSpace="true">
</or-mwc-input>
- <or-icon id="clearIcon" icon="close" @click="${() => {
- // Wipe the current value and hide the clear button
- this._filterInput.value = undefined;
- this._clearIcon.classList.remove("visible");
-
- // Call filtering
- this._doFiltering(undefined);
+ <div id="clearIconContainer">
+ <or-icon id="clearIcon" icon="close" @click="${() => {
+ // Wipe the current value and hide the clear button
+ this._filterInput.value = undefined;
+ this._clearIconContainer.classList.remove("visible");
+
+ this._attributeValueFilter.value = undefined;
+ this._attributeNameFilter.value = undefined;
+
+ this._attributeValueFilter.disabled = true;
+
+ this._assetTypeFilter = '';
+
+ this._filter = new OrAssetTreeFilter();
+
+ // Call filtering
+ this._doFiltering();
+ }}"></or-icon>
+ </div>
+ <or-icon id="filterSettingsIcon" icon="tune" @click="${() => {
+ if ( this._filterSetting.classList.contains("visible") ) {
+ this._filterSetting.classList.remove("visible");
+ } else {
+ this._filterSetting.classList.add("visible");
+ // Avoid to build again the types
+ if ( this._assetTypes.length === 0 ) {
+ let usedTypes: string[] = [];
+ const types = this._getAllowedChildTypes(this._selectedNodes[0]);
+ this._assetTypes = types.filter((t) => t.descriptorType === "asset");
+ }
+
+ if (this._filter.attribute.length > 0) {
+ this._attributeNameFilter.value = this._filter.attribute[0];
+ }
+
+ if (this._filter.attributeValue.length > 0 && this._filter.attribute.length > 0) {
+ this._attributeValueFilter.disabled = false;
+ this._attributeValueFilter.value = this._filter.attributeValue[0];
+ }
+
+ if (this._filter.assetType.length > 0) {
+ this._assetTypeFilter = this._filter.assetType[0];
+ }
+ }
}}"></or-icon>
</div>
+ <div id="asset-tree-filter-setting">
+ <div class="advanced-filter">
+ ${this._assetTypes.length > 0 ? getContentWithMenuTemplate(
+ this.assetTypeSelect(),
+ this.mapDescriptors(this._assetTypes, { text: i18next.t("filter.assetTypeMenuNone"), value: "", icon: "selection-ellipse" }),
+ undefined,
+ (v: string[] | string) => {
+ this._assetTypeFilter = (v as string);
+ },
+ undefined,
+ false,
+ true,
+ true) : html ``
+ }
+ <or-mwc-input id="attributeNameFilter" .label="${i18next.t("filter.attributeLabel")}"
+
+ .type="${InputType.TEXT}"
+ style="margin-top: 14px;"
+ ?disabled="${this._loading}"
+ @input="${(e: KeyboardEvent) => {
+ this._shouldEnableAttrTypeEvent(e);
+ }}"
+ @or-mwc-input-changed="${ (e: OrInputChangedEvent) => {
+ this._shouldEnableAttrType((e.detail.value as string) || undefined);
+ }}"></or-mwc-input>
+ <or-mwc-input id="attributeValueFilter" .label="${i18next.t("filter.attributeValueLabel")}"
+
+ .type="${InputType.TEXT}"
+ style="margin-top: 14px;"
+ disabled></or-mwc-input>
+ <div>
+ <or-mwc-input style="float: right;" style="margin-top: 14px;" type="${ InputType.BUTTON }" .label="${i18next.t("filter.action")}" raised @click="${() => {
+ this._filterFromSettings();
+ }}"></or-mwc-input>
+ </div>
+ </div>
+ </div>
${!this._nodes
? html`
<span id="loading"><or-translate value="loading"></or-translate></span>`
- : (this._nodes.length === 0
+ : ((this._nodes.length === 0 || !this.atLeastOneNodeToBeShown())
? html `<span id="noAssetsFound"><or-translate value="noAssetsFound"></or-translate></span>`
: html`
<div id="list-container">
@@ -575,30 +738,212 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
this._onNodeClicked(null, null);
}
- protected _onFilterInput(e: KeyboardEvent) {
- // Use composed path to get event source within shadow DOM
+ protected parseFromInputFilter(inputValue?: string): OrAssetTreeFilter {
+ let searchValue: string | undefined = this._filterInput.value;
+ if (inputValue) {
+ searchValue = inputValue;
+ }
+ let resultingFilter: OrAssetTreeFilter = new OrAssetTreeFilter();
+
+ if (searchValue) {
+ let asset: string = searchValue;
+ let matchingResult: RegExpMatchArray | null = searchValue.match(/(attribute\:)(\"[^"]+\")\S*/g);
+ if (matchingResult) {
+ if (matchingResult.length > 0) {
+ matchingResult.forEach((value: string, index: number) => {
+ asset = asset.replace(value, '');
+
+ const startIndex: number = value.toString().indexOf('attribute:');
+
+ const matchingVal: string = value.toString().substring(startIndex + 'attribute:'.length + 1, value.toString().length-1);
+
+ resultingFilter.attribute.push(matchingVal);
+ });
+ }
+
+ this._attributeValueFilter.disabled = false;
+ }
+
+ matchingResult = searchValue.match(/(type\:)\S+/g);
+ if (matchingResult) {
+ if (matchingResult.length > 0) {
+ matchingResult.forEach((value: string, index: number) => {
+ asset = asset.replace(value, '');
+
+ const startIndex: number = value.toString().indexOf('type:');
+
+ const matchingVal: string = value.toString().substring(startIndex + 'type:'.length);
+
+ resultingFilter.assetType.push(matchingVal);
+ });
+ }
+ }
+
+ matchingResult = searchValue.match(/(\"[^\s]+\")\:\S+/g);
+ if (matchingResult) {
+ if (matchingResult.length > 0) {
+ matchingResult.forEach((value: string, index: number) => {
+ asset = asset.replace(value, '');
+
+ const startIndex: number = value.toString().indexOf('":');
+ // Adding 2 to remove the ": matched before
+ const matchingVal: string = value.toString().substring(startIndex + 2);
+ // Starting from position 1 to remove first "
+ const matchingName: string = value.toString().substring(1, startIndex);
+
+ resultingFilter.attribute.push(matchingName);
+ resultingFilter.attributeValue.push(matchingVal);
+ });
+ }
+ }
+ resultingFilter.asset = (asset && asset.length > 0) ? asset.trim() : undefined;
+ }
+
+ return resultingFilter;
+ }
+
+ protected formatFilter(newFilter: OrAssetTreeFilter): string {
+ let searchInput: string = newFilter.asset ? newFilter.asset : '';
+
+ let prefix: string = newFilter.asset ? ' ' : '';
+
+ let handledAttributeForValues: string[] = [];
+
+ if (newFilter.assetType.length > 0) {
+ newFilter.assetType.forEach((assetType: string) => {
+ searchInput += prefix + 'type:' + assetType;
+ prefix = ' ';
+ });
+ }
+
+ if (newFilter.attribute.length > 0 && newFilter.attributeValue.length > 0) {
+ newFilter.attributeValue.forEach((attributeValue: string, index: number) => {
+ handledAttributeForValues.push(newFilter.attribute[index]);
+ searchInput += prefix + '"' + newFilter.attribute[index] + '":' + attributeValue;
+ prefix = ' ';
+ });
+ }
+
+ if (newFilter.attribute.length > 0 && newFilter.attributeValue.length === 0) {
+ newFilter.attribute.forEach((attributeName: string) => {
+ if (!handledAttributeForValues.includes(attributeName)) {
+ searchInput += prefix + 'attribute:"' + attributeName + '"';
+ prefix = ' ';
+ }
+ });
+ }
+
+ return searchInput;
+ }
+
+ protected _shouldEnableAttrTypeEvent(e: KeyboardEvent): void {
+ let value: string | undefined;
+
+ if (e.composedPath()) {
+ value = ((e.composedPath()[0] as HTMLInputElement).value) || undefined;
+ }
+
+ this._shouldEnableAttrType(value);
+ }
+
+ protected _shouldEnableAttrType(value: string | undefined): void {
+ if (value) {
+ this._attributeValueFilter.disabled = false;
+ } else {
+ this._attributeValueFilter.disabled = true;
+ }
+ }
+
+ protected applySettingFields(filter: OrAssetTreeFilter): OrAssetTreeFilter {
+ if ( this._assetTypeFilter ) {
+ filter.assetType = [ this._assetTypeFilter ];
+ } else {
+ filter.assetType = [];
+ }
+
+ if ( this._attributeNameFilter.value ) {
+ filter.attribute = [ this._attributeNameFilter.value ];
+ } else {
+ filter.attribute = [];
+ }
+
+ if ( this._attributeNameFilter.value && this._attributeValueFilter.value ) {
+ const attributeValueValue: string = this._attributeValueFilter.value.replace(' ', '');
+ filter.attributeValue = [ attributeValueValue ];
+ } else {
+ filter.attributeValue = [];
+ }
+
+ return filter;
+ }
+
+ protected _filterFromSettings(): void {
+ let filterFromSearchInput: OrAssetTreeFilter = this.parseFromInputFilter();
+
+ let filterFromSearchInputWithSettings: OrAssetTreeFilter = this.applySettingFields(filterFromSearchInput);
+
+ this._filter = filterFromSearchInputWithSettings;
+
+ let newFilterForSearchInput: string = this.formatFilter(this._filter);
+
+ if (newFilterForSearchInput) {
+ this._clearIconContainer.classList.add("visible");
+ } else {
+ this._clearIconContainer.classList.remove("visible");
+ }
+
+ this._filterInput.value = newFilterForSearchInput;
+
+ this._filterSetting.classList.remove("visible");
+
+ this._doFiltering();
+ }
+
+ protected _onFilterInputEvent(e: KeyboardEvent) {
let value: string | undefined;
if (e.composedPath()) {
value = ((e.composedPath()[0] as HTMLInputElement).value) || undefined;
if (value) {
- this._clearIcon.classList.add("visible");
+ this._clearIconContainer.classList.add("visible");
} else {
- this._clearIcon.classList.remove("visible");
+ this._clearIconContainer.classList.remove("visible");
}
}
+ this._onFilterInput(value, false);
+ }
+
+ protected _onFilterInput(newValue: string | undefined, force: boolean): void {
+ if (newValue) {
+ this._clearIconContainer.classList.add("visible");
+ } else {
+ this._clearIconContainer.classList.remove("visible");
+ }
+
+ let currentFilter: OrAssetTreeFilter = this.parseFromInputFilter(newValue);
+
+ if (Util.objectsEqual(this._filter, currentFilter,true)) {
+ return;
+ }
+
+ this._filter = currentFilter;
+
if (this._searchInputTimer) {
clearTimeout(this._searchInputTimer);
}
- this._searchInputTimer = window.setTimeout(() => {
- this._doFiltering(value);
- }, 300);
+ if (!force) {
+ this._searchInputTimer = window.setTimeout(() => {
+ this._doFiltering();
+ }, 1500);
+ } else {
+ this._doFiltering();
+ }
}
- protected async _doFiltering(value?: string) {
+ protected async _doFiltering() {
// Clear timeout in case we got here from value change
if (this._searchInputTimer) {
clearTimeout(this._searchInputTimer);
@@ -607,14 +952,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
if (this.isConnected && this._nodes) {
- if (this._filterValue === value) {
- // This value has already been filtered so ignore or is not having the minimal number of characters
- return;
- }
-
- this._filterValue = value;
-
- if (!this._filterValue) {
+ if (!this._filter.asset && !this._filter.attribute && !this._filter.assetType && !this._filter.attributeValue) {
// Clear the filter
OrAssetTree._forEachNodeRecursive(this._nodes!, (node) => {
node.notMatchingFilter = false;
@@ -628,14 +966,22 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
// Use a matcher function - this can be altered independent of the filtering logic
// Maybe we should just filter in memory for basic matches like name
- this.getMatcher(false).then((matcher: (asset: Asset) => boolean) => {
- if (this._nodes) {
- this._nodes.forEach((node: UiAssetTreeNode) => {
- this.filterTreeNode(node, matcher);
- });
- this.disabled = false;
+ if (this._filter.asset || this._filter.assetType || this._filter.attribute) {
+ let queryRequired: boolean = false;
+
+ if (this._filter.attribute) {
+ queryRequired = true;
}
- });
+
+ this.getMatcher(queryRequired).then((matcher: (asset: Asset) => boolean) => {
+ if (this._nodes) {
+ this._nodes.forEach((node: UiAssetTreeNode) => {
+ this.filterTreeNode(node, matcher);
+ });
+ this.disabled = false;
+ }
+ });
+ }
}
}
@@ -649,42 +995,145 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
protected async getSimpleNameMatcher(): Promise<((asset: Asset) => boolean)> {
return (asset) => {
- return asset.name!.toLowerCase().includes(this._filterValue!.toLowerCase());
+ let match: boolean = true;
+ if (this._filter.asset) {
+ match = match && asset.name!.toLowerCase().includes(this._filter.asset.toLowerCase());
+ }
+
+ if (this._filter.assetType.length > 0) {
+ match = match && (asset.type!.toLowerCase() === this._filter.assetType[0].toLowerCase());
+ }
+ return match;
};
}
protected async getMatcherFromQuery(): Promise<((asset: Asset) => boolean)> {
- const query: AssetQuery = {
- select: {
- attributes: []
- },
- names: [{
+ let assetCond: StringPredicate[] | undefined = undefined;
+ let attributeCond: LogicGroup<AttributePredicate> | undefined = undefined;
+ let assetTypeCond: string[] | undefined = undefined;
+
+ if (this._filter.asset) {
+ assetCond = [{
predicateType: "string",
match: AssetQueryMatch.CONTAINS,
- value: this._filterValue,
+ value: this._filter.asset,
caseSensitive: false
- }]
+ }];
+ }
+
+ if (this._filter.assetType.length > 0) {
+ assetTypeCond = this._filter.assetType;
+ }
+
+ if (this._filter.attribute.length > 0) {
+ attributeCond = {
+ operator: LogicGroupOperator.AND,
+ items:
+ this._filter.attribute.map((attributeName: string) => {
+ return {
+ name: {
+ predicateType: "string",
+ match: AssetQueryMatch.EXACT,
+ value: Util.sentenceCaseToCamelCase(attributeName),
+ caseSensitive: false
+ }
+ };
+ })
+ }
+ }
+
+ const query: AssetQuery = {
+ select: {
+ excludePath: true,
+ excludeAttributes: attributeCond ? false : true,
+ excludeParentInfo: true
+ },
+ names: assetCond,
+ types: assetTypeCond,
+ attributes: attributeCond
};
const response = await manager.rest.api.AssetResource.queryAssets(query);
+
const foundAssetIds: string[] = response.data.map((asset: Asset) => asset.id!);
return (asset) => {
- return foundAssetIds.includes(asset.id!);
+ 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 matchingAsset: Asset | undefined = response.data.find((a: Asset) => a.id === asset.id );
+
+ if (matchingAsset && matchingAsset.attributes) {
+ for (let attributeValIndex = 0; attributeValIndex < attributeVal.length; attributeValIndex++ ) {
+ let currentAttributeVal = attributeVal[attributeValIndex];
+
+ let atLeastOneAttributeMatchValue: boolean = false;
+ Object.keys(matchingAsset.attributes).forEach((key: string) => {
+ let attr: Attribute<any> = matchingAsset!.attributes![key];
+
+ // attr.value check to avoid to compare with empty/non existing value
+ if (attr.name!.toLowerCase() === currentAttributeVal[0].toLowerCase() && attr.value) {
+ switch (attr.type!) {
+ case "number":
+ case "integer":
+ case "long":
+ case "bigInteger":
+ case "bigNumber":
+ case "positiveInteger":
+ case "negativeInteger":
+ case "positiveNumber":
+ case "negativeNumber":
+ let value: string = currentAttributeVal[1];
+ if (currentAttributeVal[1].startsWith('=') && currentAttributeVal[1][1] !== '=') {
+ value = '=' + value;
+ }
+ const resultNumberEval: boolean = eval(attr.value + value);
+
+ if (resultNumberEval) {
+ atLeastOneAttributeMatchValue = true;
+ }
+ break;
+ case "text":
+ if (attr.value) {
+ let unparsedValue: string = currentAttributeVal[1];
+ const multicharString: string = '*';
+
+ let parsedValue: string = unparsedValue.replace(multicharString, '.*');
+
+ let valueFromAttribute: string = attr.value as string;
+ let answer = valueFromAttribute.match(parsedValue);
+ if (answer && answer.length > 0) {
+ atLeastOneAttributeMatchValue = true;
+ }
+ }
+ break;
+ }
+ }
+ });
+
+ attrValueCheck = atLeastOneAttributeMatchValue;
+ }
+ }
+ }
+
+ return foundAssetIds.includes(asset.id!) && attrValueCheck;
};
}
- protected filterTreeNode(currentNode: UiAssetTreeNode, matcher: (asset: Asset) => boolean): boolean {
+ protected filterTreeNode(currentNode: UiAssetTreeNode, matcher: (asset: Asset) => boolean, parentMatching: boolean = false): boolean {
let nodeOrDescendantMatches = matcher(currentNode.asset!);
currentNode.notMatchingFilter = !nodeOrDescendantMatches;
const childOrDescendantMatches = currentNode.children.map((childNode) => {
- return this.filterTreeNode(childNode, matcher);
+ return this.filterTreeNode(childNode, matcher, nodeOrDescendantMatches);
});
nodeOrDescendantMatches = nodeOrDescendantMatches || childOrDescendantMatches.some(m => m);
currentNode.expanded = nodeOrDescendantMatches && currentNode.children.length > 0;
- currentNode.hidden = !nodeOrDescendantMatches;
+ currentNode.hidden = !nodeOrDescendantMatches && !parentMatching;
return nodeOrDescendantMatches;
}
@@ -1042,7 +1491,11 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
assets.push(node.asset!);
}
});
- this._buildTreeNodes(assets, this._getSortFunction());
+
+ // In case of filter already active, do not override the actual state of assetTree
+ if ( !this._filterInput.value ) {
+ this._buildTreeNodes(assets, this._getSortFunction());
+ }
this.dispatchEvent(new OrAssetTreeAssetEvent(assetEvent));
}
}
diff --git a/ui/component/or-asset-tree/src/style.ts b/ui/component/or-asset-tree/src/style.ts
index 3e4d0384f..accac65bb 100644
--- a/ui/component/or-asset-tree/src/style.ts
+++ b/ui/component/or-asset-tree/src/style.ts
@@ -222,12 +222,20 @@ export const style = css`
display: flex;
align-items: center;
position: relative;
+ background-color: #F9F9F9;
}
#filterInput {
padding: 7px 10px;
}
+ #clearIconContainer {
+ position: absolute;
+ right: 24px;
+ padding-right: 14px;
+ display: none;
+ }
+
#clearIcon {
--or-icon-width: 20px;
--or-icon-height: 20px;
@@ -235,10 +243,49 @@ export const style = css`
right: 0;
padding-right: 16px;
cursor: pointer;
+ }
+
+ #filterAssetTypeDownIcon {
+ width: 16px;
+ height: 16px;
+ position: absolute;
+ right: 20px;
+ padding-right: 14px;
+ cursor: pointer;
+ }
+
+ #filterSettingsIcon {
+ cursor: pointer;
+ margin-right: 5px;
+ }
+
+ #asset-tree-filter-setting {
+ position: absolute;
+ background-color: #F9F9F9;
+ top: calc(var(--internal-or-asset-tree-header-height) + var(--internal-or-header-height, 50px) - 1px);
display: none;
+ width: 300px;
+ z-index: 100;
+ box-shadow: rgb(0 0 0 / 21%) 0px 1px 3px 0px;
+ box-sizing: border-box;
+ padding: 5px;
+ }
+
+ #asset-tree-filter-setting .advanced-filter {
+ display: flex;
+ flex-direction: column;
+ }
+
+ #asset-tree-filter-setting.visible {
+ display: block;
+ }
+
+ .filterAssetType {
+ display: flex;
+ align-items: center;
}
- #clearIcon.visible {
+ #clearIconContainer.visible {
display: block;
}
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 1854ef373..d4e12554e 100644
--- a/ui/component/or-mwc-components/src/or-mwc-input.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts
@@ -590,6 +590,14 @@ 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;
+ }
+
+ .or-trailing-space {
+ width: 78%;
+ }
`;
@customElement("or-mwc-input")
@@ -687,6 +695,9 @@ export class OrMwcInput extends LitElement {
@property({type: String})
public icon?: string;
+ @property({type: String})
+ public iconColor?: string;
+
@property({type: String})
public iconOn?: string;
@@ -756,6 +767,9 @@ export class OrMwcInput extends LitElement {
@property({type: Boolean})
public resizeVertical: boolean = false;
+ @property({type: Boolean})
+ public trailingSpace: boolean = false;
+
/* TEXT INPUT STYLES END */
protected _mdcComponent?: MDCComponent<any>;
@@ -837,7 +851,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" : ""}" id="label">${this.label}</span>` : undefined;
+ 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;
switch (this.type) {
case InputType.RADIO:
@@ -1269,7 +1283,7 @@ export class OrMwcInput extends LitElement {
@change="${(e: Event) => this.onValueChange((e.target as HTMLTextAreaElement), (e.target as HTMLTextAreaElement).value)}">${valMinMax[0] ? valMinMax[0] : ""}</textarea>`
: html`
<input type="${type}" id="elem" aria-labelledby="${ifDefined(label ? "label" : undefined)}"
- class="mdc-text-field__input" ?required="${this.required}" ?readonly="${this.readonly}"
+ class="mdc-text-field__input ${this.trailingSpace ? "or-trailing-space" : ""}" ?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)}" pattern="${ifDefined(this.pattern)}"
maxlength="${ifDefined(this.maxLength)}" placeholder="${ifDefined(this.placeHolder)}"
@@ -1283,7 +1297,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" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}
+ ${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>` : ``}
${outlined ? `` : html`<span class="mdc-text-field__ripple"></span>`}
${inputElem}
${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}
diff --git a/ui/component/or-mwc-components/src/or-mwc-list.ts b/ui/component/or-mwc-components/src/or-mwc-list.ts
index d62c288ff..5e346968b 100644
--- a/ui/component/or-mwc-components/src/or-mwc-list.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-list.ts
@@ -197,7 +197,7 @@ export function getItemTemplate(item: ListItem | null, index: number, selectedVa
}
return html`
- <li @click="${(e: MouseEvent) => itemClickCallback && itemClickCallback(e, item)}" style="${listItem.styleMap ? styleMap(listItem.styleMap) : ""}" class="mdc-list-item ${isSelected ? selectedClassName : ""}" role="${ifDefined(role)}" tabindex="${ifDefined(tabIndex)}" aria-checked="${ifDefined(ariaChecked)}" aria-selected="${ifDefined(ariaSelected)}" data-value="${value}">
+ <li @click="${(e: MouseEvent) => { itemClickCallback && itemClickCallback(e, item)}}" style="${listItem.styleMap ? styleMap(listItem.styleMap) : ""}" class="mdc-list-item ${isSelected ? selectedClassName : ""}" role="${ifDefined(role)}" tabindex="${ifDefined(tabIndex)}" aria-checked="${ifDefined(ariaChecked)}" aria-selected="${ifDefined(ariaSelected)}" data-value="${value}">
<span class="mdc-list-item__ripple"></span>
${leftTemplate}
${textTemplate}
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 b37739013..f729763e8 100644
--- a/ui/component/or-mwc-components/src/or-mwc-menu.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-menu.ts
@@ -50,7 +50,7 @@ declare global {
}
}
-export function getContentWithMenuTemplate(content: TemplateResult, menuItems: (ListItem | ListItem[] | null)[], selectedValues: any[] | any, valueChangedCallback: (values: any[] | any) => void, closedCallback?: () => void, multiSelect = false, translateValues = true): TemplateResult {
+export function getContentWithMenuTemplate(content: TemplateResult, menuItems: (ListItem | ListItem[] | null)[], selectedValues: string[] | string | undefined, valueChangedCallback: (values: string[] | string) => void, closedCallback?: () => void, multiSelect = false, translateValues = true, midHeight = false): TemplateResult {
const openMenu = (evt: Event) => {
if (!menuItems) {
@@ -63,7 +63,7 @@ export function getContentWithMenuTemplate(content: TemplateResult, menuItems: (
return html`
<span>
<span @click="${openMenu}">${content}</span>
- ${menuItems ? html`<or-mwc-menu ?multiselect="${multiSelect}" @or-mwc-menu-closed="${() => {if (closedCallback) { closedCallback(); }} }" @or-mwc-menu-changed="${(evt: OrMwcMenuChangedEvent) => {if (valueChangedCallback) { valueChangedCallback(evt.detail); }} }" .translateValues="${translateValues}" .values="${selectedValues}" .menuItems="${menuItems}" id="menu"></or-mwc-menu>` : ``}
+ ${menuItems ? html`<or-mwc-menu ?multiselect="${multiSelect}" @or-mwc-menu-closed="${() => {if (closedCallback) { closedCallback(); }} }" @or-mwc-menu-changed="${(evt: OrMwcMenuChangedEvent) => {if (valueChangedCallback) { valueChangedCallback(evt.detail); }} }" .translateValues="${translateValues}" .values="${selectedValues}" .menuItems="${menuItems}" .midHeight="${midHeight}" id="menu"></or-mwc-menu>` : ``}
</span>
`;
}
@@ -89,6 +89,9 @@ const style = css`
color: rgba(0, 0, 0, 0.87);
}
+ .mdc-menu-surface-mid-height {
+ max-height: calc(50vh - 32px) !important;
+ }
`;
@customElement("or-mwc-menu")
@@ -118,6 +121,9 @@ export class OrMwcMenu extends LitElement {
@property({type: Boolean, attribute: true})
public translateValues?: boolean;
+ @property({type: Boolean, attribute: false})
+ public midHeight?: boolean;
+
@query("#wrapper")
protected _wrapperElem!: HTMLElement;
@@ -149,7 +155,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 mdc-menu-surface ${this.midHeight ? "mdc-menu-surface-mid-height" : ""}" id="menu" @MDCMenuSurface:closed="${this._onMenuClosed}">
${getListTemplate(ListType.MULTI_TICK, content, isTwoLine, "menu")}
</div>
</div>