mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 19:44:02 +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) {
|
protected override DriverResult Editor(WidgetPart widgetPart, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
updater.TryUpdateModel(widgetPart, Prefix, null, null);
|
updater.TryUpdateModel(widgetPart, Prefix, null, null);
|
||||||
|
|
||||||
|
_widgetsService.MakeRoomForWidgetPosition(widgetPart);
|
||||||
|
|
||||||
return Editor(widgetPart, shapeHelper);
|
return Editor(widgetPart, shapeHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,17 @@ namespace Orchard.Widgets.Services {
|
|||||||
|
|
||||||
WidgetPart GetWidget(int widgetId);
|
WidgetPart GetWidget(int widgetId);
|
||||||
WidgetPart CreateWidget(int layerId, string widgetType, string title, string position, string zone);
|
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);
|
void DeleteWidget(int widgetId);
|
||||||
|
|
||||||
LayerPart GetLayer(int layerId);
|
LayerPart GetLayer(int layerId);
|
||||||
LayerPart CreateLayer(string name, string description, string layerRule);
|
LayerPart CreateLayer(string name, string description, string layerRule);
|
||||||
void UpdateLayer(int layerId, string name, string description, string layerRule);
|
|
||||||
void DeleteLayer(int layerId);
|
void DeleteLayer(int layerId);
|
||||||
|
|
||||||
bool MoveWidgetUp(int widgetId);
|
bool MoveWidgetUp(int widgetId);
|
||||||
bool MoveWidgetUp(WidgetPart widgetPart);
|
bool MoveWidgetUp(WidgetPart widgetPart);
|
||||||
bool MoveWidgetDown(int widgetId);
|
bool MoveWidgetDown(int widgetId);
|
||||||
bool MoveWidgetDown(WidgetPart widgetPart);
|
bool MoveWidgetDown(WidgetPart widgetPart);
|
||||||
|
void MakeRoomForWidgetPosition(int widgetId);
|
||||||
|
void MakeRoomForWidgetPosition(WidgetPart widgetPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,13 +77,6 @@ namespace Orchard.Widgets.Services {
|
|||||||
return layerPart;
|
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) {
|
public void DeleteLayer(int layerId) {
|
||||||
// Delete widgets in the layer
|
// Delete widgets in the layer
|
||||||
foreach (WidgetPart widgetPart in GetWidgets(layerId)) {
|
foreach (WidgetPart widgetPart in GetWidgets(layerId)) {
|
||||||
@@ -116,24 +109,10 @@ namespace Orchard.Widgets.Services {
|
|||||||
return widgetPart;
|
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) {
|
public void DeleteWidget(int widgetId) {
|
||||||
_contentManager.Remove(GetWidget(widgetId).ContentItem);
|
_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) {
|
public bool MoveWidgetUp(int widgetId) {
|
||||||
return MoveWidgetUp(GetWidget(widgetId));
|
return MoveWidgetUp(GetWidget(widgetId));
|
||||||
}
|
}
|
||||||
@@ -174,6 +153,31 @@ namespace Orchard.Widgets.Services {
|
|||||||
return false;
|
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) {
|
private static void SwitchWidgetPositions(WidgetPart sourceWidget, WidgetPart targetWidget) {
|
||||||
string tempPosition = sourceWidget.Record.Position;
|
string tempPosition = sourceWidget.Record.Position;
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ webkit-border-radius:0;
|
|||||||
border-radius:0;
|
border-radius:0;
|
||||||
-webkit-box-shadow:none;
|
-webkit-box-shadow:none;
|
||||||
-moz-box-shadow:none;
|
-moz-box-shadow:none;
|
||||||
box-shadow:none;
|
box-shadow:none;
|
||||||
|
height:15px;
|
||||||
filter:none;
|
filter:none;
|
||||||
float:left;
|
float:left;
|
||||||
padding:0;
|
padding:0;
|
||||||
|
|||||||
Reference in New Issue
Block a user