@openremote/or-asset-tree 1.12.0-snapshot.20251128100326 → 1.12.0-snapshot.20251128152026

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.
@@ -74,7 +74,7 @@
74
74
  <div id="footer">
75
75
 
76
76
  </div>
77
- `}_isReadonly(){return this.readonly||!_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().authenticated||!_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().hasRole("write:assets")}shouldUpdate(t){var e;let n=super.shouldUpdate(t);if((t.has("assets")||t.has("rootAssets")||t.has("rootAssetIds")||t.has("queryLimit"))&&this.refresh(),!this._nodes)return this._loadAssets().catch(t=>console.log(t.message)),!0;if(t.has("selectedIds")&&void 0!==this.selectedIds){let n=t.get("selectedIds");!_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.objectsEqual(n,this.selectedIds)&&(this._updateSelectedNodes(),(null==n?void 0:n.length)===1&&this._filter.asset===n[0]&&(this.applyFilter(new OrAssetTreeFilter,!0),(null==(e=this.selectedIds)?void 0:e.length)||this._doFiltering()))}return t.has("sortBy")&&this._updateSort(this._nodes,this._getSortFunction()),t.has("disabledSubscribe")&&this.disableSubscribe&&this._removeEventSubscriptions(),n}_updateSelectedNodes(){let t,e;if(OrAssetTree_1._forEachNodeRecursive(this._nodes,n=>{if(this.selectedIds&&this.selectedIds.indexOf(n.asset.id)>=0){null!=t||(t=[]),t.push(n.asset.id),null!=e||(e=[]),e.push(n),n.selected=!0;let i=n.parent;for(;i;)i.expanded=!0,i=i.parent}else n.selected=!1;if(this.checkboxes){let e=n.parent;for(;e;){let n=[];OrAssetTree_1._forEachNodeRecursive(e.children,t=>{n.push(t)}),e.someChildrenSelected=!1,e.allChildrenSelected=!1,n.every(e=>null==t?void 0:t.includes(e.asset.id))?e.allChildrenSelected=!0:n.some(e=>null==t?void 0:t.includes(e.asset.id))&&(e.someChildrenSelected=!0),e=e.parent}}}),(null==t?void 0:t.length)&&(this.selectedIds=t),void 0!==e||void 0!==this.selectedNodes){let t=this._selectedNodes;this._selectedNodes=null!=e?e:[],this.dispatchEvent(new OrAssetTreeSelectionEvent({oldNodes:t,newNodes:null!=e?e:[]}))}}_updateSort(t,e){t&&(t.sort(e),t.forEach(t=>this._updateSort(t.children,e)))}_toggleExpander(t,e){return __awaiter(this,arguments,void 0,function*(t,e,n=!1){var i,r,o,a;if(e&&e.expandable){if(e.expanded=!e.expanded,e.expanded)if(this._expandedNodes.push(e),null==(i=e.children)?void 0:i.length)console.debug(`Reusing cache for loading children of asset ${null==(r=e.asset)?void 0:r.id}...`);else{let t=[];OrAssetTree_1._forEachNodeRecursive(null!=(o=this._nodes)?o:[],e=>e.asset&&t.push(e.asset)),yield this._loadAssets(null==(a=e.asset)?void 0:a.id,0,t).catch(t=>console.log(t.message))}else this._expandedNodes=this._expandedNodes.filter(t=>t!==e);t.parentElement.parentElement.parentElement.toggleAttribute("data-expanded",e.expanded),n||this.dispatchEvent(new OrAssetTreeToggleExpandEvent({node:e})),this.requestUpdate()}})}_buildPaths(t){let e=[];return t.asset&&t.asset.id?(e.push(t.asset.id),t.children.length>0&&t.expanded&&t.children.forEach(t=>{e=e.concat(this._buildPaths(t))}),e):[]}_findNode(t,e){if(t.asset&&t.asset.id){if(t.asset.id===e)return t;if(t.children.length>0&&t.expanded){let n;return t.children.forEach(t=>{n||(n=this._findNode(t,e))}),n}return}}_findNodeFromAssetId(t){if(this._nodes){let e;return this._nodes.forEach(n=>{e||(e=this._findNode(n,t))}),e}}_onNodeClicked(t,e){var n,i,r,o,a,l,c,s,d,p;if(t&&t.defaultPrevented)return;t&&t.preventDefault();let m=t&&t.target.className.indexOf("expander")>=0,u=t&&(null==(i=null==(n=t.target)?void 0:n.icon)?void 0:i.includes("checkbox-multiple")),f=t&&(null==(o=null==(r=t.target)?void 0:r.parentElement)?void 0:o.classList.contains("loadmore-element"));if(m)this._toggleExpander(t.target,e);else if(f){if(e){let t=[];OrAssetTree_1._forEachNodeRecursive(null!=(a=this._nodes)?a:[],e=>e.asset&&t.push(e.asset)),this._loadAssets(null==(l=e.asset)?void 0:l.id,null!=(s=null==(c=e.children)?void 0:c.length)?s:0,t)}}else{let n=!0;if(e&&this.config&&(null==(d=this.config.select)?void 0:d.types)&&(n=this.config.select.types.indexOf(e.asset.type)>=0),!n&&!u)return;let i=[];if(e){let n=this.selectedNodes.indexOf(e),r=!0,o=!0,a=!this._isReadonly()&&(!this.config||!this.config.select||!this.config.select.multiSelect);if((this.checkboxes||a&&t&&(t.ctrlKey||t.shiftKey||t.metaKey))&&(o=!1,n>=0&&this.selectedIds&&this.selectedIds.length>1&&(r=!1)),u){i=[...this.selectedNodes];let t=[];OrAssetTree_1._forEachNodeRecursive(e.children,e=>{var n,i;let r=!0;e&&(null==(i=null==(n=this.config)?void 0:n.select)?void 0:i.types)&&(r=this.config.select.types.indexOf(e.asset.type)>=0),r&&t.push(e)}),i=e.allChildrenSelected?i.filter(e=>!t.map(t=>t.asset.id).includes(e.asset.id)):i.concat(t)}else if(o)this._latestSelected=Object.assign({},e),i=[e];else if(r){if(n<0){if(t&&t.shiftKey){let t=[];if(null==(p=this._nodes)||p.forEach(e=>{t=t.concat(this._buildPaths(e))}),this._latestSelected&&this._latestSelected.asset&&this._latestSelected.asset.id&&e.asset&&e.asset.id){let n=this._latestSelected.asset.id,r=e.asset.id,o=t.findIndex(t=>t.includes(n)),a=t.findIndex(t=>t.includes(r)),l=-1,c=-1;o>a?(l=a,c=o):(l=o,c=a);let s=t.slice(l,c+1),d=[];s.forEach(t=>{let e=this._findNodeFromAssetId(t);e&&d.push(e)}),i=(i=[...this.selectedNodes]).concat(d)}}else(i=[...this.selectedNodes]).push(e);this._latestSelected=Object.assign({},e)}}else n>=0&&(1===(i=[...this.selectedNodes]).length&&(this._latestSelected=void 0),i.splice(n,1))}_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestSelectionEvent({oldNodes:this.selectedNodes,newNodes:i})).then(t=>{t.allow&&(this.selectedNodes=t.detail.newNodes)})}}_onDeselectClicked(){this._onNodeClicked(null,null)}parseFromInputFilter(t){var e;void 0===t&&(t=null==(e=this._filterInput)?void 0:e.value);let n=new OrAssetTreeFilter;if(t){let e=t,i=t.match(/(attribute\:)(\"[^"]+\")\S*/g);i&&(i.length>0&&i.forEach((t,i)=>{e=e.replace(t,"");let r=t.toString().indexOf("attribute:"),o=t.toString().substring(r+10+1,t.toString().length-1);n.attribute.push(o),n.attributeValue.push("")}),this._attributeValueFilter.disabled=!1),(i=t.match(/(type\:)\S+/g))&&i.length>0&&i.forEach((t,i)=>{e=e.replace(t,"");let r=t.toString().indexOf("type:"),o=t.toString().substring(r+5);n.assetType.push(o)}),(i=t.match(/(\"[^\"]+\")\:(([^\"\s]+)|(\"[^\"]+\"))/g))&&i.length>0&&i.forEach((t,i)=>{e=e.replace(t,"");let r=t.toString().indexOf('":'),o=t.toString().substring(r+2),a=t.toString().substring(1,r);'"'===o[0]&&'"'===o[o.length-1]&&(o=o.substring(1,o.length-1)),n.attribute.push(a),n.attributeValue.push(o)}),n.asset=e&&e.length>0?e.trim():void 0}return n}formatFilter(t){let e=t.asset?t.asset:"",n=t.asset?" ":"",i=[];return t.assetType.length>0&&t.assetType.forEach(t=>{e+=n+"type:"+t,n=" "}),t.attribute.length>0&&t.attributeValue.length>0&&t.attributeValue.forEach((r,o)=>{i.push(t.attribute[o]),e+=n+'"'+t.attribute[o]+'":'+r,n=" "}),t.attribute.length>0&&0===t.attributeValue.length&&t.attribute.forEach(t=>{i.includes(t)||(e+=n+'attribute:"'+t+'"',n=" ")}),e}_shouldEnableAttrTypeEvent(t){let e;t.composedPath()&&(e=t.composedPath()[0].value||void 0),this._shouldEnableAttrType(e)}_shouldEnableAttrType(t){t?this._attributeValueFilter.disabled=!1:this._attributeValueFilter.disabled=!0}applySettingFields(t){if(this._assetTypeFilter?t.assetType=[this._assetTypeFilter]:t.assetType=[],this._attributeNameFilter.value?t.attribute=[this._attributeNameFilter.value]:t.attribute=[],this._attributeNameFilter.value&&this._attributeValueFilter.value){let e=this._attributeValueFilter.value;e.includes(" ")&&(e='"'+e+'"'),t.attributeValue=[e]}else t.attributeValue=[];return t}_filterFromSettings(){let t=this.parseFromInputFilter(),e=this.applySettingFields(t);this.applyFilter(e);let n=this.formatFilter(this._filter);this._filterInput.value=n,this._filterSettingOpen=!1,this._doFiltering()}_onFilterInput(t){this.applyFilter(t),this._doFiltering()}_doFiltering(){return __awaiter(this,void 0,void 0,function*(){var t,e,n,i;if(this.isConnected&&this._nodes){if(!(null==(t=this._filter.asset)?void 0:t.length)&&!(null==(e=this._filter.attribute)?void 0:e.length)&&!(null==(n=this._filter.assetType)?void 0:n.length)&&!(null==(i=this._filter.attributeValue)?void 0:i.length)){console.debug("Clearing asset tree filter..."),OrAssetTree_1._forEachNodeRecursive(this._nodes,t=>{t.notMatchingFilter=!1,t.hidden=!1}),this.refresh();return}if(console.debug("Filtering asset tree using filter:",this._filter),this.disabled=!0,this._filter.asset||this._filter.assetType||this._filter.attribute){let t=!1;this._filter.attribute&&(t=!0),this.getMatcher(t).then(({matcher:t,assets:e})=>{var n,i;if(null!=e||(e=[]),this._nodes){let r=[];OrAssetTree_1._forEachNodeRecursive(null!=(n=this._nodes)?n:[],t=>t.asset&&r.push(t.asset));let o=new Map([...r,...e].map(t=>[t.id,t])).values();this._buildTreeNodes([...o]);let a=new Map;OrAssetTree_1._forEachNodeRecursive(null!=(i=this._nodes)?i:[],e=>{var n;let i=this.filterTreeNode(e,t);i&&!e.notMatchingFilter&&(null==(n=e.asset)?void 0:n.id)&&a.set(e.asset.id,i)}),1===a.size&&(console.debug("Only 1 asset is shown, automatically selecting it..."),this.selectedIds=Array.from(a.keys())),this.disabled=!1}})}}})}getMatcher(t){return __awaiter(this,void 0,void 0,function*(){return t?this.getMatcherFromQuery():{matcher:yield this.getSimpleNameMatcher()}})}getSimpleNameMatcher(){return __awaiter(this,void 0,void 0,function*(){return t=>{let e=!0;return this._filter.asset&&(e=e&&t.name.toLowerCase().includes(this._filter.asset.toLowerCase())),this._filter.assetType.length>0&&(e=e&&t.type.toLowerCase()===this._filter.assetType[0].toLowerCase()),e}})}getMatcherFromQuery(){return __awaiter(this,void 0,void 0,function*(){let assetCond,attributeCond,assetTypeCond,foundAssetIds,assetQueries=[];this._filter.asset&&(assetCond=[{predicateType:"string",match:"CONTAINS",value:this._filter.asset,caseSensitive:!1}]),this._filter.assetType.length>0&&(assetTypeCond=this._filter.assetType),this._filter.attribute.length>0&&(attributeCond={operator:"AND",items:this._filter.attribute.map(t=>({name:{predicateType:"string",match:"EXACT",value:_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sentenceCaseToCamelCase(t),caseSensitive:!1}}))}),assetQueries.push({realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:attributeCond?void 0:[]},orderBy:{property:this._getOrderBy(this.sortBy)},names:assetCond,types:assetTypeCond,attributes:attributeCond,limit:Math.max(this.queryLimit,1)}),this._filter.asset&&22===this._filter.asset.length&&assetQueries.push({realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:attributeCond?void 0:[]},types:assetTypeCond,attributes:attributeCond,ids:[this._filter.asset],limit:1});let foundAssets=[];try{console.debug(`Querying assets using filter '${this._filterInput.nativeValue}'...`);let promises=assetQueries.map(t=>_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.queryAssets(t));foundAssetIds=(foundAssets=(yield Promise.all(promises)).flatMap(t=>t.data)).map(t=>t.id),console.debug(`The filter query found ${foundAssets.length} assets!`)}catch(e){console.error("Error querying Asset Tree assets with filter:",e),this._filter.assetType.forEach(t=>{-1===this._assetTypes.findIndex(e=>e.name===t)&&(0,_openremote_or_mwc_components_or_mwc_snackbar__WEBPACK_IMPORTED_MODULE_13__.OV)(void 0,"filter.assetTypeDoesNotExist","dismiss")}),foundAssetIds=[]}let parentIds=new Set(foundAssets.filter(t=>t.path&&t.path.length>1).flatMap(t=>t.path.slice(0,-1))),unknownParentIds=Array.from(parentIds).filter(t=>{var e;return t&&!(null==(e=this.assets)?void 0:e.some(e=>e.id===t))});if(unknownParentIds.length>0)try{console.debug(`Querying parents of ${unknownParentIds.length} assets...`);let parentAssets=yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.queryAssets({select:{attributes:attributeCond?void 0:[]},ids:unknownParentIds});console.debug(`The filter query found ${parentAssets.data.length} parents!`),foundAssetIds=foundAssets.map(t=>t.id),foundAssets=[...foundAssets,...parentAssets.data]}catch(e){console.error("Error querying Asset Tree parents of found assets:",e)}return{assets:foundAssets,matcher:asset=>{let attrValueCheck=!0;if(this._filter.attribute.length>0&&this._filter.attributeValue.length>0&&foundAssetIds.includes(asset.id)){let attributeVal=[];this._filter.attributeValue.forEach((t,e)=>{t.length>0&&attributeVal.push([this._filter.attribute[e],t])});let matchingAsset=foundAssets.find(t=>t.id===asset.id);if(matchingAsset&&matchingAsset.attributes)for(let attributeValIndex=0;attributeValIndex<attributeVal.length;attributeValIndex++){let currentAttributeVal=attributeVal[attributeValIndex],atLeastOneAttributeMatchValue=!1;Object.keys(matchingAsset.attributes).forEach(key=>{var _a,_b,_c;let attr=matchingAsset.attributes[key];if(attr.name.toLowerCase()===currentAttributeVal[0].toLowerCase())switch(attr.type){case"number":case"integer":case"long":case"bigInteger":case"bigNumber":case"positiveInteger":case"negativeInteger":case"positiveNumber":case"negativeNumber":{let normalizedValue=null==(_a=currentAttributeVal[1])?void 0:_a.replace(",",".");if(isNaN(Number(normalizedValue))){if(/\d/.test(normalizedValue)){normalizedValue.endsWith("%")&&(normalizedValue=null==normalizedValue?void 0:normalizedValue.replace("%","")),/^[0-9]/.test(normalizedValue)&&(normalizedValue="=="+normalizedValue);let func=attr.value+normalizedValue.replace(/[a-z]/gi,"");try{let resultNumberEval=eval(func);resultNumberEval&&(atLeastOneAttributeMatchValue=!0)}catch(_ignored){console.warn("Could not process filter on attribute number value;",func)}}}else(null!=(_b=attr.value)?_b:0)===Number(normalizedValue)&&(atLeastOneAttributeMatchValue=!0);break}case"boolean":{let value=currentAttributeVal[1];("false"===value||"true"===value)&&value===(null!=(_c=attr.value)&&_c).toString()&&(atLeastOneAttributeMatchValue=!0);break}case"text":if(attr.value){let unparsedValue=currentAttributeVal[1],multicharString="*",parsedValue=unparsedValue.replace(multicharString,".*");parsedValue=parsedValue.replace(/"/g,""),-1!=attr.value.toLowerCase().indexOf(parsedValue.toLowerCase())&&(atLeastOneAttributeMatchValue=!0)}}}),attrValueCheck=atLeastOneAttributeMatchValue}}return foundAssetIds.includes(asset.id)&&attrValueCheck}}})}isAnyFilter(){return void 0!==this._filter.asset||this._filter.assetType.length>0||this._filter.attribute.length>0}filterTreeNode(t,e,n=!1){let i=e(t.asset);t.notMatchingFilter=!i;let r=t.children.map(t=>this.filterTreeNode(t,e,i)).some(t=>t);return i=i||r,t.expanded=r&&t.children.length>0&&this.isAnyFilter(),t.hidden=!i&&!n,i}_onCopyClicked(){return __awaiter(this,void 0,void 0,function*(){if(1===this._selectedNodes.length)try{let t=yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.get(this._selectedNodes[0].asset.id);if(!t.data)throw Error("API returned an invalid response when retrieving the source asset");let e=JSON.parse(JSON.stringify(t.data));e.name+=" copy",delete e.id,delete e.path,delete e.createdOn,delete e.version,_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestAddEvent({sourceAsset:this._selectedNodes[0].asset,asset:e})).then(t=>{t.allow&&this.dispatchEvent(new OrAssetTreeAddEvent(t.detail))})}catch(t){console.error("Failed to copy asset",t),(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gs)("Failed to copy asset")}})}_onAddClicked(){let t,e=this._getAllowedChildTypes(this._selectedNodes[0]),n=e.filter(t=>"agent"===t.descriptorType),i=e.filter(t=>"asset"===t.descriptorType),r=this._selectedNodes&&1===this._selectedNodes.length?this._selectedNodes[0].asset:void 0,o=e=>{let n=!!e.detail.name&&e.detail.name.trim().length>0&&e.detail.name.trim().length<1024;t.shadowRoot.getElementById("add-btn").disabled=!e.detail.descriptor||!n};t=(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.vC)(new _openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.iq().setHeading(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("addAsset")).setContent((0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)`
77
+ `}_isReadonly(){return this.readonly||!_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().authenticated||!_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().hasRole("write:assets")}shouldUpdate(t){var e;let n=super.shouldUpdate(t);if((t.has("assets")||t.has("rootAssets")||t.has("rootAssetIds")||t.has("queryLimit"))&&this.refresh(),!this._nodes)return this._loadAssets().catch(t=>console.log(t.message)),!0;if(t.has("selectedIds")&&void 0!==this.selectedIds){let n=t.get("selectedIds");!_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.objectsEqual(n,this.selectedIds)&&(this._updateSelectedNodes(),(null==n?void 0:n.length)===1&&this._filter.asset===n[0]&&(this.applyFilter(new OrAssetTreeFilter,!0),(null==(e=this.selectedIds)?void 0:e.length)||this._doFiltering()))}return t.has("sortBy")&&this._updateSort(this._nodes,this._getSortFunction()),t.has("disabledSubscribe")&&this.disableSubscribe&&this._removeEventSubscriptions(),n}_updateSelectedNodes(){let t,e;if(OrAssetTree_1._forEachNodeRecursive(this._nodes,n=>{if(this.selectedIds&&this.selectedIds.indexOf(n.asset.id)>=0){null!=t||(t=[]),t.push(n.asset.id),null!=e||(e=[]),e.push(n),n.selected=!0;let i=n.parent;for(;i;)i.expanded=!0,i=i.parent}else n.selected=!1;if(this.checkboxes){let e=n.parent;for(;e;){let n=[];OrAssetTree_1._forEachNodeRecursive(e.children,t=>{n.push(t)}),e.someChildrenSelected=!1,e.allChildrenSelected=!1,n.every(e=>null==t?void 0:t.includes(e.asset.id))?e.allChildrenSelected=!0:n.some(e=>null==t?void 0:t.includes(e.asset.id))&&(e.someChildrenSelected=!0),e=e.parent}}}),(null==t?void 0:t.length)&&(this.selectedIds=t),void 0!==e||void 0!==this.selectedNodes){let t=this._selectedNodes;this._selectedNodes=null!=e?e:[],this.dispatchEvent(new OrAssetTreeSelectionEvent({oldNodes:t,newNodes:null!=e?e:[]}))}}_updateSort(t,e){t&&(t.sort(e),t.forEach(t=>this._updateSort(t.children,e)))}_toggleExpander(t,e){return __awaiter(this,arguments,void 0,function*(t,e,n=!1){var i,r,o,a;if(e&&e.expandable){if(e.expanded=!e.expanded,e.expanded)if(this._expandedNodes.push(e),null==(i=e.children)?void 0:i.length)console.debug(`Reusing cache for loading children of asset ${null==(r=e.asset)?void 0:r.id}...`);else{let t=[];OrAssetTree_1._forEachNodeRecursive(null!=(o=this._nodes)?o:[],e=>e.asset&&t.push(e.asset)),yield this._loadAssets(null==(a=e.asset)?void 0:a.id,0,t).catch(t=>console.log(t.message))}else this._expandedNodes=this._expandedNodes.filter(t=>t!==e);t.parentElement.parentElement.parentElement.toggleAttribute("data-expanded",e.expanded),n||this.dispatchEvent(new OrAssetTreeToggleExpandEvent({node:e})),this.requestUpdate()}})}_buildPaths(t){let e=[];return t.asset&&t.asset.id?(e.push(t.asset.id),t.children.length>0&&t.expanded&&t.children.forEach(t=>{e=e.concat(this._buildPaths(t))}),e):[]}_findNode(t,e){if(t.asset&&t.asset.id){if(t.asset.id===e)return t;if(t.children.length>0&&t.expanded){let n;return t.children.forEach(t=>{n||(n=this._findNode(t,e))}),n}return}}_findNodeFromAssetId(t){if(this._nodes){let e;return this._nodes.forEach(n=>{e||(e=this._findNode(n,t))}),e}}_onNodeClicked(t,e){var n,i,r,o,a,l,c,s,d,p;if(t&&t.defaultPrevented)return;t&&t.preventDefault();let m=t&&t.target.className.indexOf("expander")>=0,u=t&&(null==(i=null==(n=t.target)?void 0:n.icon)?void 0:i.includes("checkbox-multiple")),f=t&&(null==(o=null==(r=t.target)?void 0:r.parentElement)?void 0:o.classList.contains("loadmore-element"));if(m)this._toggleExpander(t.target,e);else if(f){if(e){let t=[];OrAssetTree_1._forEachNodeRecursive(null!=(a=this._nodes)?a:[],e=>e.asset&&t.push(e.asset)),this._loadAssets(null==(l=e.asset)?void 0:l.id,null!=(s=null==(c=e.children)?void 0:c.length)?s:0,t)}}else{let n=!0;if(e&&this.config&&(null==(d=this.config.select)?void 0:d.types)&&(n=this.config.select.types.indexOf(e.asset.type)>=0),!n&&!u)return;let i=[];if(e){let n=this.selectedNodes.indexOf(e),r=!0,o=!0,a=!this._isReadonly()&&(!this.config||!this.config.select||!this.config.select.multiSelect);if((this.checkboxes||a&&t&&(t.ctrlKey||t.shiftKey||t.metaKey))&&(o=!1,n>=0&&this.selectedIds&&this.selectedIds.length>1&&(r=!1)),u){i=[...this.selectedNodes];let t=[];OrAssetTree_1._forEachNodeRecursive(e.children,e=>{var n,i;let r=!0;e&&(null==(i=null==(n=this.config)?void 0:n.select)?void 0:i.types)&&(r=this.config.select.types.indexOf(e.asset.type)>=0),r&&t.push(e)}),i=e.allChildrenSelected?i.filter(e=>!t.map(t=>t.asset.id).includes(e.asset.id)):i.concat(t)}else if(o)this._latestSelected=Object.assign({},e),i=[e];else if(r){if(n<0){if(t&&t.shiftKey){let t=[];if(null==(p=this._nodes)||p.forEach(e=>{t=t.concat(this._buildPaths(e))}),this._latestSelected&&this._latestSelected.asset&&this._latestSelected.asset.id&&e.asset&&e.asset.id){let n=this._latestSelected.asset.id,r=e.asset.id,o=t.findIndex(t=>t.includes(n)),a=t.findIndex(t=>t.includes(r)),l=-1,c=-1;o>a?(l=a,c=o):(l=o,c=a);let s=t.slice(l,c+1),d=[];s.forEach(t=>{let e=this._findNodeFromAssetId(t);e&&d.push(e)}),i=(i=[...this.selectedNodes]).concat(d)}}else(i=[...this.selectedNodes]).push(e);this._latestSelected=Object.assign({},e)}}else n>=0&&(1===(i=[...this.selectedNodes]).length&&(this._latestSelected=void 0),i.splice(n,1))}_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestSelectionEvent({oldNodes:this.selectedNodes,newNodes:i})).then(t=>{t.allow&&(this.selectedNodes=t.detail.newNodes)})}}_onDeselectClicked(){this._onNodeClicked(null,null)}parseFromInputFilter(t){var e;void 0===t&&(t=null==(e=this._filterInput)?void 0:e.value);let n=new OrAssetTreeFilter;if(t){let e=t,i=t.match(/(attribute\:)(\"[^"]+\")\S*/g);i&&(i.length>0&&i.forEach((t,i)=>{e=e.replace(t,"");let r=t.toString().indexOf("attribute:"),o=t.toString().substring(r+10+1,t.toString().length-1);n.attribute.push(o),n.attributeValue.push("")}),this._attributeValueFilter.disabled=!1),(i=t.match(/(type\:)\S+/g))&&i.length>0&&i.forEach((t,i)=>{e=e.replace(t,"");let r=t.toString().indexOf("type:"),o=t.toString().substring(r+5);n.assetType.push(o)}),(i=t.match(/(\"[^\"]+\")\:(([^\"\s]+)|(\"[^\"]+\"))/g))&&i.length>0&&i.forEach((t,i)=>{e=e.replace(t,"");let r=t.toString().indexOf('":'),o=t.toString().substring(r+2),a=t.toString().substring(1,r);'"'===o[0]&&'"'===o[o.length-1]&&(o=o.substring(1,o.length-1)),n.attribute.push(a),n.attributeValue.push(o)}),n.asset=e&&e.length>0?e.trim():void 0}return n}formatFilter(t){let e=t.asset?t.asset:"",n=t.asset?" ":"",i=[];return t.assetType.length>0&&t.assetType.forEach(t=>{e+=n+"type:"+t,n=" "}),t.attribute.length>0&&t.attributeValue.length>0&&t.attributeValue.forEach((r,o)=>{i.push(t.attribute[o]),e+=n+'"'+t.attribute[o]+'":'+r,n=" "}),t.attribute.length>0&&0===t.attributeValue.length&&t.attribute.forEach(t=>{i.includes(t)||(e+=n+'attribute:"'+t+'"',n=" ")}),e}_shouldEnableAttrTypeEvent(t){let e;t.composedPath()&&(e=t.composedPath()[0].value||void 0),this._shouldEnableAttrType(e)}_shouldEnableAttrType(t){t?this._attributeValueFilter.disabled=!1:this._attributeValueFilter.disabled=!0}applySettingFields(t){if(this._assetTypeFilter?t.assetType=[this._assetTypeFilter]:t.assetType=[],this._attributeNameFilter.value?t.attribute=[this._attributeNameFilter.value]:t.attribute=[],this._attributeNameFilter.value&&this._attributeValueFilter.value){let e=this._attributeValueFilter.value;e.includes(" ")&&(e='"'+e+'"'),t.attributeValue=[e]}else t.attributeValue=[];return t}_filterFromSettings(){let t=this.parseFromInputFilter(),e=this.applySettingFields(t);this.applyFilter(e);let n=this.formatFilter(this._filter);this._filterInput.value=n,this._filterSettingOpen=!1,this._doFiltering()}_onFilterInput(t){this.applyFilter(t),this._doFiltering()}_doFiltering(){return __awaiter(this,void 0,void 0,function*(){var t,e,n,i;if(this.isConnected&&this._nodes){if(!(null==(t=this._filter.asset)?void 0:t.length)&&!(null==(e=this._filter.attribute)?void 0:e.length)&&!(null==(n=this._filter.assetType)?void 0:n.length)&&!(null==(i=this._filter.attributeValue)?void 0:i.length)){console.debug("Clearing asset tree filter..."),OrAssetTree_1._forEachNodeRecursive(this._nodes,t=>{t.notMatchingFilter=!1,t.hidden=!1}),this.refresh();return}if(console.debug("Filtering asset tree using filter:",this._filter),this.disabled=!0,this._filter.asset||this._filter.assetType||this._filter.attribute){let t=!1;this._filter.attribute&&(t=!0),this.getMatcher(t).then(({matcher:t,assets:e})=>{var n,i;if(null!=e||(e=[]),this._nodes){let r=[];OrAssetTree_1._forEachNodeRecursive(null!=(n=this._nodes)?n:[],t=>t.asset&&r.push(t.asset));let o=new Map([...r,...e].map(t=>[t.id,t])).values();this._buildTreeNodes([...o]);let a=new Map;OrAssetTree_1._forEachNodeRecursive(null!=(i=this._nodes)?i:[],e=>{var n;let i=this.filterTreeNode(e,t);i&&!e.notMatchingFilter&&(null==(n=e.asset)?void 0:n.id)&&a.set(e.asset.id,i)}),1===a.size&&(console.debug("Only 1 asset is shown, automatically selecting it..."),this.selectedIds=Array.from(a.keys())),this.disabled=!1}})}}})}getMatcher(t){return __awaiter(this,void 0,void 0,function*(){return t?this.getMatcherFromQuery():{matcher:yield this.getSimpleNameMatcher()}})}getSimpleNameMatcher(){return __awaiter(this,void 0,void 0,function*(){return t=>{let e=!0;return this._filter.asset&&(e=e&&t.name.toLowerCase().includes(this._filter.asset.toLowerCase())),this._filter.assetType.length>0&&(e=e&&t.type.toLowerCase()===this._filter.assetType[0].toLowerCase()),e}})}getMatcherFromQuery(){return __awaiter(this,void 0,void 0,function*(){let assetCond,attributeCond,assetTypeCond,foundAssetIds,assetQueries=[];this._filter.asset&&(assetCond=[{predicateType:"string",match:"CONTAINS",value:this._filter.asset,caseSensitive:!1}]),this._filter.assetType.length>0&&(assetTypeCond=this._filter.assetType),this._filter.attribute.length>0&&(attributeCond={operator:"AND",items:this._filter.attribute.map(t=>({name:{predicateType:"string",match:"EXACT",value:_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.sentenceCaseToCamelCase(t),caseSensitive:!1}}))}),assetQueries.push({realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:attributeCond?void 0:[]},orderBy:{property:this._getOrderBy(this.sortBy)},names:assetCond,types:assetTypeCond,attributes:attributeCond,limit:Math.max(this.queryLimit,1)}),this._filter.asset&&22===this._filter.asset.length&&assetQueries.push({realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},select:{attributes:attributeCond?void 0:[]},types:assetTypeCond,attributes:attributeCond,ids:[this._filter.asset],limit:1});let foundAssets=[];try{console.debug(`Querying assets using filter '${this._filterInput.nativeValue}'...`);let promises=assetQueries.map(t=>_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.queryAssetTree(t));foundAssetIds=(foundAssets=(yield Promise.all(promises)).flatMap(t=>{var e;return null!=(e=t.data.assets)?e:[]})).map(t=>t.id),console.debug(`The filter query found ${foundAssets.length} assets!`)}catch(e){console.error("Error querying Asset Tree assets with filter:",e),this._filter.assetType.forEach(t=>{-1===this._assetTypes.findIndex(e=>e.name===t)&&(0,_openremote_or_mwc_components_or_mwc_snackbar__WEBPACK_IMPORTED_MODULE_13__.OV)(void 0,"filter.assetTypeDoesNotExist","dismiss")}),foundAssetIds=[]}let parentIds=new Set(foundAssets.filter(t=>t.path&&t.path.length>1).flatMap(t=>t.path.slice(0,-1))),unknownParentIds=Array.from(parentIds).filter(t=>{var e;return t&&!(null==(e=this.assets)?void 0:e.some(e=>e.id===t))});if(unknownParentIds.length>0)try{console.debug(`Querying parents of ${unknownParentIds.length} assets...`);let parentAssets=yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.queryAssets({select:{attributes:attributeCond?void 0:[]},ids:unknownParentIds});console.debug(`The filter query found ${parentAssets.data.length} parents!`),foundAssetIds=foundAssets.map(t=>t.id),foundAssets=[...foundAssets,...parentAssets.data]}catch(e){console.error("Error querying Asset Tree parents of found assets:",e)}return{assets:foundAssets,matcher:asset=>{let attrValueCheck=!0;if(this._filter.attribute.length>0&&this._filter.attributeValue.length>0&&foundAssetIds.includes(asset.id)){let attributeVal=[];this._filter.attributeValue.forEach((t,e)=>{t.length>0&&attributeVal.push([this._filter.attribute[e],t])});let matchingAsset=foundAssets.find(t=>t.id===asset.id);if(matchingAsset&&matchingAsset.attributes)for(let attributeValIndex=0;attributeValIndex<attributeVal.length;attributeValIndex++){let currentAttributeVal=attributeVal[attributeValIndex],atLeastOneAttributeMatchValue=!1;Object.keys(matchingAsset.attributes).forEach(key=>{var _a,_b,_c;let attr=matchingAsset.attributes[key];if(attr.name.toLowerCase()===currentAttributeVal[0].toLowerCase())switch(attr.type){case"number":case"integer":case"long":case"bigInteger":case"bigNumber":case"positiveInteger":case"negativeInteger":case"positiveNumber":case"negativeNumber":{let normalizedValue=null==(_a=currentAttributeVal[1])?void 0:_a.replace(",",".");if(isNaN(Number(normalizedValue))){if(/\d/.test(normalizedValue)){normalizedValue.endsWith("%")&&(normalizedValue=null==normalizedValue?void 0:normalizedValue.replace("%","")),/^[0-9]/.test(normalizedValue)&&(normalizedValue="=="+normalizedValue);let func=attr.value+normalizedValue.replace(/[a-z]/gi,"");try{let resultNumberEval=eval(func);resultNumberEval&&(atLeastOneAttributeMatchValue=!0)}catch(_ignored){console.warn("Could not process filter on attribute number value;",func)}}}else(null!=(_b=attr.value)?_b:0)===Number(normalizedValue)&&(atLeastOneAttributeMatchValue=!0);break}case"boolean":{let value=currentAttributeVal[1];("false"===value||"true"===value)&&value===(null!=(_c=attr.value)&&_c).toString()&&(atLeastOneAttributeMatchValue=!0);break}case"text":if(attr.value){let unparsedValue=currentAttributeVal[1],multicharString="*",parsedValue=unparsedValue.replace(multicharString,".*");parsedValue=parsedValue.replace(/"/g,""),-1!=attr.value.toLowerCase().indexOf(parsedValue.toLowerCase())&&(atLeastOneAttributeMatchValue=!0)}}}),attrValueCheck=atLeastOneAttributeMatchValue}}return foundAssetIds.includes(asset.id)&&attrValueCheck}}})}isAnyFilter(){return void 0!==this._filter.asset||this._filter.assetType.length>0||this._filter.attribute.length>0}filterTreeNode(t,e,n=!1){let i=e(t.asset);t.notMatchingFilter=!i;let r=t.children.map(t=>this.filterTreeNode(t,e,i)).some(t=>t);return i=i||r,t.expanded=r&&t.children.length>0&&this.isAnyFilter(),t.hidden=!i&&!n,i}_onCopyClicked(){return __awaiter(this,void 0,void 0,function*(){if(1===this._selectedNodes.length)try{let t=yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.get(this._selectedNodes[0].asset.id);if(!t.data)throw Error("API returned an invalid response when retrieving the source asset");let e=JSON.parse(JSON.stringify(t.data));e.name+=" copy",delete e.id,delete e.path,delete e.createdOn,delete e.version,_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestAddEvent({sourceAsset:this._selectedNodes[0].asset,asset:e})).then(t=>{t.allow&&this.dispatchEvent(new OrAssetTreeAddEvent(t.detail))})}catch(t){console.error("Failed to copy asset",t),(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gs)("Failed to copy asset")}})}_onAddClicked(){let t,e=this._getAllowedChildTypes(this._selectedNodes[0]),n=e.filter(t=>"agent"===t.descriptorType),i=e.filter(t=>"asset"===t.descriptorType),r=this._selectedNodes&&1===this._selectedNodes.length?this._selectedNodes[0].asset:void 0,o=e=>{let n=!!e.detail.name&&e.detail.name.trim().length>0&&e.detail.name.trim().length<1024;t.shadowRoot.getElementById("add-btn").disabled=!e.detail.descriptor||!n};t=(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.vC)(new _openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.iq().setHeading(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("addAsset")).setContent((0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)`
78
78
  <or-add-asset-dialog id="add-panel" .config="${this.config}" .agentTypes="${n}" .assetTypes="${i}" .parent="${r}" @or-add-asset-changed="${o}"></or-add-asset-dialog>
