fix merge
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { MEDIA_TYPE_ENTITY_TYPE, MEDIA_TYPE_FOLDER_ENTITY_TYPE, MEDIA_TYPE_ROOT_ENTITY_TYPE } from '../../index.js';
|
||||
import {
|
||||
UMB_MEDIA_TYPE_ENTITY_TYPE,
|
||||
MEDIA_TYPE_FOLDER_ENTITY_TYPE,
|
||||
UMB_MEDIA_TYPE_ROOT_ENTITY_TYPE,
|
||||
} from '../../index.js';
|
||||
import { MEDIA_TYPE_DETAIL_REPOSITORY_ALIAS } from '../../repository/index.js';
|
||||
import { UmbCreateMediaTypeEntityAction } from './create.action.js';
|
||||
import { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
@@ -14,14 +18,14 @@ const entityActions: Array<ManifestTypes> = [
|
||||
icon: 'icon-add',
|
||||
label: 'Create...',
|
||||
repositoryAlias: MEDIA_TYPE_DETAIL_REPOSITORY_ALIAS,
|
||||
entityTypes: [MEDIA_TYPE_ENTITY_TYPE, MEDIA_TYPE_ROOT_ENTITY_TYPE, MEDIA_TYPE_FOLDER_ENTITY_TYPE],
|
||||
entityTypes: [UMB_MEDIA_TYPE_ENTITY_TYPE, UMB_MEDIA_TYPE_ROOT_ENTITY_TYPE, MEDIA_TYPE_FOLDER_ENTITY_TYPE],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'modal',
|
||||
alias: 'Umb.Modal.MediaTypeCreateOptions',
|
||||
name: 'Media Type Create Options Modal',
|
||||
loader: () => import('./modal/media-type-create-options-modal.element.js'),
|
||||
js: () => import('./modal/media-type-create-options-modal.element.js'),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ export class UmbMediaTypeDetailRepository
|
||||
if (!id) throw new Error('Id is missing');
|
||||
await this.#init;
|
||||
|
||||
const { data, error } = await this.#detailDataSource.get(id);
|
||||
const { data, error } = await this.#detailDataSource.read(id);
|
||||
|
||||
if (data) {
|
||||
this.#detailStore?.append(data);
|
||||
@@ -91,20 +91,13 @@ export class UmbMediaTypeDetailRepository
|
||||
return this.#detailStore!.byId(id);
|
||||
}
|
||||
|
||||
// TODO: we need to figure out where to put this
|
||||
async requestAllowedChildTypesOf(id: string) {
|
||||
if (!id) throw new Error('Id is missing');
|
||||
await this.#init;
|
||||
return this.#detailDataSource.getAllowedChildrenOf(id);
|
||||
}
|
||||
|
||||
// Could potentially be general methods:
|
||||
|
||||
async create(mediaType: ItemType) {
|
||||
if (!mediaType || !mediaType.id) throw new Error('Media Type is missing');
|
||||
await this.#init;
|
||||
|
||||
const { error } = await this.#detailDataSource.insert(mediaType);
|
||||
const { error } = await this.#detailDataSource.create(mediaType);
|
||||
|
||||
if (!error) {
|
||||
this.#detailStore?.append(mediaType);
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import type { UmbDataSource } from '@umbraco-cms/backoffice/repository';
|
||||
import {
|
||||
CreateMediaTypeRequestModel,
|
||||
MediaTypeResource,
|
||||
MediaTypeResponseModel,
|
||||
UpdateMediaTypeRequestModel,
|
||||
} from '@umbraco-cms/backoffice/backend-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
import { UmbId } from '@umbraco-cms/backoffice/id';
|
||||
|
||||
/**
|
||||
* A data source for the Media Type that fetches data from the server
|
||||
* @export
|
||||
* @class UmbMediaTypeServerDataSource
|
||||
* @implements {RepositoryDetailDataSource}
|
||||
*/
|
||||
export class UmbMediaTypeServerDataSource
|
||||
implements UmbDataSource<CreateMediaTypeRequestModel, any, UpdateMediaTypeRequestModel, MediaTypeResponseModel>
|
||||
{
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbMediaServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbMediaServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a Media with the given id from the server
|
||||
* @param {string} id
|
||||
* @return {*}
|
||||
* @memberof UmbMediaTypeServerDataSource
|
||||
*/
|
||||
async read(id: string) {
|
||||
if (!id) {
|
||||
throw new Error('Id is missing');
|
||||
}
|
||||
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
MediaTypeResource.getMediaTypeById({
|
||||
id: id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Media scaffold
|
||||
* @param {(string | null)} parentId
|
||||
* @return {*}
|
||||
* @memberof UmbMediaTypeServerDataSource
|
||||
*/
|
||||
async createScaffold(parentId: string | null) {
|
||||
//, parentId: string | null
|
||||
const data: MediaTypeResponseModel = {
|
||||
id: UmbId.new(),
|
||||
//parentId: parentId,
|
||||
name: '',
|
||||
alias: '',
|
||||
description: '',
|
||||
icon: 'icon-picture',
|
||||
allowedAsRoot: false,
|
||||
variesByCulture: false,
|
||||
variesBySegment: false,
|
||||
isElement: false,
|
||||
allowedContentTypes: [],
|
||||
compositions: [],
|
||||
properties: [],
|
||||
containers: [],
|
||||
};
|
||||
|
||||
return { data };
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Media Type on the server
|
||||
* @param {CreateMediaTypeRequestModel} mediaType
|
||||
* @return {*}
|
||||
* @memberof UmbMediaTypeServerDataSource
|
||||
*/
|
||||
async create(mediaType: CreateMediaTypeRequestModel) {
|
||||
if (!mediaType) throw new Error('Media Type is missing');
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
MediaTypeResource.postMediaType({
|
||||
requestBody: mediaType,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a Media Type on the server
|
||||
* @param {string} id
|
||||
* @param {Media} mediaType
|
||||
* @return {*}
|
||||
* @memberof UmbMediaTypeServerDataSource
|
||||
*/
|
||||
async update(id: string, mediaType: UpdateMediaTypeRequestModel) {
|
||||
if (!id) throw new Error('Id is missing');
|
||||
|
||||
mediaType = { ...mediaType };
|
||||
|
||||
// TODO: Hack to remove some props that ruins the media-type post end-point.
|
||||
(mediaType as any).id = undefined;
|
||||
|
||||
return tryExecuteAndNotify(this.#host, MediaTypeResource.putMediaTypeById({ id, requestBody: mediaType }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a Template on the server
|
||||
* @param {string} id
|
||||
* @return {*}
|
||||
* @memberof UmbMediaTypeServerDataSource
|
||||
*/
|
||||
async delete(id: string) {
|
||||
if (!id) {
|
||||
throw new Error('Id is missing');
|
||||
}
|
||||
|
||||
// TODO: Hack the type to avoid type-error here:
|
||||
return tryExecuteAndNotify(this.#host, MediaTypeResource.deleteMediaTypeById({ id })) as any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed media types for a given parent id
|
||||
* @param {string} id
|
||||
* @return {*}
|
||||
* @memberof UmbMediaTypeServerDataSource
|
||||
*/
|
||||
async getAllowedChildrenOf(id: string) {
|
||||
if (!id) throw new Error('Id is missing');
|
||||
|
||||
return tryExecuteAndNotify(
|
||||
this.#host,
|
||||
fetch(`/umbraco/management/api/v1/media-type/allowed-children-of/${id}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then((res) => res.json()),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MEDIA_TYPE_ROOT_ENTITY_TYPE } from '../index.js';
|
||||
import { UMB_MEDIA_TYPE_ROOT_ENTITY_TYPE } from '../index.js';
|
||||
import { UmbMediaTypeTreeServerDataSource } from './media-type.tree.server.data-source.js';
|
||||
import { UMB_MEDIA_TYPE_TREE_STORE_CONTEXT } from './media-type.tree.store.js';
|
||||
import { UmbMediaTypeTreeItemModel, UmbMediaTypeTreeRootModel } from './types.js';
|
||||
@@ -17,7 +17,7 @@ export class UmbMediaTypeTreeRepository
|
||||
async requestTreeRoot() {
|
||||
const data = {
|
||||
id: null,
|
||||
type: MEDIA_TYPE_ROOT_ENTITY_TYPE,
|
||||
type: UMB_MEDIA_TYPE_ROOT_ENTITY_TYPE,
|
||||
name: 'Media Types',
|
||||
icon: 'icon-folder',
|
||||
hasChildren: true,
|
||||
|
||||
@@ -22,7 +22,7 @@ const workspaceEditorViews: Array<ManifestWorkspaceEditorView> = [
|
||||
type: 'workspaceEditorView',
|
||||
alias: 'Umb.WorkspaceView.MediaType.Design',
|
||||
name: 'Media Type Workspace Design View',
|
||||
loader: () => import('./views/design/media-type-workspace-view-edit.element.js'),
|
||||
js: () => import('./views/design/media-type-workspace-view-edit.element.js'),
|
||||
weight: 1000,
|
||||
meta: {
|
||||
label: 'Design',
|
||||
@@ -40,7 +40,7 @@ const workspaceEditorViews: Array<ManifestWorkspaceEditorView> = [
|
||||
type: 'workspaceEditorView',
|
||||
alias: 'Umb.WorkspaceView.MediaType.Structure',
|
||||
name: 'Media Type Workspace Structure View',
|
||||
loader: () => import('./views/structure/media-type-workspace-view-structure.element.js'),
|
||||
js: () => import('./views/structure/media-type-workspace-view-structure.element.js'),
|
||||
weight: 800,
|
||||
meta: {
|
||||
label: 'Structure',
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
import { UmbMediaTypeRepository } from '../repository/media-type.repository.js';
|
||||
import { UmbSaveableWorkspaceContextInterface, UmbEditableWorkspaceContextBase } from '@umbraco-cms/backoffice/workspace';
|
||||
import { UmbMediaTypeDetailRepository } from '../repository/detail/media-type-detail.repository.js';
|
||||
import {
|
||||
UmbSaveableWorkspaceContextInterface,
|
||||
UmbEditableWorkspaceContextBase,
|
||||
} from '@umbraco-cms/backoffice/workspace';
|
||||
import { UmbContentTypePropertyStructureManager } from '@umbraco-cms/backoffice/content-type';
|
||||
import { UmbWorkspaceContext, UmbSaveableWorkspaceContextInterface } from '@umbraco-cms/backoffice/workspace';
|
||||
import type {
|
||||
ContentTypeCompositionModel,
|
||||
ContentTypeSortModel,
|
||||
MediaTypeResponseModel,
|
||||
} from '@umbraco-cms/backoffice/backend-api';
|
||||
import { type MediaTypeResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
|
||||
|
||||
type EntityType = MediaTypeResponseModel;
|
||||
export class UmbMediaTypeWorkspaceContext
|
||||
extends UmbEditableWorkspaceContextBase<UmbMediaTypeRepository, EntityType>
|
||||
extends UmbWorkspaceContext<UmbMediaTypeDetailRepository, EntityType>
|
||||
extends UmbEditableWorkspaceContextBase<UmbMediaTypeDetailRepository, EntityType>
|
||||
implements UmbSaveableWorkspaceContextInterface<EntityType | undefined>
|
||||
{
|
||||
// Draft is located in structure manager
|
||||
|
||||
Reference in New Issue
Block a user