add create and delete entity actions
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { UmbEntityActionBase } from '..';
|
||||
import { UmbContextConsumerController } from '@umbraco-cms/context-api';
|
||||
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
import { UmbModalService, UMB_MODAL_SERVICE_CONTEXT_TOKEN } from '@umbraco-cms/modal';
|
||||
|
||||
export class UmbDeleteEntityAction<
|
||||
T extends { delete(unique: string): Promise<void>; requestTreeItems(uniques: Array<string>): any }
|
||||
> extends UmbEntityActionBase<T> {
|
||||
#modalService?: UmbModalService;
|
||||
|
||||
constructor(host: UmbControllerHostInterface, repositoryAlias: string, unique: string) {
|
||||
super(host, repositoryAlias, unique);
|
||||
|
||||
new UmbContextConsumerController(this.host, UMB_MODAL_SERVICE_CONTEXT_TOKEN, (instance) => {
|
||||
this.#modalService = instance;
|
||||
});
|
||||
}
|
||||
|
||||
async execute() {
|
||||
if (!this.repository) return;
|
||||
|
||||
const { data } = await this.repository.requestTreeItems([this.unique]);
|
||||
|
||||
if (data) {
|
||||
const item = data[0];
|
||||
|
||||
const modalHandler = this.#modalService?.confirm({
|
||||
headline: `Delete ${item.name}`,
|
||||
content: 'Are you sure you want to delete this item?',
|
||||
color: 'danger',
|
||||
confirmLabel: 'Delete',
|
||||
});
|
||||
|
||||
modalHandler?.onClose().then(({ confirmed }) => {
|
||||
if (confirmed) {
|
||||
this.repository?.delete(this.unique);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
import { UmbModalService, UMB_MODAL_SERVICE_CONTEXT_TOKEN } from '@umbraco-cms/modal';
|
||||
|
||||
export class UmbTrashEntityAction<
|
||||
T extends { trash(unique: string): Promise<void>; requestTreeItems(uniques: Array<string>): any }
|
||||
T extends { trash(unique: Array<string>): Promise<void>; requestTreeItems(uniques: Array<string>): any }
|
||||
> extends UmbEntityActionBase<T> {
|
||||
#modalService?: UmbModalService;
|
||||
|
||||
@@ -25,15 +25,15 @@ export class UmbTrashEntityAction<
|
||||
const item = data[0];
|
||||
|
||||
const modalHandler = this.#modalService?.confirm({
|
||||
headline: `Delete ${item.name}`,
|
||||
content: 'Are you sure you want to delete this item?',
|
||||
headline: `Trash ${item.name}`,
|
||||
content: 'Are you sure you want to move this item to the recycle bin?',
|
||||
color: 'danger',
|
||||
confirmLabel: 'Delete',
|
||||
confirmLabel: 'Trash',
|
||||
});
|
||||
|
||||
modalHandler?.onClose().then(({ confirmed }) => {
|
||||
if (confirmed) {
|
||||
this.repository?.trash(this.unique);
|
||||
this.repository?.trash([this.unique]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { UmbEntityActionBase } from '../../../../shared/entity-actions';
|
||||
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
|
||||
export class UmbCreateEntityAction<T extends { copy(): Promise<void> }> extends UmbEntityActionBase<T> {
|
||||
constructor(host: UmbControllerHostInterface, repositoryAlias: string, unique: string) {
|
||||
super(host, repositoryAlias, unique);
|
||||
}
|
||||
|
||||
// TODO: can we make this a generic create action
|
||||
async execute() {
|
||||
// TODO: get entity type from repository?
|
||||
const url = `section/settings/template/create/${this.unique || 'root'}`;
|
||||
// TODO: how do we handle this with a href?
|
||||
history.pushState(null, '', url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { UmbDeleteEntityAction } from '../../../shared/entity-actions/delete/delete.action';
|
||||
import { UmbCreateEntityAction } from './create/create.action';
|
||||
import { ManifestEntityAction } from 'libs/extensions-registry/entity-action.models';
|
||||
|
||||
const entityActions: Array<ManifestEntityAction> = [
|
||||
{
|
||||
type: 'entityAction',
|
||||
alias: 'Umb.EntityAction.Template.Create',
|
||||
name: 'Create Template Entity Action',
|
||||
meta: {
|
||||
entityType: 'template',
|
||||
icon: 'umb:add',
|
||||
label: 'Create',
|
||||
api: UmbCreateEntityAction,
|
||||
repositoryAlias: 'Umb.Repository.Templates',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'entityAction',
|
||||
alias: 'Umb.EntityAction.Template.Delete',
|
||||
name: 'Delete Template Entity Action',
|
||||
meta: {
|
||||
entityType: 'template',
|
||||
icon: 'umb:trash',
|
||||
label: 'Delete',
|
||||
api: UmbDeleteEntityAction,
|
||||
repositoryAlias: 'Umb.Repository.Templates',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions];
|
||||
@@ -1,6 +1,13 @@
|
||||
import { manifests as repositoryManifests } from './repository/manifests';
|
||||
import { manifests as sidebarMenuItemManifests } from './sidebar-menu-item/manifests';
|
||||
import { manifests as treeManifests } from './tree/manifests';
|
||||
import { manifests as entityActionsManifests } from './entity-actions/manifests';
|
||||
import { manifests as workspaceManifests } from './workspace/manifests';
|
||||
|
||||
export const manifests = [...repositoryManifests, ...sidebarMenuItemManifests, ...treeManifests, ...workspaceManifests];
|
||||
export const manifests = [
|
||||
...repositoryManifests,
|
||||
...sidebarMenuItemManifests,
|
||||
...treeManifests,
|
||||
...entityActionsManifests,
|
||||
...workspaceManifests,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user