mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Making sure widget positions don't conflict when the WidgetPart is updated so the widget position in a zone is known by order alone and not also partially by FIFO
Pulling UpdateWidget and UpdateLayer since they're not really needed --HG-- branch : dev
This commit is contained in:
@@ -33,6 +33,9 @@ namespace Orchard.Widgets.Drivers {
|
||||
|
||||
protected override DriverResult Editor(WidgetPart widgetPart, IUpdateModel updater, dynamic shapeHelper) {
|
||||
updater.TryUpdateModel(widgetPart, Prefix, null, null);
|
||||
|
||||
_widgetsService.MakeRoomForWidgetPosition(widgetPart);
|
||||
|
||||
return Editor(widgetPart, shapeHelper);
|
||||
}
|
||||
|
||||
@@ -51,7 +54,7 @@ namespace Orchard.Widgets.Drivers {
|
||||
if (zone != null) {
|
||||
part.Zone = zone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(WidgetPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Title", part.Title);
|
||||
|
@@ -16,17 +16,17 @@ namespace Orchard.Widgets.Services {
|
||||
|
||||
WidgetPart GetWidget(int widgetId);
|
||||
WidgetPart CreateWidget(int layerId, string widgetType, string title, string position, string zone);
|
||||
void UpdateWidget(int widgetId, string title, string position, string zone);
|
||||
void DeleteWidget(int widgetId);
|
||||
|
||||
LayerPart GetLayer(int layerId);
|
||||
LayerPart CreateLayer(string name, string description, string layerRule);
|
||||
void UpdateLayer(int layerId, string name, string description, string layerRule);
|
||||
void DeleteLayer(int layerId);
|
||||
|
||||
bool MoveWidgetUp(int widgetId);
|
||||
bool MoveWidgetUp(WidgetPart widgetPart);
|
||||
bool MoveWidgetDown(int widgetId);
|
||||
bool MoveWidgetDown(WidgetPart widgetPart);
|
||||
void MakeRoomForWidgetPosition(int widgetId);
|
||||
void MakeRoomForWidgetPosition(WidgetPart widgetPart);
|
||||
}
|
||||
}
|
@@ -77,13 +77,6 @@ namespace Orchard.Widgets.Services {
|
||||
return layerPart;
|
||||
}
|
||||
|
||||
public void UpdateLayer(int layerId, string name, string description, string layerRule) {
|
||||
LayerPart layerPart = GetLayer(layerId);
|
||||
layerPart.Record.Name = name;
|
||||
layerPart.Record.Description = description;
|
||||
layerPart.Record.LayerRule = layerRule;
|
||||
}
|
||||
|
||||
public void DeleteLayer(int layerId) {
|
||||
// Delete widgets in the layer
|
||||
foreach (WidgetPart widgetPart in GetWidgets(layerId)) {
|
||||
@@ -116,24 +109,10 @@ namespace Orchard.Widgets.Services {
|
||||
return widgetPart;
|
||||
}
|
||||
|
||||
public void UpdateWidget(int widgetId, string title, string position, string zone) {
|
||||
WidgetPart widgetPart = GetWidget(widgetId);
|
||||
widgetPart.Record.Title = title;
|
||||
widgetPart.Record.Position = position;
|
||||
widgetPart.Record.Zone = zone;
|
||||
}
|
||||
|
||||
public void DeleteWidget(int widgetId) {
|
||||
_contentManager.Remove(GetWidget(widgetId).ContentItem);
|
||||
}
|
||||
|
||||
private static int ParsePosition(WidgetPart widgetPart) {
|
||||
int value;
|
||||
if (!int.TryParse(widgetPart.Record.Position, out value))
|
||||
return 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
public bool MoveWidgetUp(int widgetId) {
|
||||
return MoveWidgetUp(GetWidget(widgetId));
|
||||
}
|
||||
@@ -174,6 +153,31 @@ namespace Orchard.Widgets.Services {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MakeRoomForWidgetPosition(int widgetId) {
|
||||
MakeRoomForWidgetPosition(GetWidget(widgetId));
|
||||
}
|
||||
public void MakeRoomForWidgetPosition(WidgetPart widgetPart) {
|
||||
int targetPosition = ParsePosition(widgetPart);
|
||||
|
||||
IEnumerable<WidgetPart> widgetsToMove = GetWidgets()
|
||||
.Where(widget => widget.Zone == widgetPart.Zone && ParsePosition(widget) >= targetPosition)
|
||||
.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)
|
||||
return;
|
||||
|
||||
int position = targetPosition;
|
||||
foreach (WidgetPart widget in widgetsToMove)
|
||||
widget.Position = (++position).ToString();
|
||||
}
|
||||
|
||||
private static int ParsePosition(WidgetPart widgetPart) {
|
||||
int value;
|
||||
if (!int.TryParse(widgetPart.Record.Position, out value))
|
||||
return 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
private static void SwitchWidgetPositions(WidgetPart sourceWidget, WidgetPart targetWidget) {
|
||||
string tempPosition = sourceWidget.Record.Position;
|
||||
|
@@ -87,7 +87,8 @@ webkit-border-radius:0;
|
||||
border-radius:0;
|
||||
-webkit-box-shadow:none;
|
||||
-moz-box-shadow:none;
|
||||
box-shadow:none;
|
||||
box-shadow:none;
|
||||
height:15px;
|
||||
filter:none;
|
||||
float:left;
|
||||
padding:0;
|
||||
|
Reference in New Issue
Block a user