Skip to content

armgit / core

Public Imported from GitHub
0

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

UI: Bugfix for agents not showing asset import and protocol discovery panels when both supported (#2180)

Rich Turnerf78a6fbffd54
diff --git a/setup/src/integration/java/org/openremote/setup/integration/protocol/MockProtocol.java b/setup/src/integration/java/org/openremote/setup/integration/protocol/MockProtocol.java
index 96ce2c288..4dc356221 100644
--- a/setup/src/integration/java/org/openremote/setup/integration/protocol/MockProtocol.java
+++ b/setup/src/integration/java/org/openremote/setup/integration/protocol/MockProtocol.java
@@ -29,17 +29,19 @@ import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.attribute.AttributeRef;
import org.openremote.model.attribute.AttributeState;
import org.openremote.model.protocol.ProtocolAssetDiscovery;
+import org.openremote.model.protocol.ProtocolAssetImport;
import org.openremote.model.value.ValueType;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.function.Consumer;
/**
* A mock protocol for testing purposes that records the various method calls and supports protocol discovery
*/
-public class MockProtocol extends AbstractProtocol<MockAgent, MockAgentLink> implements ProtocolAssetDiscovery {
+public class MockProtocol extends AbstractProtocol<MockAgent, MockAgentLink> implements ProtocolAssetDiscovery, ProtocolAssetImport {
public static final String PROTOCOl_NAME = "Mock protocol";
public List<AttributeEvent> protocolWriteAttributeEvents = new ArrayList<>();
@@ -162,4 +164,9 @@ public class MockProtocol extends AbstractProtocol<MockAgent, MockAgentLink> imp
return null;
});
}
+
+ @Override
+ public Future<Void> startAssetImport(byte[] fileData, Consumer<AssetTreeNode[]> assetConsumer) {
+ return CompletableFuture.completedFuture(null);
+ }
}
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 3ebc260c3..69df8f93f 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -45,6 +45,7 @@ import {OrEditAssetModifiedEvent, OrEditAssetPanel, ValidatorResult} from "./or-
import "@openremote/or-mwc-components/or-mwc-snackbar";
import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";
import {progressCircular} from "@openremote/or-mwc-components/style";
+import { when } from "lit/directives/when.js";
export interface PanelConfig {
type: "info" | "setup" | "history" | "group" | "survey" | "survey-results" | "linkedUsers" | "alarm.linkedAlarms";
@@ -517,10 +518,12 @@ function getPanelContent(id: string, assetInfo: AssetInfo, hostElement: LitEleme
}
}
- let content: TemplateResult = html``;
+ if (!descriptor.assetImport && !descriptor.assetDiscovery) {
+ showSnackbar(undefined, "agent type doesn't support a known protocol to add assets", "dismiss");
+ }
- if (descriptor.assetImport) {
- content = html`
+ return html`
+ ${when(descriptor.assetImport, () => html`
<div id="fileupload">
<or-mwc-input style="flex: 0 1 auto;" outlined label="selectFile" .type="${InputType.BUTTON}" @or-mwc-input-changed="${() => hostElement.shadowRoot!.getElementById('fileupload-elem')!.click()}">
<input id="fileupload-elem" name="configfile" type="file" accept=".*" @change="${() => updateFileName()}"/>
@@ -529,24 +532,13 @@ function getPanelContent(id: string, assetInfo: AssetInfo, hostElement: LitEleme
<or-mwc-input style="flex: 0 1 auto;" id="fileupload-btn" icon="upload" .type="${InputType.BUTTON}" @or-mwc-input-changed="${() => doImport()}" disabled></or-mwc-input>
<progress id="progress-circular" class="hidden pure-material-progress-circular"></progress>
</div>
- `;
- }
- else if (descriptor.assetDiscovery) {
- content = html`
- <or-mwc-input outlined id="discover-btn" .type="${InputType.BUTTON}" label="discoverAssets" @or-mwc-input-changed="${() => discoverAssets()}"></or-mwc-input>
- <or-mwc-input id="cancel-discover-btn" .type="${InputType.BUTTON}" label="cancel" @or-mwc-input-changed="${() => cancelDiscovery()}" hidden style="margin-left:20px"></or-mwc-input>
- `;
- } else {
- showSnackbar(undefined, "agent type doesn't support a known protocol to add assets", "dismiss");
- }
-
- return html`
- <style>
- [hidden] {
- display: none;
- }
- </style>
- ${content}
+ `)}
+ ${when(descriptor.assetDiscovery, () => html`
+ <div id="discovery">
+ <or-mwc-input outlined id="discover-btn" .type="${InputType.BUTTON}" label="discoverAssets" @or-mwc-input-changed="${() => discoverAssets()}"></or-mwc-input>
+ <or-mwc-input id="cancel-discover-btn" .type="${InputType.BUTTON}" label="cancel" @or-mwc-input-changed="${() => cancelDiscovery()}" hidden style="margin-left:20px"></or-mwc-input>
+ </div>
+ `)}
`;
}
diff --git a/ui/component/or-asset-viewer/src/style.ts b/ui/component/or-asset-viewer/src/style.ts
index 6103c29d2..fe871d1df 100644
--- a/ui/component/or-asset-viewer/src/style.ts
+++ b/ui/component/or-asset-viewer/src/style.ts
@@ -256,13 +256,14 @@ export const style = css`
display: none;
cursor: pointer;
}
-
- #fileupload {
+
+ #fileupload, #discovery {
display: flex;
align-items: center;
width: 100%;
+ margin-bottom: 10px;
}
-
+
.hidden {
display: none;
}