Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Document entity bulk action "move to" #2122

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions src/packages/documents/documents/entity-bulk-actions/manifests.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -125,3 +103,5 @@ export const manifests: Array<ManifestEntityBulkAction> = [
},
*/
];

export const manifests: Array<ManifestTypes> = [...entityBulkActions, ...moveToManifests];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const UMB_BULK_MOVE_MEDIA_REPOSITORY_ALIAS = 'Umb.Repository.Media.BulkMove';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { UmbBulkMoveToDocumentRepository, UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './repository/index.js';
Original file line number Diff line number Diff line change
@@ -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];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS = 'Umb.Repository.Document.BulkMove';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { UmbBulkMoveToDocumentRepository } from './move-to.repository.js';
export { UMB_BULK_MOVE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
Original file line number Diff line number Diff line change
@@ -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];
Original file line number Diff line number Diff line change
@@ -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 };
Loading