@openremote/or-asset-tree 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/custom-elements.json +1 -1
- package/dist/umd/index.bundle.js +1191 -1191
- package/dist/umd/index.bundle.js.map +1 -1
- package/dist/umd/index.js +1191 -1191
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +1250 -1250
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/index.js +1704 -99
- package/lib/or-add-asset-dialog.js +318 -148
- package/lib/style.js +312 -306
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -1,100 +1,1705 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
`}_isReadonly(){return this.readonly||!manager.hasRole("write:assets")}shouldUpdate(e){let t=super.shouldUpdate(e);return((e.has("assets")||e.has("rootAssets")||e.has("rootAssetIds"))&&(this._nodes=void 0),this._nodes)?(e.has("selectedIds")&&!Util.objectsEqual(e.get("selectedIds"),this.selectedIds)&&this._updateSelectedNodes(),e.has("sortBy")&&this._updateSort(this._nodes,this._getSortFunction()),e.has("disabledSubscribe")&&this.disableSubscribe&&this._removeEventSubscriptions(),t):(this._loadAssets(),!0)}_updateSelectedNodes(){let e=[],t=[];OrAssetTree_1._forEachNodeRecursive(this._nodes,s=>{if(this.selectedIds&&this.selectedIds.indexOf(s.asset.id)>=0){e.push(s.asset.id),t.push(s),s.selected=!0;let i=s.parent;for(;i;)i.expanded=!0,i=i.parent}else s.selected=!1;if(this.checkboxes){let t=s.parent;for(;t;){let s=[];OrAssetTree_1._forEachNodeRecursive(t.children,e=>{s.push(e)}),t.someChildrenSelected=!1,t.allChildrenSelected=!1,s.every(t=>e.includes(t.asset.id))?t.allChildrenSelected=!0:s.some(t=>e.includes(t.asset.id))&&(t.someChildrenSelected=!0),t=t.parent}}}),this.selectedIds=e;let s=this._selectedNodes;this._selectedNodes=t,this.dispatchEvent(new OrAssetTreeSelectionEvent({oldNodes:s,newNodes:t}))}_updateSort(e,t){e&&(e.sort(t),e.forEach(e=>this._updateSort(e.children,t)))}_toggleExpander(e,t,s=!1){t&&t.expandable&&(t.expanded=!t.expanded,t.expanded?this._expandedNodes.push(t):this._expandedNodes=this._expandedNodes.filter(e=>e!==t),e.parentElement.parentElement.parentElement.toggleAttribute("data-expanded"),s||this.dispatchEvent(new OrAssetTreeToggleExpandEvent({node:t})),this.requestUpdate())}_buildPaths(e){let t=[];return e.asset&&e.asset.id?(t.push(e.asset.id),e.children.length>0&&e.expanded&&e.children.forEach(e=>{t=t.concat(this._buildPaths(e))}),t):[]}_findNode(e,t){if(e.asset&&e.asset.id){if(e.asset.id===t)return e;if(e.children.length>0&&e.expanded){let s;return e.children.forEach(e=>{s||(s=this._findNode(e,t))}),s}return}}_findNodeFromAssetId(e){if(this._nodes){let t;return this._nodes.forEach(s=>{t||(t=this._findNode(s,e))}),t}}_onNodeClicked(e,t){var s,i,r,a;if(e&&e.defaultPrevented)return;e&&e.preventDefault();let d=e&&e.target.className.indexOf("expander")>=0,n=e&&(null==(i=null==(s=e.target)?void 0:s.icon)?void 0:i.includes("checkbox-multiple"));if(d)this._toggleExpander(e.target,t);else{let s=!0;if(t&&this.config&&(null==(r=this.config.select)?void 0:r.types)&&(s=this.config.select.types.indexOf(t.asset.type)>=0),!s&&!n)return;let i=[];if(t){let s=this.selectedNodes.indexOf(t),r=!0,d=!0,o=!this._isReadonly()&&(!this.config||!this.config.select||!this.config.select.multiSelect);if((this.checkboxes||o&&e&&(e.ctrlKey||e.shiftKey||e.metaKey))&&(d=!1,s>=0&&this.selectedIds&&this.selectedIds.length>1&&(r=!1)),n){i=[...this.selectedNodes];let e=[];OrAssetTree_1._forEachNodeRecursive(t.children,t=>{var s,i;let r=!0;t&&(null==(i=null==(s=this.config)?void 0:s.select)?void 0:i.types)&&(r=this.config.select.types.indexOf(t.asset.type)>=0),r&&e.push(t)}),i=t.allChildrenSelected?i.filter(t=>!e.map(e=>e.asset.id).includes(t.asset.id)):i.concat(e)}else if(d)this._latestSelected=Object.assign({},t),i=[t];else if(r){if(s<0){if(e&&e.shiftKey){let e=[];if(null==(a=this._nodes)||a.forEach(t=>{e=e.concat(this._buildPaths(t))}),this._latestSelected&&this._latestSelected.asset&&this._latestSelected.asset.id&&t.asset&&t.asset.id){let s=this._latestSelected.asset.id,r=t.asset.id,a=e.findIndex(e=>e.includes(s)),d=e.findIndex(e=>e.includes(r)),n=-1,o=-1;a>d?(n=d,o=a):(n=a,o=d);let l=e.slice(n,o+1),h=[];l.forEach(e=>{let t=this._findNodeFromAssetId(e);t&&h.push(t)}),i=(i=[...this.selectedNodes]).concat(h)}}else(i=[...this.selectedNodes]).push(t);this._latestSelected=Object.assign({},t)}}else s>=0&&(1===(i=[...this.selectedNodes]).length&&(this._latestSelected=void 0),i.splice(s,1))}Util.dispatchCancellableEvent(this,new OrAssetTreeRequestSelectionEvent({oldNodes:this.selectedNodes,newNodes:i})).then(e=>{e.allow&&(this.selectedNodes=e.detail.newNodes)})}}_onDeselectClicked(){this._onNodeClicked(null,null)}parseFromInputFilter(e){let t=this._filterInput.value;e&&(t=e);let s=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:"),a=t.toString().substring(r+10+1,t.toString().length-1);s.attribute.push(a),s.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:"),a=t.toString().substring(r+5);s.assetType.push(a)}),(i=t.match(/(\"[^\"]+\")\:(([^\"\s]+)|(\"[^\"]+\"))/g))&&i.length>0&&i.forEach((t,i)=>{e=e.replace(t,"");let r=t.toString().indexOf('":'),a=t.toString().substring(r+2),d=t.toString().substring(1,r);'"'===a[0]&&'"'===a[a.length-1]&&(a=a.substring(1,a.length-1)),s.attribute.push(d),s.attributeValue.push(a)}),s.asset=e&&e.length>0?e.trim():void 0}return s}formatFilter(e){let t=e.asset?e.asset:"",s=e.asset?" ":"",i=[];return e.assetType.length>0&&e.assetType.forEach(e=>{t+=s+"type:"+e,s=" "}),e.attribute.length>0&&e.attributeValue.length>0&&e.attributeValue.forEach((r,a)=>{i.push(e.attribute[a]),t+=s+'"'+e.attribute[a]+'":'+r,s=" "}),e.attribute.length>0&&0===e.attributeValue.length&&e.attribute.forEach(e=>{i.includes(e)||(t+=s+'attribute:"'+e+'"',s=" ")}),t}_shouldEnableAttrTypeEvent(e){let t;e.composedPath()&&(t=e.composedPath()[0].value||void 0),this._shouldEnableAttrType(t)}_shouldEnableAttrType(e){e?this._attributeValueFilter.disabled=!1:this._attributeValueFilter.disabled=!0}applySettingFields(e){if(this._assetTypeFilter?e.assetType=[this._assetTypeFilter]:e.assetType=[],this._attributeNameFilter.value?e.attribute=[this._attributeNameFilter.value]:e.attribute=[],this._attributeNameFilter.value&&this._attributeValueFilter.value){let t=this._attributeValueFilter.value;t.includes(" ")&&(t='"'+t+'"'),e.attributeValue=[t]}else e.attributeValue=[];return e}_filterFromSettings(){let e=this.parseFromInputFilter(),t=this.applySettingFields(e);this._filter=t;let s=this.formatFilter(this._filter);this._filterInput.value=s,this._filterSettingOpen=!1,this._doFiltering()}_onFilterInputEvent(e){let t;e.composedPath()&&(t=e.composedPath()[0].value||void 0),this._onFilterInput(t,!1)}_onFilterInput(e,t){let s=this.parseFromInputFilter(e);Util.objectsEqual(this._filter,s,!0)||(this._filter=s,this._searchInputTimer&&clearTimeout(this._searchInputTimer),t?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,e=>{e.notMatchingFilter=!1,e.hidden=!1}),this.requestUpdate("_nodes");return}if(this.disabled=!0,this._filter.asset||this._filter.assetType||this._filter.attribute){let e=!1;this._filter.attribute&&(e=!0),this.getMatcher(e).then(e=>{this._nodes&&(this._nodes.forEach(t=>{this.filterTreeNode(t,e)}),this.disabled=!1)})}}})}getMatcher(e){return e?this.getMatcherFromQuery():this.getSimpleNameMatcher()}getSimpleNameMatcher(){return __awaiter(this,void 0,void 0,function*(){return e=>{let t=!0;return this._filter.asset&&(t=t&&e.name.toLowerCase().includes(this._filter.asset.toLowerCase())),this._filter.assetType.length>0&&(t=t&&e.type.toLowerCase()===this._filter.assetType[0].toLowerCase()),t}})}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(e=>({name:{predicateType:"string",match:"EXACT",value:Util.sentenceCaseToCamelCase(e),caseSensitive:!1}}))});let query={select:{attributes:attributeCond?void 0:[]},names:assetCond,types:assetTypeCond,attributes:attributeCond};try{foundAssetIds=(response=yield manager.rest.api.AssetResource.queryAssets(query)).data.map(e=>e.id)}catch(e){this._filter.assetType.forEach(e=>{-1===this._assetTypes.findIndex(t=>t.name===e)&&showSnackbar(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((e,t)=>{e.length>0&&attributeVal.push([this._filter.attribute[t],e])});let matchingAsset=response.data.find(e=>e.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(e,t,s=!1){let i=t(e.asset);e.notMatchingFilter=!i;let r=e.children.map(e=>this.filterTreeNode(e,t,i)).some(e=>e);return i=i||r,e.expanded=r&&e.children.length>0&&this.isAnyFilter(),e.hidden=!i&&!s,i}_onCopyClicked(){return __awaiter(this,void 0,void 0,function*(){if(1===this._selectedNodes.length)try{let e=yield manager.rest.api.AssetResource.get(this._selectedNodes[0].asset.id);if(!e.data)throw Error("API returned an invalid response when retrieving the source asset");let t=JSON.parse(JSON.stringify(e.data));t.name+=" copy",delete t.id,delete t.path,delete t.createdOn,delete t.version,Util.dispatchCancellableEvent(this,new OrAssetTreeRequestAddEvent({sourceAsset:this._selectedNodes[0].asset,asset:t})).then(e=>{e.allow&&this.dispatchEvent(new OrAssetTreeAddEvent(e.detail))})}catch(e){console.error("Failed to copy asset",e),showErrorDialog("Failed to copy asset")}})}_onAddClicked(){let e,t=this._getAllowedChildTypes(this._selectedNodes[0]),s=t.filter(e=>"agent"===e.descriptorType),i=t.filter(e=>"asset"===e.descriptorType),r=this._selectedNodes&&1===this._selectedNodes.length?this._selectedNodes[0].asset:void 0,a=t=>{let s=!!t.detail.name&&t.detail.name.trim().length>0&&t.detail.name.trim().length<1024;e.shadowRoot.getElementById("add-btn").disabled=!t.detail.descriptor||!s};e=showDialog(new OrMwcDialog().setHeading(i18next.t("addAsset")).setContent(html`
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var OrAssetTree_1;
|
|
17
|
+
import { html, LitElement } from "lit";
|
|
18
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
|
19
|
+
import "@openremote/or-mwc-components/or-mwc-input";
|
|
20
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
21
|
+
import "@openremote/or-icon";
|
|
22
|
+
import { AssetModelUtil } from "@openremote/model";
|
|
23
|
+
import "@openremote/or-translate";
|
|
24
|
+
import { style } from "./style";
|
|
25
|
+
import manager, { subscribe, Util } from "@openremote/core";
|
|
26
|
+
import Qs from "qs";
|
|
27
|
+
import { getAssetDescriptorIconTemplate } from "@openremote/or-icon";
|
|
28
|
+
import "@openremote/or-mwc-components/or-mwc-menu";
|
|
29
|
+
import { getContentWithMenuTemplate } from "@openremote/or-mwc-components/or-mwc-menu";
|
|
30
|
+
import "@openremote/or-mwc-components/or-mwc-list";
|
|
31
|
+
import { i18next } from "@openremote/or-translate";
|
|
32
|
+
import "@openremote/or-mwc-components/or-mwc-dialog";
|
|
33
|
+
import { OrMwcDialog, showDialog, showErrorDialog, showOkCancelDialog } from "@openremote/or-mwc-components/or-mwc-dialog";
|
|
34
|
+
import "./or-add-asset-dialog";
|
|
35
|
+
import { showSnackbar } from "@openremote/or-mwc-components/or-mwc-snackbar";
|
|
36
|
+
import { when } from "lit/directives/when.js";
|
|
37
|
+
export { style };
|
|
38
|
+
export class OrAssetTreeRequestSelectionEvent extends CustomEvent {
|
|
39
|
+
constructor(request) {
|
|
40
|
+
super(OrAssetTreeRequestSelectionEvent.NAME, {
|
|
41
|
+
bubbles: true,
|
|
42
|
+
composed: true,
|
|
43
|
+
detail: {
|
|
44
|
+
allow: true,
|
|
45
|
+
detail: request
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
OrAssetTreeRequestSelectionEvent.NAME = "or-asset-tree-request-selection";
|
|
51
|
+
export class OrAssetTreeSelectionEvent extends CustomEvent {
|
|
52
|
+
constructor(detail) {
|
|
53
|
+
super(OrAssetTreeSelectionEvent.NAME, {
|
|
54
|
+
bubbles: true,
|
|
55
|
+
composed: true,
|
|
56
|
+
detail: detail
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
OrAssetTreeSelectionEvent.NAME = "or-asset-tree-selection";
|
|
61
|
+
export class OrAssetTreeChangeParentEvent extends CustomEvent {
|
|
62
|
+
constructor(parent, assetsIds) {
|
|
63
|
+
super(OrAssetTreeChangeParentEvent.NAME, {
|
|
64
|
+
bubbles: true,
|
|
65
|
+
composed: true,
|
|
66
|
+
detail: {
|
|
67
|
+
parentId: parent,
|
|
68
|
+
assetIds: assetsIds
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
OrAssetTreeChangeParentEvent.NAME = "or-asset-tree-change-parent";
|
|
74
|
+
export class OrAssetTreeToggleExpandEvent extends CustomEvent {
|
|
75
|
+
constructor(detail) {
|
|
76
|
+
super(OrAssetTreeToggleExpandEvent.NAME, {
|
|
77
|
+
bubbles: true,
|
|
78
|
+
composed: true,
|
|
79
|
+
detail: detail
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
OrAssetTreeToggleExpandEvent.NAME = "or-asset-tree-expand";
|
|
84
|
+
var FilterElementType;
|
|
85
|
+
(function (FilterElementType) {
|
|
86
|
+
FilterElementType[FilterElementType["SEARCH_FILTER"] = 0] = "SEARCH_FILTER";
|
|
87
|
+
FilterElementType[FilterElementType["ASSET_TYPE"] = 1] = "ASSET_TYPE";
|
|
88
|
+
FilterElementType[FilterElementType["ATTRIBUTE_NAME"] = 2] = "ATTRIBUTE_NAME";
|
|
89
|
+
FilterElementType[FilterElementType["ATTRIBUTE_VALUE"] = 3] = "ATTRIBUTE_VALUE";
|
|
90
|
+
})(FilterElementType || (FilterElementType = {}));
|
|
91
|
+
export class OrAssetTreeRequestAddEvent extends CustomEvent {
|
|
92
|
+
constructor(detail) {
|
|
93
|
+
super(OrAssetTreeRequestAddEvent.NAME, {
|
|
94
|
+
bubbles: true,
|
|
95
|
+
composed: true,
|
|
96
|
+
detail: {
|
|
97
|
+
allow: true,
|
|
98
|
+
detail: detail
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
OrAssetTreeRequestAddEvent.NAME = "or-asset-tree-request-add";
|
|
104
|
+
export class OrAssetTreeAddEvent extends CustomEvent {
|
|
105
|
+
constructor(detail) {
|
|
106
|
+
super(OrAssetTreeAddEvent.NAME, {
|
|
107
|
+
bubbles: true,
|
|
108
|
+
composed: true,
|
|
109
|
+
detail: detail
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
OrAssetTreeAddEvent.NAME = "or-asset-tree-add";
|
|
114
|
+
export class OrAssetTreeRequestDeleteEvent extends CustomEvent {
|
|
115
|
+
constructor(request) {
|
|
116
|
+
super(OrAssetTreeRequestDeleteEvent.NAME, {
|
|
117
|
+
bubbles: true,
|
|
118
|
+
composed: true,
|
|
119
|
+
detail: {
|
|
120
|
+
allow: true,
|
|
121
|
+
detail: request
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
OrAssetTreeRequestDeleteEvent.NAME = "or-asset-tree-request-delete";
|
|
127
|
+
export class OrAssetTreeAssetEvent extends CustomEvent {
|
|
128
|
+
constructor(assetEvent) {
|
|
129
|
+
super(OrAssetTreeAssetEvent.NAME, {
|
|
130
|
+
bubbles: true,
|
|
131
|
+
composed: true,
|
|
132
|
+
detail: assetEvent
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
OrAssetTreeAssetEvent.NAME = "or-asset-tree-asset-event";
|
|
137
|
+
export class OrAssetTreeFilter {
|
|
138
|
+
constructor() {
|
|
139
|
+
this.asset = undefined;
|
|
140
|
+
this.assetType = [];
|
|
141
|
+
this.attribute = [];
|
|
142
|
+
this.attributeValue = [];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export const getAssetTypes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
const response = yield manager.rest.api.AssetResource.queryAssets({
|
|
147
|
+
select: {
|
|
148
|
+
attributes: []
|
|
149
|
+
},
|
|
150
|
+
recursive: true
|
|
151
|
+
});
|
|
152
|
+
if (response && response.data) {
|
|
153
|
+
return response.data.map(asset => asset.type);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
let OrAssetTree = OrAssetTree_1 = class OrAssetTree extends subscribe(manager)(LitElement) {
|
|
157
|
+
constructor() {
|
|
158
|
+
super(...arguments);
|
|
159
|
+
this.readonly = false;
|
|
160
|
+
this.disabled = false;
|
|
161
|
+
this.disableSubscribe = false;
|
|
162
|
+
this.showDeselectBtn = true;
|
|
163
|
+
this.showSortBtn = true;
|
|
164
|
+
this.showFilter = true;
|
|
165
|
+
this.sortBy = "name";
|
|
166
|
+
this.expandAllNodes = false;
|
|
167
|
+
this.expandedIds = [];
|
|
168
|
+
this.checkboxes = false;
|
|
169
|
+
this._loading = false;
|
|
170
|
+
this._connected = false;
|
|
171
|
+
this._selectedNodes = [];
|
|
172
|
+
this._expandedNodes = [];
|
|
173
|
+
this._filter = new OrAssetTreeFilter();
|
|
174
|
+
this._searchInputTimer = undefined;
|
|
175
|
+
this._filterSettingOpen = false;
|
|
176
|
+
this._assetTypes = [];
|
|
177
|
+
this._uniqueAssetTypes = [];
|
|
178
|
+
this._dragDropParentId = null;
|
|
179
|
+
this._expandTimer = undefined;
|
|
180
|
+
this._latestSelected = undefined;
|
|
181
|
+
this.assetsChildren = {};
|
|
182
|
+
}
|
|
183
|
+
static get styles() {
|
|
184
|
+
return [
|
|
185
|
+
style
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
get selectedNodes() {
|
|
189
|
+
return this._selectedNodes ? [...this._selectedNodes] : [];
|
|
190
|
+
}
|
|
191
|
+
set selectedNodes(nodes) {
|
|
192
|
+
this.selectedIds = nodes.map((node) => node.asset.id);
|
|
193
|
+
}
|
|
194
|
+
connectedCallback() {
|
|
195
|
+
super.connectedCallback();
|
|
196
|
+
}
|
|
197
|
+
disconnectedCallback() {
|
|
198
|
+
super.disconnectedCallback();
|
|
199
|
+
this.requestUpdate();
|
|
200
|
+
}
|
|
201
|
+
refresh() {
|
|
202
|
+
// Clear nodes to re-fetch them
|
|
203
|
+
this._nodes = undefined;
|
|
204
|
+
}
|
|
205
|
+
isAncestorSelected(node) {
|
|
206
|
+
if (!this.selectedIds || !node.parent) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
while (node.parent) {
|
|
210
|
+
node = node.parent;
|
|
211
|
+
if (this.selectedIds.includes(node.asset.id)) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
mapDescriptors(descriptors, withNoneValue) {
|
|
218
|
+
let items = descriptors.map((descriptor) => {
|
|
219
|
+
return {
|
|
220
|
+
styleMap: {
|
|
221
|
+
"--or-icon-fill": descriptor.colour ? "#" + descriptor.colour : "unset"
|
|
222
|
+
},
|
|
223
|
+
icon: descriptor.icon,
|
|
224
|
+
text: Util.getAssetTypeLabel(descriptor),
|
|
225
|
+
value: descriptor.name,
|
|
226
|
+
data: descriptor
|
|
227
|
+
};
|
|
228
|
+
}).sort(Util.sortByString((listItem) => listItem.text));
|
|
229
|
+
if (withNoneValue) {
|
|
230
|
+
items.splice(0, 0, withNoneValue);
|
|
231
|
+
}
|
|
232
|
+
return items;
|
|
233
|
+
}
|
|
234
|
+
getSelectHeader() {
|
|
235
|
+
return html `<or-mwc-input style="width:100%;" ?disabled="${this._loading}" type="${InputType.TEXT}" .label="${i18next.t("filter.assetTypeLabel")}" iconTrailing="menu-down" iconColor="rgba(0, 0, 0, 0.87)" icon="selection-ellipse" value="${i18next.t("filter.assetTypeNone")}"></or-mwc-input>`;
|
|
236
|
+
}
|
|
237
|
+
getSelectedHeader(descriptor) {
|
|
238
|
+
return html `<or-mwc-input style="width:100%;" ?disabled="${this._loading}" type="${InputType.TEXT}" .label="${i18next.t("filter.assetTypeLabel")}" .iconColor="${descriptor.colour}" iconTrailing="menu-down" icon="${descriptor.icon}" value="${Util.getAssetTypeLabel(descriptor)}"></or-mwc-input>`;
|
|
239
|
+
}
|
|
240
|
+
assetTypeSelect() {
|
|
241
|
+
if (this._assetTypeFilter) {
|
|
242
|
+
const descriptor = this._assetTypes.find((at) => { return at.name === this._assetTypeFilter; });
|
|
243
|
+
if (descriptor) {
|
|
244
|
+
return this.getSelectedHeader(descriptor);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
return this.getSelectHeader();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
return this.getSelectHeader();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
atLeastOneNodeToBeShown() {
|
|
255
|
+
var _a;
|
|
256
|
+
let atLeastOne = false;
|
|
257
|
+
(_a = this._nodes) === null || _a === void 0 ? void 0 : _a.forEach((value) => {
|
|
258
|
+
if (!value.hidden) {
|
|
259
|
+
atLeastOne = true;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
return atLeastOne;
|
|
263
|
+
}
|
|
264
|
+
render() {
|
|
265
|
+
const canAdd = this._canAdd();
|
|
266
|
+
return html `
|
|
267
|
+
<div id="header">
|
|
268
|
+
<div id="title-container">
|
|
269
|
+
<or-translate id="title" value="asset_plural"></or-translate>
|
|
270
|
+
</div>
|
|
271
|
+
|
|
272
|
+
<div id="header-btns">
|
|
273
|
+
<or-mwc-input ?hidden="${!this.selectedIds || this.selectedIds.length === 0 || !this.showDeselectBtn}" type="${InputType.BUTTON}" icon="close" title="${i18next.t("deselect")}" @or-mwc-input-changed="${() => this._onDeselectClicked()}"></or-mwc-input>
|
|
274
|
+
<or-mwc-input ?hidden="${this._isReadonly() || !this.selectedIds || this.selectedIds.length !== 1 || !canAdd}" type="${InputType.BUTTON}" icon="content-copy" title="${i18next.t("duplicate")}" @or-mwc-input-changed="${() => this._onCopyClicked()}"></or-mwc-input>
|
|
275
|
+
<or-mwc-input ?hidden="${this._isReadonly() || !this.selectedIds || this.selectedIds.length === 0 || this._gatewayDescendantIsSelected()}" type="${InputType.BUTTON}" icon="delete" title="${i18next.t("delete")}" @or-mwc-input-changed="${() => this._onDeleteClicked()}"></or-mwc-input>
|
|
276
|
+
<or-mwc-input ?hidden="${this._isReadonly() || !canAdd}" type="${InputType.BUTTON}" icon="plus" title="${i18next.t("addAsset")}" @or-mwc-input-changed="${() => this._onAddClicked()}"></or-mwc-input>
|
|
277
|
+
|
|
278
|
+
${getContentWithMenuTemplate(html `<or-mwc-input type="${InputType.BUTTON}" ?hidden="${!this.showSortBtn}" icon="sort-variant" title="${i18next.t("sort")}" ></or-mwc-input>`, ["name", "type", "createdOn"].map((sort) => { return { value: sort, text: i18next.t(sort) }; }), this.sortBy, (v) => this._onSortClicked(v))}
|
|
279
|
+
</div>
|
|
280
|
+
</div>
|
|
281
|
+
|
|
282
|
+
${when(this.showFilter, () => html `
|
|
283
|
+
<div id="asset-tree-filter">
|
|
284
|
+
<or-mwc-input id="filterInput"
|
|
285
|
+
?disabled="${this._loading}"
|
|
286
|
+
style="width: 100%;"
|
|
287
|
+
type="${InputType.TEXT}"
|
|
288
|
+
placeholder="${i18next.t("filter.filter")}..."
|
|
289
|
+
compact="true"
|
|
290
|
+
outlined="true"
|
|
291
|
+
@input="${(e) => {
|
|
292
|
+
// Means some input is occurring so delay filter
|
|
293
|
+
this._onFilterInputEvent(e);
|
|
294
|
+
}}"
|
|
295
|
+
@or-mwc-input-changed="${(e) => {
|
|
296
|
+
// Means field has lost focus so do filter immediately
|
|
297
|
+
this._onFilterInput(e.detail.value || undefined, true);
|
|
298
|
+
}}">
|
|
299
|
+
</or-mwc-input>
|
|
300
|
+
<or-icon id="filterSettingsIcon" icon="${this._filterSettingOpen ? "window-close" : "tune"}" title="${i18next.t(this._filterSettingOpen ? "filter.close" : "filter.open")}" @click="${() => {
|
|
301
|
+
if (this._filterSettingOpen) {
|
|
302
|
+
this._filterSettingOpen = false;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
this._filterSettingOpen = true;
|
|
306
|
+
// Avoid to build again the types
|
|
307
|
+
if (this._assetTypes.length === 0) {
|
|
308
|
+
let usedTypes = [];
|
|
309
|
+
const types = this._getAllowedChildTypes(this._selectedNodes[0]);
|
|
310
|
+
this._assetTypes = types.filter((t) => t.descriptorType === "asset");
|
|
311
|
+
}
|
|
312
|
+
if (this._filter.attribute.length > 0) {
|
|
313
|
+
this._attributeNameFilter.value = this._filter.attribute[0];
|
|
314
|
+
}
|
|
315
|
+
if (this._filter.attributeValue.length > 0 && this._filter.attribute.length > 0) {
|
|
316
|
+
this._attributeValueFilter.disabled = false;
|
|
317
|
+
this._attributeValueFilter.value = this._filter.attributeValue[0];
|
|
318
|
+
}
|
|
319
|
+
if (this._filter.assetType.length > 0) {
|
|
320
|
+
this._assetTypeFilter = this._filter.assetType[0];
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
this._assetTypeFilter = '';
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}}"></or-icon>
|
|
327
|
+
</div>
|
|
328
|
+
<div id="asset-tree-filter-setting" class="${this._filterSettingOpen ? "visible" : ""}">
|
|
329
|
+
<div class="advanced-filter">
|
|
330
|
+
${this._assetTypes.length > 0 ? getContentWithMenuTemplate(this.assetTypeSelect(), this.mapDescriptors(this._assetTypes, { text: i18next.t("filter.assetTypeMenuNone"), value: "", icon: "selection-ellipse" }), undefined, (v) => {
|
|
331
|
+
this._assetTypeFilter = v;
|
|
332
|
+
}, undefined, false, true, true) : html ``}
|
|
333
|
+
<or-mwc-input id="attributeNameFilter" .label="${i18next.t("filter.attributeLabel")}"
|
|
334
|
+
|
|
335
|
+
.type="${InputType.TEXT}"
|
|
336
|
+
style="margin-top: 10px;"
|
|
337
|
+
?disabled="${this._loading}"
|
|
338
|
+
@input="${(e) => {
|
|
339
|
+
this._shouldEnableAttrTypeEvent(e);
|
|
340
|
+
}}"
|
|
341
|
+
@or-mwc-input-changed="${(e) => {
|
|
342
|
+
this._shouldEnableAttrType(e.detail.value || undefined);
|
|
343
|
+
}}"></or-mwc-input>
|
|
344
|
+
<or-mwc-input id="attributeValueFilter" .label="${i18next.t("filter.attributeValueLabel")}"
|
|
345
|
+
|
|
346
|
+
.type="${InputType.TEXT}"
|
|
347
|
+
style="margin-top: 10px;"
|
|
348
|
+
disabled></or-mwc-input>
|
|
349
|
+
<div style="margin-top: 10px;">
|
|
350
|
+
<or-mwc-input style="float:left;" type="${InputType.BUTTON}" label="filter.clear" @or-mwc-input-changed="${() => {
|
|
351
|
+
// Wipe the current value and hide the clear button
|
|
352
|
+
this._filterInput.value = undefined;
|
|
353
|
+
this._attributeValueFilter.value = undefined;
|
|
354
|
+
this._attributeNameFilter.value = undefined;
|
|
355
|
+
this._attributeValueFilter.disabled = true;
|
|
356
|
+
this._assetTypeFilter = '';
|
|
357
|
+
this._filter = new OrAssetTreeFilter();
|
|
358
|
+
// Call filtering
|
|
359
|
+
this._doFiltering();
|
|
360
|
+
}}"></or-mwc-input>
|
|
361
|
+
<or-mwc-input style="float: right;" type="${InputType.BUTTON}" label="filter.action" raised @or-mwc-input-changed="${() => {
|
|
362
|
+
this._filterFromSettings();
|
|
363
|
+
}}"></or-mwc-input>
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
`)}
|
|
368
|
+
|
|
369
|
+
${!this._nodes
|
|
370
|
+
? html `
|
|
371
|
+
<span id="loading"><or-translate value="loading"></or-translate></span>`
|
|
372
|
+
: ((this._nodes.length === 0 || !this.atLeastOneNodeToBeShown())
|
|
373
|
+
? html `<span id="noAssetsFound"><or-translate value="noAssetsFound"></or-translate></span>`
|
|
374
|
+
: html `
|
|
375
|
+
<div id="list-container">
|
|
376
|
+
<ol id="list">
|
|
377
|
+
${this._nodes.map((treeNode) => this._treeNodeTemplate(treeNode, 0)).filter(t => !!t)}
|
|
378
|
+
<li class="asset-list-element">
|
|
379
|
+
<div class="end-element" node-asset-id="${''}" @dragleave=${(ev) => { this._onDragLeave(ev); }} @dragenter="${(ev) => this._onDragEnter(ev)}" @dragend="${(ev) => this._onDragEnd(ev)}" @dragover="${(ev) => this._onDragOver(ev)}"></div>
|
|
380
|
+
</li>
|
|
381
|
+
</ol>
|
|
382
|
+
</div>
|
|
383
|
+
`)}
|
|
384
|
+
|
|
385
|
+
<div id="footer">
|
|
386
|
+
|
|
387
|
+
</div>
|
|
388
|
+
`;
|
|
389
|
+
}
|
|
390
|
+
_isReadonly() {
|
|
391
|
+
return this.readonly || !manager.hasRole("write:assets" /* ClientRole.WRITE_ASSETS */);
|
|
392
|
+
}
|
|
393
|
+
shouldUpdate(_changedProperties) {
|
|
394
|
+
const result = super.shouldUpdate(_changedProperties);
|
|
395
|
+
if (_changedProperties.has("assets")
|
|
396
|
+
|| _changedProperties.has("rootAssets")
|
|
397
|
+
|| _changedProperties.has("rootAssetIds")) {
|
|
398
|
+
this._nodes = undefined;
|
|
399
|
+
}
|
|
400
|
+
if (!this._nodes) {
|
|
401
|
+
this._loadAssets();
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
if (_changedProperties.has("selectedIds")) {
|
|
405
|
+
if (!Util.objectsEqual(_changedProperties.get("selectedIds"), this.selectedIds)) {
|
|
406
|
+
this._updateSelectedNodes();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (_changedProperties.has("sortBy")) {
|
|
410
|
+
this._updateSort(this._nodes, this._getSortFunction());
|
|
411
|
+
}
|
|
412
|
+
if (_changedProperties.has("disabledSubscribe")) {
|
|
413
|
+
if (this.disableSubscribe) {
|
|
414
|
+
this._removeEventSubscriptions();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
418
|
+
}
|
|
419
|
+
_updateSelectedNodes() {
|
|
420
|
+
const actuallySelectedIds = [];
|
|
421
|
+
const selectedNodes = [];
|
|
422
|
+
OrAssetTree_1._forEachNodeRecursive(this._nodes, (node) => {
|
|
423
|
+
if (this.selectedIds && this.selectedIds.indexOf(node.asset.id) >= 0) {
|
|
424
|
+
actuallySelectedIds.push(node.asset.id);
|
|
425
|
+
selectedNodes.push(node);
|
|
426
|
+
node.selected = true;
|
|
427
|
+
// Expand every ancestor
|
|
428
|
+
let parent = node.parent;
|
|
429
|
+
while (parent) {
|
|
430
|
+
parent.expanded = true;
|
|
431
|
+
parent = parent.parent;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
node.selected = false;
|
|
436
|
+
}
|
|
437
|
+
if (this.checkboxes) {
|
|
438
|
+
let parent = node.parent;
|
|
439
|
+
while (parent) {
|
|
440
|
+
const allChildren = [];
|
|
441
|
+
OrAssetTree_1._forEachNodeRecursive(parent.children, (child) => {
|
|
442
|
+
allChildren.push(child);
|
|
443
|
+
});
|
|
444
|
+
parent.someChildrenSelected = false;
|
|
445
|
+
parent.allChildrenSelected = false;
|
|
446
|
+
if (allChildren.every(c => actuallySelectedIds.includes(c.asset.id))) {
|
|
447
|
+
parent.allChildrenSelected = true;
|
|
448
|
+
}
|
|
449
|
+
else if (allChildren.some(c => actuallySelectedIds.includes(c.asset.id))) {
|
|
450
|
+
parent.someChildrenSelected = true;
|
|
451
|
+
}
|
|
452
|
+
parent = parent.parent;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
this.selectedIds = actuallySelectedIds;
|
|
457
|
+
const oldSelection = this._selectedNodes;
|
|
458
|
+
this._selectedNodes = selectedNodes;
|
|
459
|
+
this.dispatchEvent(new OrAssetTreeSelectionEvent({
|
|
460
|
+
oldNodes: oldSelection,
|
|
461
|
+
newNodes: selectedNodes
|
|
462
|
+
}));
|
|
463
|
+
}
|
|
464
|
+
_updateSort(nodes, sortFunction) {
|
|
465
|
+
if (!nodes) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
nodes.sort(sortFunction);
|
|
469
|
+
nodes.forEach((node) => this._updateSort(node.children, sortFunction));
|
|
470
|
+
}
|
|
471
|
+
_toggleExpander(expander, node, silent = false) {
|
|
472
|
+
if (node && node.expandable) {
|
|
473
|
+
node.expanded = !node.expanded;
|
|
474
|
+
if (node.expanded) {
|
|
475
|
+
this._expandedNodes.push(node);
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
this._expandedNodes = this._expandedNodes.filter(n => n !== node);
|
|
479
|
+
}
|
|
480
|
+
const elem = expander.parentElement.parentElement.parentElement;
|
|
481
|
+
elem.toggleAttribute("data-expanded");
|
|
482
|
+
if (!silent) {
|
|
483
|
+
this.dispatchEvent(new OrAssetTreeToggleExpandEvent({ node: node }));
|
|
484
|
+
}
|
|
485
|
+
this.requestUpdate();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
_buildPaths(node) {
|
|
489
|
+
let paths = [];
|
|
490
|
+
if (node.asset) {
|
|
491
|
+
if (node.asset.id) {
|
|
492
|
+
paths.push(node.asset.id);
|
|
493
|
+
if (node.children.length > 0 && node.expanded) {
|
|
494
|
+
node.children.forEach((child) => {
|
|
495
|
+
paths = paths.concat(this._buildPaths(child));
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
return paths;
|
|
499
|
+
}
|
|
500
|
+
return [];
|
|
501
|
+
}
|
|
502
|
+
return [];
|
|
503
|
+
}
|
|
504
|
+
_findNode(n, assetId) {
|
|
505
|
+
if (n.asset && n.asset.id) {
|
|
506
|
+
if (n.asset.id === assetId) {
|
|
507
|
+
return n;
|
|
508
|
+
}
|
|
509
|
+
else if (n.children.length > 0 && n.expanded) {
|
|
510
|
+
let foundNode = undefined;
|
|
511
|
+
n.children.forEach((n) => {
|
|
512
|
+
if (!foundNode) {
|
|
513
|
+
foundNode = this._findNode(n, assetId);
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
return foundNode;
|
|
517
|
+
}
|
|
518
|
+
return undefined;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
_findNodeFromAssetId(assetId) {
|
|
522
|
+
if (this._nodes) {
|
|
523
|
+
let foundNode = undefined;
|
|
524
|
+
this._nodes.forEach((n) => {
|
|
525
|
+
if (!foundNode) {
|
|
526
|
+
foundNode = this._findNode(n, assetId);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
return foundNode;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
return undefined;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
_onNodeClicked(evt, node) {
|
|
536
|
+
var _a, _b, _c, _d;
|
|
537
|
+
if (evt && evt.defaultPrevented) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
if (evt) {
|
|
541
|
+
evt.preventDefault();
|
|
542
|
+
}
|
|
543
|
+
const isExpander = evt && evt.target.className.indexOf("expander") >= 0;
|
|
544
|
+
const isParentCheckbox = evt && ((_b = (_a = evt.target) === null || _a === void 0 ? void 0 : _a.icon) === null || _b === void 0 ? void 0 : _b.includes("checkbox-multiple"));
|
|
545
|
+
if (isExpander) {
|
|
546
|
+
this._toggleExpander(evt.target, node);
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
let canSelect = true;
|
|
550
|
+
if (node && this.config && ((_c = this.config.select) === null || _c === void 0 ? void 0 : _c.types)) {
|
|
551
|
+
canSelect = this.config.select.types.indexOf(node.asset.type) >= 0;
|
|
552
|
+
}
|
|
553
|
+
// If node cannot be selected, and it is not the 'select all of this parent'-checkbox, cancel it.
|
|
554
|
+
if (!canSelect && !isParentCheckbox) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
let selectedNodes = [];
|
|
558
|
+
if (node) {
|
|
559
|
+
const index = this.selectedNodes.indexOf(node);
|
|
560
|
+
let select = true;
|
|
561
|
+
let deselectOthers = true;
|
|
562
|
+
const multiSelect = !this._isReadonly() && (!this.config || !this.config.select || !this.config.select.multiSelect);
|
|
563
|
+
// determine if node was already selected
|
|
564
|
+
if (this.checkboxes || (multiSelect && evt && (evt.ctrlKey || evt.shiftKey || evt.metaKey))) {
|
|
565
|
+
deselectOthers = false;
|
|
566
|
+
if (index >= 0 && this.selectedIds && this.selectedIds.length > 1) {
|
|
567
|
+
select = false;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
// handle selected state
|
|
571
|
+
if (isParentCheckbox) {
|
|
572
|
+
selectedNodes = [...this.selectedNodes];
|
|
573
|
+
const childNodes = [];
|
|
574
|
+
OrAssetTree_1._forEachNodeRecursive(node.children, (childNode) => {
|
|
575
|
+
var _a, _b;
|
|
576
|
+
let canSelectChild = true;
|
|
577
|
+
// If not of required asset type, cancel selection of the child
|
|
578
|
+
if (childNode && ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.select) === null || _b === void 0 ? void 0 : _b.types)) {
|
|
579
|
+
canSelectChild = this.config.select.types.indexOf(childNode.asset.type) >= 0;
|
|
75
580
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
581
|
+
if (canSelectChild) {
|
|
582
|
+
childNodes.push(childNode);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
// based on multiple-box already selected, remove or add to array of selected nodes
|
|
586
|
+
selectedNodes = (!node.allChildrenSelected)
|
|
587
|
+
? selectedNodes.concat(childNodes)
|
|
588
|
+
: selectedNodes.filter(n => !childNodes.map(cn => cn.asset.id).includes(n.asset.id));
|
|
589
|
+
}
|
|
590
|
+
else if (deselectOthers) {
|
|
591
|
+
this._latestSelected = Object.assign({}, node);
|
|
592
|
+
selectedNodes = [node];
|
|
593
|
+
}
|
|
594
|
+
else if (select) {
|
|
595
|
+
if (index < 0) {
|
|
596
|
+
if (evt && evt.shiftKey) {
|
|
597
|
+
let hierarchy = [];
|
|
598
|
+
(_d = this._nodes) === null || _d === void 0 ? void 0 : _d.forEach((n) => {
|
|
599
|
+
hierarchy = hierarchy.concat(this._buildPaths(n));
|
|
600
|
+
});
|
|
601
|
+
if (this._latestSelected && this._latestSelected.asset && this._latestSelected.asset.id && node.asset && node.asset.id) {
|
|
602
|
+
let latestSelectedAssetId = this._latestSelected.asset.id;
|
|
603
|
+
let newlySelectedAssetId = node.asset.id;
|
|
604
|
+
let previousIndex = hierarchy.findIndex((val) => { return val.includes(latestSelectedAssetId); });
|
|
605
|
+
let newIndex = hierarchy.findIndex((val) => { return val.includes(newlySelectedAssetId); });
|
|
606
|
+
let startIndex = -1;
|
|
607
|
+
let endIndex = -1;
|
|
608
|
+
if (previousIndex > newIndex) {
|
|
609
|
+
startIndex = newIndex;
|
|
610
|
+
endIndex = previousIndex;
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
startIndex = previousIndex;
|
|
614
|
+
endIndex = newIndex;
|
|
615
|
+
}
|
|
616
|
+
let assetIdsToSelect = hierarchy.slice(startIndex, endIndex + 1);
|
|
617
|
+
let foundNodes = [];
|
|
618
|
+
assetIdsToSelect.forEach((assetIdToSelect) => {
|
|
619
|
+
let foundNode = this._findNodeFromAssetId(assetIdToSelect);
|
|
620
|
+
if (foundNode) {
|
|
621
|
+
foundNodes.push(foundNode);
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
selectedNodes = [...this.selectedNodes];
|
|
625
|
+
selectedNodes = selectedNodes.concat(foundNodes);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
selectedNodes = [...this.selectedNodes];
|
|
630
|
+
selectedNodes.push(node);
|
|
631
|
+
}
|
|
632
|
+
this._latestSelected = Object.assign({}, node);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
else if (index >= 0) {
|
|
636
|
+
selectedNodes = [...this.selectedNodes];
|
|
637
|
+
if (selectedNodes.length === 1) {
|
|
638
|
+
this._latestSelected = undefined;
|
|
639
|
+
}
|
|
640
|
+
selectedNodes.splice(index, 1);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
Util.dispatchCancellableEvent(this, new OrAssetTreeRequestSelectionEvent({
|
|
644
|
+
oldNodes: this.selectedNodes,
|
|
645
|
+
newNodes: selectedNodes
|
|
646
|
+
})).then((detail) => {
|
|
647
|
+
if (detail.allow) {
|
|
648
|
+
this.selectedNodes = detail.detail.newNodes;
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
_onDeselectClicked() {
|
|
654
|
+
this._onNodeClicked(null, null);
|
|
655
|
+
}
|
|
656
|
+
parseFromInputFilter(inputValue) {
|
|
657
|
+
let searchValue = this._filterInput.value;
|
|
658
|
+
if (inputValue) {
|
|
659
|
+
searchValue = inputValue;
|
|
660
|
+
}
|
|
661
|
+
let resultingFilter = new OrAssetTreeFilter();
|
|
662
|
+
if (searchValue) {
|
|
663
|
+
let asset = searchValue;
|
|
664
|
+
let matchingResult = searchValue.match(/(attribute\:)(\"[^"]+\")\S*/g);
|
|
665
|
+
if (matchingResult) {
|
|
666
|
+
if (matchingResult.length > 0) {
|
|
667
|
+
matchingResult.forEach((value, index) => {
|
|
668
|
+
asset = asset.replace(value, '');
|
|
669
|
+
const startIndex = value.toString().indexOf('attribute:');
|
|
670
|
+
const matchingVal = value.toString().substring(startIndex + 'attribute:'.length + 1, value.toString().length - 1);
|
|
671
|
+
resultingFilter.attribute.push(matchingVal);
|
|
672
|
+
resultingFilter.attributeValue.push('');
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
this._attributeValueFilter.disabled = false;
|
|
676
|
+
}
|
|
677
|
+
matchingResult = searchValue.match(/(type\:)\S+/g);
|
|
678
|
+
if (matchingResult) {
|
|
679
|
+
if (matchingResult.length > 0) {
|
|
680
|
+
matchingResult.forEach((value, index) => {
|
|
681
|
+
asset = asset.replace(value, '');
|
|
682
|
+
const startIndex = value.toString().indexOf('type:');
|
|
683
|
+
const matchingVal = value.toString().substring(startIndex + 'type:'.length);
|
|
684
|
+
resultingFilter.assetType.push(matchingVal);
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
matchingResult = searchValue.match(/(\"[^\"]+\")\:(([^\"\s]+)|(\"[^\"]+\"))/g);
|
|
689
|
+
if (matchingResult) {
|
|
690
|
+
if (matchingResult.length > 0) {
|
|
691
|
+
matchingResult.forEach((value, index) => {
|
|
692
|
+
asset = asset.replace(value, '');
|
|
693
|
+
const startIndex = value.toString().indexOf('":');
|
|
694
|
+
// Adding 2 to remove the ": matched before
|
|
695
|
+
let matchingVal = value.toString().substring(startIndex + 2);
|
|
696
|
+
// Starting from position 1 to remove first "
|
|
697
|
+
const matchingName = value.toString().substring(1, startIndex);
|
|
698
|
+
if (matchingVal[0] === '"' && matchingVal[matchingVal.length - 1] === '"') {
|
|
699
|
+
matchingVal = matchingVal.substring(1, matchingVal.length - 1);
|
|
700
|
+
}
|
|
701
|
+
resultingFilter.attribute.push(matchingName);
|
|
702
|
+
resultingFilter.attributeValue.push(matchingVal);
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
resultingFilter.asset = (asset && asset.length > 0) ? asset.trim() : undefined;
|
|
707
|
+
}
|
|
708
|
+
return resultingFilter;
|
|
709
|
+
}
|
|
710
|
+
formatFilter(newFilter) {
|
|
711
|
+
let searchInput = newFilter.asset ? newFilter.asset : '';
|
|
712
|
+
let prefix = newFilter.asset ? ' ' : '';
|
|
713
|
+
let handledAttributeForValues = [];
|
|
714
|
+
if (newFilter.assetType.length > 0) {
|
|
715
|
+
newFilter.assetType.forEach((assetType) => {
|
|
716
|
+
searchInput += prefix + 'type:' + assetType;
|
|
717
|
+
prefix = ' ';
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
if (newFilter.attribute.length > 0 && newFilter.attributeValue.length > 0) {
|
|
721
|
+
newFilter.attributeValue.forEach((attributeValue, index) => {
|
|
722
|
+
handledAttributeForValues.push(newFilter.attribute[index]);
|
|
723
|
+
searchInput += prefix + '"' + newFilter.attribute[index] + '":' + attributeValue;
|
|
724
|
+
prefix = ' ';
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
if (newFilter.attribute.length > 0 && newFilter.attributeValue.length === 0) {
|
|
728
|
+
newFilter.attribute.forEach((attributeName) => {
|
|
729
|
+
if (!handledAttributeForValues.includes(attributeName)) {
|
|
730
|
+
searchInput += prefix + 'attribute:"' + attributeName + '"';
|
|
731
|
+
prefix = ' ';
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
return searchInput;
|
|
736
|
+
}
|
|
737
|
+
_shouldEnableAttrTypeEvent(e) {
|
|
738
|
+
let value;
|
|
739
|
+
if (e.composedPath()) {
|
|
740
|
+
value = (e.composedPath()[0].value) || undefined;
|
|
741
|
+
}
|
|
742
|
+
this._shouldEnableAttrType(value);
|
|
743
|
+
}
|
|
744
|
+
_shouldEnableAttrType(value) {
|
|
745
|
+
if (value) {
|
|
746
|
+
this._attributeValueFilter.disabled = false;
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
this._attributeValueFilter.disabled = true;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
applySettingFields(filter) {
|
|
753
|
+
if (this._assetTypeFilter) {
|
|
754
|
+
filter.assetType = [this._assetTypeFilter];
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
filter.assetType = [];
|
|
758
|
+
}
|
|
759
|
+
if (this._attributeNameFilter.value) {
|
|
760
|
+
filter.attribute = [this._attributeNameFilter.value];
|
|
761
|
+
}
|
|
762
|
+
else {
|
|
763
|
+
filter.attribute = [];
|
|
764
|
+
}
|
|
765
|
+
if (this._attributeNameFilter.value && this._attributeValueFilter.value) {
|
|
766
|
+
let attributeValueValue = this._attributeValueFilter.value;
|
|
767
|
+
if (attributeValueValue.includes(' ')) {
|
|
768
|
+
attributeValueValue = '"' + attributeValueValue + '"';
|
|
769
|
+
}
|
|
770
|
+
filter.attributeValue = [attributeValueValue];
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
filter.attributeValue = [];
|
|
774
|
+
}
|
|
775
|
+
return filter;
|
|
776
|
+
}
|
|
777
|
+
_filterFromSettings() {
|
|
778
|
+
let filterFromSearchInput = this.parseFromInputFilter();
|
|
779
|
+
let filterFromSearchInputWithSettings = this.applySettingFields(filterFromSearchInput);
|
|
780
|
+
this._filter = filterFromSearchInputWithSettings;
|
|
781
|
+
let newFilterForSearchInput = this.formatFilter(this._filter);
|
|
782
|
+
this._filterInput.value = newFilterForSearchInput;
|
|
783
|
+
this._filterSettingOpen = false;
|
|
784
|
+
this._doFiltering();
|
|
785
|
+
}
|
|
786
|
+
_onFilterInputEvent(e) {
|
|
787
|
+
let value;
|
|
788
|
+
if (e.composedPath()) {
|
|
789
|
+
value = (e.composedPath()[0].value) || undefined;
|
|
790
|
+
}
|
|
791
|
+
this._onFilterInput(value, false);
|
|
792
|
+
}
|
|
793
|
+
_onFilterInput(newValue, force) {
|
|
794
|
+
let currentFilter = this.parseFromInputFilter(newValue);
|
|
795
|
+
if (Util.objectsEqual(this._filter, currentFilter, true)) {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
this._filter = currentFilter;
|
|
799
|
+
if (this._searchInputTimer) {
|
|
800
|
+
clearTimeout(this._searchInputTimer);
|
|
801
|
+
}
|
|
802
|
+
if (!force) {
|
|
803
|
+
this._searchInputTimer = window.setTimeout(() => {
|
|
804
|
+
this._doFiltering();
|
|
805
|
+
}, 350);
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
this._doFiltering();
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
_doFiltering() {
|
|
812
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
813
|
+
// Clear timeout in case we got here from value change
|
|
814
|
+
if (this._searchInputTimer) {
|
|
815
|
+
clearTimeout(this._searchInputTimer);
|
|
816
|
+
this._searchInputTimer = undefined;
|
|
817
|
+
}
|
|
818
|
+
if (this.isConnected && this._nodes) {
|
|
819
|
+
if (!this._filter.asset && !this._filter.attribute && !this._filter.assetType && !this._filter.attributeValue) {
|
|
820
|
+
// Clear the filter
|
|
821
|
+
OrAssetTree_1._forEachNodeRecursive(this._nodes, (node) => {
|
|
822
|
+
node.notMatchingFilter = false;
|
|
823
|
+
node.hidden = false;
|
|
824
|
+
});
|
|
825
|
+
this.requestUpdate("_nodes");
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
this.disabled = true;
|
|
829
|
+
// Use a matcher function - this can be altered independent of the filtering logic
|
|
830
|
+
// Maybe we should just filter in memory for basic matches like name
|
|
831
|
+
if (this._filter.asset || this._filter.assetType || this._filter.attribute) {
|
|
832
|
+
let queryRequired = false;
|
|
833
|
+
if (this._filter.attribute) {
|
|
834
|
+
queryRequired = true;
|
|
835
|
+
}
|
|
836
|
+
this.getMatcher(queryRequired).then((matcher) => {
|
|
837
|
+
if (this._nodes) {
|
|
838
|
+
this._nodes.forEach((node) => {
|
|
839
|
+
this.filterTreeNode(node, matcher);
|
|
840
|
+
});
|
|
841
|
+
this.disabled = false;
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
getMatcher(requireQuery) {
|
|
849
|
+
if (requireQuery) {
|
|
850
|
+
return this.getMatcherFromQuery();
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
return this.getSimpleNameMatcher();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
getSimpleNameMatcher() {
|
|
857
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
858
|
+
return (asset) => {
|
|
859
|
+
let match = true;
|
|
860
|
+
if (this._filter.asset) {
|
|
861
|
+
match = match && asset.name.toLowerCase().includes(this._filter.asset.toLowerCase());
|
|
862
|
+
}
|
|
863
|
+
if (this._filter.assetType.length > 0) {
|
|
864
|
+
match = match && (asset.type.toLowerCase() === this._filter.assetType[0].toLowerCase());
|
|
865
|
+
}
|
|
866
|
+
return match;
|
|
867
|
+
};
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
getMatcherFromQuery() {
|
|
871
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
872
|
+
let assetCond = undefined;
|
|
873
|
+
let attributeCond = undefined;
|
|
874
|
+
let assetTypeCond = undefined;
|
|
875
|
+
if (this._filter.asset) {
|
|
876
|
+
assetCond = [{
|
|
877
|
+
predicateType: "string",
|
|
878
|
+
match: "CONTAINS" /* AssetQueryMatch.CONTAINS */,
|
|
879
|
+
value: this._filter.asset,
|
|
880
|
+
caseSensitive: false
|
|
881
|
+
}];
|
|
882
|
+
}
|
|
883
|
+
if (this._filter.assetType.length > 0) {
|
|
884
|
+
assetTypeCond = this._filter.assetType;
|
|
885
|
+
}
|
|
886
|
+
if (this._filter.attribute.length > 0) {
|
|
887
|
+
attributeCond = {
|
|
888
|
+
operator: "AND" /* LogicGroupOperator.AND */,
|
|
889
|
+
items: this._filter.attribute.map((attributeName) => {
|
|
890
|
+
return {
|
|
891
|
+
name: {
|
|
892
|
+
predicateType: "string",
|
|
893
|
+
match: "EXACT" /* AssetQueryMatch.EXACT */,
|
|
894
|
+
value: Util.sentenceCaseToCamelCase(attributeName),
|
|
895
|
+
caseSensitive: false
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
})
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
const query = {
|
|
902
|
+
select: {
|
|
903
|
+
attributes: attributeCond ? undefined : []
|
|
904
|
+
},
|
|
905
|
+
names: assetCond,
|
|
906
|
+
types: assetTypeCond,
|
|
907
|
+
attributes: attributeCond
|
|
908
|
+
};
|
|
909
|
+
let response;
|
|
910
|
+
let foundAssetIds;
|
|
911
|
+
try {
|
|
912
|
+
response = yield manager.rest.api.AssetResource.queryAssets(query);
|
|
913
|
+
foundAssetIds = response.data.map((asset) => asset.id);
|
|
914
|
+
}
|
|
915
|
+
catch (e) {
|
|
916
|
+
this._filter.assetType.forEach((assetT) => {
|
|
917
|
+
if (this._assetTypes.findIndex((assetD) => { return assetD.name === assetT; }) === -1) {
|
|
918
|
+
showSnackbar(undefined, "filter.assetTypeDoesNotExist", "dismiss");
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
foundAssetIds = [];
|
|
922
|
+
}
|
|
923
|
+
return (asset) => {
|
|
924
|
+
let attrValueCheck = true;
|
|
925
|
+
if (this._filter.attribute.length > 0 && this._filter.attributeValue.length > 0 && foundAssetIds.includes(asset.id)) {
|
|
926
|
+
let attributeVal = [];
|
|
927
|
+
this._filter.attributeValue.forEach((attrVal, index) => {
|
|
928
|
+
if (attrVal.length > 0) {
|
|
929
|
+
attributeVal.push([this._filter.attribute[index], attrVal]);
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
let matchingAsset = response.data.find((a) => a.id === asset.id);
|
|
933
|
+
if (matchingAsset && matchingAsset.attributes) {
|
|
934
|
+
for (let attributeValIndex = 0; attributeValIndex < attributeVal.length; attributeValIndex++) {
|
|
935
|
+
let currentAttributeVal = attributeVal[attributeValIndex];
|
|
936
|
+
let atLeastOneAttributeMatchValue = false;
|
|
937
|
+
Object.keys(matchingAsset.attributes).forEach((key) => {
|
|
938
|
+
let attr = matchingAsset.attributes[key];
|
|
939
|
+
// attr.value check to avoid to compare with empty/non existing value
|
|
940
|
+
if (attr.name.toLowerCase() === currentAttributeVal[0].toLowerCase() && attr.value) {
|
|
941
|
+
switch (attr.type) {
|
|
942
|
+
case "number":
|
|
943
|
+
case "integer":
|
|
944
|
+
case "long":
|
|
945
|
+
case "bigInteger":
|
|
946
|
+
case "bigNumber":
|
|
947
|
+
case "positiveInteger":
|
|
948
|
+
case "negativeInteger":
|
|
949
|
+
case "positiveNumber":
|
|
950
|
+
case "negativeNumber":
|
|
951
|
+
let value = currentAttributeVal[1];
|
|
952
|
+
if (currentAttributeVal[1].startsWith('=') && currentAttributeVal[1][1] !== '=') {
|
|
953
|
+
value = '=' + value;
|
|
954
|
+
}
|
|
955
|
+
if (/^[0-9]+$/.test(currentAttributeVal[1])) {
|
|
956
|
+
value = '==' + value;
|
|
957
|
+
}
|
|
958
|
+
const resultNumberEval = eval(attr.value + value);
|
|
959
|
+
if (resultNumberEval) {
|
|
960
|
+
atLeastOneAttributeMatchValue = true;
|
|
961
|
+
}
|
|
962
|
+
break;
|
|
963
|
+
case "text":
|
|
964
|
+
if (attr.value) {
|
|
965
|
+
let unparsedValue = currentAttributeVal[1];
|
|
966
|
+
const multicharString = '*';
|
|
967
|
+
let parsedValue = unparsedValue.replace(multicharString, '.*');
|
|
968
|
+
parsedValue = parsedValue.replace(/"/g, '');
|
|
969
|
+
let valueFromAttribute = attr.value;
|
|
970
|
+
if (valueFromAttribute.toLowerCase().indexOf(parsedValue.toLowerCase()) != -1) {
|
|
971
|
+
atLeastOneAttributeMatchValue = true;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
break;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
attrValueCheck = atLeastOneAttributeMatchValue;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return foundAssetIds.includes(asset.id) && attrValueCheck;
|
|
983
|
+
};
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
isAnyFilter() {
|
|
987
|
+
return this._filter.asset !== undefined || this._filter.assetType.length > 0 || this._filter.attribute.length > 0;
|
|
988
|
+
}
|
|
989
|
+
filterTreeNode(currentNode, matcher, parentMatching = false) {
|
|
990
|
+
let nodeOrDescendantMatches = matcher(currentNode.asset);
|
|
991
|
+
currentNode.notMatchingFilter = !nodeOrDescendantMatches;
|
|
992
|
+
const childOrDescendantMatches = currentNode.children.map((childNode) => {
|
|
993
|
+
return this.filterTreeNode(childNode, matcher, nodeOrDescendantMatches);
|
|
994
|
+
});
|
|
995
|
+
let childMatches = childOrDescendantMatches.some(m => m);
|
|
996
|
+
nodeOrDescendantMatches = nodeOrDescendantMatches || childMatches;
|
|
997
|
+
currentNode.expanded = childMatches && currentNode.children.length > 0 && this.isAnyFilter();
|
|
998
|
+
currentNode.hidden = !nodeOrDescendantMatches && !parentMatching;
|
|
999
|
+
return nodeOrDescendantMatches;
|
|
1000
|
+
}
|
|
1001
|
+
_onCopyClicked() {
|
|
1002
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1003
|
+
if (this._selectedNodes.length !== 1) {
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
try {
|
|
1007
|
+
// Need to fully load the source asset
|
|
1008
|
+
const response = yield manager.rest.api.AssetResource.get(this._selectedNodes[0].asset.id);
|
|
1009
|
+
if (!response.data) {
|
|
1010
|
+
throw new Error("API returned an invalid response when retrieving the source asset");
|
|
1011
|
+
}
|
|
1012
|
+
const asset = JSON.parse(JSON.stringify(response.data));
|
|
1013
|
+
asset.name += " copy";
|
|
1014
|
+
delete asset.id;
|
|
1015
|
+
delete asset.path;
|
|
1016
|
+
delete asset.createdOn;
|
|
1017
|
+
delete asset.version;
|
|
1018
|
+
Util.dispatchCancellableEvent(this, new OrAssetTreeRequestAddEvent({
|
|
1019
|
+
sourceAsset: this._selectedNodes[0].asset,
|
|
1020
|
+
asset: asset
|
|
1021
|
+
})).then((detail) => {
|
|
1022
|
+
if (detail.allow) {
|
|
1023
|
+
this.dispatchEvent(new OrAssetTreeAddEvent(detail.detail));
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
catch (e) {
|
|
1028
|
+
console.error("Failed to copy asset", e);
|
|
1029
|
+
showErrorDialog("Failed to copy asset");
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
_onAddClicked() {
|
|
1034
|
+
const types = this._getAllowedChildTypes(this._selectedNodes[0]);
|
|
1035
|
+
const agentTypes = types.filter((t) => t.descriptorType === "agent");
|
|
1036
|
+
const assetTypes = types.filter((t) => t.descriptorType === "asset");
|
|
1037
|
+
const parent = this._selectedNodes && this._selectedNodes.length === 1 ? this._selectedNodes[0].asset : undefined;
|
|
1038
|
+
let dialog;
|
|
1039
|
+
const onAddChanged = (ev) => {
|
|
1040
|
+
const nameValid = !!ev.detail.name && ev.detail.name.trim().length > 0 && ev.detail.name.trim().length < 1024;
|
|
1041
|
+
const addBtn = dialog.shadowRoot.getElementById("add-btn");
|
|
1042
|
+
addBtn.disabled = !ev.detail.descriptor || !nameValid;
|
|
1043
|
+
};
|
|
1044
|
+
dialog = showDialog(new OrMwcDialog()
|
|
1045
|
+
.setHeading(i18next.t("addAsset"))
|
|
1046
|
+
.setContent(html `
|
|
1047
|
+
<or-add-asset-dialog id="add-panel" .config="${this.config}" .agentTypes="${agentTypes}" .assetTypes="${assetTypes}" .parent="${parent}" @or-add-asset-changed="${onAddChanged}"></or-add-asset-dialog>
|
|
1048
|
+
`)
|
|
1049
|
+
.setActions([
|
|
1050
|
+
{
|
|
1051
|
+
actionName: "cancel",
|
|
1052
|
+
content: "cancel"
|
|
1053
|
+
},
|
|
1054
|
+
{
|
|
1055
|
+
actionName: "add",
|
|
1056
|
+
content: html `<or-mwc-input id="add-btn" class="button" .type="${InputType.BUTTON}" label="add" disabled></or-mwc-input>`,
|
|
1057
|
+
action: () => {
|
|
1058
|
+
const addAssetDialog = dialog.shadowRoot.getElementById("add-panel");
|
|
1059
|
+
const descriptor = addAssetDialog.selectedType;
|
|
1060
|
+
const selectedOptionalAttributes = addAssetDialog.selectedAttributes;
|
|
1061
|
+
const name = addAssetDialog.name.trim();
|
|
1062
|
+
const parent = addAssetDialog.parent;
|
|
1063
|
+
if (!descriptor) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
const asset = {
|
|
1067
|
+
name: name,
|
|
1068
|
+
type: descriptor.name,
|
|
1069
|
+
realm: manager.displayRealm
|
|
1070
|
+
};
|
|
1071
|
+
// Construct attributes
|
|
1072
|
+
const assetTypeInfo = AssetModelUtil.getAssetTypeInfo(descriptor.name);
|
|
1073
|
+
if (!assetTypeInfo) {
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
if (assetTypeInfo.attributeDescriptors) {
|
|
1077
|
+
asset.attributes = {};
|
|
1078
|
+
assetTypeInfo.attributeDescriptors
|
|
1079
|
+
.filter((attributeDescriptor) => !attributeDescriptor.optional)
|
|
1080
|
+
.forEach((attributeDescriptor) => {
|
|
1081
|
+
asset.attributes[attributeDescriptor.name] = {
|
|
1082
|
+
name: attributeDescriptor.name,
|
|
1083
|
+
type: attributeDescriptor.type,
|
|
1084
|
+
meta: attributeDescriptor.meta ? Object.assign({}, attributeDescriptor.meta) : undefined
|
|
1085
|
+
};
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
if (selectedOptionalAttributes) {
|
|
1089
|
+
selectedOptionalAttributes === null || selectedOptionalAttributes === void 0 ? void 0 : selectedOptionalAttributes.forEach(attribute => {
|
|
1090
|
+
asset.attributes[attribute.name] = {
|
|
1091
|
+
name: attribute.name,
|
|
1092
|
+
type: attribute.type,
|
|
1093
|
+
meta: attribute.meta ? Object.assign({}, attribute.meta) : undefined
|
|
1094
|
+
};
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
if (this.selectedIds) {
|
|
1098
|
+
asset.parentId = parent ? parent.id : undefined;
|
|
1099
|
+
}
|
|
1100
|
+
const detail = {
|
|
1101
|
+
asset: asset
|
|
1102
|
+
};
|
|
1103
|
+
Util.dispatchCancellableEvent(this, new OrAssetTreeRequestAddEvent(detail))
|
|
1104
|
+
.then((detail) => {
|
|
1105
|
+
if (detail.allow) {
|
|
1106
|
+
this.dispatchEvent(new OrAssetTreeAddEvent(detail.detail));
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
])
|
|
1112
|
+
.setStyles(html `
|
|
1113
|
+
<style>
|
|
1114
|
+
.mdc-dialog__content {
|
|
1115
|
+
padding: 0 !important;
|
|
1116
|
+
}
|
|
1117
|
+
</style>
|
|
1118
|
+
`)
|
|
1119
|
+
.setDismissAction(null));
|
|
1120
|
+
}
|
|
1121
|
+
_gatewayDescendantIsSelected() {
|
|
1122
|
+
return this._selectedNodes.some((n) => {
|
|
1123
|
+
var _a;
|
|
1124
|
+
let parentNode = n === null || n === void 0 ? void 0 : n.parent;
|
|
1125
|
+
while (parentNode) {
|
|
1126
|
+
if (((_a = parentNode.asset) === null || _a === void 0 ? void 0 : _a.type) === "GatewayAsset" /* WellknownAssets.GATEWAYASSET */) {
|
|
1127
|
+
return true;
|
|
1128
|
+
}
|
|
1129
|
+
parentNode = parentNode.parent;
|
|
1130
|
+
}
|
|
1131
|
+
return false;
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
_onDeleteClicked() {
|
|
1135
|
+
if (this._selectedNodes.length > 0) {
|
|
1136
|
+
Util.dispatchCancellableEvent(this, new OrAssetTreeRequestDeleteEvent(this._selectedNodes))
|
|
1137
|
+
.then((detail) => {
|
|
1138
|
+
if (detail.allow) {
|
|
1139
|
+
this._doDelete();
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
_onSortClicked(sortBy) {
|
|
1145
|
+
this.sortBy = sortBy;
|
|
1146
|
+
}
|
|
1147
|
+
_doDelete() {
|
|
1148
|
+
if (!this._selectedNodes || this._selectedNodes.length === 0) {
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
const uniqueAssets = new Set();
|
|
1152
|
+
// Add gateway nodes first
|
|
1153
|
+
const nodes = this._selectedNodes.filter((node) => {
|
|
1154
|
+
var _a;
|
|
1155
|
+
if (((_a = node.asset) === null || _a === void 0 ? void 0 : _a.type) === "GatewayAsset" /* WellknownAssets.GATEWAYASSET */) {
|
|
1156
|
+
// Add gateway straight to the unique list and don't recursively select children
|
|
1157
|
+
uniqueAssets.add(node.asset);
|
|
1158
|
+
return false;
|
|
1159
|
+
}
|
|
1160
|
+
return true;
|
|
1161
|
+
});
|
|
1162
|
+
// Iterate through descendants of selected nodes that aren't gateways
|
|
1163
|
+
// and add to delete list (don't recurse descendant gateway nodes)
|
|
1164
|
+
OrAssetTree_1._forEachNodeRecursive(nodes, (node) => {
|
|
1165
|
+
var _a;
|
|
1166
|
+
// Check no ancestor is of type gateway
|
|
1167
|
+
let ancestor = node.parent;
|
|
1168
|
+
let okToAdd = true;
|
|
1169
|
+
while (ancestor && okToAdd) {
|
|
1170
|
+
const ancestorType = (_a = ancestor === null || ancestor === void 0 ? void 0 : ancestor.asset) === null || _a === void 0 ? void 0 : _a.type;
|
|
1171
|
+
if (ancestorType === "GatewayAsset" /* WellknownAssets.GATEWAYASSET */) {
|
|
1172
|
+
okToAdd = false;
|
|
1173
|
+
}
|
|
1174
|
+
ancestor = ancestor.parent;
|
|
1175
|
+
}
|
|
1176
|
+
if (okToAdd) {
|
|
1177
|
+
uniqueAssets.add(node.asset);
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
const assetIds = Array.from(uniqueAssets).map(asset => asset.id);
|
|
1181
|
+
const assetNames = Array.from(uniqueAssets).map(asset => asset.name);
|
|
1182
|
+
const doDelete = () => {
|
|
1183
|
+
this.disabled = true;
|
|
1184
|
+
manager.rest.api.AssetResource.delete({
|
|
1185
|
+
assetId: assetIds
|
|
1186
|
+
}, {
|
|
1187
|
+
paramsSerializer: params => Qs.stringify(params, { arrayFormat: 'repeat' })
|
|
1188
|
+
}).then((response) => {
|
|
1189
|
+
// Clear nodes to re-fetch them
|
|
1190
|
+
this.refresh();
|
|
1191
|
+
this.disabled = false;
|
|
1192
|
+
if (response.status !== 204) {
|
|
1193
|
+
showErrorDialog(i18next.t("deleteAssetsFailed"));
|
|
1194
|
+
}
|
|
1195
|
+
}).catch((reason) => {
|
|
1196
|
+
this.refresh();
|
|
1197
|
+
this.disabled = false;
|
|
1198
|
+
showErrorDialog(i18next.t("deleteAssetsFailed"));
|
|
1199
|
+
});
|
|
1200
|
+
};
|
|
1201
|
+
// Confirm deletion request
|
|
1202
|
+
showOkCancelDialog(i18next.t("deleteAssets"), i18next.t("deleteAssetsConfirm", { assetNames: assetNames.join(",\n- ") }), i18next.t("delete"))
|
|
1203
|
+
.then((ok) => {
|
|
1204
|
+
if (ok) {
|
|
1205
|
+
doDelete();
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
_canAdd() {
|
|
1210
|
+
var _a;
|
|
1211
|
+
if (this._selectedNodes && this._selectedNodes.length > 1) {
|
|
1212
|
+
return false;
|
|
1213
|
+
}
|
|
1214
|
+
const selectedNode = this._selectedNodes ? this._selectedNodes[0] : undefined;
|
|
1215
|
+
if (((_a = selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.asset) === null || _a === void 0 ? void 0 : _a.type) === "GatewayAsset" /* WellknownAssets.GATEWAYASSET */) {
|
|
1216
|
+
// Cannot add to a gateway asset
|
|
1217
|
+
return false;
|
|
1218
|
+
}
|
|
1219
|
+
if (this._gatewayDescendantIsSelected()) {
|
|
1220
|
+
// Cannot add to a descendant of a gateway asset
|
|
1221
|
+
return false;
|
|
1222
|
+
}
|
|
1223
|
+
return this._getAllowedChildTypes(selectedNode).length > 0;
|
|
1224
|
+
}
|
|
1225
|
+
_getAllowedChildTypes(selectedNode) {
|
|
1226
|
+
let includedAssetTypes;
|
|
1227
|
+
let excludedAssetTypes;
|
|
1228
|
+
if (this.config && this.config.add) {
|
|
1229
|
+
if (this.config.add.typesProvider) {
|
|
1230
|
+
const allowedTypes = this.config.add.typesProvider(selectedNode);
|
|
1231
|
+
if (allowedTypes) {
|
|
1232
|
+
return allowedTypes;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
if (this.config.add.typesParent) {
|
|
1236
|
+
let config;
|
|
1237
|
+
if (!selectedNode && this.config.add.typesParent.none) {
|
|
1238
|
+
config = this.config.add.typesParent.none;
|
|
1239
|
+
}
|
|
1240
|
+
else if (selectedNode && this.config.add.typesParent.assetTypes) {
|
|
1241
|
+
config = this.config.add.typesParent.assetTypes[selectedNode.asset.type];
|
|
1242
|
+
}
|
|
1243
|
+
if (!config) {
|
|
1244
|
+
config = this.config.add.typesParent.default;
|
|
1245
|
+
}
|
|
1246
|
+
if (config) {
|
|
1247
|
+
includedAssetTypes = config.include;
|
|
1248
|
+
excludedAssetTypes = config.exclude || [];
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
return AssetModelUtil.getAssetDescriptors()
|
|
1253
|
+
.filter((descriptor) => (!includedAssetTypes || includedAssetTypes.some((inc) => Util.stringMatch(inc, descriptor.name)))
|
|
1254
|
+
&& (!excludedAssetTypes || !excludedAssetTypes.some((exc) => Util.stringMatch(exc, descriptor.name))));
|
|
1255
|
+
}
|
|
1256
|
+
_getSortFunction() {
|
|
1257
|
+
switch (this.sortBy) {
|
|
1258
|
+
case "createdOn":
|
|
1259
|
+
return Util.sortByNumber((node) => node.asset[this.sortBy]);
|
|
1260
|
+
default:
|
|
1261
|
+
return Util.sortByString((node) => node.asset[this.sortBy]);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
_loadAssets() {
|
|
1265
|
+
const sortFunction = this._getSortFunction();
|
|
1266
|
+
if (!this.assets) {
|
|
1267
|
+
if (!this._connected) {
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
if (this._loading) {
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
this._loading = true;
|
|
1274
|
+
if (this.dataProvider) {
|
|
1275
|
+
this.dataProvider().then(assets => {
|
|
1276
|
+
this._loading = false;
|
|
1277
|
+
this._buildTreeNodes(assets, sortFunction);
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
else {
|
|
1281
|
+
const query = {
|
|
1282
|
+
realm: {
|
|
1283
|
+
name: manager.displayRealm
|
|
1284
|
+
},
|
|
1285
|
+
select: {
|
|
1286
|
+
attributes: []
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
if (this.assetIds) {
|
|
1290
|
+
query.ids = this.assetIds;
|
|
1291
|
+
query.recursive = true;
|
|
1292
|
+
}
|
|
1293
|
+
else if (this.rootAssets) {
|
|
1294
|
+
query.ids = this.rootAssets.map((asset) => asset.id);
|
|
1295
|
+
query.recursive = true;
|
|
1296
|
+
}
|
|
1297
|
+
else if (this.rootAssetIds) {
|
|
1298
|
+
query.ids = this.rootAssetIds;
|
|
1299
|
+
query.recursive = true;
|
|
1300
|
+
}
|
|
1301
|
+
this._sendEventWithReply({
|
|
1302
|
+
eventType: "read-assets",
|
|
1303
|
+
assetQuery: query
|
|
1304
|
+
}).then((ev) => {
|
|
1305
|
+
this._loading = false;
|
|
1306
|
+
this._buildTreeNodes(ev.assets, sortFunction);
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
else {
|
|
1311
|
+
this._loading = false;
|
|
1312
|
+
this._buildTreeNodes(this.assets, sortFunction);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
/* Subscribe mixin overrides */
|
|
1316
|
+
_addEventSubscriptions() {
|
|
1317
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1318
|
+
if (!this.disableSubscribe) {
|
|
1319
|
+
// Subscribe to asset events for all assets in the realm
|
|
1320
|
+
this._subscriptionIds = [yield manager.getEventProvider().subscribeAssetEvents(undefined, false, (event) => this._onEvent(event))];
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
onEventsConnect() {
|
|
1325
|
+
this._connected = true;
|
|
1326
|
+
this._loadAssets();
|
|
1327
|
+
}
|
|
1328
|
+
onEventsDisconnect() {
|
|
1329
|
+
this._connected = false;
|
|
1330
|
+
this._nodes = undefined;
|
|
1331
|
+
}
|
|
1332
|
+
getNodes() {
|
|
1333
|
+
return this._nodes || [];
|
|
1334
|
+
}
|
|
1335
|
+
_onEvent(event) {
|
|
1336
|
+
if (event.eventType === "assets") {
|
|
1337
|
+
const assetsEvent = event;
|
|
1338
|
+
this._buildTreeNodes(assetsEvent.assets, this._getSortFunction());
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
if (event.eventType === "asset") {
|
|
1342
|
+
const assetEvent = event;
|
|
1343
|
+
if (assetEvent.cause === "READ" /* AssetEventCause.READ */) {
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
if (assetEvent.cause === "UPDATE" /* AssetEventCause.UPDATE */
|
|
1347
|
+
&& !(assetEvent.updatedProperties.includes("name")
|
|
1348
|
+
|| assetEvent.updatedProperties.includes("parentId"))) {
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
// Extract all assets, update and rebuild tree
|
|
1352
|
+
const assets = [];
|
|
1353
|
+
if (assetEvent.cause !== "DELETE" /* AssetEventCause.DELETE */) {
|
|
1354
|
+
assets.push(assetEvent.asset);
|
|
1355
|
+
}
|
|
1356
|
+
if (this._nodes) {
|
|
1357
|
+
OrAssetTree_1._forEachNodeRecursive(this._nodes, (node) => {
|
|
1358
|
+
if (node.asset.id !== assetEvent.asset.id) {
|
|
1359
|
+
assets.push(node.asset);
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
// In case of filter already active, do not override the actual state of assetTree
|
|
1364
|
+
this._buildTreeNodes(assets, this._getSortFunction());
|
|
1365
|
+
if (this._filterInput.value) {
|
|
1366
|
+
this._doFiltering();
|
|
1367
|
+
}
|
|
1368
|
+
this.dispatchEvent(new OrAssetTreeAssetEvent(assetEvent));
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
_buildTreeNodes(assets, sortFunction) {
|
|
1372
|
+
if (!assets || assets.length === 0) {
|
|
1373
|
+
this._nodes = [];
|
|
1374
|
+
}
|
|
1375
|
+
else {
|
|
1376
|
+
if (manager.isRestrictedUser()) {
|
|
1377
|
+
// Restricted users might have access to children, without access to the parent asset.
|
|
1378
|
+
// Any assets whose parents aren't accessible need to be 're-parented'.
|
|
1379
|
+
assets.forEach(asset => {
|
|
1380
|
+
if (!!asset.parentId && !!asset.path && assets.find(a => a.id === asset.parentId) === undefined) {
|
|
1381
|
+
let reparentId = null;
|
|
1382
|
+
// Loop through ALL assets in the path, and check if they're present in the (restricted) asset list
|
|
1383
|
+
// Once found, update its parent ID without replacing the original (that's why it's named 'reparentId').
|
|
1384
|
+
for (let i = 0; i < asset.path.length; i++) {
|
|
1385
|
+
const ancestorId = asset.path[i];
|
|
1386
|
+
if (asset.id !== ancestorId && assets.find(a => a.id === ancestorId) !== undefined) {
|
|
1387
|
+
reparentId = ancestorId;
|
|
1388
|
+
// break; No break statement here, as when an asset further down the tree has been found, it should overwrite the parent ID.
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
asset.reparentId = reparentId;
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
let rootAssetIds;
|
|
1396
|
+
if (this.rootAssetIds) {
|
|
1397
|
+
rootAssetIds = this.rootAssetIds;
|
|
1398
|
+
}
|
|
1399
|
+
else if (this.rootAssets) {
|
|
1400
|
+
rootAssetIds = this.rootAssets.map((ra) => ra.id);
|
|
1401
|
+
}
|
|
1402
|
+
let rootAssets;
|
|
1403
|
+
if (rootAssetIds) {
|
|
1404
|
+
rootAssets = assets.filter((asset) => rootAssetIds.indexOf(asset.id) >= 0 || asset.reparentId === null).map((asset) => {
|
|
1405
|
+
return {
|
|
1406
|
+
asset: asset
|
|
1407
|
+
};
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
rootAssets = assets.filter((asset) => !asset.parentId || asset.reparentId === null).map((asset) => {
|
|
1412
|
+
return {
|
|
1413
|
+
asset: asset
|
|
1414
|
+
};
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
this.assetsChildren = {};
|
|
1418
|
+
assets.forEach((asset) => {
|
|
1419
|
+
if (asset.parentId) {
|
|
1420
|
+
if (!this.assetsChildren[asset.parentId]) {
|
|
1421
|
+
this.assetsChildren[asset.parentId] = [];
|
|
1422
|
+
}
|
|
1423
|
+
this.assetsChildren[asset.parentId].push({
|
|
1424
|
+
asset: asset
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
if (asset.reparentId) {
|
|
1428
|
+
if (!this.assetsChildren[asset.reparentId]) {
|
|
1429
|
+
this.assetsChildren[asset.reparentId] = [];
|
|
1430
|
+
}
|
|
1431
|
+
this.assetsChildren[asset.reparentId].push({
|
|
1432
|
+
asset: asset
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
});
|
|
1436
|
+
rootAssets.sort(sortFunction);
|
|
1437
|
+
rootAssets.forEach((rootAsset) => this._buildChildTreeNodes(rootAsset, assets, sortFunction));
|
|
1438
|
+
this._nodes = rootAssets;
|
|
1439
|
+
const newExpanded = [];
|
|
1440
|
+
this._expandedNodes.forEach(expandedNode => {
|
|
1441
|
+
OrAssetTree_1._forEachNodeRecursive(this._nodes, n => {
|
|
1442
|
+
if (n.asset && expandedNode && expandedNode.asset && n.asset.id === expandedNode.asset.id) {
|
|
1443
|
+
n.expanded = true;
|
|
1444
|
+
newExpanded.push(n);
|
|
1445
|
+
// Expand every ancestor
|
|
1446
|
+
let parent = n.parent;
|
|
1447
|
+
while (parent) {
|
|
1448
|
+
parent.expanded = true;
|
|
1449
|
+
parent = parent.parent;
|
|
1450
|
+
if (newExpanded.indexOf(parent) < 0) {
|
|
1451
|
+
newExpanded.push(parent);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
1456
|
+
});
|
|
1457
|
+
this._expandedNodes = newExpanded;
|
|
1458
|
+
}
|
|
1459
|
+
if (this.selectedIds && this.selectedIds.length > 0) {
|
|
1460
|
+
this._updateSelectedNodes();
|
|
1461
|
+
}
|
|
1462
|
+
if (this.expandAllNodes) {
|
|
1463
|
+
OrAssetTree_1._forEachNodeRecursive(this._nodes, (node) => {
|
|
1464
|
+
if (node.children && node.children.length > 0) {
|
|
1465
|
+
node.expanded = true;
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
_buildChildTreeNodes(treeNode, assets, sortFunction) {
|
|
1471
|
+
let children = this.assetsChildren[treeNode.asset.id];
|
|
1472
|
+
treeNode.children = children ? children.sort(sortFunction) : [];
|
|
1473
|
+
if (treeNode.children.length > 0) {
|
|
1474
|
+
treeNode.expandable = true;
|
|
1475
|
+
}
|
|
1476
|
+
treeNode.children.forEach((childNode) => {
|
|
1477
|
+
childNode.parent = treeNode;
|
|
1478
|
+
this._buildChildTreeNodes(childNode, assets, sortFunction);
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
_onDragStart(ev) {
|
|
1482
|
+
this._dragDropParentId = null;
|
|
1483
|
+
let currentElement = ev.currentTarget;
|
|
1484
|
+
let selectedId = currentElement.getAttribute('node-asset-id');
|
|
1485
|
+
if (!this.selectedIds) {
|
|
1486
|
+
this.selectedIds = [];
|
|
1487
|
+
}
|
|
1488
|
+
if (selectedId && this.selectedIds && !this.selectedIds.includes(selectedId)) {
|
|
1489
|
+
if (!ev.ctrlKey && !ev.shiftKey) {
|
|
1490
|
+
this.selectedIds = [];
|
|
1491
|
+
}
|
|
1492
|
+
this.selectedIds.push(selectedId);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
_onDragEnd(ev) {
|
|
1496
|
+
const dragEndTargetX = ev.x;
|
|
1497
|
+
const dragEndTargetY = ev.y;
|
|
1498
|
+
if (this.shadowRoot !== null) {
|
|
1499
|
+
let listElement = this.shadowRoot.getElementById('list');
|
|
1500
|
+
if (listElement) {
|
|
1501
|
+
const topY = listElement.getBoundingClientRect().top;
|
|
1502
|
+
const bottomY = listElement.getBoundingClientRect().bottom;
|
|
1503
|
+
const leftX = listElement.getBoundingClientRect().left;
|
|
1504
|
+
const rightX = listElement.getBoundingClientRect().right;
|
|
1505
|
+
if (dragEndTargetX < leftX || dragEndTargetX > rightX || dragEndTargetY > bottomY || dragEndTargetY < topY) {
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
if (this.selectedIds) {
|
|
1511
|
+
this.dispatchEvent(new OrAssetTreeChangeParentEvent(!this._dragDropParentId ? undefined : this._dragDropParentId, this.selectedIds));
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
isExpandable(assetId) {
|
|
1515
|
+
if (this._nodes) {
|
|
1516
|
+
if (this.shadowRoot) {
|
|
1517
|
+
let elem = this.shadowRoot.querySelector('[node-asset-id="' + assetId + '"] > .node-name > [data-expandable]');
|
|
1518
|
+
if (elem) {
|
|
1519
|
+
return true;
|
|
1520
|
+
}
|
|
1521
|
+
else {
|
|
1522
|
+
return false;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
return false;
|
|
1527
|
+
}
|
|
1528
|
+
_onDragOver(ev) {
|
|
1529
|
+
let currentElement = ev.currentTarget;
|
|
1530
|
+
currentElement.classList.add('over');
|
|
1531
|
+
let assetId = currentElement.getAttribute('node-asset-id');
|
|
1532
|
+
if (assetId && this.isExpandable(assetId) && !this._expandTimer) {
|
|
1533
|
+
this._expandTimer = window.setTimeout(() => {
|
|
1534
|
+
this.expandNode(assetId);
|
|
1535
|
+
}, 1000);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
expandNode(assetId) {
|
|
1539
|
+
var _a;
|
|
1540
|
+
if (this.shadowRoot && assetId && assetId === this._dragDropParentId) {
|
|
1541
|
+
const node = this._findNodeFromAssetId(assetId);
|
|
1542
|
+
let elem = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('[node-asset-id="' + assetId + '"]');
|
|
1543
|
+
if (elem && node && !node.expanded) {
|
|
1544
|
+
this._toggleExpander(elem.firstElementChild.firstElementChild, node, true);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
_onDragEnter(ev) {
|
|
1549
|
+
let currentElement = ev.currentTarget;
|
|
1550
|
+
currentElement.classList.add('over');
|
|
1551
|
+
let enteredId = currentElement.getAttribute('node-asset-id');
|
|
1552
|
+
this._dragDropParentId = enteredId;
|
|
1553
|
+
}
|
|
1554
|
+
_onDragLeave(ev) {
|
|
1555
|
+
let currentElement = ev.currentTarget;
|
|
1556
|
+
currentElement.classList.remove('over');
|
|
1557
|
+
clearTimeout(this._expandTimer);
|
|
1558
|
+
this._expandTimer = undefined;
|
|
1559
|
+
}
|
|
1560
|
+
_treeNodeTemplate(treeNode, level) {
|
|
1561
|
+
const descriptor = AssetModelUtil.getAssetDescriptor(treeNode.asset.type);
|
|
1562
|
+
let parentCheckboxIcon;
|
|
1563
|
+
if (treeNode.allChildrenSelected) {
|
|
1564
|
+
parentCheckboxIcon = 'checkbox-multiple-marked';
|
|
1565
|
+
}
|
|
1566
|
+
else if (treeNode.someChildrenSelected) {
|
|
1567
|
+
parentCheckboxIcon = 'checkbox-multiple-marked-outline';
|
|
1568
|
+
}
|
|
1569
|
+
else {
|
|
1570
|
+
parentCheckboxIcon = 'checkbox-multiple-blank-outline';
|
|
1571
|
+
}
|
|
1572
|
+
if (treeNode.hidden) {
|
|
1573
|
+
return html ``;
|
|
1574
|
+
}
|
|
1575
|
+
let filterColorForNonMatchingAsset = false;
|
|
1576
|
+
if (treeNode.asset && treeNode.notMatchingFilter) {
|
|
1577
|
+
filterColorForNonMatchingAsset = true;
|
|
1578
|
+
}
|
|
1579
|
+
if (treeNode.expanded && treeNode.children.length === 0) {
|
|
1580
|
+
treeNode.expanded = false;
|
|
1581
|
+
}
|
|
1582
|
+
if (this.expandedIds && this.expandedIds.findIndex((expandId) => { return expandId === treeNode.asset.id; }) !== -1) {
|
|
1583
|
+
treeNode.expanded = true;
|
|
1584
|
+
}
|
|
1585
|
+
return html `
|
|
1586
|
+
<li class="asset-list-element" ?data-selected="${treeNode.selected}" ?data-expanded="${treeNode.expanded}" @click="${(evt) => this._onNodeClicked(evt, treeNode)}">
|
|
1587
|
+
<div class="in-between-element" node-asset-id="${treeNode.parent ? (treeNode.parent.asset ? treeNode.parent.asset.id : '') : undefined}" @dragleave=${(ev) => { this._onDragLeave(ev); }} @dragenter="${(ev) => this._onDragEnter(ev)}" @dragend="${(ev) => this._onDragEnd(ev)}" @dragover="${(ev) => this._onDragOver(ev)}"></div>
|
|
1588
|
+
<div class="node-container draggable" node-asset-id="${treeNode.asset ? treeNode.asset.id : ''}" draggable="${!this._isReadonly()}" @dragleave=${(ev) => { this._onDragLeave(ev); }} @dragenter="${(ev) => this._onDragEnter(ev)}" @dragstart="${(ev) => this._onDragStart(ev)}" @dragend="${(ev) => this._onDragEnd(ev)}" @dragover="${(ev) => this._onDragOver(ev)}" style="padding-left: ${level * 22}px">
|
|
1589
|
+
<div class="node-name">
|
|
1590
|
+
<div class="expander" ?data-expandable="${treeNode.expandable}"></div>
|
|
1591
|
+
${getAssetDescriptorIconTemplate(descriptor, undefined, undefined, (filterColorForNonMatchingAsset ? 'd3d3d3' : undefined))}
|
|
1592
|
+
<span style="color: ${filterColorForNonMatchingAsset ? '#d3d3d3;' : ''}">${treeNode.asset.name}</span>
|
|
1593
|
+
${this.checkboxes ? html `
|
|
1594
|
+
<span class="mdc-list-item__graphic">
|
|
1595
|
+
${treeNode.expandable
|
|
1596
|
+
? html `<div class="mdc-checkbox">
|
|
1597
|
+
<or-icon class="mdc-checkbox--parent" icon="${parentCheckboxIcon}"></or-icon>
|
|
1598
|
+
</div>`
|
|
1599
|
+
: ``}
|
|
1600
|
+
<div class="mdc-checkbox">
|
|
1601
|
+
${treeNode.selected ? html `<or-icon icon="checkbox-marked"></or-icon>` : html `<or-icon icon="checkbox-blank-outline"></or-icon>`}
|
|
1602
|
+
</div>
|
|
1603
|
+
</span>`
|
|
1604
|
+
: ``}
|
|
1605
|
+
</div>
|
|
1606
|
+
</div>
|
|
1607
|
+
<ol>
|
|
1608
|
+
${!treeNode.children || (treeNode.expandable && !treeNode.expanded) ? `` : treeNode.children.map((childNode) => this._treeNodeTemplate(childNode, level + 1)).filter(t => !!t)}
|
|
1609
|
+
</ol>
|
|
1610
|
+
</li>
|
|
1611
|
+
`;
|
|
1612
|
+
}
|
|
1613
|
+
static _forEachNodeRecursive(nodes, fn) {
|
|
1614
|
+
if (!nodes) {
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
nodes.forEach((node) => {
|
|
1618
|
+
fn(node);
|
|
1619
|
+
this._forEachNodeRecursive(node.children, fn);
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
__decorate([
|
|
1624
|
+
property({ type: Array, reflect: false })
|
|
1625
|
+
], OrAssetTree.prototype, "assets", void 0);
|
|
1626
|
+
__decorate([
|
|
1627
|
+
property({ type: Object })
|
|
1628
|
+
], OrAssetTree.prototype, "assetInfos", void 0);
|
|
1629
|
+
__decorate([
|
|
1630
|
+
property({ type: Array })
|
|
1631
|
+
], OrAssetTree.prototype, "_assetIdsOverride", void 0);
|
|
1632
|
+
__decorate([
|
|
1633
|
+
property({ type: Array })
|
|
1634
|
+
], OrAssetTree.prototype, "rootAssets", void 0);
|
|
1635
|
+
__decorate([
|
|
1636
|
+
property({ type: Array })
|
|
1637
|
+
], OrAssetTree.prototype, "rootAssetIds", void 0);
|
|
1638
|
+
__decorate([
|
|
1639
|
+
property({ type: Object })
|
|
1640
|
+
], OrAssetTree.prototype, "dataProvider", void 0);
|
|
1641
|
+
__decorate([
|
|
1642
|
+
property({ type: Boolean })
|
|
1643
|
+
], OrAssetTree.prototype, "readonly", void 0);
|
|
1644
|
+
__decorate([
|
|
1645
|
+
property({ type: Boolean })
|
|
1646
|
+
], OrAssetTree.prototype, "disabled", void 0);
|
|
1647
|
+
__decorate([
|
|
1648
|
+
property({ type: Boolean })
|
|
1649
|
+
], OrAssetTree.prototype, "disableSubscribe", void 0);
|
|
1650
|
+
__decorate([
|
|
1651
|
+
property({ type: Array })
|
|
1652
|
+
], OrAssetTree.prototype, "selectedIds", void 0);
|
|
1653
|
+
__decorate([
|
|
1654
|
+
property({ type: Boolean })
|
|
1655
|
+
], OrAssetTree.prototype, "showDeselectBtn", void 0);
|
|
1656
|
+
__decorate([
|
|
1657
|
+
property({ type: Boolean })
|
|
1658
|
+
], OrAssetTree.prototype, "showSortBtn", void 0);
|
|
1659
|
+
__decorate([
|
|
1660
|
+
property({ type: Boolean })
|
|
1661
|
+
], OrAssetTree.prototype, "showFilter", void 0);
|
|
1662
|
+
__decorate([
|
|
1663
|
+
property({ type: String })
|
|
1664
|
+
], OrAssetTree.prototype, "sortBy", void 0);
|
|
1665
|
+
__decorate([
|
|
1666
|
+
property({ type: Boolean })
|
|
1667
|
+
], OrAssetTree.prototype, "expandAllNodes", void 0);
|
|
1668
|
+
__decorate([
|
|
1669
|
+
property({ type: Array })
|
|
1670
|
+
], OrAssetTree.prototype, "expandedIds", void 0);
|
|
1671
|
+
__decorate([
|
|
1672
|
+
property({ type: Boolean })
|
|
1673
|
+
], OrAssetTree.prototype, "checkboxes", void 0);
|
|
1674
|
+
__decorate([
|
|
1675
|
+
property({ attribute: false })
|
|
1676
|
+
], OrAssetTree.prototype, "_nodes", void 0);
|
|
1677
|
+
__decorate([
|
|
1678
|
+
state()
|
|
1679
|
+
], OrAssetTree.prototype, "_filter", void 0);
|
|
1680
|
+
__decorate([
|
|
1681
|
+
query("#clearIconContainer")
|
|
1682
|
+
], OrAssetTree.prototype, "_clearIconContainer", void 0);
|
|
1683
|
+
__decorate([
|
|
1684
|
+
query("#filterInput")
|
|
1685
|
+
], OrAssetTree.prototype, "_filterInput", void 0);
|
|
1686
|
+
__decorate([
|
|
1687
|
+
state()
|
|
1688
|
+
], OrAssetTree.prototype, "_filterSettingOpen", void 0);
|
|
1689
|
+
__decorate([
|
|
1690
|
+
state()
|
|
1691
|
+
], OrAssetTree.prototype, "_assetTypes", void 0);
|
|
1692
|
+
__decorate([
|
|
1693
|
+
query("#attributeNameFilter")
|
|
1694
|
+
], OrAssetTree.prototype, "_attributeNameFilter", void 0);
|
|
1695
|
+
__decorate([
|
|
1696
|
+
query("#attributeValueFilter")
|
|
1697
|
+
], OrAssetTree.prototype, "_attributeValueFilter", void 0);
|
|
1698
|
+
__decorate([
|
|
1699
|
+
state()
|
|
1700
|
+
], OrAssetTree.prototype, "_assetTypeFilter", void 0);
|
|
1701
|
+
OrAssetTree = OrAssetTree_1 = __decorate([
|
|
1702
|
+
customElement("or-asset-tree")
|
|
1703
|
+
], OrAssetTree);
|
|
1704
|
+
export { OrAssetTree };
|
|
1705
|
+
//# sourceMappingURL=index.js.map
|