diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/configuration.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/configuration.repository.ts new file mode 100644 index 0000000000..39c091362c --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/configuration.repository.ts @@ -0,0 +1,22 @@ +import { UmbDocumentTypeConfigurationServerDataSource } from './configuration.server.data-source.js'; +import type { UmbDocumentTypeConfigurationModel } from './types.js'; +import { UmbRepositoryBase, type UmbRepositoryResponse } from '@umbraco-cms/backoffice/repository'; + +/** + * @description - Repository for Document Type configuration. + * @exports + * @class UmbDocumentTypeConfigurationRepository + * @augments UmbRepositoryBase + */ +export class UmbDocumentTypeConfigurationRepository extends UmbRepositoryBase { + #serverDataSource = new UmbDocumentTypeConfigurationServerDataSource(this); + + /** + * Requests the Document Type configuration + * @returns {Promise>} - The document type configuration. + * @memberof UmbDocumentTypeConfigurationRepository + */ + requestConfiguration(): Promise> { + return this.#serverDataSource.getConfiguration(); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/configuration.server.data-source.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/configuration.server.data-source.ts new file mode 100644 index 0000000000..d4d75d7d98 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/configuration.server.data-source.ts @@ -0,0 +1,29 @@ +import type { UmbDocumentTypeConfigurationModel } from './types.js'; +import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { DocumentTypeService } from '@umbraco-cms/backoffice/external/backend-api'; +import type { UmbDataSourceResponse } from '@umbraco-cms/backoffice/repository'; +import { tryExecute } from '@umbraco-cms/backoffice/resources'; + +export class UmbDocumentTypeConfigurationServerDataSource extends UmbControllerBase { + /** + * Gets the document type configuration from the server. + * @returns {Promise>} - The document type configuration. + * @memberof UmbDocumentTypeConfigurationServerDataSource + */ + async getConfiguration(): Promise> { + const { data, error } = await tryExecute(this, DocumentTypeService.getDocumentTypeConfiguration()); + + if (data) { + const mappedData: UmbDocumentTypeConfigurationModel = { + dataTypesCanBeChanged: data.dataTypesCanBeChanged === 'True' ? true : false, + disableTemplates: data.disableTemplates, + useSegments: data.useSegments, + reservedFieldNames: data.reservedFieldNames, + }; + + return { data: mappedData }; + } + + return { error }; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/types.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/types.ts new file mode 100644 index 0000000000..4fdfda2c98 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/configuration/types.ts @@ -0,0 +1,6 @@ +export interface UmbDocumentTypeConfigurationModel { + dataTypesCanBeChanged: boolean; + disableTemplates: boolean; + useSegments: boolean; + reservedFieldNames: Array; +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type/views/settings/document-type-workspace-view-settings.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type/views/settings/document-type-workspace-view-settings.element.ts index 51f689e68c..3c7d8d5ce6 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type/views/settings/document-type-workspace-view-settings.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type/views/settings/document-type-workspace-view-settings.element.ts @@ -1,5 +1,14 @@ import { UMB_DOCUMENT_TYPE_WORKSPACE_CONTEXT } from '../../document-type-workspace.context-token.js'; -import { css, html, customElement, state, when, nothing } from '@umbraco-cms/backoffice/external/lit'; +import { UmbDocumentTypeConfigurationRepository } from '../../../../configuration/configuration.repository.js'; +import { + css, + html, + customElement, + state, + when, + nothing, + type PropertyValues, +} from '@umbraco-cms/backoffice/external/lit'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import type { UUIBooleanInputEvent, UUIToggleElement } from '@umbraco-cms/backoffice/external/uui'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; @@ -27,6 +36,11 @@ export class UmbDocumentTypeWorkspaceViewSettingsElement extends UmbLitElement i @state() private _preventCleanup?: boolean; + @state() + private _useSegments?: boolean; + + #configurationRepository = new UmbDocumentTypeConfigurationRepository(this); + constructor() { super(); @@ -37,6 +51,15 @@ export class UmbDocumentTypeWorkspaceViewSettingsElement extends UmbLitElement i }); } + protected override async firstUpdated(_changedProperties: PropertyValues): Promise { + super.firstUpdated(_changedProperties); + const { data } = await this.#configurationRepository.requestConfiguration(); + + if (data) { + this._useSegments = data.useSegments; + } + } + #observeDocumentType() { if (!this.#workspaceContext) return; this.observe( @@ -104,27 +127,7 @@ export class UmbDocumentTypeWorkspaceViewSettingsElement extends UmbLitElement i - ${this._isElement - ? nothing - : html` - -
- Allow editors to segment their content. -
-
- { - this.#workspaceContext?.setVariesBySegment((e.target as UUIToggleElement).checked); - }} - label=${this.localize.term('contentTypeEditor_segmentVariantLabel')}> -
-
- `} + ${this.#renderVaryBySegmentProperty()}
@@ -201,6 +204,31 @@ export class UmbDocumentTypeWorkspaceViewSettingsElement extends UmbLitElement i `; } + #renderVaryBySegmentProperty() { + if (!this._useSegments) return nothing; + if (this._isElement) return nothing; + + return html` + +
+ Allow editors to segment their content. +
+
+ { + this.#workspaceContext?.setVariesBySegment((e.target as UUIToggleElement).checked); + }} + label=${this.localize.term('contentTypeEditor_segmentVariantLabel')}> +
+
+ `; + } + static override styles = [ UmbTextStyles, css`