12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../Graphic.js";import a from"../../core/Accessor.js";import i from"../../core/Collection.js";import r from"../../core/Error.js";import{isSome as n}from"../../core/maybe.js";import{watch as s,initial as o}from"../../core/reactiveUtils.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{cast as h}from"../../core/accessorSupport/decorators/cast.js";import{subclass as d}from"../../core/accessorSupport/decorators/subclass.js";import m from"../../rest/query/support/AttachmentInfo.js";import l from"../../rest/support/AttachmentQuery.js";import{getSourceLayer as p}from"../Feature/support/featureUtils.js";const u={editing:!1,operations:{add:!0,update:!0,delete:!0}},y=i.ofType(m),A="graphic.layer.capabilities.operations.supportsResizeAttachments";let f=class extends a{constructor(t){super(t),this._getAttachmentsPromise=null,this._attachmentLayer=null,this.abilities={...u},this.activeAttachmentInfo=null,this.attachmentInfos=new y,this.graphic=null,this.mode="view",this.own(s((()=>this.graphic),(()=>this._graphicChanged()),o))}destroy(){this._attachmentLayer=null,this.graphic=null}castAbilities(t){return{...u,...t}}get state(){return this._getAttachmentsPromise?"loading":this.graphic?"ready":"disabled"}get supportsResizeAttachments(){return this.get(A)||!1}async getAttachments(){const{_attachmentLayer:t,attachmentInfos:e}=this;if(!t||"function"!=typeof t.queryAttachments)throw new r("invalid-layer","getAttachments(): A valid layer is required.");const a=this._getFeatureId(),i=new l({objectIds:[a],returnMetadata:!0}),n=[],s=t.queryAttachments(i).then((t=>t[a]||n)).catch((()=>n));this._getAttachmentsPromise=s,this.notifyChange("state");const o=await s;return e.removeAll(),o.length&&e.addMany(o),this._getAttachmentsPromise=null,this.notifyChange("state"),o}async addAttachment(t){const{_attachmentLayer:e,attachmentInfos:a,graphic:i,abilities:n}=this;if(!t)throw new r("invalid-attachment","addAttachment(): An attachment is required.",{attachment:t});if(!n.operations.add)throw new r("invalid-abilities","addAttachment(): add abilities are required.");if(!e||"function"!=typeof e.addAttachment)throw new r("invalid-layer","addAttachment(): A valid layer is required.");const s=e.addAttachment(i,t).then((t=>this._queryAttachment(t.objectId))),o=await s;return a.add(o),o}async deleteAttachment(t){const{_attachmentLayer:e,attachmentInfos:a,graphic:i,abilities:n}=this;if(!t)throw new r("invalid-attachment-info","deleteAttachment(): An attachmentInfo is required.",{attachmentInfo:t});if(!n.operations.delete)throw new r("invalid-abilities","deleteAttachment(): delete abilities are required.");if(!e||"function"!=typeof e.deleteAttachments)throw new r("invalid-layer","deleteAttachment(): A valid layer is required.");const s=e.deleteAttachments(i,[t.id]).then((()=>t)),o=await s;return a.remove(o),o}async updateAttachment(t,e=this.activeAttachmentInfo){const{_attachmentLayer:a,attachmentInfos:i,graphic:n,abilities:s}=this;if(!t)throw new r("invalid-attachment","updateAttachment(): An attachment is required.",{attachment:t});if(!e)throw new r("invalid-attachment-info","updateAttachment(): An attachmentInfo is required.",{attachmentInfo:e});if(!s.operations.update)throw new r("invalid-abilities","updateAttachment(): Update abilities are required.");const o=i.findIndex((t=>t===e));if(!a||"function"!=typeof a.updateAttachment)throw new r("invalid-layer","updateAttachment(): A valid layer is required.");const c=a.updateAttachment(n,e.id,t).then((t=>this._queryAttachment(t.objectId))),h=await c;return i.splice(o,1,h),h}async _queryAttachment(t){if(!t)throw new r("invalid-attachment-id","Could not query attachment.");const{_attachmentLayer:e}=this,a=this._getFeatureId(),i=new l({objectIds:[a],attachmentsWhere:`AttachmentId=${t}`,returnMetadata:!0});return e.queryAttachments(i).then((t=>t[a][0]))}_getFeatureId(){const{_attachmentLayer:t,graphic:e}=this;if(!t||!e)return null;const{objectIdField:a}=t,{attributes:i}=e;return i&&i[a]}_graphicChanged(){this.graphic&&(this._setAttachmentLayer(),this.getAttachments().catch((()=>{})))}_setAttachmentLayer(){const{graphic:t}=this,e=p(t);this._attachmentLayer=e?"scene"===e.type&&n(e.associatedLayer)?e.associatedLayer:e:null}};t([c()],f.prototype,"abilities",void 0),t([h("abilities")],f.prototype,"castAbilities",null),t([c()],f.prototype,"activeAttachmentInfo",void 0),t([c({readOnly:!0,type:y})],f.prototype,"attachmentInfos",void 0),t([c({type:e})],f.prototype,"graphic",void 0),t([c()],f.prototype,"mode",void 0),t([c({readOnly:!0})],f.prototype,"state",null),t([c({readOnly:!0})],f.prototype,"supportsResizeAttachments",null),f=t([d("esri.widgets.Attachments.AttachmentsViewModel")],f);const g=f;export{g as default};
|