add sort children of media entity
This commit is contained in:
@@ -2,6 +2,7 @@ import { UMB_MEDIA_DETAIL_REPOSITORY_ALIAS, UMB_MEDIA_ITEM_REPOSITORY_ALIAS } fr
|
||||
import { UMB_MEDIA_ENTITY_TYPE } from '../entity.js';
|
||||
import { manifests as createManifests } from './create/manifests.js';
|
||||
import { manifests as moveManifests } from './move-to/manifests.js';
|
||||
import { manifests as sortChildrenOfManifests } from './sort-children-of/manifests.js';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UMB_ENTITY_IS_TRASHED_CONDITION_ALIAS } from '@umbraco-cms/backoffice/recycle-bin';
|
||||
|
||||
@@ -25,4 +26,4 @@ const entityActions: Array<ManifestTypes> = [
|
||||
},
|
||||
];
|
||||
|
||||
export const manifests: Array<ManifestTypes> = [...entityActions, ...moveManifests];
|
||||
export const manifests: Array<ManifestTypes> = [...entityActions, ...moveManifests, ...sortChildrenOfManifests];
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export { UmbSortChildrenOfMediaRepository, UMB_SORT_CHILDREN_OF_MEDIA_REPOSITORY_ALIAS } from './repository/index.js';
|
||||
|
||||
export type { UmbSortChildrenOfArgs } from './repository/index.js';
|
||||
@@ -0,0 +1,28 @@
|
||||
import { UMB_MEDIA_ENTITY_TYPE, UMB_MEDIA_ROOT_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_MEDIA_ITEM_REPOSITORY_ALIAS } from '../../repository/index.js';
|
||||
import { UMB_MEDIA_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
|
||||
import { UMB_SORT_CHILDREN_OF_MEDIA_REPOSITORY_ALIAS } from './repository/constants.js';
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import { UMB_ENTITY_IS_NOT_TRASHED_CONDITION_ALIAS } from '@umbraco-cms/backoffice/recycle-bin';
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const manifests: Array<ManifestTypes> = [
|
||||
...repositoryManifests,
|
||||
{
|
||||
type: 'entityAction',
|
||||
kind: 'sortChildrenOf',
|
||||
alias: 'Umb.EntityAction.Media.SortChildrenOf',
|
||||
name: 'Sort Children Of Media Entity Action',
|
||||
forEntityTypes: [UMB_MEDIA_ROOT_ENTITY_TYPE, UMB_MEDIA_ENTITY_TYPE],
|
||||
meta: {
|
||||
itemRepositoryAlias: UMB_MEDIA_ITEM_REPOSITORY_ALIAS,
|
||||
sortChildrenOfRepositoryAlias: UMB_SORT_CHILDREN_OF_MEDIA_REPOSITORY_ALIAS,
|
||||
treeRepositoryAlias: UMB_MEDIA_TREE_REPOSITORY_ALIAS,
|
||||
},
|
||||
conditions: [
|
||||
{
|
||||
alias: UMB_ENTITY_IS_NOT_TRASHED_CONDITION_ALIAS,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_SORT_CHILDREN_OF_MEDIA_REPOSITORY_ALIAS = 'Umb.Repository.Media.SortChildrenOf';
|
||||
@@ -0,0 +1,3 @@
|
||||
export { UmbSortChildrenOfMediaRepository } from './sort-children-of.repository.js';
|
||||
export { UMB_SORT_CHILDREN_OF_MEDIA_REPOSITORY_ALIAS } from './constants.js';
|
||||
export type { UmbSortChildrenOfArgs } from './types.js';
|
||||
@@ -0,0 +1,11 @@
|
||||
import { UMB_SORT_CHILDREN_OF_MEDIA_REPOSITORY_ALIAS } from './constants.js';
|
||||
import type { ManifestRepository, ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const repository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_SORT_CHILDREN_OF_MEDIA_REPOSITORY_ALIAS,
|
||||
name: 'Sort Children Of Media Repository',
|
||||
api: () => import('./sort-children-of.repository.js'),
|
||||
};
|
||||
|
||||
export const manifests: Array<ManifestTypes> = [repository];
|
||||
@@ -0,0 +1,39 @@
|
||||
import { UmbSortChildrenOfMediaServerDataSource } from './sort-children-of.server.data.js';
|
||||
import type { UmbSortChildrenOfArgs } from './types.js';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import type { UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
|
||||
|
||||
export class UmbSortChildrenOfMediaRepository extends UmbControllerBase implements UmbApi {
|
||||
#dataSource: UmbSortChildrenOfMediaServerDataSource;
|
||||
|
||||
#notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
|
||||
this.#dataSource = new UmbSortChildrenOfMediaServerDataSource(this);
|
||||
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => {
|
||||
this.#notificationContext = instance;
|
||||
});
|
||||
}
|
||||
|
||||
async sortChildrenOf(args: UmbSortChildrenOfArgs) {
|
||||
if (args.unique === undefined) throw new Error('Unique is missing');
|
||||
if (!args.sorting) throw new Error('Sorting details are missing');
|
||||
|
||||
const { error } = await this.#dataSource.sortChildrenOf(args);
|
||||
|
||||
if (!error) {
|
||||
const notification = { data: { message: `Items sorted` } };
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
}
|
||||
|
||||
export { UmbSortChildrenOfMediaRepository as api };
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { UmbSortChildrenOfArgs } from './types.js';
|
||||
import { MediaService } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
/**
|
||||
* A server data source for sorting children of a Media
|
||||
* @export
|
||||
* @class UmbSortChildrenOfMediaServerDataSource
|
||||
* @implements {RepositoryDetailDataSource}
|
||||
*/
|
||||
export class UmbSortChildrenOfMediaServerDataSource {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbSortChildrenOfMediaServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbSortChildrenOfMediaServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Public Access for the given Media unique
|
||||
* @param {UmbSortChildrenOfArgs} args
|
||||
* @memberof UmbSortChildrenOfMediaServerDataSource
|
||||
*/
|
||||
async sortChildrenOf(args: UmbSortChildrenOfArgs) {
|
||||
if (args.unique === undefined) throw new Error('unique is missing');
|
||||
|
||||
const sortingMapping = args.sorting.map((item) => ({ id: item.unique, sortOrder: item.sortOrder }));
|
||||
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
MediaService.putMediaSort({
|
||||
requestBody: {
|
||||
parent: args.unique ? { id: args.unique } : null,
|
||||
sorting: sortingMapping,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface UmbSortChildrenOfArgs {
|
||||
unique: string | null;
|
||||
sorting: Array<{ unique: string; sortOrder: number }>;
|
||||
}
|
||||
Reference in New Issue
Block a user