@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.59 kB
JavaScript
import{_ as t}from"../chunks/tslib.es6.js";import r from"../core/Error.js";import{JSONSupport as e}from"../core/JSONSupport.js";import{property as o}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import s from"./PortalFolder.js";import n from"./PortalGroup.js";var i;let u=i=class extends e{constructor(...t){super(...t),this.access=null,this.created=null,this.culture=null,this.description=null,this.email=null,this.fullName=null,this.modified=null,this.orgId=null,this.portal=null,this.preferredView=null,this.privileges=null,this.region=null,this.role=null,this.roleId=null,this.sourceJSON=null,this.units=null,this.username=null,this.userType=null}get thumbnailUrl(){const t=this.url,r=this.thumbnail;return t&&r?this.portal.normalizeUrl(`${t}/info/${r}?f=json`):null}get userContentUrl(){const t=this.get("portal.restUrl");return t?`${t}/content/users/${this.username}`:null}get url(){const t=this.get("portal.restUrl");return t?`${t}/community/users/${this.username}`:null}addItem(t){const r=t&&t.item,e=t&&t.data,o=t&&t.folder,l={method:"post"};r&&(l.query=r.createPostQuery(),null!=e&&("string"==typeof e?l.query.text=e:"object"==typeof e&&(l.query.text=JSON.stringify(e))));let s=this.userContentUrl;return o&&(s+="/"+("string"==typeof o?o:o.id)),this.portal.request(s+"/addItem",l).then((t=>(r.id=t.id,r.portal=this.portal,r.loaded?r.reload():r.load())))}deleteItem(t){let r=this.userContentUrl;return t.ownerFolder&&(r+="/"+t.ownerFolder),this.portal.request(r+`/items/${t.id}/delete`,{method:"post"}).then((()=>{t.id=null,t.portal=null}))}deleteItems(t){const r=this.userContentUrl+"/deleteItems",e=t.map((t=>t.id));if(e.length){const o={method:"post",query:{items:e.join(",")}};return this.portal.request(r,o).then((()=>{t.forEach((t=>{t.id=null,t.portal=null}))}))}return Promise.resolve(void 0)}fetchFolders(){const t={query:{num:1}};return this.portal.request(this.userContentUrl??"",t).then((t=>{let r;return r=t&&t.folders?t.folders.map((t=>{const r=s.fromJSON(t);return r.portal=this.portal,r})):[],r}))}fetchGroups(){return this.portal.request(this.url??"").then((t=>{let r;return r=t&&t.groups?t.groups.map((t=>{const r=n.fromJSON(t);return r.portal=this.portal,r})):[],r}))}fetchItems(t){const r=t??{};let e,o=this.userContentUrl??"";return r.folder&&(o+="/"+r.folder.id),import("./PortalItem.js").then((({default:t})=>{e=t;const l={folders:!1,num:r.num||10,start:r.start||1,sortField:r.sortField||"created",sortOrder:r.sortOrder||"asc"};return this.portal.request(o,{query:l})})).then((t=>{let r;return t&&t.items?(r=t.items.map((t=>{const r=e.fromJSON(t);return r.portal=this.portal,r})),Promise.all(r.map((t=>t.load()))).catch((t=>t)).then((()=>({items:r,nextStart:t.nextStart,total:t.total})))):{items:[],nextStart:-1,total:0}}))}fetchTags(){return this.portal.request(this.url+"/tags").then((t=>t.tags))}getThumbnailUrl(t){let r=this.thumbnailUrl;return r&&t&&(r+=`&w=${t}`),r}queryFavorites(t){return this.favGroupId?(this._favGroup||(this._favGroup=new n({id:this.favGroupId,portal:this.portal})),this._favGroup.queryItems(t)):Promise.reject(new r("internal:unknown","Unknown internal error",{internalError:"Unknown favGroupId"}))}toJSON(){throw new r("internal:not-yet-implemented","PortalGroup.toJSON is not yet implemented")}static fromJSON(t){if(!t)return null;if(t.declaredClass)throw new Error("JSON object is already hydrated");const r=new i;return r.sourceJSON=t,r.read(t),r}};t([o()],u.prototype,"access",void 0),t([o({type:Date})],u.prototype,"created",void 0),t([o()],u.prototype,"culture",void 0),t([o()],u.prototype,"description",void 0),t([o()],u.prototype,"email",void 0),t([o()],u.prototype,"favGroupId",void 0),t([o()],u.prototype,"fullName",void 0),t([o({type:Date})],u.prototype,"modified",void 0),t([o()],u.prototype,"orgId",void 0),t([o()],u.prototype,"portal",void 0),t([o()],u.prototype,"preferredView",void 0),t([o()],u.prototype,"privileges",void 0),t([o()],u.prototype,"region",void 0),t([o()],u.prototype,"role",void 0),t([o()],u.prototype,"roleId",void 0),t([o()],u.prototype,"sourceJSON",void 0),t([o()],u.prototype,"thumbnail",void 0),t([o({readOnly:!0})],u.prototype,"thumbnailUrl",null),t([o()],u.prototype,"units",void 0),t([o({readOnly:!0})],u.prototype,"userContentUrl",null),t([o({readOnly:!0})],u.prototype,"url",null),t([o()],u.prototype,"username",void 0),t([o()],u.prototype,"userType",void 0),u=i=t([l("esri.portal.PortalUser")],u);const p=u;export{p as default};