@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 6.35 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../chunks/tslib.es6.js";import{watch as t,on as r,initial as i}from"../../core/reactiveUtils.js";import{property as l}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as s}from"../../core/accessorSupport/decorators/subclass.js";import{isSubtypeGroupLayer as o,getEffectiveLayerCapabilities as a}from"../../layers/support/layerUtils.js";import n from"../Feature/FeatureRelationship/FeatureRelationshipViewModel.js";import{isRelatableFeatureSupportedLayer as p}from"../Feature/support/featureUtils.js";import d from"./EditableInput.js";import{getComputedAttributes as u,parseFormTemplateString as h}from"./featureFormUtils.js";const y=3;let g=class extends d{constructor(e){super(e),this._relationshipVM=null,this.group=null,this.type="relationship",this.addHandles([t((()=>({feature:this.feature,element:this.element,layer:this.layer})),(e=>this._createRelationshipVM(e)),i),r((()=>this.relatedLayer),"edits",(()=>this._relationshipVM?.refresh()))])}destroy(){this._relationshipVM?.destroy()}get canAddRelatedFeature(){const{editable:e,featureCount:t,relationship:r}=this;if(!r||!this.loaded||!this.relatedLayerAllowsAdds)return!1;if(this.allCategories?.length&&!this.activeCategory)return!1;const{cardinality:i,role:l}=r;return!("one-to-one"===i&&t>0)&&("many-to-many"!==i&&(!("one-to-many"===i&&"destination"===l&&t>0)&&e))}get activeCategory(){return this._relationshipVM?.activeCategory}set activeCategory(e){const t=this._relationshipVM;t&&(t.activeCategory=e)}get allCategories(){const{relatedLayer:e}=this,t=this._relationshipVM?.categories;if(!o(e))return;const r=(e.subtypes??[]).map((({code:e,name:r})=>{const i=t?.find((e=>e.name===r));return{name:r,count:i?.count??0,value:i?.value??e}}));return r.length?r:null}get categories(){return this.showAllEnabled?this.allCategories:this.allCategories?.slice(0,this.displayCount)}get displayCount(){return this.element.displayCount??y}get displayType(){return this.element.displayType}get editable(){return!!this.relatedLayerAllowsEdits&&(this.evaluatedEditableExpression??!0)}get featureCount(){return this._relationshipVM?.featureCount??0}get label(){return this.activeCategory?.name?this.activeCategory.name:this.getFormattedLabel(this.element?.label)}get loaded(){return"loading"!==this._relationshipVM?.state}get map(){return this._get("map")}set map(e){e&&this._relationshipVM?.set("map",e),this._set("map",e)}get orderByFields(){return this.element.orderByFields}get originHasValidKey(){return!(!this.relationship||!this.feature.getAttribute(this.relationship.keyField))}get relationship(){return this._relationshipVM?.relationship}get relationshipId(){return this.element.relationshipId}get relatedFeatureInfos(){const{_relationshipVM:e,timeZone:t}=this;if(!e?.relatedFeatures?.length||!e?.relatedLayer)return[];const{itemDescriptionFieldName:r,relatedFeatures:i,relatedLayer:l}=e,s=l&&"formTemplate"in l&&l.formTemplate?l.formTemplate.title:void 0;return i.map((e=>{let i;if(r){const s=e.getAttribute(r),o=l.fieldsIndex.get(r);if(o){const e=u({values:[s],fields:[o],timeZone:t??void 0})[r];null!=e&&(i=e.toString())}}return{feature:e,description:i,title:s?h({label:s,attributes:e.attributes,fieldsIndex:l.fieldsIndex,timeZone:t}):void 0}})).toArray()}get relatedLayer(){return this._relationshipVM?.relatedLayer}get relatedLayerIsTable(){return!!this.relatedLayer?.isTable}get relatedLayerAllowsAdds(){const{relatedLayer:e}=this;if(!e||!this.relatedLayerAllowsEdits)return!1;const t=a(e);return!!t?.operations?.supportsAdd}get relatedLayerAllowsEdits(){const{relatedLayer:e}=this;if(!e)return!1;const t=a(e);return!!t?.operations?.supportsEditing}get showAllEnabled(){return this._get("showAllEnabled")}set showAllEnabled(e){this._relationshipVM?.set("showAllEnabled",e),this._set("showAllEnabled",e)}get showAllActionVisible(){return!this.showAllEnabled&&this.featureCount>0&&this.featureCount>this.displayCount}get showAllCategoriesVisible(){const e=this.allCategories?.length??0;return!this.showAllEnabled&&e>0&&e>this.displayCount}get visible(){const{relationship:e}=this;if(!e)return!1;const{cardinality:t}=e;return"many-to-many"!==t&&(null!=this.evaluatedVisibilityExpression?this.evaluatedVisibilityExpression:null!=this.element)}get updating(){return"loading"===this._relationshipVM?.state||"querying"===this._relationshipVM?.state}incrementPage(){this._relationshipVM&&this._relationshipVM.featurePage++}getRelatedFeatureByObjectId(e){return this._relationshipVM?.getRelatedFeatureByObjectId(e)}_createRelationshipVM(e){const{feature:t,element:r,layer:i}=e;if(this._relationshipVM?.destroy(),!t||!r||!i)return;const{displayCount:l,map:s,orderByFields:o,relationshipId:a,showAllEnabled:d}=this;p(i)&&(this._relationshipVM=new n({graphic:t,displayCount:l,layer:i,map:s,orderByFields:o,relationshipId:a,showAllEnabled:d}))}};e([l()],g.prototype,"_relationshipVM",void 0),e([l()],g.prototype,"canAddRelatedFeature",null),e([l()],g.prototype,"activeCategory",null),e([l()],g.prototype,"allCategories",null),e([l()],g.prototype,"categories",null),e([l()],g.prototype,"displayCount",null),e([l()],g.prototype,"displayType",null),e([l()],g.prototype,"editable",null),e([l()],g.prototype,"featureCount",null),e([l()],g.prototype,"group",void 0),e([l()],g.prototype,"label",null),e([l()],g.prototype,"loaded",null),e([l()],g.prototype,"map",null),e([l()],g.prototype,"orderByFields",null),e([l()],g.prototype,"originHasValidKey",null),e([l()],g.prototype,"relationship",null),e([l()],g.prototype,"relationshipId",null),e([l()],g.prototype,"relatedFeatureInfos",null),e([l()],g.prototype,"relatedLayer",null),e([l()],g.prototype,"relatedLayerIsTable",null),e([l()],g.prototype,"relatedLayerAllowsAdds",null),e([l()],g.prototype,"relatedLayerAllowsEdits",null),e([l()],g.prototype,"showAllEnabled",null),e([l()],g.prototype,"showAllActionVisible",null),e([l()],g.prototype,"showAllCategoriesVisible",null),e([l({readOnly:!0})],g.prototype,"type",void 0),e([l()],g.prototype,"visible",null),e([l()],g.prototype,"updating",null),g=e([s("esri.widgets.FeatureForm.RelationshipInput")],g);const c=g;export{c as default};