From de58256c3ce7d63045eb9325f54739ddf6a5ebda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 20 Mar 2024 12:30:15 +0100 Subject: [PATCH] partial views --- .../partial-views/workspace/manifests.ts | 7 +- .../partial-view-workspace-editor.element.ts | 4 +- .../partial-view-workspace.context-token.ts | 13 ++++ .../partial-view-workspace.context.ts | 67 +++++++++++++++---- .../workspace/script-workspace.context.ts | 2 + 5 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context-token.ts diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/manifests.ts index 44fb274234..433349499d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/manifests.ts @@ -1,13 +1,14 @@ import { UmbSaveWorkspaceAction } from '@umbraco-cms/backoffice/workspace'; -import type { ManifestWorkspace, ManifestWorkspaceActions } from '@umbraco-cms/backoffice/extension-registry'; +import type { ManifestWorkspaces, ManifestWorkspaceActions } from '@umbraco-cms/backoffice/extension-registry'; export const UMB_PARTIAL_VIEW_WORKSPACE_ALIAS = 'Umb.Workspace.PartialView'; -const workspace: ManifestWorkspace = { +const workspace: ManifestWorkspaces = { type: 'workspace', + kind: 'routable', alias: UMB_PARTIAL_VIEW_WORKSPACE_ALIAS, name: 'Partial View Workspace', - js: () => import('./partial-view-workspace.element.js'), + api: () => import('./partial-view-workspace.context.js'), meta: { entityType: 'partial-view', }, diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace-editor.element.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace-editor.element.ts index 69c4476a59..e334376665 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace-editor.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace-editor.element.ts @@ -1,6 +1,6 @@ import type { UmbTemplatingInsertMenuElement } from '../../components/index.js'; import { getQuerySnippet } from '../../utils/index.js'; -import { UMB_PARTIAL_VIEW_WORKSPACE_CONTEXT } from './partial-view-workspace.context.js'; +import { UMB_PARTIAL_VIEW_WORKSPACE_CONTEXT } from './partial-view-workspace.context-token.js'; import { UMB_TEMPLATE_QUERY_BUILDER_MODAL } from '@umbraco-cms/backoffice/template'; import type { UmbCodeEditorElement } from '@umbraco-cms/backoffice/code-editor'; import type { UUIInputElement } from '@umbraco-cms/backoffice/external/uui'; @@ -117,7 +117,7 @@ export class UmbPartialViewWorkspaceEditorElement extends UmbLitElement { ? this.#renderCodeEditor() : html`
-
`} + `} `; } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context-token.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context-token.ts new file mode 100644 index 0000000000..cd524599bf --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context-token.ts @@ -0,0 +1,13 @@ +import { UMB_PARTIAL_VIEW_ENTITY_TYPE } from '../entity.js'; +import type { UmbPartialViewWorkspaceContext } from './partial-view-workspace.context.js'; +import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; +import type { UmbSaveableWorkspaceContextInterface } from '@umbraco-cms/backoffice/workspace'; + +export const UMB_PARTIAL_VIEW_WORKSPACE_CONTEXT = new UmbContextToken< + UmbSaveableWorkspaceContextInterface, + UmbPartialViewWorkspaceContext +>( + 'UmbWorkspaceContext', + undefined, + (context): context is UmbPartialViewWorkspaceContext => context.getEntityType?.() === UMB_PARTIAL_VIEW_ENTITY_TYPE, +); diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context.ts index 9d701a8c14..764f7623d9 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-view-workspace.context.ts @@ -1,21 +1,29 @@ import { UmbPartialViewDetailRepository } from '../repository/partial-view-detail.repository.js'; import type { UmbPartialViewDetailModel } from '../types.js'; import { UMB_PARTIAL_VIEW_ENTITY_TYPE } from '../entity.js'; +import { UmbPartialViewWorkspaceEditorElement } from './partial-view-workspace-editor.element.js'; import { UmbBooleanState, UmbObjectState } from '@umbraco-cms/backoffice/observable-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import type { UmbSaveableWorkspaceContextInterface } from '@umbraco-cms/backoffice/workspace'; -import { UmbEditableWorkspaceContextBase } from '@umbraco-cms/backoffice/workspace'; +import type { + UmbRoutableWorkspaceContext, + UmbSaveableWorkspaceContextInterface, +} from '@umbraco-cms/backoffice/workspace'; +import { + UmbEditableWorkspaceContextBase, + UmbWorkspaceIsNewRedirectController, + UmbWorkspaceRouteManager, +} from '@umbraco-cms/backoffice/workspace'; import { loadCodeEditor } from '@umbraco-cms/backoffice/code-editor'; -import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; import { PartialViewResource } from '@umbraco-cms/backoffice/external/backend-api'; import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'; import { UmbReloadTreeItemChildrenRequestEntityActionEvent } from '@umbraco-cms/backoffice/tree'; import { UmbRequestReloadStructureForEntityEvent } from '@umbraco-cms/backoffice/event'; +import type { IRoutingInfo, PageComponent } from '@umbraco-cms/backoffice/router'; export class UmbPartialViewWorkspaceContext extends UmbEditableWorkspaceContextBase - implements UmbSaveableWorkspaceContextInterface + implements UmbSaveableWorkspaceContextInterface, UmbRoutableWorkspaceContext { public readonly repository = new UmbPartialViewDetailRepository(this); @@ -30,11 +38,53 @@ export class UmbPartialViewWorkspaceContext #isCodeEditorReady = new UmbBooleanState(false); readonly isCodeEditorReady = this.#isCodeEditorReady.asObservable(); + readonly routes = new UmbWorkspaceRouteManager(this); + constructor(host: UmbControllerHost) { super(host, 'Umb.Workspace.PartialView'); this.#loadCodeEditor(); + + this.routes.setRoutes([ + { + path: 'create/parent/:entityType/:parentUnique/snippet/:snippetId', + component: UmbPartialViewWorkspaceEditorElement, + setup: async (component: PageComponent, info: IRoutingInfo) => { + const parentEntityType = info.match.params.entityType; + const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique; + const snippetId = info.match.params.snippetId; + this.#onCreate({ entityType: parentEntityType, unique: parentUnique }, snippetId); + }, + }, + { + path: 'create/parent/:entityType/:parentUnique', + component: UmbPartialViewWorkspaceEditorElement, + setup: async (component: PageComponent, info: IRoutingInfo) => { + const parentEntityType = info.match.params.entityType; + const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique; + this.#onCreate({ entityType: parentEntityType, unique: parentUnique }); + }, + }, + { + path: 'edit/:unique', + component: UmbPartialViewWorkspaceEditorElement, + setup: (component: PageComponent, info: IRoutingInfo) => { + const unique = info.match.params.unique; + this.load(unique); + }, + }, + ]); } + #onCreate = async (parent: { entityType: string; unique: string | null }, snippetId?: string) => { + await this.create(parent, snippetId); + + new UmbWorkspaceIsNewRedirectController( + this, + this, + this.getHostElement().shadowRoot!.querySelector('umb-router-slot')!, + ); + }; + protected resetState(): void { super.resetState(); this.#data.setValue(undefined); @@ -152,11 +202,4 @@ export class UmbPartialViewWorkspaceContext } } -export const UMB_PARTIAL_VIEW_WORKSPACE_CONTEXT = new UmbContextToken< - UmbSaveableWorkspaceContextInterface, - UmbPartialViewWorkspaceContext ->( - 'UmbWorkspaceContext', - undefined, - (context): context is UmbPartialViewWorkspaceContext => context.getEntityType?.() === UMB_PARTIAL_VIEW_ENTITY_TYPE, -); +export { UmbPartialViewWorkspaceContext as api }; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/workspace/script-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/workspace/script-workspace.context.ts index d7c0fd7ea3..ea0c25b340 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/workspace/script-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/workspace/script-workspace.context.ts @@ -167,3 +167,5 @@ export class UmbScriptWorkspaceContext this.#data.destroy(); } } + +export { UmbScriptWorkspaceContext as api };