Removes the need for duplicate templates for partial views. Of course we can have partial view only templates if necessary but currently we just borrow them from the partial view macros and update the header

This commit is contained in:
Shannon
2014-02-10 13:50:31 +11:00
parent ccaf82d797
commit 1faeb76c27
21 changed files with 116 additions and 485 deletions

View File

@@ -2167,7 +2167,6 @@
<SubType>Code</SubType>
</Content>
<Content Include="Umbraco\Scripting\templates\cshtml\MultinodeTree-picker.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\Empty.cshtml" />
<Content Include="Umbraco\PartialViewMacros\Templates\EditProfile.cshtml" />
<Content Include="Umbraco\PartialViewMacros\Templates\Empty.cshtml" />
<Content Include="Umbraco\PartialViewMacros\Templates\Login.cshtml" />
@@ -2192,21 +2191,6 @@
<Content Include="Umbraco\PartialViewMacros\Templates\MultinodeTree-picker.cshtml" />
<Content Include="Umbraco\PartialViewMacros\Templates\Navigation.cshtml" />
<Content Include="Umbraco\PartialViewMacros\Templates\SiteMap.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\Breadcrumb.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\Empty %28ForUseWithCustomViews%29.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\ListAncestorsFromCurrentPage.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\ListChildPagesFromCurrentPage.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\ListChildPagesOrderedByDate.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\ListChildPagesOrderedByName.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\ListChildPagesWithDoctype.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\ListDescendantsFromCurrentPage.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\EditProfile.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\Login.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\LoginStatus.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\RegisterMember.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\MultinodeTree-picker.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\Navigation.cshtml" />
<Content Include="Umbraco\PartialViews\Templates\SiteMap.cshtml" />
<None Include="Umbraco_client\CodeMirror\js\mode\coffeescript\LICENSE" />
<None Include="Umbraco_client\CodeMirror\js\mode\pascal\LICENSE" />
<None Include="Umbraco_client\CodeMirror\js\mode\perl\LICENSE" />
@@ -2664,6 +2648,7 @@
<Folder Include="MasterPages\" />
<Folder Include="Media\" />
<Folder Include="Scripts\" />
<Folder Include="Umbraco\PartialViews\Templates\" />
<Folder Include="Umbraco_Client\FolderBrowser\Images\" />
<Folder Include="Umbraco_Client\Tags\images\" />
<Folder Include="UserControls\" />

View File

@@ -1,22 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
This snippet makes a breadcrumb of parents using an unordred html list.
How it works:
- It uses the Ancestors() method to get all parents and then generates links so the visitor get go back
- Finally it outputs the name of the current page (without a link)
*@
@if (CurrentPage.Ancestors().Any())
{
<ul class="breadcrumb">
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@foreach (var page in CurrentPage.Ancestors().OrderBy("Level"))
{
<li><a href="@page.Url">@page.Name</a> <span class="divider">/</span></li>
}
@* Display the current page as the last item in the list *@
<li class="active">@CurrentPage.Name</li>
</ul>
}

View File

@@ -1,54 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
var profileModel = Members.CreateProfileModel();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
}
@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
@Html.RenderJsHere()
@if (Members.IsLoggedIn())
{
using (Html.BeginUmbracoForm<UmbProfileController>("HandleUpdateProfile"))
{
<fieldset>
<legend>Edit profile</legend>
@Html.ValidationSummary(true)
@Html.LabelFor(m => profileModel.Name)
@Html.TextBoxFor(m => profileModel.Name)
@Html.ValidationMessageFor(m => profileModel.Name)
<br />
@Html.LabelFor(m => profileModel.Email)
@Html.TextBoxFor(m => profileModel.Email)
@Html.ValidationMessageFor(m => profileModel.Email)
<br />
@for (var i = 0; i < profileModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
@Html.EditorFor(m => profileModel.MemberProperties[i].Value)
@Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
<br />
}
@Html.HiddenFor(m => profileModel.MemberTypeAlias)
<button>Save</button>
</fieldset>
}
}

View File

@@ -1 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>

View File

@@ -1 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

View File

@@ -1,16 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@* Check the current page has ancestors *@
@if (CurrentPage.Ancestors().Any())
{
<ul>
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@foreach (var page in CurrentPage.Ancestors().OrderBy("Level"))
{
<li><a href="@page.Url">@page.Name</a> &raquo;</li>
}
@* Display the current page as the last item in the list *@
<li>@CurrentPage.Name</li>
</ul>
}

View File

@@ -1,15 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
@if (CurrentPage.Children.Where("Visible").Any())
{
<ul>
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in CurrentPage.Children.Where("Visible"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>
</li>
}
</ul>
}

View File