79
79
  `).setActions([{actionName:"cancel",content:"cancel"},{actionName:"add",content:(0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)`<or-mwc-input id="add-btn" class="button" .type="${_openremote_or_mwc_components_or_mwc_input__WEBPACK_IMPORTED_MODULE_2__.n$.BUTTON}" label="add" disabled></or-mwc-input>`,action:()=>{let e=t.shadowRoot.getElementById("add-panel"),n=e.selectedType,i=e.selectedAttributes,r=e.name.trim(),o=e.parent;if(!n)return;let a={name:r,type:n.name,realm:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},l=_openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetTypeInfo(n.name);if(!l)return;l.attributeDescriptors&&(a.attributes={},l.attributeDescriptors.filter(t=>!t.optional).forEach(t=>{a.attributes[t.name]={name:t.name,type:t.type,meta:t.meta?Object.assign({},t.meta):void 0}})),i&&(null==i||i.forEach(t=>{a.attributes[t.name]={name:t.name,type:t.type,meta:t.meta?Object.assign({},t.meta):void 0}})),this.selectedIds&&(a.parentId=o?o.id:void 0);let c={asset:a};_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.dispatchCancellableEvent(this,new OrAssetTreeRequestAddEvent(c)).then(t=>{t.allow&&this.dispatchEvent(new OrAssetTreeAddEvent(t.detail))})}}]).setStyles((0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)`
80
80
  <style>