From 9c8c9d8a398a4d0fc0810bb9474bb3b709d76ed7 Mon Sep 17 00:00:00 2001 From: Claus Date: Tue, 27 Feb 2018 15:47:47 +0100 Subject: [PATCH] UAASSCRUM-1405 Clean up preview for Headless --- .../components/content/edit.controller.js | 8 +++--- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 12 +++++++++ src/Umbraco.Web/Editors/PreviewController.cs | 27 +++++++++++++++++++ src/Umbraco.Web/Features/DisabledFeatures.cs | 5 ++++ src/Umbraco.Web/Mvc/BackOfficeArea.cs | 14 +++++----- 5 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 src/Umbraco.Web/Editors/PreviewController.cs diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index 1ecb2d7403..8441963e87 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -242,10 +242,10 @@ // Chromes popup blocker will kick in if a window is opened // without the initial scoped request. This trick will fix that. // - var previewWindow = $window.open('preview/?init=true&id=' + content.id, 'umbpreview'); + var previewWindow = $window.open('previews/?init=true&id=' + content.id, 'umbpreview'); // Build the correct path so both /#/ and #/ work. - var redirect = Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/preview/?id=' + content.id; + var redirect = Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/previews/?id=' + content.id; //The user cannot save if they don't have access to do that, in which case we just want to preview //and that's it otherwise they'll get an unauthorized access message @@ -255,11 +255,9 @@ else { $scope.save().then(function (data) { previewWindow.location.href = redirect; - }); + }); } - } - }; $scope.restore = function (content) { diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 8ca1759cf1..7d370140b5 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -837,6 +837,18 @@ + + + + + + + + + + + + Web.Template.config diff --git a/src/Umbraco.Web/Editors/PreviewController.cs b/src/Umbraco.Web/Editors/PreviewController.cs new file mode 100644 index 0000000000..971b504d61 --- /dev/null +++ b/src/Umbraco.Web/Editors/PreviewController.cs @@ -0,0 +1,27 @@ +using System; +using System.Web.Mvc; +using Umbraco.Web.Features; +using Umbraco.Web.Mvc; + +namespace Umbraco.Web.Editors +{ + [UmbracoAuthorize] + [DisableBrowserCache] + public class PreviewController : Controller + { + private const string ViewsPath = "~/Umbraco/Views/Preview/"; + + public ActionResult Index() + { + ViewData["DisableDevicePreview"] = FeaturesResolver.Current.Features.Disabled.DevicePreview; + return View(ViewsPath + "Index.cshtml"); + } + + [AllowAnonymous] + public ActionResult Editors(string editor) + { + if (string.IsNullOrEmpty(editor)) throw new ArgumentNullException("editor"); + return View(ViewsPath + editor.Replace(".html", string.Empty) + ".cshtml"); + } + } +} diff --git a/src/Umbraco.Web/Features/DisabledFeatures.cs b/src/Umbraco.Web/Features/DisabledFeatures.cs index b9d8d0a2d9..c061faefce 100644 --- a/src/Umbraco.Web/Features/DisabledFeatures.cs +++ b/src/Umbraco.Web/Features/DisabledFeatures.cs @@ -20,5 +20,10 @@ namespace Umbraco.Web.Features /// Gets the disabled controllers. /// public TypeList Controllers { get; private set; } + + /// + /// Disables the device preview feature of previewing. + /// + public bool DevicePreview { get; set; } } } diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs index 68afc3fc39..b594b0272b 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -1,10 +1,6 @@ -using System.Web; -using System.Web.Mvc; -using System.Web.Routing; +using System.Web.Mvc; using Umbraco.Core.Configuration; using Umbraco.Web.Editors; -using Umbraco.Web.Install; -using Umbraco.Web.Install.Controllers; namespace Umbraco.Web.Mvc { @@ -24,6 +20,12 @@ namespace Umbraco.Web.Mvc /// public override void RegisterArea(AreaRegistrationContext context) { + context.MapRoute( + "Umbraco_preview", + GlobalSettings.UmbracoMvcArea + "/previews/{action}/{editor}", + new {controller = "Preview", action = "Index", editor = UrlParameter.Optional}, + new[] { "Umbraco.Web.Editors" }); + context.MapRoute( "Umbraco_back_office", GlobalSettings.UmbracoMvcArea + "/{action}/{id}", @@ -51,4 +53,4 @@ namespace Umbraco.Web.Mvc get { return GlobalSettings.UmbracoMvcArea; } } } -} \ No newline at end of file +}