@@ -1,10 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<ul>
@*OrderBy() takes the property to sort by and optionally order desc/asc *@
@foreach (var page in CurrentPage.Children.Where("Visible").OrderBy("CreateDate desc"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>

View File

@@ -1,8 +0,0 @@
@inherits Umbraco.Web.Macros.PartialViewMacroPage
<ul>
@*OrderBy() takes the property to sort by*@
@foreach (var page in CurrentPage.Children.Where("Visible").OrderBy("Name"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>

View File

@@ -1,32 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
This snippet shows how simple it is to fetch only children of a certain Document Type using Razor. Instead of
calling .Children, simply call .AliasOfDocumentType in plural.
For instance .Textpages or .NewsArticles (you can find the alias of your Document Type by editing it in the
Settings section).
*@
@{
@*Build a query and return the visible items *@
var selection= CurrentPage.Textpages.Where("Visible");
@*
Example of more querying, if you have a true/false property with the alias of shouldBeFeatured:
var selection= Model.Textpages.Where("shouldBeFeatured == true").Where("Visible");
*@
}
@*Determine if there are any nodes in the selection, then render list *@
@if(selection.Any()){
<ul>
@foreach(var page in selection){
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
}

View File

@@ -1,54 +0,0 @@
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
@if (CurrentPage.Children.Where("Visible").Any())
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = CurrentPage.Children.Where("Visible").First().Level;
@* Add in level for a CSS hook *@
<ul class="level-@naviLevel">
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in CurrentPage.Children.Where("Visible"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>
@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("Visible").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children)
}
</li>
}
</ul>
}
@helper childPages(dynamic pages)
{
@* Ensure that we have a collection of pages *@
if (pages.Any())
{
@* Get the first page in pages and get the level *@
var naviLevel = pages.First().Level;
@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@foreach (var page in pages.Where("Visible"))
{
<li>
<a href="@page.Url">@page.Name</a>
@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (page.Children.Where("Visible").Any())
{
@* Call our helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
}
}

View File

@@ -1,41 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
var loginModel = new LoginModel();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
}
@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
@Html.RenderJsHere()
@using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
{
<fieldset>
<legend>Login</legend>
@Html.ValidationSummary(true)
@Html.LabelFor(m => loginModel.Username)
@Html.TextBoxFor(m => loginModel.Username)
@Html.ValidationMessageFor(m => loginModel.Username)
<br />
@Html.LabelFor(m => loginModel.Password)
@Html.PasswordFor(m => loginModel.Password)
@Html.ValidationMessageFor(m => loginModel.Password)
<br />
<button>Login</button>
</fieldset>
}

View File

@@ -1,32 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
var loginStatusModel = Members.GetCurrentLoginStatus();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
}
@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
@Html.RenderJsHere()
@if (loginStatusModel.IsLoggedIn)
{
<p>You are currently logged in as @loginStatusModel.Name</p>
using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout"))
{
<fieldset>
<legend>Logout</legend>
<button>Logout</button>
</fieldset>
}
}

View File

@@ -1,20 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
Macro to list nodes from a Multinode tree picker, using the pickers default settings.
Content Values stored as xml.
To get it working with any site's data structure, simply set the selection equal to the property which has the
multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
*@
@* Lists each selected value from the picker as a link *@
<ul>
@foreach(var id in CurrentPage.PropertyWithPicker){
@*For each link, get the node, and display its name and url*@
var content = Umbraco.Content(id.InnerText);
<li><a href="@content.Url">@content.Name</a></li>
}
</ul>

View File

@@ -1,22 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
Macro to display child pages below the root page of a standard website.
Also highlights the current active page/section in the navigation with
the css class "current".
*@
@{
@*Get the root of the website *@
var root = CurrentPage.AncestorOrSelf(1);
}
<ul>
@foreach (var page in root.Children.Where("Visible"))
{
<li class="@(page.IsAncestorOrSelf(CurrentPage) ? "current" : null)">
<a href="@page.Url">@page.Name</a>
</li>
}
</ul>

View File

@@ -1,91 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
var registerModel = Members.CreateRegistrationModel();
@*
Configurable here:
registerModel.MemberTypeAlias - the default is "Member"
registerModel.RedirectOnSucces - the default is false
registerModel.RedirectUrl - what page do we go to if the registration was successful?
the default is "/" unless RedirectOnSuccess is set to false
registerModel.UsernameIsEmail - the default is true
if you want the username to be different from the email
address, set this to true and add a new Username field in
the form below
@Html.LabelFor(m => registerModel.Username)
@Html.TextBoxFor(m => registerModel.Username)
@Html.ValidationMessageFor(m => registerModel.Username)
*@
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
var success = TempData["FormSuccess"] != null;
}
@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
@Html.RenderJsHere()
@if (success)
{
// This message will show if RedirectOnSucces is set to false (default)
<p>Registration succeeeded.</p>
}
else
{
using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember"))
{
<fieldset>
<legend>Register Member</legend>
@Html.ValidationSummary(true)
@Html.LabelFor(m => registerModel.Name)
@Html.TextBoxFor(m => registerModel.Name)
@Html.ValidationMessageFor(m => registerModel.Name)
<br />
@Html.LabelFor(m => registerModel.Email)
@Html.TextBoxFor(m => registerModel.Email)
@Html.ValidationMessageFor(m => registerModel.Email)
<br />
@Html.LabelFor(m => registerModel.Password)
@Html.PasswordFor(m => registerModel.Password)
@Html.ValidationMessageFor(m => registerModel.Password)
<br />
@if (registerModel.MemberProperties != null) {
for (var i = 0; i < registerModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)
@Html.EditorFor(m => registerModel.MemberProperties[i].Value)
@Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
<br />
}
}
@Html.HiddenFor(m => registerModel.MemberTypeAlias)
@Html.HiddenFor(m => registerModel.RedirectOnSucces)
@Html.HiddenFor(m => registerModel.RedirectUrl)
@Html.HiddenFor(m => registerModel.UsernameIsEmail)
<button>Register</button>
</fieldset>
}
}

