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: Remember or-asset-tree expanded nodes between refreshes (Closes #557)

Rich Turner35a3869dbc04
diff --git a/test/src/main/resources/org/openremote/test/rules/ResidenceVacationMode.groovy b/test/src/main/resources/org/openremote/test/rules/ResidenceVacationMode.groovy
index 9a49fc536..f2b377222 100644
--- a/test/src/main/resources/org/openremote/test/rules/ResidenceVacationMode.groovy
+++ b/test/src/main/resources/org/openremote/test/rules/ResidenceVacationMode.groovy
@@ -6,7 +6,7 @@ import org.openremote.model.asset.impl.BuildingAsset
import org.openremote.model.query.AssetQuery
import org.openremote.model.query.filter.AttributePredicate
import org.openremote.model.query.filter.StringPredicate
-import org.openremote.model.query.filter.ValueNotEmptyPredicate
+import org.openremote.model.query.filter.ValueEmptyPredicate
import org.openremote.model.rules.AssetState
import org.openremote.model.rules.Assets
@@ -92,7 +92,7 @@ rules.add()
facts.matchFirstAssetState(
new AssetQuery().types(BuildingAsset)
.ids(vacationMode.residenceId)
- .attributes(new AttributePredicate(new StringPredicate("vacationUntil"), new ValueNotEmptyPredicate()))
+ .attributes(new AttributePredicate(new StringPredicate("vacationUntil"), new ValueEmptyPredicate().negate(true)))
).map { residence ->
vacationMode.until != residence.value.get()
}.orElse(false)
@@ -116,7 +116,7 @@ rules.add()
!facts.matchFirstAssetState(
new AssetQuery().types(BuildingAsset)
.ids(vacationMode.residenceId)
- .attributes(new AttributePredicate(new StringPredicate("vacationUntil"), new ValueNotEmptyPredicate()))).isPresent()
+ .attributes(new AttributePredicate(new StringPredicate("vacationUntil"), new ValueEmptyPredicate().negate(true)))).isPresent()
}.map { vacationMode ->
facts.bind("vacationMode", vacationMode)
true
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index 5a3eef57c..47df51295 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -266,6 +266,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
protected _loading: boolean = false;
protected _connected: boolean = false;
protected _selectedNodes: UiAssetTreeNode[] = [];
+ protected _expandedNodes: UiAssetTreeNode[] = [];
protected _initCallback?: EventCallback;
public get selectedNodes(): UiAssetTreeNode[] {
@@ -439,6 +440,21 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
nodes.forEach((node) => this._updateSort(node.children, sortFunction));
}
+ protected _toggleExpander(expander: HTMLElement, node: UiAssetTreeNode | null) {
+ if (node && node.expandable) {
+ node.expanded = !node.expanded;
+
+ if (node.expanded) {
+ this._expandedNodes.push(node);
+ } else {
+ this._expandedNodes = this._expandedNodes.filter(n => n !== node);
+ }
+
+ const elem = expander.parentElement!.parentElement!.parentElement!;
+ elem.toggleAttribute("data-expanded");
+ }
+ }
+
protected _onNodeClicked(evt: MouseEvent | null, node: UiAssetTreeNode | null) {
if (evt && evt.defaultPrevented) {
return;
@@ -452,11 +468,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
const isParentCheckbox = evt && (evt.target as OrIcon)?.icon?.includes("checkbox-multiple");
if (isExpander) {
- if (node && node.expandable) {
- node.expanded = !node.expanded;
- const elem = (evt!.target as HTMLElement).parentElement!.parentElement!.parentElement!;
- elem.toggleAttribute("data-expanded");
- }
+ this._toggleExpander((evt.target as HTMLElement), node);
} else {
let canSelect = true;
@@ -888,6 +900,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
}
protected _buildTreeNodes(assets: Asset[], sortFunction: (a: UiAssetTreeNode, b: UiAssetTreeNode) => number) {
+
if (!assets || assets.length === 0) {
this._nodes = [];
} else {
@@ -935,6 +948,16 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
rootAssets.sort(sortFunction);
rootAssets.forEach((rootAsset) => this._buildChildTreeNodes(rootAsset, assets, sortFunction));
this._nodes = rootAssets;
+ const newExpanded: UiAssetTreeNode[] = [];
+ this._expandedNodes.forEach(expandedNode => {
+ OrAssetTree._forEachNodeRecursive(this._nodes!, n => {
+ if (n.asset && expandedNode.asset && n.asset.id === expandedNode.asset.id) {
+ n.expanded = true;
+ newExpanded.push(n);
+ }
+ });
+ });
+ this._expandedNodes = newExpanded;
}
if (this.selectedIds && this.selectedIds.length > 0) {