Fixes up macros and file trees

This commit is contained in:
Shannon
2018-05-01 00:35:49 +10:00
parent 6db5ebf6f9
commit 0a5db8f97b
7 changed files with 78 additions and 166 deletions

View File

@@ -49,9 +49,9 @@ namespace Umbraco.Web.UI.Umbraco.Developer.Macros
/// <param name="macroCachePeriod"></param>
/// <param name="macroAssemblyValue"></param>
/// <param name="macroTypeValue"></param>
protected override void SetMacroValuesFromPostBack(IMacro macro, int macroCachePeriod, string macroAssemblyValue, string macroTypeValue)
protected override void SetMacroValuesFromPostBack(IMacro macro, int macroCachePeriod, string macroTypeValue)
{
base.SetMacroValuesFromPostBack(macro, macroCachePeriod, macroAssemblyValue, macroTypeValue);
base.SetMacroValuesFromPostBack(macro, macroCachePeriod, macroTypeValue);
if (!SelectedPartialView.Text.IsNullOrWhiteSpace())
{
macro.ScriptPath = SelectedPartialView.Text;

View File

@@ -57,6 +57,9 @@
</cc1:PropertyPanel>
<cc1:PropertyPanel runat="server" Text="Alias">
<asp:TextBox ID="macroAlias" runat="server" CssClass="guiInputText"></asp:TextBox>
</cc1:PropertyPanel>
<cc1:PropertyPanel runat="server" Text="Key">
<asp:Label ID="macroKey" runat="server" CssClass="guiLabel"></asp:Label>
</cc1:PropertyPanel>
</cc1:Pane>
@@ -149,7 +152,7 @@
<asp:TextBox runat="server" ID="macroPropertySortOrder" CLASS="-full-width-input" Text='<%#Eval("SortOrder")%>' />
</td>
<td>
<asp:Button OnClick="deleteMacroProperty" ID="delete" Text="Delete" runat="server" CssClass="btn btn-default delete-button" />
<asp:Button OnClick="DeleteMacroProperty" ID="delete" Text="Delete" runat="server" CssClass="btn btn-default delete-button" />
</td>
</tr>
</ItemTemplate>

View File

@@ -18,30 +18,28 @@ namespace Umbraco.Web.Trees
protected abstract IFileSystem FileSystem { get; }
protected abstract string[] Extensions { get; }
protected abstract string FileIcon { get; }
protected abstract bool EnableCreateOnFolder { get; }
/// <summary>
/// Inheritors can override this method to modify the file node that is created.
/// </summary>
protected virtual void OnRenderFileNode(ref TreeNode treeNode)
{ }
/// <param name="treeNode"></param>
protected virtual void OnRenderFileNode(ref TreeNode treeNode) { }
/// <summary>
/// Inheritors can override this method to modify the folder node that is created.
/// </summary>
protected virtual void OnRenderFolderNode(ref TreeNode treeNode)
{ }
/// <param name="treeNode"></param>
protected virtual void OnRenderFolderNode(ref TreeNode treeNode) { }
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection();
var path = string.IsNullOrEmpty(id) == false && id != Constants.System.Root.ToInvariantString()
? HttpUtility.UrlDecode(id).TrimStart("/")
: "";
var directories = FileSystem.GetDirectories(path);
var nodes = new TreeNodeCollection();
foreach (var directory in directories)
{
var hasChildren = FileSystem.GetFiles(directory).Any() || FileSystem.GetDirectories(directory).Any();
@@ -53,24 +51,22 @@ namespace Umbraco.Web.Trees
nodes.Add(node);
}
//this is a hack to enable file system tree to support multiple file extension look-up
//so the pattern both support *.* *.xml and xml,js,vb for lookups
var files = FileSystem.GetFiles(path).Where(x =>
{
var extension = Path.GetExtension(x);
return extension != null && Extensions.Contains(extension.Trim('.'), StringComparer.InvariantCultureIgnoreCase);
// fixme - should we filter out hidden files? but then, FileSystem does not support attributes!
});
foreach (var file in files)
{
var withoutExt = Path.GetFileNameWithoutExtension(file);
if (string.IsNullOrWhiteSpace(withoutExt)) continue;
if (withoutExt.IsNullOrWhiteSpace()) continue;
var name = Path.GetFileName(file);
var node = CreateTreeNode(HttpUtility.UrlEncode(file), path, queryStrings, name, FileIcon, false);
OnRenderFileNode(ref node);
if (node != null)
nodes.Add(node);
}
@@ -78,89 +74,77 @@ namespace Umbraco.Web.Trees
return nodes;
}
protected virtual TreeNodeCollection GetTreeNodesForFile(string path, string id, FormDataCollection queryStrings)
{
return new TreeNodeCollection();
}
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
protected virtual MenuItemCollection GetMenuForRootNode(FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
OnBeforeRenderMenu(menu, id, queryStrings);
// if root node no need to visit the filesystem so lets just create the menu and return it
if (id == Constants.System.Root.ToInvariantString())
{
GetMenuForRootNode(menu, queryStrings);
}
else
{
var path = string.IsNullOrEmpty(id) == false && id != Constants.System.Root.ToInvariantString()
? HttpUtility.UrlDecode(id).TrimStart("/")
: "";
var isFile = FileSystem.FileExists(path);
var isDirectory = FileSystem.DirectoryExists(path);
if (isDirectory)
GetMenuForFolder(menu, path, id, queryStrings);
else if (isFile)
GetMenuForFile(menu, path, id, queryStrings);
}
OnAfterRenderMenu(menu, id, queryStrings);
//set the default to create
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
//create action
menu.Items.Add<ActionNew>(Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias)));
//refresh action
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), true);
return menu;
}
protected virtual void GetMenuForRootNode(MenuItemCollection menu, FormDataCollection queryStrings)
protected virtual MenuItemCollection GetMenuForFolder(string path, FormDataCollection queryStrings)
{
// default create
var menu = new MenuItemCollection();
//set the default to create
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
//create action
menu.Items.Add<ActionNew>(Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias)));
// create action
//Since we haven't implemented anything for file systems in angular, this needs to be converted to
//use the legacy format
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias))
.ConvertLegacyFileSystemMenuItem("", "init" + TreeAlias, queryStrings.GetValue<string>("application"));
var hasChildren = FileSystem.GetFiles(path).Any() || FileSystem.GetDirectories(path).Any();
// refresh action
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
}
protected virtual void GetMenuForFolder(MenuItemCollection menu, string path, string id, FormDataCollection queryStrings)
{
if (EnableCreateOnFolder)
//We can only delete folders if it doesn't have any children (folders or files)
if (hasChildren == false)
{
// default create
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
// create action
//Since we haven't implemented anything for file systems in angular, this needs to be converted to
//use the legacy format
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias))
.ConvertLegacyFileSystemMenuItem(id, TreeAlias + "Folder", queryStrings.GetValue<string>("application"));
//delete action
menu.Items.Add<ActionDelete>(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias)), true);
}
// delete action
menu.Items.Add<ActionDelete>(Services.TextService.Localize("actions", ActionDelete.Instance.Alias), true)
.ConvertLegacyFileSystemMenuItem(id, TreeAlias + "Folder", queryStrings.GetValue<string>("application"));
//refresh action
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), true);
// refresh action
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
return menu;
}
protected virtual void GetMenuForFile(MenuItemCollection menu, string path, string id, FormDataCollection queryStrings)
protected virtual MenuItemCollection GetMenuForFile(string path, FormDataCollection queryStrings)
{
// delete action
menu.Items.Add<ActionDelete>(Services.TextService.Localize("actions", ActionDelete.Instance.Alias), true)
.ConvertLegacyFileSystemMenuItem(id, TreeAlias, queryStrings.GetValue<string>("application"));
var menu = new MenuItemCollection();
//if it's not a directory then we only allow to delete the item
menu.Items.Add<ActionDelete>(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias)));
return menu;
}
protected virtual void OnBeforeRenderMenu(MenuItemCollection menu, string id, FormDataCollection queryStrings)
{ }
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
//if root node no need to visit the filesystem so lets just create the menu and return it
if (id == Constants.System.Root.ToInvariantString())
{
return GetMenuForRootNode(queryStrings);
}
protected virtual void OnAfterRenderMenu(MenuItemCollection menu, string id, FormDataCollection queryStrings)
{ }
var menu = new MenuItemCollection();
var path = string.IsNullOrEmpty(id) == false && id != Constants.System.Root.ToInvariantString()
? HttpUtility.UrlDecode(id).TrimStart("/")
: "";
var isFile = FileSystem.FileExists(path);
var isDirectory = FileSystem.DirectoryExists(path);
if (isDirectory)
{
return GetMenuForFolder(path, queryStrings);
}
return isFile ? GetMenuForFile(path, queryStrings) : menu;
}
}
}