View File

@@ -1,32 +0,0 @@
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*Render the sitemap by passing the root node to the traverse helper*@
<div class="sitemap">
@Traverse(CurrentPage.AncestorOrSelf())
</div>
@*Helper method to travers through all descendants*@
@helper Traverse(dynamic node)
{
@* Update the level to reflect how deep you want the sitemap to go *@
var maxLevelForSitemap = 4;
@*Select visible children *@
var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
@*If any items are returned, render a list *@
if (items.Any())
{
<ul>
@foreach (var item in items)
{
<li class="level-@item.Level">
<a href="@item.Url">@item.Name</a>
@*Run the traverse helper again *@
@Traverse(item)
</li>
}
</ul>
}
}

View File

@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
@@ -21,26 +23,66 @@ namespace Umbraco.Web.UI.Umbraco.Create
private static void LoadTemplates(ListControl list)
{
var path = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViews/Templates/");
var partialViewTemplatePath = new
{
path = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViews/Templates/"),
include = new string[]{}
};
//include these templates from the partial view macro templates!
var partialViewMacrosTemplatePath = new
{
path = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViewMacros/Templates/"),
include = new[]
{
"Breadcrumb",
"EditProfile",
"Empty (ForUseWithCustomViews)",
"Empty",
"ListAncestorsFromCurrentPage",
"ListChildPagesFromCurrentPage",
"ListChildPagesOrderedByDate",
"ListChildPagesOrderedByName",
"ListChildPagesWithDoctype",
"ListDescendantsFromCurrentPage",
"Login",
"LoginStatus",
"MultinodeTree-picker",
"Navigation",
"RegisterMember",
"SiteMap"
}
};
var paths = new[] { partialViewTemplatePath, partialViewMacrosTemplatePath };
const string extension = ".cshtml";
var namesAdded = new List<string>();
list.Items.Clear();
// always add the options of empty snippets
list.Items.Add(new ListItem("Empty", "Empty.cshtml"));
list.Items.Add(new ListItem("Empty (For Use With Custom Views)", "Empty (ForUseWithCustomViews).cshtml"));
if (System.IO.Directory.Exists(path))
foreach (var pathFilter in paths)
{
const string extension = ".cshtml";
//Already adding Empty as the first item, so don't add it again
foreach (var fileInfo in new System.IO.DirectoryInfo(path).GetFiles("*" + extension).Where(f => f.Name.StartsWith("Empty") == false))
if (Directory.Exists(pathFilter.path) == false) continue;
var p = pathFilter;
foreach (var fileInfo in new DirectoryInfo(pathFilter.path).GetFiles("*" + extension)
//check if we've already added this name
.Where(f => namesAdded.InvariantContains(f.Name) == false)
//Already adding Empty as the first item, so don't add it again
.Where(f => f.Name.StartsWith("Empty") == false)
//don't add if not in the inclusion list
.Where(f => p.include.Length == 0 || (p.include.Length > 0 && p.include.InvariantContains(f.Name) == false)))
{
var filename = System.IO.Path.GetFileName(fileInfo.FullName);
var filename = Path.GetFileName(fileInfo.FullName);
namesAdded.Add(filename);
var liText = filename.Replace(extension, "").SplitPascalCasing().ToFirstUpperInvariant();
list.Items.Add(new ListItem(liText, filename));
}
}
}
protected void SubmitButton_Click(object sender, System.EventArgs e)

View File

@@ -11,6 +11,8 @@ namespace Umbraco.Web.UI.Umbraco.Create
{
public partial class PartialViewMacro : UserControl
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);