Differential D20409 Diff 48716 src/applications/dashboard/controller/dashboard/PhabricatorDashboardAdjustController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/controller/dashboard/PhabricatorDashboardAdjustController.php
| Show All 33 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| $panel_key = $request->getStr('panelKey'); | $panel_key = $request->getStr('panelKey'); | ||||
| if (strlen($panel_key)) { | if (strlen($panel_key)) { | ||||
| $panel_ref = $ref_list->getPanelRef($panel_key); | $panel_ref = $ref_list->getPanelRef($panel_key); | ||||
| if (!$panel_ref) { | if (!$panel_ref) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $this->panelKey = $panel_key; | $this->panelKey = $panel_key; | ||||
| } else { | |||||
| $panel_ref = null; | |||||
| } | } | ||||
| $column_key = $request->getStr('columnKey'); | $column_key = $request->getStr('columnKey'); | ||||
| if (strlen($column_key)) { | if (strlen($column_key)) { | ||||
| $columns = $ref_list->getColumns(); | $columns = $ref_list->getColumns(); | ||||
| if (!isset($columns[$column_key])) { | if (!isset($columns[$column_key])) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $this->columnKey = $column_key; | $this->columnKey = $column_key; | ||||
| } | } | ||||
| $after_ref = null; | |||||
| $after_key = $request->getStr('afterKey'); | |||||
| if (strlen($after_key)) { | |||||
| $after_ref = $ref_list->getPanelRef($after_key); | |||||
| if (!$after_ref) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| } | |||||
| switch ($request->getURIData('op')) { | switch ($request->getURIData('op')) { | ||||
| case 'add': | case 'add': | ||||
| return $this->handleAddRequest($dashboard, $done_uri); | return $this->handleAddRequest($dashboard, $done_uri); | ||||
| case 'remove': | case 'remove': | ||||
| if (!$panel_ref) { | if (!$panel_ref) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| return $this->handleRemoveRequest($dashboard, $panel_ref, $done_uri); | return $this->handleRemoveRequest($dashboard, $panel_ref, $done_uri); | ||||
| case 'move': | |||||
| return $this->handleMoveRequest($dashboard, $panel_ref, $after_ref); | |||||
| } | } | ||||
| } | } | ||||
| private function handleAddRequest( | private function handleAddRequest( | ||||
| PhabricatorDashboard $dashboard, | PhabricatorDashboard $dashboard, | ||||
| $done_uri) { | $done_uri) { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| ▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | private function handleRemoveRequest( | ||||
| return $this->newEditDialog() | return $this->newEditDialog() | ||||
| ->setTitle(pht('Remove Dashboard Panel')) | ->setTitle(pht('Remove Dashboard Panel')) | ||||
| ->appendParagraph($message) | ->appendParagraph($message) | ||||
| ->addCancelButton($done_uri) | ->addCancelButton($done_uri) | ||||
| ->addSubmitButton(pht('Remove Panel')); | ->addSubmitButton(pht('Remove Panel')); | ||||
| } | } | ||||
| private function handleMoveRequest( | |||||
| PhabricatorDashboard $dashboard, | |||||
| PhabricatorDashboardPanelRef $panel_ref, | |||||
| PhabricatorDashboardPanelRef $after_ref = null) { | |||||
| $request = $this->getRequest(); | |||||
| $request->validateCSRF(); | |||||
| $viewer = $this->getViewer(); | |||||
| $xactions = array(); | |||||
| $ref_list = clone $dashboard->getPanelRefList(); | |||||
| $ref_list->movePanelRef($panel_ref, $this->columnKey, $after_ref); | |||||
| $new_panels = $ref_list->toDictionary(); | |||||
| $xactions[] = $dashboard->getApplicationTransactionTemplate() | |||||
| ->setTransactionType( | |||||
| PhabricatorDashboardPanelsTransaction::TRANSACTIONTYPE) | |||||
| ->setNewValue($new_panels); | |||||
| $editor = $dashboard->getApplicationTransactionEditor() | |||||
| ->setActor($viewer) | |||||
| ->setContentSourceFromRequest($request) | |||||
| ->setContinueOnNoEffect(true) | |||||
| ->setContinueOnMissingFields(true); | |||||
| $editor->applyTransactions($dashboard, $xactions); | |||||
| return id(new AphrontAjaxResponse())->setContent(array()); | |||||
| } | |||||
| private function newEditDialog() { | private function newEditDialog() { | ||||
| return $this->newDialog() | return $this->newDialog() | ||||
| ->addHiddenInput('contextPHID', $this->contextPHID) | ->addHiddenInput('contextPHID', $this->contextPHID) | ||||
| ->addHiddenInput('panelKey', $this->panelKey) | ->addHiddenInput('panelKey', $this->panelKey) | ||||
| ->addHiddenInput('columnKey', $this->columnKey); | ->addHiddenInput('columnKey', $this->columnKey); | ||||
| } | } | ||||
| } | } | ||||