remove data type repo base class
This commit is contained in:
@@ -1,21 +1,35 @@
|
||||
import { UmbDataTypeRepositoryBase } from '../data-type-repository-base.js';
|
||||
import { UMB_DATA_TYPE_TREE_STORE_CONTEXT, UmbDataTypeTreeStore } from '../../tree/data-type.tree.store.js';
|
||||
import { UmbDataTypeDetailRepository } from '../detail/data-type-detail.repository.js';
|
||||
import { UmbDataTypeCopyServerDataSource } from './data-type-copy.server.data-source.js';
|
||||
import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbCopyDataSource, UmbCopyRepository } from '@umbraco-cms/backoffice/repository';
|
||||
import { UmbCopyDataSource, UmbCopyRepository, UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbCopyDataTypeRepository extends UmbDataTypeRepositoryBase implements UmbCopyRepository {
|
||||
export class UmbCopyDataTypeRepository extends UmbRepositoryBase implements UmbCopyRepository {
|
||||
#init: Promise<unknown>;
|
||||
#copySource: UmbCopyDataSource;
|
||||
#detailRepository: UmbDataTypeDetailRepository;
|
||||
#treeStore?: UmbDataTypeTreeStore;
|
||||
#notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.#copySource = new UmbDataTypeCopyServerDataSource(this);
|
||||
this.#detailRepository = new UmbDataTypeDetailRepository(this);
|
||||
|
||||
this.#init = Promise.all([
|
||||
this.consumeContext(UMB_DATA_TYPE_TREE_STORE_CONTEXT, (instance) => {
|
||||
this.#treeStore = instance;
|
||||
}).asPromise(),
|
||||
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
||||
this.#notificationContext = instance;
|
||||
}).asPromise(),
|
||||
]);
|
||||
}
|
||||
|
||||
async copy(unique: string, targetUnique: string | null) {
|
||||
await this._init;
|
||||
await this.#init;
|
||||
const { data: dataTypeCopyUnique, error } = await this.#copySource.copy(unique, targetUnique);
|
||||
if (error) return { error };
|
||||
|
||||
@@ -24,10 +38,10 @@ export class UmbCopyDataTypeRepository extends UmbDataTypeRepositoryBase impleme
|
||||
if (!dataTypeCopy) throw new Error('Could not find copied data type');
|
||||
|
||||
// TODO: Be aware about this responsibility.
|
||||
this._treeStore!.append(dataTypeCopy);
|
||||
this.#treeStore!.append(dataTypeCopy);
|
||||
|
||||
const notification = { data: { message: `Data type copied` } };
|
||||
this._notificationContext!.peek('positive', notification);
|
||||
this.#notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { data: dataTypeCopyUnique };
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { UMB_DATA_TYPE_TREE_STORE_CONTEXT, UmbDataTypeTreeStore } from '../tree/data-type.tree.store.js';
|
||||
import { UMB_DATA_TYPE_ITEM_STORE_CONTEXT, UmbDataTypeItemStore } from './item/data-type-item.store.js';
|
||||
import { UMB_DATA_TYPE_DETAIL_STORE_CONTEXT, UmbDataTypeDetailStore } from './detail/data-type-detail.store.js';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDataTypeRepositoryBase extends UmbRepositoryBase {
|
||||
protected _init: Promise<unknown>;
|
||||
|
||||
protected _detailStore?: UmbDataTypeDetailStore;
|
||||
protected _treeStore?: UmbDataTypeTreeStore;
|
||||
protected _itemStore?: UmbDataTypeItemStore;
|
||||
|
||||
protected _notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
|
||||
this._init = Promise.all([
|
||||
this.consumeContext(UMB_DATA_TYPE_DETAIL_STORE_CONTEXT, (instance) => {
|
||||
this._detailStore = instance;
|
||||
}).asPromise(),
|
||||
|
||||
this.consumeContext(UMB_DATA_TYPE_TREE_STORE_CONTEXT, (instance) => {
|
||||
this._treeStore = instance;
|
||||
}).asPromise(),
|
||||
|
||||
this.consumeContext(UMB_DATA_TYPE_ITEM_STORE_CONTEXT, (instance) => {
|
||||
this._itemStore = instance;
|
||||
}).asPromise(),
|
||||
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
||||
this._notificationContext = instance;
|
||||
}).asPromise(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,52 @@
|
||||
import { UmbDataTypeRepositoryBase } from '../data-type-repository-base.js';
|
||||
import { createFolderTreeItem } from '../utils.js';
|
||||
import { UMB_DATA_TYPE_TREE_STORE_CONTEXT, UmbDataTypeTreeStore } from '../../tree/data-type.tree.store.js';
|
||||
import { UmbDataTypeFolderServerDataSource } from './data-type-folder.server.data.js';
|
||||
import type { UmbFolderRepository, UmbFolderDataSource } from '@umbraco-cms/backoffice/repository';
|
||||
import {
|
||||
type UmbFolderRepository,
|
||||
type UmbFolderDataSource,
|
||||
UmbRepositoryBase,
|
||||
} from '@umbraco-cms/backoffice/repository';
|
||||
import { type UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { CreateFolderRequestModel, FolderModelBaseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
export class UmbDataTypeFolderRepository extends UmbDataTypeRepositoryBase implements UmbFolderRepository {
|
||||
import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
|
||||
export class UmbDataTypeFolderRepository extends UmbRepositoryBase implements UmbFolderRepository {
|
||||
#init: Promise<unknown>;
|
||||
#folderSource: UmbFolderDataSource;
|
||||
#treeStore?: UmbDataTypeTreeStore;
|
||||
#notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.#folderSource = new UmbDataTypeFolderServerDataSource(this);
|
||||
|
||||
this.#init = Promise.all([
|
||||
this.consumeContext(UMB_DATA_TYPE_TREE_STORE_CONTEXT, (instance) => {
|
||||
this.#treeStore = instance;
|
||||
}).asPromise(),
|
||||
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
||||
this.#notificationContext = instance;
|
||||
}).asPromise(),
|
||||
]);
|
||||
}
|
||||
|
||||
async createFolderScaffold(parentId: string | null) {
|
||||
if (parentId === undefined) throw new Error('Parent id is missing');
|
||||
await this._init;
|
||||
await this.#init;
|
||||
return this.#folderSource.createScaffold(parentId);
|
||||
}
|
||||
|
||||
// TODO: temp create type until backend is ready. Remove the id addition when new types are generated.
|
||||
async createFolder(folderRequest: CreateFolderRequestModel & { id?: string | undefined }) {
|
||||
if (!folderRequest) throw new Error('folder request is missing');
|
||||
await this._init;
|
||||
await this.#init;
|
||||
|
||||
const { error } = await this.#folderSource.create(folderRequest);
|
||||
|
||||
if (!error) {
|
||||
// TODO: We need to push a new item to the tree store to update the tree. How do we want to create the tree items?
|
||||
const folderTreeItem = createFolderTreeItem(folderRequest);
|
||||
this._treeStore!.appendItems([folderTreeItem]);
|
||||
this.#treeStore!.appendItems([folderTreeItem]);
|
||||
}
|
||||
|
||||
return { error };
|
||||
@@ -36,12 +54,12 @@ export class UmbDataTypeFolderRepository extends UmbDataTypeRepositoryBase imple
|
||||
|
||||
async deleteFolder(id: string) {
|
||||
if (!id) throw new Error('Key is missing');
|
||||
await this._init;
|
||||
await this.#init;
|
||||
|
||||
const { error } = await this.#folderSource.delete(id);
|
||||
|
||||
if (!error) {
|
||||
this._treeStore!.removeItem(id);
|
||||
this.#treeStore!.removeItem(id);
|
||||
}
|
||||
|
||||
return { error };
|
||||
@@ -50,12 +68,12 @@ export class UmbDataTypeFolderRepository extends UmbDataTypeRepositoryBase imple
|
||||
async updateFolder(id: string, folder: FolderModelBaseModel) {
|
||||
if (!id) throw new Error('Key is missing');
|
||||
if (!folder) throw new Error('Folder data is missing');
|
||||
await this._init;
|
||||
await this.#init;
|
||||
|
||||
const { error } = await this.#folderSource.update(id, folder);
|
||||
|
||||
if (!error) {
|
||||
this._treeStore!.updateItem(id, { name: folder.name });
|
||||
this.#treeStore!.updateItem(id, { name: folder.name });
|
||||
}
|
||||
|
||||
return { error };
|
||||
@@ -63,7 +81,7 @@ export class UmbDataTypeFolderRepository extends UmbDataTypeRepositoryBase imple
|
||||
|
||||
async requestFolder(id: string) {
|
||||
if (!id) throw new Error('Key is missing');
|
||||
await this._init;
|
||||
await this.#init;
|
||||
return await this.#folderSource.read(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,40 @@
|
||||
import { UmbDataTypeRepositoryBase } from '../data-type-repository-base.js';
|
||||
import { UMB_DATA_TYPE_TREE_STORE_CONTEXT, UmbDataTypeTreeStore } from '../../tree/data-type.tree.store.js';
|
||||
import { UmbDataTypeMoveServerDataSource } from './data-type-move.server.data-source.js';
|
||||
import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbMoveDataSource, UmbMoveRepository } from '@umbraco-cms/backoffice/repository';
|
||||
import { UmbMoveDataSource, UmbMoveRepository, UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbMoveDataTypeRepository extends UmbDataTypeRepositoryBase implements UmbMoveRepository {
|
||||
export class UmbMoveDataTypeRepository extends UmbRepositoryBase implements UmbMoveRepository {
|
||||
#init: Promise<unknown>;
|
||||
#moveSource: UmbMoveDataSource;
|
||||
#treeStore?: UmbDataTypeTreeStore;
|
||||
#notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.#moveSource = new UmbDataTypeMoveServerDataSource(this);
|
||||
|
||||
this.#init = Promise.all([
|
||||
this.consumeContext(UMB_DATA_TYPE_TREE_STORE_CONTEXT, (instance) => {
|
||||
this.#treeStore = instance;
|
||||
}).asPromise(),
|
||||
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
||||
this.#notificationContext = instance;
|
||||
}).asPromise(),
|
||||
]);
|
||||
}
|
||||
|
||||
async move(unique: string, targetUnique: string | null) {
|
||||
await this._init;
|
||||
await this.#init;
|
||||
const { error } = await this.#moveSource.move(unique, targetUnique);
|
||||
|
||||
if (!error) {
|
||||
// TODO: Be aware about this responsibility.
|
||||
this._treeStore!.updateItem(unique, { parentUnique: targetUnique });
|
||||
this.#treeStore!.updateItem(unique, { parentUnique: targetUnique });
|
||||
|
||||
const notification = { data: { message: `Data type moved` } };
|
||||
this._notificationContext!.peek('positive', notification);
|
||||
this.#notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
|
||||
Reference in New Issue
Block a user