From 6645ecb41c68feaeec6bdd125a38e651aa201142 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 8 Feb 2023 11:13:43 +0100 Subject: [PATCH] add create and delete entity actions --- .../entity-actions/delete/delete.action.ts | 41 +++++++++++++++++++ .../entity-actions/trash/trash.action.ts | 10 ++--- .../entity-actions/create/create.action.ts | 16 ++++++++ .../templates/entity-actions/manifests.ts | 32 +++++++++++++++ .../templating/templates/manifests.ts | 9 +++- 5 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/delete/delete.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/create/create.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/manifests.ts diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/delete/delete.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/delete/delete.action.ts new file mode 100644 index 0000000000..bc416bb2c8 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/delete/delete.action.ts @@ -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; requestTreeItems(uniques: Array): any } +> extends UmbEntityActionBase { + #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); + } + }); + } + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/trash/trash.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/trash/trash.action.ts index 409f9273ac..626452118d 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/trash/trash.action.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/entity-actions/trash/trash.action.ts @@ -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; requestTreeItems(uniques: Array): any } + T extends { trash(unique: Array): Promise; requestTreeItems(uniques: Array): any } > extends UmbEntityActionBase { #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]); } }); } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/create/create.action.ts new file mode 100644 index 0000000000..12af1d77c2 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/create/create.action.ts @@ -0,0 +1,16 @@ +import { UmbEntityActionBase } from '../../../../shared/entity-actions'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; + +export class UmbCreateEntityAction }> extends UmbEntityActionBase { + 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); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/manifests.ts new file mode 100644 index 0000000000..35518ab257 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/entity-actions/manifests.ts @@ -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 = [ + { + 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]; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/manifests.ts index 7fddd3f55d..9ca5faf660 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/templating/templates/manifests.ts @@ -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, +];