From 691f3f30eb007890499fce1d91205a1b2764021d Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 16 Sep 2010 15:41:25 -0700 Subject: [PATCH] Converting Orchard.Themes --HG-- branch : dev --- .../Controllers/AdminController.cs | 10 ++- .../Orchard.Themes/Orchard.Themes.csproj | 6 +- .../Orchard.Themes/Preview/PreviewTheme.cs | 27 +++---- .../Preview/PreviewThemeFilter.cs | 21 +++--- .../Preview/PreviewThemeSelector.cs | 19 +++++ .../ViewModels/PreviewViewModel.cs | 8 --- .../Orchard.Themes/Views/Admin/Index.aspx | 53 -------------- .../Orchard.Themes/Views/Admin/Index.cshtml | 57 +++++++++++++++ .../Orchard.Themes/Views/Admin/Install.aspx | 12 ---- .../Orchard.Themes/Views/Admin/Install.cshtml | 10 +++ .../Views/Admin/ThemePreview.ascx | 70 ------------------ .../Orchard.Themes/Views/ThemePreview.cshtml | 71 +++++++++++++++++++ src/Orchard/Mvc/Html/ThemeExtensions.cs | 6 +- 13 files changed, 189 insertions(+), 181 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeSelector.cs delete mode 100644 src/Orchard.Web/Modules/Orchard.Themes/ViewModels/PreviewViewModel.cs delete mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.aspx create mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml delete mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.aspx create mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.cshtml delete mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/ThemePreview.ascx create mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Views/ThemePreview.cshtml diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs index 1b49fb6d5..77febbd52 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs @@ -18,7 +18,7 @@ namespace Orchard.Themes.Controllers { public AdminController( IOrchardServices services, IThemeService themeService, - PreviewTheme previewTheme, + IPreviewTheme previewTheme, IAuthorizer authorizer, INotifier notifier, IShapeHelperFactory shapeHelperFactory) { @@ -37,11 +37,11 @@ namespace Orchard.Themes.Controllers { var themes = _themeService.GetInstalledThemes(); var currentTheme = _themeService.GetSiteTheme(); var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes }; - return View(Shape.Model(model)); + return View(model); } catch (Exception exception) { Services.Notifier.Error(T("Listing themes failed: " + exception.Message)); - return View(Shape.Model(new ThemesIndexViewModel())); + return View(new ThemesIndexViewModel()); } } @@ -102,6 +102,10 @@ namespace Orchard.Themes.Controllers { } } + public ActionResult Install() { + return View(); + } + [HttpPost] public ActionResult Install(FormCollection input) { try { diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj index 9164d4f29..cd5d1e8aa 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj +++ b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj @@ -78,20 +78,20 @@ + - - + - + diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewTheme.cs b/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewTheme.cs index c1e064dc8..cff59b2ae 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewTheme.cs +++ b/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewTheme.cs @@ -1,36 +1,29 @@ using System; using System.Web; -using System.Web.Routing; +using Orchard.Mvc; namespace Orchard.Themes.Preview { - public class PreviewTheme : IPreviewTheme, IThemeSelector { + public class PreviewTheme : IPreviewTheme { + private readonly IHttpContextAccessor _httpContextAccessor; private static readonly string PreviewThemeKey = typeof(PreviewTheme).FullName; - private readonly HttpContextBase _httpContext; - public PreviewTheme(HttpContextBase httpContext) { - _httpContext = httpContext; + public PreviewTheme(IHttpContextAccessor httpContextAccessor) { + _httpContextAccessor = httpContextAccessor; } public string GetPreviewTheme() { - return Convert.ToString(_httpContext.Session[PreviewThemeKey]); + var httpContext = _httpContextAccessor.Current(); + return Convert.ToString(httpContext.Session[PreviewThemeKey]); } public void SetPreviewTheme(string themeName) { + var httpContext = _httpContextAccessor.Current(); if (string.IsNullOrEmpty(themeName)) { - _httpContext.Session.Remove(PreviewThemeKey); + httpContext.Session.Remove(PreviewThemeKey); } else { - _httpContext.Session[PreviewThemeKey] = themeName; + httpContext.Session[PreviewThemeKey] = themeName; } } - - public ThemeSelectorResult GetTheme(RequestContext context) { - var previewThemeName = GetPreviewTheme(); - if (string.IsNullOrEmpty(previewThemeName)) - return null; - - return new ThemeSelectorResult { Priority = 90, ThemeName = previewThemeName }; - } - } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeFilter.cs b/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeFilter.cs index c718b1da5..51df15320 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeFilter.cs @@ -23,19 +23,20 @@ namespace Orchard.Themes.Preview { if (string.IsNullOrEmpty(previewThemeName)) return; - var themes = _themeService.GetInstalledThemes(); - var model = new PreviewViewModel { - Themes = themes.Select(theme => new SelectListItem { - Text = theme.DisplayName, - Value = theme.ThemeName, - Selected = theme.ThemeName == previewThemeName - }) - }; + var installedThemes = _themeService.GetInstalledThemes(); + var themeListItems = installedThemes + .Select(theme => new SelectListItem { + Text = theme.DisplayName, + Value = theme.ThemeName, + Selected = theme.ThemeName == previewThemeName + }) + .ToList(); + var shape = _shapeHelperFactory.CreateHelper(); - _workContextAccessor.GetContext(filterContext).Page.Zones["Body"].Add(shape.ThemePreview(model), ":before"); + _workContextAccessor.GetContext(filterContext).Page.Zones["Body"].Add(shape.ThemePreview(Themes: themeListItems), ":before"); } - public void OnResultExecuted(ResultExecutedContext filterContext) {} + public void OnResultExecuted(ResultExecutedContext filterContext) { } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeSelector.cs b/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeSelector.cs new file mode 100644 index 000000000..0a81bcb8d --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeSelector.cs @@ -0,0 +1,19 @@ +using System.Web.Routing; + +namespace Orchard.Themes.Preview { + public class PreviewThemeSelector : IThemeSelector { + private readonly IPreviewTheme _previewTheme; + + public PreviewThemeSelector(IPreviewTheme previewTheme) { + _previewTheme = previewTheme; + } + + public ThemeSelectorResult GetTheme(RequestContext context) { + var previewThemeName = _previewTheme.GetPreviewTheme(); + if (string.IsNullOrEmpty(previewThemeName)) + return null; + + return new ThemeSelectorResult { Priority = 90, ThemeName = previewThemeName }; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/ViewModels/PreviewViewModel.cs b/src/Orchard.Web/Modules/Orchard.Themes/ViewModels/PreviewViewModel.cs deleted file mode 100644 index 10aa15ac8..000000000 --- a/src/Orchard.Web/Modules/Orchard.Themes/ViewModels/PreviewViewModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; -using System.Web.Mvc; - -namespace Orchard.Themes.ViewModels { - public class PreviewViewModel { - public IEnumerable Themes { get; set; } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.aspx b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.aspx deleted file mode 100644 index d380f6256..000000000 --- a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.aspx +++ /dev/null @@ -1,53 +0,0 @@ -<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage" %> -<%@ Import Namespace="Orchard.Mvc.Html"%> -<%@ Import Namespace="Orchard.Themes.ViewModels"%><% - Html.RegisterStyle("admin.css"); %> -

<%: Html.TitleForPage(T("Manage Themes").ToString()) %>

-<% if (Model.CurrentTheme == null) { - %>

<%: T("There is no current theme in the application. The built-in theme will be used.") - %>
<%: Html.ActionLink(T("Install a new Theme").ToString(), "Install") %>

<% - } else { - %>

<%: T("Current Theme")%> - <%: Model.CurrentTheme.DisplayName %>

- - <%: Html.Image(Html.ThemePath(Model.CurrentTheme, "/Theme.png"), Html.Encode(Model.CurrentTheme.DisplayName), new { @class = "themePreviewImage" })%> -
<%: T("By") %> <%: Model.CurrentTheme.Author %>
- -

- <%: T("Version:") %> <%: Model.CurrentTheme.Version %>
- <%: Model.CurrentTheme.Description %>
- <%: Model.CurrentTheme.HomePage %> -

- <%: Html.ActionLink(T("Install a new Theme").ToString(), "Install", null, new { @class = "button primaryAction" })%> - -<% } %> -

<%: T("Available Themes")%>

-
    -<% foreach (var theme in Model.Themes) { - if (Model.CurrentTheme == null || theme.ThemeName != Model.CurrentTheme.ThemeName) { - %>
  • -
    -

    <%: theme.DisplayName %>

    - <%: Html.Image(Html.ThemePath(theme, "/Theme.png"), Html.Encode(theme.DisplayName), null)%> - <% using (Html.BeginFormAntiForgeryPost(Url.Action("Activate"), FormMethod.Post, new { @class = "inline" })) { %> - <%: Html.Hidden("themeName", theme.ThemeName)%> - - <% } %> - <% using (Html.BeginFormAntiForgeryPost(Url.Action("Preview"), FormMethod.Post, new { @class = "inline" })) { %> - <%: Html.Hidden("themeName", theme.ThemeName)%> - - <% } %> -
    <%: T("By") %> <%: theme.Author %>
    -

    - <%: T("Version:") %> <%: theme.Version %>
    - <%: theme.Description %>
    - <%: theme.HomePage %> -

    - <% using (Html.BeginFormAntiForgeryPost(Url.Action("Uninstall"), FormMethod.Post, new { @class = "inline link" })) { %> - <%: Html.Hidden("themeName", theme.ThemeName)%> - - <% } %> -
    -
  • - <% } -} %> -
\ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml new file mode 100644 index 000000000..e6a6bf769 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml @@ -0,0 +1,57 @@ +@model Orchard.Themes.ViewModels.ThemesIndexViewModel +@{ + Html.RegisterStyle("admin.css"); +} + +

@Html.TitleForPage(T("Manage Themes").ToString())

+@if (Model.CurrentTheme == null) { +

+ @T("There is no current theme in the application. The built-in theme will be used.")
+ @Html.ActionLink(T("Install a new Theme").ToString(), "Install") +

+} else { +

@T("Current Theme") - @Model.CurrentTheme.DisplayName

+ + @Html.Image(Href(Html.ThemePath(Model.CurrentTheme, "/Theme.png")), Html.Encode(Model.CurrentTheme.DisplayName), new { @class = "themePreviewImage" }) +
@T("By") @Model.CurrentTheme.Author
+ +

+ @T("Version:") @Model.CurrentTheme.Version
+ @Model.CurrentTheme.Description
+ @Model.CurrentTheme.HomePage +

+ + @Html.ActionLink(T("Install a new Theme").ToString(), "Install", null, new { @class = "button primaryAction" }) +} + +

@T("Available Themes")

+
    + @foreach (var theme in Model.Themes) { + if (Model.CurrentTheme == null || theme.ThemeName != Model.CurrentTheme.ThemeName) { +
  • +
    +

    @theme.DisplayName

    + @Html.Image(Href(Html.ThemePath(theme, "/Theme.png")), Html.Encode(theme.DisplayName), null) + @using (Html.BeginFormAntiForgeryPost(Url.Action("Activate"), FormMethod.Post, new { @class = "inline" })) { + @Html.Hidden("themeName", theme.ThemeName) + + } + @using (Html.BeginFormAntiForgeryPost(Url.Action("Preview"), FormMethod.Post, new { @class = "inline" })) { + @Html.Hidden("themeName", theme.ThemeName) + + } +
    @T("By") @theme.Author
    +

    + @T("Version:") @theme.Version
    + @theme.Description
    + @theme.HomePage +

    + @using (Html.BeginFormAntiForgeryPost(Url.Action("Uninstall"), FormMethod.Post, new { @class = "inline link" })) { + @Html.Hidden("themeName", theme.ThemeName) + + } +
    +
  • + } + } +
\ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.aspx b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.aspx deleted file mode 100644 index 7ac34398b..000000000 --- a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.aspx +++ /dev/null @@ -1,12 +0,0 @@ -<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage" %> -<%@ Import Namespace="Orchard.Mvc.Html"%> -

<%: Html.TitleForPage(T("Install Theme").ToString()) %>

-<% using (Html.BeginForm("Install", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" })) {%> - <%: Html.ValidationSummary() %> -
- - " size="64" />
- " /> - <%: Html.AntiForgeryTokenOrchard() %> -
-<% } %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.cshtml b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.cshtml new file mode 100644 index 000000000..c67534362 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.cshtml @@ -0,0 +1,10 @@ +

@Html.TitleForPage(T("Install Theme").ToString())

+@using (Html.BeginForm("Install", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" })) { + @Html.ValidationSummary() +
+ +
+ + @Html.AntiForgeryTokenOrchard() +
+} diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/ThemePreview.ascx b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/ThemePreview.ascx deleted file mode 100644 index dcbe48351..000000000 --- a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/ThemePreview.ascx +++ /dev/null @@ -1,70 +0,0 @@ -<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> -<%@ Import Namespace="Orchard.Mvc.Html"%> -<%@ Import Namespace="Orchard.Themes.ViewModels"%> - -
-<% using(Html.BeginFormAntiForgeryPost(Url.Action("Preview", new{Controller="Admin", Area="Orchard.Themes"}), FormMethod.Post, new { @class = "inline" })) { %> -
- <%: T("You are previewing: ")%> - <%: Html.Hidden("ReturnUrl", Context.Request.RawUrl)%> - <%: Html.DropDownList("ThemeName", Model.Themes, new {onChange = "this.form.submit();"})%> - - - -
-<% } %> -
- diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/ThemePreview.cshtml b/src/Orchard.Web/Modules/Orchard.Themes/Views/ThemePreview.cshtml new file mode 100644 index 000000000..e925a15a3 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Themes/Views/ThemePreview.cshtml @@ -0,0 +1,71 @@ +@{ + var themes = (IEnumerable)Model.Themes; +} + + +
+ @using(Html.BeginFormAntiForgeryPost(Url.Action("Preview", new{Controller="Admin", Area="Orchard.Themes"}), FormMethod.Post, new { @class = "inline" })) { +
+ @T("You are previewing: ") + @Html.DropDownList("ThemeName", themes, new {onChange = "this.form.submit();"}) + @Html.Hidden("ReturnUrl", Context.Request.RawUrl) + + + +
+ } +
+ diff --git a/src/Orchard/Mvc/Html/ThemeExtensions.cs b/src/Orchard/Mvc/Html/ThemeExtensions.cs index a48da2e9c..8ffe8d5f1 100644 --- a/src/Orchard/Mvc/Html/ThemeExtensions.cs +++ b/src/Orchard/Mvc/Html/ThemeExtensions.cs @@ -20,11 +20,7 @@ namespace Orchard.Mvc.Html { } public static string ThemePath(this HtmlHelper helper, ITheme theme, string path) { - Control parent = helper.ViewDataContainer as Control; - - Argument.ThrowIfNull(parent, "helper.ViewDataContainer"); - - return parent.ResolveUrl(helper.Resolve().GetThemeLocation(theme) + path); + return helper.Resolve().GetThemeLocation(theme) + path; } } }