diff --git a/src/packages/documents/documents/entity-bulk-actions/manifests.ts b/src/packages/documents/documents/entity-bulk-actions/manifests.ts index 1ea725ee64..1053c25ce1 100644 --- a/src/packages/documents/documents/entity-bulk-actions/manifests.ts +++ b/src/packages/documents/documents/entity-bulk-actions/manifests.ts @@ -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 = [ +export const entityBulkActions: Array = [ { type: 'entityBulkAction', kind: 'default', @@ -76,30 +78,6 @@ export const manifests: Array = [ ], }, */ - /* 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 = [ }, */ ]; + +export const manifests: Array = [...entityBulkActions, ...moveToManifests]; diff --git a/src/packages/documents/documents/entity-bulk-actions/move-to/constants.ts b/src/packages/documents/documents/entity-bulk-actions/move-to/constants.ts new file mode 100644 index 0000000000..4037b48892 --- /dev/null +++ b/src/packages/documents/documents/entity-bulk-actions/move-to/constants.ts @@ -0,0 +1 @@ +export const UMB_BULK_MOVE_MEDIA_REPOSITORY_ALIAS = 'Umb.Repository.Media.BulkMove'; diff --git a/src/packages/documents/documents/entity-bulk-actions/move-to/index.ts b/src/packages/documents/documents/entity-bulk-actions/move-to/index.ts new file mode 100644 index 0000000000..91b4f3a861 --- /dev/null +++ b/src/packages/documents/documents/entity-bulk-actions/move-to/index.ts @@ -0,0 +1 @@ +export { UmbBulkMoveToDocumentRepository, UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './repository/index.js'; diff --git a/src/packages/documents/documents/entity-bulk-actions/move-to/manifests.ts b/src/packages/documents/documents/entity-bulk-actions/move-to/manifests.ts new file mode 100644 index 0000000000..9dfba6f60a --- /dev/null +++ b/src/packages/documents/documents/entity-bulk-actions/move-to/manifests.ts @@ -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 = [bulkMoveAction, ...repositoryManifests]; diff --git a/src/packages/documents/documents/entity-bulk-actions/move-to/repository/constants.ts b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/constants.ts new file mode 100644 index 0000000000..1a97d3b4c2 --- /dev/null +++ b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/constants.ts @@ -0,0 +1 @@ +export const UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS = 'Umb.Repository.Document.BulkMove'; diff --git a/src/packages/documents/documents/entity-bulk-actions/move-to/repository/index.ts b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/index.ts new file mode 100644 index 0000000000..6d61dfcc9c --- /dev/null +++ b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/index.ts @@ -0,0 +1,2 @@ +export { UmbBulkMoveToDocumentRepository } from './move-to.repository.js'; +export { UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js'; diff --git a/src/packages/documents/documents/entity-bulk-actions/move-to/repository/manifests.ts b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/manifests.ts new file mode 100644 index 0000000000..b9e609a144 --- /dev/null +++ b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/manifests.ts @@ -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 = [bulkMoveRepository]; diff --git a/src/packages/documents/documents/entity-bulk-actions/move-to/repository/move-to.repository.ts b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/move-to.repository.ts new file mode 100644 index 0000000000..f791fe10c1 --- /dev/null +++ b/src/packages/documents/documents/entity-bulk-actions/move-to/repository/move-to.repository.ts @@ -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 { + 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 };