View File

@@ -31,7 +31,5 @@ namespace Umbraco.Web.Trees
treeNode.AdditionalData["jsClickCallback"] = "javascript:void(0);";
treeNode.Icon = "icon-article";
}
protected override bool EnableCreateOnFolder => true;
}
}

View File

@@ -17,8 +17,6 @@ namespace Umbraco.Web.Trees
protected override string FileIcon => "icon-script";
protected override bool EnableCreateOnFolder => true;
protected override void OnRenderFolderNode(ref TreeNode treeNode)
{
//TODO: This isn't the best way to ensure a noop process for clicking a node but it works for now.

View File

@@ -14,7 +14,5 @@ namespace Umbraco.Web.Trees
protected override string[] Extensions => ExtensionsStatic;
protected override string FileIcon => "icon-brackets";
protected override bool EnableCreateOnFolder => false;
}
}

View File

@@ -52,10 +52,7 @@ namespace umbraco.cms.presentation.developer
PopulateFieldsOnLoad(_macro, tempMacroType);
// Load elements from macro
macroPropertyBind();
// Load xslt files from default dir
PopulateXsltFiles();
MacroPropertyBind();
// Load usercontrols
PopulateUserControls(IOHelper.MapPath(SystemDirectories.UserControls));
@@ -81,21 +78,13 @@ namespace umbraco.cms.presentation.developer
cacheByPage.Checked = macro.CacheByPage;
cachePersonalized.Checked = macro.CacheByMember;
// Populate either user control or custom control
if (macroTypeValue != string.Empty)
{
macroType.Text = macroTypeValue;
}
else
{
macroUserControl.Text = macroTypeValue;
}
macroUserControl.Text = macroTypeValue;
}
/// <summary>
/// Sets the values on the Macro object from the values posted back before saving the macro
/// </summary>
protected virtual void SetMacroValuesFromPostBack(IMacro macro, int macroCachePeriod, string macroAssemblyValue, string macroTypeValue)
protected virtual void SetMacroValuesFromPostBack(IMacro macro, int macroCachePeriod, string macroTypeValue)
{
macro.UseInEditor = macroEditor.Checked;
macro.DontRender = macroRenderContent.Checked == false;
@@ -106,37 +95,8 @@ namespace umbraco.cms.presentation.developer
macro.Name = macroName.Text;
macro.ControlType = macroTypeValue;
}
private static void GetXsltFilesFromDir(string orgPath, string path, ArrayList files)
{
var dirInfo = new DirectoryInfo(path);
if (dirInfo.Exists == false) return;
// Populate subdirectories
var dirInfos = dirInfo.GetDirectories();
foreach (var dir in dirInfos)
GetXsltFilesFromDir(orgPath, path + "/" + dir.Name, files);
var fileInfo = dirInfo.GetFiles("*.xsl*");
foreach (var file in fileInfo)
files.Add((path.Replace(orgPath, string.Empty).Trim('/') + "/" + file.Name).Trim('/'));
}
private void PopulateXsltFiles()
{
var xslts = new ArrayList();
var xsltDir = IOHelper.MapPath(SystemDirectories.Xslt + "/");
GetXsltFilesFromDir(xsltDir, xsltDir, xslts);
xsltFiles.DataSource = xslts;
xsltFiles.DataBind();
xsltFiles.Items.Insert(0, new ListItem("Browse xslt files on server...", string.Empty));
}
public void deleteMacroProperty(object sender, EventArgs e)
public void DeleteMacroProperty(object sender, EventArgs e)
{
var macroPropertyId = (HtmlInputHidden)((Control)sender).Parent.FindControl("macroPropertyID");
@@ -145,10 +105,10 @@ namespace umbraco.cms.presentation.developer
Services.MacroService.Save(_macro);
macroPropertyBind();
MacroPropertyBind();
}
public void macroPropertyBind()
public void MacroPropertyBind()
{
macroProperties.DataSource = _macro.Properties.OrderBy(x => x.SortOrder);
macroProperties.DataBind();
@@ -203,7 +163,7 @@ namespace umbraco.cms.presentation.developer
Services.MacroService.Save(_macro);
macroPropertyBind();
MacroPropertyBind();
}
}
@@ -274,15 +234,13 @@ namespace umbraco.cms.presentation.developer
ClientTools
.SyncTree("-1," + _macro.Id.ToInvariantString(), true); //true forces the reload
var tempMacroAssembly = macroAssembly.Text;
var tempMacroType = macroType.Text;
var tempCachePeriod = cachePeriod.Text;
if (tempCachePeriod == string.Empty)
tempCachePeriod = "0";
if (tempMacroAssembly == string.Empty && macroUserControl.Text != string.Empty)
tempMacroType = macroUserControl.Text;
var tempMacroType = macroUserControl.Text;
SetMacroValuesFromPostBack(_macro, Convert.ToInt32(tempCachePeriod), tempMacroAssembly, tempMacroType);
SetMacroValuesFromPostBack(_macro, Convert.ToInt32(tempCachePeriod), tempMacroType);
// save elements
// this is oh so completely broken
@@ -324,7 +282,7 @@ namespace umbraco.cms.presentation.developer
ClientTools.ShowSpeechBubble(SpeechBubbleIcon.Save, "Macro saved", "");
macroPropertyBind();
MacroPropertyBind();
}
/// <summary>
@@ -390,15 +348,6 @@ namespace umbraco.cms.presentation.developer
/// </remarks>
protected global::Umbraco.Web._Legacy.Controls.Pane Pane1_2;
/// <summary>
/// xsltFiles control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList xsltFiles;
/// <summary>
/// macroUserControl control.
/// </summary>
@@ -416,25 +365,7 @@ namespace umbraco.cms.presentation.developer
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList userControlList;
/// <summary>
/// macroAssembly control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox macroAssembly;
/// <summary>
/// macroType control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox macroType;
/// <summary>
/// Pane1_3 control.
/// </summary>