Merge pull request #1833 from umbraco/temp-U4-9679

fixes: U4-9679 Inserting partial views in the new template editor is …
This commit is contained in:
Claus
2017-03-28 13:46:24 +02:00
committed by GitHub
3 changed files with 38 additions and 8 deletions

View File

@@ -8,8 +8,15 @@
return "@Umbraco.GetDictionaryValue(\"" + nodeName + "\")";
}
function getInsertPartialSnippet(nodeName) {
return "@Html.Partial(\"" + nodeName + "\")";
function getInsertPartialSnippet(parentId, nodeName) {
var partialViewName = nodeName.replace(".cshtml", "");
if(parentId) {
partialViewName = parentId + "/" + partialViewName;
}
return "@Html.Partial(\"" + partialViewName + "\")";
}
function getQuerySnippet(queryExpression) {

View File

@@ -308,7 +308,7 @@
break;
case "partial":
var code = templateHelper.getInsertPartialSnippet(model.insert.node.name);
var code = templateHelper.getInsertPartialSnippet(model.insert.node.parentId, model.insert.node.name);
insert(code);
break;
@@ -419,8 +419,8 @@
show: true,
title: localizationService.localize("template_insertPartialView"),
select: function(node){
var code = templateHelper.getInsertPartialSnippet(node.name);
var code = templateHelper.getInsertPartialSnippet(node.parentId, node.name);
insert(code);
vm.partialItemOverlay.show = false;

View File

@@ -23,9 +23,32 @@ describe('service: templateHelper', function () {
describe('getInsertPartialSnippet', function () {
it('should return the snippet for inserting a partial', function () {
var snippet = '@Html.Partial("nodeName")';
expect(templateHelper.getInsertPartialSnippet("nodeName")).toBe(snippet);
it('should return the snippet for inserting a partial from the root', function () {
var parentId = "";
var nodeName = "Footer.cshtml";
var snippet = '@Html.Partial("Footer")';
expect(templateHelper.getInsertPartialSnippet(parentId, nodeName)).toBe(snippet);
});
it('should return the snippet for inserting a partial from a folder', function () {
var parentId = "Folder";
var nodeName = "Footer.cshtml";
var snippet = '@Html.Partial("Folder/Footer")';
expect(templateHelper.getInsertPartialSnippet(parentId, nodeName)).toBe(snippet);
});
it('should return the snippet for inserting a partial from a nested folder', function () {
var parentId = "Folder/NestedFolder";
var nodeName = "Footer.cshtml";
var snippet = '@Html.Partial("Folder/NestedFolder/Footer")';
expect(templateHelper.getInsertPartialSnippet(parentId, nodeName)).toBe(snippet);
});
it('should return the snippet for inserting a partial from a folder with spaces in its name', function () {
var parentId = "Folder with spaces";
var nodeName = "Footer.cshtml";
var snippet = '@Html.Partial("Folder with spaces/Footer")';
expect(templateHelper.getInsertPartialSnippet(parentId, nodeName)).toBe(snippet);
});
});