mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Shifting Widgets
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Orchard.Core.Settings.Services {
|
||||
public ISite GetSiteSettings() {
|
||||
var siteId = _cacheManager.Get("SiteId", ctx => {
|
||||
var site = _contentManager.Query("Site")
|
||||
.Slice(0, 1)
|
||||
.List()
|
||||
.FirstOrDefault();
|
||||
|
||||
if (site == null) {
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace Orchard.Widgets.Commands {
|
||||
Context.Output.WriteLine(T("Creating Layer {0}", name));
|
||||
|
||||
IContent layer = _contentManager.Create<LayerPart>("Layer", t => {
|
||||
t.Record.Name = name;
|
||||
t.Record.LayerRule = LayerRule;
|
||||
t.Record.Description = Description ?? String.Empty;
|
||||
t.Name = name;
|
||||
t.LayerRule = LayerRule;
|
||||
t.Description = Description ?? String.Empty;
|
||||
});
|
||||
|
||||
_contentManager.Publish(layer.ContentItem);
|
||||
|
||||
@@ -53,13 +53,13 @@ namespace Orchard.Widgets.Filters {
|
||||
|
||||
// Once the Rule Engine is done:
|
||||
// Get Layers and filter by zone and rule
|
||||
IEnumerable<LayerPart> activeLayers = _orchardServices.ContentManager.Query<LayerPart, LayerPartRecord>().List();
|
||||
IEnumerable<LayerPart> activeLayers = _orchardServices.ContentManager.Query<LayerPart>().List();
|
||||
|
||||
var activeLayerIds = new List<int>();
|
||||
foreach (var activeLayer in activeLayers) {
|
||||
// ignore the rule if it fails to execute
|
||||
try {
|
||||
if (_ruleManager.Matches(activeLayer.Record.LayerRule)) {
|
||||
if (_ruleManager.Matches(activeLayer.LayerRule)) {
|
||||
activeLayerIds.Add(activeLayer.ContentItem.Id);
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace Orchard.Widgets.Filters {
|
||||
}
|
||||
|
||||
var widgetShape = _orchardServices.ContentManager.BuildDisplay(widgetPart);
|
||||
zones[widgetPart.Record.Zone].Add(widgetShape, widgetPart.Record.Position);
|
||||
zones[widgetPart.Zone].Add(widgetShape, widgetPart.Position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,16 +9,16 @@ namespace Orchard.Widgets.Models {
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Name {
|
||||
get { return Record.Name; }
|
||||
set { Record.Name = value; }
|
||||
get { return Retrieve(x => x.Name); }
|
||||
set { Store(x => x.Name, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The layer's description.
|
||||
/// </summary>
|
||||
public string Description {
|
||||
get { return Record.Description; }
|
||||
set { Record.Description = value; }
|
||||
get { return Retrieve(x => x.Description); }
|
||||
set { Store(x => x.Description, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -26,8 +26,8 @@ namespace Orchard.Widgets.Models {
|
||||
/// The rule defines when the layer is active (should or not be displayed).
|
||||
/// </summary>
|
||||
public string LayerRule {
|
||||
get { return Record.LayerRule; }
|
||||
set { Record.LayerRule = value; }
|
||||
get { return Retrieve(x => x.LayerRule); }
|
||||
set { Store(x => x.LayerRule, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ namespace Orchard.Widgets.Models {
|
||||
/// The widget's title.
|
||||
/// </summary>
|
||||
public string Title {
|
||||
get { return Record.Title; }
|
||||
set { Record.Title = value; }
|
||||
get { return Retrieve(x => x.Title); }
|
||||
set { Store(x => x.Title, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -20,16 +20,16 @@ namespace Orchard.Widgets.Models {
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Zone {
|
||||
get { return Record.Zone; }
|
||||
set { Record.Zone = value; }
|
||||
get { return Retrieve(x => x.Zone); }
|
||||
set { Store(x => x.Zone, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the Title should be rendered on the front-end
|
||||
/// </summary>
|
||||
public bool RenderTitle {
|
||||
get { return Record.RenderTitle; }
|
||||
set { Record.RenderTitle = value; }
|
||||
get { return Retrieve(x => x.RenderTitle); }
|
||||
set { Store(x => x.RenderTitle, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,16 +38,16 @@ namespace Orchard.Widgets.Models {
|
||||
[Required]
|
||||
public string Position
|
||||
{
|
||||
get { return Record.Position; }
|
||||
set { Record.Position = value; }
|
||||
get { return Retrieve(x => x.Position); }
|
||||
set { Store(x => x.Position, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The technical name of the widget.
|
||||
/// </summary>
|
||||
public string Name {
|
||||
get { return Record.Name; }
|
||||
set { Record.Name = value; }
|
||||
get { return Retrieve(x => x.Name); }
|
||||
set { Store(x => x.Name, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Widgets.Models;
|
||||
|
||||
namespace Orchard.Widgets.Services {
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Orchard.Widgets.Services {
|
||||
|
||||
public IEnumerable<WidgetPart> GetWidgets(int[] layerIds) {
|
||||
return _contentManager
|
||||
.Query<WidgetPart, WidgetPartRecord>()
|
||||
.Query<WidgetPart>()
|
||||
.Where<CommonPartRecord>(x => layerIds.Contains(x.Container.Id))
|
||||
.List();
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace Orchard.Widgets.Services {
|
||||
.ToList();
|
||||
|
||||
// if this theme has no zones defined then walk the BaseTheme chain until we hit a theme which defines zones
|
||||
while (zones.Count() == 0 && theme != null && !string.IsNullOrWhiteSpace(theme.BaseTheme)) {
|
||||
while (!zones.Any() && theme != null && !string.IsNullOrWhiteSpace(theme.BaseTheme)) {
|
||||
string baseTheme = theme.BaseTheme;
|
||||
theme = _extensionManager.GetExtension(baseTheme);
|
||||
if (theme != null && theme.Zones != null)
|
||||
@@ -117,9 +117,9 @@ namespace Orchard.Widgets.Services {
|
||||
public LayerPart CreateLayer(string name, string description, string layerRule) {
|
||||
LayerPart layerPart = _contentManager.Create<LayerPart>("Layer",
|
||||
layer => {
|
||||
layer.Record.Name = name;
|
||||
layer.Record.Description = description;
|
||||
layer.Record.LayerRule = layerRule;
|
||||
layer.Name = name;
|
||||
layer.Description = description;
|
||||
layer.LayerRule = layerRule;
|
||||
});
|
||||
|
||||
return layerPart;
|
||||
@@ -148,9 +148,9 @@ namespace Orchard.Widgets.Services {
|
||||
|
||||
WidgetPart widgetPart = _contentManager.Create<WidgetPart>(widgetType,
|
||||
widget => {
|
||||
widget.Record.Title = title;
|
||||
widget.Record.Position = position;
|
||||
widget.Record.Zone = zone;
|
||||
widget.Title = title;
|
||||
widget.Position = position;
|
||||
widget.Zone = zone;
|
||||
widget.LayerPart = layerPart;
|
||||
});
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace Orchard.Widgets.Services {
|
||||
.OrderBy(widget => widget.Position, new UI.FlatPositionComparer()).ToList();
|
||||
|
||||
// no need to continue if there are no widgets that will conflict with this widget's position
|
||||
if (widgetsToMove.Count() == 0 || ParsePosition(widgetsToMove.First()) > targetPosition)
|
||||
if (!widgetsToMove.Any() || ParsePosition(widgetsToMove.First()) > targetPosition)
|
||||
return;
|
||||
|
||||
int position = targetPosition;
|
||||
@@ -238,7 +238,7 @@ namespace Orchard.Widgets.Services {
|
||||
|
||||
private static int ParsePosition(WidgetPart widgetPart) {
|
||||
int value;
|
||||
if (!int.TryParse(widgetPart.Record.Position, out value))
|
||||
if (!int.TryParse(widgetPart.Position, out value))
|
||||
return 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -205,5 +205,47 @@ namespace Upgrade.Controllers {
|
||||
|
||||
return new JsonResult { Data = lastContentItemId };
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public JsonResult MigrateWidgetPart(int id) {
|
||||
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner))
|
||||
throw new AuthenticationException("");
|
||||
|
||||
var lastContentItemId = id;
|
||||
|
||||
_upgradeService.ExecuteReader("SELECT TOP " + BATCH + " * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Widgets_WidgetPartRecord") + " WHERE Id > " + id,
|
||||
(reader, connection) => {
|
||||
lastContentItemId = (int)reader["Id"];
|
||||
var contentPermissionPart = _orchardServices.ContentManager.Get(lastContentItemId);
|
||||
|
||||
contentPermissionPart.As<InfosetPart>().Store("WidgetPart", "Title", (string)reader["Title"]);
|
||||
contentPermissionPart.As<InfosetPart>().Store("WidgetPart", "Position", (string)reader["Position"]);
|
||||
contentPermissionPart.As<InfosetPart>().Store("WidgetPart", "Zone", (string)reader["Zone"]);
|
||||
contentPermissionPart.As<InfosetPart>().Store("WidgetPart", "RenderTitle", (bool)reader["RenderTitle"]);
|
||||
contentPermissionPart.As<InfosetPart>().Store("WidgetPart", "Name", (string)reader["Name"]);
|
||||
});
|
||||
|
||||
return new JsonResult { Data = lastContentItemId };
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public JsonResult MigrateLayerPart(int id) {
|
||||
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner))
|
||||
throw new AuthenticationException("");
|
||||
|
||||
var lastContentItemId = id;
|
||||
|
||||
_upgradeService.ExecuteReader("SELECT TOP " + BATCH + " * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Widgets_LayerPartRecord") + " WHERE Id > " + id,
|
||||
(reader, connection) => {
|
||||
lastContentItemId = (int)reader["Id"];
|
||||
var contentPermissionPart = _orchardServices.ContentManager.Get(lastContentItemId);
|
||||
|
||||
contentPermissionPart.As<InfosetPart>().Store("LayerPart", "Name", (string)reader["Name"]);
|
||||
contentPermissionPart.As<InfosetPart>().Store("LayerPart", "Description", (string)reader["Description"]);
|
||||
contentPermissionPart.As<InfosetPart>().Store("LayerPart", "LayerRule", (string)reader["LayerRule"]);
|
||||
});
|
||||
|
||||
return new JsonResult { Data = lastContentItemId };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,18 @@
|
||||
<button type="button" class="button button-migrate" data-url="@Url.Action("MigrateTagsPart", "Infoset")">@T("Migrate")</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>@T("Migrating Widget Parts:")</legend>
|
||||
<span class="hint">@T("This migration step will copy all Widget parts to Infosets.")</span>
|
||||
<button type="button" class="button button-migrate" data-url="@Url.Action("MigrateWidgetPart", "Infoset")">@T("Migrate")</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>@T("Migrating Layer Parts:")</legend>
|
||||
<span class="hint">@T("This migration step will copy all Layer parts to Infosets.")</span>
|
||||
<button type="button" class="button button-migrate" data-url="@Url.Action("MigrateLayerPart", "Infoset")">@T("Migrate")</button>
|
||||
</fieldset>
|
||||
|
||||
@using (Script.Foot()) {
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
|
||||
Reference in New Issue
Block a user