2014-05-09 12:23:59 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2016-03-30 16:07:45 +02:00
|
|
|
|
using System.Net.Http.Formatting;
|
2014-05-09 12:23:59 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2016-03-30 16:07:45 +02:00
|
|
|
|
using ClientDependency.Core;
|
|
|
|
|
|
using Umbraco.Core;
|
2014-05-09 12:23:59 +02:00
|
|
|
|
using Umbraco.Core.IO;
|
2016-03-30 16:07:45 +02:00
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2014-05-09 12:23:59 +02:00
|
|
|
|
using Umbraco.Web.Models.Trees;
|
2016-03-30 16:07:45 +02:00
|
|
|
|
using Umbraco.Web._Legacy.Actions;
|
|
|
|
|
|
using Constants = Umbraco.Core.Constants;
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
|
{
|
|
|
|
|
|
public abstract class FileSystemTreeController : TreeController
|
|
|
|
|
|
{
|
|
|
|
|
|
protected abstract string FilePath { get; }
|
2016-03-30 16:07:45 +02:00
|
|
|
|
protected abstract IEnumerable<string> FileSearchPattern { get; }
|
|
|
|
|
|
protected abstract string EditFormUrl { get; }
|
|
|
|
|
|
protected abstract bool EnableCreateOnFolder { get; }
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Inheritors can override this method to modify the file node that is created.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="xNode"></param>
|
2016-03-30 16:07:45 +02:00
|
|
|
|
protected virtual void OnRenderFileNode(TreeNode treeNode, FileInfo file)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Inheritors can override this method to modify the folder node that is created.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="xNode"></param>
|
2016-03-30 16:07:45 +02:00
|
|
|
|
protected virtual void OnRenderFolderNode(TreeNode treeNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
|
2014-05-09 12:23:59 +02:00
|
|
|
|
{
|
2016-03-30 16:07:45 +02:00
|
|
|
|
var nodes = new TreeNodeCollection();
|
|
|
|
|
|
|
2014-05-09 12:23:59 +02:00
|
|
|
|
string orgPath = "";
|
|
|
|
|
|
string path = "";
|
2016-03-30 16:07:45 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(id) && id != Constants.System.Root.ToInvariantString())
|
2014-05-09 12:23:59 +02:00
|
|
|
|
{
|
|
|
|
|
|
orgPath = id;
|
|
|
|
|
|
path = IOHelper.MapPath(FilePath + "/" + orgPath);
|
|
|
|
|
|
orgPath += "/";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
path = IOHelper.MapPath(FilePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
if (!Directory.Exists(path) && !System.IO.File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
return nodes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (System.IO.File.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetTreeNodesForFile(path, id, queryStrings);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-05-09 12:23:59 +02:00
|
|
|
|
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
2016-03-30 16:07:45 +02:00
|
|
|
|
DirectoryInfo[] dirInfos = new DirectoryInfo(path).GetDirectories();
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
|
|
|
|
|
foreach (DirectoryInfo dir in dirInfos)
|
|
|
|
|
|
{
|
2016-03-30 16:07:45 +02:00
|
|
|
|
if ((dir.Attributes.HasFlag(FileAttributes.Hidden)) == false)
|
2014-05-09 12:23:59 +02:00
|
|
|
|
{
|
2016-03-30 16:07:45 +02:00
|
|
|
|
var hasChildren = dir.GetFiles().Length > 0 || dir.GetDirectories().Length > 0;
|
|
|
|
|
|
var node = CreateTreeNode(orgPath + dir.Name, orgPath, queryStrings, dir.Name, "icon-folder",
|
|
|
|
|
|
hasChildren);
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: This isn't the best way to ensure a noop process for clicking a node but it works for now.
|
|
|
|
|
|
node.AdditionalData["jsClickCallback"] = "javascript:void(0);";
|
|
|
|
|
|
OnRenderFolderNode(node);
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
nodes.Add(node);
|
2014-05-09 12:23:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
var files = FileSearchPattern
|
|
|
|
|
|
.SelectMany(p => dirInfo.GetFiles("*." + p))
|
|
|
|
|
|
.Where(f => !f.Attributes.HasFlag(FileAttributes.Hidden));
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
foreach (FileInfo file in files)
|
2014-05-09 12:23:59 +02:00
|
|
|
|
{
|
2016-03-30 16:07:45 +02:00
|
|
|
|
var nodeId = orgPath + file.Name;
|
|
|
|
|
|
|
|
|
|
|
|
var node = CreateTreeNode(
|
|
|
|
|
|
nodeId,
|
|
|
|
|
|
orgPath, queryStrings,
|
|
|
|
|
|
file.Name.StripFileExtension(),
|
|
|
|
|
|
"icon-file",
|
|
|
|
|
|
false,
|
|
|
|
|
|
"/" + queryStrings.GetValue<string>("application") + "/framed/" +
|
|
|
|
|
|
Uri.EscapeDataString(string.Format(EditFormUrl, nodeId)));
|
|
|
|
|
|
|
|
|
|
|
|
OnRenderFileNode(node, file);
|
|
|
|
|
|
|
|
|
|
|
|
nodes.Add(node);
|
2014-05-09 12:23:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
return nodes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual TreeNodeCollection GetTreeNodesForFile(string path, string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new TreeNodeCollection();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
|
|
|
|
|
OnBeforeRenderMenu(menu, id, queryStrings);
|
|
|
|
|
|
|
|
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
2014-05-09 12:23:59 +02:00
|
|
|
|
{
|
2016-03-30 16:07:45 +02:00
|
|
|
|
//Create the normal create action
|
|
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias))
|
|
|
|
|
|
//Since we haven't implemented anything for file systems in angular, this needs to be converted to
|
|
|
|
|
|
//use the legacy format
|
|
|
|
|
|
.ConvertLegacyFileSystemMenuItem("", "init" + TreeAlias, queryStrings.GetValue<string>("application"));
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
//refresh action
|
|
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(
|
|
|
|
|
|
Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
return menu;
|
2014-05-09 12:23:59 +02:00
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(IOHelper.MapPath(FilePath + "/" + id)))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (EnableCreateOnFolder)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Create the normal create action
|
|
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias))
|
|
|
|
|
|
//Since we haven't implemented anything for file systems in angular, this needs to be converted to
|
|
|
|
|
|
//use the legacy format
|
|
|
|
|
|
.ConvertLegacyFileSystemMenuItem(id, TreeAlias + "Folder",
|
|
|
|
|
|
queryStrings.GetValue<string>("application"));
|
2014-05-09 12:23:59 +02:00
|
|
|
|
}
|
2016-03-30 16:07:45 +02:00
|
|
|
|
|
|
|
|
|
|
//refresh action
|
|
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(
|
|
|
|
|
|
Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
|
|
|
|
|
|
|
2014-05-09 12:23:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-30 16:07:45 +02:00
|
|
|
|
//add delete option for all languages
|
|
|
|
|
|
menu.Items.Add<ActionDelete>(Services.TextService.Localize("actions", ActionDelete.Instance.Alias), true)
|
|
|
|
|
|
.ConvertLegacyFileSystemMenuItem(
|
|
|
|
|
|
id, TreeAlias, queryStrings.GetValue<string>("application"));
|
|
|
|
|
|
|
|
|
|
|
|
OnAfterRenderMenu(menu, id, queryStrings);
|
|
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnBeforeRenderMenu(MenuItemCollection menu, string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnAfterRenderMenu(MenuItemCollection menu, string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2014-05-09 12:23:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|