register folder workspace

This commit is contained in:
Mads Rasmussen
2024-09-26 17:06:17 +02:00
parent 59860da588
commit 68388cf880
8 changed files with 130 additions and 0 deletions

View File

@@ -1 +1,2 @@
export * from './repository/index.js';
export * from './workspace/index.js';

View File

@@ -1,6 +1,7 @@
import { UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE } from '../../entity.js';
import { UMB_PARTIAL_VIEW_FOLDER_REPOSITORY_ALIAS } from './repository/index.js';
import { manifests as repositoryManifests } from './repository/manifests.js';
import { manifests as workspaceManifests } from './workspace/manifests.js';
export const UMB_DELETE_PARTIAL_VIEW_FOLDER_ENTITY_ACTION_ALIAS = 'Umb.EntityAction.PartialView.Folder.Delete';
@@ -16,4 +17,5 @@ export const manifests: Array<UmbExtensionManifest> = [
},
},
...repositoryManifests,
...workspaceManifests,
];

View File

@@ -0,0 +1 @@
export const UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_ALIAS = 'Umb.Workspace.PartialView.Folder';

View File

@@ -0,0 +1 @@
export * from './constants.js';

View File

@@ -0,0 +1,15 @@
import { UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE } from '../../../entity.js';
import { UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_ALIAS } from './constants.js';
export const manifests: Array<UmbExtensionManifest> = [
{
type: 'workspace',
kind: 'routable',
alias: UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_ALIAS,
name: 'Partial View Folder Workspace',
api: () => import('./partial-view-folder-workspace.context.js'),
meta: {
entityType: UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE,
},
},
];

View File

@@ -0,0 +1,47 @@
import { UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_ALIAS } from './constants.js';
import { UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_CONTEXT } from './partial-view-folder-workspace.context-token.js';
import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
const elementName = 'umb-partial-view-folder-workspace-editor';
@customElement(elementName)
export class UmbPartialViewFolderWorkspaceEditorElement extends UmbLitElement {
@state()
private _name = '';
#workspaceContext?: typeof UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_CONTEXT.TYPE;
constructor() {
super();
this.consumeContext(UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_CONTEXT, (workspaceContext) => {
this.#workspaceContext = workspaceContext;
this.#observeName();
});
}
#observeName() {
if (!this.#workspaceContext) return;
this.observe(this.#workspaceContext.name, (name) => {
if (name !== this._name) {
this._name = name ?? '';
}
});
}
override render() {
return html`<umb-workspace-editor headline=${this._name} alias=${UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_ALIAS}>
</umb-workspace-editor>`;
}
static override styles = [UmbTextStyles, css``];
}
export { UmbPartialViewFolderWorkspaceEditorElement as element };
declare global {
interface HTMLElementTagNameMap {
[elementName]: UmbPartialViewFolderWorkspaceEditorElement;
}
}

View File

@@ -0,0 +1,14 @@
import { UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE } from '../../../entity.js';
import type { UmbPartialViewFolderWorkspaceContext } from './partial-view-folder-workspace.context.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import type { UmbWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
export const UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_CONTEXT = new UmbContextToken<
UmbWorkspaceContext,
UmbPartialViewFolderWorkspaceContext
>(
'UmbWorkspaceContext',
undefined,
(context): context is UmbPartialViewFolderWorkspaceContext =>
context.getEntityType?.() === UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE,
);

View File

@@ -0,0 +1,49 @@
import { UMB_PARTIAL_VIEW_FOLDER_REPOSITORY_ALIAS, type UmbPartialViewFolderRepository } from '../repository/index.js';
import { UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE } from '../../../entity.js';
import { UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_ALIAS } from './constants.js';
import { UmbPartialViewFolderWorkspaceEditorElement } from './partial-view-folder-workspace-editor.element.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import {
UmbEntityDetailWorkspaceContextBase,
type UmbRoutableWorkspaceContext,
type UmbSubmittableWorkspaceContext,
} from '@umbraco-cms/backoffice/workspace';
import type { IRoutingInfo, PageComponent } from '@umbraco-cms/backoffice/router';
import type { UmbFolderModel } from '@umbraco-cms/backoffice/tree';
export class UmbPartialViewFolderWorkspaceContext
extends UmbEntityDetailWorkspaceContextBase<UmbFolderModel, UmbPartialViewFolderRepository>
implements UmbSubmittableWorkspaceContext, UmbRoutableWorkspaceContext
{
public readonly name = this._data.createObservablePartOfCurrent((data) => data?.name);
constructor(host: UmbControllerHost) {
super(host, {
workspaceAlias: UMB_PARTIAL_VIEW_FOLDER_WORKSPACE_ALIAS,
entityType: UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE,
detailRepositoryAlias: UMB_PARTIAL_VIEW_FOLDER_REPOSITORY_ALIAS,
});
this.routes.setRoutes([
{
path: 'edit/:unique',
component: UmbPartialViewFolderWorkspaceEditorElement,
setup: (component: PageComponent, info: IRoutingInfo) => {
const unique = info.match.params.unique;
this.load(unique);
},
},
]);
}
/**
* @description Set the name of the script
* @param {string} value
* @memberof UmbScriptWorkspaceContext
*/
public setName(value: string) {
this._data.updateCurrent({ name: value });
}
}
export { UmbPartialViewFolderWorkspaceContext as api };