From 37b4735fa226cc635f1a48baf22f9d7a9fe955fe Mon Sep 17 00:00:00 2001 From: Jonathan Wall Date: Tue, 19 Oct 2010 11:58:44 -0700 Subject: [PATCH 1/3] Updated Manage Widgets UI. --HG-- branch : dev --- .../Modules/Orchard.Widgets/Styles/admin.css | 16 ++++- .../Orchard.Widgets/Views/Admin/Index.cshtml | 58 ++++++++++--------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Styles/admin.css b/src/Orchard.Web/Modules/Orchard.Widgets/Styles/admin.css index c6cfaa63b..9fa9a23d8 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Styles/admin.css +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Styles/admin.css @@ -4,20 +4,23 @@ } .widgets-availableWidgets { + float: right; float: left; width: 30%; + margin: 0 0 0 2em; } .widgets-availableLayers { float: left; margin: 0 0 0 2em; - width: 45%; + width: 60%; + min-width: 40%; } .widgets-layerZones { font-size: 1.4em; float: left; - width: 70%; + width: 60%; border: 1px solid #eaeaea; background: #fff; } @@ -65,4 +68,13 @@ .widgets-layerZones ul li ul { margin: 0; padding: 0; +} + +.new-layer { + padding: .6em; +} + +.new-layer a { + text-decoration: none; + font-weight: 600; } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml index dfd99c72c..19d953a03 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml @@ -5,7 +5,7 @@ Style.Require("WidgetsAdmin"); }

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

-
@Html.ActionLink(T("Add a layer").ToString(), "AddLayer", new { }, new { @class = "button primaryAction" })
+ @using(Html.BeginFormAntiForgeryPost()) { Html.ValidationSummary(); @@ -13,31 +13,7 @@
-
-

Available Widgets

-
- - - - - - - - - - - - @foreach (string widget in Model.WidgetTypes) { - - - - - } -
@T("Name")
@widget@Html.ActionLink(T("Add").ToString(), "AddWidget", new { layerId = Model.CurrentLayer.Id, widgetType = widget })
- -
-

Widget Zones

@@ -92,9 +68,39 @@ } } -
    +
+
+ @Html.ActionLink(T("+ Add a layer").ToString(), "AddLayer", new { }) +
+ + +
+

Available Widgets

+ +
+ + + + + + + + + + + + @foreach (string widget in Model.WidgetTypes) { + + + + + } +
@T("Name")
@widget@Html.ActionLink(T("Add").ToString(), "AddWidget", new { layerId = Model.CurrentLayer.Id, widgetType = widget })
+ +
+
} \ No newline at end of file From 99924a92792e4a48005b56f63ad547dbe8f0dd9b Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 19 Oct 2010 12:01:58 -0700 Subject: [PATCH 2/3] Adding validation logic and syntax error management in layer rules --HG-- branch : dev --- .../Controllers/AdminController.cs | 33 ++++++++++++++++++- .../Orchard.Widgets/Filters/WidgetFilter.cs | 20 +++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs index e1264dc24..98217016c 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Controllers/AdminController.cs @@ -7,6 +7,7 @@ using Orchard.Core.Contents.Controllers; using Orchard.Localization; using Orchard.UI.Admin; using Orchard.UI.Notify; +using Orchard.UI.Widgets; using Orchard.Widgets.Models; using Orchard.Widgets.Services; using Orchard.Widgets.ViewModels; @@ -19,13 +20,16 @@ namespace Orchard.Widgets.Controllers { private const string NotAuthorizedManageWidgetsLabel = "Not authorized to manage widgets"; private readonly IWidgetsService _widgetsService; + private readonly IRuleManager _ruleManager; public AdminController( IOrchardServices services, - IWidgetsService widgetsService) { + IWidgetsService widgetsService, + IRuleManager ruleManager) { Services = services; _widgetsService = widgetsService; + _ruleManager = ruleManager; T = NullLocalizer.Instance; } @@ -171,6 +175,9 @@ namespace Orchard.Widgets.Controllers { return HttpNotFound(); var model = Services.ContentManager.UpdateEditor(layerPart, this); + + ValidateLayer(layerPart); + if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return View(model); @@ -216,6 +223,9 @@ namespace Orchard.Widgets.Controllers { return HttpNotFound(); var model = Services.ContentManager.UpdateEditor(layerPart, this); + + ValidateLayer(layerPart); + if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return View(model); @@ -325,6 +335,27 @@ namespace Orchard.Widgets.Controllers { 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 model, string prefix, string[] includeProperties, string[] excludeProperties) { return base.TryUpdateModel(model, prefix, includeProperties, excludeProperties); } diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs index ae148948e..ee00ba7b1 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs @@ -1,7 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Web.Mvc; using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; +using Orchard.Localization; +using Orchard.Logging; using Orchard.Mvc.Filters; using Orchard.UI.Admin; using Orchard.UI.Widgets; @@ -17,8 +20,13 @@ namespace Orchard.Widgets.Filters { _contentManager = contentManager; _workContextAccessor = workContextAccessor; _ruleManager = ruleManager; + Logger = NullLogger.Instance; + T = NullLocalizer.Instance; } + public ILogger Logger { get; set; } + public Localizer T { get; private set; } + public void OnResultExecuting(ResultExecutingContext filterContext) { // layers and widgets should only run on a full view rendering result var viewResult = filterContext.Result as ViewResult; @@ -42,8 +50,14 @@ namespace Orchard.Widgets.Filters { List activeLayerIds = new List(); foreach (var activeLayer in activeLayers) { var context = workContext.HttpContext; - if (_ruleManager.Matches(activeLayer.Record.LayerRule)) { - activeLayerIds.Add(activeLayer.ContentItem.Id); + // ignore the rule if it fails to execute + 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); } } From 280f015e1d54b3a288431bdb0a9f923c1bbd7d1c Mon Sep 17 00:00:00 2001 From: BertrandLeRoy Date: Tue, 19 Oct 2010 12:10:10 -0700 Subject: [PATCH 3/3] Fixing typo. --HG-- branch : dev --- .../Migration/Interpreters/DefaultDataMigrationInterpreter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs index 24039ba9d..0c97a6ab0 100644 --- a/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs @@ -194,7 +194,7 @@ namespace Orchard.Data.Migration.Interpreters { } else { 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")); } }