diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts index 14db77d673..f2bbc5b626 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts @@ -1,5 +1,5 @@ import { - DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, + UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, type UmbDocumentTypeItemModel, } from '@umbraco-cms/backoffice/document-type'; import { html, customElement, property, state, ifDefined } from '@umbraco-cms/backoffice/external/lit'; @@ -11,7 +11,7 @@ export class UmbBlockTypeCardElement extends UmbLitElement { // #itemManager = new UmbRepositoryItemsManager( this, - DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, + UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, (x) => x.unique, ); diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts index 16d2b502ae..2bc3df350f 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/workspace/block-type-workspace-editor.element.ts @@ -4,14 +4,14 @@ import { customElement, css, html, state, property } from '@umbraco-cms/backoffi import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; import { UmbRepositoryItemsManager } from '@umbraco-cms/backoffice/repository'; import type { UmbDocumentTypeItemModel } from '@umbraco-cms/backoffice/document-type'; -import { DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '@umbraco-cms/backoffice/document-type'; +import { UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '@umbraco-cms/backoffice/document-type'; @customElement('umb-block-type-workspace-editor') export class UmbBlockTypeWorkspaceEditorElement extends UmbLitElement { // #itemManager = new UmbRepositoryItemsManager( this, - DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, + UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, (x) => x.unique, ); diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/components/input-document-type/input-document-type.context.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/components/input-document-type/input-document-type.context.ts index 6e890c91bf..ac987fa0eb 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/components/input-document-type/input-document-type.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/components/input-document-type/input-document-type.context.ts @@ -1,5 +1,5 @@ import type { UmbDocumentTypeItemModel } from '../../repository/index.js'; -import { DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '../../repository/index.js'; +import { UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '../../repository/index.js'; import { UmbPickerInputContext } from '@umbraco-cms/backoffice/picker-input'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UMB_DOCUMENT_TYPE_PICKER_MODAL } from '@umbraco-cms/backoffice/document-type'; @@ -8,6 +8,6 @@ export class UmbDocumentTypePickerContext extends UmbPickerInputContext = [ + { + type: 'entityAction', + kind: 'duplicateTo', + alias: 'Umb.EntityAction.DocumentType.DuplicateTo', + name: 'Duplicate Document To Entity Action', + forEntityTypes: [UMB_DOCUMENT_TYPE_ENTITY_TYPE], + meta: { + duplicateRepositoryAlias: UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS, + treeAlias: UMB_DOCUMENT_TYPE_TREE_ALIAS, + treeRepositoryAlias: UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS, + }, + }, +]; + +export const manifests = [...entityActions, ...repositoryManifests]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/constants.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/constants.ts new file mode 100644 index 0000000000..20b111059d --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/constants.ts @@ -0,0 +1 @@ +export const UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DocumentType.Duplicate'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/document-type-duplicate.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/document-type-duplicate.repository.ts new file mode 100644 index 0000000000..432cb81012 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/document-type-duplicate.repository.ts @@ -0,0 +1,20 @@ +import { UmbDuplicateDocumentTypeServerDataSource } from './document-type-duplicate.server.data-source.js'; +import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification'; +import type { UmbDuplicateRepository, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action'; +import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository'; + +export class UmbDuplicateDocumentTypeRepository extends UmbRepositoryBase implements UmbDuplicateRepository { + #duplicateSource = new UmbDuplicateDocumentTypeServerDataSource(this); + + async requestDuplicateTo(args: UmbDuplicateToRequestArgs) { + const { error } = await this.#duplicateSource.duplicateTo(args); + + if (!error) { + const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT); + const notification = { data: { message: `Duplicated` } }; + notificationContext.peek('positive', notification); + } + + return { error }; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/document-type-duplicate.server.data-source.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/document-type-duplicate.server.data-source.ts new file mode 100644 index 0000000000..4d824b5f52 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/document-type-duplicate.server.data-source.ts @@ -0,0 +1,43 @@ +import { DocumentTypeService } from '@umbraco-cms/backoffice/external/backend-api'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; +import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; +import type { UmbDuplicateDataSource, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action'; + +/** + * Duplicate Document Server Data Source + * @export + * @class UmbDuplicateDocumentTypeServerDataSource + */ +export class UmbDuplicateDocumentTypeServerDataSource implements UmbDuplicateDataSource { + #host: UmbControllerHost; + + /** + * Creates an instance of UmbDuplicateDocumentTypeServerDataSource. + * @param {UmbControllerHost} host + * @memberof UmbDuplicateDocumentTypeServerDataSource + */ + constructor(host: UmbControllerHost) { + this.#host = host; + } + + /** + * Duplicate an item for the given id to the destination unique + * @param {UmbDuplicateToRequestArgs} args + * @return {*} + * @memberof UmbDuplicateDocumentTypeServerDataSource + */ + async duplicateTo(args: UmbDuplicateToRequestArgs) { + if (!args.unique) throw new Error('Unique is missing'); + if (args.destination.unique === undefined) throw new Error('Destination unique is missing'); + + return tryExecuteAndNotify( + this.#host, + DocumentTypeService.postDocumentTypeByIdCopy({ + id: args.unique, + requestBody: { + target: args.destination.unique ? { id: args.destination.unique } : null, + }, + }), + ); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/index.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/index.ts new file mode 100644 index 0000000000..c1d246e7e6 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/index.ts @@ -0,0 +1,2 @@ +export { UmbDuplicateDocumentTypeRepository } from './document-type-duplicate.repository.js'; +export { UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './constants.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/manifests.ts new file mode 100644 index 0000000000..cac84b044f --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/duplicate/repository/manifests.ts @@ -0,0 +1,12 @@ +import { UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './constants.js'; +import { UmbDuplicateDocumentTypeRepository } from './document-type-duplicate.repository.js'; +import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry'; + +const duplicateRepository: ManifestRepository = { + type: 'repository', + alias: UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS, + name: 'Duplicate Document Type Repository', + api: UmbDuplicateDocumentTypeRepository, +}; + +export const manifests = [duplicateRepository]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/manifests.ts index 0c300d0386..d6e35494d9 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/manifests.ts @@ -1,8 +1,11 @@ import { UMB_DOCUMENT_TYPE_ENTITY_TYPE } from '../entity.js'; -import { DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS } from '../repository/index.js'; +import { + UMB_DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, + UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, +} from '../repository/index.js'; import { manifests as createManifests } from './create/manifests.js'; import { manifests as moveManifests } from './move-to/manifests.js'; -import { UMB_DOCUMENT_TYPE_PICKER_MODAL } from '@umbraco-cms/backoffice/document-type'; +import { manifests as duplicateManifests } from './duplicate/manifests.js'; import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; const entityActions: Array = [ @@ -13,22 +16,10 @@ const entityActions: Array = [ name: 'Delete Document-Type Entity Action', forEntityTypes: [UMB_DOCUMENT_TYPE_ENTITY_TYPE], meta: { - itemRepositoryAlias: DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, - detailRepositoryAlias: DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, - }, - }, - { - type: 'entityAction', - kind: 'duplicate', - alias: 'Umb.EntityAction.DocumentType.Duplicate', - name: 'Duplicate Document Type Entity Action', - forEntityTypes: [UMB_DOCUMENT_TYPE_ENTITY_TYPE], - meta: { - itemRepositoryAlias: DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, - duplicateRepositoryAlias: DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, - pickerModal: UMB_DOCUMENT_TYPE_PICKER_MODAL, + itemRepositoryAlias: UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, + detailRepositoryAlias: UMB_DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, }, }, ]; -export const manifests = [...entityActions, ...createManifests, ...moveManifests]; +export const manifests = [...entityActions, ...createManifests, ...moveManifests, ...duplicateManifests]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/move-to/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/move-to/manifests.ts index 0258c013f1..91290d49bb 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/move-to/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/move-to/manifests.ts @@ -1,6 +1,5 @@ import { UMB_DOCUMENT_TYPE_ENTITY_TYPE } from '../../entity.js'; -import { UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS } from '../../tree/index.js'; -import { UMB_DOCUMENT_TYPE_TREE_ALIAS } from '../../tree/manifests.js'; +import { UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS, UMB_DOCUMENT_TYPE_TREE_ALIAS } from '../../tree/index.js'; import { UMB_MOVE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './repository/index.js'; import { manifests as repositoryManifests } from './repository/manifests.js'; import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/menu/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/menu/manifests.ts index 042e49cc96..a075f20fb7 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/menu/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/menu/manifests.ts @@ -1,4 +1,4 @@ -import { UMB_DOCUMENT_TYPE_TREE_ALIAS } from '../tree/manifests.js'; +import { UMB_DOCUMENT_TYPE_TREE_ALIAS } from '../tree/index.js'; export const manifests = [ { diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/detail/index.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/detail/index.ts index 6edc2a7661..537d9901ef 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/detail/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/detail/index.ts @@ -1,6 +1,3 @@ export { UmbDocumentTypeDetailRepository } from './document-type-detail.repository.js'; -export { - UMB_DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS as DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, - UMB_DOCUMENT_TYPE_DETAIL_STORE_ALIAS as DOCUMENT_TYPE_DETAIL_STORE_ALIAS, -} from './manifests.js'; +export { UMB_DOCUMENT_TYPE_DETAIL_REPOSITORY_ALIAS, UMB_DOCUMENT_TYPE_DETAIL_STORE_ALIAS } from './manifests.js'; export { UMB_DOCUMENT_TYPE_DETAIL_STORE_CONTEXT } from './document-type-detail.store.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/item/index.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/item/index.ts index 99f6422ade..2ff626ece5 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/item/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/repository/item/index.ts @@ -1,6 +1,3 @@ export { UmbDocumentTypeItemRepository } from './document-type-item.repository.js'; -export { - UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS as DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, - UMB_DOCUMENT_TYPE_ITEM_STORE_ALIAS as DOCUMENT_TYPE_ITEM_STORE_ALIAS, -} from './manifests.js'; +export { UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, UMB_DOCUMENT_TYPE_ITEM_STORE_ALIAS } from './manifests.js'; export * from './types.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/constants.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/constants.ts new file mode 100644 index 0000000000..621a753824 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/constants.ts @@ -0,0 +1,3 @@ +export const UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS = 'Umb.Repository.DocumentType.Tree'; +export const UMB_DOCUMENT_TYPE_TREE_STORE_ALIAS = 'Umb.Store.DocumentType.Tree'; +export const UMB_DOCUMENT_TYPE_TREE_ALIAS = 'Umb.Tree.DocumentType'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/index.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/index.ts index 96ea19523c..f0c2150e54 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/index.ts @@ -1,3 +1,3 @@ export { UMB_DOCUMENT_TYPE_TREE_STORE_CONTEXT } from './document-type.tree.store.js'; -export { UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS } from './manifests.js'; +export { UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS, UMB_DOCUMENT_TYPE_TREE_ALIAS } from './constants.js'; export * from './folder/index.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/manifests.ts index 2753645169..e5200f2240 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/tree/manifests.ts @@ -3,6 +3,11 @@ import { UMB_DOCUMENT_TYPE_FOLDER_ENTITY_TYPE, UMB_DOCUMENT_TYPE_ROOT_ENTITY_TYPE, } from '../entity.js'; +import { + UMB_DOCUMENT_TYPE_TREE_ALIAS, + UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS, + UMB_DOCUMENT_TYPE_TREE_STORE_ALIAS, +} from './constants.js'; import { UmbDocumentTypeTreeRepository } from './document-type-tree.repository.js'; import { UmbDocumentTypeTreeStore } from './document-type.tree.store.js'; import { manifests as folderManifests } from './folder/manifests.js'; @@ -14,10 +19,6 @@ import type { ManifestTreeStore, } from '@umbraco-cms/backoffice/extension-registry'; -export const UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS = 'Umb.Repository.DocumentType.Tree'; -export const UMB_DOCUMENT_TYPE_TREE_STORE_ALIAS = 'Umb.Store.DocumentType.Tree'; -export const UMB_DOCUMENT_TYPE_TREE_ALIAS = 'Umb.Tree.DocumentType'; - const treeRepository: ManifestRepository = { type: 'repository', alias: UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS,