Implements Document "duplicate to" entity bulk action
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export {
|
||||
UmbBulkDuplicateToDocumentRepository,
|
||||
UMB_BULK_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS,
|
||||
} from './repository/index.js';
|
||||
@@ -0,0 +1,36 @@
|
||||
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_DUPLICATE_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 bulkDuplicateAction: ManifestTypes = {
|
||||
type: 'entityBulkAction',
|
||||
kind: 'duplicateTo',
|
||||
alias: 'Umb.EntityBulkAction.Document.DuplicateTo',
|
||||
name: 'Duplicate Document Entity Bulk Action',
|
||||
weight: 30,
|
||||
forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
|
||||
meta: {
|
||||
bulkDuplicateRepositoryAlias: UMB_BULK_DUPLICATE_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.allowBulkCopy,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const manifests: Array<ManifestTypes> = [bulkDuplicateAction, ...repositoryManifests];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_BULK_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS = 'Umb.Repository.Document.BulkDuplicate';
|
||||
@@ -0,0 +1,49 @@
|
||||
import { UmbDuplicateDocumentServerDataSource } from '../../../entity-actions/duplicate/repository/document-duplicate.server.data-source.js';
|
||||
import type { UmbBulkDuplicateToDocumentRequestArgs } from './types.js';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbBulkDuplicateToRepository } 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 UmbBulkDuplicateToDocumentRepository extends UmbRepositoryBase implements UmbBulkDuplicateToRepository {
|
||||
#duplicateSource = new UmbDuplicateDocumentServerDataSource(this);
|
||||
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => {
|
||||
this.#notificationContext = notificationContext;
|
||||
});
|
||||
}
|
||||
|
||||
async requestBulkDuplicateTo(args: UmbBulkDuplicateToDocumentRequestArgs): Promise<UmbRepositoryErrorResponse> {
|
||||
let count = 0;
|
||||
|
||||
for (const unique of args.uniques) {
|
||||
const { error } = await this.#duplicateSource.duplicate({
|
||||
unique,
|
||||
destination: args.destination,
|
||||
relateToOriginal: args.relateToOriginal,
|
||||
includeDescendants: args.includeDescendants,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
const notification = { data: { message: error.message } };
|
||||
this.#notificationContext?.peek('danger', notification);
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
const notification = { data: { message: `Duplicated ${count} ${count === 1 ? 'document' : 'documents'}` } };
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export { UmbBulkDuplicateToDocumentRepository as api };
|
||||
@@ -0,0 +1,2 @@
|
||||
export { UmbBulkDuplicateToDocumentRepository } from './duplicate-to.repository.js';
|
||||
export { UMB_BULK_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
|
||||
@@ -0,0 +1,11 @@
|
||||
import { UMB_BULK_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
|
||||
import type { ManifestRepository, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const bulkDuplicateRepository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_BULK_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS,
|
||||
name: 'Bulk Duplicate Media Repository',
|
||||
api: () => import('./duplicate-to.repository.js'),
|
||||
};
|
||||
|
||||
export const manifests: Array<ManifestTypes> = [bulkDuplicateRepository];
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { UmbBulkDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-bulk-action';
|
||||
|
||||
export interface UmbBulkDuplicateToDocumentRequestArgs extends UmbBulkDuplicateToRequestArgs {
|
||||
relateToOriginal: boolean;
|
||||
includeDescendants: boolean;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-bulk-action';
|
||||
|
||||
export class UmbDocumentDuplicateEntityBulkAction extends UmbEntityBulkActionBase<object> {
|
||||
async execute() {
|
||||
console.log('execute bulk duplicate');
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
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 duplicateToManifests } from './duplicate-to/manifests.js';
|
||||
import { manifests as moveToManifests } from './move-to/manifests.js';
|
||||
import type { UmbCollectionBulkActionPermissions } from '@umbraco-cms/backoffice/collection';
|
||||
import type { ManifestEntityBulkAction, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
@@ -54,30 +54,6 @@ export const entityBulkActions: Array<ManifestEntityBulkAction> = [
|
||||
},
|
||||
],
|
||||
},
|
||||
/* TODO: implement bulk duplicate action
|
||||
{
|
||||
type: 'entityBulkAction',
|
||||
kind: 'default',
|
||||
alias: 'Umb.EntityBulkAction.Document.Duplicate',
|
||||
name: 'Duplicate Document Entity Bulk Action',
|
||||
weight: 30,
|
||||
api: UmbDocumentDuplicateEntityBulkAction,
|
||||
meta: {
|
||||
label: 'Duplicate...',
|
||||
},
|
||||
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.allowBulkCopy,
|
||||
},
|
||||
],
|
||||
},
|
||||
*/
|
||||
/* TODO: implement bulk trash action
|
||||
{
|
||||
type: 'entityBulkAction',
|
||||
@@ -104,4 +80,4 @@ export const entityBulkActions: Array<ManifestEntityBulkAction> = [
|
||||
*/
|
||||
];
|
||||
|
||||
export const manifests: Array<ManifestTypes> = [...entityBulkActions, ...moveToManifests];
|
||||
export const manifests: Array<ManifestTypes> = [...entityBulkActions, ...duplicateToManifests, ...moveToManifests];
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { UmbEntityBulkActionBase } from '@umbraco-cms/backoffice/entity-bulk-action';
|
||||
|
||||
export class UmbMoveDocumentEntityBulkAction extends UmbEntityBulkActionBase<object> {
|
||||
async execute() {
|
||||
console.log(`execute bulk move`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user