save
This commit is contained in:
@@ -141,18 +141,19 @@ export class UmbMediaTypeRepository implements UmbTreeRepository<EntityTreeItemR
|
||||
return this.#detailSource.delete(id);
|
||||
}
|
||||
|
||||
async save(id: string, updatedMediaType: UpdateMediaTypeRequestModel) {
|
||||
async save(id: string, item: UpdateMediaTypeRequestModel) {
|
||||
if (!id) throw new Error('Data Type id is missing');
|
||||
if (!updatedMediaType) throw new Error('Media Type is missing');
|
||||
if (!item) throw new Error('Media Type is missing');
|
||||
await this.#init;
|
||||
|
||||
const { error } = await this.#detailSource.update(id, updatedMediaType);
|
||||
const { error } = await this.#detailSource.update(id, item);
|
||||
|
||||
if (!error) {
|
||||
const notification = { data: { message: `Media type '${updatedMediaType.name}' saved` } };
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
this.#detailStore?.append(item);
|
||||
this.#treeStore?.updateItem(id, item);
|
||||
|
||||
//TODO: Update stores
|
||||
const notification = { data: { message: `Media type '${item.name}' saved` } };
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { UmbMediaTypeRepository } from '../repository/media-type.repository.js';
|
||||
import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
import { UmbSaveableWorkspaceContextInterface, UmbWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
|
||||
@@ -59,12 +58,16 @@ export class UmbMediaTypeWorkspaceContext
|
||||
}
|
||||
|
||||
async save() {
|
||||
const id = await firstValueFrom(this.id);
|
||||
if (!this.#data.value) return;
|
||||
if (!this.#data.value.id) return;
|
||||
|
||||
if (!this.#data.value || !id) return;
|
||||
if (this.getIsNew()) {
|
||||
await this.repository.create(this.#data.value);
|
||||
} else {
|
||||
await this.repository.save(this.#data.value.id, this.#data.value);
|
||||
}
|
||||
|
||||
await this.repository.save(id, this.#data.value);
|
||||
this.setIsNew(false);
|
||||
this.saveComplete(this.#data.value);
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
|
||||
Reference in New Issue
Block a user