--HG--
branch : dev
This commit is contained in:
Dave Reed
2010-10-19 12:12:37 -07:00
5 changed files with 96 additions and 33 deletions

View File

@@ -7,6 +7,7 @@ using Orchard.Core.Contents.Controllers;
using Orchard.Localization; using Orchard.Localization;
using Orchard.UI.Admin; using Orchard.UI.Admin;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.UI.Widgets;
using Orchard.Widgets.Models; using Orchard.Widgets.Models;
using Orchard.Widgets.Services; using Orchard.Widgets.Services;
using Orchard.Widgets.ViewModels; using Orchard.Widgets.ViewModels;
@@ -19,13 +20,16 @@ namespace Orchard.Widgets.Controllers {
private const string NotAuthorizedManageWidgetsLabel = "Not authorized to manage widgets"; private const string NotAuthorizedManageWidgetsLabel = "Not authorized to manage widgets";
private readonly IWidgetsService _widgetsService; private readonly IWidgetsService _widgetsService;
private readonly IRuleManager _ruleManager;
public AdminController( public AdminController(
IOrchardServices services, IOrchardServices services,
IWidgetsService widgetsService) { IWidgetsService widgetsService,
IRuleManager ruleManager) {
Services = services; Services = services;
_widgetsService = widgetsService; _widgetsService = widgetsService;
_ruleManager = ruleManager;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -171,6 +175,9 @@ namespace Orchard.Widgets.Controllers {
return HttpNotFound(); return HttpNotFound();
var model = Services.ContentManager.UpdateEditor(layerPart, this); var model = Services.ContentManager.UpdateEditor(layerPart, this);
ValidateLayer(layerPart);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
Services.TransactionManager.Cancel(); Services.TransactionManager.Cancel();
return View(model); return View(model);
@@ -216,6 +223,9 @@ namespace Orchard.Widgets.Controllers {
return HttpNotFound(); return HttpNotFound();
var model = Services.ContentManager.UpdateEditor(layerPart, this); var model = Services.ContentManager.UpdateEditor(layerPart, this);
ValidateLayer(layerPart);
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
Services.TransactionManager.Cancel(); Services.TransactionManager.Cancel();
return View(model); return View(model);
@@ -325,6 +335,27 @@ namespace Orchard.Widgets.Controllers {
RedirectToAction("Index"); RedirectToAction("Index");
} }
public bool ValidateLayer(LayerPart layer) {
if ( String.IsNullOrWhiteSpace(layer.LayerRule) ) {
layer.LayerRule = "true";
}
if(_widgetsService.GetLayers().Any(l => String.CompareOrdinal(l.Name, layer.Name) == 0)) {
ModelState.AddModelError("Name", T("A Layer with the same name already exists").Text);
return false;
}
try {
_ruleManager.Matches(layer.LayerRule);
}
catch ( Exception e ) {
ModelState.AddModelError("Description", T("The rule is not valid: {0}", e.Message).Text);
return false;
}
return true;
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return base.TryUpdateModel(model, prefix, includeProperties, excludeProperties); return base.TryUpdateModel(model, prefix, includeProperties, excludeProperties);
} }

View File

@@ -1,7 +1,10 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Mvc.Filters; using Orchard.Mvc.Filters;
using Orchard.UI.Admin; using Orchard.UI.Admin;
using Orchard.UI.Widgets; using Orchard.UI.Widgets;
@@ -17,8 +20,13 @@ namespace Orchard.Widgets.Filters {
_contentManager = contentManager; _contentManager = contentManager;
_workContextAccessor = workContextAccessor; _workContextAccessor = workContextAccessor;
_ruleManager = ruleManager; _ruleManager = ruleManager;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
} }
public ILogger Logger { get; set; }
public Localizer T { get; private set; }
public void OnResultExecuting(ResultExecutingContext filterContext) { public void OnResultExecuting(ResultExecutingContext filterContext) {
// layers and widgets should only run on a full view rendering result // layers and widgets should only run on a full view rendering result
var viewResult = filterContext.Result as ViewResult; var viewResult = filterContext.Result as ViewResult;
@@ -42,8 +50,14 @@ namespace Orchard.Widgets.Filters {
List<int> activeLayerIds = new List<int>(); List<int> activeLayerIds = new List<int>();
foreach (var activeLayer in activeLayers) { foreach (var activeLayer in activeLayers) {
var context = workContext.HttpContext; var context = workContext.HttpContext;
if (_ruleManager.Matches(activeLayer.Record.LayerRule)) { // ignore the rule if it fails to execute
activeLayerIds.Add(activeLayer.ContentItem.Id); try {
if (_ruleManager.Matches(activeLayer.Record.LayerRule)) {
activeLayerIds.Add(activeLayer.ContentItem.Id);
}
}
catch(Exception e) {
Logger.Debug(e, T("An error occured during layer evaluation").Text);
} }
} }

View File

@@ -4,20 +4,23 @@
} }
.widgets-availableWidgets { .widgets-availableWidgets {
float: right;
float: left; float: left;
width: 30%; width: 30%;
margin: 0 0 0 2em;
} }
.widgets-availableLayers { .widgets-availableLayers {
float: left; float: left;
margin: 0 0 0 2em; margin: 0 0 0 2em;
width: 45%; width: 60%;
min-width: 40%;
} }
.widgets-layerZones { .widgets-layerZones {
font-size: 1.4em; font-size: 1.4em;
float: left; float: left;
width: 70%; width: 60%;
border: 1px solid #eaeaea; border: 1px solid #eaeaea;
background: #fff; background: #fff;
} }
@@ -66,3 +69,12 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.new-layer {
padding: .6em;
}
.new-layer a {
text-decoration: none;
font-weight: 600;
}

View File

@@ -5,7 +5,7 @@
Style.Require("WidgetsAdmin"); Style.Require("WidgetsAdmin");
} }
<h1>@Html.TitleForPage(T("Manage Widgets").ToString())</h1> <h1>@Html.TitleForPage(T("Manage Widgets").ToString())</h1>
<div class="manage">@Html.ActionLink(T("Add a layer").ToString(), "AddLayer", new { }, new { @class = "button primaryAction" })</div>
@using(Html.BeginFormAntiForgeryPost()) { @using(Html.BeginFormAntiForgeryPost()) {
Html.ValidationSummary(); Html.ValidationSummary();
@@ -13,31 +13,7 @@
<div id="widgets"> <div id="widgets">
<div class="widgets-availableWidgets">
<h2>Available Widgets</h2>
<fieldset>
<table class="items" summary="@T("This is a table of the widgets currently available for use in your application.")">
<colgroup>
<col id="Col1" />
<col id="Col2" />
</colgroup>
<thead>
<tr>
<th scope="col">@T("Name")</th>
<th scope="col"></th>
</tr>
</thead>
@foreach (string widget in Model.WidgetTypes) {
<tr>
<td>@widget</td>
<td>@Html.ActionLink(T("Add").ToString(), "AddWidget", new { layerId = Model.CurrentLayer.Id, widgetType = widget })</td>
</tr>
}
</table>
</fieldset>
</div>
<div class="widgets-availableLayers"> <div class="widgets-availableLayers">
<h2>Widget Zones</h2> <h2>Widget Zones</h2>
@@ -92,9 +68,39 @@
</li> </li>
} }
} }
<ul> </ul>
<div class="new-layer">
@Html.ActionLink(T("+ Add a layer").ToString(), "AddLayer", new { })
</div>
</div> </div>
</fieldset> </fieldset>
</div> </div>
<div class="widgets-availableWidgets">
<h2>Available Widgets</h2>
<fieldset>
<table class="items" summary="@T("This is a table of the widgets currently available for use in your application.")">
<colgroup>
<col id="Col1" />
<col id="Col2" />
</colgroup>
<thead>
<tr>
<th scope="col">@T("Name")</th>
<th scope="col"></th>
</tr>
</thead>
@foreach (string widget in Model.WidgetTypes) {
<tr>
<td>@widget</td>
<td>@Html.ActionLink(T("Add").ToString(), "AddWidget", new { layerId = Model.CurrentLayer.Id, widgetType = widget })</td>
</tr>
}
</table>
</fieldset>
</div>
</div> </div>
} }

View File

@@ -194,7 +194,7 @@ namespace Orchard.Data.Migration.Interpreters {
} }
else { else {
if(command.Length > 0 || command.Precision > 0 || command.Scale > 0) { if(command.Length > 0 || command.Precision > 0 || command.Scale > 0) {
throw new OrchardException(T("Error while executing data migration: you need to specify the field's type in order to change it's properies")); throw new OrchardException(T("Error while executing data migration: you need to specify the field's type in order to change its properties"));
} }
} }