sets the template content when creating a new
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user