@openremote/or-asset-tree 1.8.0-snapshot.20250728151446 → 1.8.0-snapshot.20250808124803

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.
@@ -66,7 +66,7 @@
66
66
  <div id="footer">
67
67
 
68
68
  </div>
69
- `}_isReadonly(){return this.readonly||!_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().hasRole("write:assets")}shouldUpdate(t){let e=super.shouldUpdate(t);return((t.has("assets")||t.has("rootAssets")||t.has("rootAssetIds"))&&(this._nodes=void 0),this._nodes)?(t.has("selectedIds")&&!_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.objectsEqual(t.get("selectedIds"),this.selectedIds)&&this._updateSelectedNodes(),t.has("sortBy")&&this._updateSort(this._nodes,this._getSortFunction()),t.has("disabledSubscribe")&&this.disableSubscribe&&this._removeEventSubscriptions(),e):(this._loadAssets(),!0)}_updateSelectedNodes(){let t=[],e=[];OrAssetTree_1._forEachNodeRecursive(this._nodes,n=>{if(this.selectedIds&&this.selectedIds.indexOf(n.asset.id)>=0){t.push(n.asset.id),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=>t.includes(e.asset.id))?e.allChildrenSelected=!0:n.some(e=>t.includes(e.asset.id))&&(e.someChildrenSelected=!0),e=e.parent}}}),this.selectedIds=t;let n=this._selectedNodes;this._selectedNodes=e,this.dispatchEvent(new OrAssetTreeSelectionEvent({oldNodes:n,newNodes:e}))}_updateSort(t,e){t&&(t.sort(e),t.forEach(t=>this._updateSort(t.children,e)))}_toggleExpander(t,e,n=!1){e&&e.expandable&&(e.expanded=!e.expanded,e.expanded?this._expandedNodes.push(e):this._expandedNodes=this._expandedNodes.filter(t=>t!==e),t.parentElement.parentElement.parentElement.toggleAttribute("data-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;if(t&&t.defaultPrevented)return;t&&t.preventDefault();let a=t&&t.target.className.indexOf("expander")>=0,l=t&&(null==(i=null==(n=t.target)?void 0:n.icon)?void 0:i.includes("checkbox-multiple"));if(a)this._toggleExpander(t.target,e);else{let n=!0;if(e&&this.config&&(null==(r=this.config.select)?void 0:r.types)&&(n=this.config.select.types.indexOf(e.asset.type)>=0),!n&&!l)return;let i=[];if(e){let n=this.selectedNodes.indexOf(e),r=!0,a=!0,c=!this._isReadonly()&&(!this.config||!this.config.select||!this.config.select.multiSelect);if((this.checkboxes||c&&t&&(t.ctrlKey||t.shiftKey||t.metaKey))&&(a=!1,n>=0&&this.selectedIds&&this.selectedIds.length>1&&(r=!1)),l){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(a)this._latestSelected=Object.assign({},e),i=[e];else if(r){if(n<0){if(t&&t.shiftKey){let t=[];if(null==(o=this._nodes)||o.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 d=t.slice(l,c+1),s=[];d.forEach(t=>{let e=this._findNodeFromAssetId(t);e&&s.push(e)}),i=(i=[...this.selectedNodes]).concat(s)}}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){let e=this._filterInput.value;t&&(e=t);let n=new OrAssetTreeFilter;if(e){let t=e,i=e.match(/(attribute\:)(\"[^"]+\")\S*/g);i&&(i.length>0&&i.forEach((e,i)=>{t=t.replace(e,"");let r=e.toString().indexOf("attribute:"),o=e.toString().substring(r+10+1,e.toString().length-1);n.attribute.push(o),n.attributeValue.push("")}),this._attributeValueFilter.disabled=!1),(i=e.match(/(type\:)\S+/g))&&i.length>0&&i.forEach((e,i)=>{t=t.replace(e,"");let r=e.toString().indexOf("type:"),o=e.toString().substring(r+5);n.assetType.push(o)}),(i=e.match(/(\"[^\"]+\")\:(([^\"\s]+)|(\"[^\"]+\"))/g))&&i.length>0&&i.forEach((e,i)=>{t=t.replace(e,"");let r=e.toString().indexOf('":'),o=e.toString().substring(r+2),a=e.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=t&&t.length>0?t.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._filter=e;let n=this.formatFilter(this._filter);this._filterInput.value=n,this._filterSettingOpen=!1,this._doFiltering()}_onFilterInputEvent(t){let e;t.composedPath()&&(e=t.composedPath()[0].value||void 0),this._onFilterInput(e,!1)}_onFilterInput(t,e){let n=this.parseFromInputFilter(t);_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.objectsEqual(this._filter,n,!0)||(this._filter=n,this._searchInputTimer&&clearTimeout(this._searchInputTimer),e?this._doFiltering():this._searchInputTimer=window.setTimeout(()=>{this._doFiltering()},350))}_doFiltering(){return __awaiter(this,void 0,void 0,function*(){if(this._searchInputTimer&&(clearTimeout(this._searchInputTimer),this._searchInputTimer=void 0),this.isConnected&&this._nodes){if(!this._filter.asset&&!this._filter.attribute&&!this._filter.assetType&&!this._filter.attributeValue){OrAssetTree_1._forEachNodeRecursive(this._nodes,t=>{t.notMatchingFilter=!1,t.hidden=!1}),this.requestUpdate("_nodes");return}if(this.disabled=!0,this._filter.asset||this._filter.assetType||this._filter.attribute){let t=!1;this._filter.attribute&&(t=!0),this.getMatcher(t).then(t=>{this._nodes&&(this._nodes.forEach(e=>{this.filterTreeNode(e,t)}),this.disabled=!1)})}}})}getMatcher(t){return t?this.getMatcherFromQuery():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 response,foundAssetIds,assetCond,attributeCond,assetTypeCond;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}}))});let query={select:{attributes:attributeCond?void 0:[]},names:assetCond,types:assetTypeCond,attributes:attributeCond};try{foundAssetIds=(response=yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.queryAssets(query)).data.map(t=>t.id)}catch(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=[]}return 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=response.data.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=>{let attr=matchingAsset.attributes[key];if(attr.name.toLowerCase()===currentAttributeVal[0].toLowerCase()&&attr.value)switch(attr.type){case"number":case"integer":case"long":case"bigInteger":case"bigNumber":case"positiveInteger":case"negativeInteger":case"positiveNumber":case"negativeNumber":let value=currentAttributeVal[1];currentAttributeVal[1].startsWith("=")&&"="!==currentAttributeVal[1][1]&&(value="="+value),/^[0-9]+$/.test(currentAttributeVal[1])&&(value="=="+value);let resultNumberEval=eval(attr.value+value);resultNumberEval&&(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)`
69
+ `}_isReadonly(){return this.readonly||!_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().hasRole("write:assets")}shouldUpdate(t){let e=super.shouldUpdate(t);return((t.has("assets")||t.has("rootAssets")||t.has("rootAssetIds"))&&(this._nodes=void 0),this._nodes)?(t.has("selectedIds")&&!_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.objectsEqual(t.get("selectedIds"),this.selectedIds)&&this._updateSelectedNodes(),t.has("sortBy")&&this._updateSort(this._nodes,this._getSortFunction()),t.has("disabledSubscribe")&&this.disableSubscribe&&this._removeEventSubscriptions(),e):(this._loadAssets(),!0)}_updateSelectedNodes(){let t=[],e=[];OrAssetTree_1._forEachNodeRecursive(this._nodes,n=>{if(this.selectedIds&&this.selectedIds.indexOf(n.asset.id)>=0){t.push(n.asset.id),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=>t.includes(e.asset.id))?e.allChildrenSelected=!0:n.some(e=>t.includes(e.asset.id))&&(e.someChildrenSelected=!0),e=e.parent}}}),this.selectedIds=t;let n=this._selectedNodes;this._selectedNodes=e,this.dispatchEvent(new OrAssetTreeSelectionEvent({oldNodes:n,newNodes:e}))}_updateSort(t,e){t&&(t.sort(e),t.forEach(t=>this._updateSort(t.children,e)))}_toggleExpander(t,e,n=!1){e&&e.expandable&&(e.expanded=!e.expanded,e.expanded?this._expandedNodes.push(e):this._expandedNodes=this._expandedNodes.filter(t=>t!==e),t.parentElement.parentElement.parentElement.toggleAttribute("data-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;if(t&&t.defaultPrevented)return;t&&t.preventDefault();let a=t&&t.target.className.indexOf("expander")>=0,l=t&&(null==(i=null==(n=t.target)?void 0:n.icon)?void 0:i.includes("checkbox-multiple"));if(a)this._toggleExpander(t.target,e);else{let n=!0;if(e&&this.config&&(null==(r=this.config.select)?void 0:r.types)&&(n=this.config.select.types.indexOf(e.asset.type)>=0),!n&&!l)return;let i=[];if(e){let n=this.selectedNodes.indexOf(e),r=!0,a=!0,c=!this._isReadonly()&&(!this.config||!this.config.select||!this.config.select.multiSelect);if((this.checkboxes||c&&t&&(t.ctrlKey||t.shiftKey||t.metaKey))&&(a=!1,n>=0&&this.selectedIds&&this.selectedIds.length>1&&(r=!1)),l){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(a)this._latestSelected=Object.assign({},e),i=[e];else if(r){if(n<0){if(t&&t.shiftKey){let t=[];if(null==(o=this._nodes)||o.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 d=t.slice(l,c+1),s=[];d.forEach(t=>{let e=this._findNodeFromAssetId(t);e&&s.push(e)}),i=(i=[...this.selectedNodes]).concat(s)}}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){let e=this._filterInput.value;t&&(e=t);let n=new OrAssetTreeFilter;if(e){let t=e,i=e.match(/(attribute\:)(\"[^"]+\")\S*/g);i&&(i.length>0&&i.forEach((e,i)=>{t=t.replace(e,"");let r=e.toString().indexOf("attribute:"),o=e.toString().substring(r+10+1,e.toString().length-1);n.attribute.push(o),n.attributeValue.push("")}),this._attributeValueFilter.disabled=!1),(i=e.match(/(type\:)\S+/g))&&i.length>0&&i.forEach((e,i)=>{t=t.replace(e,"");let r=e.toString().indexOf("type:"),o=e.toString().substring(r+5);n.assetType.push(o)}),(i=e.match(/(\"[^\"]+\")\:(([^\"\s]+)|(\"[^\"]+\"))/g))&&i.length>0&&i.forEach((e,i)=>{t=t.replace(e,"");let r=e.toString().indexOf('":'),o=e.toString().substring(r+2),a=e.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=t&&t.length>0?t.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._filter=e;let n=this.formatFilter(this._filter);this._filterInput.value=n,this._filterSettingOpen=!1,this._doFiltering()}_onFilterInputEvent(t){let e;t.composedPath()&&(e=t.composedPath()[0].value||void 0),this._onFilterInput(e,!1)}_onFilterInput(t,e){let n=this.parseFromInputFilter(t);_openremote_core__WEBPACK_IMPORTED_MODULE_7__.Util.objectsEqual(this._filter,n,!0)||(this._filter=n,this._searchInputTimer&&clearTimeout(this._searchInputTimer),e?this._doFiltering():this._searchInputTimer=window.setTimeout(()=>{this._doFiltering()},350))}_doFiltering(){return __awaiter(this,void 0,void 0,function*(){if(this._searchInputTimer&&(clearTimeout(this._searchInputTimer),this._searchInputTimer=void 0),this.isConnected&&this._nodes){if(!this._filter.asset&&!this._filter.attribute&&!this._filter.assetType&&!this._filter.attributeValue){OrAssetTree_1._forEachNodeRecursive(this._nodes,t=>{t.notMatchingFilter=!1,t.hidden=!1}),this.requestUpdate("_nodes");return}if(this.disabled=!0,this._filter.asset||this._filter.assetType||this._filter.attribute){let t=!1;this._filter.attribute&&(t=!0),this.getMatcher(t).then(t=>{this._nodes&&(this._nodes.forEach(e=>{this.filterTreeNode(e,t)}),this.disabled=!1)})}}})}getMatcher(t){return t?this.getMatcherFromQuery():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 response,foundAssetIds,assetCond,attributeCond,assetTypeCond;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}}))});let query={select:{attributes:attributeCond?void 0:[]},names:assetCond,types:assetTypeCond,attributes:attributeCond};try{foundAssetIds=(response=yield _openremote_core__WEBPACK_IMPORTED_MODULE_7___default().rest.api.AssetResource.queryAssets(query)).data.map(t=>t.id)}catch(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=[]}return 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=response.data.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)`
70
70
  <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>
71
71
  `).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)`
72
72
  <style>