Features list display link to update schema if available

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-07-06 12:51:26 -07:00
parent 4ed7964cbf
commit 8b9a8e14ea
5 changed files with 49 additions and 10 deletions

View File

@@ -2,6 +2,7 @@
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orchard.Data.Migration;
using Orchard.Localization;
using Orchard.Modules.ViewModels;
using Orchard.Mvc.Results;
@@ -11,10 +12,12 @@ using Orchard.Utility.Extensions;
namespace Orchard.Modules.Controllers {
public class AdminController : Controller {
private readonly IModuleService _moduleService;
private readonly IDataMigrationManager _dataMigrationManager;
public AdminController(IOrchardServices services, IModuleService moduleService) {
public AdminController(IOrchardServices services, IModuleService moduleService, IDataMigrationManager dataMigrationManager) {
Services = services;
_moduleService = moduleService;
_dataMigrationManager = dataMigrationManager;
T = NullLocalizer.Instance;
}
@@ -68,7 +71,9 @@ namespace Orchard.Modules.Controllers {
return new HttpUnauthorizedResult();
var features = _moduleService.GetAvailableFeatures().ToList();
return View(new FeaturesViewModel {Features = features});
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
return View(new FeaturesViewModel { Features = features, FeaturesThatNeedUpdate = featuresThatNeedUpdate });
}
[HttpPost]
@@ -96,5 +101,24 @@ namespace Orchard.Modules.Controllers {
return RedirectToAction("Features");
}
[HttpPost]
public ActionResult Update(string id, bool? force) {
if ( !Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")) )
return new HttpUnauthorizedResult();
if ( string.IsNullOrEmpty(id) )
return new NotFoundResult();
try {
_dataMigrationManager.Update(id);
Services.Notifier.Information(T("The feature {0} was updated succesfuly", id));
}
catch(Exception ex) {
Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, ex.Message));
}
return RedirectToAction("Features");
}
}
}

View File

@@ -4,5 +4,6 @@ using Orchard.Mvc.ViewModels;
namespace Orchard.Modules.ViewModels {
public class FeaturesViewModel : BaseViewModel {
public IEnumerable<IModuleFeature> Features { get; set; }
public IEnumerable<string> FeaturesThatNeedUpdate { get; set; }
}
}

View File

@@ -29,7 +29,7 @@
//hmmm...I feel like I've done this before...
var featureId = feature.Descriptor.Name.AsFeatureId(n => T(n));
var featureState = feature.IsEnabled ? "enabled" : "disabled";
var featureClassName = string.Format("feature {0}", featureState);
var featureClassName = string.Format("feature {0}", featureState + (Model.FeaturesThatNeedUpdate.Contains(feature.Descriptor.Name) ? " update" : String.Empty));
if (feature == features.First())
featureClassName += " first";
if (feature == features.Last())
@@ -65,7 +65,15 @@
<%: Html.Hidden("force", true)%>
<button type="submit"><%: T("Enable") %></button><%
}
} %>
}
if(Model.FeaturesThatNeedUpdate.Contains(feature.Descriptor.Name)){
using (Html.BeginFormAntiForgeryPost(string.Format("{0}", Url.Action("Update", new { area = "Orchard.Modules" })), FormMethod.Post, new {@class = "inline link"})) { %>
<%: Html.Hidden("id", feature.Descriptor.Name, new { id = "" })%>
<%: Html.Hidden("force", true)%>
<button type="submit" class="update"><%: T("Update") %></button><%
}
}
%>
</div><%
} %>
</div>

View File

@@ -110,6 +110,16 @@
top:.4em;
}
a.update {
margin-left:.5em;
}
.features .update.feature {
background:#ecc;
}
.features.summary-view .update.feature {
border-color:#e77;
}
.cathedral {
bottom:0;
font-size:.8em;
@@ -121,4 +131,4 @@
.cathedral a:visited,
.cathedral form.inline.link button {
color:#aeaeae;
}
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Orchard.Data.Migration.Generator;
using Orchard.Data.Migration.Interpreters;
using Orchard.Data.Migration.Records;
using Orchard.Data.Migration.Schema;
@@ -20,20 +19,17 @@ namespace Orchard.Data.Migration {
private readonly IRepository<DataMigrationRecord> _dataMigrationRepository;
private readonly IExtensionManager _extensionManager;
private readonly IDataMigrationInterpreter _interpreter;
private readonly ISchemaCommandGenerator _generator;
public DataMigrationManager(
IEnumerable<IDataMigration> dataMigrations,
IRepository<DataMigrationRecord> dataMigrationRepository,
IExtensionManager extensionManager,
IDataMigrationInterpreter interpreter,
ISchemaCommandGenerator generator
IDataMigrationInterpreter interpreter
) {
_dataMigrations = dataMigrations;
_dataMigrationRepository = dataMigrationRepository;
_extensionManager = extensionManager;
_interpreter = interpreter;
_generator = generator;
Logger = NullLogger.Instance;
}