From fb61c55fa782c817ec3aa0f0c7ff9f64f527deb5 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Tue, 4 Dec 2012 03:26:04 +0500 Subject: [PATCH] Started on PartialViewMacros --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 1 + .../developer/Macros/EditMacro.aspx.cs | 39 ++++++++++++++++ .../Macros/EditMacro.aspx.designer.cs | 18 ++++++++ .../umbraco/developer/Macros/editMacro.aspx | 36 +++++++++++---- src/Umbraco.Web/Mvc/ControllerExtensions.cs | 2 +- src/Umbraco.Web/PublishedContentExtensions.cs | 14 ++++++ src/Umbraco.Web/Umbraco.Web.csproj | 2 + ...ureSystemPathsApplicationStartupHandler.cs | 7 ++- .../developer/Macros/editMacro.aspx.cs | 45 ++++++------------- .../businesslogic/macro/IMacroEngine.cs | 9 ++-- src/umbraco.cms/businesslogic/macro/Macro.cs | 2 +- .../businesslogic/macro/MacroModel.cs | 39 ---------------- src/umbraco.cms/umbraco.cms.csproj | 3 ++ 13 files changed, 129 insertions(+), 88 deletions(-) diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index bc06fffbb8..3e7f7e4be1 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -288,6 +288,7 @@ + editMacro.aspx ASPXCodeBehind diff --git a/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.cs b/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.cs index c1c756b42d..5ffcc42354 100644 --- a/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.cs +++ b/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.cs @@ -1,11 +1,50 @@ using System; +using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Web; +using System.Web.UI.WebControls; +using Umbraco.Core.IO; namespace Umbraco.Web.UI.Umbraco.Developer.Macros { public partial class EditMacro : global::umbraco.cms.presentation.developer.editMacro { + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + PopulatePartialViewFiles(); + } + + private void PopulatePartialViewFiles() + { + var partialsDir = IOHelper.MapPath(SystemDirectories.MvcViews + "/MacroPartials"); + var views = GetPartialViewFiles(partialsDir, partialsDir); + PartialViewList.DataSource = views; + PartialViewList.DataBind(); + PartialViewList.Items.Insert(0, new ListItem("Browse partial view files on server...", string.Empty)); + } + + private IEnumerable GetPartialViewFiles(string orgPath, string path) + { + var files = new List(); + var dirInfo = new DirectoryInfo(path); + + // Populate subdirectories + var dirInfos = dirInfo.GetDirectories(); + foreach (var dir in dirInfos) + { + files.AddRange(GetPartialViewFiles(orgPath, path + "/" + dir.Name)); + } + + var fileInfo = dirInfo.GetFiles("*.*"); + + files.AddRange(fileInfo.Select(file => (path.Replace(orgPath, string.Empty).Trim('/') + "/" + file.Name).Trim('/'))); + return files; + } + } } \ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.designer.cs b/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.designer.cs index 73bedddb9e..5b6dde9290 100644 --- a/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.designer.cs +++ b/src/Umbraco.Web.UI/umbraco/developer/Macros/EditMacro.aspx.designer.cs @@ -11,5 +11,23 @@ namespace Umbraco.Web.UI.Umbraco.Developer.Macros { public partial class EditMacro { + + /// + /// SelectedPartialView control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox SelectedPartialView; + + /// + /// PartialViewList control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.DropDownList PartialViewList; } } diff --git a/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx b/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx index 33509f4d86..a958e1e62c 100644 --- a/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx +++ b/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx @@ -3,10 +3,20 @@ <%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> - @@ -32,11 +42,22 @@ - +
+ + + +
- Xslt Icon - Use XSLT file + python Icon + Use MVC Partial View + + + + +
+ Xslt Icon + or XSLT file @@ -46,7 +67,7 @@
- User control Icon + User control Icon or .NET User Control @@ -58,8 +79,7 @@
- Custom Control Icon + Custom Control Icon or .NET Custom Control @@ -72,7 +92,7 @@
- python Icon + python Icon or script file diff --git a/src/Umbraco.Web/Mvc/ControllerExtensions.cs b/src/Umbraco.Web/Mvc/ControllerExtensions.cs index 3fa8495a72..59900e6489 100644 --- a/src/Umbraco.Web/Mvc/ControllerExtensions.cs +++ b/src/Umbraco.Web/Mvc/ControllerExtensions.cs @@ -92,7 +92,7 @@ namespace Umbraco.Web.Mvc : ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName); var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw); viewResult.View.Render(viewContext, sw); - + viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View); return sw.GetStringBuilder().ToString(); } } diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index abad9afdb4..8bcf54459f 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Data; using System.Linq; using System.Web; @@ -12,6 +13,7 @@ using umbraco; using umbraco.cms.businesslogic; using Umbraco.Core; using umbraco.cms.businesslogic.template; +using umbraco.interfaces; namespace Umbraco.Web { @@ -24,6 +26,18 @@ namespace Umbraco.Web /// public static class PublishedContentExtensions { + + /// + /// Converts an INode to an IPublishedContent item + /// + /// + /// + internal static IPublishedContent ConvertFromNode(this INode node) + { + var umbHelper = new UmbracoHelper(UmbracoContext.Current); + return umbHelper.TypedContent(node.Id); + } + /// /// Gets the NiceUrl for the content item /// diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 2037086798..1f6bc43f04 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -249,11 +249,13 @@ + + diff --git a/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs b/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs index a6071c4432..4fa5d515a1 100644 --- a/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs +++ b/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; -using umbraco.IO; +using Umbraco.Core.IO; using umbraco.businesslogic; using umbraco.interfaces; @@ -19,8 +19,11 @@ namespace umbraco.presentation EnsurePathExists(SystemDirectories.Masterpages); EnsurePathExists(SystemDirectories.Media); EnsurePathExists(SystemDirectories.Scripts); - EnsurePathExists(SystemDirectories.Usercontrols); + EnsurePathExists(SystemDirectories.UserControls); EnsurePathExists(SystemDirectories.Xslt); + EnsurePathExists(SystemDirectories.MvcViews); + EnsurePathExists(SystemDirectories.MvcViews + "/Partials"); + EnsurePathExists(SystemDirectories.MvcViews + "/MacroPartials"); } public void EnsurePathExists(string path) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs index 8ef7995f36..510264bec3 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs @@ -25,7 +25,6 @@ namespace umbraco.cms.presentation.developer public editMacro() { CurrentApp = BusinessLogic.DefaultApps.developer.ToString(); - } protected PlaceHolder buttons; @@ -86,17 +85,14 @@ namespace umbraco.cms.presentation.developer macroPropertyBind(); // Load xslt files from default dir - populateXsltFiles(); + PopulateXsltFiles(); // Load python files from default dir - populatePythonFiles(); + PopulatePythonFiles(); // Load usercontrols - populateUserControls(IOHelper.MapPath(SystemDirectories.Usercontrols)); + PopulateUserControls(IOHelper.MapPath(SystemDirectories.Usercontrols)); userControlList.Items.Insert(0, new ListItem("Browse usercontrols on server...", string.Empty)); - userControlList.Attributes.Add("onChange", - "document.getElementById('" + macroUserControl.ClientID + "').value = this[this.selectedIndex].value;"); - } else @@ -167,14 +163,14 @@ namespace umbraco.cms.presentation.developer } } - private void getXsltFilesFromDir(string orgPath, string path, ArrayList files) + private void GetXsltFilesFromDir(string orgPath, string path, ArrayList files) { DirectoryInfo dirInfo = new DirectoryInfo(path); // Populate subdirectories DirectoryInfo[] dirInfos = dirInfo.GetDirectories(); foreach (DirectoryInfo dir in dirInfos) - getXsltFilesFromDir(orgPath, path + "/" + dir.Name, files); + GetXsltFilesFromDir(orgPath, path + "/" + dir.Name, files); FileInfo[] fileInfo = dirInfo.GetFiles("*.xsl*"); @@ -182,19 +178,17 @@ namespace umbraco.cms.presentation.developer files.Add((path.Replace(orgPath, string.Empty).Trim('/') + "/" + file.Name).Trim('/')); } - private void populateXsltFiles() + private void PopulateXsltFiles() { ArrayList xslts = new ArrayList(); string xsltDir = IOHelper.MapPath(SystemDirectories.Xslt + "/"); - getXsltFilesFromDir(xsltDir, xsltDir, xslts); + GetXsltFilesFromDir(xsltDir, xsltDir, xslts); xsltFiles.DataSource = xslts; xsltFiles.DataBind(); xsltFiles.Items.Insert(0, new ListItem("Browse xslt files on server...", string.Empty)); - xsltFiles.Attributes.Add("onChange", - "document.getElementById('" + macroXslt.ClientID + "').value = this[this.selectedIndex].value; document.getElementById('" + macroPython.ClientID + "').value =''"); } - private void getPythonFilesFromDir(string orgPath, string path, ArrayList files) + private void GetPythonFilesFromDir(string orgPath, string path, ArrayList files) { var dirInfo = new DirectoryInfo(path); if (!dirInfo.Exists) @@ -207,19 +201,17 @@ namespace umbraco.cms.presentation.developer // Populate subdirectories var dirInfos = dirInfo.GetDirectories(); foreach (var dir in dirInfos) - getPythonFilesFromDir(orgPath, path + "/" + dir.Name + "/", files); + GetPythonFilesFromDir(orgPath, path + "/" + dir.Name + "/", files); } - private void populatePythonFiles() + private void PopulatePythonFiles() { ArrayList pythons = new ArrayList(); string pythonDir = IOHelper.MapPath(SystemDirectories.MacroScripts + "/"); - getPythonFilesFromDir(pythonDir, pythonDir, pythons); + GetPythonFilesFromDir(pythonDir, pythonDir, pythons); pythonFiles.DataSource = pythons; pythonFiles.DataBind(); pythonFiles.Items.Insert(0, new ListItem("Browse scripting files on server...", string.Empty)); - pythonFiles.Attributes.Add("onChange", - "document.getElementById('" + macroPython.ClientID + "').value = this[this.selectedIndex].value; document.getElementById('" + macroXslt.ClientID + "').value = ''"); } public void deleteMacroProperty(object sender, EventArgs e) @@ -304,7 +296,7 @@ namespace umbraco.cms.presentation.developer } } - private void populateUserControls(string path) + private void PopulateUserControls(string path) { DirectoryInfo di = new DirectoryInfo(path); @@ -313,7 +305,7 @@ namespace umbraco.cms.presentation.developer foreach (FileInfo uc in di.GetFiles("*.ascx")) { userControlList.Items.Add( - new ListItem(SystemDirectories.Usercontrols + + new ListItem(SystemDirectories.Usercontrols + uc.FullName.Substring(rootDir.Length).Replace(IOHelper.DirSepChar, '/'))); /* uc.FullName.IndexOf(usercontrolsDir), @@ -322,7 +314,7 @@ namespace umbraco.cms.presentation.developer } foreach (DirectoryInfo dir in di.GetDirectories()) - populateUserControls(dir.FullName); + PopulateUserControls(dir.FullName); } #region Web Form Designer generated code @@ -418,15 +410,6 @@ namespace umbraco.cms.presentation.developer /// protected global::umbraco.uicontrols.Pane Pane1_2; - /// - /// Table2 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.HtmlControls.HtmlTable Table2; - /// /// macroXslt control. /// diff --git a/src/umbraco.cms/businesslogic/macro/IMacroEngine.cs b/src/umbraco.cms/businesslogic/macro/IMacroEngine.cs index d7f025e87b..952ee11158 100644 --- a/src/umbraco.cms/businesslogic/macro/IMacroEngine.cs +++ b/src/umbraco.cms/businesslogic/macro/IMacroEngine.cs @@ -10,14 +10,11 @@ namespace umbraco.cms.businesslogic.macro string Name { get; } IEnumerable SupportedExtensions { get; } IEnumerable SupportedUIExtensions { get; } + + [Obsolete("This property is not used in the codebase")] Dictionary SupportedProperties { get; } + bool Validate(string code, string tempFileName, INode currentPage, out string errorMessage); string Execute(MacroModel macro, INode currentPage); } - - public interface IMacroEngineResultStatus - { - bool Success { get; } - Exception ResultException { get; } - } } diff --git a/src/umbraco.cms/businesslogic/macro/Macro.cs b/src/umbraco.cms/businesslogic/macro/Macro.cs index 8d024a32ab..8000045b6e 100644 --- a/src/umbraco.cms/businesslogic/macro/Macro.cs +++ b/src/umbraco.cms/businesslogic/macro/Macro.cs @@ -161,7 +161,7 @@ namespace umbraco.cms.businesslogic.macro } /// - /// The python file used to be executed + /// The razor macro file to be executed /// /// Umbraco assumes that the python file is present in the "/python" folder /// diff --git a/src/umbraco.cms/businesslogic/macro/MacroModel.cs b/src/umbraco.cms/businesslogic/macro/MacroModel.cs index da394c3635..2801832c7f 100644 --- a/src/umbraco.cms/businesslogic/macro/MacroModel.cs +++ b/src/umbraco.cms/businesslogic/macro/MacroModel.cs @@ -80,43 +80,4 @@ namespace umbraco.cms.businesslogic.macro MacroType = Macro.FindMacroType(Xslt, ScriptName, TypeName, TypeAssembly); } } - - [Serializable] - public class MacroPropertyModel - { - public string Key { get; set; } - public string Value { get; set; } - public string Type { get; set; } - public string CLRType { get; set; } - public MacroPropertyModel() - { - - } - - public MacroPropertyModel(string key, string value) - { - Key = key; - Value = value; - } - - public MacroPropertyModel(string key, string value, string type, string clrType) - { - Key = key; - Value = value; - Type = type; - CLRType = clrType; - } - } - - public enum MacroTypes - { - XSLT = 1, - CustomControl = 2, - UserControl = 3, - Unknown = 4, - Python = 5, - Script = 6 - } - - } diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index 35d55b0343..40ee3db30d 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -224,8 +224,11 @@ + + +