Merge pull request #2122 from umbraco/v14/feature/document-entity-bulk-action-move-to

Feature: Document entity bulk action "move to"
This commit is contained in:
Lee Kelleher
2024-07-17 15:30:50 +01:00
committed by GitHub
8 changed files with 103 additions and 26 deletions

View File

@@ -1,13 +1,15 @@
import { UMB_DOCUMENT_COLLECTION_ALIAS } from '../collection/index.js';
import { UMB_DOCUMENT_ENTITY_TYPE } from '../entity.js';
//import { UMB_DOCUMENT_TREE_ALIAS } from '../tree/manifests.js';
import { manifests as moveToManifests } from './move-to/manifests.js';
import type { UmbCollectionBulkActionPermissions } from '@umbraco-cms/backoffice/collection';
import type { ManifestEntityBulkAction } from '@umbraco-cms/backoffice/extension-registry';
import type { ManifestEntityBulkAction, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
import {
UMB_COLLECTION_ALIAS_CONDITION,
UMB_COLLECTION_BULK_ACTION_PERMISSION_CONDITION,
} from '@umbraco-cms/backoffice/collection';
export const manifests: Array<ManifestEntityBulkAction> = [
export const entityBulkActions: Array<ManifestEntityBulkAction> = [
{
type: 'entityBulkAction',
kind: 'default',
@@ -76,30 +78,6 @@ export const manifests: Array<ManifestEntityBulkAction> = [
],
},
*/
/* TODO: implement bulk move action
{
type: 'entityBulkAction',
kind: 'default',
alias: 'Umb.EntityBulkAction.Document.MoveTo',
name: 'Move Document Entity Bulk Action',
weight: 20,
api: UmbMoveDocumentEntityBulkAction,
meta: {
label: 'Move',
},
forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
conditions: [
{
alias: UMB_COLLECTION_ALIAS_CONDITION,
match: UMB_DOCUMENT_COLLECTION_ALIAS,
},
{
alias: UMB_COLLECTION_BULK_ACTION_PERMISSION_CONDITION,
match: (permissions: UmbCollectionBulkActionPermissions) => permissions.allowBulkMove,
},
],
},
*/
/* TODO: implement bulk trash action
{
type: 'entityBulkAction',
@@ -125,3 +103,5 @@ export const manifests: Array<ManifestEntityBulkAction> = [
},
*/
];
export const manifests: Array<ManifestTypes> = [...entityBulkActions, ...moveToManifests];

View File

@@ -0,0 +1 @@
export const UMB_BULK_MOVE_MEDIA_REPOSITORY_ALIAS = 'Umb.Repository.Media.BulkMove';

View File

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

View File

@@ -0,0 +1,37 @@
import { UMB_DOCUMENT_COLLECTION_ALIAS } from '../../collection/index.js';
import { UMB_DOCUMENT_ENTITY_TYPE } from '../../entity.js';
import { UMB_DOCUMENT_TREE_ALIAS } from '../../tree/manifests.js';
import { UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './repository/constants.js';
import { manifests as repositoryManifests } from './repository/manifests.js';
import {
UMB_COLLECTION_ALIAS_CONDITION,
UMB_COLLECTION_BULK_ACTION_PERMISSION_CONDITION,
} from '@umbraco-cms/backoffice/collection';
import type { UmbCollectionBulkActionPermissions } from '@umbraco-cms/backoffice/collection';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
const bulkMoveAction: ManifestTypes = {
type: 'entityBulkAction',
kind: 'moveTo',
alias: 'Umb.EntityBulkAction.Document.MoveTo',
name: 'Move Document Entity Bulk Action',
weight: 20,
forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
meta: {
bulkMoveRepositoryAlias: UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS,
treeAlias: UMB_DOCUMENT_TREE_ALIAS,
},
conditions: [
{
alias: UMB_COLLECTION_ALIAS_CONDITION,
match: UMB_DOCUMENT_COLLECTION_ALIAS,
},
{
alias: UMB_COLLECTION_BULK_ACTION_PERMISSION_CONDITION,
match: (permissions: UmbCollectionBulkActionPermissions) => permissions.allowBulkMove,
},
],
};
export const manifests: Array<ManifestTypes> = [bulkMoveAction, ...repositoryManifests];

View File

@@ -0,0 +1 @@
export const UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS = 'Umb.Repository.Document.BulkMove';

View File

@@ -0,0 +1,2 @@
export { UmbBulkMoveToDocumentRepository } from './move-to.repository.js';
export { UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';

View File

@@ -0,0 +1,11 @@
import { UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
import type { ManifestRepository, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
const bulkMoveRepository: ManifestRepository = {
type: 'repository',
alias: UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS,
name: 'Bulk Move Document Repository',
api: () => import('./move-to.repository.js'),
};
export const manifests: Array<ManifestTypes> = [bulkMoveRepository];

View File

@@ -0,0 +1,44 @@
import { UmbMoveDocumentServerDataSource } from '../../../entity-actions/move-to/repository/document-move.server.data-source.js';
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
import type { UmbBulkMoveToRepository, UmbBulkMoveToRequestArgs } from '@umbraco-cms/backoffice/entity-bulk-action';
import type { UmbRepositoryErrorResponse } from '@umbraco-cms/backoffice/repository';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
export class UmbBulkMoveToDocumentRepository extends UmbRepositoryBase implements UmbBulkMoveToRepository {
#moveSource = new UmbMoveDocumentServerDataSource(this);
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
constructor(host: UmbControllerHost) {
super(host);
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => {
this.#notificationContext = notificationContext;
});
}
async requestBulkMoveTo(args: UmbBulkMoveToRequestArgs): Promise<UmbRepositoryErrorResponse> {
let count = 0;
const destination = args.destination;
for (const unique of args.uniques) {
const { error } = await this.#moveSource.moveTo({ unique, destination });
if (error) {
const notification = { data: { message: error.message } };
this.#notificationContext?.peek('danger', notification);
} else {
count++;
}
}
if (count > 0) {
const notification = { data: { message: `Moved ${count} ${count === 1 ? 'document' : 'documents'}` } };
this.#notificationContext?.peek('positive', notification);
}
return {};
}
}
export { UmbBulkMoveToDocumentRepository as api };