UNPKG

@arcgis/map-components

Version:
261 lines (260 loc) 13.1 kB
import { c as S } from "../../chunks/runtime.js"; import { html as g } from "lit-html"; import { once as _, watch as y } from "@arcgis/core/core/reactiveUtils.js"; import P from "@arcgis/core/widgets/VersionManagement/VersionManagementViewModel.js"; import { LitElement as F, createEvent as w, noShadowRoot as M, safeClassMap as N } from "@arcgis/lumina"; import { createRef as k, ref as C } from "lit-html/directives/ref.js"; import { u as b } from "../../chunks/useT9n.js"; import { m as $ } from "../../chunks/useViewModel.js"; import { css as A } from "@lit/reactive-element/css-tag.js"; /*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. v4.32.13 */ const T = A`@layer{.initial-version-invalid-block{margin-bottom:1rem}.calcite-combobox-item{width:330px}.calcite-flow-widget{width:350px}calcite-block{margin:0}calcite-pagination{justify-content:center}}`, x = $(P), u = "map-components:version-management"; class D extends F { constructor() { super(...arguments), this.flowElement = k(), this.messages = b({ blocking: !0 }), this.viewModel = x(this), this._isInitialVersionInvalid = /* @__PURE__ */ new Map(), this._initialVersionInfos = [], this._showInvalidFeatureServiceNotice = !1, this.allowEditingDisabled = !1, this.autoDestroyDisabled = !1, this.closable = !1, this.pageSize = 5, this.position = "top-right", this.state = this.viewModel.state, this.versioningStates = this.viewModel.versioningStates, this.view = this.viewModel.view, this.arcgisReady = w(), this.arcgisVersioningStateChanged = w(); } static { this.properties = { versionList: 16, _showInvalidFeatureServiceNotice: 16, allowEditingDisabled: 5, autoDestroyDisabled: 5, closable: 7, initialVersionInfos: 0, icon: 3, label: 3, messageOverrides: 0, mode: 1, pageSize: 9, position: 1, referenceElement: 1, state: 3, versioningStates: 0, view: 0 }; } static { this.styles = T; } static { this.shadowRootOptions = M; } get initialVersionInfos() { return this._initialVersionInfos; } /** * The `initialVersionInfos` property enables users to initialize the Version Management Component with a predefined set of versions. * By providing an array of `InitialVersionInfo`, the component displays a specified version for each feature service upon initialization. */ set initialVersionInfos(e) { this._initialVersionInfos = e.map((i) => ({ ...i, url: this._removeTrailingSlash(i.url) })); } //#endregion //#region Public Methods /** Permanently destroy the component */ async destroy() { await this.manager.destroy(); } //#endregion //#region Lifecycle async load() { _(() => this.viewModel.state === "ready").then(() => { this.initialVersionInfos.forEach((e) => { try { this._changeToInitialVersion(e); } catch (i) { console.error(i); } }); }), this.manager.onLifecycle(() => [ y(() => this.viewModel.state, (e) => { const { flowElement: { value: i }, versionList: t } = this, s = i?.getElementsByTagName("arcgis-version-management-version-properties")[0]; if (e === "disabled" && i) { s && this._removeVersionPropertiesFlowItem(i), t && this._removeVersionListFlowItem(i); return; } t && (t.versionListElementProps = { ...t.versionListElementProps, executionError: this.viewModel.executionError }, t.versionListElementProps = { ...t.versionListElementProps, state: e }), s && (s.versionPropertiesElementProps = { ...s.versionPropertiesElementProps, state: e }); }) ]); } //#endregion //#region Private Methods _removeTrailingSlash(e) { return e.replace(/\/+$/u, ""); } _createVersionPropertiesFlowItem(e, i) { const { closable: t, flowElement: { value: s }, viewModel: n, viewModel: { state: l } } = this, o = document.createElement("arcgis-version-management-version-properties"); return o.versionPropertiesElementProps = { closable: t, currentUser: n.userLookup.get(e), hasAdvEditingUte: n.advancedEditingUserTypeExtensionLookup.get(e), isVersionAdministrator: n.versionAdministratorLookup.get(e), serviceUrl: e, state: l, strings: this.messages, versionInfo: i }, o.selected = !0, o.showBackButton = !0, o.addEventListener("arcgisCreateVersion", (r) => { const { createVersionParameters: d, switchToVersion: v } = r.detail; n.createVersion(d).then(async (a) => { a && this.arcgisVersioningStateChanged.emit({ type: "version-created", versionIdentifier: a.versionIdentifier, versioningState: n.versioningStateLookup.get(e) }), v && await this.viewModel.changeVersion(e, a.versionIdentifier.name, a.versionIdentifier.guid).then((h) => { h && this.arcgisVersioningStateChanged.emit({ type: "version-switched", versionIdentifier: a.versionIdentifier, versioningState: n.versioningStateLookup.get(e) }); }), await this._refreshVersionList(e); }).finally(() => { s && this._removeVersionPropertiesFlowItem(s); }); }), o.addEventListener("arcgisAlterVersion", async (r) => { const { flowElement: { value: d } } = this, { alterVersionParameters: v } = r.detail; await n.alterVersion(v).then(async (a) => { a && this.arcgisVersioningStateChanged.emit({ type: "version-changed", versionIdentifier: v.versionIdentifier, versioningState: n.versioningStateLookup.get(e) }), await this._refreshVersionList(e); }).finally(() => { d && this._removeVersionPropertiesFlowItem(d); }); }), o.addEventListener("arcgisFlowItemBack", () => { this._removeVersionPropertiesFlowItem(this.flowElement.value); }), o.addEventListener("calciteFlowItemBack", (r) => { r.preventDefault(), this._removeVersionPropertiesFlowItem(this.flowElement.value), this.versionList && (this.versionList.selected = !0); }), o.addEventListener("calciteFlowItemClose", () => { this._handleFlowItemClose(); }), o; } _getLoadError(e) { const { messages: i } = this; switch (e) { case "no-feature-services": return i.loadErrors.noFeatureServices; case "no-view-property": return i.loadErrors.noViewProperty; default: return e; } } _changeToInitialVersion(e) { const { _isInitialVersionInvalid: i, viewModel: t } = this, { url: s, name: n } = e, l = t.versioningStateLookup.get(s); if (!l) throw this._showInvalidFeatureServiceNotice = !0, new Error(`${u} - no versioning state found for feature service ${s}`); const o = l?.versionInfos.find((v) => v.versionIdentifier.name === n); if (!o) throw i.set(s, !0), new Error(`${u} - version ${n} not found in the versioning state for feature service ${s}`); const r = o.versionIdentifier, d = l?.currentVersionInfo?.versionIdentifier; r.guid !== d?.guid && t.changeVersion(s, r.name, r.guid); } _handleFlowItemClose() { const e = document.querySelector("arcgis-version-management"); e.parentElement?.removeChild(e); } async _handleNewVersionAction(e) { const i = this._createVersionPropertiesFlowItem(e.detail.serviceUrl, void 0); this.flowElement.value?.appendChild(i), this.versionList && (this.versionList.selected = !1); } async _handleManageVersionAction(e) { const { actionType: i, serviceUrl: t, versionInfo: s } = e.detail, { viewModel: n, flowElement: l } = this; switch (i) { case "changeVersion": { n.changeVersion(t, s.versionIdentifier.name, s.versionIdentifier.guid).then((o) => { o && this.arcgisVersioningStateChanged.emit({ type: "version-switched", versionIdentifier: s.versionIdentifier, versioningState: n.versioningStateLookup.get(t) }); const { versionList: r } = this; r && (r.versionListElementProps = { ...r.versionListElementProps, currentVersionIdentifier: n.versioningStateLookup.get(t).currentVersionInfo.versionIdentifier }); }); break; } case "deleteVersion": { n.deleteVersion(t, s.versionIdentifier.name, s.versionIdentifier.guid).then(async (o) => { o && this.arcgisVersioningStateChanged.emit({ type: "version-deleted", versionIdentifier: s.versionIdentifier, versioningState: n.versioningStateLookup.get(t) }), await this._refreshVersionList(t); }); break; } case "editVersion": { const o = this._createVersionPropertiesFlowItem(t, s); l.value?.appendChild(o), this.versionList && (this.versionList.selected = !1); break; } } } async _refreshVersionList(e) { const { flowElement: { value: i }, versionList: t, viewModel: s } = this; if (i) { const n = await s.getVersionInfos(e), l = i.getElementsByTagName("arcgis-version-management-service-item"); for (const o of l) o.serviceItemElementProps.serviceUrl === e && (o.serviceItemElementProps = { ...o.serviceItemElementProps, versionInfos: n }); t && (t.versionListElementProps = { ...t.versionListElementProps, currentVersionIdentifier: s.versioningStateLookup.get(e).currentVersionInfo.versionIdentifier, versionInfos: n }); } } _removeVersionListFlowItem(e) { for (const i of e.childNodes) i.nodeName.toUpperCase() === "ARCGIS-VERSION-MANAGEMENT-VERSION-LIST" && (e.removeChild(i), this.versionList = void 0), i.nodeName.toUpperCase() === "CALCITE-FLOW-ITEM" && (i.hidden = !1); } _removeVersionPropertiesFlowItem(e) { for (const i of e.childNodes) i.nodeName.toUpperCase() === "ARCGIS-VERSION-MANAGEMENT-VERSION-PROPERTIES" && e.removeChild(i); } //#endregion //#region Rendering render() { const { allowEditingDisabled: e, closable: i, flowElement: { value: t }, initialVersionInfos: s, _isInitialVersionInvalid: n, label: l, messages: o, mode: r, pageSize: d, versionList: v, viewModel: a, viewModel: { loadError: h, state: m } } = this, I = Array.from(a.serviceNameLookup, ([c, f]) => ({ url: c, name: f })), V = m !== "disabled" ? I.map((c) => { const f = { allowEditing: !e, closable: i, currentUser: a.userLookup.get(c.url), currentVersionIdentifier: a.versioningStateLookup.get(c.url).currentVersionInfo.versionIdentifier, executionError: void 0, flowElement: t, hasAdvEditingUte: a.advancedEditingUserTypeExtensionLookup.get(c.url), heading: l, initialVersionInfos: s, isInitialVersionInvalid: n, isVersionAdministrator: a.versionAdministratorLookup.get(c.url), isVersioningApiAvailable: (a.serverVersionLookup.get(c.url) ?? 0) >= 11.2, mode: r, pageSize: d, serviceName: c.name, state: m, serviceUrl: c.url, strings: o, versionInfos: a.versioningStateLookup.get(c.url)?.versionInfos ?? [] }; return g`<arcgis-version-management-service-item .serviceItemElementProps=${f} @arcgisGetVersions=${async (p) => { await this._refreshVersionList(p.detail.serviceUrl); }} @arcgisFlowItemBack=${() => { t && (this._removeVersionListFlowItem(t), this.versionList = void 0); }} @arcgisFlowItemClose=${() => { this._handleFlowItemClose(); }} @arcgisManageVersion=${this._handleManageVersionAction} @arcgisNewVersion=${this._handleNewVersionAction} @arcgisCreateVersionList=${(p) => { this.versionList = p.detail; }}></arcgis-version-management-service-item>`; }) : void 0, E = m === "disabled" && h != null ? g`<calcite-notice class="notice" kind=warning open scale=s slot=footer width=full><div slot=message>${this._getLoadError(h)}</div></calcite-notice>` : void 0, L = this._showInvalidFeatureServiceNotice ? g`<calcite-notice closable kind=warning open scale=s slot=content-top width=full icon @calciteNoticeClose=${() => this._showInvalidFeatureServiceNotice = !1}><div slot=title>${o.headers.invalidInitialFeatureService}</div><div slot=message>${o.loadErrors.invalidInitialFeatureService}</div></calcite-notice>` : void 0; return g`<calcite-flow custom-item-selectors="arcgis-version-management-version-list, arcgis-version-management-version-properties" class=${N(this.mode === "dialog" ? "" : "calcite-flow-widget")} ${C(this.flowElement)}><calcite-flow-item .closable=${this.closable} .heading=${l ?? void 0} @calciteFlowItemClose=${() => { this._handleFlowItemClose(); }} .selected=${!v}>${L}<calcite-panel .loading=${m === "loading" || m === "executing"}>${V}${E}</calcite-panel></calcite-flow-item></calcite-flow>`; } } S("arcgis-version-management", D); export { D as ArcgisVersionManagement };