using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web.Http.Routing;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Services;
using Umbraco.Web.Actions;
using Umbraco.Web.Composing;
using Umbraco.Web.Models.Trees;
namespace Umbraco.Web.Trees
{
///
/// Converts the legacy tree data to the new format
///
internal class LegacyTreeDataConverter
{
//fixme: remove this whole class when everything is angularized
///
/// This will look at the legacy IAction's JsFunctionName and convert it to a confirmation dialog view if possible
///
///
///
internal static Attempt GetLegacyConfirmView(IAction action)
{
switch (action)
{
case ActionDelete actionDelete:
return Attempt.Succeed(
UmbracoConfig.For.GlobalSettings().Path.EnsureEndsWith('/') + "views/common/dialogs/legacydelete.html");
}
return Attempt.Fail();
}
///
/// This will look at a legacy IAction's JsFunctionName and convert it to a URL if possible.
///
///
///
///
///
///
internal static Attempt GetUrlAndTitleFromLegacyAction(IAction action, string nodeId, string nodeType, string nodeName, string currentSection)
{
switch (action)
{
case ActionNew actionNew:
return Attempt.Succeed(
new LegacyUrlAction(
"create.aspx?nodeId=" + nodeId + "&nodeType=" + nodeType + "&nodeName=" + nodeName + "&rnd=" + DateTime.UtcNow.Ticks,
Current.Services.TextService.Localize("actions/create")));
case ActionProtect actionProtect:
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/protectPage.aspx?mode=cut&nodeId=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
Current.Services.TextService.Localize("actions/protect")));
}
return Attempt.Fail();
}
internal class LegacyUrlAction
{
public LegacyUrlAction(string url, string dialogTitle)
: this(url, dialogTitle, ActionUrlMethod.Dialog)
{
}
public LegacyUrlAction(string url, string dialogTitle, ActionUrlMethod actionMethod)
{
Url = url;
ActionMethod = actionMethod;
DialogTitle = dialogTitle;
}
public string Url { get; private set; }
public ActionUrlMethod ActionMethod { get; private set; }
public string DialogTitle { get; private set; }
}
}
}