mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Themes admin allows you to enable/disable themes separately from setting them to the default. DataMigrations for themes are done there too.
--HG-- branch : dev
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.Reports.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.Themes.Preview;
|
||||
using Orchard.Themes.ViewModels;
|
||||
@@ -14,8 +17,12 @@ namespace Orchard.Themes.Controllers {
|
||||
public class AdminController : Controller {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IPreviewTheme _previewTheme;
|
||||
private readonly IDataMigrationManager _dataMigrationManager;
|
||||
private readonly IReportsCoordinator _reportsCoordinator;
|
||||
|
||||
public AdminController(
|
||||
IDataMigrationManager dataMigraitonManager,
|
||||
IReportsCoordinator reportsCoordinator,
|
||||
IOrchardServices services,
|
||||
IThemeService themeService,
|
||||
IPreviewTheme previewTheme,
|
||||
@@ -23,6 +30,8 @@ namespace Orchard.Themes.Controllers {
|
||||
INotifier notifier,
|
||||
IShapeHelperFactory shapeHelperFactory) {
|
||||
Services = services;
|
||||
_dataMigrationManager = dataMigraitonManager;
|
||||
_reportsCoordinator = reportsCoordinator;
|
||||
_themeService = themeService;
|
||||
_previewTheme = previewTheme;
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -36,7 +45,8 @@ namespace Orchard.Themes.Controllers {
|
||||
try {
|
||||
var themes = _themeService.GetInstalledThemes();
|
||||
var currentTheme = _themeService.GetSiteTheme();
|
||||
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes };
|
||||
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
|
||||
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes, FeaturesThatNeedUpdate = featuresThatNeedUpdate };
|
||||
return View(model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
@@ -66,12 +76,11 @@ namespace Orchard.Themes.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
_themeService.SetSiteTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Preview"), FormValueRequired("submit.Cancel")]
|
||||
@@ -80,12 +89,37 @@ namespace Orchard.Themes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Enable(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't enable the theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.EnableTheme(themeName);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Enabling theme failed: " + exception.Message));
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Disable(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't disable the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.DisableTheme(themeName);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Disabling theme failed: " + exception.Message));
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -94,12 +128,11 @@ namespace Orchard.Themes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't set the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.SetSiteTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Activating theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Install() {
|
||||
@@ -137,6 +170,26 @@ namespace Orchard.Themes.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Update(string themeName) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't update theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (string.IsNullOrEmpty(themeName))
|
||||
return new NotFoundResult();
|
||||
|
||||
try {
|
||||
_reportsCoordinator.Register("Data Migration", "Upgrade " + themeName, "Orchard installation");
|
||||
_dataMigrationManager.Update(themeName);
|
||||
Services.Notifier.Information(T("The theme {0} was updated succesfuly", themeName));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Services.Notifier.Error(T("An error occured while updating the theme {0}: {1}", themeName, ex.Message));
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
class FormValueRequiredAttribute : ActionMethodSelectorAttribute {
|
||||
private readonly string _submitButtonName;
|
||||
|
||||
|
Reference in New Issue
Block a user