add duplicate for media type
This commit is contained in:
@@ -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 { UmbDuplicateRepository, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbDuplicateMediaTypeRepository extends UmbRepositoryBase implements UmbDuplicateRepository {
|
||||
#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 { UmbDuplicateDataSource, UmbDuplicateToRequestArgs } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
/**
|
||||
* Duplicate Document Server Data Source
|
||||
* @export
|
||||
* @class UmbDuplicateMediaTypeServerDataSource
|
||||
*/
|
||||
export class UmbDuplicateMediaTypeServerDataSource implements UmbDuplicateDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDuplicateMediaTypeServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbDuplicateMediaTypeServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate an item for the given id 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];
|
||||
|
||||
Reference in New Issue
Block a user