1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

Fix some off-by-one issues when drag-and-dropping dashboard panels

Summary: Fixes T5321. There were a couple of off-by-one issues here which could result in inserts into the wrong position.

Test Plan:
  - Dragged panels to the top, bottom, and first position of columns.
  - Dragged panels from one column to another.
  - Reloaded the page after drags, things stayed where I put them.

Reviewers: chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T5321

Differential Revision: https://secure.phabricator.com/D9573
This commit is contained in:
epriestley 2014-06-16 09:15:35 -07:00
parent 0efa1ca643
commit 5f52f1f82c

View file

@ -41,29 +41,32 @@ final class PhabricatorDashboardMovePanelController
$layout_config->removePanel($panel_phid);
$panel_location_grid = $layout_config->getPanelLocations();
$panel_columns = idx($panel_location_grid, $column_id, array());
if ($panel_columns) {
$column_phids = idx($panel_location_grid, $column_id, array());
$column_phids = array_values($column_phids);
if ($column_phids) {
$insert_at = 0;
$new_panel_columns = $panel_columns;
foreach ($panel_columns as $index => $curr_panel_phid) {
if ($curr_panel_phid === $before_phid) {
$insert_at = max($index - 1, 0);
break;
}
if ($curr_panel_phid === $after_phid) {
foreach ($column_phids as $index => $phid) {
if ($phid === $before_phid) {
$insert_at = $index;
break;
}
if ($phid === $after_phid) {
$insert_at = $index + 1;
break;
}
}
$new_column_phids = $column_phids;
array_splice(
$new_panel_columns,
$new_column_phids,
$insert_at,
0,
array($panel_phid));
} else {
$new_panel_columns = array(0 => $panel_phid);
$new_column_phids = array(0 => $panel_phid);
}
$panel_location_grid[$column_id] = $new_panel_columns;
$panel_location_grid[$column_id] = $new_column_phids;
$layout_config->setPanelLocations($panel_location_grid);
$dashboard->setLayoutConfigFromObject($layout_config);
$dashboard->save();