@openremote/or-asset-viewer 1.2.0-snapshot.20240512154942
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 +87 -0
- package/lib/index.d.ts +248 -0
- package/lib/index.js +174 -0
- package/lib/index.js.map +1 -0
- package/lib/or-add-attribute-panel.d.ts +33 -0
- package/lib/or-add-attribute-panel.js +14 -0
- package/lib/or-add-attribute-panel.js.map +1 -0
- package/lib/or-edit-asset-panel.d.ts +42 -0
- package/lib/or-edit-asset-panel.js +248 -0
- package/lib/or-edit-asset-panel.js.map +1 -0
- package/lib/style.d.ts +2 -0
- package/lib/style.js +328 -0
- package/lib/style.js.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @openremote/or-asset-viewer \<or-asset-viewer\>
|
|
2
|
+
[![NPM Version][npm-image]][npm-url]
|
|
3
|
+
[![Linux Build][travis-image]][travis-url]
|
|
4
|
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
5
|
+
|
|
6
|
+
Web Component for displaying an asset tree. This component requires an OpenRemote Manager to retrieve, save and query assets.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
```bash
|
|
10
|
+
npm i @openremote/or-asset-viewer
|
|
11
|
+
yarn add @openremote/or-asset-viewer
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
By default the or-asset-viewer is using a 2 columns grid. This can be changed by using a different config.
|
|
16
|
+
|
|
17
|
+
4 column grid, 25% for each column:
|
|
18
|
+
```javascript
|
|
19
|
+
const viewerConfig = {
|
|
20
|
+
viewerStyles: {
|
|
21
|
+
gridTemplateColumns: "repeat(auto-fill, minmax(calc(25%),1fr))";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
<or-asset-viewer .config="${viewerConfig}"></or-asset-viewer>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
The position of a panel can also be changed by changing the config of or-asset-viewer
|
|
29
|
+
|
|
30
|
+
To change the width of a panel use gridColumn:
|
|
31
|
+
```javascript
|
|
32
|
+
const viewerConfig = {
|
|
33
|
+
panels: {
|
|
34
|
+
"info": {
|
|
35
|
+
type: "property",
|
|
36
|
+
panelStyles: {
|
|
37
|
+
gridColumn: "1 / -1" // same as 1 / 3 in a 2 column grid: Start on column 1, End on column 3
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
gridColumn can also be used to change the position horizontaly.
|
|
45
|
+
```javascript
|
|
46
|
+
const viewerConfig = {
|
|
47
|
+
panels: {
|
|
48
|
+
"info": {
|
|
49
|
+
type: "property",
|
|
50
|
+
panelStyles: {
|
|
51
|
+
gridColumnStart: "2" // start the panel in the second column
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
To change the vertical position of a panel use gridRowStart. To start the panel on the first row set gridRowStart to 1:
|
|
59
|
+
```javascript
|
|
60
|
+
const viewerConfig = {
|
|
61
|
+
panels: {
|
|
62
|
+
"info": {
|
|
63
|
+
type: "property",
|
|
64
|
+
panelStyles: {
|
|
65
|
+
gridRowStart: "1"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
For a full list of properties, methods and options refer to the TypeDoc generated [documentation]().
|
|
73
|
+
|
|
74
|
+
## Supported Browsers
|
|
75
|
+
The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition,
|
|
76
|
+
Internet Explorer 11 is also supported.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
[GNU AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)
|
|
81
|
+
|
|
82
|
+
[npm-image]: https://img.shields.io/npm/v/live-xxx.svg
|
|
83
|
+
[npm-url]: https://npmjs.org/package/@openremote/or-asset-list
|
|
84
|
+
[travis-image]: https://img.shields.io/travis/live-js/live-xxx/master.svg
|
|
85
|
+
[travis-url]: https://travis-ci.org/live-js/live-xxx
|
|
86
|
+
[coveralls-image]: https://img.shields.io/coveralls/live-js/live-xxx/master.svg
|
|
87
|
+
[coveralls-url]: https://coveralls.io/r/live-js/live-xxx?branch=master
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { LitElement, PropertyValues, TemplateResult } from "lit";
|
|
2
|
+
import "@openremote/or-icon";
|
|
3
|
+
import "@openremote/or-mwc-components/or-mwc-input";
|
|
4
|
+
import "@openremote/or-attribute-input";
|
|
5
|
+
import "@openremote/or-attribute-history";
|
|
6
|
+
import "@openremote/or-chart";
|
|
7
|
+
import "@openremote/or-mwc-components/or-mwc-table";
|
|
8
|
+
import "@openremote/or-components/or-panel";
|
|
9
|
+
import "@openremote/or-mwc-components/or-mwc-dialog";
|
|
10
|
+
import "@openremote/or-mwc-components/or-mwc-list";
|
|
11
|
+
import { InputType, OrMwcInput } from "@openremote/or-mwc-components/or-mwc-input";
|
|
12
|
+
import { Util } from "@openremote/core";
|
|
13
|
+
import { OrChartConfig } from "@openremote/or-chart";
|
|
14
|
+
import { HistoryConfig } from "@openremote/or-attribute-history";
|
|
15
|
+
import { Asset, Attribute, SharedEvent } from "@openremote/model";
|
|
16
|
+
import { InitOptions } from "i18next";
|
|
17
|
+
import "./or-edit-asset-panel";
|
|
18
|
+
import { OrEditAssetPanel, ValidatorResult } from "./or-edit-asset-panel";
|
|
19
|
+
import "@openremote/or-mwc-components/or-mwc-snackbar";
|
|
20
|
+
export interface PanelConfig {
|
|
21
|
+
type: "info" | "setup" | "history" | "group" | "survey" | "survey-results" | "linkedUsers";
|
|
22
|
+
title?: string;
|
|
23
|
+
hide?: boolean;
|
|
24
|
+
column?: number;
|
|
25
|
+
hideOnMobile?: boolean;
|
|
26
|
+
panelStyles?: {
|
|
27
|
+
[style: string]: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface InfoPanelItemConfig {
|
|
31
|
+
label?: string;
|
|
32
|
+
hideOnMobile?: boolean;
|
|
33
|
+
readonly?: boolean;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
disableButton?: boolean;
|
|
36
|
+
disableHelperText?: boolean;
|
|
37
|
+
inputTypeOverride?: InputType;
|
|
38
|
+
fullWidth?: boolean;
|
|
39
|
+
priority?: number;
|
|
40
|
+
styles?: {
|
|
41
|
+
[style: string]: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface InfoPanelConfig extends PanelConfig {
|
|
45
|
+
type: "info";
|
|
46
|
+
attributes: {
|
|
47
|
+
include?: string[];
|
|
48
|
+
exclude?: string[];
|
|
49
|
+
itemConfig?: {
|
|
50
|
+
[name: string]: InfoPanelItemConfig;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
properties: {
|
|
54
|
+
include?: string[];
|
|
55
|
+
exclude?: string[];
|
|
56
|
+
itemConfig?: {
|
|
57
|
+
[name: string]: InfoPanelItemConfig;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface SetupPanelConfig extends PanelConfig {
|
|
62
|
+
type: "setup";
|
|
63
|
+
}
|
|
64
|
+
export interface HistoryPanelConfig extends PanelConfig {
|
|
65
|
+
type: "history";
|
|
66
|
+
include?: string[];
|
|
67
|
+
exclude?: string[];
|
|
68
|
+
}
|
|
69
|
+
export interface GroupPanelConfig extends PanelConfig {
|
|
70
|
+
type: "group";
|
|
71
|
+
childAssetTypes?: {
|
|
72
|
+
[assetType: string]: {
|
|
73
|
+
availableAttributes?: string[];
|
|
74
|
+
selectedAttributes?: string[];
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export interface AssetViewerConfig {
|
|
79
|
+
panels?: PanelConfigUnion[];
|
|
80
|
+
viewerStyles?: {
|
|
81
|
+
[style: string]: string;
|
|
82
|
+
};
|
|
83
|
+
propertyViewProvider?: PropertyViewProvider;
|
|
84
|
+
attributeViewProvider?: AttributeViewProvider;
|
|
85
|
+
panelViewProvider?: PanelViewProvider;
|
|
86
|
+
historyConfig?: HistoryConfig;
|
|
87
|
+
chartConfig?: OrChartConfig;
|
|
88
|
+
}
|
|
89
|
+
export type PanelConfigUnion = InfoPanelConfig | SetupPanelConfig | GroupPanelConfig | HistoryPanelConfig | PanelConfig;
|
|
90
|
+
export interface ViewerConfig {
|
|
91
|
+
default?: AssetViewerConfig;
|
|
92
|
+
assetTypes?: {
|
|
93
|
+
[assetType: string]: AssetViewerConfig;
|
|
94
|
+
};
|
|
95
|
+
historyConfig?: HistoryConfig;
|
|
96
|
+
}
|
|
97
|
+
interface UserAssetLinkInfo {
|
|
98
|
+
userId: string;
|
|
99
|
+
usernameAndId: string;
|
|
100
|
+
roles: string[];
|
|
101
|
+
restrictedUser: boolean;
|
|
102
|
+
}
|
|
103
|
+
interface AssetInfo {
|
|
104
|
+
asset: Asset;
|
|
105
|
+
userAssetLinks?: UserAssetLinkInfo[];
|
|
106
|
+
childAssets?: Asset[];
|
|
107
|
+
viewerConfig: AssetViewerConfig;
|
|
108
|
+
modified: boolean;
|
|
109
|
+
attributeTemplateMap: {
|
|
110
|
+
[attrName: string]: TemplateResult;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export type PanelViewProvider = (asset: Asset, attributes: {
|
|
114
|
+
[index: string]: Attribute<any>;
|
|
115
|
+
}, panelName: string, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfigUnion) => TemplateResult | undefined;
|
|
116
|
+
export type PropertyViewProvider = (asset: Asset, property: string, value: any, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfigUnion) => TemplateResult | undefined;
|
|
117
|
+
export type AttributeViewProvider = (asset: Asset, attribute: Attribute<any>, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfigUnion) => TemplateResult | undefined;
|
|
118
|
+
export declare function getIncludedProperties(config?: InfoPanelConfig): string[];
|
|
119
|
+
export declare function getIncludedAttributes(attributes: {
|
|
120
|
+
[index: string]: Attribute<any>;
|
|
121
|
+
}, config?: InfoPanelConfig): Attribute<any>[];
|
|
122
|
+
export declare class OrAssetViewerComputeGridEvent extends CustomEvent<void> {
|
|
123
|
+
static readonly NAME = "or-asset-viewer-compute-grid-event";
|
|
124
|
+
constructor();
|
|
125
|
+
}
|
|
126
|
+
export type SaveResult = {
|
|
127
|
+
success: boolean;
|
|
128
|
+
assetId: string;
|
|
129
|
+
isNew?: boolean;
|
|
130
|
+
isCopy?: boolean;
|
|
131
|
+
};
|
|
132
|
+
export declare class OrAssetViewerRequestSaveEvent extends CustomEvent<Util.RequestEventDetail<Asset>> {
|
|
133
|
+
static readonly NAME = "or-asset-viewer-request-save";
|
|
134
|
+
constructor(asset: Asset);
|
|
135
|
+
}
|
|
136
|
+
export declare class OrAssetViewerSaveEvent extends CustomEvent<SaveResult> {
|
|
137
|
+
static readonly NAME = "or-asset-viewer-save";
|
|
138
|
+
constructor(saveResult: SaveResult);
|
|
139
|
+
}
|
|
140
|
+
export declare class OrAssetViewerChangeParentEvent extends CustomEvent<{
|
|
141
|
+
parentId: string | undefined;
|
|
142
|
+
assetsIds: string[];
|
|
143
|
+
}> {
|
|
144
|
+
static readonly NAME = "or-asset-viewer-change-parent";
|
|
145
|
+
constructor(parent: string | undefined, assetsIds: string[]);
|
|
146
|
+
}
|
|
147
|
+
export declare class OrAssetViewerRequestEditToggleEvent extends CustomEvent<Util.RequestEventDetail<boolean>> {
|
|
148
|
+
static readonly NAME = "or-asset-viewer-request-edit-toggle";
|
|
149
|
+
constructor(edit: boolean);
|
|
150
|
+
}
|
|
151
|
+
export declare class OrAssetViewerEditToggleEvent extends CustomEvent<boolean> {
|
|
152
|
+
static readonly NAME = "or-asset-viewer-edit-toggle";
|
|
153
|
+
constructor(edit: boolean);
|
|
154
|
+
}
|
|
155
|
+
export declare class OrAssetViewerLoadUserEvent extends CustomEvent<string> {
|
|
156
|
+
static readonly NAME = "or-asset-viewer-load-user-event";
|
|
157
|
+
constructor(userId: string);
|
|
158
|
+
}
|
|
159
|
+
declare global {
|
|
160
|
+
export interface HTMLElementEventMap {
|
|
161
|
+
[OrAssetViewerComputeGridEvent.NAME]: OrAssetViewerComputeGridEvent;
|
|
162
|
+
[OrAssetViewerRequestSaveEvent.NAME]: OrAssetViewerRequestSaveEvent;
|
|
163
|
+
[OrAssetViewerSaveEvent.NAME]: OrAssetViewerSaveEvent;
|
|
164
|
+
[OrAssetViewerRequestEditToggleEvent.NAME]: OrAssetViewerRequestEditToggleEvent;
|
|
165
|
+
[OrAssetViewerEditToggleEvent.NAME]: OrAssetViewerEditToggleEvent;
|
|
166
|
+
[OrAssetViewerChangeParentEvent.NAME]: OrAssetViewerChangeParentEvent;
|
|
167
|
+
[OrAssetViewerLoadUserEvent.NAME]: OrAssetViewerLoadUserEvent;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export declare function getPanel(id: string, panelConfig: PanelConfig, content: TemplateResult | undefined): TemplateResult<1> | undefined;
|
|
171
|
+
export declare function getAttributeTemplate(asset: Asset, attribute: Attribute<any>, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, itemConfig: InfoPanelItemConfig): TemplateResult;
|
|
172
|
+
export declare function getPropertyTemplate(asset: Asset, property: string, hostElement: LitElement, viewerConfig: AssetViewerConfig | undefined, panelConfig: PanelConfig | undefined, itemConfig: InfoPanelItemConfig): TemplateResult;
|
|
173
|
+
export declare function getField(name: string, itemConfig?: InfoPanelItemConfig, content?: TemplateResult): TemplateResult;
|
|
174
|
+
export declare function saveAsset(asset: Asset): Promise<SaveResult>;
|
|
175
|
+
export declare const DEFAULT_ASSET_PROPERTIES: string[];
|
|
176
|
+
export declare const DEFAULT_VIEWER_CONFIG: AssetViewerConfig;
|
|
177
|
+
declare const OrAssetViewer_base: (new (...args: any[]) => {
|
|
178
|
+
_connectRequested: boolean;
|
|
179
|
+
_subscriptionIds?: string[] | undefined;
|
|
180
|
+
_assetIds?: string[] | undefined;
|
|
181
|
+
_attributeRefs?: import("@openremote/model").AttributeRef[] | undefined;
|
|
182
|
+
_status: import("@openremote/core").EventProviderStatus;
|
|
183
|
+
_statusCallback: (status: import("@openremote/core").EventProviderStatus) => void;
|
|
184
|
+
connectedCallback(): void;
|
|
185
|
+
disconnectedCallback(): void;
|
|
186
|
+
connectEvents(): void;
|
|
187
|
+
disconnectEvents(): void;
|
|
188
|
+
_doConnect(): Promise<void>;
|
|
189
|
+
readonly eventsConnected: boolean;
|
|
190
|
+
_onEventProviderStatusChanged(status: import("@openremote/core").EventProviderStatus): void;
|
|
191
|
+
_onEventsConnect(): void;
|
|
192
|
+
_onEventsDisconnect(): void;
|
|
193
|
+
_addEventSubscriptions(): Promise<void>;
|
|
194
|
+
_removeEventSubscriptions(): void;
|
|
195
|
+
_refreshEventSubscriptions(): void;
|
|
196
|
+
assetIds: string[] | undefined;
|
|
197
|
+
attributeRefs: import("@openremote/model").AttributeRef[] | undefined;
|
|
198
|
+
_sendEvent(event: SharedEvent): void;
|
|
199
|
+
_sendEventWithReply<U extends SharedEvent, V extends SharedEvent>(event: import("@openremote/model").EventRequestResponseWrapper<U>): Promise<V>;
|
|
200
|
+
onEventsConnect(): void;
|
|
201
|
+
onEventsDisconnect(): void;
|
|
202
|
+
_onEvent(event: SharedEvent): void;
|
|
203
|
+
requestUpdate(name?: PropertyKey | undefined, oldValue?: unknown): void;
|
|
204
|
+
readonly isConnected: boolean;
|
|
205
|
+
}) & (new (...args: any[]) => {
|
|
206
|
+
_i18nextJustInitialized: boolean;
|
|
207
|
+
connectedCallback(): void;
|
|
208
|
+
disconnectedCallback(): void;
|
|
209
|
+
shouldUpdate(changedProps: import("lit").PropertyValueMap<any> | Map<PropertyKey, unknown>): any;
|
|
210
|
+
initCallback: (options: InitOptions) => void;
|
|
211
|
+
langChangedCallback: () => void;
|
|
212
|
+
readonly isConnected: boolean;
|
|
213
|
+
}) & typeof LitElement;
|
|
214
|
+
export declare class OrAssetViewer extends OrAssetViewer_base {
|
|
215
|
+
static get styles(): import("lit").CSSResult[];
|
|
216
|
+
asset?: Asset;
|
|
217
|
+
ids: string[] | undefined;
|
|
218
|
+
config?: ViewerConfig;
|
|
219
|
+
editMode?: boolean;
|
|
220
|
+
readonly?: boolean;
|
|
221
|
+
protected _assetInfo?: AssetInfo;
|
|
222
|
+
protected _validationResults: ValidatorResult[];
|
|
223
|
+
protected wrapperElem: HTMLDivElement;
|
|
224
|
+
protected saveBtnElem: OrMwcInput;
|
|
225
|
+
protected editBtnElem: OrMwcInput;
|
|
226
|
+
protected editor: OrEditAssetPanel;
|
|
227
|
+
protected headerElem: HTMLDivElement;
|
|
228
|
+
protected containerElem: HTMLDivElement;
|
|
229
|
+
protected _saveResult?: SaveResult;
|
|
230
|
+
constructor();
|
|
231
|
+
isModified(): boolean | undefined;
|
|
232
|
+
shouldUpdate(changedProperties: PropertyValues): boolean;
|
|
233
|
+
updated(_changedProperties: PropertyValues): void;
|
|
234
|
+
loadAssetInfo(asset: Asset): Promise<AssetInfo>;
|
|
235
|
+
protected _doValidation(): void;
|
|
236
|
+
protected _onParentChangeClick(): void;
|
|
237
|
+
protected render(): TemplateResult | void;
|
|
238
|
+
protected _toggleHeaderShadow(): void;
|
|
239
|
+
protected _isReadonly(): boolean;
|
|
240
|
+
protected _onEditToggleClicked(edit: boolean): void;
|
|
241
|
+
protected _doEditToggle(edit: boolean): void;
|
|
242
|
+
protected _onSaveClicked(): void;
|
|
243
|
+
protected _doSave(): Promise<void>;
|
|
244
|
+
protected _onAssetModified(validationResults: ValidatorResult[]): void;
|
|
245
|
+
_onEvent(event: SharedEvent): void;
|
|
246
|
+
protected _getPanelConfig(asset: Asset): AssetViewerConfig;
|
|
247
|
+
}
|
|
248
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,s,i){var o,r=arguments.length,n=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,s,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(n=(r<3?o(n):r>3?o(t,s,n):o(t,s))||n);return r>3&&n&&Object.defineProperty(t,s,n),n},__awaiter=this&&this.__awaiter||function(e,t,s,i){return new(s||(s=Promise))((function(o,r){function n(e){try{l(i.next(e))}catch(e){r(e)}}function a(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(n,a)}l((i=i.apply(e,t||[])).next())}))};import{html,LitElement,unsafeCSS}from"lit";import{customElement,property,query,state}from"lit/decorators.js";import"@openremote/or-icon";import"@openremote/or-mwc-components/or-mwc-input";import"@openremote/or-attribute-input";import"@openremote/or-attribute-history";import"@openremote/or-chart";import"@openremote/or-mwc-components/or-mwc-table";import"@openremote/or-components/or-panel";import"@openremote/or-mwc-components/or-mwc-dialog";import{OrMwcDialog,showDialog,showOkCancelDialog,showOkDialog}from"@openremote/or-mwc-components/or-mwc-dialog";import"@openremote/or-mwc-components/or-mwc-list";import{translate}from"@openremote/or-translate";import{InputType}from"@openremote/or-mwc-components/or-mwc-input";import manager,{subscribe,Util,DefaultColor5}from"@openremote/core";import{AssetModelUtil}from"@openremote/model";import{panelStyles,style}from"./style";import i18next from"i18next";import{styleMap}from"lit/directives/style-map.js";import{classMap}from"lit/directives/class-map.js";import"./or-edit-asset-panel";import{OrEditAssetModifiedEvent}from"./or-edit-asset-panel";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";export function getIncludedProperties(e){const t=e&&e.properties&&e.properties.include?e.properties.include:DEFAULT_ASSET_PROPERTIES,s=e&&e.properties&&e.properties.exclude?e.properties.exclude:[];return t.filter((e=>!s||s.indexOf(e)<0))}export function getIncludedAttributes(e,t){const s=t&&t.attributes&&t.attributes.include?t.attributes.include:void 0,i=t&&t.attributes&&t.attributes.exclude?t.attributes.exclude:void 0;return s||i?Object.values(e).filter((e=>(!s||s.some((t=>Util.stringMatch(t,e.name))))&&(!i||!i.some((t=>Util.stringMatch(t,e.name)))))):Object.values(e)}export class OrAssetViewerComputeGridEvent extends CustomEvent{constructor(){super(OrAssetViewerComputeGridEvent.NAME,{bubbles:!0,composed:!0})}}OrAssetViewerComputeGridEvent.NAME="or-asset-viewer-compute-grid-event";export class OrAssetViewerRequestSaveEvent extends CustomEvent{constructor(e){super(OrAssetViewerRequestSaveEvent.NAME,{bubbles:!0,composed:!0,detail:{allow:!0,detail:e}})}}OrAssetViewerRequestSaveEvent.NAME="or-asset-viewer-request-save";export class OrAssetViewerSaveEvent extends CustomEvent{constructor(e){super(OrAssetViewerSaveEvent.NAME,{bubbles:!0,composed:!0,detail:e})}}OrAssetViewerSaveEvent.NAME="or-asset-viewer-save";export class OrAssetViewerChangeParentEvent extends CustomEvent{constructor(e,t){super(OrAssetViewerChangeParentEvent.NAME,{bubbles:!0,composed:!0,detail:{parentId:e,assetsIds:t}})}}OrAssetViewerChangeParentEvent.NAME="or-asset-viewer-change-parent";export class OrAssetViewerRequestEditToggleEvent extends CustomEvent{constructor(e){super(OrAssetViewerRequestEditToggleEvent.NAME,{bubbles:!0,composed:!0,detail:{allow:!0,detail:e}})}}OrAssetViewerRequestEditToggleEvent.NAME="or-asset-viewer-request-edit-toggle";export class OrAssetViewerEditToggleEvent extends CustomEvent{constructor(e){super(OrAssetViewerEditToggleEvent.NAME,{bubbles:!0,composed:!0,detail:e})}}OrAssetViewerEditToggleEvent.NAME="or-asset-viewer-edit-toggle";export class OrAssetViewerLoadUserEvent extends CustomEvent{constructor(e){super(OrAssetViewerLoadUserEvent.NAME,{bubbles:!0,composed:!0,detail:e})}}OrAssetViewerLoadUserEvent.NAME="or-asset-viewer-load-user-event";export function getPanel(e,t,s){if(s)return html`
|
|
2
|
+
<div class=${classMap({panel:!0,mobileHidden:!0===t.hideOnMobile})} style="${t&&t.panelStyles?styleMap(t.panelStyles):""}" id="${e}-panel">
|
|
3
|
+
<div class="panel-content-wrapper">
|
|
4
|
+
<div class="panel-title">
|
|
5
|
+
<or-translate value="${t.title||t.type}"></or-translate>
|
|
6
|
+
</div>
|
|
7
|
+
<div class="panel-content">
|
|
8
|
+
${s}
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
`}function getPanelContent(e,t,s,i,o){var r;const n=t.asset;if(i.panelViewProvider){const t=i.panelViewProvider(n,n.attributes,e,s,i,o);if(t)return t}if(o){if("info"===o.type){const e=o,r=getIncludedProperties(e),a=getIncludedAttributes(n.attributes,e);if(0===r.length&&0===a.length)return;const l=[];r.forEach((t=>{const s=e.properties&&e.properties.itemConfig?e.properties.itemConfig[t]:{};void 0===s.label&&(s.label=i18next.t(t)),s.priority=s.priority||0,l.push({item:t,itemConfig:s})})),a.forEach((t=>{const s=e.attributes&&e.attributes.itemConfig&&e.attributes.itemConfig[t.name]?e.attributes.itemConfig[t.name]:{};if(void 0===s.label){const e=AssetModelUtil.getAttributeAndValueDescriptors(n.type,t.name,t);s.label=Util.getAttributeLabel(t,e[0],n.type,!0)}s.priority=s.priority||0,l.push({item:t,itemConfig:s})}));const d=Util.sortByString((e=>e.itemConfig.label.toUpperCase()));return l.sort(((e,t)=>{const s=e.itemConfig.priority,i=t.itemConfig.priority;return s<i?1:s>i?-1:d(e,t)})),html`
|
|
13
|
+
${l.map((e=>{if("string"==typeof e.item)return getField(e.item,e.itemConfig,getPropertyTemplate(n,e.item,s,i,o,e.itemConfig));{if(t.attributeTemplateMap[e.item.name])return getField(e.item.name,e.itemConfig,t.attributeTemplateMap[e.item.name]);const r=getAttributeTemplate(n,e.item,s,i,o,e.itemConfig);return t.attributeTemplateMap[e.item.name]=r,getField(e.item.name,e.itemConfig,r)}}))}`}if("setup"===o.type){const e=AssetModelUtil.getAssetDescriptor(n.type);if(!e||!n.id||"agent"!==e.descriptorType||!e.assetDiscovery&&!e.assetImport)return;const t=()=>{const e=s.shadowRoot.getElementById("fileupload-elem"),t=s.shadowRoot.getElementById("filename-elem"),i=s.shadowRoot.getElementById("fileupload-btn"),o=e.value;if(!o)return;let r;i.disabled=!1,o.lastIndexOf("\\")?r=o.lastIndexOf("\\")+1:o.lastIndexOf("/")&&(r=o.lastIndexOf("/")+1),t.value=o.slice(r,o.length)},i=()=>{const e=s.shadowRoot.getElementById("discover-btn"),t=s.shadowRoot.getElementById("cancel-discover-btn");if(!e||!t)return!1;t.hidden=!1,e.disabled=!0,e.label=i18next.t("discovering")+"...",manager.rest.api.AgentResource.doProtocolAssetDiscovery(n.id).then((e=>{200!==e.status?showSnackbar(void 0,"somethingWentWrong","dismiss"):(showSnackbar(void 0,"Import successful! Added "+e.data.length+" assets!","dismiss"),console.info(e.data,e))})).catch((e=>{showSnackbar(void 0,"somethingWentWrong","dismiss"),console.error(e)})).finally((()=>{t.hidden=!0,e.disabled=!1,e.label=i18next.t("discoverAssets")}))},o=()=>{const e=s.shadowRoot.getElementById("discover-btn"),t=s.shadowRoot.getElementById("cancel-discover-btn");e.disabled=!1,e.label=i18next.t("discoverAssets"),t.hidden=!0},r=()=>{const e=s.shadowRoot.getElementById("filename-elem"),t=s.shadowRoot.getElementById("fileupload-btn"),i=s.shadowRoot.getElementById("progress-circular");if(!t||!i)return!1;t.disabled=!0,t.classList.add("hidden"),i.classList.remove("hidden");const o=s.shadowRoot.getElementById("fileupload-elem");if(o){const s=new FileReader;o.files&&o.files.length&&s.readAsDataURL(o.files[0]),s.onload=()=>{if(s.result){let o=s.result.toString().replace(/^data:(.*,)?/,"");o.length%4>0&&(o+="=".repeat(4-o.length%4));const r={name:"filename",contents:o,binary:!0};manager.rest.api.AgentResource.doProtocolAssetImport(n.id,r,void 0,{timeout:3e4}).then((e=>{200!==e.status?showSnackbar(void 0,"somethingWentWrong","dismiss"):(showSnackbar(void 0,"Import successful! Added "+e.data.length+" assets!","dismiss"),console.info(e.data,e))})).catch((e=>{showSnackbar(void 0,"somethingWentWrong","dismiss"),console.error(e)})).finally((()=>{e.value="",t.disabled=!0,t.classList.remove("hidden"),i.classList.add("hidden")}))}else showSnackbar(void 0,"somethingWentWrong","dismiss"),console.error(s)}}};let a=html``;return e.assetImport?a=html`
|
|
14
|
+
<div id="fileupload">
|
|
15
|
+
<or-mwc-input style="flex: 0 1 auto;" outlined label="selectFile" .type="${InputType.BUTTON}" @or-mwc-input-changed="${()=>s.shadowRoot.getElementById("fileupload-elem").click()}">
|
|
16
|
+
<input id="fileupload-elem" name="configfile" type="file" accept=".*" @change="${()=>t()}"/>
|
|
17
|
+
</or-mwc-input>
|
|
18
|
+
<or-mwc-input style="flex: 1 1 auto; margin: 0 4px 0 10px;" id="filename-elem" .label="${i18next.t("file")}" .type="${InputType.TEXT}" disabled></or-mwc-input>
|
|
19
|
+
<or-mwc-input style="flex: 0 1 auto;" id="fileupload-btn" icon="upload" .type="${InputType.BUTTON}" @or-mwc-input-changed="${()=>r()}" disabled></or-mwc-input>
|
|
20
|
+
<progress id="progress-circular" class="hidden pure-material-progress-circular"></progress>
|
|
21
|
+
</div>
|
|
22
|
+
`:e.assetDiscovery?a=html`
|
|
23
|
+
<or-mwc-input outlined id="discover-btn" .type="${InputType.BUTTON}" label="discoverAssets" @or-mwc-input-changed="${()=>i()}"></or-mwc-input>
|
|
24
|
+
<or-mwc-input id="cancel-discover-btn" .type="${InputType.BUTTON}" label="cancel" @or-mwc-input-changed="${()=>o()}" hidden style="margin-left:20px"></or-mwc-input>
|
|
25
|
+
`:showSnackbar(void 0,"agent type doesn't support a known protocol to add assets","dismiss"),html`
|
|
26
|
+
<style>
|
|
27
|
+
[hidden] {
|
|
28
|
+
display: none;
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
31
|
+
${a}
|
|
32
|
+
`}if("history"===o.type){const e=o,a=e.include?e.include:void 0,l=e.exclude?e.exclude:[],d=Object.values(null===(r=null==t?void 0:t.asset)||void 0===r?void 0:r.attributes).filter((e=>(!a||a.indexOf(e.name)>=0)&&(!l||l.indexOf(e.name)<0)&&e.meta&&(e.meta.hasOwnProperty("storeDataPoints")?e.meta.storeDataPoints:e.meta.hasOwnProperty("agentLink"))));if(0===d.length)return;let c;const p=e=>{if(s.shadowRoot){const t=s.shadowRoot.getElementById("attribute-history");if(e&&t){let s=n.attributes&&n.attributes[e];const i=AssetModelUtil.getAttributeAndValueDescriptors(n.type,s.name,s);Util.getAttributeLabel(s,i[0],n.type,!0),t.attribute=s,c=s}}},u=d.map((e=>{const t=AssetModelUtil.getAttributeAndValueDescriptors(n.type,e.name,e),s=Util.getAttributeLabel(e,t[0],n.type,!0);return[e.name,s]})).sort(Util.sortByString((e=>void 0===e[1]?e[0]:e[1])));let m=html`
|
|
33
|
+
<div id="attribute-picker">
|
|
34
|
+
<or-mwc-input .checkAssetWrite="${!1}" .label="${i18next.t("attribute")}" @or-mwc-input-changed="${e=>p(e.detail.value)}" .type="${InputType.SELECT}" .options="${u}"></or-mwc-input>
|
|
35
|
+
</div>`;return html`
|
|
36
|
+
<style>
|
|
37
|
+
#attribute-picker {
|
|
38
|
+
flex: 0;
|
|
39
|
+
margin: 0 0 10px 0;
|
|
40
|
+
position: unset;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#attribute-picker > or-mwc-input {
|
|
44
|
+
width: 250px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
or-attribute-history {
|
|
48
|
+
width: 100%;
|
|
49
|
+
--or-attribute-history-controls-margin: 0 0 10px -5px;
|
|
50
|
+
--or-attribute-history-controls-justify-content: flex-start;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@media screen and (min-width: 1900px) {
|
|
54
|
+
#attribute-picker {
|
|
55
|
+
position: absolute;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
or-attribute-history {
|
|
59
|
+
--or-attribute-history-controls-margin: 0 0 10px 0;
|
|
60
|
+
--or-attribute-history-controls-justify-content: flex-end;
|
|
61
|
+
min-height: 70px;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
65
|
+
${m}
|
|
66
|
+
<or-attribute-history id="attribute-history" .config="${i.historyConfig}" .assetType="${n.type}" .assetId="${n.id}"></or-attribute-history>
|
|
67
|
+
`}if("group"===o.type){if(!n.id||"GroupAsset"!==n.type)return;const i=t.childAssets;if(!i||0===i.length)return;const r=n.attributes&&n.attributes.childAssetType,a=o;if(!r||"string"!=typeof r.value)return;const l=r.value;let d=[],c=[];a.childAssetTypes&&a.childAssetTypes[l]&&(d=a.childAssetTypes[l].availableAttributes?a.childAssetTypes[l].availableAttributes:[],c=a.childAssetTypes[l].selectedAttributes?a.childAssetTypes[l].selectedAttributes:[]);const p=t=>{c.length=0,c.push(...t);const i=s.shadowRoot.getElementById(e+"-attribute-table"),o=m();i.columns=o[0],i.rows=o[1],u.views[n.id]=[...c],manager.console.storeData("OrAssetConfig",u)};let u;if(manager.console.retrieveData("OrAssetConfig").then((e=>{u=e,u||(u={views:{}}),u.views||(u.views={});const t=u.views[n.id];t&&p([...t])})),0===d.length){const e=AssetModelUtil.getAssetTypeInfo(l);e&&e.attributeDescriptors&&(d=e.attributeDescriptors.map((e=>e.name)))}c&&0!==c.length||!d||(c=[...new Set(i.map((e=>Object.keys(e.attributes))).flat())]);const m=()=>{const e=[...c].sort(),t=e.map((e=>{const t=AssetModelUtil.getAttributeDescriptor(e,l);return Util.getAttributeLabel(void 0,t,n.type,!1)})),s=i.map((t=>{const s=e.map((e=>{const s=AssetModelUtil.getAttributeDescriptor(e,l);return t.attributes[e]?Util.getAttributeValueAsString(t.attributes[e],s,n.type,!1):""}));return s.unshift(t.name),s}));return t.unshift(i18next.t("groupAssetName")),[t,s]},h=()=>{const e=[...c];showOkCancelDialog(i18next.t("addRemoveAttributes"),html`
|
|
68
|
+
<div style="display: flex; flex-direction: column;">
|
|
69
|
+
${d.sort().map((t=>html`
|
|
70
|
+
<or-mwc-input .type="${InputType.CHECKBOX}" .label="${i18next.t(Util.camelCaseToSentenceCase(t))}" style="display: inline-flex;"
|
|
71
|
+
.value="${!!c.find((e=>e===t))}"
|
|
72
|
+
@or-mwc-input-changed="${s=>s.detail.value?e.push(t):e.splice(e.findIndex((e=>e===t)),1)}"
|
|
73
|
+
></or-mwc-input>
|
|
74
|
+
`))}
|
|
75
|
+
</div>
|
|
76
|
+
`).then((t=>{t&&p(e)}))},v=m();return html`
|
|
77
|
+
<style>
|
|
78
|
+
.asset-group-add-remove-button {
|
|
79
|
+
position: absolute;
|
|
80
|
+
--or-mwc-input-color: currentColor;
|
|
81
|
+
top: calc(var(--internal-or-asset-viewer-panel-padding) - 15px);
|
|
82
|
+
right: calc(var(--internal-or-asset-viewer-panel-padding) - 15px);
|
|
83
|
+
}
|
|
84
|
+
.asset-group-add-remove-button.active {
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
opacity: 1;
|
|
87
|
+
}
|
|
88
|
+
</style>
|
|
89
|
+
<or-mwc-input .type="${InputType.BUTTON}" class="asset-group-add-remove-button" icon="pencil" @click="${()=>h()}"></or-mwc-input>
|
|
90
|
+
<or-mwc-table .columns="${v[0]}" .rows="${v[1]}" .id="${e}-attribute-table" .config="${{stickyFirstColumn:!0}}"></or-mwc-table>
|
|
91
|
+
`}if("linkedUsers"===o.type){const e=manager.hasRole("read:admin"),i=t.userAssetLinks;if(!e)return;if(!i||0===i.length)return;const o=[i18next.t("username"),i18next.t("roles"),i18next.t("restrictedUser")],r=i.sort(Util.sortByString((e=>e.usernameAndId))).map((e=>[e.usernameAndId,e.roles.join(", "),e.restrictedUser?i18next.t("yes"):i18next.t("no")]));return html`<or-mwc-table .rows="${r}" .config="${{stickyFirstColumn:!1}}" .columns="${o}"
|
|
92
|
+
@or-mwc-table-row-click="${e=>{s.dispatchEvent(new OrAssetViewerLoadUserEvent(i[e.detail.index].userId))}}">
|
|
93
|
+
</or-mwc-table>`}}}export function getAttributeTemplate(e,t,s,i,o,r){if(i.attributeViewProvider){const r=i.attributeViewProvider(e,t,s,i,o);if(r)return r}let n,a,l,d,c,p;return r&&(n=r.label,a=r.disabled,l=r.readonly,d=r.disableButton,p=r.disableHelperText,c=r.inputTypeOverride),html`
|
|
94
|
+
<or-attribute-input class="force-btn-padding" disablesubscribe .assetType="${e.type}" .attribute="${t}" .assetId="${e.id}" .disabled="${a}" .label="${n}" .readonly="${l}" resizeVertical .disableButton="${d}" .inputType="${c}" .hasHelperText="${!p}" .fullWidth="${"location"===t.name}"></or-attribute-input>
|
|
95
|
+
`}export function getPropertyTemplate(e,t,s,i,o,r){let n=e[t];if(i&&i.propertyViewProvider&&o){const r=i.propertyViewProvider(e,t,n,s,i,o);if(r)return r}let a=InputType.TEXT;switch(t){case"parentId":n=e.path||["",e.parentId];const t=[...n];t.pop(),n="",t.length>0&&(getAssetNames(t).then((e=>{if(s&&s.shadowRoot){const t=s.shadowRoot.getElementById("property-parentId");t&&(t.value=e.join(" > "))}})),n=i18next.t("loading"));break;case"createdOn":a=InputType.DATETIME;break;case"accessPublicRead":a=InputType.CHECKBOX}return html`<or-mwc-input id="property-${t}" .type="${a}" dense .value="${n}" .readonly="${void 0===r.readonly||r.readonly}" .label="${r.label}"></or-mwc-input>`}export function getField(e,t,s){return s?html`
|
|
96
|
+
<div id="field-${e}" style="${t&&t.styles?styleMap(t.styles):""}" class=${classMap({field:!0,mobileHidden:!!t&&!!t.hideOnMobile})}>
|
|
97
|
+
${s}
|
|
98
|
+
</div>
|
|
99
|
+
`:html``}function getAssetNames(e){return __awaiter(this,void 0,void 0,(function*(){const t=yield manager.rest.api.AssetResource.queryAssets({select:{attributes:[]},ids:e});return 200===t.status&&t.data&&t.data.length===e.length?e.map((e=>t.data.find((t=>t.id===e)).name)):e}))}function getAssetChildren(e,t){return __awaiter(this,void 0,void 0,(function*(){let s;try{s=yield manager.rest.api.AssetResource.queryAssets({parents:[{id:e}]})}catch(e){return console.log("Failed to get child assets: "+e),[]}return 200===s.status&&s.data?s.data.filter((e=>e.type===t)):[]}))}function getLinkedUserInfo(e){return __awaiter(this,void 0,void 0,(function*(){const t=e.id.userId;return{userId:t,usernameAndId:e.userFullName,roles:yield manager.rest.api.UserResource.getUserRoles(manager.displayRealm,t).then((e=>e.data.filter((e=>e.composite)).map((e=>e.name)))).catch((e=>(console.info("User not allowed to get roles",e),[]))),restrictedUser:yield manager.rest.api.UserResource.getUserRealmRoles(manager.displayRealm,t).then((e=>!!e.data&&!!e.data.find((e=>e.assigned&&"restricted_user"===e.name))))}}))}function getLinkedUsers(e){return __awaiter(this,void 0,void 0,(function*(){try{return yield manager.rest.api.AssetResource.getUserAssetLinks({realm:manager.displayRealm,assetId:e.id}).then((e=>{const t=e.data.map((e=>getLinkedUserInfo(e)));return Promise.all(t)}))}catch(e){return console.log("Failed to get child assets: "+e),[]}}))}export function saveAsset(e){return __awaiter(this,void 0,void 0,(function*(){const t=!!e.id&&void 0!==e.version;let s,i="";try{if(t){if(!e.id)throw new Error("Request to update existing asset but asset ID is not set");s=200===(yield manager.rest.api.AssetResource.update(e.id,e)).status,i=e.id}else{const t=yield manager.rest.api.AssetResource.create(e);s=200===t.status,s&&(i=t.data.id)}}catch(e){s=!1,showSnackbar(void 0,t?"saveAssetFailed":"createAssetFailed","dismiss"),console.error("Failed to save asset",e)}return{assetId:i,success:s,isNew:!t}}))}const tableStyle=require("@material/data-table/dist/mdc.data-table.css");export const DEFAULT_ASSET_PROPERTIES=["name","createdOn","type","parentId","accessPublicRead"];export const DEFAULT_VIEWER_CONFIG={viewerStyles:{},panels:[{type:"group",title:"underlyingAssets"},{type:"info",hideOnMobile:!0,properties:{include:[]},attributes:{include:["notes","manufacturer","model"]}},{title:"attributes",type:"info",properties:{include:[]},attributes:{exclude:["location","notes","manufacturer","model"]}},{type:"setup",hideOnMobile:!1},{title:"location",type:"info",column:1,properties:{include:[]},attributes:{include:["location"],itemConfig:{location:{label:"",readonly:!0}}}},{type:"history",column:1},{type:"linkedUsers",column:1}]};let OrAssetViewer=class extends(subscribe(manager)(translate(i18next)(LitElement))){static get styles(){return[unsafeCSS(tableStyle),progressCircular,panelStyles,style]}constructor(){super(),this._validationResults=[],this.addEventListener(OrEditAssetModifiedEvent.NAME,(e=>this._onAssetModified(e.detail)))}isModified(){return!!this.editMode&&this._assetInfo&&this._assetInfo.modified}shouldUpdate(e){return this._isReadonly()&&(this.editMode=!1),e.has("ids")&&(this._assetInfo=void 0,this.asset=void 0,this.ids&&1===this.ids.length?super.assetIds=[this.ids[0]]:super.assetIds=void 0),e.has("asset")&&(this._assetInfo=void 0,this.ids=void 0,super.assetIds=void 0,this.asset&&this.loadAssetInfo(this.asset).then((e=>this._assetInfo=e)).catch((e=>{}))),super.shouldUpdate(e)}updated(e){e.has("asset")&&this._doValidation()}loadAssetInfo(e){return __awaiter(this,void 0,void 0,(function*(){if(!e)throw new Error("Asset has changed");e.attributes||(e.attributes={});const t=!!e.id,s=!t,i=this._getPanelConfig(e);if(!t)return{asset:e,modified:s,viewerConfig:i,attributeTemplateMap:{}};const o=yield getLinkedUsers(e);if(!this.ids||1!=this.ids.length||this.ids[0]!==e.id)throw new Error("Asset has changed");let r;if("GroupAsset"===e.type&&(r=yield getAssetChildren(e.id,e.attributes.childAssetType.value)),!this.ids||1!=this.ids.length||this.ids[0]!==e.id)throw new Error("Asset has changed");return{asset:e,modified:s,viewerConfig:i,childAssets:r,userAssetLinks:o,attributeTemplateMap:{}}}))}_doValidation(){this.editMode&&this.editor&&(this._validationResults=this.editor.validate())}_onParentChangeClick(){let e;const t=e=>{e.stopPropagation()},s=html`
|
|
100
|
+
<or-asset-tree id="parent-asset-tree" disableSubscribe readonly .selectedIds="${[]}"
|
|
101
|
+
@or-asset-tree-request-select="${t}"
|
|
102
|
+
@or-asset-tree-selection-changed="${t}"></or-asset-tree>`,i=[{actionName:"clear",content:"none",action:()=>{this.dispatchEvent(new OrAssetViewerChangeParentEvent(void 0,this.ids||[]))}},{actionName:"ok",content:"ok",action:()=>{const t=e.shadowRoot.getElementById("parent-asset-tree");let s=1===t.selectedIds.length?t.selectedIds[0]:void 0;this.dispatchEvent(new OrAssetViewerChangeParentEvent(s,this.ids||[]))}},{default:!0,actionName:"cancel",content:"cancel"}];e=showDialog((new OrMwcDialog).setContent(s).setActions(i).setStyles(html`
|
|
103
|
+
<style>
|
|
104
|
+
.mdc-dialog__surface {
|
|
105
|
+
width: 400px;
|
|
106
|
+
height: 800px;
|
|
107
|
+
display: flex;
|
|
108
|
+
overflow: visible;
|
|
109
|
+
overflow-x: visible !important;
|
|
110
|
+
overflow-y: visible !important;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#dialog-content {
|
|
114
|
+
flex: 1;
|
|
115
|
+
overflow: visible;
|
|
116
|
+
min-height: 0;
|
|
117
|
+
padding: 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
footer.mdc-dialog__actions {
|
|
121
|
+
border-top: 1px solid ${unsafeCSS(DefaultColor5)};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
or-asset-tree {
|
|
125
|
+
height: 100%;
|
|
126
|
+
}
|
|
127
|
+
</style>
|
|
128
|
+
`).setHeading(i18next.t("setParent")).setDismissAction(null))}render(){const e=!(this.asset||this.ids&&0!==this.ids.length);if(!this.asset&&this.ids&&this.ids.length>1)return html`
|
|
129
|
+
<div class="msg">
|
|
130
|
+
<div class="multipleAssetsView">
|
|
131
|
+
<or-translate value="multiAssetSelected" .options="${{assetNbr:this.ids.length}}"></or-translate>
|
|
132
|
+
<or-mwc-input .type="${InputType.BUTTON}" label="changeParent" @click="${()=>this._onParentChangeClick()}" outlined></or-mwc-input>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
`;if(e)return html`
|
|
136
|
+
<div class="msg"><or-translate value="noAssetSelected"></or-translate></div>
|
|
137
|
+
`;if(!this._assetInfo)return html`
|
|
138
|
+
<div class="msg"><or-translate value="loading"></or-translate></div>
|
|
139
|
+
`;if(!this._assetInfo.asset)return html`
|
|
140
|
+
<div><or-translate value="notFound"></or-translate></div>
|
|
141
|
+
`;const t=this._assetInfo.asset,s=AssetModelUtil.getAssetDescriptor(t.type),i=!!this.editMode;let o="",r=[];if(i)o=html`
|
|
142
|
+
<div id="edit-container">
|
|
143
|
+
<or-edit-asset-panel id="editor" .asset="${t}"></or-edit-asset-panel>
|
|
144
|
+
</div>
|
|
145
|
+
`,r=this._validationResults.filter((e=>!e.valid||e.metaResults&&e.metaResults.some((e=>!e.valid)))).flatMap((e=>{const t=[];return e.valid||t.push(i18next.t("validation.invalidAttributeValue",{attrName:e.name})),e.metaResults&&e.metaResults.filter((e=>!e.valid)).forEach((s=>{t.push(i18next.t("validation.invalidMetaItemValue",{attrName:e.name,metaName:s.name}))})),t}));else{const e=this._assetInfo.viewerConfig;if(e.panels){const t=[],s=[];e.panels.forEach(((i,o)=>{if(!i.hide){const r=o+"",n=i.column||0,a=getPanel(r,i,getPanelContent(r,this._assetInfo,this,e,i))||"";a&&(0==n?t.push(a):s.push(a))}})),o=html`
|
|
146
|
+
<div id="view-container" style="${e.viewerStyles?styleMap(e.viewerStyles):""}" @scroll="${this._toggleHeaderShadow}">
|
|
147
|
+
<div id="left-column" class="panelContainer">
|
|
148
|
+
${t}
|
|
149
|
+
</div>
|
|
150
|
+
<div id="right-column" class="panelContainer">
|
|
151
|
+
${s}
|
|
152
|
+
</div>
|
|
153
|
+
</div>`}}return html`
|
|
154
|
+
<div id="wrapper">
|
|
155
|
+
<div id="asset-header" class=${i?"editmode":""}>
|
|
156
|
+
<a class="back-navigation" @click="${()=>window.history.back()}">
|
|
157
|
+
<or-icon icon="chevron-left"></or-icon>
|
|
158
|
+
</a>
|
|
159
|
+
<div id="title">
|
|
160
|
+
<or-icon title="${s&&s.name?s.name:"unset"}" style="--or-icon-fill: ${s&&s.colour?"#"+s.colour:"unset"}" icon="${s&&s.icon?s.icon:AssetModelUtil.getAssetDescriptorIcon("ThingAsset")}"></or-icon>
|
|
161
|
+
${i?html`
|
|
162
|
+
<or-mwc-input id="name-input" .type="${InputType.TEXT}" min="1" max="1023" comfortable required outlined .label="${i18next.t("name")}" .value="${t.name}" @or-mwc-input-changed="${e=>{t.name=e.detail.value,this._assetInfo.modified=!0,this._doValidation()}}"></or-mwc-input>
|
|
163
|
+
`:html`<span>${t.name}</span>`}
|
|
164
|
+
</div>
|
|
165
|
+
<div id="right-wrapper" class="mobileHidden">
|
|
166
|
+
${0===r.length?t.createdOn?html`<or-translate id="created-time" class="tabletHidden" value="createdOnWithDate" .options="${{date:new Date(t.createdOn)}}"></or-translate>`:"":html`<span id="error-wrapper" .title="${r.join("\n")}"><or-icon icon="alert"></or-icon><or-translate class="tabletHidden" value="validation.invalidAsset"></or-translate></span>`}
|
|
167
|
+
${i?html`<or-mwc-input id="save-btn" .disabled="${!this.isModified()}" raised .type="${InputType.BUTTON}" label="save" @or-mwc-input-changed="${()=>this._onSaveClicked()}"></or-mwc-input>`:""}
|
|
168
|
+
${this._isReadonly()?"":html`<or-mwc-input id="edit-btn" .disabled="${!this._assetInfo.asset.id}" outlined .type="${InputType.BUTTON}" .value="${this.editMode}" .label="${this.editMode?i18next.t("viewAsset"):i18next.t("editAsset")}" icon="${this.editMode?"eye":"pencil"}" @or-mwc-input-changed="${()=>this._onEditToggleClicked(!this.editMode)}"></or-mwc-input>
|
|
169
|
+
`}
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
${o}
|
|
173
|
+
</div>
|
|
174
|
+
`}_toggleHeaderShadow(){this.containerElem.scrollTop>0?this.headerElem.classList.add("scrolled"):this.headerElem.classList.remove("scrolled")}_isReadonly(){return this.readonly||!manager.hasRole("write:assets")}_onEditToggleClicked(e){Util.dispatchCancellableEvent(this,new OrAssetViewerRequestEditToggleEvent(e)).then((t=>{t.allow?this._doEditToggle(e):this.editBtnElem.value=!e}))}_doEditToggle(e){this.editMode=e,this.dispatchEvent(new OrAssetViewerEditToggleEvent(e))}_onSaveClicked(){this._assetInfo&&this._assetInfo.asset&&Util.dispatchCancellableEvent(this,new OrAssetViewerRequestSaveEvent(this._assetInfo.asset)).then((e=>{e.allow&&this._doSave()}))}_doSave(){return __awaiter(this,void 0,void 0,(function*(){if(!this._assetInfo)return;const e=this._assetInfo.asset;this.saveBtnElem.disabled=!0,this.wrapperElem.classList.add("saving"),this._saveResult=yield saveAsset(e),this.wrapperElem.classList.remove("saving"),this.saveBtnElem.disabled=!1,this._assetInfo&&this._assetInfo.asset===e&&(this._saveResult.success&&(this._assetInfo.modified=!1,this.asset=void 0,this.ids=[this._saveResult.assetId]),this.dispatchEvent(new OrAssetViewerSaveEvent(this._saveResult)))}))}_onAssetModified(e){this._assetInfo&&(this._assetInfo.modified=!0,this._validationResults=e)}_onEvent(e){var t;const s=this.ids&&this.ids.length>0?this.ids[0]:void 0;if("asset"===e.eventType&&e.asset.id===s||"attribute"===e.eventType&&e.ref.id==s){if("asset"===e.eventType){const i=e.asset;if(!this._assetInfo)return void this.loadAssetInfo(i).then((e=>this._assetInfo=e)).catch((e=>{}));if(i.id!==s)return;if(this.editMode){if(!this._assetInfo.modified||(null===(t=this._saveResult)||void 0===t?void 0:t.assetId)===s)return this._assetInfo=void 0,this._saveResult=void 0,void this.loadAssetInfo(i).then((e=>this._assetInfo=e)).catch((e=>{}));showOkDialog("assetModified",i18next.t("assetModifiedMustRefresh")).then((()=>{this._assetInfo=void 0,this.loadAssetInfo(i).then((e=>this._assetInfo=e)).catch((e=>{}))}))}else this._assetInfo=void 0,this.loadAssetInfo(i).then((e=>this._assetInfo=e)).catch((e=>{}))}if("attribute"===e.eventType){if(!this._assetInfo)return;const t=this._assetInfo.asset,s=e,i=s.ref.name;if(t&&t.attributes&&t.attributes[i]){delete this._assetInfo.attributeTemplateMap[i];const e=Object.assign({},t.attributes[i]);if(e.value=s.value,e.timestamp=s.timestamp,t.attributes[i]=e,this.editMode){const e=this.shadowRoot.getElementById("editor");e&&e.attributeUpdated(i)}else this.requestUpdate()}}}}_getPanelConfig(e){const t=Object.assign({},DEFAULT_VIEWER_CONFIG);if(this.config){t.viewerStyles=Object.assign({},t.viewerStyles),t.panels=t.panels?[...t.panels]:[];const s=this.config.assetTypes&&this.config.assetTypes.hasOwnProperty(e.type)?this.config.assetTypes[e.type]:this.config.default;s&&(s.viewerStyles&&Object.assign(t.viewerStyles,s.viewerStyles),s.panels&&(t.panels=s.panels),t.attributeViewProvider=s.attributeViewProvider||(this.config.default?this.config.default.attributeViewProvider:void 0),t.panelViewProvider=s.panelViewProvider||(this.config.default?this.config.default.panelViewProvider:void 0),t.propertyViewProvider=s.propertyViewProvider||(this.config.default?this.config.default.propertyViewProvider:void 0),t.historyConfig=s.historyConfig||this.config.historyConfig)}return t}};__decorate([property({type:Object,reflect:!1})],OrAssetViewer.prototype,"asset",void 0),__decorate([property({type:Array})],OrAssetViewer.prototype,"ids",void 0),__decorate([property({type:Object})],OrAssetViewer.prototype,"config",void 0),__decorate([property({type:Boolean})],OrAssetViewer.prototype,"editMode",void 0),__decorate([property({type:Boolean})],OrAssetViewer.prototype,"readonly",void 0),__decorate([state()],OrAssetViewer.prototype,"_assetInfo",void 0),__decorate([state()],OrAssetViewer.prototype,"_validationResults",void 0),__decorate([query("#wrapper")],OrAssetViewer.prototype,"wrapperElem",void 0),__decorate([query("#save-btn")],OrAssetViewer.prototype,"saveBtnElem",void 0),__decorate([query("#edit-btn")],OrAssetViewer.prototype,"editBtnElem",void 0),__decorate([query("#editor")],OrAssetViewer.prototype,"editor",void 0),__decorate([query("#asset-header")],OrAssetViewer.prototype,"headerElem",void 0),__decorate([query("#view-container")],OrAssetViewer.prototype,"containerElem",void 0),OrAssetViewer=__decorate([customElement("or-asset-viewer")],OrAssetViewer);export{OrAssetViewer};
|