mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -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>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
||||
return base.TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
||||
}
|
||||
|
@@ -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,10 +50,16 @@ namespace Orchard.Widgets.Filters {
|
||||
List<int> activeLayerIds = new List<int>();
|
||||
foreach (var activeLayer in activeLayers) {
|
||||
var context = workContext.HttpContext;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// Build and add shape to zone.
|
||||
var zones = workContext.Layout.Zones;
|
||||
|
@@ -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;
|
||||
}
|
||||
@@ -66,3 +69,12 @@
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.new-layer {
|
||||
padding: .6em;
|
||||
}
|
||||
|
||||
.new-layer a {
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
Style.Require("WidgetsAdmin");
|
||||
}
|
||||
<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()) {
|
||||
Html.ValidationSummary();
|
||||
@@ -13,31 +13,7 @@
|
||||
|
||||
<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">
|
||||
<h2>Widget Zones</h2>
|
||||
@@ -92,8 +68,38 @@
|
||||
</li>
|
||||
}
|
||||
}
|
||||
<ul>
|
||||
</ul>
|
||||
<div class="new-layer">
|
||||
@Html.ActionLink(T("+ Add a layer").ToString(), "AddLayer", new { })
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</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>
|
||||
|
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user