add missing properties. and add generic updateProperty function
This commit is contained in:
@@ -4,17 +4,22 @@ import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api
|
||||
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import { MediaTypeResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
type EntityType = MediaTypeResponseModel;
|
||||
export class UmbMediaTypeWorkspaceContext
|
||||
extends UmbWorkspaceContext<UmbMediaTypeRepository, MediaTypeResponseModel>
|
||||
implements UmbSaveableWorkspaceContextInterface<MediaTypeResponseModel | undefined>
|
||||
extends UmbWorkspaceContext<UmbMediaTypeRepository, EntityType>
|
||||
implements UmbSaveableWorkspaceContextInterface<EntityType | undefined>
|
||||
{
|
||||
#data = new UmbObjectState<MediaTypeResponseModel | undefined>(undefined);
|
||||
#data = new UmbObjectState<EntityType | undefined>(undefined);
|
||||
data = this.#data.asObservable();
|
||||
#getDataPromise?: Promise<any>;
|
||||
|
||||
name = this.#data.asObservablePart((data) => data?.name);
|
||||
id = this.#data.asObservablePart((data) => data?.id);
|
||||
alias = this.#data.asObservablePart((data) => data?.alias);
|
||||
description = this.#data.asObservablePart((data) => data?.description);
|
||||
icon = this.#data.asObservablePart((data) => data?.icon);
|
||||
|
||||
constructor(host: UmbControllerHostElement) {
|
||||
super(host, 'Umb.Workspace.MediaType', new UmbMediaTypeRepository(host));
|
||||
@@ -32,12 +37,8 @@ export class UmbMediaTypeWorkspaceContext
|
||||
return 'media-type';
|
||||
}
|
||||
|
||||
setName(name: string) {
|
||||
this.#data.update({ name });
|
||||
}
|
||||
|
||||
setPropertyValue(alias: string, value: string) {
|
||||
// TODO => Implement setPropertyValue
|
||||
updateProperty<PropertyName extends keyof EntityType>(propertyName: PropertyName, value: EntityType[PropertyName]) {
|
||||
this.#data.update({ [propertyName]: value });
|
||||
}
|
||||
|
||||
async load(id: string) {
|
||||
@@ -52,13 +53,17 @@ export class UmbMediaTypeWorkspaceContext
|
||||
async create() {
|
||||
const { data } = await this.repository.createScaffold();
|
||||
if (!data) return;
|
||||
|
||||
this.setIsNew(true);
|
||||
this.#data.next(data);
|
||||
}
|
||||
|
||||
async save() {
|
||||
if (!this.#data.value) return;
|
||||
await this.repository.save(this.#data.value);
|
||||
const id = await firstValueFrom(this.id);
|
||||
|
||||
if (!this.#data.value || !id) return;
|
||||
|
||||
await this.repository.save(id, this.#data.value);
|
||||
this.setIsNew(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user