From eae645a9b880078ab92032f0336f91f350dfaff6 Mon Sep 17 00:00:00 2001 From: Robert Lyon Date: Tue, 8 Dec 2015 12:59:01 +1300 Subject: [PATCH] Bug 1523719: Allowing blocks to order right When moving them downwards in a column from a non-first position to a non-last position with a jump greater than one place behatnotneeded Change-Id: Ie9bacc4a1a4ef77efd4e481c9ab3713885821dc1 Signed-off-by: Robert Lyon (cherry picked from commit a8750346a3f671847c9c6e54e61466d0382fde41) --- htdocs/lib/view.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/htdocs/lib/view.php b/htdocs/lib/view.php index f49807f81b..7fdb4c5658 100644 --- a/htdocs/lib/view.php +++ b/htdocs/lib/view.php @@ -2254,12 +2254,6 @@ class View { } else { $this->shuffle_cell($values['row'], $bi->get('column'), $values['order'], $bi->get('order')); - if ($bi->get('order') < $values['order']) { - // When moving a block down within a column, the final order is one less - // than the 'desired' order because of the empty space created when the - // block gets taken out of its original spot. - $values['order'] -= 1; - } } } // moving to another column @@ -2694,14 +2688,22 @@ class View { // move it out of range (set to 0) set_field_select('block_instance', 'order', 0, '"order" = ? AND "view" = ? AND "row" = ? AND "column" = ?', array($remove, $this->get('id'), $row, $column)); if (!empty($insert)) { - // shuffle everything up - $this->shuffle_helper('order', 'up', '>=', $insert, '"row" = ? AND "column" = ?', array($row, $column)); + // shuffle everything + if ($insert > $remove) { + $this->shuffle_helper('order', 'down', '>=', $remove, '"order" <= ? AND "row" = ? AND "column" = ?', array($insert, $row, $column)); + } + else { + $this->shuffle_helper('order', 'up', '>=', $insert, '"row" = ? AND "column" = ?', array($row, $column)); + // shuffle everything down + $this->shuffle_helper('order', 'down', '>', $remove, '"row" = ? AND "column" = ?', array($row, $column)); + } // now move it back set_field_select('block_instance', 'order', $insert, '"order" = ? AND "view" = ? AND "row" = ? AND "column" = ?', array(0, $this->get('id'), $row, $column)); } - - // shuffle everything down - $this->shuffle_helper('order', 'down', '>', $remove, '"row" = ? AND "column" = ?', array($row, $column)); + else { + // shuffle everything down + $this->shuffle_helper('order', 'down', '>', $remove, '"row" = ? AND "column" = ?', array($row, $column)); + } } else if (!empty($insert)) { // shuffle everything up -- GitLab