Merge branch 'main' into bugfix/check-for-tree-root-items
This commit is contained in:
@@ -10,7 +10,8 @@ export default {
|
||||
chooseWhereToCopy: 'Choose where to copy',
|
||||
chooseWhereToImport: 'Choose where to import',
|
||||
chooseWhereToMove: 'Choose where to move',
|
||||
copy: 'Copy to',
|
||||
copy: 'Duplicate',
|
||||
copyTo: 'Duplicate to',
|
||||
create: 'Create',
|
||||
createblueprint: 'Create Document Blueprint',
|
||||
createGroup: 'Create group',
|
||||
|
||||
@@ -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<UmbDocumentTypeItemModel>(
|
||||
this,
|
||||
DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
|
||||
UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
|
||||
(x) => x.unique,
|
||||
);
|
||||
|
||||
|
||||
@@ -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<UmbDocumentTypeItemModel>(
|
||||
this,
|
||||
DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
|
||||
UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS,
|
||||
(x) => x.unique,
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { UmbDuplicateToRequestArgs } from './types.js';
|
||||
import type { UmbDataSourceErrorResponse } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export interface UmbDuplicateToDataSource {
|
||||
duplicateTo(args: UmbDuplicateToRequestArgs): Promise<UmbDataSourceErrorResponse>;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { UmbRepositoryErrorResponse } from '../../../../repository/types.js';
|
||||
import type { UmbDuplicateToRequestArgs } from './types.js';
|
||||
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
|
||||
|
||||
export interface UmbDuplicateToRepository extends UmbApi {
|
||||
requestDuplicateTo(args: UmbDuplicateToRequestArgs): Promise<UmbRepositoryErrorResponse>;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { UMB_ENTITY_ACTION_DEFAULT_KIND_MANIFEST } from '../../../default/default.action.kind.js';
|
||||
import type { UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const manifest: UmbBackofficeManifestKind = {
|
||||
type: 'kind',
|
||||
alias: 'Umb.Kind.EntityAction.DuplicateTo',
|
||||
matchKind: 'duplicateTo',
|
||||
matchType: 'entityAction',
|
||||
manifest: {
|
||||
...UMB_ENTITY_ACTION_DEFAULT_KIND_MANIFEST.manifest,
|
||||
type: 'entityAction',
|
||||
kind: 'duplicateTo',
|
||||
api: () => import('./duplicate-to.action.js'),
|
||||
weight: 600,
|
||||
forEntityTypes: [],
|
||||
meta: {
|
||||
icon: 'icon-enter',
|
||||
label: '#actions_copyTo',
|
||||
treeRepositoryAlias: '',
|
||||
duplicateRepositoryAlias: '',
|
||||
treeAlias: '',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
import { UmbEntityActionBase } from '../../../entity-action-base.js';
|
||||
import { UmbRequestReloadStructureForEntityEvent } from '../../../request-reload-structure-for-entity.event.js';
|
||||
import { UMB_DUPLICATE_TO_MODAL } from './modal/duplicate-to-modal.token.js';
|
||||
import type { UmbDuplicateToRepository } from './types.js';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
import type { MetaEntityActionDuplicateToKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
|
||||
export class UmbDuplicateToEntityAction extends UmbEntityActionBase<MetaEntityActionDuplicateToKind> {
|
||||
async execute() {
|
||||
if (!this.args.unique) throw new Error('Unique is not available');
|
||||
if (!this.args.entityType) throw new Error('Entity Type is not available');
|
||||
|
||||
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
|
||||
const modal = modalManager.open(this, UMB_DUPLICATE_TO_MODAL, {
|
||||
data: {
|
||||
unique: this.args.unique,
|
||||
entityType: this.args.entityType,
|
||||
treeAlias: this.args.meta.treeAlias,
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const value = await modal.onSubmit();
|
||||
const destinationUnique = value.destination.unique;
|
||||
if (destinationUnique === undefined) throw new Error('Destination Unique is not available');
|
||||
|
||||
const duplicateRepository = await createExtensionApiByAlias<UmbDuplicateToRepository>(
|
||||
this,
|
||||
this.args.meta.duplicateRepositoryAlias,
|
||||
);
|
||||
if (!duplicateRepository) throw new Error('Duplicate repository is not available');
|
||||
|
||||
const { error } = await duplicateRepository.requestDuplicateTo({
|
||||
unique: this.args.unique,
|
||||
destination: { unique: destinationUnique },
|
||||
});
|
||||
|
||||
if (!error) {
|
||||
this.#reloadMenu();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async #reloadMenu() {
|
||||
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
||||
const event = new UmbRequestReloadStructureForEntityEvent({
|
||||
unique: this.args.unique,
|
||||
entityType: this.args.entityType,
|
||||
});
|
||||
|
||||
actionEventContext.dispatchEvent(event);
|
||||
|
||||
// TODO: Reload destination
|
||||
}
|
||||
}
|
||||
|
||||
export { UmbDuplicateToEntityAction as api };
|
||||
@@ -0,0 +1 @@
|
||||
export { UmbDuplicateToEntityAction } from './duplicate-to.action.js';
|
||||
@@ -0,0 +1,4 @@
|
||||
import { manifests as modalManifests } from './modal/manifests.js';
|
||||
import { manifest as duplicateToKindManifest } from './duplicate-to.action.kind.js';
|
||||
|
||||
export const manifests = [duplicateToKindManifest, ...modalManifests];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DUPLICATE_TO_MODAL_ALIAS = 'Umb.Modal.DuplicateTo';
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { UmbDuplicateToModalData, UmbDuplicateToModalValue } from './duplicate-to-modal.token.js';
|
||||
import { html, customElement, nothing } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
|
||||
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
import type { UmbSelectionChangeEvent } from '@umbraco-cms/backoffice/event';
|
||||
import type { UmbTreeElement } from '@umbraco-cms/backoffice/tree';
|
||||
|
||||
const elementName = 'umb-duplicate-to-modal';
|
||||
@customElement(elementName)
|
||||
export class UmbDuplicateToModalElement extends UmbModalBaseElement<UmbDuplicateToModalData, UmbDuplicateToModalValue> {
|
||||
#onTreeSelectionChange(event: UmbSelectionChangeEvent) {
|
||||
const target = event.target as UmbTreeElement;
|
||||
const selection = target.getSelection();
|
||||
if (selection.length === 0) throw new Error('Selection is required');
|
||||
this.updateValue({ destination: { unique: selection[0] } });
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.data) return nothing;
|
||||
|
||||
return html`
|
||||
<umb-body-layout headline="Duplicate">
|
||||
<uui-box>
|
||||
<umb-tree alias=${this.data.treeAlias} @selection-change=${this.#onTreeSelectionChange}></umb-tree>
|
||||
</uui-box>
|
||||
|
||||
${this.#renderActions()}
|
||||
</umb-body-layout>
|
||||
`;
|
||||
}
|
||||
|
||||
#renderActions() {
|
||||
return html`
|
||||
<uui-button slot="actions" label="Cancel" @click="${this._rejectModal}"></uui-button>
|
||||
<uui-button
|
||||
slot="actions"
|
||||
color="positive"
|
||||
look="primary"
|
||||
label="Duplicate"
|
||||
@click=${this._submitModal}></uui-button>
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = [UmbTextStyles];
|
||||
}
|
||||
|
||||
export { UmbDuplicateToModalElement as element };
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
[elementName]: UmbDuplicateToModalElement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { UMB_DUPLICATE_TO_MODAL_ALIAS } from './constants.js';
|
||||
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
export interface UmbDuplicateToModalData {
|
||||
unique: string | null;
|
||||
entityType: string;
|
||||
treeAlias: string;
|
||||
}
|
||||
|
||||
export interface UmbDuplicateToModalValue {
|
||||
destination: {
|
||||
unique: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export const UMB_DUPLICATE_TO_MODAL = new UmbModalToken<UmbDuplicateToModalData, UmbDuplicateToModalValue>(
|
||||
UMB_DUPLICATE_TO_MODAL_ALIAS,
|
||||
{
|
||||
modal: {
|
||||
type: 'sidebar',
|
||||
size: 'small',
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './constants.js';
|
||||
export * from './duplicate-to-modal.token.js';
|
||||
@@ -0,0 +1,11 @@
|
||||
import { UMB_DUPLICATE_TO_MODAL_ALIAS } from './constants.js';
|
||||
import type { ManifestModal } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const manifests: Array<ManifestModal> = [
|
||||
{
|
||||
type: 'modal',
|
||||
alias: UMB_DUPLICATE_TO_MODAL_ALIAS,
|
||||
name: 'Duplicate To Modal',
|
||||
js: () => import('./duplicate-to-modal.element.js'),
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { UmbDuplicateRequestArgs } from '../duplicate/types.js';
|
||||
|
||||
export * from './duplicate-to-data-source.interface.js';
|
||||
export * from './duplicate-to-repository.interface.js';
|
||||
|
||||
export interface UmbDuplicateToRequestArgs extends UmbDuplicateRequestArgs {
|
||||
destination: {
|
||||
unique: string | null;
|
||||
};
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import { UmbEntityActionBase } from '../../entity-action-base.js';
|
||||
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 { MetaEntityActionDuplicateKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
import type { UmbDuplicateRepository, UmbItemRepository } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateEntityAction extends UmbEntityActionBase<MetaEntityActionDuplicateKind> {
|
||||
// TODO: make base type for item and detail models
|
||||
#itemRepository?: UmbItemRepository<any>;
|
||||
#duplicateRepository?: UmbDuplicateRepository;
|
||||
#init: Promise<unknown>;
|
||||
|
||||
constructor(host: UmbControllerHost, args: UmbEntityActionArgs<MetaEntityActionDuplicateKind>) {
|
||||
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.duplicateRepositoryAlias,
|
||||
[this._host],
|
||||
(permitted, ctrl) => {
|
||||
this.#duplicateRepository = permitted ? (ctrl.api as UmbDuplicateRepository) : undefined;
|
||||
},
|
||||
).asPromise(),
|
||||
]);
|
||||
}
|
||||
|
||||
async execute() {
|
||||
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.pickerModal) as any; // TODO: make generic picker interface with selection
|
||||
const value = await modalContext.onSubmit();
|
||||
if (!value) return;
|
||||
await this.#duplicateRepository!.duplicate(this.args.unique, value.selection[0]);
|
||||
}
|
||||
}
|
||||
|
||||
export default UmbDuplicateEntityAction;
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { UmbDuplicateRequestArgs } from './types.js';
|
||||
import type { UmbDataSourceErrorResponse } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export interface UmbDuplicateDataSource {
|
||||
duplicate(args: UmbDuplicateRequestArgs): Promise<UmbDataSourceErrorResponse>;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { UmbRepositoryErrorResponse } from '../../../../repository/types.js';
|
||||
import type { UmbDuplicateRequestArgs } from './types.js';
|
||||
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
|
||||
|
||||
export interface UmbDuplicateRepository extends UmbApi {
|
||||
requestDuplicate(args: UmbDuplicateRequestArgs): Promise<UmbRepositoryErrorResponse>;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UMB_ENTITY_ACTION_DEFAULT_KIND_MANIFEST } from '../../default/default.action.kind.js';
|
||||
import { UMB_ENTITY_ACTION_DEFAULT_KIND_MANIFEST } from '../../../default/default.action.kind.js';
|
||||
import type { UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const manifest: UmbBackofficeManifestKind = {
|
||||
@@ -11,14 +11,13 @@ export const manifest: UmbBackofficeManifestKind = {
|
||||
type: 'entityAction',
|
||||
kind: 'duplicate',
|
||||
api: () => import('./duplicate.action.js'),
|
||||
weight: 600,
|
||||
weight: 650,
|
||||
forEntityTypes: [],
|
||||
meta: {
|
||||
icon: 'icon-documents',
|
||||
icon: 'icon-enter',
|
||||
label: '#actions_copy',
|
||||
itemRepositoryAlias: '',
|
||||
treeRepositoryAlias: '',
|
||||
duplicateRepositoryAlias: '',
|
||||
pickerModal: '',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
import { UmbEntityActionBase } from '../../../entity-action-base.js';
|
||||
import { UmbRequestReloadStructureForEntityEvent } from '../../../request-reload-structure-for-entity.event.js';
|
||||
import type { UmbDuplicateRepository } from './duplicate-repository.interface.js';
|
||||
import type { MetaEntityActionDuplicateToKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
|
||||
export class UmbDuplicateEntityAction extends UmbEntityActionBase<MetaEntityActionDuplicateToKind> {
|
||||
async execute() {
|
||||
if (!this.args.unique) throw new Error('Unique is not available');
|
||||
if (!this.args.entityType) throw new Error('Entity Type is not available');
|
||||
|
||||
try {
|
||||
const duplicateRepository = await createExtensionApiByAlias<UmbDuplicateRepository>(
|
||||
this,
|
||||
this.args.meta.duplicateRepositoryAlias,
|
||||
);
|
||||
if (!duplicateRepository) throw new Error('Duplicate repository is not available');
|
||||
|
||||
const { error } = await duplicateRepository.requestDuplicate({
|
||||
unique: this.args.unique,
|
||||
});
|
||||
|
||||
if (!error) {
|
||||
this.#reloadMenu();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async #reloadMenu() {
|
||||
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
||||
const event = new UmbRequestReloadStructureForEntityEvent({
|
||||
unique: this.args.unique,
|
||||
entityType: this.args.entityType,
|
||||
});
|
||||
|
||||
actionEventContext.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
export { UmbDuplicateEntityAction as api };
|
||||
@@ -0,0 +1 @@
|
||||
export { UmbDuplicateEntityAction } from './duplicate.action.js';
|
||||
@@ -0,0 +1,3 @@
|
||||
import { manifest as duplicateKindManifest } from './duplicate.action.kind.js';
|
||||
|
||||
export const manifests = [duplicateKindManifest];
|
||||
@@ -0,0 +1,6 @@
|
||||
export * from './duplicate-data-source.interface.js';
|
||||
export * from './duplicate-repository.interface.js';
|
||||
|
||||
export interface UmbDuplicateRequestArgs {
|
||||
unique: string;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export { UmbDuplicateEntityAction } from './duplicate/index.js';
|
||||
export { UmbDuplicateToEntityAction } from './duplicate-to/index.js';
|
||||
|
||||
export * from './duplicate/types.js';
|
||||
export * from './duplicate-to/types.js';
|
||||
@@ -1,3 +1,4 @@
|
||||
import { manifest as duplicateKindManifest } from './duplicate.action.kind.js';
|
||||
import { manifests as duplicateManifests } from './duplicate/manifests.js';
|
||||
import { manifests as duplicateToManifests } from './duplicate-to/manifests.js';
|
||||
|
||||
export const manifests = [duplicateKindManifest];
|
||||
export const manifests = [...duplicateManifests, ...duplicateToManifests];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './duplicate/duplicate.action.js';
|
||||
export * from './duplicate/index.js';
|
||||
export * from './move/index.js';
|
||||
export * from './delete/delete.action.js';
|
||||
export * from './move/move-to.action.js';
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { manifests as defaultEntityActionManifests } from './default/manifests.js';
|
||||
import { manifests as deleteEntityActionManifests } from './common/delete/manifests.js';
|
||||
import { manifests as duplicateEntityActionManifests } from './common/duplicate/manifests.js';
|
||||
import { manifests as moveToEntityActionManifests } from './common/move/manifests.js';
|
||||
import { manifests as moveEntityActionManifests } from './common/move/manifests.js';
|
||||
import { manifests as sortChildrenOfEntityActionManifests } from './common/sort-children-of/manifests.js';
|
||||
|
||||
export const manifests = [
|
||||
...defaultEntityActionManifests,
|
||||
...deleteEntityActionManifests,
|
||||
...duplicateEntityActionManifests,
|
||||
...moveToEntityActionManifests,
|
||||
...moveEntityActionManifests,
|
||||
...sortChildrenOfEntityActionManifests,
|
||||
];
|
||||
|
||||
@@ -113,16 +113,16 @@ export interface ManifestEntityActionReloadTreeItemChildrenKind
|
||||
|
||||
export interface MetaEntityActionReloadTreeItemChildrenKind extends MetaEntityActionDefaultKind {}
|
||||
|
||||
// DUPLICATE
|
||||
export interface ManifestEntityActionDuplicateKind extends ManifestEntityAction<MetaEntityActionDuplicateKind> {
|
||||
// DUPLICATE TO
|
||||
export interface ManifestEntityActionDuplicateToKind extends ManifestEntityAction<MetaEntityActionDuplicateToKind> {
|
||||
type: 'entityAction';
|
||||
kind: 'duplicate';
|
||||
kind: 'duplicateTo';
|
||||
}
|
||||
|
||||
export interface MetaEntityActionDuplicateKind extends MetaEntityActionDefaultKind {
|
||||
export interface MetaEntityActionDuplicateToKind extends MetaEntityActionDefaultKind {
|
||||
duplicateRepositoryAlias: string;
|
||||
itemRepositoryAlias: string;
|
||||
pickerModal: UmbModalToken | string;
|
||||
treeRepositoryAlias: string;
|
||||
treeAlias: string;
|
||||
}
|
||||
|
||||
// MOVE TO
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
ManifestEntityActionDeleteKind,
|
||||
ManifestEntityActionRenameServerFileKind,
|
||||
ManifestEntityActionReloadTreeItemChildrenKind,
|
||||
ManifestEntityActionDuplicateKind,
|
||||
ManifestEntityActionDuplicateToKind,
|
||||
ManifestEntityActionMoveToKind,
|
||||
ManifestEntityActionCreateFolderKind,
|
||||
ManifestEntityActionUpdateFolderKind,
|
||||
@@ -116,7 +116,7 @@ export type ManifestEntityActions =
|
||||
| ManifestEntityActionDefaultKind
|
||||
| ManifestEntityActionDeleteFolderKind
|
||||
| ManifestEntityActionDeleteKind
|
||||
| ManifestEntityActionDuplicateKind
|
||||
| ManifestEntityActionDuplicateToKind
|
||||
| ManifestEntityActionEmptyRecycleBinKind
|
||||
| ManifestEntityActionMoveToKind
|
||||
| ManifestEntityActionReloadTreeItemChildrenKind
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import type { UmbDataSourceResponse } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export interface UmbDuplicateDataSource {
|
||||
duplicate(unique: string, targetUnique: string | null): Promise<UmbDataSourceResponse<string>>;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import type { UmbRepositoryResponse } from '../types.js';
|
||||
|
||||
export interface UmbDuplicateRepository {
|
||||
duplicate(unique: string, targetUnique: string): Promise<UmbRepositoryResponse<string>>;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export type { UmbDuplicateDataSource } from './duplicate-data-source.interface.js';
|
||||
export type { UmbDuplicateRepository } from './duplicate-repository.interface.js';
|
||||
@@ -5,5 +5,4 @@ export * from './item/index.js';
|
||||
export * from './detail/index.js';
|
||||
|
||||
export type { UmbDataSourceResponse, UmbDataSourceErrorResponse } from './data-source-response.interface.js';
|
||||
export type { UmbDuplicateDataSource, UmbDuplicateRepository } from './duplicate/index.js';
|
||||
export type { UmbPagedModel, UmbRepositoryResponse, UmbRepositoryErrorResponse } from './types.js';
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { UmbDuplicateDataTypeRepository, UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
@@ -1,22 +1,22 @@
|
||||
import { UMB_DATA_TYPE_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_DATA_TYPE_PICKER_MODAL } from '../../modals/data-type-picker-modal.token.js';
|
||||
import { UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS } from '../../repository/duplicate/manifests.js';
|
||||
import { UMB_DATA_TYPE_ITEM_REPOSITORY_ALIAS } from '../../repository/index.js';
|
||||
import { UMB_DATA_TYPE_TREE_ALIAS, UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const entityActions: Array<ManifestTypes> = [
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'duplicate',
|
||||
alias: 'Umb.EntityAction.DataType.Duplicate',
|
||||
name: 'Duplicate Data Type Entity Action',
|
||||
kind: 'duplicateTo',
|
||||
alias: 'Umb.EntityAction.DataType.DuplicateTo',
|
||||
name: 'Duplicate Document To Entity Action',
|
||||
forEntityTypes: [UMB_DATA_TYPE_ENTITY_TYPE],
|
||||
meta: {
|
||||
duplicateRepositoryAlias: UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS,
|
||||
itemRepositoryAlias: UMB_DATA_TYPE_ITEM_REPOSITORY_ALIAS,
|
||||
pickerModal: UMB_DATA_TYPE_PICKER_MODAL,
|
||||
treeAlias: UMB_DATA_TYPE_TREE_ALIAS,
|
||||
treeRepositoryAlias: UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions];
|
||||
export const manifests = [...entityActions, ...repositoryManifests];
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DataType.Duplicate';
|
||||
@@ -0,0 +1,20 @@
|
||||
import { UmbDuplicateDataTypeServerDataSource } from './data-type-duplicate.server.data-source.js';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbDuplicateToRepository, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateDataTypeRepository extends UmbRepositoryBase implements UmbDuplicateToRepository {
|
||||
#duplicateSource = new UmbDuplicateDataTypeServerDataSource(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 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { DataTypeService } 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,
|
||||
UmbDuplicateRequestArgs,
|
||||
UmbDuplicateToDataSource,
|
||||
UmbDuplicateToRequestArgs,
|
||||
} from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
/**
|
||||
* Duplicate Document Server Data Source
|
||||
* @export
|
||||
* @class UmbDuplicateDataTypeServerDataSource
|
||||
*/
|
||||
export class UmbDuplicateDataTypeServerDataSource implements UmbDuplicateToDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDuplicateDataTypeServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbDuplicateDataTypeServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate an item for the given unique to the destination unique
|
||||
* @param {UmbDuplicateToRequestArgs} args
|
||||
* @return {*}
|
||||
* @memberof UmbDuplicateDataTypeServerDataSource
|
||||
*/
|
||||
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,
|
||||
DataTypeService.postDataTypeByIdCopy({
|
||||
id: args.unique,
|
||||
requestBody: {
|
||||
target: args.destination.unique ? { id: args.destination.unique } : null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
export { UmbDuplicateDataTypeRepository } from './data-type-duplicate.repository.js';
|
||||
export { UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS } from './manifests.js';
|
||||
export { UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS } from './constants.js';
|
||||
@@ -1,8 +1,7 @@
|
||||
import { UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS } from './constants.js';
|
||||
import { UmbDuplicateDataTypeRepository } from './data-type-duplicate.repository.js';
|
||||
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DataType.Duplicate';
|
||||
|
||||
const duplicateRepository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS,
|
||||
@@ -1,6 +1,5 @@
|
||||
import { UMB_DATA_TYPE_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_DATA_TYPE_TREE_ALIAS } from '../../tree/manifests.js';
|
||||
import { UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS, UMB_DATA_TYPE_TREE_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_MOVE_DATA_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { UmbDataTypeDetailRepository } from '../detail/data-type-detail.repository.js';
|
||||
import { UmbDataTypeDuplicateServerDataSource } from './data-type-duplicate.server.data-source.js';
|
||||
import type { UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import type { UmbDuplicateRepository, UmbDuplicateDataSource } from '@umbraco-cms/backoffice/repository';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateDataTypeRepository extends UmbRepositoryBase implements UmbDuplicateRepository {
|
||||
#init: Promise<unknown>;
|
||||
#duplicateSource: UmbDuplicateDataSource;
|
||||
#detailRepository: UmbDataTypeDetailRepository;
|
||||
#notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
this.#duplicateSource = new UmbDataTypeDuplicateServerDataSource(this);
|
||||
this.#detailRepository = new UmbDataTypeDetailRepository(this);
|
||||
|
||||
this.#init = Promise.all([
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => {
|
||||
this.#notificationContext = instance;
|
||||
}).asPromise(),
|
||||
]);
|
||||
}
|
||||
|
||||
async duplicate(unique: string, targetUnique: string | null) {
|
||||
await this.#init;
|
||||
const { data: dataTypeDuplicateUnique, error } = await this.#duplicateSource.duplicate(unique, targetUnique);
|
||||
if (error) return { error };
|
||||
|
||||
if (dataTypeDuplicateUnique) {
|
||||
const { data: dataTypeDuplicate } = await this.#detailRepository.requestByUnique(dataTypeDuplicateUnique);
|
||||
if (!dataTypeDuplicate) throw new Error('Could not find copied data type');
|
||||
// TODO: reload tree
|
||||
const notification = { data: { message: `Data type copied` } };
|
||||
this.#notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { data: dataTypeDuplicateUnique };
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import { DataTypeService } 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 } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
/**
|
||||
* A data source for Data Type items that fetches data from the server
|
||||
* @export
|
||||
* @class UmbDataTypeDuplicateServerDataSource
|
||||
*/
|
||||
export class UmbDataTypeDuplicateServerDataSource implements UmbDuplicateDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDataTypeDuplicateServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbDataTypeDuplicateServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy an item for the given unique to the target unique
|
||||
* @param {Array<string>} unique
|
||||
* @return {*}
|
||||
* @memberof UmbDataTypeDuplicateServerDataSource
|
||||
*/
|
||||
async duplicate(unique: string, targetUnique: string | null) {
|
||||
if (!unique) throw new Error('Unique is missing');
|
||||
if (targetUnique === undefined) throw new Error('Target unique is missing');
|
||||
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
DataTypeService.postDataTypeByIdCopy({
|
||||
id: unique,
|
||||
requestBody: {
|
||||
target: targetUnique ? { id: targetUnique } : null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
export { UmbDuplicateDataTypeRepository, UMB_DUPLICATE_DATA_TYPE_REPOSITORY_ALIAS } from './duplicate/index.js';
|
||||
export {
|
||||
UmbDataTypeDetailRepository,
|
||||
UMB_DATA_TYPE_DETAIL_REPOSITORY_ALIAS,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { manifests as duplicateManifests } from './duplicate/manifests.js';
|
||||
import { manifests as detailManifests } from './detail/manifests.js';
|
||||
import { manifests as itemManifests } from './item/manifests.js';
|
||||
|
||||
export const manifests = [...duplicateManifests, ...detailManifests, ...itemManifests];
|
||||
export const manifests = [...detailManifests, ...itemManifests];
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export const UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS = 'Umb.Repository.DataType.Tree';
|
||||
export const UMB_DATA_TYPE_TREE_STORE_ALIAS = 'Umb.Store.DataType.Tree';
|
||||
export const UMB_DATA_TYPE_TREE_ALIAS = 'Umb.Tree.DataType';
|
||||
@@ -1,3 +1,3 @@
|
||||
export { UMB_DATA_TYPE_TREE_STORE_CONTEXT } from './data-type-tree.store.js';
|
||||
export { UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS } from './manifests.js';
|
||||
export { UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS, UMB_DATA_TYPE_TREE_ALIAS } from './constants.js';
|
||||
export * from './folder/index.js';
|
||||
|
||||
@@ -2,6 +2,11 @@ import { manifests as folderManifests } from './folder/manifests.js';
|
||||
import { manifests as reloadManifests } from './reload-tree-item-children/manifests.js';
|
||||
import { UmbDataTypeTreeRepository } from './data-type-tree.repository.js';
|
||||
import { UmbDataTypeTreeStore } from './data-type-tree.store.js';
|
||||
import {
|
||||
UMB_DATA_TYPE_TREE_ALIAS,
|
||||
UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS,
|
||||
UMB_DATA_TYPE_TREE_STORE_ALIAS,
|
||||
} from './constants.js';
|
||||
import type {
|
||||
ManifestRepository,
|
||||
ManifestTree,
|
||||
@@ -9,10 +14,6 @@ import type {
|
||||
ManifestTreeStore,
|
||||
} from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS = 'Umb.Repository.DataType.Tree';
|
||||
export const UMB_DATA_TYPE_TREE_STORE_ALIAS = 'Umb.Store.DataType.Tree';
|
||||
export const UMB_DATA_TYPE_TREE_ALIAS = 'Umb.Tree.DataType';
|
||||
|
||||
const treeRepository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_DATA_TYPE_TREE_REPOSITORY_ALIAS,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { UMB_DICTIONARY_TREE_ALIAS } from '../../tree/manifests.js';
|
||||
import { UmbDictionaryImportRepository } from '../../repository/index.js';
|
||||
import type { UmbImportDictionaryModalData, UmbImportDictionaryModalValue } from './import-dictionary-modal.token.js';
|
||||
import { css, html, customElement, query, state, when } from '@umbraco-cms/backoffice/external/lit';
|
||||
|
||||
@@ -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<UmbDocum
|
||||
constructor(host: UmbControllerHost) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
super(host, DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, UMB_DOCUMENT_TYPE_PICKER_MODAL);
|
||||
super(host, UMB_DOCUMENT_TYPE_ITEM_REPOSITORY_ALIAS, UMB_DOCUMENT_TYPE_PICKER_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export {
|
||||
UmbDuplicateDocumentTypeRepository,
|
||||
UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS,
|
||||
} from './repository/index.js';
|
||||
@@ -0,0 +1,22 @@
|
||||
import { UMB_DOCUMENT_TYPE_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_DOCUMENT_TYPE_TREE_ALIAS, UMB_DOCUMENT_TYPE_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_DUPLICATE_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';
|
||||
|
||||
const entityActions: Array<ManifestTypes> = [
|
||||
{
|
||||
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];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.DocumentType.Duplicate';
|
||||
@@ -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 { UmbDuplicateToRepository, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateDocumentTypeRepository extends UmbRepositoryBase implements UmbDuplicateToRepository {
|
||||
#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 };
|
||||
}
|
||||
}
|
||||
@@ -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 { UmbDuplicateToDataSource, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
/**
|
||||
* Duplicate Document Server Data Source
|
||||
* @export
|
||||
* @class UmbDuplicateDocumentTypeServerDataSource
|
||||
*/
|
||||
export class UmbDuplicateDocumentTypeServerDataSource implements UmbDuplicateToDataSource {
|
||||
#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,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { UmbDuplicateDocumentTypeRepository } from './document-type-duplicate.repository.js';
|
||||
export { UMB_DUPLICATE_DOCUMENT_TYPE_REPOSITORY_ALIAS } from './constants.js';
|
||||
@@ -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];
|
||||
@@ -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<ManifestTypes> = [
|
||||
@@ -13,22 +16,10 @@ const entityActions: Array<ManifestTypes> = [
|
||||
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];
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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 = [
|
||||
{
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
@@ -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';
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { UMB_DUPLICATE_DOCUMENT_MODAL } from './modal/index.js';
|
||||
import { UmbDuplicateDocumentRepository } from './repository/index.js';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
import { UmbEntityActionBase, UmbRequestReloadStructureForEntityEvent } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
export class UmbDuplicateDocumentEntityAction extends UmbEntityActionBase<any> {
|
||||
async execute() {
|
||||
if (!this.args.unique) throw new Error('Unique is not available');
|
||||
if (!this.args.entityType) throw new Error('Entity Type is not available');
|
||||
|
||||
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
|
||||
const modal = modalManager.open(this, UMB_DUPLICATE_DOCUMENT_MODAL, {
|
||||
data: {
|
||||
unique: this.args.unique,
|
||||
entityType: this.args.entityType,
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const value = await modal.onSubmit();
|
||||
const destinationUnique = value.destination.unique;
|
||||
if (destinationUnique === undefined) throw new Error('Destination Unique is not available');
|
||||
|
||||
const duplicateRepository = new UmbDuplicateDocumentRepository(this);
|
||||
|
||||
const { error } = await duplicateRepository.requestDuplicate({
|
||||
unique: this.args.unique,
|
||||
destination: { unique: destinationUnique },
|
||||
relateToOriginal: value.relateToOriginal,
|
||||
includeDescendants: value.includeDescendants,
|
||||
});
|
||||
|
||||
if (!error) {
|
||||
this.#reloadMenu();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async #reloadMenu() {
|
||||
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
||||
const event = new UmbRequestReloadStructureForEntityEvent({
|
||||
unique: this.args.unique,
|
||||
entityType: this.args.entityType,
|
||||
});
|
||||
|
||||
actionEventContext.dispatchEvent(event);
|
||||
// TODO: Reload destination
|
||||
}
|
||||
}
|
||||
|
||||
export { UmbDuplicateDocumentEntityAction as api };
|
||||
@@ -0,0 +1 @@
|
||||
export { UmbDuplicateDocumentRepository, UMB_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
@@ -0,0 +1,23 @@
|
||||
import { UMB_DOCUMENT_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_USER_PERMISSION_DOCUMENT_DUPLICATE } from '../../user-permissions/constants.js';
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import { manifests as modalManifests } from './modal/manifests.js';
|
||||
|
||||
export const manifests = [
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'duplicateTo',
|
||||
alias: 'Umb.EntityAction.Document.DuplicateTo',
|
||||
name: 'Duplicate Document To Entity Action',
|
||||
forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
|
||||
api: () => import('./duplicate-document.action.js'),
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.UserPermission.Document',
|
||||
allOf: [UMB_USER_PERMISSION_DOCUMENT_DUPLICATE],
|
||||
},
|
||||
],
|
||||
},
|
||||
...repositoryManifests,
|
||||
...modalManifests,
|
||||
];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DUPLICATE_DOCUMENT_MODAL_ALIAS = 'Umb.Modal.Document.Duplicate';
|
||||
@@ -0,0 +1,95 @@
|
||||
import { UMB_DOCUMENT_TREE_ALIAS } from '../../../tree/manifests.js';
|
||||
import type {
|
||||
UmbDuplicateDocumentModalData,
|
||||
UmbDuplicateDocumentModalValue,
|
||||
} from './duplicate-document-modal.token.js';
|
||||
import { html, customElement, nothing, css } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
|
||||
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
import type { UUIBooleanInputEvent } from '@umbraco-cms/backoffice/external/uui';
|
||||
import type { UmbSelectionChangeEvent } from '@umbraco-cms/backoffice/event';
|
||||
import type { UmbTreeElement } from '@umbraco-cms/backoffice/tree';
|
||||
|
||||
const elementName = 'umb-document-duplicate-to-modal';
|
||||
@customElement(elementName)
|
||||
export class UmbDocumentDuplicateToModalElement extends UmbModalBaseElement<
|
||||
UmbDuplicateDocumentModalData,
|
||||
UmbDuplicateDocumentModalValue
|
||||
> {
|
||||
#onTreeSelectionChange(event: UmbSelectionChangeEvent) {
|
||||
const target = event.target as UmbTreeElement;
|
||||
const selection = target.getSelection();
|
||||
if (selection.length === 0) throw new Error('Selection is required');
|
||||
this.updateValue({ destination: { unique: selection[0] } });
|
||||
}
|
||||
|
||||
#onRelateToOriginalChange(event: UUIBooleanInputEvent) {
|
||||
const target = event.target;
|
||||
this.updateValue({ relateToOriginal: target.checked });
|
||||
}
|
||||
|
||||
#onIncludeDescendantsChange(event: UUIBooleanInputEvent) {
|
||||
const target = event.target;
|
||||
this.updateValue({ includeDescendants: target.checked });
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.data) return nothing;
|
||||
|
||||
return html`
|
||||
<umb-body-layout headline="Duplicate">
|
||||
<uui-box id="tree-box" headline="Duplicate to">
|
||||
<umb-tree alias=${UMB_DOCUMENT_TREE_ALIAS} @selection-change=${this.#onTreeSelectionChange}></umb-tree>
|
||||
</uui-box>
|
||||
<uui-box headline="Options">
|
||||
<umb-property-layout label="Relate to original" orientation="vertical"
|
||||
><div slot="editor">
|
||||
<uui-toggle
|
||||
@change=${this.#onRelateToOriginalChange}
|
||||
.checked=${this.value?.relateToOriginal}></uui-toggle>
|
||||
</div>
|
||||
</umb-property-layout>
|
||||
|
||||
<umb-property-layout label="Include descendants" orientation="vertical"
|
||||
><div slot="editor">
|
||||
<uui-toggle
|
||||
@change=${this.#onIncludeDescendantsChange}
|
||||
.checked=${this.value?.includeDescendants}></uui-toggle>
|
||||
</div>
|
||||
</umb-property-layout>
|
||||
</uui-box>
|
||||
${this.#renderActions()}
|
||||
</umb-body-layout>
|
||||
`;
|
||||
}
|
||||
|
||||
#renderActions() {
|
||||
return html`
|
||||
<uui-button slot="actions" label="Cancel" @click="${this._rejectModal}"></uui-button>
|
||||
<uui-button
|
||||
slot="actions"
|
||||
color="positive"
|
||||
look="primary"
|
||||
label="Duplicate"
|
||||
@click=${this._submitModal}></uui-button>
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = [
|
||||
UmbTextStyles,
|
||||
css`
|
||||
#tree-box {
|
||||
margin-bottom: var(--uui-size-layout-1);
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
export { UmbDocumentDuplicateToModalElement as element };
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
[elementName]: UmbDocumentDuplicateToModalElement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { UMB_DUPLICATE_DOCUMENT_MODAL_ALIAS } from './constants.js';
|
||||
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
export interface UmbDuplicateDocumentModalData {
|
||||
unique: string | null;
|
||||
entityType: string;
|
||||
}
|
||||
|
||||
export interface UmbDuplicateDocumentModalValue {
|
||||
destination: {
|
||||
unique: string | null;
|
||||
};
|
||||
relateToOriginal: boolean;
|
||||
includeDescendants: boolean;
|
||||
}
|
||||
|
||||
export const UMB_DUPLICATE_DOCUMENT_MODAL = new UmbModalToken<
|
||||
UmbDuplicateDocumentModalData,
|
||||
UmbDuplicateDocumentModalValue
|
||||
>(UMB_DUPLICATE_DOCUMENT_MODAL_ALIAS, {
|
||||
modal: {
|
||||
type: 'sidebar',
|
||||
size: 'small',
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './constants.js';
|
||||
export * from './duplicate-document-modal.token.js';
|
||||
@@ -0,0 +1,11 @@
|
||||
import { UMB_DUPLICATE_DOCUMENT_MODAL_ALIAS } from './constants.js';
|
||||
import type { ManifestModal } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const manifests: Array<ManifestModal> = [
|
||||
{
|
||||
type: 'modal',
|
||||
alias: UMB_DUPLICATE_DOCUMENT_MODAL_ALIAS,
|
||||
name: 'Duplicate Document To Modal',
|
||||
js: () => import('./duplicate-document-modal.element.js'),
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS = 'Umb.Repository.Document.Duplicate';
|
||||
@@ -0,0 +1,20 @@
|
||||
import { UmbDuplicateDocumentServerDataSource } from './document-duplicate.server.data-source.js';
|
||||
import type { UmbDuplicateDocumentRequestArgs } from './types.js';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateDocumentRepository extends UmbRepositoryBase {
|
||||
#duplicateSource = new UmbDuplicateDocumentServerDataSource(this);
|
||||
|
||||
async requestDuplicate(args: UmbDuplicateDocumentRequestArgs) {
|
||||
const { error } = await this.#duplicateSource.duplicate(args);
|
||||
|
||||
if (!error) {
|
||||
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
|
||||
const notification = { data: { message: `Duplicated` } };
|
||||
notificationContext.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { UmbDuplicateDocumentRequestArgs } from './types.js';
|
||||
import { DocumentService } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
/**
|
||||
* Duplicate Document Server Data Source
|
||||
* @export
|
||||
* @class UmbDuplicateDocumentServerDataSource
|
||||
*/
|
||||
export class UmbDuplicateDocumentServerDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDuplicateDocumentServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbDuplicateDocumentServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate an item for the given id to the destination unique
|
||||
* @param {UmbDuplicateDocumentRequestArgs} args
|
||||
* @return {*}
|
||||
* @memberof UmbDuplicateDocumentServerDataSource
|
||||
*/
|
||||
async duplicate(args: UmbDuplicateDocumentRequestArgs) {
|
||||
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,
|
||||
DocumentService.postDocumentByIdCopy({
|
||||
id: args.unique,
|
||||
requestBody: {
|
||||
target: args.destination.unique ? { id: args.destination.unique } : null,
|
||||
relateToOriginal: args.relateToOriginal,
|
||||
includeDescendants: args.includeDescendants,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { UmbDuplicateDocumentRepository } from './document-duplicate.repository.js';
|
||||
export { UMB_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
|
||||
@@ -0,0 +1,12 @@
|
||||
import { UMB_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS } from './constants.js';
|
||||
import { UmbDuplicateDocumentRepository } from './document-duplicate.repository.js';
|
||||
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const duplicateRepository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_DUPLICATE_DOCUMENT_REPOSITORY_ALIAS,
|
||||
name: 'Duplicate Document Repository',
|
||||
api: UmbDuplicateDocumentRepository,
|
||||
};
|
||||
|
||||
export const manifests = [duplicateRepository];
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
export interface UmbDuplicateDocumentRequestArgs extends UmbDuplicateToRequestArgs {
|
||||
relateToOriginal: boolean;
|
||||
includeDescendants: boolean;
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
import { UMB_DOCUMENT_DETAIL_REPOSITORY_ALIAS, UMB_DOCUMENT_ITEM_REPOSITORY_ALIAS } from '../repository/index.js';
|
||||
import { UMB_DOCUMENT_ENTITY_TYPE } from '../entity.js';
|
||||
import { UMB_DOCUMENT_PICKER_MODAL } from '../modals/index.js';
|
||||
import {
|
||||
UMB_USER_PERMISSION_DOCUMENT_DELETE,
|
||||
UMB_USER_PERMISSION_DOCUMENT_DUPLICATE,
|
||||
UMB_USER_PERMISSION_DOCUMENT_NOTIFICATIONS,
|
||||
UMB_USER_PERMISSION_DOCUMENT_PERMISSIONS,
|
||||
UMB_USER_PERMISSION_DOCUMENT_PUBLISH,
|
||||
UMB_USER_PERMISSION_DOCUMENT_UNPUBLISH,
|
||||
} from '../user-permissions/constants.js';
|
||||
import { manifests as createManifests } from './create/manifests.js';
|
||||
import { manifests as createBlueprintManifests } from './create-blueprint/manifests.js';
|
||||
import { manifests as publicAccessManifests } from './public-access/manifests.js';
|
||||
import { manifests as createManifests } from './create/manifests.js';
|
||||
import { manifests as cultureAndHostnamesManifests } from './culture-and-hostnames/manifests.js';
|
||||
import { manifests as sortChildrenOfManifests } from './sort-children-of/manifests.js';
|
||||
import { manifests as duplicateManifests } from './duplicate/manifests.js';
|
||||
import { manifests as moveManifests } from './move-to/manifests.js';
|
||||
import { manifests as publicAccessManifests } from './public-access/manifests.js';
|
||||
import { manifests as sortChildrenOfManifests } from './sort-children-of/manifests.js';
|
||||
|
||||
import type { ManifestEntityAction } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const entityActions: Array<ManifestEntityAction> = [
|
||||
@@ -35,25 +35,6 @@ const entityActions: Array<ManifestEntityAction> = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'duplicate',
|
||||
alias: 'Umb.EntityAction.Document.Duplicate',
|
||||
name: 'Duplicate Document Entity Action',
|
||||
weight: 800,
|
||||
forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
|
||||
meta: {
|
||||
duplicateRepositoryAlias: UMB_DOCUMENT_DETAIL_REPOSITORY_ALIAS,
|
||||
itemRepositoryAlias: UMB_DOCUMENT_DETAIL_REPOSITORY_ALIAS,
|
||||
pickerModal: UMB_DOCUMENT_PICKER_MODAL,
|
||||
},
|
||||
conditions: [
|
||||
{
|
||||
alias: 'Umb.Condition.UserPermission.Document',
|
||||
allOf: [UMB_USER_PERMISSION_DOCUMENT_DUPLICATE],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'default',
|
||||
@@ -133,11 +114,12 @@ const entityActions: Array<ManifestEntityAction> = [
|
||||
];
|
||||
|
||||
export const manifests = [
|
||||
...createManifests,
|
||||
...createBlueprintManifests,
|
||||
...publicAccessManifests,
|
||||
...createManifests,
|
||||
...cultureAndHostnamesManifests,
|
||||
...sortChildrenOfManifests,
|
||||
...duplicateManifests,
|
||||
...moveManifests,
|
||||
...publicAccessManifests,
|
||||
...sortChildrenOfManifests,
|
||||
...entityActions,
|
||||
];
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { UmbDuplicateMediaTypeRepository, UMB_DUPLICATE_MEDIA_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
@@ -0,0 +1,22 @@
|
||||
import { UMB_MEDIA_TYPE_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_MEDIA_TYPE_TREE_ALIAS, UMB_MEDIA_TYPE_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_DUPLICATE_MEDIA_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const entityActions: Array<ManifestTypes> = [
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'duplicateTo',
|
||||
alias: 'Umb.EntityAction.MediaType.DuplicateTo',
|
||||
name: 'Duplicate Document To Entity Action',
|
||||
forEntityTypes: [UMB_MEDIA_TYPE_ENTITY_TYPE],
|
||||
meta: {
|
||||
duplicateRepositoryAlias: UMB_DUPLICATE_MEDIA_TYPE_REPOSITORY_ALIAS,
|
||||
treeAlias: UMB_MEDIA_TYPE_TREE_ALIAS,
|
||||
treeRepositoryAlias: UMB_MEDIA_TYPE_TREE_REPOSITORY_ALIAS,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions, ...repositoryManifests];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DUPLICATE_MEDIA_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.MediaType.Duplicate';
|
||||
@@ -0,0 +1,2 @@
|
||||
export { UmbDuplicateMediaTypeRepository } from './media-type-duplicate.repository.js';
|
||||
export { UMB_DUPLICATE_MEDIA_TYPE_REPOSITORY_ALIAS } from './constants.js';
|
||||
@@ -0,0 +1,12 @@
|
||||
import { UMB_DUPLICATE_MEDIA_TYPE_REPOSITORY_ALIAS } from './constants.js';
|
||||
import { UmbDuplicateMediaTypeRepository } from './media-type-duplicate.repository.js';
|
||||
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const duplicateRepository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_DUPLICATE_MEDIA_TYPE_REPOSITORY_ALIAS,
|
||||
name: 'Duplicate Media Type Repository',
|
||||
api: UmbDuplicateMediaTypeRepository,
|
||||
};
|
||||
|
||||
export const manifests = [duplicateRepository];
|
||||
@@ -0,0 +1,20 @@
|
||||
import { UmbDuplicateMediaTypeServerDataSource } from './media-type-duplicate.server.data-source.js';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbDuplicateToRepository, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateMediaTypeRepository extends UmbRepositoryBase implements UmbDuplicateToRepository {
|
||||
#duplicateSource = new UmbDuplicateMediaTypeServerDataSource(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 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { MediaTypeService } 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 { UmbDuplicateToDataSource, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
/**
|
||||
* Duplicate Document Server Data Source
|
||||
* @export
|
||||
* @class UmbDuplicateMediaTypeServerDataSource
|
||||
*/
|
||||
export class UmbDuplicateMediaTypeServerDataSource implements UmbDuplicateToDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDuplicateMediaTypeServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbDuplicateMediaTypeServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate an item for the given unique to the destination unique
|
||||
* @param {UmbDuplicateToRequestArgs} args
|
||||
* @return {*}
|
||||
* @memberof UmbDuplicateMediaTypeServerDataSource
|
||||
*/
|
||||
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,
|
||||
MediaTypeService.postMediaTypeByIdCopy({
|
||||
id: args.unique,
|
||||
requestBody: {
|
||||
target: args.destination.unique ? { id: args.destination.unique } : null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,11 @@
|
||||
import { UMB_MEDIA_TYPE_ENTITY_TYPE } from '../entity.js';
|
||||
import { UMB_MEDIA_TYPE_DETAIL_REPOSITORY_ALIAS, UMB_MEDIA_TYPE_ITEM_REPOSITORY_ALIAS } from '../repository/index.js';
|
||||
import { UMB_MEDIA_TYPE_PICKER_MODAL } from '../tree/index.js';
|
||||
import { manifests as createManifests } from './create/manifests.js';
|
||||
import { manifests as moveManifests } from './move-to/manifests.js';
|
||||
import { manifests as duplicateManifests } from './duplicate/manifests.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const entityActions: Array<ManifestTypes> = [
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'duplicate',
|
||||
alias: 'Umb.EntityAction.MediaType.Duplicate',
|
||||
name: 'Duplicate Media Type Entity Action',
|
||||
forEntityTypes: [UMB_MEDIA_TYPE_ENTITY_TYPE],
|
||||
meta: {
|
||||
duplicateRepositoryAlias: UMB_MEDIA_TYPE_DETAIL_REPOSITORY_ALIAS,
|
||||
itemRepositoryAlias: UMB_MEDIA_TYPE_ITEM_REPOSITORY_ALIAS,
|
||||
pickerModal: UMB_MEDIA_TYPE_PICKER_MODAL,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'delete',
|
||||
@@ -31,4 +19,4 @@ const entityActions: Array<ManifestTypes> = [
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions, ...createManifests, ...moveManifests];
|
||||
export const manifests = [...entityActions, ...createManifests, ...moveManifests, ...duplicateManifests];
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { UmbDuplicateMemberTypeRepository, UMB_DUPLICATE_MEMBER_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
@@ -0,0 +1,21 @@
|
||||
import { UMB_MEMBER_TYPE_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_MEMBER_TYPE_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_DUPLICATE_MEMBER_TYPE_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const entityActions: Array<ManifestTypes> = [
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'duplicate',
|
||||
alias: 'Umb.EntityAction.MemberType.Duplicate',
|
||||
name: 'Duplicate Member Type Entity Action',
|
||||
forEntityTypes: [UMB_MEMBER_TYPE_ENTITY_TYPE],
|
||||
meta: {
|
||||
duplicateRepositoryAlias: UMB_DUPLICATE_MEMBER_TYPE_REPOSITORY_ALIAS,
|
||||
treeRepositoryAlias: UMB_MEMBER_TYPE_TREE_REPOSITORY_ALIAS,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions, ...repositoryManifests];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DUPLICATE_MEMBER_TYPE_REPOSITORY_ALIAS = 'Umb.Repository.MemberType.Duplicate';
|
||||
@@ -0,0 +1,2 @@
|
||||
export { UmbDuplicateMemberTypeRepository } from './member-type-duplicate.repository.js';
|
||||
export { UMB_DUPLICATE_MEMBER_TYPE_REPOSITORY_ALIAS } from './constants.js';
|
||||
@@ -0,0 +1,11 @@
|
||||
import { UMB_DUPLICATE_MEMBER_TYPE_REPOSITORY_ALIAS } from './constants.js';
|
||||
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const duplicateRepository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_DUPLICATE_MEMBER_TYPE_REPOSITORY_ALIAS,
|
||||
name: 'Duplicate Member Type Repository',
|
||||
api: () => import('./member-type-duplicate.repository.js'),
|
||||
};
|
||||
|
||||
export const manifests = [duplicateRepository];
|
||||
@@ -0,0 +1,22 @@
|
||||
import { UmbDuplicateMemberTypeServerDataSource } from './member-type-duplicate.server.data-source.js';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbDuplicateRepository, UmbDuplicateRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateMemberTypeRepository extends UmbRepositoryBase implements UmbDuplicateRepository {
|
||||
#duplicateSource = new UmbDuplicateMemberTypeServerDataSource(this);
|
||||
|
||||
async requestDuplicate(args: UmbDuplicateRequestArgs) {
|
||||
const { error } = await this.#duplicateSource.duplicate(args);
|
||||
|
||||
if (!error) {
|
||||
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
|
||||
const notification = { data: { message: `Duplicated` } };
|
||||
notificationContext.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
}
|
||||
|
||||
export { UmbDuplicateMemberTypeRepository as api };
|
||||
@@ -0,0 +1,39 @@
|
||||
import { MemberTypeService } 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, UmbDuplicateRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
/**
|
||||
* Duplicate Document Server Data Source
|
||||
* @export
|
||||
* @class UmbDuplicateMemberTypeServerDataSource
|
||||
*/
|
||||
export class UmbDuplicateMemberTypeServerDataSource implements UmbDuplicateDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDuplicateMemberTypeServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbDuplicateMemberTypeServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate an item for the given unique
|
||||
* @param {UmbDuplicateRequestArgs} args
|
||||
* @return {*}
|
||||
* @memberof UmbDuplicateDataTypeServerDataSource
|
||||
*/
|
||||
async duplicate(args: UmbDuplicateRequestArgs) {
|
||||
if (!args.unique) throw new Error('Unique is missing');
|
||||
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
MemberTypeService.postMemberTypeByIdCopy({
|
||||
id: args.unique,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { UMB_MEMBER_TYPE_ENTITY_TYPE, UMB_MEMBER_TYPE_ROOT_ENTITY_TYPE } from '.
|
||||
import { UMB_MEMBER_TYPE_DETAIL_REPOSITORY_ALIAS } from '../repository/detail/index.js';
|
||||
import { UMB_MEMBER_TYPE_ITEM_REPOSITORY_ALIAS } from '../repository/index.js';
|
||||
import { UmbCreateMemberTypeEntityAction } from './create.action.js';
|
||||
import { manifests as duplicateManifests } from './duplicate/manifests.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const entityActions: Array<ManifestTypes> = [
|
||||
@@ -31,4 +32,4 @@ const entityActions: Array<ManifestTypes> = [
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests = [...entityActions];
|
||||
export const manifests = [...entityActions, ...duplicateManifests];
|
||||
|
||||
Reference in New Issue
Block a user