@openremote/or-asset-tree 1.11.1 → 1.11.3
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 +2 -2
- package/dist/umd/index.bundle.js.map +1 -1
- package/dist/umd/index.js +2 -2
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +3 -3
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
package/dist/umd/index.bundle.js
CHANGED
|
@@ -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(console.warn),!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.warn(t))}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.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)`
|
|
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>
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
padding: 0 !important;
|
|
83
83
|
}
|
|
84
84
|
</style>
|
|
85
|
-
`).setDismissAction(null))}_gatewayDescendantIsSelected(){return this._selectedNodes.some(t=>{var e;let n=null==t?void 0:t.parent;for(;n;){if((null==(e=n.asset)?void 0:e.type)==="GatewayAsset")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;let t=new Set,e=this._selectedNodes.filter(e=>{var n;return(null==(n=e.asset)?void 0:n.type)!=="GatewayAsset"||(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.type)&&(r=!1),i=i.parent;r&&t.add(e.asset)});let 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._onDeselectClicked(),204!==t.status&&(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gs)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}).catch(t=>{(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gs)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}).finally(()=>{this.disabled=!1})};(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.w)(_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;let e=this._selectedNodes?this._selectedNodes[0]:void 0;return!((null==(t=null==e?void 0:e.asset)?void 0:t.type)==="GatewayAsset"||this._gatewayDescendantIsSelected())&&this._getAllowedChildTypes(e).length>0}_getAllowedChildTypes(t){let e,n;if(this.config&&this.config.add){if(this.config.add.typesProvider){let 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])}_getOrderBy(t){switch(t){case"createdOn":return"CREATED_ON";case"type":return"ASSET_TYPE";default:return"NAME"}}_loadAssets(t){return __awaiter(this,arguments,void 0,function*(t,e=0,n){if(console.debug(`Loading assets with ${t?`parent ${t}`:"no parents"}...`),this.assets){console.debug("Assets already pre-loaded using HTML attributes; reusing them to construct the tree UI..."),this._loading=!1,this._buildTreeNodes(this.assets);return}if(!this._connected)throw Error("Not connected to the server; cannot load assets.");if(this._loading)throw Error("Already loading assets for asset tree; ignoring request.");if(this._loading=!0,this.dataProvider)this.dataProvider().then(t=>{var e;this._loading=!1,this._buildTreeNodes(t),(null==(e=this._filterInput)?void 0:e.value)&&this._doFiltering()});else{let i={realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},parents:t?[{id:t}]:[],select:{attributes:[]},orderBy:{property:this._getOrderBy(this.sortBy)},offset:e,limit:Math.max(this.queryLimit,1)};this.assetIds?(i.ids=this.assetIds,i.recursive=!0):this.rootAssets?(i.ids=this.rootAssets.map(t=>t.id),i.recursive=!0):this.rootAssetIds&&(i.ids=this.rootAssetIds,i.recursive=!0);let r=this._sendEventWithReply({eventType:"read-asset-tree",assetQuery:i});return r.then(e=>{var i,r,o,a,l,c;let s=null!=(r=null==(i=e.assetTree)?void 0:i.assets)?r:[],d=null!=(a=null==(o=e.assetTree)?void 0:o.hasMore)&&a;if(t?t&&this._incompleteParentIds.includes(t)&&!d?this._incompleteParentIds=this._incompleteParentIds.filter(e=>e!==t):t&&d&&(this._incompleteParentIds=[...this._incompleteParentIds,t]):this._hasMoreParents=d,console.debug(`Received read-assets-tree event with ${s.length} assets.`),console.debug(`Combining these assets with the cache of ${null!=(l=null==n?void 0:n.length)?l:0} assets...`),this._loading=!1,n){let t=[...n,...s.filter(t=>!n.find(e=>e.id===t.id))];this._buildTreeNodes(t)}else this._buildTreeNodes(s);(null==(c=this._filterInput)?void 0:c.value)&&this._doFiltering()}),r}})}_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().catch(console.warn)}onEventsDisconnect(){this._connected=!1,this._nodes=void 0}getNodes(){return this._nodes||[]}_onEvent(t){var e;if("assets"===t.eventType){let e=t;this._buildTreeNodes(e.assets);return}if("asset"===t.eventType){let n=t;if("READ"===n.cause||"UPDATE"===n.cause&&!(n.updatedProperties.includes("name")||n.updatedProperties.includes("parentId")))return;let i=[];"DELETE"!==n.cause&&i.push(n.asset),this._nodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,t=>{t.asset.id!==n.asset.id&&i.push(t.asset)}),this._buildTreeNodes(i),(null==(e=this._filterInput)?void 0:e.value)&&this._doFiltering(),this.dispatchEvent(new OrAssetTreeAssetEvent(n))}}_buildTreeNodes(t,e=this._getSortFunction()){var n;if(console.debug(`Building asset tree nodes for ${t.length} assets...`),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++){let 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;let r=[];this._expandedNodes.forEach(t=>{OrAssetTree_1._forEachNodeRecursive(this._nodes,e=>{var n,i;if((null==(n=e.asset)?void 0:n.id)&&(null==(i=null==t?void 0:t.asset)?void 0:i.id)&&e.asset.id===t.asset.id&&this.isExpandable(t.asset.id)){e.expanded=!0,r.push(e);let t=e.parent;for(;t;)t.expanded=!0,t=t.parent,0>r.indexOf(t)&&r.push(t)}})}),this._expandedNodes=r}else this._nodes=[];console.debug(`Asset tree nodes built. Now selecting ${null==(n=this.selectedIds)?void 0:n.length} 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){var i,r;let o=this.assetsChildren[t.asset.id];t.children=o?o.sort(n):[],t.expandable=(null==(i=t.asset)?void 0:i.hasChildren)||(null==(r=t.children)?void 0:r.length),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){let e=t.x,n=t.y;if(null!==this.shadowRoot){let t=this.shadowRoot.getElementById("list");if(t){let 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?void 0:this._dragDropParentId,this.selectedIds))}isExpandable(t){return!!(this._nodes&&this.shadowRoot&&this.shadowRoot.querySelector('[node-asset-id="'+t+'"] > .node-name > [data-expandable]'))||!1}_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){let n=this._findNodeFromAssetId(t),i=null==(e=this.shadowRoot)?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){var n;let i,r=_openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptor(t.asset.type);if(i=t.allChildrenSelected?"checkbox-multiple-marked":t.someChildrenSelected?"checkbox-multiple-marked-outline":"checkbox-multiple-blank-outline",t.hidden)return(0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)``;let o=!1;return t.asset&&t.notMatchingFilter&&(o=!0),t.expanded&&0===t.children.length&&(console.debug("Tree node has no children, collapsing it..."),t.expanded=!1),(0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)`
|
|
85
|
+
`).setDismissAction(null))}_gatewayDescendantIsSelected(){return this._selectedNodes.some(t=>{var e;let n=null==t?void 0:t.parent;for(;n;){if((null==(e=n.asset)?void 0:e.type)==="GatewayAsset")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;let t=new Set,e=this._selectedNodes.filter(e=>{var n;return(null==(n=e.asset)?void 0:n.type)!=="GatewayAsset"||(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.type)&&(r=!1),i=i.parent;r&&t.add(e.asset)});let 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._onDeselectClicked(),204!==t.status&&(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gs)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}).catch(t=>{(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.gs)(_openremote_or_translate__WEBPACK_IMPORTED_MODULE_5__.i18next.t("deleteAssetsFailed"))}).finally(()=>{this.disabled=!1})};(0,_openremote_or_mwc_components_or_mwc_dialog__WEBPACK_IMPORTED_MODULE_11__.w)(_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;let e=this._selectedNodes?this._selectedNodes[0]:void 0;return!((null==(t=null==e?void 0:e.asset)?void 0:t.type)==="GatewayAsset"||this._gatewayDescendantIsSelected())&&this._getAllowedChildTypes(e).length>0}_getAllowedChildTypes(t){let e,n;if(this.config&&this.config.add){if(this.config.add.typesProvider){let 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])}_getOrderBy(t){switch(t){case"createdOn":return"CREATED_ON";case"type":return"ASSET_TYPE";default:return"NAME"}}_loadAssets(t){return __awaiter(this,arguments,void 0,function*(t,e=0,n){if(console.debug(`Loading assets with ${t?`parent ${t}`:"no parents"}...`),this.assets){console.debug("Assets already pre-loaded using HTML attributes; reusing them to construct the tree UI..."),this._loading=!1,this._buildTreeNodes(this.assets);return}if(!this._connected)throw Error("Not connected to the server; cannot load assets.");if(this._loading)throw Error("Already loading assets for asset tree; ignoring request.");if(this._loading=!0,this.dataProvider)this.dataProvider().then(t=>{var e;this._loading=!1,this._buildTreeNodes(t),(null==(e=this._filterInput)?void 0:e.value)&&this._doFiltering()});else{let i={realm:{name:_openremote_core__WEBPACK_IMPORTED_MODULE_7___default().displayRealm},parents:t?[{id:t}]:[],select:{attributes:[]},orderBy:{property:this._getOrderBy(this.sortBy)},offset:e,limit:Math.max(this.queryLimit,1)};this.assetIds?(i.ids=this.assetIds,i.recursive=!0):this.rootAssets?(i.ids=this.rootAssets.map(t=>t.id),i.recursive=!0):this.rootAssetIds&&(i.ids=this.rootAssetIds,i.recursive=!0);let r=this._sendEventWithReply({eventType:"read-asset-tree",assetQuery:i});return r.then(e=>{var i,r,o,a,l,c;let s=null!=(r=null==(i=e.assetTree)?void 0:i.assets)?r:[],d=null!=(a=null==(o=e.assetTree)?void 0:o.hasMore)&&a;if(t?t&&this._incompleteParentIds.includes(t)&&!d?this._incompleteParentIds=this._incompleteParentIds.filter(e=>e!==t):t&&d&&(this._incompleteParentIds=[...this._incompleteParentIds,t]):this._hasMoreParents=d,console.debug(`Received read-assets-tree event with ${s.length} assets.`),console.debug(`Combining these assets with the cache of ${null!=(l=null==n?void 0:n.length)?l:0} assets...`),this._loading=!1,n){let t=[...n,...s.filter(t=>!n.find(e=>e.id===t.id))];this._buildTreeNodes(t)}else this._buildTreeNodes(s);(null==(c=this._filterInput)?void 0:c.value)&&this._doFiltering()}),r}})}_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().catch(t=>console.log(t.message))}onEventsDisconnect(){this._connected=!1,this._nodes=void 0}getNodes(){return this._nodes||[]}_onEvent(t){var e;if("assets"===t.eventType){let e=t;this._buildTreeNodes(e.assets);return}if("asset"===t.eventType){let n=t;if("READ"===n.cause||"UPDATE"===n.cause&&!(n.updatedProperties.includes("name")||n.updatedProperties.includes("parentId")))return;let i=[];"DELETE"!==n.cause&&i.push(n.asset),this._nodes&&OrAssetTree_1._forEachNodeRecursive(this._nodes,t=>{t.asset.id!==n.asset.id&&i.push(t.asset)}),this._buildTreeNodes(i),(null==(e=this._filterInput)?void 0:e.value)&&this._doFiltering(),this.dispatchEvent(new OrAssetTreeAssetEvent(n))}}_buildTreeNodes(t,e=this._getSortFunction()){var n;if(console.debug(`Building asset tree nodes for ${t.length} assets...`),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++){let 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;let r=[];this._expandedNodes.forEach(t=>{OrAssetTree_1._forEachNodeRecursive(this._nodes,e=>{var n,i;if((null==(n=e.asset)?void 0:n.id)&&(null==(i=null==t?void 0:t.asset)?void 0:i.id)&&e.asset.id===t.asset.id&&this.isExpandable(t.asset.id)){e.expanded=!0,r.push(e);let t=e.parent;for(;t;)t.expanded=!0,t=t.parent,0>r.indexOf(t)&&r.push(t)}})}),this._expandedNodes=r}else this._nodes=[];console.debug(`Asset tree nodes built. Now selecting ${null==(n=this.selectedIds)?void 0:n.length} 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){var i,r;let o=this.assetsChildren[t.asset.id];t.children=o?o.sort(n):[],t.expandable=(null==(i=t.asset)?void 0:i.hasChildren)||(null==(r=t.children)?void 0:r.length),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){let e=t.x,n=t.y;if(null!==this.shadowRoot){let t=this.shadowRoot.getElementById("list");if(t){let 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?void 0:this._dragDropParentId,this.selectedIds))}isExpandable(t){return!!(this._nodes&&this.shadowRoot&&this.shadowRoot.querySelector('[node-asset-id="'+t+'"] > .node-name > [data-expandable]'))||!1}_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){let n=this._findNodeFromAssetId(t),i=null==(e=this.shadowRoot)?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){var n;let i,r=_openremote_model__WEBPACK_IMPORTED_MODULE_4__.AssetModelUtil.getAssetDescriptor(t.asset.type);if(i=t.allChildrenSelected?"checkbox-multiple-marked":t.someChildrenSelected?"checkbox-multiple-marked-outline":"checkbox-multiple-blank-outline",t.hidden)return(0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)``;let o=!1;return t.asset&&t.notMatchingFilter&&(o=!0),t.expanded&&0===t.children.length&&(console.debug("Tree node has no children, collapsing it..."),t.expanded=!1),(0,lit__WEBPACK_IMPORTED_MODULE_0__.dy)`
|
|
86
86
|
<li class="asset-list-element" ?data-selected="${t.selected}" ?data-expanded="${t.expanded}" @click="${e=>this._onNodeClicked(e,t)}">
|
|
87
87
|
<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>
|
|
88
88
|
<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">
|