@openremote/or-attribute-input 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -31
- package/dist/umd/index.js +770 -770
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +1801 -1801
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/agent-link-json-forms-renderer.js +87 -11
- package/lib/index.js +657 -94
- package/package.json +8 -8
|
@@ -1,12 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { rankWith, and, mapStateToControlProps, mapDispatchToControlProps, uiTypeIs, formatIs } from "@jsonforms/core";
|
|
2
|
+
import manager, { OREvent } from "@openremote/core";
|
|
3
|
+
import { getTemplateWrapper } from "@openremote/or-json-forms";
|
|
4
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
5
|
+
import { html } from "lit";
|
|
6
|
+
import "@openremote/or-mwc-components/or-mwc-input";
|
|
7
|
+
import { i18next } from "@openremote/or-translate";
|
|
8
|
+
import { until } from "lit/directives/until.js";
|
|
9
|
+
/**
|
|
10
|
+
* This function creates a short lived cache for loading the list of agents; this is useful when multiple instances
|
|
11
|
+
* of this control are used in a single UI
|
|
12
|
+
*/
|
|
13
|
+
let agents;
|
|
14
|
+
let loadingPromise;
|
|
15
|
+
let subscribed = false;
|
|
16
|
+
const timeout = 2000;
|
|
17
|
+
export function loadAgents() {
|
|
18
|
+
if (agents) {
|
|
19
|
+
return Promise.resolve(agents);
|
|
20
|
+
}
|
|
21
|
+
if (loadingPromise) {
|
|
22
|
+
return loadingPromise;
|
|
23
|
+
}
|
|
24
|
+
if (!subscribed) {
|
|
25
|
+
manager.addListener((ev) => {
|
|
26
|
+
switch (ev) {
|
|
27
|
+
case OREvent.DISPLAY_REALM_CHANGED:
|
|
28
|
+
agents = undefined;
|
|
29
|
+
loadingPromise = undefined;
|
|
30
|
+
break;
|
|
9
31
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
});
|
|
33
|
+
manager.events.subscribeAssetEvents(undefined, false, (assetEvent) => {
|
|
34
|
+
if (assetEvent.asset && assetEvent.asset.type.endsWith("Agent")) {
|
|
35
|
+
agents = undefined;
|
|
36
|
+
loadingPromise = undefined;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
subscribed = true;
|
|
40
|
+
}
|
|
41
|
+
loadingPromise = manager.rest.api.AssetResource.queryAssets({
|
|
42
|
+
realm: {
|
|
43
|
+
name: manager.displayRealm
|
|
44
|
+
},
|
|
45
|
+
types: [
|
|
46
|
+
"Agent"
|
|
47
|
+
],
|
|
48
|
+
select: {
|
|
49
|
+
attributes: []
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.then(response => response.data)
|
|
53
|
+
.then(agnts => {
|
|
54
|
+
agents = agnts;
|
|
55
|
+
return agnts;
|
|
56
|
+
});
|
|
57
|
+
return loadingPromise;
|
|
58
|
+
}
|
|
59
|
+
const agentIdTester = rankWith(6, and(uiTypeIs("Control"), formatIs("or-agent-id")));
|
|
60
|
+
const agentIdRenderer = (state, props) => {
|
|
61
|
+
props = Object.assign(Object.assign(Object.assign({}, props), mapStateToControlProps({ jsonforms: Object.assign({}, state) }, props)), mapDispatchToControlProps(state.dispatch));
|
|
62
|
+
const onAgentChanged = (agent) => {
|
|
63
|
+
props.handleChange(props.path, agent ? agent.id : undefined);
|
|
64
|
+
return;
|
|
65
|
+
};
|
|
66
|
+
const loadedTemplatePromise = loadAgents().then(agents => {
|
|
67
|
+
const options = agents.map(agent => [agent.id, agent.name + " (" + agent.id + ")"]);
|
|
68
|
+
return html `
|
|
69
|
+
<or-mwc-input .label="${i18next.t("agentId")}" required class="agent-id-picker" @or-mwc-input-changed="${(ev) => onAgentChanged(agents.find((agent) => agent.id === ev.detail.value))}" type="${InputType.SELECT}" .value="${props.data}" .placeholder="${i18next.t("selectAgent")}" .options="${options}"></or-mwc-input>
|
|
70
|
+
`;
|
|
71
|
+
});
|
|
72
|
+
const template = html `
|
|
73
|
+
<style>
|
|
74
|
+
.agent-id-picker {
|
|
75
|
+
min-width: 300px;
|
|
76
|
+
max-width: 600px;
|
|
77
|
+
width: 100%;
|
|
78
|
+
}
|
|
79
|
+
</style>
|
|
80
|
+
${until(loadedTemplatePromise, html `<or-mwc-input class="agent-id-picker" .type="${InputType.SELECT}"></or-mwc-input>`)}
|
|
81
|
+
`;
|
|
82
|
+
return getTemplateWrapper(template, undefined);
|
|
83
|
+
};
|
|
84
|
+
export const agentIdRendererRegistryEntry = {
|
|
85
|
+
tester: agentIdTester,
|
|
86
|
+
renderer: agentIdRenderer
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=agent-link-json-forms-renderer.js.map
|