add parent aliast to the content when creating the template

This commit is contained in:
Julia Gru
2023-05-31 15:29:06 +02:00
parent fb80ec07af
commit 858e6314f7
2 changed files with 12 additions and 11 deletions

View File

@@ -122,11 +122,19 @@ export class UmbTemplateWorkspaceContext extends UmbWorkspaceContext<UmbTemplate
}
}
async createScaffold() {
async createScaffold(parentId: string | null = null) {
const { data } = await this.repository.createScaffold();
if (!data) return;
this.setIsNew(true);
this.#data.next(data as any);
this.#data.next({ ...data, id: '', name: '', alias: '', $type: 'TemplateResponseModel' });
if (!parentId || parentId === 'root') return;
await this.setMasterTemplate(parentId);
const RegexString = /(@{[\s\S][^if]*?Layout\s*?=\s*?)("[^"]*?"|null)(;[\s\S]*?})/gi;
const content = this.#data.value?.content ?? '';
const masterTemplateName = this.#masterTemplate.value?.name ?? '';
const string = content.replace(RegexString, `$1"${masterTemplateName}.cshtml"$3`) ?? '';
this.setContent(string);
}
public destroy() {

View File

@@ -12,18 +12,11 @@ export class UmbTemplateWorkspaceElement extends UmbLitElement {
this.#templateWorkspaceContext.load(entityId);
}
@state()
private _name?: string | null = '';
@state()
private _content?: string | null = '';
#templateWorkspaceContext = new UmbTemplateWorkspaceContext(this);
#routerPath? = '';
#element = document.createElement('umb-template-workspace-edit');
#key = '';
@state()
_routes: UmbRoute[] = [
@@ -31,8 +24,8 @@ export class UmbTemplateWorkspaceElement extends UmbLitElement {
path: 'create/:parentKey',
component: () => this.#element,
setup: (component: PageComponent, info: IRoutingInfo) => {
// const parentKey = info.match.params.parentKey;
this.#templateWorkspaceContext.createScaffold();
const parentKey = info.match.params.parentKey;
this.#templateWorkspaceContext.createScaffold(parentKey);
},
},
{