add move document
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export { UmbMoveDocumentRepository, UMB_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
@@ -0,0 +1,23 @@
|
||||
import { UMB_DOCUMENT_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_DOCUMENT_PICKER_MODAL } from '../../modals/document-picker-modal.token.js';
|
||||
import { UMB_DOCUMENT_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_MOVE_DOCUMENT_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.Document.Move',
|
||||
name: 'Move Document Entity Action',
|
||||
forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
|
||||
meta: {
|
||||
treeRepositoryAlias: UMB_DOCUMENT_TREE_REPOSITORY_ALIAS,
|
||||
moveToRepositoryAlias: UMB_MOVE_DOCUMENT_REPOSITORY_ALIAS,
|
||||
treePickerModal: UMB_DOCUMENT_PICKER_MODAL,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions, ...repositoryManifests];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_MOVE_DOCUMENT_REPOSITORY_ALIAS = 'Umb.Repository.Document.Move';
|
||||
@@ -0,0 +1,20 @@
|
||||
import { UmbMoveDocumentServerDataSource } from './document-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 UmbMoveDocumentRepository extends UmbRepositoryBase implements UmbMoveToRepository {
|
||||
#moveSource = new UmbMoveDocumentServerDataSource(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 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { DocumentService } 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 Document Server Data Source
|
||||
* @export
|
||||
* @class UmbMoveDocumentServerDataSource
|
||||
*/
|
||||
export class UmbMoveDocumentServerDataSource implements UmbMoveToDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbMoveDocumentServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbMoveDocumentServerDataSource
|
||||
*/
|
||||
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 UmbMoveDocumentServerDataSource
|
||||
*/
|
||||
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,
|
||||
DocumentService.putDocumentByIdMove({
|
||||
id: args.unique,
|
||||
requestBody: {
|
||||
target: args.destination.unique ? { id: args.destination.unique } : null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { UmbMoveDocumentRepository } from './document-move.repository.js';
|
||||
export { UMB_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
|
||||
@@ -0,0 +1,12 @@
|
||||
import { UMB_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
|
||||
import { UmbMoveDocumentRepository } from './document-move.repository.js';
|
||||
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const moveRepository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_MOVE_DOCUMENT_REPOSITORY_ALIAS,
|
||||
name: 'Move Document Repository',
|
||||
api: UmbMoveDocumentRepository,
|
||||
};
|
||||
|
||||
export const manifests = [moveRepository];
|
||||
Reference in New Issue
Block a user