add isNew to workspaces

This commit is contained in:
Mads Rasmussen
2023-02-16 14:29:37 +01:00
parent 858975e21a
commit fb51ebf761
6 changed files with 29 additions and 26 deletions

View File

@@ -19,7 +19,7 @@ export class UmbDocumentWorkspaceContext
extends UmbWorkspaceContext
implements UmbWorkspaceEntityContextInterface<EntityType | undefined>
{
#isNew = false;
isNew = false;
#host: UmbControllerHostInterface;
#documentRepository: UmbDocumentRepository;
#documentTypeRepository: UmbDocumentTypeRepository;
@@ -44,7 +44,7 @@ export class UmbDocumentWorkspaceContext
async load(entityKey: string) {
const { data } = await this.#documentRepository.requestByKey(entityKey);
if (data) {
this.#isNew = false;
this.isNew = false;
this.#data.next(data);
}
}
@@ -52,7 +52,7 @@ export class UmbDocumentWorkspaceContext
async createScaffold(parentKey: string | null) {
const { data } = await this.#documentRepository.createScaffold(parentKey);
if (!data) return;
this.#isNew = true;
this.isNew = true;
this.#data.next(data);
}
@@ -174,13 +174,13 @@ export class UmbDocumentWorkspaceContext
async save() {
if (!this.#data.value) return;
if (this.#isNew) {
if (this.isNew) {
await this.#documentRepository.create(this.#data.value);
} else {
await this.#documentRepository.save(this.#data.value);
}
// If it went well, then its not new anymore?.
this.#isNew = false;
this.isNew = false;
}
async delete(key: string) {

View File

@@ -10,6 +10,7 @@ export class UmbWorkspaceMediaTypeContext
extends UmbWorkspaceContext
implements UmbWorkspaceEntityContextInterface<EntityType | undefined>
{
isNew = false;
#host: UmbControllerHostInterface;
#repo: UmbMediaTypeRepository;

View File

@@ -10,7 +10,7 @@ export class UmbMediaWorkspaceContext
extends UmbWorkspaceContext
implements UmbWorkspaceEntityContextInterface<EntityType | undefined>
{
#isNew = false;
isNew = false;
#host: UmbControllerHostInterface;
#detailRepository: UmbMediaRepository;
@@ -54,7 +54,7 @@ export class UmbMediaWorkspaceContext
async load(entityKey: string) {
const { data } = await this.#detailRepository.requestByKey(entityKey);
if (data) {
this.#isNew = false;
this.isNew = false;
this.#data.next(data);
}
}
@@ -62,19 +62,19 @@ export class UmbMediaWorkspaceContext
async createScaffold(parentKey: string | null) {
const { data } = await this.#detailRepository.createScaffold(parentKey);
if (!data) return;
this.#isNew = true;
this.isNew = true;
this.#data.next(data);
}
async save() {
if (!this.#data.value) return;
if (this.#isNew) {
if (this.isNew) {
await this.#detailRepository.create(this.#data.value);
} else {
await this.#detailRepository.save(this.#data.value);
}
// If it went well, then its not new anymore?.
this.#isNew = false;
this.isNew = false;
}
async delete(key: string) {

View File

@@ -11,7 +11,7 @@ export class UmbWorkspaceMemberTypeContext
extends UmbWorkspaceContext
implements UmbWorkspaceEntityContextInterface<EntityType | undefined>
{
#isNew = false;
isNew = false;
#host: UmbControllerHostInterface;
#dataTypeRepository: UmbMemberTypeRepository;
@@ -27,7 +27,7 @@ export class UmbWorkspaceMemberTypeContext
async load(entityKey: string) {
const { data } = await this.#dataTypeRepository.requestByKey(entityKey);
if (data) {
this.#isNew = false;
this.isNew = false;
this.#data.next(data);
}
}
@@ -35,7 +35,7 @@ export class UmbWorkspaceMemberTypeContext
async createScaffold() {
const { data } = await this.#dataTypeRepository.createScaffold();
if (!data) return;
this.#isNew = true;
this.isNew = true;
this.#data.next(data);
}
@@ -61,13 +61,13 @@ export class UmbWorkspaceMemberTypeContext
async save() {
if (!this.#data.value) return;
if (this.#isNew) {
if (this.isNew) {
await this.#dataTypeRepository.create(this.#data.value);
} else {
await this.#dataTypeRepository.save(this.#data.value);
}
// If it went well, then its not new anymore?.
this.#isNew = false;
this.isNew = false;
}
async delete(key: string) {

View File

@@ -1,4 +1,3 @@
import { BehaviorSubject } from 'rxjs';
import { UmbWorkspaceContext } from '../../../shared/components/workspace/workspace-context/workspace-context';
import { UmbWorkspaceEntityContextInterface } from '../../../shared/components/workspace/workspace-context/workspace-entity-context.interface';
import { UmbDataTypeRepository } from '../repository/data-type.repository';
@@ -10,7 +9,7 @@ export class UmbDataTypeWorkspaceContext
extends UmbWorkspaceContext
implements UmbWorkspaceEntityContextInterface<DataTypeModel | undefined>
{
#isNew = false;
isNew = false;
#host: UmbControllerHostInterface;
#dataTypeRepository: UmbDataTypeRepository;
@@ -28,24 +27,26 @@ export class UmbDataTypeWorkspaceContext
async load(key: string) {
const { data } = await this.#dataTypeRepository.requestByKey(key);
if (data) {
this.#isNew = false;
this.isNew = false;
this.#data.update(data);
}
}
async createScaffold(parentKey: string | null) {
this.isNew = true;
const { data } = await this.#dataTypeRepository.createScaffold(parentKey);
if (!data) return;
this.#isNew = true;
this.#data.next(data);
}
getData() {
return this.#data.getValue();
}
getEntityKey() {
return this.getData()?.key || '';
}
getEntityType() {
return 'data-type';
}
@@ -75,13 +76,13 @@ export class UmbDataTypeWorkspaceContext
async save() {
if (!this.#data.value) return;
if (this.#isNew) {
if (this.isNew) {
await this.#dataTypeRepository.create(this.#data.value);
} else {
await this.#dataTypeRepository.save(this.#data.value);
}
// If it went well, then its not new anymore?.
this.#isNew = false;
this.isNew = false;
}
async delete(key: string) {

View File

@@ -4,10 +4,11 @@ import { UmbWorkspaceEntityContextInterface } from '../../../shared/components/w
import { UMB_USER_GROUP_STORE_CONTEXT_TOKEN } from '../user-group.store';
import type { UserGroupDetails } from '@umbraco-cms/models';
export class UmbWorkspaceUserGroupContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface<UserGroupDetails | undefined> {
export class UmbWorkspaceUserGroupContext
extends UmbWorkspaceContext
implements UmbWorkspaceEntityContextInterface<UserGroupDetails | undefined>
{
isNew = false;
#manager = new UmbEntityWorkspaceManager(this._host, 'user-group', UMB_USER_GROUP_STORE_CONTEXT_TOKEN);
@@ -15,7 +16,7 @@ export class UmbWorkspaceUserGroupContext extends UmbWorkspaceContext implements
public readonly name = this.#manager.state.getObservablePart((state) => state?.name);
setName(name: string) {
this.#manager.state.update({name: name})
this.#manager.state.update({ name: name });
}
getEntityType = this.#manager.getEntityType;
getUnique = this.#manager.getEntityKey;