Updating installed themes page.

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2011-02-16 10:22:09 -08:00
parent ec478ec34b
commit 4bf1b2e389
9 changed files with 122 additions and 67 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.Mvc;
@@ -12,6 +13,7 @@ using Orchard.Logging;
using Orchard.Mvc.Extensions;
using Orchard.Reports.Services;
using Orchard.Security;
using Orchard.Themes.Models;
using Orchard.Themes.Preview;
using Orchard.Themes.Services;
using Orchard.Themes.ViewModels;
@@ -61,20 +63,30 @@ namespace Orchard.Themes.Controllers {
public ActionResult Index() {
try {
var currentTheme = _siteThemeService.GetSiteTheme();
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
var themes = _extensionManager.AvailableExtensions()
.Where(d => DefaultExtensionTypes.IsTheme(d.ExtensionType))
.Select(d => new ThemeEntry {
Descriptor = d,
NeedsUpdate = featuresThatNeedUpdate.Contains(d.Id),
Enabled = _shellDescriptor.Features.Any(sf => sf.Name == d.Id)
ThemeEntry currentTheme = new ThemeEntry(_siteThemeService.GetSiteTheme());
IEnumerable<ThemeEntry> themes = _extensionManager.AvailableExtensions()
.Where(extensionDescriptor => {
bool hidden = false;
string tags = extensionDescriptor.Tags;
if (tags != null) {
hidden = tags.Split(',').Any(t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase));
}
return !hidden &&
DefaultExtensionTypes.IsTheme(extensionDescriptor.ExtensionType) &&
!currentTheme.Descriptor.Id.Equals(extensionDescriptor.Id);
})
.Select(extensionDescriptor => new ThemeEntry(extensionDescriptor) {
NeedsUpdate = featuresThatNeedUpdate.Contains(extensionDescriptor.Id),
Enabled = _shellDescriptor.Features.Any(sf => sf.Name == extensionDescriptor.Id)
})
.ToArray();
return View(new ThemesIndexViewModel {
CurrentTheme = currentTheme, Themes = themes,
CurrentTheme = currentTheme,
Themes = themes,
InstallThemes = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null
});
} catch (Exception exception) {

View File

@@ -1,4 +1,5 @@
using Orchard.Data.Migration;
using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;
namespace Orchard.Themes {
public class ThemesDataMigration : DataMigrationImpl {

View File

@@ -0,0 +1,19 @@
using Orchard.Environment.Extensions.Models;
namespace Orchard.Themes.Models {
public class ThemeEntry {
public ThemeEntry() {}
public ThemeEntry(ExtensionDescriptor extensionDescriptor) {
Descriptor = extensionDescriptor;
}
public ExtensionDescriptor Descriptor { get; set; }
public bool Enabled { get; set; }
public bool NeedsUpdate { get; set; }
public string Name { get { return Descriptor.Name; } }
}
}

View File

@@ -49,6 +49,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AdminMenu.cs" />
<Compile Include="Models\ThemeEntry.cs" />
<Compile Include="ResourceManifest.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Migrations.cs" />

View File

@@ -1,6 +1,27 @@
#main .templates p {
margin:0 0 .3em 0;
}
#currentTheme .themePreviewImage {
float: left;
margin-right: 20px;
}
#installedBar {
clear: both;
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: #E4E5E6;
height: 50px;
margin: 10px 0 10px 0;
}
#installedBar h3 {
float: left;
padding-top: 10px;
}
#installedBar p a {
color: #3A822E;
float: right;
padding-top: 20px;
}
.templates li {
margin:.8em;
width:30%;
@@ -29,4 +50,4 @@
}
.themePreviewImage {
height:300px;
}
}

View File

@@ -1,23 +1,10 @@
using System;
using System.Collections.Generic;
using Orchard.Environment.Extensions.Models;
using System.Collections.Generic;
using Orchard.Themes.Models;
namespace Orchard.Themes.ViewModels {
public class ThemesIndexViewModel {
public bool InstallThemes { get; set; }
public ExtensionDescriptor CurrentTheme { get; set; }
public ThemeEntry CurrentTheme { get; set; }
public IEnumerable<ThemeEntry> Themes { get; set; }
}
public class ThemeEntry {
public ExtensionDescriptor Descriptor { get; set; }
public bool Enabled { get; set; }
public bool NeedsUpdate { get; set; }
public string Id { get { return Descriptor.Id; } }
public string Name { get { return Descriptor.Name; } }
public string ThemePath(string path) {
return Descriptor.Location + "/" + Descriptor.Id + path;
}
}
}

View File

