UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 5.72 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import{isNone as s}from"../../../core/maybe.js";import{isAbortError as t}from"../../../core/promiseUtils.js";import{property as r}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import o from"../../../portal/Portal.js";import i from"../../Widget.js";import"../../support/widgetUtils.js";import{messageBundle as l}from"../../support/decorators/messageBundle.js";import{tsx as n}from"../../support/jsxFactory.js";const c="esri-save-layer",m={panel:`${c}`,error:`${c}__error`,errorIcon:`${c}__error-icon`,errorLabel:`${c}__error-label`,layerNameLabel:`${c}__layer-name-label`,portalFolderLabel:`${c}__portal-folder-label`,processLabel:`${c}__process-label`,processLoader:`${c}__process-loader`};let p=class extends i{constructor(e,s){super(e,s),this._folders=null,this._layer=null,this._userName=null,this.messages=null,this.messagesCommon=null,this.messagesIdentity=null,this.opened=!1,this.state="initialized",this.close=()=>{this.opened=!1,this.state="initialized"}}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-combobox.js"),import("@esri/calcite-components/dist/components/calcite-combobox-item.js"),import("@esri/calcite-components/dist/components/calcite-icon.js"),import("@esri/calcite-components/dist/components/calcite-input.js"),import("@esri/calcite-components/dist/components/calcite-label.js"),import("@esri/calcite-components/dist/components/calcite-loader.js"),import("@esri/calcite-components/dist/components/calcite-panel.js")])}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}async open(e){this.state="initialized",this.opened=!0,this._layer=e,this.state="connect-to-portal";const s=o.getDefault();try{await s.signIn()}catch(a){return void(t(a)||"identity-manager:user-aborted"===a.name?this.close():this.state="connect-to-portal-error")}this.state="fetch-portal-information";const{user:r}=s;this._userName=r.username;try{this._folders=await r.fetchFolders()}catch{return void(this.state="fetch-portal-information-error")}this.state="save-layer"}render(){switch(this.state){case"initialized":return this._renderInitialized();case"connect-to-portal":return this._renderProcess(this.messagesIdentity.lblSigning);case"connect-to-portal-error":return this._renderError(this.messages.errors.authenticating);case"fetch-portal-information":return this._renderProcess(this.messages.processing.fetching);case"fetch-portal-information-error":return this._renderError(this.messages.errors.fetching);case"save-layer":return this._renderSaveLayer();case"saving":return this._renderProcess(this.messages.processing.saving);case"saving-error":return this._renderError(this.messages.errors.saving)}}_renderError(e){return n("calcite-panel",{class:m.panel,heading:this.messages.widgetLabel,key:`${c}-error-panel`},n("div",{class:m.error},n("calcite-icon",{class:m.errorIcon,icon:"exclamation-mark-triangle",scale:"l",textLabel:this.messagesCommon.errorMessage}),n("calcite-label",{class:m.errorLabel},e)),n("calcite-button",{appearance:"outline",onclick:this.close,slot:"footer-actions",width:"half"},this.messagesCommon.close))}_renderInitialized(){return n("calcite-panel",{class:m.panel,heading:this.messages.widgetLabel,key:`${c}-initialize-panel`})}_renderProcess(e){return n("calcite-panel",{class:m.panel,heading:this.messages.widgetLabel,key:`${c}-process-panel`},n("calcite-loader",{class:m.processLoader,label:e}),n("calcite-label",{class:m.processLabel,alignment:"center"},e))}_renderSaveLayer(){if(s(this._layer)||s(this._folders)||s(this._userName))return this._renderInitialized();const{stops:e}=this._layer,t=`${e.getItemAt(0).name} - ${e.getItemAt(e.length-1).name}`,r=this._folders.map((e=>n("calcite-combobox-item",{key:`${c}-folder-${e.id}`,textLabel:e.title,value:e.id})));return r.unshift(n("calcite-combobox-item",{key:`${c}-folder-home`,selected:!0,textLabel:`${this._userName} (${this.messagesCommon.home})`,value:null})),n("calcite-panel",{class:m.panel,heading:this.messages.widgetLabel,key:`${c}-save-panel`},n("calcite-label",{class:m.layerNameLabel},this.messages.laverName,n("calcite-input",{afterCreate:e=>{this._layerNameInput=e},label:this.messages.laverName,value:t})),n("calcite-label",{class:m.portalFolderLabel},this.messages.saveInFolder,n("calcite-combobox",{afterCreate:e=>{this._portalFolderCombobox=e},label:this.messages.saveInFolder,overlayPositioning:"fixed",selectionMode:"single"},r)),n("calcite-button",{onclick:()=>this._saveButtonClick(),slot:"footer-actions",width:"half"},this.messagesCommon.save),n("calcite-button",{appearance:"outline",onclick:()=>{this.close()},slot:"footer-actions",width:"half"},this.messagesCommon.cancel))}_saveButtonClick(){this.state="saving",this._saveLayer().then((()=>{this.close()})).catch((()=>{this.state="saving-error"}))}async _saveLayer(){if(s(this._layer)||s(this._folders))return;const e=this._layerNameInput.value,t=this._portalFolderCombobox.value,r=this._folders.find((e=>e.id===t));await this._layer.saveAs({title:e},{folder:r})}};e([r()],p.prototype,"label",null),e([r(),l("esri/widgets/support/t9n/SaveLayer")],p.prototype,"messages",void 0),e([r(),l("esri/t9n/common")],p.prototype,"messagesCommon",void 0),e([r(),l("esri/identity/t9n/identity")],p.prototype,"messagesIdentity",void 0),e([r()],p.prototype,"opened",void 0),e([r()],p.prototype,"state",void 0),p=e([a("esri.widgets.Directions.SaveLayer")],p);export{p as SaveLayer};