Differential D17351 Diff 41733 src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php
<?php | <?php | ||||
final class PhabricatorDashboardAddPanelController | final class PhabricatorDashboardAddPanelController | ||||
extends PhabricatorDashboardController { | extends PhabricatorDashboardController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
$dashboard = id(new PhabricatorDashboardQuery()) | $dashboard = id(new PhabricatorDashboardQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($id)) | ->withIDs(array($id)) | ||||
->needPanels(true) | |||||
->requireCapabilities( | ->requireCapabilities( | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$dashboard) { | if (!$dashboard) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$redirect_uri = $this->getApplicationURI( | $redirect_uri = $this->getApplicationURI( | ||||
'arrange/'.$dashboard->getID().'/'); | 'arrange/'.$dashboard->getID().'/'); | ||||
$v_panel = head($request->getArr('panel')); | $v_panel = head($request->getArr('panel')); | ||||
$e_panel = true; | $e_panel = true; | ||||
$errors = array(); | $errors = array(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
if (strlen($v_panel)) { | if (strlen($v_panel)) { | ||||
$panel = id(new PhabricatorDashboardPanelQuery()) | $panel = id(new PhabricatorDashboardPanelQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($v_panel)) | ->withIDs(array($v_panel)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$panel) { | if (!$panel) { | ||||
$errors[] = pht('No such panel!'); | $errors[] = pht('Not a valid panel.'); | ||||
$e_panel = pht('Invalid'); | $e_panel = pht('Invalid'); | ||||
} | } | ||||
$on_dashboard = $dashboard->getPanels(); | |||||
$on_ids = mpull($on_dashboard, null, 'getID'); | |||||
if (array_key_exists($v_panel, $on_ids)) { | |||||
$p_name = $panel->getName(); | |||||
$errors[] = pht('Panel "%s" already exists on dashboard.', $p_name); | |||||
$e_panel = pht('Invalid'); | |||||
} | |||||
} else { | } else { | ||||
$errors[] = pht('Select a panel to add.'); | $errors[] = pht('Select a panel to add.'); | ||||
$e_panel = pht('Required'); | $e_panel = pht('Required'); | ||||
} | } | ||||
if (!$errors) { | if (!$errors) { | ||||
PhabricatorDashboardTransactionEditor::addPanelToDashboard( | PhabricatorDashboardTransactionEditor::addPanelToDashboard( | ||||
$viewer, | $viewer, | ||||
Show All 29 Lines | $form = id(new AphrontFormView()) | ||||
->appendRemarkupInstructions( | ->appendRemarkupInstructions( | ||||
pht('Choose a panel to add to this dashboard:')) | pht('Choose a panel to add to this dashboard:')) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setUser($this->getViewer()) | ->setUser($this->getViewer()) | ||||
->setDatasource(new PhabricatorDashboardPanelDatasource()) | ->setDatasource(new PhabricatorDashboardPanelDatasource()) | ||||
->setLimit(1) | ->setLimit(1) | ||||
->setName('panel') | ->setName('panel') | ||||
->setLabel(pht('Panel')) | ->setLabel(pht('Panel'))); | ||||
->setValue($v_panel)); | |||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Add Panel')) | ->setTitle(pht('Add Panel')) | ||||
->setErrors($errors) | ->setErrors($errors) | ||||
->appendChild($form->buildLayoutView()) | ->appendChild($form->buildLayoutView()) | ||||
->addCancelButton($redirect_uri) | ->addCancelButton($redirect_uri) | ||||
->addSubmitButton(pht('Add Panel')); | ->addSubmitButton(pht('Add Panel')); | ||||
} | } | ||||
} | } |