@@ -1,4 +1,7 @@
@model Orchard.Themes.ViewModels.ThemesIndexViewModel
@using Orchard.Themes.Models
@using Orchard.Mvc.Html
@{
Style.Require("ThemesAdmin");
WorkContext.Layout.BeforeContent.Add(New.BeforeContent(Title: "Themes"), "5");
@@ -10,67 +13,82 @@
@Html.ActionLink(T("Install a new Theme").ToString(), "Install")
</p>
} else {
<h3>@T("Current Theme") - @Model.CurrentTheme.Name</h3>
<h3 id="currentThemeTitle">@T("Current Theme")</h3>
@Html.Image(Href(Html.ThemePath(Model.CurrentTheme, "/Theme.png")), Html.Encode(Model.CurrentTheme.Name), new { @class = "themePreviewImage" })
<h5>@T("By") @Model.CurrentTheme.Author</h5>
<p>
@T("Version:") @Model.CurrentTheme.Version<br />
@Model.CurrentTheme.Description<br />
@Model.CurrentTheme.WebSite
</p>
<div id="currentTheme">
@Html.Image(Href(Html.ThemePath(Model.CurrentTheme.Descriptor, "/Theme.png")), Html.Encode(Model.CurrentTheme.Name), new { @class = "themePreviewImage" })
if (Model.InstallThemes) {
<p>@Html.ActionLink(T("Install a theme").ToString(), "AddTheme", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })</p>
}
<div class="details">
@Model.CurrentTheme.Name<br />
@T("By") @Model.CurrentTheme.Descriptor.Author<br />
@T("Version:") @Model.CurrentTheme.Descriptor.Version<br />
@if (Model.CurrentTheme.Descriptor.WebSite != null) {
<a href="@Model.CurrentTheme.Descriptor.WebSite">@Model.CurrentTheme.Descriptor.WebSite</a><br />
}
<br />
<p>@Model.CurrentTheme.Descriptor.Description</p>
</div>
</div>
}
<h2>@T("Available Themes")</h2>
<ul class="templates">
@foreach (var theme in Model.Themes) {
var tags = theme.Descriptor.Tags;
bool hidden = false;
if (tags != null) {
hidden = tags.Split(',').Any(t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase));
}
if (!hidden && (Model.CurrentTheme == null || theme.Id != Model.CurrentTheme.Id)) {
<div id="installedBar">
<h3>@T("Installed")</h3>
@if (Model.InstallThemes) {
<p>@Html.ActionLink(T("Install theme").ToString(), "AddTheme", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "primaryAction" })</p>
}
</div>
@if (Model.Themes == null || Model.Themes.Count() <= 0) {
<p>@T("There are no additional themes installed.")</p>
} else {
<ul class="templates">
@foreach (ThemeEntry theme in Model.Themes) {
<li>
<div>
<h3>@theme.Name</h3>
@Html.Image(Href(theme.ThemePath("/Theme.png")), Html.Encode(theme.Name), null)
@using (Html.BeginFormAntiForgeryPost(Url.Action(theme.Enabled ? "Disable" : "Enable"), FormMethod.Post, new { @class = "inline" })) {
@Html.Hidden("themeName", theme.Id)
<button type="submit" title="@T(theme.Enabled ? "Disable" : "Enable")">@T(theme.Enabled ? "Disable" : "Enable")</button>
}
@Html.Image(Href(Html.ThemePath(Model.CurrentTheme.Descriptor, "/Theme.png")), Html.Encode(Model.CurrentTheme.Name), null)
@using (Html.BeginFormAntiForgeryPost(Url.Action("Activate"), FormMethod.Post, new { @class = "inline" })) {
@Html.Hidden("themeName", theme.Id)
@Html.Hidden("themeName", theme.Descriptor.Id)
<button type="submit" title="@T("Activate")">@T("Set Current")</button>
}
@using (Html.BeginFormAntiForgeryPost(Url.Action("Preview"), FormMethod.Post, new { @class = "inline" })) {
@Html.Hidden("themeName", theme.Id)
@Html.Hidden("themeName", theme.Descriptor.Id)
<button type="submit" title="@T("Preview")">@T("Preview")</button>
}
<h5>@T("By") @theme.Descriptor.Author</h5>
<p>
@T("Version:") @theme.Descriptor.Version<br />
@theme.Descriptor.Description<br />
@theme.Descriptor.WebSite
@if (theme.Descriptor.WebSite != null) {
<a href="@theme.Descriptor.WebSite">@theme.Descriptor.WebSite</a><br />
}
</p>
@if(theme.NeedsUpdate){
@if (theme.Enabled) {
using (Html.BeginFormAntiForgeryPost(Url.Action("Disable"), FormMethod.Post, new { @class = "inline link" })) {
@Html.Hidden("themeName", theme.Descriptor.Id)
<button type="submit" title="Disable">@T("Disable")</button>
}
}
@if (theme.NeedsUpdate) {
using (Html.BeginFormAntiForgeryPost(Url.Action("Update"), FormMethod.Post, new { @class = "inline link" })) {
@Html.Hidden("themeName", theme.Id)
@Html.Hidden("themeName", theme.Descriptor.Id)
<button type="submit" class="update">@T("Update")</button> <br/>
}
}
@if (Model.InstallThemes) {
using (Html.BeginFormAntiForgeryPost(Url.Action("RemoveTheme", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl, retryUrl = HttpContext.Current.Request.RawUrl, themeId = theme.Id }), FormMethod.Post, new { @class = "inline link" })) {
using (Html.BeginFormAntiForgeryPost(Url.Action("RemoveTheme", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl, retryUrl = HttpContext.Current.Request.RawUrl, themeId = theme.Descriptor.Id }), FormMethod.Post, new { @class = "inline link" })) {
<button type="submit" class="uninstall" title="@T("Uninstall")">@T("Uninstall")</button>
}
}
</div>
</li>
}
}
</ul>
</ul>
}