add move for document types

This commit is contained in:
Mads Rasmussen
2024-04-11 13:36:26 +02:00
parent 7c22d43331
commit 1a1f6bc879
8 changed files with 108 additions and 17 deletions

View File

@@ -1,40 +1,28 @@
import { UMB_DOCUMENT_TYPE_ENTITY_TYPE } from '../entity.js';
import { DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '../repository/index.js';
import { manifests as createManifests } from './create/manifests.js';
import { manifests as moveManifests } from './move-to/manifests.js';
import { UMB_DOCUMENT_TYPE_PICKER_MODAL } from '@umbraco-cms/backoffice/document-type';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
const entityType = 'document-type';
const entityActions: Array<ManifestTypes> = [
{
type: 'entityAction',
kind: 'delete',
alias: 'Umb.EntityAction.DocumentType.Delete',
name: 'Delete Document-Type Entity Action',
forEntityTypes: [entityType],
forEntityTypes: [UMB_DOCUMENT_TYPE_ENTITY_TYPE],
meta: {
itemRepositoryAlias: DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
detailRepositoryAlias: DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS,
},
},
{
type: 'entityAction',
kind: 'moveTo',
alias: 'Umb.EntityAction.DocumentType.MoveTo',
name: 'Move Document Type Entity Action',
forEntityTypes: [entityType],
meta: {
itemRepositoryAlias: DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
moveRepositoryAlias: DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS,
pickerModal: UMB_DOCUMENT_TYPE_PICKER_MODAL,
},
},
{
type: 'entityAction',
kind: 'duplicate',
alias: 'Umb.EntityAction.DocumentType.Duplicate',
name: 'Duplicate Document Type Entity Action',
forEntityTypes: [entityType],
forEntityTypes: [UMB_DOCUMENT_TYPE_ENTITY_TYPE],
meta: {
itemRepositoryAlias: DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
duplicateRepositoryAlias: DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS,
@@ -43,4 +31,4 @@ const entityActions: Array<ManifestTypes> = [
},
];
export const manifests = [...entityActions, ...createManifests];
export const manifests = [...entityActions, ...createManifests, ...moveManifests];

View File

@@ -0,0 +1 @@
export { UmbMoveDocumentTypeRepository, UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './repository/index.js';

View File

@@ -0,0 +1,23 @@
import { UMB_DOCUMENT_TYPE_ENTITY_TYPE } from '../../entity.js';
import { UMB_DOCUMENT_TYPE_PICKER_MODAL } from '../../modals/document-type-picker-modal.token.js';
import { UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
import { UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
import { manifests as repositoryManifests } from './repository/manifests.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
const entityActions: Array<ManifestTypes> = [
{
type: 'entityAction',
kind: 'moveTo',
alias: 'Umb.EntityAction.DocumentType.Move',
name: 'Move Document Type Entity Action',
forEntityTypes: [UMB_DOCUMENT_TYPE_ENTITY_TYPE],
meta: {
treeRepositoryAlias: UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS,
moveToRepositoryAlias: UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS,
treePickerModal: UMB_DOCUMENT_TYPE_PICKER_MODAL,
},
},
];
export const manifests = [...entityActions, ...repositoryManifests];

View File

@@ -0,0 +1 @@
export const UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DocumentType.Move';

View File

@@ -0,0 +1,20 @@
import { UmbDocumentTypeMoveServerDataSource } from './document-type-move.server.data-source.js';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
import type { UmbMoveToRepository, UmbMoveToRequestArgs } from '@umbraco-cms/backoffice/repository';
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
export class UmbMoveDocumentTypeRepository extends UmbRepositoryBase implements UmbMoveToRepository {
#moveSource = new UmbDocumentTypeMoveServerDataSource(this);
async requestMove(args: UmbMoveToRequestArgs) {
const { error } = await this.#moveSource.move(args);
if (!error) {
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
const notification = { data: { message: `Moved` } };
notificationContext.peek('positive', notification);
}
return { error };
}
}

View File

@@ -0,0 +1,44 @@
import { DocumentTypeService } from '@umbraco-cms/backoffice/external/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
import type { UmbMoveToDataSource, UmbMoveToRequestArgs } from '@umbraco-cms/backoffice/repository';
/**
* Move DocumentType Server Data Source
* @export
* @class UmbDocumentTypeMoveServerDataSource
*/
export class UmbDocumentTypeMoveServerDataSource implements UmbMoveToDataSource {
#host: UmbControllerHost;
/**
* Creates an instance of UmbDocumentTypeMoveServerDataSource.
* @param {UmbControllerHost} host
* @memberof UmbDocumentTypeMoveServerDataSource
*/
constructor(host: UmbControllerHost) {
this.#host = host;
}
/**
* Move an item for the given id to the target unique
* @param {string} unique
* @param {(string | null)} targetUnique
* @return {*}
* @memberof UmbDocumentTypeMoveServerDataSource
*/
async move(args: UmbMoveToRequestArgs) {
if (!args.unique) throw new Error('Unique is missing');
if (args.destination.unique === undefined) throw new Error('Destination unique is missing');
return tryExecuteAndNotify(
this.#host,
DocumentTypeService.putDocumentTypeByIdMove({
id: args.unique,
requestBody: {
target: args.destination.unique ? { id: args.destination.unique } : null,
},
}),
);
}
}

View File

@@ -0,0 +1,2 @@
export { UmbMoveDocumentTypeRepository } from './document-type-move.repository.js';
export { UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './constants.js';

View File

@@ -0,0 +1,12 @@
import { UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './constants.js';
import { UmbMoveDocumentTypeRepository } from './document-type-move.repository.js';
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
const moveRepository: ManifestRepository = {
type: 'repository',
alias: UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS,
name: 'Move Document Type Repository',
api: UmbMoveDocumentTypeRepository,
};
export const manifests = [moveRepository];