From dbe9c6a2a92b2ca0c5a836e2739734f6822a82d2 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Sun, 30 Dec 2012 00:59:25 +0300 Subject: [PATCH] Fixes: #U4-1360 - full names of tree types in config. Updates: #U4-1303 - basic UI support for partial view macros. --- src/Umbraco.Core/TypeExtensions.cs | 19 ++ .../config/trees.Release.config | 57 ++--- src/Umbraco.Web.UI/config/trees.config | 58 ++--- .../umbraco/settings/views/EditView.aspx | 3 + .../umbraco/settings/views/EditView.aspx.cs | 209 +++++++++++------- .../settings/views/EditView.aspx.designer.cs | 90 ++++++++ .../umbraco_client/Editors/EditView.js | 31 ++- src/Umbraco.Web/Trees/PartialViewsTree.cs | 89 ++++++-- src/Umbraco.Web/Umbraco.Web.csproj | 7 +- .../WebServices/FolderBrowserService.cs | 2 + .../umbraco/Trees/TreeDefinitionCollection.cs | 17 +- .../webservices/codeEditorSave.asmx.cs | 48 +++- src/umbraco.businesslogic/ApplicationTree.cs | 2 +- .../ApplicationTreeRegistrar.cs | 16 +- .../Utils/TypeResolver.cs | 1 + 15 files changed, 466 insertions(+), 183 deletions(-) diff --git a/src/Umbraco.Core/TypeExtensions.cs b/src/Umbraco.Core/TypeExtensions.cs index 33d59ccb62..4cab37051e 100644 --- a/src/Umbraco.Core/TypeExtensions.cs +++ b/src/Umbraco.Core/TypeExtensions.cs @@ -296,5 +296,24 @@ namespace Umbraco.Core var attrs = propertyInfo.GetCustomAttributes(typeof(TAttribute), inherit); return (attrs.Length > 0 ? attrs.ToList().ConvertAll(input => (TAttribute)input) : null); } + + /// + /// Returns the full type name with the assembly but without all of the assembly specific version information. + /// + /// + /// + /// + /// This method is like an 'inbetween' of Type.FullName and Type.AssemblyQualifiedName which returns the type and the assembly separated + /// by a comma. + /// + /// + /// The output of this class would be: + /// + /// Umbraco.Core.TypeExtensions, Umbraco.Core + /// + public static string GetFullNameWithAssembly(this Type type) + { + return string.Concat(type.FullName, ", ", type.Assembly.GetName().Name); + } } } \ No newline at end of file diff --git a/src/Umbraco.Web.UI/config/trees.Release.config b/src/Umbraco.Web.UI/config/trees.Release.config index 861161d69f..43e7713ea0 100644 --- a/src/Umbraco.Web.UI/config/trees.Release.config +++ b/src/Umbraco.Web.UI/config/trees.Release.config @@ -2,48 +2,49 @@ - - + + - - + + - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - - - + + + - - - + + + - - + + - \ No newline at end of file diff --git a/src/Umbraco.Web.UI/config/trees.config b/src/Umbraco.Web.UI/config/trees.config index e73f851257..e72a6179db 100644 --- a/src/Umbraco.Web.UI/config/trees.config +++ b/src/Umbraco.Web.UI/config/trees.config @@ -1,39 +1,41 @@  - - + + - - + + - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - - - + + + - - - + + + + + + - - - \ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx index a0dcdea02f..91b892738a 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx +++ b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx @@ -14,6 +14,8 @@ $(document).ready(function () { //create a new EditView object var editView = new Umbraco.Editors.EditView({ + editorType: "<%= EditorType.ToString() %>", + originalFileName: "<%=OriginalFileName %>", masterPageDropDown: $("#<%= MasterTemplate.ClientID %>"), nameTxtBox: $("#<%= NameTxt.ClientID %>"), aliasTxtBox: $("#<%= AliasTxt.ClientID %>"), @@ -40,6 +42,7 @@ + diff --git a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs index 261bfdd5f7..8da653aa01 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs +++ b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.cs @@ -1,14 +1,18 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Core.IO; +using Umbraco.Web.Trees; using umbraco; using umbraco.BasePages; -using umbraco.IO; using umbraco.cms.businesslogic.template; +using umbraco.cms.helpers; using umbraco.cms.presentation.Trees; +using Umbraco.Core; using umbraco.uicontrols; namespace Umbraco.Web.UI.Umbraco.Settings.Views @@ -16,78 +20,119 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views public partial class EditView : global::umbraco.BasePages.UmbracoEnsuredPage { private Template _template; - - protected global::ClientDependency.Core.Controls.CssInclude CssInclude1; - protected global::ClientDependency.Core.Controls.JsInclude JsInclude; - - protected global::umbraco.uicontrols.UmbracoPanel Panel1; - protected global::umbraco.uicontrols.Pane Pane7; - protected global::umbraco.uicontrols.PropertyPanel pp_name; - protected global::System.Web.UI.WebControls.TextBox NameTxt; - protected global::umbraco.uicontrols.PropertyPanel pp_alias; - protected global::System.Web.UI.WebControls.TextBox AliasTxt; - protected global::umbraco.uicontrols.PropertyPanel pp_masterTemplate; - protected global::System.Web.UI.WebControls.DropDownList MasterTemplate; - protected global::umbraco.uicontrols.PropertyPanel pp_source; - protected global::umbraco.uicontrols.CodeArea editorSource; - protected global::System.Web.UI.WebControls.Repeater rpt_codeTemplates; - protected global::System.Web.UI.WebControls.Repeater rpt_macros; - protected MenuIconI SaveButton; - + protected MenuIconI SaveButton; public EditView() { CurrentApp = global::umbraco.BusinessLogic.DefaultApps.settings.ToString(); } + /// + /// The type of MVC/Umbraco view the editor is editing + /// + public enum ViewEditorType + { + Template, + PartialView + } + + /// + /// Returns the type of view being edited + /// + protected ViewEditorType EditorType + { + get { return _template == null ? ViewEditorType.PartialView : ViewEditorType.Template; } + } + + /// + /// Returns the original file name that the editor was loaded with + /// + /// + /// this is used for editing a partial view + /// + protected string OriginalFileName { get; private set; } + protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { - MasterTemplate.Items.Add(new ListItem(ui.Text("none"), "0")); - var selectedTemplate = string.Empty; - foreach (Template t in Template.GetAllAsList()) + //configure screen for editing a template + if (_template != null) { - if (t.Id == _template.Id) continue; + MasterTemplate.Items.Add(new ListItem(ui.Text("none"), "0")); + var selectedTemplate = string.Empty; - var li = new ListItem(t.Text, t.Id.ToString()); - li.Attributes.Add("id", t.Alias.Replace(" ", "") + ".cshtml"); - MasterTemplate.Items.Add(li); - } + foreach (Template t in Template.GetAllAsList()) + { + if (t.Id == _template.Id) continue; - try - { - if (_template.MasterTemplate > 0) - MasterTemplate.SelectedValue = _template.MasterTemplate.ToString(); - } - catch (Exception ex) - { - } + var li = new ListItem(t.Text, t.Id.ToString()); + li.Attributes.Add("id", t.Alias.Replace(" ", "") + ".cshtml"); + MasterTemplate.Items.Add(li); + } - MasterTemplate.SelectedValue = selectedTemplate; + try + { + if (_template.MasterTemplate > 0) + MasterTemplate.SelectedValue = _template.MasterTemplate.ToString(); + } + catch (Exception ex) + { + } - NameTxt.Text = _template.GetRawText(); - AliasTxt.Text = _template.Alias; - editorSource.Text = _template.Design; + MasterTemplate.SelectedValue = selectedTemplate; + NameTxt.Text = _template.GetRawText(); + AliasTxt.Text = _template.Alias; + editorSource.Text = _template.Design; - ClientTools - .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) + ClientTools + .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) .SyncTree("-1,init," + _template.Path.Replace("-1,", ""), false); + } + else + { + //configure editor for editing a file.... + + NameTxt.Text = OriginalFileName; + var file = IOHelper.MapPath(SystemDirectories.MvcViews + "/Partials/" + OriginalFileName); + + using (var sr = File.OpenText(file)) + { + var s = sr.ReadToEnd(); + editorSource.Text = s; + } + + //string path = DeepLink.GetTreePathFromFilePath(file); + //ClientTools + // .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) + // .SyncTree(path, false); + } } } protected override void OnInit(EventArgs e) { - _template = new Template(int.Parse(Request.QueryString["templateID"])); - // - // CODEGEN: This call is required by the ASP.NET Web Form Designer. - // - InitializeComponent(); base.OnInit(e); + + //check if a templateId is assigned, meaning we are editing a template + if (!Request.QueryString["templateID"].IsNullOrWhiteSpace()) + { + _template = new Template(int.Parse(Request.QueryString["templateID"])); + } + else if (!Request.QueryString["file"].IsNullOrWhiteSpace()) + { + //we are editing a view (i.e. partial view) + OriginalFileName = Request.QueryString["file"]; + } + else + { + throw new InvalidOperationException("Cannot render the editor without a supplied templateId or a file"); + } + Panel1.hasMenu = true; SaveButton = Panel1.Menu.NewIcon(); @@ -129,6 +174,44 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views Panel1.Menu.NewElement("div", "splitButtonMacroPlaceHolder", "sbPlaceHolder", 40); + + if (_template == null) + { + InitializeEditorForPartialView(); + } + else + { + InitializeEditorForTemplate(); + } + + + //Spit button + Panel1.Menu.InsertSplitter(); + Panel1.Menu.NewElement("div", "splitButtonPlaceHolder", "sbPlaceHolder", 40); + } + + protected override void OnPreRender(EventArgs e) + { + base.OnPreRender(e); + ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/codeEditorSave.asmx")); + ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/legacyAjaxCalls.asmx")); + } + + /// + /// Configure the editor for partial view editing + /// + private void InitializeEditorForPartialView() + { + pp_masterTemplate.Visible = false; + pp_alias.Visible = false; + pp_name.Text = "Filename"; + } + + /// + /// Configure the editor for editing a template + /// + private void InitializeEditorForTemplate() + { if (UmbracoSettings.UseAspNetMasterPages) { Panel1.Menu.InsertSplitter(); @@ -150,40 +233,6 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/dialogs/insertMasterpageContent.aspx?id=" + _template.Id, ui.Text("template", "insertContentArea"), 470, 300); } - - - //Spit button - Panel1.Menu.InsertSplitter(); - Panel1.Menu.NewElement("div", "splitButtonPlaceHolder", "sbPlaceHolder", 40); - - // Help - Panel1.Menu.InsertSplitter(); - - MenuIconI helpIcon = Panel1.Menu.NewIcon(); - helpIcon.OnClickCommand = - ClientTools.Scripts.OpenModalWindow( - IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/settings/modals/showumbracotags.aspx?alias=" + - _template.Alias, ui.Text("template", "quickGuide"), 600, 580); - helpIcon.ImageURL = UmbracoPath + "/images/editor/help.png"; - helpIcon.AltText = ui.Text("template", "quickGuide"); - } - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - - } - - - - protected override void OnPreRender(EventArgs e) - { - base.OnPreRender(e); - ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/codeEditorSave.asmx")); - ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/legacyAjaxCalls.asmx")); } } diff --git a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.designer.cs b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.designer.cs index 3764274310..3ed3a392b9 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.designer.cs +++ b/src/Umbraco.Web.UI/umbraco/settings/views/EditView.aspx.designer.cs @@ -20,5 +20,95 @@ namespace Umbraco.Web.UI.Umbraco.Settings.Views { /// To modify move field declaration from designer file to code-behind file. /// protected global::ClientDependency.Core.Controls.JsInclude JsInclude1; + + /// + /// Panel1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.UmbracoPanel Panel1; + + /// + /// Pane7 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.Pane Pane7; + + /// + /// pp_name control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.PropertyPanel pp_name; + + /// + /// NameTxt control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox NameTxt; + + /// + /// pp_alias control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.PropertyPanel pp_alias; + + /// + /// AliasTxt control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox AliasTxt; + + /// + /// pp_masterTemplate control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.PropertyPanel pp_masterTemplate; + + /// + /// MasterTemplate control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.DropDownList MasterTemplate; + + /// + /// pp_source control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.PropertyPanel pp_source; + + /// + /// editorSource control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.CodeArea editorSource; } } diff --git a/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js b/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js index db723874e6..a76d59d948 100644 --- a/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js +++ b/src/Umbraco.Web.UI/umbraco_client/Editors/EditView.js @@ -30,17 +30,32 @@ }, doSubmit: function () { + /// Submits the data to the server for saving var codeVal = UmbClientMgr.contentFrame().UmbEditor.GetCode(); var self = this; - umbraco.presentation.webservices.codeEditorSave.SaveTemplate( - this._opts.nameTxtBox.val(), - this._opts.aliasTxtBox.val(), - codeVal, - this._opts.templateId, - this._opts.masterPageDropDown.val(), - function (t) { self.submitSuccess(t); }, - function (t) { self.submitFailure(t); }); + if (this._opts.editorType == "Template") { + //saving a template view + + umbraco.presentation.webservices.codeEditorSave.SaveTemplate( + this._opts.nameTxtBox.val(), + this._opts.aliasTxtBox.val(), + codeVal, + this._opts.templateId, + this._opts.masterPageDropDown.val(), + function(t) { self.submitSuccess(t); }, + function(t) { self.submitFailure(t); }); + } + else { + //saving a partial view + + umbraco.presentation.webservices.codeEditorSave.SavePartialView( + this._opts.nameTxtBox.val(), + this._opts.originalFileName, + codeVal, + function (t) { self.submitSuccess(t); }, + function (t) { self.submitFailure(t); }); + } }, submitSuccess: function (t) { diff --git a/src/Umbraco.Web/Trees/PartialViewsTree.cs b/src/Umbraco.Web/Trees/PartialViewsTree.cs index 748eda041b..7ebf050aec 100644 --- a/src/Umbraco.Web/Trees/PartialViewsTree.cs +++ b/src/Umbraco.Web/Trees/PartialViewsTree.cs @@ -1,20 +1,62 @@ -//using System; -//using System.Collections.Generic; -//using System.IO; -//using System.Linq; -//using System.Text; -//using Umbraco.Core.Configuration; -//using Umbraco.Core.IO; -//using umbraco.BusinessLogic.Actions; -//using umbraco.businesslogic; -//using umbraco.cms.presentation.Trees; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.IO; +using umbraco.BusinessLogic.Actions; +using umbraco.businesslogic; +using umbraco.cms.businesslogic.template; +using umbraco.cms.presentation.Trees; +using umbraco.interfaces; -//namespace Umbraco.Web.Trees -//{ -// [Tree("settings", "partialViews", "Partial Views", sortOrder: 2)] -// public class PartialViewsTree : BaseTree -// { -// public PartialViewsTree(string application) : base(application) { } +namespace Umbraco.Web.Trees +{ + [Tree("settings", "partialViews", "Partial Views", sortOrder: 2)] + public class PartialViewsTree : FileSystemTree + { + public PartialViewsTree(string application) : base(application) { } + + public override void RenderJS(ref StringBuilder javascript) + { + javascript.Append( + @" + function openPartialView(id) { + UmbClientMgr.contentFrame('Settings/Views/EditView.aspx?file=' + id); + } + "); + } + + protected override void CreateRootNode(ref XmlTreeNode rootNode) + { + rootNode.NodeType = "init" + TreeAlias; + rootNode.NodeID = "init"; + } + + protected override string FilePath + { + get { return SystemDirectories.MvcViews + "/Partials/"; } + } + + protected override string FileSearchPattern + { + get { return "*.*"; } + } + + //protected override void OnRenderFolderNode(ref XmlTreeNode xNode) + //{ + // xNode.Menu = new List(new IAction[] { ActionDelete.Instance, ContextMenuSeperator.Instance, ActionNew.Instance, ContextMenuSeperator.Instance, ActionRefresh.Instance }); + // xNode.NodeType = "scriptsFolder"; + //} + + protected override void OnRenderFileNode(ref XmlTreeNode xNode) + { + xNode.Action = xNode.Action.Replace("openFile", "openPartialView"); + xNode.Icon = "settingsScript.gif"; + xNode.OpenIcon = "settingsScript.gif"; + } // protected override void CreateRootNode(ref XmlTreeNode rootNode) // { @@ -22,6 +64,7 @@ // rootNode.NodeID = "init"; // } +// private string _partialViewsFolder = SystemDirectories.MvcViews + "/Partials/"; // public override void RenderJS(ref StringBuilder Javascript) // { @@ -38,22 +81,19 @@ // public override void Render(ref XmlTree tree) // { // string folder = global::umbraco.library.Request("folder"); -// string folderPath = umbraco.library.Request("folderPath"); +// string folderPath = global::umbraco.library.Request("folderPath"); // if (!string.IsNullOrEmpty(folder)) // RenderTemplateFolderItems(folder, folderPath, ref tree); // else // { -// if (UmbracoSettings.EnableTemplateFolders) -// RenderTemplateFolders(ref tree); - // RenderTemplates(ref tree); // } // } // private void RenderTemplateFolderItems(string folder, string folderPath, ref XmlTree tree) // { -// string relPath = SystemDirectories.Masterpages + "/" + folder; +// string relPath = _partialViewsFolder + folder; // if (!string.IsNullOrEmpty(folderPath)) // relPath += folderPath; @@ -127,7 +167,7 @@ // { // if (base.m_id == -1) // { -// foreach (string s in Directory.GetDirectories(IO.IOHelper.MapPath(IO.SystemDirectories.Masterpages))) +// foreach (string s in Directory.GetDirectories(IOHelper.MapPath(_partialViewsFolder))) // { // var _s = Path.GetFileNameWithoutExtension(s); @@ -205,5 +245,6 @@ // actions.AddRange(new IAction[] { ActionNew.Instance, ActionDelete.Instance, // ContextMenuSeperator.Instance, ActionRefresh.Instance }); // } -// } -//} + + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index dfc4d8334a..bf6d842b2d 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -328,9 +328,10 @@ - + + ASPXCodeBehind @@ -2184,9 +2185,7 @@ umbraco_org_umbraco_update_CheckForUpgrade - - - + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/src/Umbraco.Web/WebServices/FolderBrowserService.cs b/src/Umbraco.Web/WebServices/FolderBrowserService.cs index 02132356f0..205ddce19c 100644 --- a/src/Umbraco.Web/WebServices/FolderBrowserService.cs +++ b/src/Umbraco.Web/WebServices/FolderBrowserService.cs @@ -15,6 +15,8 @@ using Umbraco.Web.BaseRest; namespace Umbraco.Web.WebServices { + //TODO: Can we convert this to MVC please instead of /base? + [RestExtension("FolderBrowserService")] public class FolderBrowserService { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs index 5d816ce07f..062145bbf7 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs @@ -166,8 +166,23 @@ namespace umbraco.cms.presentation.Trees //find the Application tree's who's combination of assembly name and tree type is equal to //the Type that was found's full name. //Since a tree can exist in multiple applications we'll need to register them all. + + //The logic of this has changed in 6.0: http://issues.umbraco.org/issue/U4-1360 + // we will support the old legacy way but the normal way is to match on assembly qualified names + var appTreesForType = appTrees.FindAll( - tree => (string.Format("{0}.{1}", tree.AssemblyName, tree.Type) == type.FullName) + tree => + { + //match the type on assembly qualified name if the assembly attribute is empty or if the + // tree type contains a comma (meaning it is assembly qualified) + if (tree.AssemblyName.IsNullOrWhiteSpace() || tree.Type.Contains(",")) + { + return tree.Type == type.GetFullNameWithAssembly(); + } + + //otherwise match using legacy match rules + return (string.Format("{0}.{1}", tree.AssemblyName, tree.Type).InvariantEquals(type.FullName)); + } ); foreach (var appTree in appTreesForType) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs index 722abb3d18..1802307a20 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs @@ -11,13 +11,13 @@ using System.Web.Services; using System.Web.UI; using System.Xml; using System.Xml.Xsl; +using Umbraco.Core.IO; using umbraco.BasePages; using umbraco.cms.businesslogic.macro; using umbraco.cms.businesslogic.template; using umbraco.cms.businesslogic.web; using umbraco.presentation.cache; using System.Net; -using umbraco.IO; using System.Collections; using umbraco.NodeFactory; using umbraco.scripting; @@ -34,8 +34,7 @@ namespace umbraco.presentation.webservices public class codeEditorSave : WebService { [WebMethod] - public string Save(string fileName, string fileAlias, string fileContents, string fileType, int fileID, - int masterID, bool ignoreDebug) + public string Save(string fileName, string fileAlias, string fileContents, string fileType, int fileID, int masterID, bool ignoreDebug) { return "Not implemented"; } @@ -339,6 +338,49 @@ namespace umbraco.presentation.webservices return "false"; } + [WebMethod] + public string SavePartialView(string filename, string oldName, string contents) + { + if (BasePage.ValidateUserContextID(BasePage.umbracoUserContextID)) + { + var folderPath = SystemDirectories.MvcViews + "/Partials/"; + + // validate file + IOHelper.ValidateEditPath(IOHelper.MapPath(folderPath + filename), folderPath); + // validate extension + IOHelper.ValidateFileExtension(IOHelper.MapPath(folderPath + filename), new[] {"cshtml"}.ToList()); + + + var val = contents; + string returnValue; + var saveOldPath = oldName.StartsWith("~/") ? IOHelper.MapPath(oldName) : IOHelper.MapPath(folderPath + oldName); + var savePath = filename.StartsWith("~/") ? IOHelper.MapPath(filename) : IOHelper.MapPath(folderPath + filename); + + //Directory check.. only allow files in script dir and below to be edited + if (savePath.StartsWith(IOHelper.MapPath(folderPath))) + { + //deletes the old file + if (savePath != saveOldPath) + { + if (File.Exists(saveOldPath)) + File.Delete(saveOldPath); + } + using (var sw = File.CreateText(savePath)) + { + sw.Write(val); + } + returnValue = "true"; + } + else + { + returnValue = "illegalPath"; + } + + return returnValue; + } + return "false"; + } + [WebMethod] public string SaveScript(string filename, string oldName, string contents) { diff --git a/src/umbraco.businesslogic/ApplicationTree.cs b/src/umbraco.businesslogic/ApplicationTree.cs index 65dbb34d21..fdebf70488 100644 --- a/src/umbraco.businesslogic/ApplicationTree.cs +++ b/src/umbraco.businesslogic/ApplicationTree.cs @@ -404,7 +404,7 @@ namespace umbraco.BusinessLogic addElement.Attribute("title").Value, addElement.Attribute("iconClosed").Value, addElement.Attribute("iconOpen").Value, - addElement.Attribute("assembly").Value, + (string)addElement.Attribute("assembly"), //this could be empty: http://issues.umbraco.org/issue/U4-1360 addElement.Attribute("type").Value, addElement.Attribute("action") != null ? addElement.Attribute("action").Value : "")); } diff --git a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs index 16e98ba493..67c07ff025 100644 --- a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs @@ -34,10 +34,8 @@ namespace umbraco.BusinessLogic { var type = tuple.Item1; var attr = tuple.Item2; - - var typeParts = type.AssemblyQualifiedName.Split(','); - var assemblyName = typeParts[1].Trim(); - var typeName = typeParts[0].Substring(assemblyName.Length + 1).Trim(); + + //Add the new tree that doesn't exist in the config that was found by type finding doc.Root.Add(new XElement("add", new XAttribute("silent", attr.Silent), @@ -48,11 +46,17 @@ namespace umbraco.BusinessLogic new XAttribute("title", attr.Title), new XAttribute("iconClosed", attr.IconClosed), new XAttribute("iconOpen", attr.IconOpen), - new XAttribute("assembly", assemblyName), - new XAttribute("type", typeName), + // don't add the assembly, we don't need this: + // http://issues.umbraco.org/issue/U4-1360 + //new XAttribute("assembly", assemblyName), + //new XAttribute("type", typeName), + // instead, store the assembly type name + new XAttribute("type", type.GetFullNameWithAssembly()), new XAttribute("action", attr.Action))); } + //add any trees that were found in the database that don't exist in the config + var db = ApplicationContext.Current.DatabaseContext.Database; var exist = db.TableExist("umbracoAppTree"); if (exist) diff --git a/src/umbraco.businesslogic/Utils/TypeResolver.cs b/src/umbraco.businesslogic/Utils/TypeResolver.cs index 1d13c1c765..040a7ef96e 100644 --- a/src/umbraco.businesslogic/Utils/TypeResolver.cs +++ b/src/umbraco.businesslogic/Utils/TypeResolver.cs @@ -15,6 +15,7 @@ namespace umbraco.BusinessLogic.Utils /// The typeresolver is a collection of utillities for finding and determining types and classes with reflection. /// [Serializable] + [Obsolete("This class is not longer used and will be removed in future versions")] public class TypeResolver : MarshalByRefObject { ///