sets the template content when creating a new

This commit is contained in:
Lone Iversen
2024-02-15 14:45:11 +01:00
parent d6ea707195
commit ac7b5d135f
2 changed files with 17 additions and 10 deletions

View File

@@ -34,17 +34,25 @@ export class UmbTemplateServerDataSource implements UmbDetailDataSource<UmbTempl
* @return { CreateTemplateRequestModel }
* @memberof UmbTemplateServerDataSource
*/
async createScaffold(parentUnique: string | null) {
async createScaffold(parentUnique: string | null, preset?: Partial<UmbTemplateDetailModel>) {
// TODO: API throws "Not found". Making snippet hardcoded for now.
/*const scaffold = await tryExecuteAndNotify(
this.#host,
TemplateResource.getTemplateScaffold({ masterTemplateId: parentUnique ?? undefined }),
);*/
const scaffold =
'@using Umbraco.Cms.Web.Common.PublishedModels;\n@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage\n@{\n\tLayout = null;\n}';
const data: UmbTemplateDetailModel = {
entityType: UMB_TEMPLATE_ENTITY_TYPE,
unique: UmbId.new(),
parentUnique,
name: '',
alias: '',
content: '',
masterTemplate: null,
name: preset?.name ?? '',
alias: preset?.alias ?? '',
content: preset?.content ?? scaffold,
masterTemplate: preset?.masterTemplate ?? null,
};
return { data };
}

View File

@@ -129,15 +129,14 @@ ${currentContent}`;
this.setContent(string);
};
async create(parentUnique: string | null) {
const { data } = await this.detailRepository.createScaffold(parentUnique);
async create(parentUnique: string | null, preset?: Partial<UmbTemplateDetailModel>) {
const { data } = await this.detailRepository.createScaffold(parentUnique, preset);
if (!data) return;
this.setIsNew(true);
this.#data.setValue(data);
/*
if (!parentUnique) return;
await this.setMasterTemplate(parentUnique);
*/
}
async save() {