register generic copy entity action
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
import { UmbCopyEntityAction } from './copy.action.js';
|
||||||
|
import type { UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||||
|
|
||||||
|
export const manifest: UmbBackofficeManifestKind = {
|
||||||
|
type: 'kind',
|
||||||
|
alias: 'Umb.Kind.EntityAction.Copy',
|
||||||
|
matchKind: 'copy',
|
||||||
|
matchType: 'entityAction',
|
||||||
|
manifest: {
|
||||||
|
type: 'entityAction',
|
||||||
|
kind: 'copy',
|
||||||
|
api: UmbCopyEntityAction,
|
||||||
|
weight: 900,
|
||||||
|
meta: {
|
||||||
|
icon: 'icon-trash',
|
||||||
|
label: 'Delete...',
|
||||||
|
entityTypes: [],
|
||||||
|
itemRepositoryAlias: '',
|
||||||
|
copyRepositoryAlias: '',
|
||||||
|
pickerModalAlias: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,13 +1,55 @@
|
|||||||
import { UmbEntityActionBase } from '../../entity-action-base.js';
|
import { UmbEntityActionBase } from '../../entity-action-base.js';
|
||||||
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||||
|
import type { UmbEntityActionArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||||
|
import { UmbExtensionApiInitializer } from '@umbraco-cms/backoffice/extension-api';
|
||||||
|
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||||
|
import type { MetaEntityActionCopyKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||||
|
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||||
|
import type { UmbCopyRepository, UmbItemRepository } from '@umbraco-cms/backoffice/repository';
|
||||||
|
|
||||||
export class UmbCopyEntityAction extends UmbEntityActionBase<any> {
|
export class UmbCopyEntityAction extends UmbEntityActionBase<MetaEntityActionCopyKind> {
|
||||||
constructor(host: UmbControllerHostElement, args: any) {
|
// TODO: make base type for item and detail models
|
||||||
|
#itemRepository?: UmbItemRepository<any>;
|
||||||
|
#copyRepository?: UmbCopyRepository;
|
||||||
|
#init: Promise<unknown>;
|
||||||
|
|
||||||
|
constructor(host: UmbControllerHost, args: UmbEntityActionArgs<MetaEntityActionCopyKind>) {
|
||||||
super(host, args);
|
super(host, args);
|
||||||
|
|
||||||
|
// TODO: We should properly look into how we can simplify the one time usage of a extension api, as its a bit of overkill to take conditions/overwrites and observation of extensions into play here: [NL]
|
||||||
|
// But since this happens when we execute an action, it does most likely not hurt any users, but it is a bit of a overkill to do this for every action: [NL]
|
||||||
|
this.#init = Promise.all([
|
||||||
|
new UmbExtensionApiInitializer(
|
||||||
|
this._host,
|
||||||
|
umbExtensionsRegistry,
|
||||||
|
this.args.meta.itemRepositoryAlias,
|
||||||
|
[this._host],
|
||||||
|
(permitted, ctrl) => {
|
||||||
|
this.#itemRepository = permitted ? (ctrl.api as UmbItemRepository<any>) : undefined;
|
||||||
|
},
|
||||||
|
).asPromise(),
|
||||||
|
|
||||||
|
new UmbExtensionApiInitializer(
|
||||||
|
this._host,
|
||||||
|
umbExtensionsRegistry,
|
||||||
|
this.args.meta.copyRepositoryAlias,
|
||||||
|
[this._host],
|
||||||
|
(permitted, ctrl) => {
|
||||||
|
this.#copyRepository = permitted ? (ctrl.api as UmbCopyRepository) : undefined;
|
||||||
|
},
|
||||||
|
).asPromise(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute() {
|
async execute() {
|
||||||
console.log(`execute copy for: ${this.args.unique}`);
|
if (!this.args.unique) throw new Error('Unique is not available');
|
||||||
|
await this.#init;
|
||||||
|
|
||||||
|
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
|
||||||
|
const modalContext = modalManager.open(this, this.args.meta.pickerModalAlias) as any; // TODO: make generic picker interface with selection
|
||||||
|
const value = await modalContext.onSubmit();
|
||||||
|
if (!value) return;
|
||||||
|
await this.#copyRepository!.copy(this.args.unique, value.selection[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy(): void {}
|
destroy(): void {}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { manifest as copyKindManifest } from './copy.action.kind.js';
|
||||||
|
|
||||||
|
export const manifests = [copyKindManifest];
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { manifest as deleteKindManifest } from './delete.action.kind.js';
|
||||||
|
|
||||||
|
export const manifests = [deleteKindManifest];
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
export * from './copy/copy.action.js';
|
export * from './copy/copy.action.js';
|
||||||
export * from './delete/delete.action.js';
|
export * from './delete/delete.action.js';
|
||||||
export * from './move/move.action.js';
|
export * from './move/move.action.js';
|
||||||
|
export * from './rename/index.js';
|
||||||
export * from './sort-children-of/sort-children-of.action.js';
|
export * from './sort-children-of/sort-children-of.action.js';
|
||||||
export * from './trash/trash.action.js';
|
export * from './trash/trash.action.js';
|
||||||
export * from './rename/index.js';
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
import { manifests as renameModalManifests } from './modal/manifests.js';
|
import { manifests as renameModalManifests } from './modal/manifests.js';
|
||||||
|
import { manifest as renameKindManifest } from './rename.action.kind.js';
|
||||||
|
|
||||||
export const manifests = [...renameModalManifests];
|
export const manifests = [...renameModalManifests, renameKindManifest];
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
import { manifests as copyEntityActionManifests } from './common/copy/manifests.js';
|
||||||
|
import { manifests as deleteEntityActionManifests } from './common/delete/manifests.js';
|
||||||
import { manifests as renameEntityActionManifests } from './common/rename/manifests.js';
|
import { manifests as renameEntityActionManifests } from './common/rename/manifests.js';
|
||||||
import { manifest as deleteEntityActionManifest } from './common/delete/delete.action.kind.js';
|
|
||||||
|
|
||||||
export const manifests = [...renameEntityActionManifests, deleteEntityActionManifest];
|
export const manifests = [...copyEntityActionManifests, ...renameEntityActionManifests, deleteEntityActionManifests];
|
||||||
|
|||||||
@@ -66,3 +66,16 @@ export interface ManifestEntityActionReloadTreeItemChildrenKind extends Manifest
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MetaEntityActionReloadTreeItemChildrenKind extends MetaEntityAction {}
|
export interface MetaEntityActionReloadTreeItemChildrenKind extends MetaEntityAction {}
|
||||||
|
|
||||||
|
// COPY
|
||||||
|
export interface ManifestEntityActionCopyKind extends ManifestEntityAction {
|
||||||
|
type: 'entityAction';
|
||||||
|
kind: 'copy';
|
||||||
|
meta: MetaEntityActionCopyKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MetaEntityActionCopyKind extends MetaEntityAction {
|
||||||
|
copyRepositoryAlias: string;
|
||||||
|
itemRepositoryAlias: string;
|
||||||
|
pickerModalAlias: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
ManifestEntityActionDeleteKind,
|
ManifestEntityActionDeleteKind,
|
||||||
ManifestEntityActionRenameKind,
|
ManifestEntityActionRenameKind,
|
||||||
ManifestEntityActionReloadTreeItemChildrenKind,
|
ManifestEntityActionReloadTreeItemChildrenKind,
|
||||||
|
ManifestEntityActionCopyKind,
|
||||||
} from './entity-action.model.js';
|
} from './entity-action.model.js';
|
||||||
import type { ManifestDynamicRootOrigin, ManifestDynamicRootQueryStep } from './dynamic-root.model.js';
|
import type { ManifestDynamicRootOrigin, ManifestDynamicRootQueryStep } from './dynamic-root.model.js';
|
||||||
import type { ManifestEntityBulkAction } from './entity-bulk-action.model.js';
|
import type { ManifestEntityBulkAction } from './entity-bulk-action.model.js';
|
||||||
@@ -102,6 +103,7 @@ export type ManifestTypes =
|
|||||||
| ManifestEntityActionDeleteKind
|
| ManifestEntityActionDeleteKind
|
||||||
| ManifestEntityActionRenameKind
|
| ManifestEntityActionRenameKind
|
||||||
| ManifestEntityActionReloadTreeItemChildrenKind
|
| ManifestEntityActionReloadTreeItemChildrenKind
|
||||||
|
| ManifestEntityActionCopyKind
|
||||||
| ManifestEntityBulkAction
|
| ManifestEntityBulkAction
|
||||||
| ManifestEntryPoint
|
| ManifestEntryPoint
|
||||||
| ManifestExternalLoginProvider
|
| ManifestExternalLoginProvider
|
||||||
|
|||||||
Reference in New Issue
Block a user