check current variant
This commit is contained in:
@@ -4,7 +4,7 @@ import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import { type Observable, map } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbBooleanState, UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import type { UmbVariantModel } from '@umbraco-cms/backoffice/variant';
|
||||
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
import type { UmbContentTypeModel, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type';
|
||||
@@ -30,6 +30,9 @@ export class UmbContentPropertyDatasetContext<
|
||||
culture = this.#currentVariant.asObservablePart((x) => x?.culture);
|
||||
segment = this.#currentVariant.asObservablePart((x) => x?.segment);
|
||||
|
||||
#currentVariantCultureIsReadOnly = new UmbBooleanState(false);
|
||||
public currentVariantCultureIsReadOnly = this.#currentVariantCultureIsReadOnly.asObservable();
|
||||
|
||||
getEntityType(): string {
|
||||
return this.#workspace.getEntityType();
|
||||
}
|
||||
@@ -46,6 +49,10 @@ export class UmbContentPropertyDatasetContext<
|
||||
return this.#workspace.getVariant(this.#variantId);
|
||||
}
|
||||
|
||||
getCurrentVariantCultureIsReadOnly() {
|
||||
return this.#currentVariantCultureIsReadOnly.getValue();
|
||||
}
|
||||
|
||||
constructor(
|
||||
host: UmbControllerHost,
|
||||
workspace: UmbContentWorkspaceContext<ContentTypeModel, VariantModelType>,
|
||||
@@ -64,6 +71,18 @@ export class UmbContentPropertyDatasetContext<
|
||||
},
|
||||
'_observeActiveVariant',
|
||||
);
|
||||
|
||||
this.observe(
|
||||
this.#workspace.readOnlyState.states,
|
||||
(states) => {
|
||||
const isReadOnly = states.some(
|
||||
(state) => state.unique.startsWith('UMB_CULTURE_') && state.variantId.equal(this.#variantId),
|
||||
);
|
||||
|
||||
this.#currentVariantCultureIsReadOnly.setValue(isReadOnly);
|
||||
},
|
||||
'umbObserveReadOnlyStates',
|
||||
);
|
||||
}
|
||||
|
||||
#createPropertyVariantId(property: UmbPropertyTypeModel) {
|
||||
|
||||
@@ -25,6 +25,9 @@ export interface UmbPropertyDatasetContext extends UmbContext {
|
||||
getName(): string | undefined;
|
||||
readonly name: Observable<string | undefined>;
|
||||
|
||||
getCurrentVariantCultureIsReadOnly(): boolean;
|
||||
readonly currentVariantCultureIsReadOnly: Observable<boolean>;
|
||||
|
||||
// Should it be possible to get the properties as a list of property aliases?
|
||||
//readonly properties: Observable<Array<string>>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user