12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import"../../intl.js";import s from"../../core/Collection.js";import{HandleOwnerMixin as i}from"../../core/HandleOwner.js";import r from"../../core/Handles.js";import{isSome as o}from"../../core/maybe.js";import{debounce as l,ignoreAbortErrors as n}from"../../core/promiseUtils.js";import{on as a,watch as h}from"../../core/reactiveUtils.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as m}from"../../core/accessorSupport/decorators/subclass.js";import{highlightsSupported as g}from"../../views/support/layerViewUtils.js";import c from"./AttachmentsColumn.js";import u from"./FieldColumn.js";import p from"./Grid/Column.js";import y from"./Grid/Grid.js";import f from"./Grid/GridViewModel.js";import b from"./Grid/GroupColumn.js";import _ from"./support/FeatureStore.js";import"../support/widgetUtils.js";import{messageBundle as w}from"../support/decorators/messageBundle.js";import{onLocaleChange as I}from"../../intl/locale.js";import{fetchMessageBundle as E}from"../../intl/messages.js";let v=class extends(i(f)){constructor(e){super(e),this._debounceRefresh=l((()=>this._refresh())),this._defaultHiddenFields=["CreationDate","Creator","EditDate","Editor","GlobalID"],this._highlights=new r,this.activeFilters=new s,this.autoRefreshEnabled=!0,this.cellClassNameGenerator=(e,t)=>e.path||null,this.columns=new s,this.dataProvider=async(e,t)=>{const{store:s}=this,{page:i,pageSize:r,sortOrders:o}=e,l=this._sortOrdersToLayerOrderByFields(o);t&&(s?(await s.set({orderByFields:l}),"loaded"!==s.state&&"loading"!==s.state&&await s.load(),t&&t(await s.fetchItems({page:i,pageSize:r}))):t&&t([]))},this.editingEnabled=!1,this.fieldConfigs=null,this.grid=null,this.highlightEnabled=!0,this.itemIdPath="objectId",this.messagesCommon=null,this.messagesURIUtils=null,this.relatedRecordsEnabled=!1,this.store=null,this.tableTemplate=null,this.view=null;const{hiddenFields:t,itemIdPath:i}=this;t.addMany(this._defaultHiddenFields),this._onLayerRefresh=this._onLayerRefresh.bind(this),this._set("store",new _),this._set("grid",new y({itemIdPath:i,viewModel:this}))}initialize(){const e=async()=>{this.messages=await E("esri/widgets/FeatureTable/t9n/FeatureTable"),this.messagesCommon=await E("esri/t9n/common"),this.messagesURIUtils=await E("esri/widgets/support/t9n/uriUtils")};e(),this.handles.add([I((()=>{e(),this._generateColumns()})),a((()=>this.highlightIds),"change",(e=>this._onHighlightIdsChange(e)),{onListenerAdd:()=>{this.highlightIds.forEach((e=>this._highlight(e)))},onListenerRemove:()=>{this.highlightIds.forEach((e=>this._unhighlight(e)))}}),h((()=>this.layerView),(()=>{this._highlights.removeAll(),this.layerView&&this.highlightEnabled&&this.highlightIds?.forEach((e=>this._highlight(e)))})),h((()=>this.highlightEnabled),(()=>{this._highlights.removeAll(),this.highlightEnabled&&this.highlightIds?.forEach((e=>this._highlight(e)))})),h((()=>this.relatedRecordsEnabled),(e=>this.store.relatedRecordsEnabled=e)),h((()=>this.layer?.loaded),(e=>e&&this._onLayerLoad())),h((()=>this.store.state),(e=>{"loaded"===e&&this.grid?.scrollToTop()})),h((()=>[this.messages,this.tableTemplate,this.fieldConfigs]),(()=>this.layer?.loaded&&this._generateColumns())),h((()=>this.editingEnabled),(e=>this.columns.forEach((t=>{"editingEnabled"in t&&(t.editingEnabled=e)})))),h((()=>this.layer?.definitionExpression),((e,t)=>(e||t)&&"loaded"===this.store.state&&this.reset())),h((()=>this.layer&&"timeExtent"in this.layer&&this.layer.timeExtent),((e,t)=>(e||t)&&!this.timeExtent&&"loaded"===this.store.state&&this.reset())),a((()=>this.layer),"refresh",(e=>this._onLayerRefresh(e)))])}destroy(){this._resetColumns(),this.handles.removeAll(),this._highlights.removeAll(),this._highlights.destroy(),this.grid?.destroy(),this.columns?.destroy(),this.layer=null,this.view=null}get activeSortOrders(){return this.grid?.sortOrders?this.grid.sortOrders.map((({path:e,direction:t})=>({fieldName:e,direction:t}))):[]}set attachmentsEnabled(e){this.attachmentsEnabled!==e&&(this._set("attachmentsEnabled",e),this._generateColumns(),this.store.attachmentsEnabled=e)}set filterGeometry(e){if(!this.filterGeometry&&!e)return;const t=this.activeFilters.find((e=>"geometry"===e.type));t&&this.activeFilters.remove(t),this._set("filterGeometry",e),this.store.filterGeometry=e,e&&this.activeFilters.add({type:"geometry",geometry:e})}get hiddenFields(){return this._get("hiddenFields")||new s}set hiddenFields(e){Array.isArray(e)?this._set("hiddenFields",new s(e)):this._set("hiddenFields",e)}get highlightOnRowSelectEnabled(){return this.highlightEnabled}set highlightOnRowSelectEnabled(e){this.highlightEnabled=e}set layer(e){this._set("layer",e),this.grid?.clearSort(),this._resetColumns(),this.store.layer=e,e&&(e.loaded?this._onLayerLoad():e.load()),this.notifyChange("state")}get layerView(){return this.view?.allLayerViews.find((e=>e.layer===this.layer))||null}set messages(e){this.grid?.set("messages",e),this._set("messages",e)}get state(){const{store:e}=this;return e&&"disabled"!==e.state?"loading"===e.state?"loading":"loaded"===e.state?"loaded":"ready":"disabled"}set timeExtent(e){this._set("timeExtent",e),this.store.timeExtent=e}clearHighlights(){this._highlights.removeAll()}clearSelection(){this.grid?.clearSelection()}async deleteSelection(){const e=this.highlightIds.toArray();if(!e?.length)return;const{deleteFeatureResults:t}=await this.store.deleteRowsByObjectId(e),s=t.filter((e=>!e.error)).map((e=>e.objectId));s.length&&(this.deselectRows(s),await this.refresh())}deselectRows(e){const t=this._getStoreItemsFromSelectionParams(e);this.grid.deselectRows(t)}filterBySelection(){const e=this.highlightIds.toArray();e.length&&(this.clearSelectionFilter(),this.store.objectIds=e,this.activeFilters.add({type:"selection",objectIds:e}))}getObjectIdIndex(e){return this.store?.getObjectIdIndex(e)}getValue(e,t){return this.store.getItemByObjectId(e)?.feature?.attributes[t]}get highlightIds(){return this._get("highlightIds")||new s}set highlightIds(e){Array.isArray(e)?this._set("highlightIds",new s(e)):this._set("highlightIds",e)}async refresh(){return n(this._debounceRefresh())}reset(){this.grid.reset()}selectRows(e){const t=this._getStoreItemsFromSelectionParams(e);return this.grid.selectRows(t)}scrollToIndex(e){this.grid?.scrollToIndex(e)}clearSelectionFilter(){this.store.objectIds=null;const e=this.activeFilters.find((e=>"selection"===e.type));e&&this.activeFilters.remove(e)}zoomToSelection(){const{layer:e,view:t}=this,s=this.highlightIds.toArray();if(!e||!t||!s.length)return;const i=e.createQuery();i.objectIds=s,i.returnGeometry=!0,e.queryFeatures(i).then((e=>{t.goTo(e.features).catch((e=>{"AbortError"!==e.name&&console.error(e)}))}))}async _refresh(){await this.store.refreshLayerInfo();const e=this.highlightIds.toArray();if(e.length){(await this.store.verifyFeaturesByObjectId(e)).forEach(((t,s)=>{t||this.deselectRows(e[s])}))}this.grid.refreshPageCache()}_onLayerLoad(){const e=this.layer.capabilities.query.maxRecordCount;e&&e<this.pageSize&&this.grid&&(this.grid.pageSize=e),this._generateColumns()}_onLayerRefresh(e){this.autoRefreshEnabled&&e.dataChanged&&this.refresh()}_generateColumns(){this._resetColumns();const e=[],t=this.tableTemplate?.columnTemplates?this._generateColumnsFromTemplates(this.tableTemplate.columnTemplates):this.fieldConfigs?.length?this._generateColumnsFromConfigs():this._generateDefaultFieldColumns();e.push(...t),this.attachmentsEnabled&&e.push(this._generateDefaultAttachmentColumn()),this.columns.addMany([...e])}_generateColumnsFromTemplates(e){const{editingEnabled:t,grid:s,hiddenFields:i,layer:r,messages:o,messagesCommon:l,messagesURIUtils:n,store:a,tableTemplate:h}=this,d=this.layer?.fields??[];return e.filter((e=>(d||[]).find((t=>"fieldName"in e&&e.fieldName===t.name))||"group"===e.type&&"columnTemplates"in e)).map((e=>{if("fieldName"in e){const m=(d||[]).find((t=>e.fieldName===t.name)),g=!1===e.visible||!0!==e.visible&&i.includes(m.name),{direction:c,formatFunction:p,initialSortPriority:y,menuConfig:f,textAlign:b}=e,_=h.expressionInfos||null;return new u({direction:c,editingEnabled:t,expressionInfos:_,field:m,formatFunction:p,grid:s,hidden:g,initialSortPriority:y,layer:r,messages:o,messagesCommon:l,messagesURIUtils:n,menuConfig:f,store:a,template:e,textAlign:b})}if("group"===e.type&&"columnTemplates"in e){const t=this._generateColumnsFromTemplates(e.columnTemplates),s=!1===e.visible||!0!==e.visible&&i.includes(e.label),{label:r}=e;return new b({header:r,columns:t,hidden:s})}return new p({...e})}))}_generateColumnsFromConfigs(){const{editingEnabled:e,fieldConfigs:t,grid:s,hiddenFields:i,layer:r,messages:l,messagesCommon:n,messagesURIUtils:a,store:h}=this,d=this.layer?.fields??[];return t.filter((e=>(d||[]).find((t=>e.name===t.name)))).map((t=>{const m=t.direction||null,g=t.formatFunction||null,c=t.textAlign||null,p=o(t.initialSortPriority)?t.initialSortPriority:null,y=(d||[]).find((e=>t.name===e.name)),f=!1===t.visible||!0!==t.visible&&i.includes(y.name),b=t.menuConfig||null;return new u({config:t,direction:m,editingEnabled:e,field:y,formatFunction:g,grid:s,hidden:f,layer:r,store:h,messages:l,messagesCommon:n,messagesURIUtils:a,menuConfig:b,textAlign:c,initialSortPriority:p})}))}_generateDefaultFieldColumns(){const{editingEnabled:e,grid:t,hiddenFields:s,layer:i,messages:r,messagesCommon:o,messagesURIUtils:l,store:n}=this;return(this.layer?.fields??[]).map((a=>{const h=s.includes(a.name);return new u({editingEnabled:e,field:a,grid:t,hidden:h,layer:i,store:n,messages:r,messagesCommon:o,messagesURIUtils:l})}))}_generateDefaultAttachmentColumn(){return new c({header:this.messages?.attachments})}_sortOrdersToLayerOrderByFields(e){return e&&e.length?e.filter(((e,t,s)=>s.map((e=>e.path)).indexOf(e.path)===t)).filter((({direction:e})=>!!e)).map((({direction:e,path:t})=>t+" "+e.toUpperCase())):[]}_highlight(e){this.layerView&&g(this.layerView)&&this._highlights.add(this.layerView.highlight(e),e)}_unhighlight(e){this._highlights.remove(e)}_getStoreItemsFromSelectionParams(e){const s=[];return(e=e instanceof Array?e:[e]).forEach((e=>{let i=e instanceof t?e:null;const r=i?i.getObjectId():e;if("number"==typeof r||"string"==typeof r){if(!i){const e=this.store.getItemByObjectId(r);e&&(i=e.feature)}s.push({objectId:r,feature:i})}})),s}_onHighlightIdsChange(e){const{highlightEnabled:t}=this,{added:s,removed:i}=e;t&&(s.forEach((e=>this._highlight(e))),i.forEach((e=>this._unhighlight(e))))}_resetColumns(){this.columns.items.forEach((e=>e.destroy())),this.columns.removeAll()}};e([d({readOnly:!0})],v.prototype,"activeFilters",void 0),e([d({readOnly:!0})],v.prototype,"activeSortOrders",null),e([d()],v.prototype,"attachmentsEnabled",null),e([d()],v.prototype,"autoRefreshEnabled",void 0),e([d()],v.prototype,"cellClassNameGenerator",void 0),e([d({readOnly:!0})],v.prototype,"columns",void 0),e([d()],v.prototype,"dataProvider",void 0),e([d()],v.prototype,"editingEnabled",void 0),e([d()],v.prototype,"fieldConfigs",void 0),e([d()],v.prototype,"filterGeometry",null),e([d({readOnly:!0})],v.prototype,"grid",void 0),e([d()],v.prototype,"hiddenFields",null),e([d()],v.prototype,"highlightEnabled",void 0),e([d()],v.prototype,"highlightOnRowSelectEnabled",null),e([d({readOnly:!0})],v.prototype,"itemIdPath",void 0),e([d()],v.prototype,"layer",null),e([d()],v.prototype,"layerView",null),e([d()],v.prototype,"messages",null),e([d(),w("esri/t9n/common")],v.prototype,"messagesCommon",void 0),e([d(),w("esri/widgets/support/t9n/uriUtils")],v.prototype,"messagesURIUtils",void 0),e([d()],v.prototype,"relatedRecordsEnabled",void 0),e([d({readOnly:!0})],v.prototype,"state",null),e([d({readOnly:!0,type:_})],v.prototype,"store",void 0),e([d()],v.prototype,"tableTemplate",void 0),e([d()],v.prototype,"timeExtent",null),e([d()],v.prototype,"view",void 0),e([d()],v.prototype,"highlightIds",null),v=e([m("esri.widgets.FeatureTable.FeatureTableViewModel")],v);const C=v;export{C as default};
|