split out move and copy
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { UmbDataTypeRepositoryBase } from '../data-type-repository-base.js';
|
||||
import { UmbDataTypeCopyServerDataSource } from '../sources/data-type-copy.server.data.js';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbCopyDataSource, UmbCopyRepository } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDataTypeCopyRepository extends UmbDataTypeRepositoryBase implements UmbCopyRepository {
|
||||
#copySource: UmbCopyDataSource;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.#copySource = new UmbDataTypeCopyServerDataSource(this);
|
||||
}
|
||||
|
||||
async copy(id: string, targetId: string | null) {
|
||||
await this._init;
|
||||
const { data: dataTypeCopyId, error } = await this.#copySource.copy(id, targetId);
|
||||
if (error) return { error };
|
||||
|
||||
if (dataTypeCopyId) {
|
||||
const { data: dataTypeCopy } = await this.requestById(dataTypeCopyId);
|
||||
if (!dataTypeCopy) throw new Error('Could not find copied data type');
|
||||
|
||||
// TODO: Be aware about this responsibility.
|
||||
this._treeStore!.appendItems([dataTypeCopy]);
|
||||
// only update the target if its not the root
|
||||
if (targetId) {
|
||||
this._treeStore!.updateItem(targetId, { hasChildren: true });
|
||||
}
|
||||
|
||||
const notification = { data: { message: `Data type copied` } };
|
||||
this._notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { data: dataTypeCopyId };
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,15 @@
|
||||
import { DATA_TYPE_ROOT_ENTITY_TYPE } from '../entities.js';
|
||||
import { UmbDataTypeTreeServerDataSource } from './sources/data-type.tree.server.data.js';
|
||||
import { UmbDataTypeMoveServerDataSource } from './sources/data-type-move.server.data.js';
|
||||
import { UmbDataTypeServerDataSource } from './sources/data-type.server.data.js';
|
||||
import { UmbDataTypeFolderServerDataSource } from './sources/data-type-folder.server.data.js';
|
||||
import { UmbDataTypeCopyServerDataSource } from './sources/data-type-copy.server.data.js';
|
||||
import { UmbDataTypeRepositoryBase } from './data-type-repository-base.js';
|
||||
import type {
|
||||
UmbTreeRepository,
|
||||
UmbDetailRepository,
|
||||
UmbFolderRepository,
|
||||
UmbMoveRepository,
|
||||
UmbCopyRepository,
|
||||
UmbTreeDataSource,
|
||||
UmbDataSource,
|
||||
UmbFolderDataSource,
|
||||
UmbMoveDataSource,
|
||||
UmbCopyDataSource,
|
||||
} from '@umbraco-cms/backoffice/repository';
|
||||
import { type UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import {
|
||||
@@ -33,15 +27,11 @@ export class UmbDataTypeRepository
|
||||
UmbTreeRepository<FolderTreeItemResponseModel>,
|
||||
UmbDetailRepository<CreateDataTypeRequestModel, any, UpdateDataTypeRequestModel, DataTypeResponseModel>,
|
||||
UmbFolderRepository,
|
||||
UmbMoveRepository,
|
||||
UmbCopyRepository,
|
||||
UmbApi
|
||||
{
|
||||
#treeSource: UmbTreeDataSource<FolderTreeItemResponseModel>;
|
||||
#detailSource: UmbDataSource<CreateDataTypeRequestModel, any, UpdateDataTypeRequestModel, DataTypeResponseModel>;
|
||||
#folderSource: UmbFolderDataSource;
|
||||
#moveSource: UmbMoveDataSource;
|
||||
#copySource: UmbCopyDataSource;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
@@ -50,8 +40,6 @@ export class UmbDataTypeRepository
|
||||
this.#treeSource = new UmbDataTypeTreeServerDataSource(this);
|
||||
this.#detailSource = new UmbDataTypeServerDataSource(this);
|
||||
this.#folderSource = new UmbDataTypeFolderServerDataSource(this);
|
||||
this.#moveSource = new UmbDataTypeMoveServerDataSource(this);
|
||||
this.#copySource = new UmbDataTypeCopyServerDataSource(this);
|
||||
}
|
||||
|
||||
// TREE:
|
||||
@@ -259,49 +247,6 @@ export class UmbDataTypeRepository
|
||||
await this._init;
|
||||
return await this.#folderSource.get(id);
|
||||
}
|
||||
|
||||
// Actions
|
||||
async move(id: string, targetId: string | null) {
|
||||
await this._init;
|
||||
const { error } = await this.#moveSource.move(id, targetId);
|
||||
|
||||
if (!error) {
|
||||
// TODO: Be aware about this responsibility.
|
||||
this._treeStore!.updateItem(id, { parentId: targetId });
|
||||
// only update the target if its not the root
|
||||
if (targetId) {
|
||||
this._treeStore!.updateItem(targetId, { hasChildren: true });
|
||||
}
|
||||
|
||||
const notification = { data: { message: `Data type moved` } };
|
||||
this._notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
|
||||
async copy(id: string, targetId: string | null) {
|
||||
await this._init;
|
||||
const { data: dataTypeCopyId, error } = await this.#copySource.copy(id, targetId);
|
||||
if (error) return { error };
|
||||
|
||||
if (dataTypeCopyId) {
|
||||
const { data: dataTypeCopy } = await this.requestById(dataTypeCopyId);
|
||||
if (!dataTypeCopy) throw new Error('Could not find copied data type');
|
||||
|
||||
// TODO: Be aware about this responsibility.
|
||||
this._treeStore!.appendItems([dataTypeCopy]);
|
||||
// only update the target if its not the root
|
||||
if (targetId) {
|
||||
this._treeStore!.updateItem(targetId, { hasChildren: true });
|
||||
}
|
||||
|
||||
const notification = { data: { message: `Data type copied` } };
|
||||
this._notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { data: dataTypeCopyId };
|
||||
}
|
||||
}
|
||||
|
||||
export const createTreeItem = (item: CreateDataTypeRequestModel): FolderTreeItemResponseModel => {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { UmbDataTypeRepositoryBase } from '../data-type-repository-base.js';
|
||||
import { UmbDataTypeMoveServerDataSource } from '../sources/data-type-move.server.data.js';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbMoveDataSource, UmbMoveRepository } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDataTypeMoveRepository extends UmbDataTypeRepositoryBase implements UmbMoveRepository {
|
||||
#moveSource: UmbMoveDataSource;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.#moveSource = new UmbDataTypeMoveServerDataSource(this);
|
||||
}
|
||||
|
||||
async move(id: string, targetId: string | null) {
|
||||
await this._init;
|
||||
const { error } = await this.#moveSource.move(id, targetId);
|
||||
|
||||
if (!error) {
|
||||
// TODO: Be aware about this responsibility.
|
||||
this._treeStore!.updateItem(id, { parentId: targetId });
|
||||
// only update the target if its not the root
|
||||
if (targetId) {
|
||||
this._treeStore!.updateItem(targetId, { hasChildren: true });
|
||||
}
|
||||
|
||||
const notification = { data: { message: `Data type moved` } };
|
||||
this._notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user