@openremote/or-asset-tree 1.4.0-snapshot.20250328114049 → 1.4.0-snapshot.20250331211521
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/dist/umd/index.bundle.js +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.orbundle.js +2 -2
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +8 -8
package/dist/umd/index.bundle.js
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
padding: 0 !important;
|
|
76
76
|
}
|
|
77
77
|
</style>
|
|
78
|
-
`).setDismissAction(null))}_gatewayDescendantIsSelected(){return this._selectedNodes.some((t=>{var e;let n=null==t?void 0:t.parent;for(;n;){if("GatewayAsset"===(null===(e=n.asset)||void 0===e?void 0:e.type))return!0;n=n.parent}return!1}))}_onDeleteClicked(){this._selectedNodes.length>0&&_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestDeleteEvent(this._selectedNodes)).then((t=>{t.allow&&this._doDelete()}))}_onSortClicked(t){this.sortBy=t}_doDelete(){if(!this._selectedNodes||0===this._selectedNodes.length)return;const t=new Set,e=this._selectedNodes.filter((e=>{var n;return"GatewayAsset"!==(null===(n=e.asset)||void 0===n?void 0:n.type)||(t.add(e.asset),!1)}));OrAssetTree_1._forEachNodeRecursive(e,(e=>{var n;let i=e.parent,r=!0;for(;i&&r;)"GatewayAsset"===(null===(n=null==i?void 0:i.asset)||void 0===n?void 0:n.type)&&(r=!1),i=i.parent;r&&t.add(e.asset)}));const n=Array.from(t).map((t=>t.id)),i=Array.from(t).map((t=>t.name)),r=()=>{this.disabled=!0,_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.delete({assetId:n},{paramsSerializer:t=>qs__WEBPACK_IMPORTED_MODULE_8___default().stringify(t,{arrayFormat:"repeat"})}).then((t=>{this.refresh(),this.disabled=!1,204!==t.status&&(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))})).catch((t=>{this.refresh(),this.disabled=!1,(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}))};(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.aK)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssets"),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsConfirm",{assetNames:i.join(",\n- ")}),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("delete")).then((t=>{t&&r()}))}_canAdd(){var t;if(this._selectedNodes&&this._selectedNodes.length>1)return!1;const e=this._selectedNodes?this._selectedNodes[0]:void 0;return"GatewayAsset"!==(null===(t=null==e?void 0:e.asset)||void 0===t?void 0:t.type)&&!this._gatewayDescendantIsSelected()&&this._getAllowedChildTypes(e).length>0}_getAllowedChildTypes(t){let e,n;if(this.config&&this.config.add){if(this.config.add.typesProvider){const e=this.config.add.typesProvider(t);if(e)return e}if(this.config.add.typesParent){let i;!t&&this.config.add.typesParent.none?i=this.config.add.typesParent.none:t&&this.config.add.typesParent.assetTypes&&(i=this.config.add.typesParent.assetTypes[t.asset.type]),i||(i=this.config.add.typesParent.default),i&&(e=i.include,n=i.exclude||[])}}return _openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptors().filter((t=>(!e||e.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))&&(!n||!n.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))))}_getSortFunction(){return"createdOn"===this.sortBy?_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByNumber((t=>t.asset[this.sortBy])):_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByString((t=>t.asset[this.sortBy]))}_loadAssets(){const t=this._getSortFunction();if(this.assets)this._loading=!1,this._buildTreeNodes(this.assets,t);else{if(!this._connected)return;if(this._loading)return;if(this._loading=!0,this.dataProvider)this.dataProvider().then((e=>{this._loading=!1,this._buildTreeNodes(e,t)}));else{const e={realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:[]}};this.assetIds?(e.ids=this.assetIds,e.recursive=!0):this.rootAssets?(e.ids=this.rootAssets.map((t=>t.id)),e.recursive=!0):this.rootAssetIds&&(e.ids=this.rootAssetIds,e.recursive=!0),this._sendEventWithReply({eventType:"read-assets",assetQuery:e}).then((e=>{this._loading=!1,this._buildTreeNodes(e.assets,t)}))}}}_addEventSubscriptions(){return __awaiter(this,void 0,void 0,(function*(){this.disableSubscribe||(this._subscriptionIds=[yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().getEventProvider().subscribeAssetEvents(void 0,!1,(t=>this._onEvent(t)))])}))}onEventsConnect(){this._connected=!0,this._loadAssets()}onEventsDisconnect(){this._connected=!1,this._nodes=void 0}getNodes(){return this._nodes||[]}_onEvent(t){if("assets"!==t.eventType){if("asset"===t.eventType){const e=t;if("READ"===e.cause)return;if("UPDATE"===e.cause&&!e.updatedProperties.includes("name")&&!e.updatedProperties.includes("parentId"))return;const n=[];"DELETE"!==e.cause&&n.push(e.asset),this._nodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,(t=>{t.asset.id!==e.asset.id&&n.push(t.asset)})),this._buildTreeNodes(n,this._getSortFunction()),this._filterInput.value&&this._doFiltering(),this.dispatchEvent(new OrAssetTreeAssetEvent(e))}}else{const e=t;this._buildTreeNodes(e.assets,this._getSortFunction())}}_buildTreeNodes(t,e){if(t&&0!==t.length){let n,i;_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().isRestrictedUser()&&t.forEach((e=>{if(e.parentId&&e.path&&void 0===t.find((t=>t.id===e.parentId))){let n=null;for(let i=
|
|
78
|
+
`).setDismissAction(null))}_gatewayDescendantIsSelected(){return this._selectedNodes.some((t=>{var e;let n=null==t?void 0:t.parent;for(;n;){if("GatewayAsset"===(null===(e=n.asset)||void 0===e?void 0:e.type))return!0;n=n.parent}return!1}))}_onDeleteClicked(){this._selectedNodes.length>0&&_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestDeleteEvent(this._selectedNodes)).then((t=>{t.allow&&this._doDelete()}))}_onSortClicked(t){this.sortBy=t}_doDelete(){if(!this._selectedNodes||0===this._selectedNodes.length)return;const t=new Set,e=this._selectedNodes.filter((e=>{var n;return"GatewayAsset"!==(null===(n=e.asset)||void 0===n?void 0:n.type)||(t.add(e.asset),!1)}));OrAssetTree_1._forEachNodeRecursive(e,(e=>{var n;let i=e.parent,r=!0;for(;i&&r;)"GatewayAsset"===(null===(n=null==i?void 0:i.asset)||void 0===n?void 0:n.type)&&(r=!1),i=i.parent;r&&t.add(e.asset)}));const n=Array.from(t).map((t=>t.id)),i=Array.from(t).map((t=>t.name)),r=()=>{this.disabled=!0,_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.delete({assetId:n},{paramsSerializer:t=>qs__WEBPACK_IMPORTED_MODULE_8___default().stringify(t,{arrayFormat:"repeat"})}).then((t=>{this.refresh(),this.disabled=!1,204!==t.status&&(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))})).catch((t=>{this.refresh(),this.disabled=!1,(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}))};(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.aK)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssets"),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsConfirm",{assetNames:i.join(",\n- ")}),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("delete")).then((t=>{t&&r()}))}_canAdd(){var t;if(this._selectedNodes&&this._selectedNodes.length>1)return!1;const e=this._selectedNodes?this._selectedNodes[0]:void 0;return"GatewayAsset"!==(null===(t=null==e?void 0:e.asset)||void 0===t?void 0:t.type)&&!this._gatewayDescendantIsSelected()&&this._getAllowedChildTypes(e).length>0}_getAllowedChildTypes(t){let e,n;if(this.config&&this.config.add){if(this.config.add.typesProvider){const e=this.config.add.typesProvider(t);if(e)return e}if(this.config.add.typesParent){let i;!t&&this.config.add.typesParent.none?i=this.config.add.typesParent.none:t&&this.config.add.typesParent.assetTypes&&(i=this.config.add.typesParent.assetTypes[t.asset.type]),i||(i=this.config.add.typesParent.default),i&&(e=i.include,n=i.exclude||[])}}return _openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptors().filter((t=>(!e||e.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))&&(!n||!n.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))))}_getSortFunction(){return"createdOn"===this.sortBy?_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByNumber((t=>t.asset[this.sortBy])):_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByString((t=>t.asset[this.sortBy]))}_loadAssets(){const t=this._getSortFunction();if(this.assets)this._loading=!1,this._buildTreeNodes(this.assets,t);else{if(!this._connected)return;if(this._loading)return;if(this._loading=!0,this.dataProvider)this.dataProvider().then((e=>{this._loading=!1,this._buildTreeNodes(e,t)}));else{const e={realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:[]}};this.assetIds?(e.ids=this.assetIds,e.recursive=!0):this.rootAssets?(e.ids=this.rootAssets.map((t=>t.id)),e.recursive=!0):this.rootAssetIds&&(e.ids=this.rootAssetIds,e.recursive=!0),this._sendEventWithReply({eventType:"read-assets",assetQuery:e}).then((e=>{this._loading=!1,this._buildTreeNodes(e.assets,t)}))}}}_addEventSubscriptions(){return __awaiter(this,void 0,void 0,(function*(){this.disableSubscribe||(this._subscriptionIds=[yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().getEventProvider().subscribeAssetEvents(void 0,!1,(t=>this._onEvent(t)))])}))}onEventsConnect(){this._connected=!0,this._loadAssets()}onEventsDisconnect(){this._connected=!1,this._nodes=void 0}getNodes(){return this._nodes||[]}_onEvent(t){if("assets"!==t.eventType){if("asset"===t.eventType){const e=t;if("READ"===e.cause)return;if("UPDATE"===e.cause&&!e.updatedProperties.includes("name")&&!e.updatedProperties.includes("parentId"))return;const n=[];"DELETE"!==e.cause&&n.push(e.asset),this._nodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,(t=>{t.asset.id!==e.asset.id&&n.push(t.asset)})),this._buildTreeNodes(n,this._getSortFunction()),this._filterInput.value&&this._doFiltering(),this.dispatchEvent(new OrAssetTreeAssetEvent(e))}}else{const e=t;this._buildTreeNodes(e.assets,this._getSortFunction())}}_buildTreeNodes(t,e){if(t&&0!==t.length){let n,i;_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().isRestrictedUser()&&t.forEach((e=>{if(e.parentId&&e.path&&void 0===t.find((t=>t.id===e.parentId))){let n=null;for(let i=0;i<e.path.length;i++){const r=e.path[i];e.id!==r&&void 0!==t.find((t=>t.id===r))&&(n=r)}e.reparentId=n}})),this.rootAssetIds?n=this.rootAssetIds:this.rootAssets&&(n=this.rootAssets.map((t=>t.id))),i=n?t.filter((t=>n.indexOf(t.id)>=0||null===t.reparentId)).map((t=>({asset:t}))):t.filter((t=>!t.parentId||null===t.reparentId)).map((t=>({asset:t}))),this.assetsChildren={},t.forEach((t=>{t.parentId&&(this.assetsChildren[t.parentId]||(this.assetsChildren[t.parentId]=[]),this.assetsChildren[t.parentId].push({asset:t})),t.reparentId&&(this.assetsChildren[t.reparentId]||(this.assetsChildren[t.reparentId]=[]),this.assetsChildren[t.reparentId].push({asset:t}))})),i.sort(e),i.forEach((n=>this._buildChildTreeNodes(n,t,e))),this._nodes=i;const r=[];this._expandedNodes.forEach((t=>{OrAssetTree_1._forEachNodeRecursive(this._nodes,(e=>{if(e.asset&&t&&t.asset&&e.asset.id===t.asset.id){e.expanded=!0,r.push(e);let t=e.parent;for(;t;)t.expanded=!0,t=t.parent,r.indexOf(t)<0&&r.push(t)}}))})),this._expandedNodes=r}else this._nodes=[];this.selectedIds&&this.selectedIds.length>0&&this._updateSelectedNodes(),this.expandAllNodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,(t=>{t.children&&t.children.length>0&&(t.expanded=!0)}))}_buildChildTreeNodes(t,e,n){let i=this.assetsChildren[t.asset.id];t.children=i?i.sort(n):[],t.children.length>0&&(t.expandable=!0),t.children.forEach((i=>{i.parent=t,this._buildChildTreeNodes(i,e,n)}))}_onDragStart(t){this._dragDropParentId=null;let e=t.currentTarget.getAttribute("node-asset-id");this.selectedIds||(this.selectedIds=[]),e&&this.selectedIds&&!this.selectedIds.includes(e)&&(t.ctrlKey||t.shiftKey||(this.selectedIds=[]),this.selectedIds.push(e))}_onDragEnd(t){const e=t.x,n=t.y;if(null!==this.shadowRoot){let t=this.shadowRoot.getElementById("list");if(t){const i=t.getBoundingClientRect().top,r=t.getBoundingClientRect().bottom,o=t.getBoundingClientRect().left,a=t.getBoundingClientRect().right;if(e<o||e>a||n>r||n<i)return}}this.selectedIds&&this.dispatchEvent(new OrAssetTreeChangeParentEvent(this._dragDropParentId?this._dragDropParentId:void 0,this.selectedIds))}isExpandable(t){return!(!this._nodes||!this.shadowRoot)&&!!this.shadowRoot.querySelector('[node-asset-id="'+t+'"] > .node-name > [data-expandable]')}_onDragOver(t){let e=t.currentTarget;e.classList.add("over");let n=e.getAttribute("node-asset-id");n&&this.isExpandable(n)&&!this._expandTimer&&(this._expandTimer=window.setTimeout((()=>{this.expandNode(n)}),1e3))}expandNode(t){var e;if(this.shadowRoot&&t&&t===this._dragDropParentId){const n=this._findNodeFromAssetId(t);let i=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[node-asset-id="'+t+'"]');i&&n&&!n.expanded&&this._toggleExpander(i.firstElementChild.firstElementChild,n,!0)}}_onDragEnter(t){let e=t.currentTarget;e.classList.add("over");let n=e.getAttribute("node-asset-id");this._dragDropParentId=n}_onDragLeave(t){t.currentTarget.classList.remove("over"),clearTimeout(this._expandTimer),this._expandTimer=void 0}_treeNodeTemplate(t,e){const n=_openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptor(t.asset.type);let i;if(i=t.allChildrenSelected?"checkbox-multiple-marked":t.someChildrenSelected?"checkbox-multiple-marked-outline":"checkbox-multiple-blank-outline",t.hidden)return lit__WEBPACK_IMPORTED_MODULE_0__.kP``;let r=!1;return t.asset&&t.notMatchingFilter&&(r=!0),t.expanded&&0===t.children.length&&(t.expanded=!1),this.expandedIds&&-1!==this.expandedIds.findIndex((e=>e===t.asset.id))&&(t.expanded=!0),lit__WEBPACK_IMPORTED_MODULE_0__.kP`
|
|
79
79
|
<li class="asset-list-element" ?data-selected="${t.selected}" ?data-expanded="${t.expanded}" @click="${e=>this._onNodeClicked(e,t)}">
|
|
80
80
|
<div class="in-between-element" node-asset-id="${t.parent?t.parent.asset?t.parent.asset.id:"":void 0}" @dragleave=${t=>{this._onDragLeave(t)}} @dragenter="${t=>this._onDragEnter(t)}" @dragend="${t=>this._onDragEnd(t)}" @dragover="${t=>this._onDragOver(t)}"></div>
|
|
81
81
|
<div class="node-container draggable" node-asset-id="${t.asset?t.asset.id:""}" draggable="${!this._isReadonly()}" @dragleave=${t=>{this._onDragLeave(t)}} @dragenter="${t=>this._onDragEnter(t)}" @dragstart="${t=>this._onDragStart(t)}" @dragend="${t=>this._onDragEnd(t)}" @dragover="${t=>this._onDragOver(t)}" style="padding-left: ${22*e}px">
|
package/dist/umd/index.js
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
padding: 0 !important;
|
|
76
76
|
}
|
|
77
77
|
</style>
|
|
78
|
-
`).setDismissAction(null))}_gatewayDescendantIsSelected(){return this._selectedNodes.some((t=>{var e;let n=null==t?void 0:t.parent;for(;n;){if("GatewayAsset"===(null===(e=n.asset)||void 0===e?void 0:e.type))return!0;n=n.parent}return!1}))}_onDeleteClicked(){this._selectedNodes.length>0&&_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestDeleteEvent(this._selectedNodes)).then((t=>{t.allow&&this._doDelete()}))}_onSortClicked(t){this.sortBy=t}_doDelete(){if(!this._selectedNodes||0===this._selectedNodes.length)return;const t=new Set,e=this._selectedNodes.filter((e=>{var n;return"GatewayAsset"!==(null===(n=e.asset)||void 0===n?void 0:n.type)||(t.add(e.asset),!1)}));OrAssetTree_1._forEachNodeRecursive(e,(e=>{var n;let i=e.parent,r=!0;for(;i&&r;)"GatewayAsset"===(null===(n=null==i?void 0:i.asset)||void 0===n?void 0:n.type)&&(r=!1),i=i.parent;r&&t.add(e.asset)}));const n=Array.from(t).map((t=>t.id)),i=Array.from(t).map((t=>t.name)),r=()=>{this.disabled=!0,_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.delete({assetId:n},{paramsSerializer:t=>qs__WEBPACK_IMPORTED_MODULE_8___default().stringify(t,{arrayFormat:"repeat"})}).then((t=>{this.refresh(),this.disabled=!1,204!==t.status&&(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))})).catch((t=>{this.refresh(),this.disabled=!1,(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}))};(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.aK)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssets"),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsConfirm",{assetNames:i.join(",\n- ")}),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("delete")).then((t=>{t&&r()}))}_canAdd(){var t;if(this._selectedNodes&&this._selectedNodes.length>1)return!1;const e=this._selectedNodes?this._selectedNodes[0]:void 0;return"GatewayAsset"!==(null===(t=null==e?void 0:e.asset)||void 0===t?void 0:t.type)&&!this._gatewayDescendantIsSelected()&&this._getAllowedChildTypes(e).length>0}_getAllowedChildTypes(t){let e,n;if(this.config&&this.config.add){if(this.config.add.typesProvider){const e=this.config.add.typesProvider(t);if(e)return e}if(this.config.add.typesParent){let i;!t&&this.config.add.typesParent.none?i=this.config.add.typesParent.none:t&&this.config.add.typesParent.assetTypes&&(i=this.config.add.typesParent.assetTypes[t.asset.type]),i||(i=this.config.add.typesParent.default),i&&(e=i.include,n=i.exclude||[])}}return _openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptors().filter((t=>(!e||e.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))&&(!n||!n.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))))}_getSortFunction(){return"createdOn"===this.sortBy?_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByNumber((t=>t.asset[this.sortBy])):_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByString((t=>t.asset[this.sortBy]))}_loadAssets(){const t=this._getSortFunction();if(this.assets)this._loading=!1,this._buildTreeNodes(this.assets,t);else{if(!this._connected)return;if(this._loading)return;if(this._loading=!0,this.dataProvider)this.dataProvider().then((e=>{this._loading=!1,this._buildTreeNodes(e,t)}));else{const e={realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:[]}};this.assetIds?(e.ids=this.assetIds,e.recursive=!0):this.rootAssets?(e.ids=this.rootAssets.map((t=>t.id)),e.recursive=!0):this.rootAssetIds&&(e.ids=this.rootAssetIds,e.recursive=!0),this._sendEventWithReply({eventType:"read-assets",assetQuery:e}).then((e=>{this._loading=!1,this._buildTreeNodes(e.assets,t)}))}}}_addEventSubscriptions(){return __awaiter(this,void 0,void 0,(function*(){this.disableSubscribe||(this._subscriptionIds=[yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().getEventProvider().subscribeAssetEvents(void 0,!1,(t=>this._onEvent(t)))])}))}onEventsConnect(){this._connected=!0,this._loadAssets()}onEventsDisconnect(){this._connected=!1,this._nodes=void 0}getNodes(){return this._nodes||[]}_onEvent(t){if("assets"!==t.eventType){if("asset"===t.eventType){const e=t;if("READ"===e.cause)return;if("UPDATE"===e.cause&&!e.updatedProperties.includes("name")&&!e.updatedProperties.includes("parentId"))return;const n=[];"DELETE"!==e.cause&&n.push(e.asset),this._nodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,(t=>{t.asset.id!==e.asset.id&&n.push(t.asset)})),this._buildTreeNodes(n,this._getSortFunction()),this._filterInput.value&&this._doFiltering(),this.dispatchEvent(new OrAssetTreeAssetEvent(e))}}else{const e=t;this._buildTreeNodes(e.assets,this._getSortFunction())}}_buildTreeNodes(t,e){if(t&&0!==t.length){let n,i;_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().isRestrictedUser()&&t.forEach((e=>{if(e.parentId&&e.path&&void 0===t.find((t=>t.id===e.parentId))){let n=null;for(let i=
|
|
78
|
+
`).setDismissAction(null))}_gatewayDescendantIsSelected(){return this._selectedNodes.some((t=>{var e;let n=null==t?void 0:t.parent;for(;n;){if("GatewayAsset"===(null===(e=n.asset)||void 0===e?void 0:e.type))return!0;n=n.parent}return!1}))}_onDeleteClicked(){this._selectedNodes.length>0&&_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestDeleteEvent(this._selectedNodes)).then((t=>{t.allow&&this._doDelete()}))}_onSortClicked(t){this.sortBy=t}_doDelete(){if(!this._selectedNodes||0===this._selectedNodes.length)return;const t=new Set,e=this._selectedNodes.filter((e=>{var n;return"GatewayAsset"!==(null===(n=e.asset)||void 0===n?void 0:n.type)||(t.add(e.asset),!1)}));OrAssetTree_1._forEachNodeRecursive(e,(e=>{var n;let i=e.parent,r=!0;for(;i&&r;)"GatewayAsset"===(null===(n=null==i?void 0:i.asset)||void 0===n?void 0:n.type)&&(r=!1),i=i.parent;r&&t.add(e.asset)}));const n=Array.from(t).map((t=>t.id)),i=Array.from(t).map((t=>t.name)),r=()=>{this.disabled=!0,_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.delete({assetId:n},{paramsSerializer:t=>qs__WEBPACK_IMPORTED_MODULE_8___default().stringify(t,{arrayFormat:"repeat"})}).then((t=>{this.refresh(),this.disabled=!1,204!==t.status&&(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))})).catch((t=>{this.refresh(),this.disabled=!1,(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gz)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}))};(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.aK)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssets"),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsConfirm",{assetNames:i.join(",\n- ")}),_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("delete")).then((t=>{t&&r()}))}_canAdd(){var t;if(this._selectedNodes&&this._selectedNodes.length>1)return!1;const e=this._selectedNodes?this._selectedNodes[0]:void 0;return"GatewayAsset"!==(null===(t=null==e?void 0:e.asset)||void 0===t?void 0:t.type)&&!this._gatewayDescendantIsSelected()&&this._getAllowedChildTypes(e).length>0}_getAllowedChildTypes(t){let e,n;if(this.config&&this.config.add){if(this.config.add.typesProvider){const e=this.config.add.typesProvider(t);if(e)return e}if(this.config.add.typesParent){let i;!t&&this.config.add.typesParent.none?i=this.config.add.typesParent.none:t&&this.config.add.typesParent.assetTypes&&(i=this.config.add.typesParent.assetTypes[t.asset.type]),i||(i=this.config.add.typesParent.default),i&&(e=i.include,n=i.exclude||[])}}return _openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptors().filter((t=>(!e||e.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))&&(!n||!n.some((e=>_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.stringMatch(e,t.name))))))}_getSortFunction(){return"createdOn"===this.sortBy?_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByNumber((t=>t.asset[this.sortBy])):_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sortByString((t=>t.asset[this.sortBy]))}_loadAssets(){const t=this._getSortFunction();if(this.assets)this._loading=!1,this._buildTreeNodes(this.assets,t);else{if(!this._connected)return;if(this._loading)return;if(this._loading=!0,this.dataProvider)this.dataProvider().then((e=>{this._loading=!1,this._buildTreeNodes(e,t)}));else{const e={realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:[]}};this.assetIds?(e.ids=this.assetIds,e.recursive=!0):this.rootAssets?(e.ids=this.rootAssets.map((t=>t.id)),e.recursive=!0):this.rootAssetIds&&(e.ids=this.rootAssetIds,e.recursive=!0),this._sendEventWithReply({eventType:"read-assets",assetQuery:e}).then((e=>{this._loading=!1,this._buildTreeNodes(e.assets,t)}))}}}_addEventSubscriptions(){return __awaiter(this,void 0,void 0,(function*(){this.disableSubscribe||(this._subscriptionIds=[yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().getEventProvider().subscribeAssetEvents(void 0,!1,(t=>this._onEvent(t)))])}))}onEventsConnect(){this._connected=!0,this._loadAssets()}onEventsDisconnect(){this._connected=!1,this._nodes=void 0}getNodes(){return this._nodes||[]}_onEvent(t){if("assets"!==t.eventType){if("asset"===t.eventType){const e=t;if("READ"===e.cause)return;if("UPDATE"===e.cause&&!e.updatedProperties.includes("name")&&!e.updatedProperties.includes("parentId"))return;const n=[];"DELETE"!==e.cause&&n.push(e.asset),this._nodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,(t=>{t.asset.id!==e.asset.id&&n.push(t.asset)})),this._buildTreeNodes(n,this._getSortFunction()),this._filterInput.value&&this._doFiltering(),this.dispatchEvent(new OrAssetTreeAssetEvent(e))}}else{const e=t;this._buildTreeNodes(e.assets,this._getSortFunction())}}_buildTreeNodes(t,e){if(t&&0!==t.length){let n,i;_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().isRestrictedUser()&&t.forEach((e=>{if(e.parentId&&e.path&&void 0===t.find((t=>t.id===e.parentId))){let n=null;for(let i=0;i<e.path.length;i++){const r=e.path[i];e.id!==r&&void 0!==t.find((t=>t.id===r))&&(n=r)}e.reparentId=n}})),this.rootAssetIds?n=this.rootAssetIds:this.rootAssets&&(n=this.rootAssets.map((t=>t.id))),i=n?t.filter((t=>n.indexOf(t.id)>=0||null===t.reparentId)).map((t=>({asset:t}))):t.filter((t=>!t.parentId||null===t.reparentId)).map((t=>({asset:t}))),this.assetsChildren={},t.forEach((t=>{t.parentId&&(this.assetsChildren[t.parentId]||(this.assetsChildren[t.parentId]=[]),this.assetsChildren[t.parentId].push({asset:t})),t.reparentId&&(this.assetsChildren[t.reparentId]||(this.assetsChildren[t.reparentId]=[]),this.assetsChildren[t.reparentId].push({asset:t}))})),i.sort(e),i.forEach((n=>this._buildChildTreeNodes(n,t,e))),this._nodes=i;const r=[];this._expandedNodes.forEach((t=>{OrAssetTree_1._forEachNodeRecursive(this._nodes,(e=>{if(e.asset&&t&&t.asset&&e.asset.id===t.asset.id){e.expanded=!0,r.push(e);let t=e.parent;for(;t;)t.expanded=!0,t=t.parent,r.indexOf(t)<0&&r.push(t)}}))})),this._expandedNodes=r}else this._nodes=[];this.selectedIds&&this.selectedIds.length>0&&this._updateSelectedNodes(),this.expandAllNodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,(t=>{t.children&&t.children.length>0&&(t.expanded=!0)}))}_buildChildTreeNodes(t,e,n){let i=this.assetsChildren[t.asset.id];t.children=i?i.sort(n):[],t.children.length>0&&(t.expandable=!0),t.children.forEach((i=>{i.parent=t,this._buildChildTreeNodes(i,e,n)}))}_onDragStart(t){this._dragDropParentId=null;let e=t.currentTarget.getAttribute("node-asset-id");this.selectedIds||(this.selectedIds=[]),e&&this.selectedIds&&!this.selectedIds.includes(e)&&(t.ctrlKey||t.shiftKey||(this.selectedIds=[]),this.selectedIds.push(e))}_onDragEnd(t){const e=t.x,n=t.y;if(null!==this.shadowRoot){let t=this.shadowRoot.getElementById("list");if(t){const i=t.getBoundingClientRect().top,r=t.getBoundingClientRect().bottom,o=t.getBoundingClientRect().left,a=t.getBoundingClientRect().right;if(e<o||e>a||n>r||n<i)return}}this.selectedIds&&this.dispatchEvent(new OrAssetTreeChangeParentEvent(this._dragDropParentId?this._dragDropParentId:void 0,this.selectedIds))}isExpandable(t){return!(!this._nodes||!this.shadowRoot)&&!!this.shadowRoot.querySelector('[node-asset-id="'+t+'"] > .node-name > [data-expandable]')}_onDragOver(t){let e=t.currentTarget;e.classList.add("over");let n=e.getAttribute("node-asset-id");n&&this.isExpandable(n)&&!this._expandTimer&&(this._expandTimer=window.setTimeout((()=>{this.expandNode(n)}),1e3))}expandNode(t){var e;if(this.shadowRoot&&t&&t===this._dragDropParentId){const n=this._findNodeFromAssetId(t);let i=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('[node-asset-id="'+t+'"]');i&&n&&!n.expanded&&this._toggleExpander(i.firstElementChild.firstElementChild,n,!0)}}_onDragEnter(t){let e=t.currentTarget;e.classList.add("over");let n=e.getAttribute("node-asset-id");this._dragDropParentId=n}_onDragLeave(t){t.currentTarget.classList.remove("over"),clearTimeout(this._expandTimer),this._expandTimer=void 0}_treeNodeTemplate(t,e){const n=_openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptor(t.asset.type);let i;if(i=t.allChildrenSelected?"checkbox-multiple-marked":t.someChildrenSelected?"checkbox-multiple-marked-outline":"checkbox-multiple-blank-outline",t.hidden)return lit__WEBPACK_IMPORTED_MODULE_0__.kP``;let r=!1;return t.asset&&t.notMatchingFilter&&(r=!0),t.expanded&&0===t.children.length&&(t.expanded=!1),this.expandedIds&&-1!==this.expandedIds.findIndex((e=>e===t.asset.id))&&(t.expanded=!0),lit__WEBPACK_IMPORTED_MODULE_0__.kP`
|
|
79
79
|
<li class="asset-list-element" ?data-selected="${t.selected}" ?data-expanded="${t.expanded}" @click="${e=>this._onNodeClicked(e,t)}">
|
|
80
80
|
<div class="in-between-element" node-asset-id="${t.parent?t.parent.asset?t.parent.asset.id:"":void 0}" @dragleave=${t=>{this._onDragLeave(t)}} @dragenter="${t=>this._onDragEnter(t)}" @dragend="${t=>this._onDragEnd(t)}" @dragover="${t=>this._onDragOver(t)}"></div>
|
|
81
81
|
<div class="node-container draggable" node-asset-id="${t.asset?t.asset.id:""}" draggable="${!this._isReadonly()}" @dragleave=${t=>{this._onDragLeave(t)}} @dragenter="${t=>this._onDragEnter(t)}" @dragstart="${t=>this._onDragStart(t)}" @dragend="${t=>this._onDragEnd(t)}" @dragover="${t=>this._onDragOver(t)}" style="padding-left: ${22*e}px">
|