@openremote/or-asset-viewer 1.3.0-snapshot.20250117092414 → 1.3.0-snapshot.20250117163435
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/component.stories.js +109 -0
- package/dist/umd/index.orbundle.js +3 -3
- package/package.json +15 -15
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { getWcStorybookHelpers } from "wc-storybook-helpers";
|
|
2
|
+
import openremote, {manager} from "@openremote/core";
|
|
3
|
+
import { html } from "lit";
|
|
4
|
+
import {OrAssetViewer} from "@openremote/or-asset-viewer";
|
|
5
|
+
|
|
6
|
+
const { events, args, argTypes, template } = getWcStorybookHelpers("or-asset-viewer");
|
|
7
|
+
|
|
8
|
+
/** @type { import('@storybook/web-components').Meta } */
|
|
9
|
+
const meta = {
|
|
10
|
+
title: "Playground/or-asset-viewer",
|
|
11
|
+
component: "or-asset-viewer",
|
|
12
|
+
args,
|
|
13
|
+
argTypes: {
|
|
14
|
+
...argTypes,
|
|
15
|
+
},
|
|
16
|
+
parameters: {
|
|
17
|
+
actions: {
|
|
18
|
+
handles: events
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** @type { import('@storybook/web-components').StoryObj } */
|
|
24
|
+
export const Primary = {
|
|
25
|
+
loaders: [
|
|
26
|
+
async (args) => ({
|
|
27
|
+
orAssetViewer: await loadOrAssetViewer(args.allArgs)
|
|
28
|
+
})
|
|
29
|
+
],
|
|
30
|
+
parameters: {
|
|
31
|
+
docs: {
|
|
32
|
+
source: {
|
|
33
|
+
code: getExampleCode()
|
|
34
|
+
},
|
|
35
|
+
story: {
|
|
36
|
+
height: "480px"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
render: (args, { loaded: { orAssetViewer }}) => html`${orAssetViewer}`
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/* ------------------------------------------------------- */
|
|
44
|
+
/* UTILITY FUNCTIONS */
|
|
45
|
+
/* ------------------------------------------------------- */
|
|
46
|
+
|
|
47
|
+
function getExampleCode() {
|
|
48
|
+
|
|
49
|
+
//language=javascript
|
|
50
|
+
return `
|
|
51
|
+
import openremote from "@openremote/core";
|
|
52
|
+
import "@openremote/or-asset-viewer";
|
|
53
|
+
|
|
54
|
+
// Wait for OpenRemote JS library initialization
|
|
55
|
+
await openremote.init({
|
|
56
|
+
managerUrl: "http://localhost:8080",
|
|
57
|
+
keycloakUrl: "http://localhost:8080/auth"
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Prompt login screen if necessary
|
|
61
|
+
if(!manager.authenticated) {
|
|
62
|
+
manager.login();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// (optional) Query an asset ID to show
|
|
67
|
+
const assets = (await manager.rest.api.AssetResource.queryAssets({
|
|
68
|
+
realm: { name: "master" }, // or any other realm
|
|
69
|
+
limit: 1
|
|
70
|
+
})).data;
|
|
71
|
+
const assetIds = assets.map(a => a.id);
|
|
72
|
+
|
|
73
|
+
// in your HTML code use this, and inject the ids;
|
|
74
|
+
<or-asset-viewer assetIds="{assetIds}"></or-asset-viewer>
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function loadOrAssetViewer(args) {
|
|
79
|
+
|
|
80
|
+
await manager.init({
|
|
81
|
+
managerUrl: "http://localhost:8080",
|
|
82
|
+
keycloakUrl: "http://localhost:8080/auth"
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if(!manager.authenticated) {
|
|
86
|
+
console.debug("Prompting login!");
|
|
87
|
+
manager.login();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const assets = (await manager.rest.api.AssetResource.queryAssets({
|
|
92
|
+
realm: { name: "master" },
|
|
93
|
+
limit: 1
|
|
94
|
+
})).data;
|
|
95
|
+
const assetIds = assets.map(a => a.id);
|
|
96
|
+
|
|
97
|
+
const newArgs = Object.fromEntries(Object.entries(args).filter(([key, value]) => (
|
|
98
|
+
value != null && String(value).length > 0
|
|
99
|
+
)));
|
|
100
|
+
|
|
101
|
+
const orAssetViewer = Object.assign(new OrAssetViewer(), newArgs);
|
|
102
|
+
if(!orAssetViewer.id) {
|
|
103
|
+
orAssetViewer.id = assetIds[0];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return orAssetViewer;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default meta;
|