2014-05-15 19:12:40 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorDashboardMovePanelController
|
|
|
|
extends PhabricatorDashboardController {
|
|
|
|
|
2015-07-22 13:27:30 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2014-05-15 19:12:40 -07:00
|
|
|
|
|
|
|
$column_id = $request->getStr('columnID');
|
|
|
|
$panel_phid = $request->getStr('objectPHID');
|
|
|
|
$after_phid = $request->getStr('afterPHID');
|
|
|
|
$before_phid = $request->getStr('beforePHID');
|
|
|
|
|
|
|
|
$dashboard = id(new PhabricatorDashboardQuery())
|
|
|
|
->setViewer($viewer)
|
2015-07-22 13:27:30 -07:00
|
|
|
->withIDs(array($id))
|
2014-05-15 19:12:40 -07:00
|
|
|
->needPanels(true)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$dashboard) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
$panels = mpull($dashboard->getPanels(), null, 'getPHID');
|
|
|
|
$panel = idx($panels, $panel_phid);
|
|
|
|
if (!$panel) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$layout_config = $dashboard->getLayoutConfigObject();
|
2014-05-19 14:04:26 -07:00
|
|
|
$layout_config->removePanel($panel_phid);
|
2014-05-15 19:12:40 -07:00
|
|
|
$panel_location_grid = $layout_config->getPanelLocations();
|
|
|
|
|
2014-06-16 09:15:35 -07:00
|
|
|
$column_phids = idx($panel_location_grid, $column_id, array());
|
|
|
|
$column_phids = array_values($column_phids);
|
|
|
|
if ($column_phids) {
|
2014-05-15 19:12:40 -07:00
|
|
|
$insert_at = 0;
|
2014-06-16 09:15:35 -07:00
|
|
|
foreach ($column_phids as $index => $phid) {
|
|
|
|
if ($phid === $before_phid) {
|
|
|
|
$insert_at = $index;
|
2014-05-15 19:12:40 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-06-16 09:15:35 -07:00
|
|
|
if ($phid === $after_phid) {
|
|
|
|
$insert_at = $index + 1;
|
2014-05-15 19:12:40 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-16 09:15:35 -07:00
|
|
|
|
|
|
|
$new_column_phids = $column_phids;
|
2014-05-15 19:12:40 -07:00
|
|
|
array_splice(
|
2014-06-16 09:15:35 -07:00
|
|
|
$new_column_phids,
|
2014-05-15 19:12:40 -07:00
|
|
|
$insert_at,
|
|
|
|
0,
|
|
|
|
array($panel_phid));
|
|
|
|
} else {
|
2014-06-16 09:15:35 -07:00
|
|
|
$new_column_phids = array(0 => $panel_phid);
|
2014-05-15 19:12:40 -07:00
|
|
|
}
|
2014-06-16 09:15:35 -07:00
|
|
|
|
|
|
|
$panel_location_grid[$column_id] = $new_column_phids;
|
2014-05-15 19:12:40 -07:00
|
|
|
$layout_config->setPanelLocations($panel_location_grid);
|
|
|
|
$dashboard->setLayoutConfigFromObject($layout_config);
|
|
|
|
$dashboard->save();
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent('');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|