render toggle if segmentation is enabled in the config
This commit is contained in:
@@ -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<UmbRepositoryResponse<UmbDocumentTypeConfigurationModel>>} - The document type configuration.
|
||||
* @memberof UmbDocumentTypeConfigurationRepository
|
||||
*/
|
||||
requestConfiguration(): Promise<UmbRepositoryResponse<UmbDocumentTypeConfigurationModel>> {
|
||||
return this.#serverDataSource.getConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -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<UmbDataSourceResponse<UmbDocumentTypeConfigurationModel>>} - The document type configuration.
|
||||
* @memberof UmbDocumentTypeConfigurationServerDataSource
|
||||
*/
|
||||
async getConfiguration(): Promise<UmbDataSourceResponse<UmbDocumentTypeConfigurationModel>> {
|
||||
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 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface UmbDocumentTypeConfigurationModel {
|
||||
dataTypesCanBeChanged: boolean;
|
||||
disableTemplates: boolean;
|
||||
useSegments: boolean;
|
||||
reservedFieldNames: Array<string>;
|
||||
}
|
||||
@@ -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<void> {
|
||||
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
|
||||
</div>
|
||||
</umb-property-layout>
|
||||
|
||||
${this._isElement
|
||||
? nothing
|
||||
: html`
|
||||
<umb-property-layout
|
||||
alias="VaryBySegments"
|
||||
label=${this.localize.term('contentTypeEditor_segmentVariantHeading')}>
|
||||
<div slot="description">
|
||||
<umb-localize key="contentTypeEditor_segmentVariantDescription"
|
||||
>Allow editors to segment their content.</umb-localize
|
||||
>
|
||||
</div>
|
||||
<div slot="editor">
|
||||
<uui-toggle
|
||||
?checked=${this._variesBySegment}
|
||||
@change=${(e: CustomEvent) => {
|
||||
this.#workspaceContext?.setVariesBySegment((e.target as UUIToggleElement).checked);
|
||||
}}
|
||||
label=${this.localize.term('contentTypeEditor_segmentVariantLabel')}></uui-toggle>
|
||||
</div>
|
||||
</umb-property-layout>
|
||||
`}
|
||||
${this.#renderVaryBySegmentProperty()}
|
||||
|
||||
<umb-property-layout alias="ElementType" label=${this.localize.term('contentTypeEditor_elementHeading')}>
|
||||
<div slot="description">
|
||||
@@ -201,6 +204,31 @@ export class UmbDocumentTypeWorkspaceViewSettingsElement extends UmbLitElement i
|
||||
`;
|
||||
}
|
||||
|
||||
#renderVaryBySegmentProperty() {
|
||||
if (!this._useSegments) return nothing;
|
||||
if (this._isElement) return nothing;
|
||||
|
||||
return html`
|
||||
<umb-property-layout
|
||||
alias="VaryBySegments"
|
||||
label=${this.localize.term('contentTypeEditor_segmentVariantHeading')}>
|
||||
<div slot="description">
|
||||
<umb-localize key="contentTypeEditor_segmentVariantDescription"
|
||||
>Allow editors to segment their content.</umb-localize
|
||||
>
|
||||
</div>
|
||||
<div slot="editor">
|
||||
<uui-toggle
|
||||
?checked=${this._variesBySegment}
|
||||
@change=${(e: CustomEvent) => {
|
||||
this.#workspaceContext?.setVariesBySegment((e.target as UUIToggleElement).checked);
|
||||
}}
|
||||
label=${this.localize.term('contentTypeEditor_segmentVariantLabel')}></uui-toggle>
|
||||
</div>
|
||||
</umb-property-layout>
|
||||
`;
|
||||
}
|
||||
|
||||
static override styles = [
|
||||
UmbTextStyles,
|
||||
css`
|
||||
|
||||
Reference in New Issue
Block a user