align content workspaces
This commit is contained in:
@@ -3,6 +3,7 @@ import { UMB_DOCUMENT_BLUEPRINT_ENTITY_TYPE } from '../entity.js';
|
||||
import { UmbDocumentBlueprintDetailRepository } from '../repository/index.js';
|
||||
import type {
|
||||
UmbDocumentBlueprintDetailModel,
|
||||
UmbDocumentBlueprintValueModel,
|
||||
UmbDocumentBlueprintVariantModel,
|
||||
UmbDocumentBlueprintVariantOptionModel,
|
||||
} from '../types.js';
|
||||
@@ -35,6 +36,7 @@ import type { UmbLanguageDetailModel } from '@umbraco-cms/backoffice/language';
|
||||
import { UmbContentWorkspaceDataManager, type UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content';
|
||||
import { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
|
||||
import { UMB_DOCUMENT_DETAIL_MODEL_VARIANT_SCAFFOLD } from '@umbraco-cms/backoffice/document';
|
||||
import { UmbDataTypeItemRepositoryManager } from '@umbraco-cms/backoffice/data-type';
|
||||
|
||||
type EntityModel = UmbDocumentBlueprintDetailModel;
|
||||
|
||||
@@ -80,6 +82,11 @@ export class UmbDocumentBlueprintWorkspaceContext
|
||||
x ? x.variesByCulture || x.variesBySegment : undefined,
|
||||
);
|
||||
#varies?: boolean;
|
||||
#variesByCulture?: boolean;
|
||||
#variesBySegment?: boolean;
|
||||
|
||||
readonly #dataTypeItemManager = new UmbDataTypeItemRepositoryManager(this);
|
||||
#dataTypeSchemaAliasMap = new Map<string, string>();
|
||||
|
||||
readonly splitView = new UmbWorkspaceSplitViewManager();
|
||||
|
||||
@@ -118,8 +125,29 @@ export class UmbDocumentBlueprintWorkspaceContext
|
||||
super(host, UMB_DOCUMENT_BLUEPRINT_WORKSPACE_ALIAS);
|
||||
|
||||
this.observe(this.contentTypeUnique, (unique) => this.structure.loadType(unique));
|
||||
|
||||
this.observe(this.variesByCulture, (varies) => {
|
||||
this.#data.setVariesByCulture(varies);
|
||||
this.#variesByCulture = varies;
|
||||
});
|
||||
this.observe(this.variesBySegment, (varies) => {
|
||||
this.#data.setVariesBySegment(varies);
|
||||
this.#variesBySegment = varies;
|
||||
});
|
||||
this.observe(this.varies, (varies) => (this.#varies = varies));
|
||||
|
||||
this.observe(this.structure.contentTypeDataTypeUniques, (dataTypeUniques: Array<string>) => {
|
||||
this.#dataTypeItemManager.setUniques(dataTypeUniques);
|
||||
});
|
||||
|
||||
this.observe(this.#dataTypeItemManager.items, (dataTypes) => {
|
||||
// Make a map of the data type unique and editorAlias:
|
||||
this.#dataTypeSchemaAliasMap = new Map(
|
||||
dataTypes.map((dataType) => {
|
||||
return [dataType.unique, dataType.propertyEditorSchemaAlias];
|
||||
}),
|
||||
);
|
||||
});
|
||||
this.loadLanguages();
|
||||
|
||||
this.routes.setRoutes([
|
||||
@@ -218,10 +246,15 @@ export class UmbDocumentBlueprintWorkspaceContext
|
||||
return this.getData()?.documentType.unique;
|
||||
}
|
||||
|
||||
// TODO: Check if this is used:
|
||||
getVaries() {
|
||||
return this.#varies;
|
||||
}
|
||||
getVariesByCulture() {
|
||||
return this.#variesByCulture;
|
||||
}
|
||||
getVariesBySegment() {
|
||||
return this.#variesBySegment;
|
||||
}
|
||||
|
||||
variantById(variantId: UmbVariantId) {
|
||||
return this.#data.current.asObservablePart((data) => data?.variants?.find((x) => variantId.compare(x)));
|
||||
@@ -285,36 +318,35 @@ export class UmbDocumentBlueprintWorkspaceContext
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
async setPropertyValue<UmbDocumentBlueprintValueModel = unknown>(
|
||||
alias: string,
|
||||
value: UmbDocumentBlueprintValueModel,
|
||||
variantId?: UmbVariantId,
|
||||
) {
|
||||
if (!variantId) throw new Error('VariantId is missing');
|
||||
|
||||
async setPropertyValue<ValueType = unknown>(alias: string, value: ValueType, variantId?: UmbVariantId) {
|
||||
this.initiatePropertyValueChange();
|
||||
variantId ??= UmbVariantId.CreateInvariant();
|
||||
const property = await this.structure.getPropertyStructureByAlias(alias);
|
||||
|
||||
if (!property) {
|
||||
throw new Error(`Property alias "${alias}" not found.`);
|
||||
}
|
||||
|
||||
//const dataType = await this.#dataTypeItemManager.getItemByUnique(property.dataType.unique);
|
||||
//const editorAlias = dataType.editorAlias;
|
||||
const editorAlias = 'Umbraco.TextBox';
|
||||
const editorAlias = this.#dataTypeSchemaAliasMap.get(property.dataType.unique);
|
||||
if (!editorAlias) {
|
||||
throw new Error(`Editor Alias of "${property.dataType.unique}" not found.`);
|
||||
}
|
||||
|
||||
const entry = { ...variantId.toObject(), alias, editorAlias, value };
|
||||
const currentData = this.#data.current.value;
|
||||
const entry = { ...variantId.toObject(), alias, editorAlias, value } as UmbDocumentBlueprintValueModel<ValueType>;
|
||||
|
||||
const currentData = this.getData();
|
||||
if (currentData) {
|
||||
const values = appendToFrozenArray(
|
||||
currentData.values || [],
|
||||
currentData.values ?? [],
|
||||
entry,
|
||||
(x) => x.alias === alias && (variantId ? variantId.compare(x as any) : true),
|
||||
(x) => x.alias === alias && variantId!.compare(x),
|
||||
);
|
||||
this.#data.current.update({ values });
|
||||
|
||||
// TODO: We should move this type of logic to the act of saving [NL]
|
||||
this.#updateVariantData(variantId);
|
||||
this.#data.ensureVariantData(variantId);
|
||||
}
|
||||
this.finishPropertyValueChange();
|
||||
}
|
||||
|
||||
#updateLock = 0;
|
||||
|
||||
@@ -346,7 +346,6 @@ export class UmbDocumentWorkspaceContext
|
||||
return this.getData()?.documentType.unique;
|
||||
}
|
||||
|
||||
// TODO: Check if this is used:
|
||||
getVaries() {
|
||||
return this.#varies;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,12 @@ import { UmbMediaTypeDetailRepository } from '../../media-types/repository/detai
|
||||
import { UmbMediaPropertyDatasetContext } from '../property-dataset-context/media-property-dataset-context.js';
|
||||
import { UMB_MEDIA_ENTITY_TYPE } from '../entity.js';
|
||||
import { UmbMediaDetailRepository } from '../repository/index.js';
|
||||
import type { UmbMediaDetailModel, UmbMediaVariantModel, UmbMediaVariantOptionModel } from '../types.js';
|
||||
import type {
|
||||
UmbMediaDetailModel,
|
||||
UmbMediaValueModel,
|
||||
UmbMediaVariantModel,
|
||||
UmbMediaVariantOptionModel,
|
||||
} from '../types.js';
|
||||
import { UMB_MEMBER_DETAIL_MODEL_VARIANT_SCAFFOLD } from './constants.js';
|
||||
import { UMB_INVARIANT_CULTURE, UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
import { UmbContentTypeStructureManager } from '@umbraco-cms/backoffice/content-type';
|
||||
@@ -30,6 +35,7 @@ import { UmbContentWorkspaceDataManager, type UmbContentWorkspaceContext } from
|
||||
import { UmbEntityContext } from '@umbraco-cms/backoffice/entity';
|
||||
import { UmbIsTrashedEntityContext } from '@umbraco-cms/backoffice/recycle-bin';
|
||||
import { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
|
||||
import { UmbDataTypeItemRepositoryManager } from '@umbraco-cms/backoffice/data-type';
|
||||
|
||||
type EntityModel = UmbMediaDetailModel;
|
||||
export class UmbMediaWorkspaceContext
|
||||
@@ -76,6 +82,11 @@ export class UmbMediaWorkspaceContext
|
||||
x ? x.variesByCulture || x.variesBySegment : undefined,
|
||||
);
|
||||
#varies?: boolean;
|
||||
#variesByCulture?: boolean;
|
||||
#variesBySegment?: boolean;
|
||||
|
||||
readonly #dataTypeItemManager = new UmbDataTypeItemRepositoryManager(this);
|
||||
#dataTypeSchemaAliasMap = new Map<string, string>();
|
||||
|
||||
readonly splitView = new UmbWorkspaceSplitViewManager();
|
||||
|
||||
@@ -119,8 +130,29 @@ export class UmbMediaWorkspaceContext
|
||||
super(host, 'Umb.Workspace.Media');
|
||||
|
||||
this.observe(this.contentTypeUnique, (unique) => this.structure.loadType(unique));
|
||||
|
||||
this.observe(this.variesByCulture, (varies) => {
|
||||
this.#data.setVariesByCulture(varies);
|
||||
this.#variesByCulture = varies;
|
||||
});
|
||||
this.observe(this.variesBySegment, (varies) => {
|
||||
this.#data.setVariesBySegment(varies);
|
||||
this.#variesBySegment = varies;
|
||||
});
|
||||
this.observe(this.varies, (varies) => (this.#varies = varies));
|
||||
|
||||
this.observe(this.structure.contentTypeDataTypeUniques, (dataTypeUniques: Array<string>) => {
|
||||
this.#dataTypeItemManager.setUniques(dataTypeUniques);
|
||||
});
|
||||
|
||||
this.observe(this.#dataTypeItemManager.items, (dataTypes) => {
|
||||
// Make a map of the data type unique and editorAlias:
|
||||
this.#dataTypeSchemaAliasMap = new Map(
|
||||
dataTypes.map((dataType) => {
|
||||
return [dataType.unique, dataType.propertyEditorSchemaAlias];
|
||||
}),
|
||||
);
|
||||
});
|
||||
this.loadLanguages();
|
||||
|
||||
this.routes.setRoutes([
|
||||
@@ -223,10 +255,15 @@ export class UmbMediaWorkspaceContext
|
||||
return this.getData()?.mediaType.unique;
|
||||
}
|
||||
|
||||
// TODO: Check if this is used:
|
||||
getVaries() {
|
||||
return this.#varies;
|
||||
}
|
||||
getVariesByCulture() {
|
||||
return this.#variesByCulture;
|
||||
}
|
||||
getVariesBySegment() {
|
||||
return this.#variesBySegment;
|
||||
}
|
||||
|
||||
variantById(variantId: UmbVariantId) {
|
||||
return this.#data.current.asObservablePart((data) => data?.variants?.find((x) => variantId.compare(x)));
|
||||
@@ -290,36 +327,36 @@ export class UmbMediaWorkspaceContext
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
async setPropertyValue<UmbMediaValueModel = unknown>(
|
||||
alias: string,
|
||||
value: UmbMediaValueModel,
|
||||
variantId?: UmbVariantId,
|
||||
) {
|
||||
if (!variantId) throw new Error('VariantId is missing');
|
||||
|
||||
async setPropertyValue<ValueType = unknown>(alias: string, value: ValueType, variantId?: UmbVariantId) {
|
||||
this.initiatePropertyValueChange();
|
||||
variantId ??= UmbVariantId.CreateInvariant();
|
||||
const property = await this.structure.getPropertyStructureByAlias(alias);
|
||||
|
||||
if (!property) {
|
||||
throw new Error(`Property alias "${alias}" not found.`);
|
||||
}
|
||||
|
||||
//const dataType = await this.#dataTypeItemManager.getItemByUnique(property.dataType.unique);
|
||||
//const editorAlias = dataType.editorAlias;
|
||||
const editorAlias = 'Umbraco.TextBox';
|
||||
const editorAlias = this.#dataTypeSchemaAliasMap.get(property.dataType.unique);
|
||||
if (!editorAlias) {
|
||||
throw new Error(`Editor Alias of "${property.dataType.unique}" not found.`);
|
||||
}
|
||||
|
||||
const entry = { ...variantId.toObject(), alias, editorAlias, value };
|
||||
const currentData = this.#data.current.value;
|
||||
const entry = { ...variantId.toObject(), alias, editorAlias, value } as UmbMediaValueModel<ValueType>;
|
||||
|
||||
const currentData = this.getData();
|
||||
if (currentData) {
|
||||
const values = appendToFrozenArray(
|
||||
currentData.values || [],
|
||||
currentData.values ?? [],
|
||||
entry,
|
||||
(x) => x.alias === alias && (variantId ? variantId.compare(x as any) : true),
|
||||
(x) => x.alias === alias && variantId!.compare(x),
|
||||
);
|
||||
this.#data.current.update({ values });
|
||||
|
||||
// TODO: We should move this type of logic to the act of saving [NL]
|
||||
this.#updateVariantData(variantId);
|
||||
this.#data.ensureVariantData(variantId);
|
||||
}
|
||||
this.finishPropertyValueChange();
|
||||
}
|
||||
|
||||
#updateLock = 0;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { UmbMemberVariantModel } from '../../types.js';
|
||||
|
||||
export const UMB_MEMBER_DETAIL_MODEL_VARIANT_SCAFFOLD: UmbMemberVariantModel = {
|
||||
culture: null,
|
||||
segment: null,
|
||||
name: '',
|
||||
createDate: null,
|
||||
updateDate: null,
|
||||
} as const;
|
||||
@@ -1,43 +1,44 @@
|
||||
import { UmbMemberDetailRepository } from '../../repository/index.js';
|
||||
import type { UmbMemberDetailModel, UmbMemberVariantModel, UmbMemberVariantOptionModel } from '../../types.js';
|
||||
import type {
|
||||
UmbMemberDetailModel,
|
||||
UmbMemberValueModel,
|
||||
UmbMemberVariantModel,
|
||||
UmbMemberVariantOptionModel,
|
||||
} from '../../types.js';
|
||||
import { UmbMemberPropertyDatasetContext } from '../../property-dataset-context/member-property-dataset-context.js';
|
||||
import { UMB_MEMBER_WORKSPACE_ALIAS } from './manifests.js';
|
||||
import { UmbMemberWorkspaceEditorElement } from './member-workspace-editor.element.js';
|
||||
import { type UmbMemberTypeDetailModel, UmbMemberTypeDetailRepository } from '@umbraco-cms/backoffice/member-type';
|
||||
import { UMB_MEMBER_DETAIL_MODEL_VARIANT_SCAFFOLD } from './constants.js';
|
||||
import { UmbMemberTypeDetailRepository, type UmbMemberTypeDetailModel } from '@umbraco-cms/backoffice/member-type';
|
||||
import {
|
||||
UmbSubmittableWorkspaceContextBase,
|
||||
UmbWorkspaceIsNewRedirectController,
|
||||
UmbWorkspaceSplitViewManager,
|
||||
} from '@umbraco-cms/backoffice/workspace';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import {
|
||||
UmbArrayState,
|
||||
UmbObjectState,
|
||||
appendToFrozenArray,
|
||||
mergeObservables,
|
||||
} from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbArrayState, appendToFrozenArray, mergeObservables } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbContentTypeStructureManager } from '@umbraco-cms/backoffice/content-type';
|
||||
import { UMB_INVARIANT_CULTURE, UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
import type { UmbLanguageDetailModel } from '@umbraco-cms/backoffice/language';
|
||||
import { UmbLanguageCollectionRepository } from '@umbraco-cms/backoffice/language';
|
||||
import type { UmbDataSourceResponse } from '@umbraco-cms/backoffice/repository';
|
||||
import type { UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content';
|
||||
import { UmbContentWorkspaceDataManager, type UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content';
|
||||
import { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
|
||||
import { UmbDataTypeItemRepositoryManager } from '@umbraco-cms/backoffice/data-type';
|
||||
|
||||
type EntityType = UmbMemberDetailModel;
|
||||
type EntityModel = UmbMemberDetailModel;
|
||||
export class UmbMemberWorkspaceContext
|
||||
extends UmbSubmittableWorkspaceContextBase<EntityType>
|
||||
implements UmbContentWorkspaceContext<EntityType, UmbMemberTypeDetailModel, UmbMemberVariantModel>
|
||||
extends UmbSubmittableWorkspaceContextBase<EntityModel>
|
||||
implements UmbContentWorkspaceContext<EntityModel, UmbMemberTypeDetailModel, UmbMemberVariantModel>
|
||||
{
|
||||
public readonly IS_CONTENT_WORKSPACE_CONTEXT = true as const;
|
||||
|
||||
public readonly repository = new UmbMemberDetailRepository(this);
|
||||
|
||||
#persistedData = new UmbObjectState<EntityType | undefined>(undefined);
|
||||
#currentData = new UmbObjectState<EntityType | undefined>(undefined);
|
||||
readonly #data = new UmbContentWorkspaceDataManager<EntityModel>(this, UMB_MEMBER_DETAIL_MODEL_VARIANT_SCAFFOLD);
|
||||
#getDataPromise?: Promise<UmbDataSourceResponse<UmbMemberDetailModel>>;
|
||||
|
||||
// TODo: Optimize this so it uses either a App Language Context? [NL]
|
||||
// TODO: Optimize this so it uses either a App Language Context or another somehow cached solution? [NL]
|
||||
#languageRepository = new UmbLanguageCollectionRepository(this);
|
||||
#languages = new UmbArrayState<UmbLanguageDetailModel>([], (x) => x.unique);
|
||||
public readonly languages = this.#languages.asObservable();
|
||||
@@ -48,20 +49,27 @@ export class UmbMemberWorkspaceContext
|
||||
return this.#getDataPromise;
|
||||
}
|
||||
|
||||
readonly data = this.#currentData.asObservable();
|
||||
readonly unique = this.#currentData.asObservablePart((data) => data?.unique);
|
||||
readonly createDate = this.#currentData.asObservablePart((data) => data?.variants[0].createDate);
|
||||
readonly updateDate = this.#currentData.asObservablePart((data) => data?.variants[0].updateDate);
|
||||
readonly contentTypeUnique = this.#currentData.asObservablePart((data) => data?.memberType.unique);
|
||||
readonly kind = this.#currentData.asObservablePart((data) => data?.kind);
|
||||
readonly structure = new UmbContentTypeStructureManager(this, new UmbMemberTypeDetailRepository(this));
|
||||
readonly data = this.#data.current.asObservable();
|
||||
readonly unique = this.#data.current.asObservablePart((data) => data?.unique);
|
||||
readonly createDate = this.#data.current.asObservablePart((data) => data?.variants[0].createDate);
|
||||
readonly updateDate = this.#data.current.asObservablePart((data) => data?.variants[0].updateDate);
|
||||
readonly contentTypeUnique = this.#data.current.asObservablePart((data) => data?.memberType.unique);
|
||||
readonly kind = this.#data.current.asObservablePart((data) => data?.kind);
|
||||
|
||||
readonly structure = new UmbContentTypeStructureManager(this, new UmbMemberTypeDetailRepository(this));
|
||||
readonly variesByCulture = this.structure.ownerContentTypePart((x) => x?.variesByCulture);
|
||||
readonly variesBySegment = this.structure.ownerContentTypePart((x) => x?.variesBySegment);
|
||||
readonly varies = this.structure.ownerContentTypePart((x) =>
|
||||
x ? x.variesByCulture || x.variesBySegment : undefined,
|
||||
);
|
||||
#varies?: boolean;
|
||||
#variesByCulture?: boolean;
|
||||
#variesBySegment?: boolean;
|
||||
|
||||
readonly variants = this.#currentData.asObservablePart((data) => data?.variants ?? []);
|
||||
readonly variants = this.#data.current.asObservablePart((data) => data?.variants ?? []);
|
||||
|
||||
readonly #dataTypeItemManager = new UmbDataTypeItemRepositoryManager(this);
|
||||
#dataTypeSchemaAliasMap = new Map<string, string>();
|
||||
|
||||
readonly splitView = new UmbWorkspaceSplitViewManager();
|
||||
|
||||
@@ -100,8 +108,29 @@ export class UmbMemberWorkspaceContext
|
||||
super(host, UMB_MEMBER_WORKSPACE_ALIAS);
|
||||
|
||||
this.observe(this.contentTypeUnique, (unique) => this.structure.loadType(unique));
|
||||
|
||||
this.observe(this.variesByCulture, (varies) => {
|
||||
this.#data.setVariesByCulture(varies);
|
||||
this.#variesByCulture = varies;
|
||||
});
|
||||
this.observe(this.variesBySegment, (varies) => {
|
||||
this.#data.setVariesBySegment(varies);
|
||||
this.#variesBySegment = varies;
|
||||
});
|
||||
this.observe(this.varies, (varies) => (this.#varies = varies));
|
||||
|
||||
this.observe(this.structure.contentTypeDataTypeUniques, (dataTypeUniques: Array<string>) => {
|
||||
this.#dataTypeItemManager.setUniques(dataTypeUniques);
|
||||
});
|
||||
|
||||
this.observe(this.#dataTypeItemManager.items, (dataTypes) => {
|
||||
// Make a map of the data type unique and editorAlias:
|
||||
this.#dataTypeSchemaAliasMap = new Map(
|
||||
dataTypes.map((dataType) => {
|
||||
return [dataType.unique, dataType.propertyEditorSchemaAlias];
|
||||
}),
|
||||
);
|
||||
});
|
||||
this.loadLanguages();
|
||||
|
||||
this.routes.setRoutes([
|
||||
@@ -132,8 +161,8 @@ export class UmbMemberWorkspaceContext
|
||||
|
||||
override resetState() {
|
||||
super.resetState();
|
||||
this.#persistedData.setValue(undefined);
|
||||
this.#currentData.setValue(undefined);
|
||||
this.#data.setPersistedData(undefined);
|
||||
this.#data.setCurrentData(undefined);
|
||||
}
|
||||
|
||||
async loadLanguages() {
|
||||
@@ -150,14 +179,14 @@ export class UmbMemberWorkspaceContext
|
||||
|
||||
if (data) {
|
||||
this.setIsNew(false);
|
||||
this.#persistedData.update(data);
|
||||
this.#currentData.update(data);
|
||||
this.#data.setPersistedData(data);
|
||||
this.#data.setCurrentData(data);
|
||||
}
|
||||
|
||||
this.observe(asObservable(), (member) => this.#onMemberStoreChange(member), 'umbMemberStoreObserver');
|
||||
}
|
||||
|
||||
#onMemberStoreChange(member: EntityType | undefined) {
|
||||
#onMemberStoreChange(member: EntityModel | undefined) {
|
||||
if (!member) {
|
||||
//TODO: This solution is alright for now. But reconsider when we introduce signal-r
|
||||
history.pushState(null, '', 'section/member-management');
|
||||
@@ -175,13 +204,13 @@ export class UmbMemberWorkspaceContext
|
||||
if (!data) return undefined;
|
||||
|
||||
this.setIsNew(true);
|
||||
this.#persistedData.setValue(undefined);
|
||||
this.#currentData.setValue(data);
|
||||
this.#data.setPersistedData(undefined);
|
||||
this.#data.setCurrentData(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
getData() {
|
||||
return this.#currentData.getValue();
|
||||
return this.#data.current.getValue();
|
||||
}
|
||||
|
||||
getUnique() {
|
||||
@@ -196,21 +225,26 @@ export class UmbMemberWorkspaceContext
|
||||
return this.getData()?.memberType.unique;
|
||||
}
|
||||
|
||||
// TODO: Check if this is used:
|
||||
getVaries() {
|
||||
return this.#varies;
|
||||
}
|
||||
getVariesByCulture() {
|
||||
return this.#variesByCulture;
|
||||
}
|
||||
getVariesBySegment() {
|
||||
return this.#variesBySegment;
|
||||
}
|
||||
|
||||
variantById(variantId: UmbVariantId) {
|
||||
return this.#currentData.asObservablePart((data) => data?.variants?.find((x) => variantId.compare(x)));
|
||||
return this.#data.current.asObservablePart((data) => data?.variants?.find((x) => variantId.compare(x)));
|
||||
}
|
||||
|
||||
getVariant(variantId: UmbVariantId) {
|
||||
return this.#currentData.getValue()?.variants?.find((x) => variantId.compare(x));
|
||||
return this.#data.current.getValue()?.variants?.find((x) => variantId.compare(x));
|
||||
}
|
||||
|
||||
getName(variantId?: UmbVariantId) {
|
||||
const variants = this.#currentData.getValue()?.variants;
|
||||
const variants = this.#data.current.getValue()?.variants;
|
||||
if (!variants) return;
|
||||
if (variantId) {
|
||||
return variants.find((x) => variantId.compare(x))?.name;
|
||||
@@ -220,11 +254,13 @@ export class UmbMemberWorkspaceContext
|
||||
}
|
||||
|
||||
setName(name: string, variantId?: UmbVariantId) {
|
||||
this.#updateVariantData(variantId ?? UmbVariantId.CreateInvariant(), { name });
|
||||
this.#data.updateVariantData(variantId ?? UmbVariantId.CreateInvariant(), { name });
|
||||
}
|
||||
|
||||
name(variantId?: UmbVariantId) {
|
||||
return this.#currentData.asObservablePart((data) => data?.variants?.find((x) => variantId?.compare(x))?.name ?? '');
|
||||
return this.#data.current.asObservablePart(
|
||||
(data) => data?.variants?.find((x) => variantId?.compare(x))?.name ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
async propertyStructureById(propertyId: string) {
|
||||
@@ -233,13 +269,13 @@ export class UmbMemberWorkspaceContext
|
||||
|
||||
/**
|
||||
* @function propertyValueByAlias
|
||||
* @param {string} propertyAlias
|
||||
* @param {UmbVariantId} variantId
|
||||
* @param {string} propertyAlias - property alias to observe
|
||||
* @param {UmbVariantId} variantId - variant identifier for the value to observe
|
||||
* @returns {Promise<Observable<ReturnType | undefined> | undefined>}
|
||||
* @description Get an Observable for the value of this property.
|
||||
*/
|
||||
async propertyValueByAlias<PropertyValueType = unknown>(propertyAlias: string, variantId?: UmbVariantId) {
|
||||
return this.#currentData.asObservablePart(
|
||||
return this.#data.current.asObservablePart(
|
||||
(data) =>
|
||||
data?.values?.find((x) => x?.alias === propertyAlias && (variantId ? variantId.compare(x) : true))
|
||||
?.value as PropertyValueType,
|
||||
@@ -248,9 +284,9 @@ export class UmbMemberWorkspaceContext
|
||||
|
||||
/**
|
||||
* Get the current value of the property with the given alias and variantId.
|
||||
* @param alias
|
||||
* @param variantId
|
||||
* @returns The value or undefined if not set or found.
|
||||
* @param {string} alias - property alias to set.
|
||||
* @param {UmbVariantId} variantId - variant identifier for this value to be defined for.
|
||||
* @returns {ReturnType | undefined}The value or undefined if not set or found.
|
||||
*/
|
||||
getPropertyValue<ReturnType = unknown>(alias: string, variantId?: UmbVariantId) {
|
||||
const currentData = this.getData();
|
||||
@@ -262,42 +298,41 @@ export class UmbMemberWorkspaceContext
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
async setPropertyValue<UmbMemberValueModel = unknown>(
|
||||
alias: string,
|
||||
value: UmbMemberValueModel,
|
||||
variantId?: UmbVariantId,
|
||||
) {
|
||||
async setPropertyValue<ValueType = unknown>(alias: string, value: ValueType, variantId?: UmbVariantId) {
|
||||
this.initiatePropertyValueChange();
|
||||
variantId ??= UmbVariantId.CreateInvariant();
|
||||
|
||||
const property = await this.structure.getPropertyStructureByAlias(alias);
|
||||
|
||||
if (!property) {
|
||||
throw new Error(`Property alias "${alias}" not found.`);
|
||||
}
|
||||
|
||||
//const dataType = await this.#dataTypeItemManager.getItemByUnique(property.dataType.unique);
|
||||
//const editorAlias = dataType.editorAlias;
|
||||
const editorAlias = 'Umbraco.TextBox';
|
||||
const editorAlias = this.#dataTypeSchemaAliasMap.get(property.dataType.unique);
|
||||
if (!editorAlias) {
|
||||
throw new Error(`Editor Alias of "${property.dataType.unique}" not found.`);
|
||||
}
|
||||
|
||||
const entry = { ...variantId.toObject(), alias, editorAlias, value } as UmbMemberValueModel<ValueType>;
|
||||
|
||||
const entry = { ...variantId.toObject(), alias, editorAlias, value };
|
||||
const currentData = this.getData();
|
||||
if (currentData) {
|
||||
const values = appendToFrozenArray(
|
||||
currentData.values || [],
|
||||
currentData.values ?? [],
|
||||
entry,
|
||||
(x) => x.alias === alias && (variantId ? variantId.compare(x) : true),
|
||||
(x) => x.alias === alias && variantId!.compare(x),
|
||||
);
|
||||
this.#currentData.update({ values });
|
||||
this.#data.current.update({ values });
|
||||
|
||||
// TODO: We should move this type of logic to the act of saving [NL]
|
||||
this.#updateVariantData(variantId);
|
||||
this.#data.ensureVariantData(variantId);
|
||||
}
|
||||
this.finishPropertyValueChange();
|
||||
}
|
||||
|
||||
#updateLock = 0;
|
||||
initiatePropertyValueChange() {
|
||||
this.#updateLock++;
|
||||
this.#currentData.mute();
|
||||
this.#data.current.mute();
|
||||
// TODO: When ready enable this code will enable handling a finish automatically by this implementation 'using myState.initiatePropertyValueChange()' (Relies on TS support of Using) [NL]
|
||||
/*return {
|
||||
[Symbol.dispose]: this.finishPropertyValueChange,
|
||||
@@ -309,68 +344,25 @@ export class UmbMemberWorkspaceContext
|
||||
};
|
||||
#triggerPropertyValueChanges() {
|
||||
if (this.#updateLock === 0) {
|
||||
this.#currentData.unmute();
|
||||
}
|
||||
}
|
||||
|
||||
#updateVariantData(variantId: UmbVariantId, update?: Partial<UmbMemberVariantModel>) {
|
||||
const currentData = this.getData();
|
||||
if (!currentData) throw new Error('Data is missing');
|
||||
if (this.#varies === true) {
|
||||
// If variant Id is invariant, we don't to have the variant appended to our data.
|
||||
if (variantId.isInvariant()) return;
|
||||
const variant = currentData.variants.find((x) => variantId.compare(x));
|
||||
const newVariants = appendToFrozenArray(
|
||||
currentData.variants,
|
||||
{
|
||||
name: '',
|
||||
createDate: null,
|
||||
updateDate: null,
|
||||
...variantId.toObject(),
|
||||
...variant,
|
||||
...update,
|
||||
},
|
||||
(x) => variantId.compare(x),
|
||||
);
|
||||
this.#currentData.update({ variants: newVariants });
|
||||
} else if (this.#varies === false) {
|
||||
// TODO: Beware about segments, in this case we need to also consider segments, if its allowed to vary by segments.
|
||||
const invariantVariantId = UmbVariantId.CreateInvariant();
|
||||
const variant = currentData.variants.find((x) => invariantVariantId.compare(x));
|
||||
// Cause we are invariant, we will just overwrite all variants with this one:
|
||||
const newVariants = [
|
||||
{
|
||||
state: null,
|
||||
name: '',
|
||||
publishDate: null,
|
||||
createDate: null,
|
||||
updateDate: null,
|
||||
...invariantVariantId.toObject(),
|
||||
...variant,
|
||||
...update,
|
||||
},
|
||||
];
|
||||
this.#currentData.update({ variants: newVariants });
|
||||
} else {
|
||||
throw new Error('Varies by culture is missing');
|
||||
this.#data.current.unmute();
|
||||
}
|
||||
}
|
||||
|
||||
async submit() {
|
||||
if (!this.#currentData.value) throw new Error('Data is missing');
|
||||
if (!this.#currentData.value.unique) throw new Error('Unique is missing');
|
||||
if (!this.#data.current.value) throw new Error('Data is missing');
|
||||
if (!this.#data.current.value.unique) throw new Error('Unique is missing');
|
||||
|
||||
let newData = undefined;
|
||||
|
||||
if (this.getIsNew()) {
|
||||
const { data } = await this.repository.create(this.#currentData.value);
|
||||
const { data } = await this.repository.create(this.#data.current.value);
|
||||
if (!data) {
|
||||
throw new Error('Could not create member.');
|
||||
}
|
||||
newData = data;
|
||||
this.setIsNew(false);
|
||||
} else {
|
||||
const { data } = await this.repository.save(this.#currentData.value);
|
||||
const { data } = await this.repository.save(this.#data.current.value);
|
||||
if (!data) {
|
||||
throw new Error('Could not create member.');
|
||||
}
|
||||
@@ -378,8 +370,8 @@ export class UmbMemberWorkspaceContext
|
||||
}
|
||||
|
||||
if (newData) {
|
||||
this.#persistedData.setValue(newData);
|
||||
this.#currentData.setValue(newData);
|
||||
this.#data.setPersistedData(newData);
|
||||
this.#data.setCurrentData(newData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,24 +390,22 @@ export class UmbMemberWorkspaceContext
|
||||
}
|
||||
|
||||
public override destroy(): void {
|
||||
this.#currentData.destroy();
|
||||
this.#data.destroy();
|
||||
super.destroy();
|
||||
this.#persistedData.destroy();
|
||||
this.#currentData.destroy();
|
||||
}
|
||||
|
||||
set<PropertyName extends keyof UmbMemberDetailModel>(
|
||||
propertyName: PropertyName,
|
||||
value: UmbMemberDetailModel[PropertyName],
|
||||
) {
|
||||
this.#currentData.update({ [propertyName]: value });
|
||||
this.#data.current.update({ [propertyName]: value });
|
||||
}
|
||||
|
||||
// Only for CRUD demonstration purposes
|
||||
updateData(data: Partial<EntityType>) {
|
||||
const currentData = this.#currentData.getValue();
|
||||
updateData(data: Partial<EntityModel>) {
|
||||
const currentData = this.#data.current.getValue();
|
||||
if (!currentData) throw new Error('No data to update');
|
||||
this.#currentData.setValue({ ...currentData, ...data });
|
||||
this.#data.current.setValue({ ...currentData, ...data });
|
||||
}
|
||||
|
||||
get email(): string {
|
||||
@@ -459,7 +449,7 @@ export class UmbMemberWorkspaceContext
|
||||
}
|
||||
|
||||
#get<PropertyName extends keyof UmbMemberDetailModel>(propertyName: PropertyName) {
|
||||
return this.#currentData.getValue()?.[propertyName];
|
||||
return this.#data.current.getValue()?.[propertyName];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user