From eefb35fae062961c4bc2b16652e7ede81417388f Mon Sep 17 00:00:00 2001 From: Julia Gru <56249914+julczka@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:25:52 +0200 Subject: [PATCH] create empty partial --- .../entity-actions/create/create-empty.action.ts | 2 +- .../create/create-from-snippet.action.ts | 8 ++++++-- .../workspace/partial-views-workspace.context.ts | 15 +++++++++------ .../workspace/partial-views-workspace.element.ts | 5 +++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-empty.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-empty.action.ts index 961d49455f..85c4972003 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-empty.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-empty.action.ts @@ -7,6 +7,6 @@ export class UmbCreateEmptyPartialViewAction } } async execute() { - throw new Error('Method not implemented.'); + history.pushState(null, '', `section/settings/workspace/partial-view/create/${this.unique ?? 'null'}/`); } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-from-snippet.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-from-snippet.action.ts index cb0cda80cb..ddd4ad1a54 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-from-snippet.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create-from-snippet.action.ts @@ -1,12 +1,16 @@ import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; +import { UmbPartialViewsRepository } from '../../repository/index.js'; -export class UmbCreateFromSnippetPartialViewAction }> extends UmbEntityActionBase { +export class UmbCreateFromSnippetPartialViewAction< + T extends { copy(): Promise } +> extends UmbEntityActionBase { constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) { super(host, repositoryAlias, unique); } async execute() { - throw new Error('Method not implemented.'); + const snippets = await this.repository?.getSnippets({}); + console.log(snippets); } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.context.ts index fe4239d28e..6ac89765d3 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.context.ts @@ -6,10 +6,7 @@ import { UmbWorkspaceContext } from '@umbraco-cms/backoffice/workspace'; import { loadCodeEditor } from '@umbraco-cms/backoffice/code-editor'; import { UpdatePartialViewRequestModel } from '@umbraco-cms/backoffice/backend-api'; -export class UmbPartialViewsWorkspaceContext extends UmbWorkspaceContext< - UmbPartialViewsRepository, - PartialViewDetails -> { +export class UmbPartialViewsWorkspaceContext extends UmbWorkspaceContext { getEntityId(): string | undefined { throw new Error('Method not implemented.'); } @@ -81,10 +78,16 @@ export class UmbPartialViewsWorkspaceContext extends UmbWorkspaceContext< } } - async create(parentKey: string | null, name = 'empty') { + async create(parentKey: string | null, name = 'Empty') { const { data } = await this.repository.createScaffold(parentKey, name); + debugger; + const newPartial = { + ...data, + name: '', + path: parentKey ?? '', + }; if (!data) return; this.setIsNew(true); - this.#data.next(data); + this.#data.next(newPartial); } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.element.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.element.ts index 86cf5bc845..46d7cd7f55 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/workspace/partial-views-workspace.element.ts @@ -22,9 +22,10 @@ export class UmbPartialViewsWorkspaceElement extends UmbLitElement { component: () => this.#element, setup: async (component: PageComponent, info: IRoutingInfo) => { const parentKey = info.match.params.parentKey; - const decodePath = decodeURIComponent(parentKey).replace('-cshtml', '.cshtml'); + const decodePath = decodeURIComponent(parentKey); + const snippetName = 'Empty'; - this.#partialViewsWorkspaceContext.create(parentKey); + this.#partialViewsWorkspaceContext.create(parentKey === 'null' ? null : parentKey, snippetName); new UmbWorkspaceIsNewRedirectController( this,